Cacti / plugin_mactrack

Mactrack Plugin for Cacti
GNU General Public License v2.0
12 stars 25 forks source link

Update mactrack send mail (poller_mactrack.php) #179

Closed GrayFox14048 closed 1 year ago

GrayFox14048 commented 1 year ago

Find "function mactrack_process_mac_auth_report (in poller_mactrack.php) and replace:

`function mactrack_process_mac_auth_report($mac_auth_frequency, $last_macauth_time) { if ($mac_auth_frequency == 0) { $ports = db_fetch_assoc("SELECT mac_track_temp_ports., mac_track_sites.site_name FROM mac_track_temp_ports LEFT JOIN mac_track_sites ON mac_track_sites.site_id=mac_track_temp_ports.site_id WHERE authorized=0"); }else{ $ports = db_fetch_assoc("SELECT mac_track_ports., mac_track_sites.site_name FROM mac_track_ports LEFT JOIN mac_track_sites ON mac_track_sites.site_id=mac_track_temp_ports.site_id WHERE authorized=0"); }

if (sizeof($ports)) {
    foreach($ports as $port) {
        /* create the report */
    }

    /* email the report */
}else{
    if ($mac_auth_frequency > 0) {
        /* send out an empty report */
    }
}

}`

With

`function mactrack_process_mac_auth_report($mac_auth_frequency, $last_macauth_time) { / ############## Patch ############# / if ($mac_auth_frequency == 0) { $ports = db_fetch_assoc("SELECT mac_track_temp_ports., mac_track_sites.site_name FROM mac_track_temp_ports LEFT JOIN mac_track_sites ON mac_track_sites.site_id=mac_track_temp_ports.site_id WHERE authorized=0 ORDER BY mac_track_temp_ports.device_name,mac_track_temp_ports.port_number,mac_track_temp_ports.scan_date,mac_track_temp_ports.mac_address");
}else{ $ports = db_fetch_assoc("SELECT mac_track_ports.
, mac_track_sites.site_name FROM mac_track_ports LEFT JOIN mac_track_sites ON mac_track_sites.site_id=mac_track_ports.site_id WHERE authorized=0 ORDER BY mac_track_ports.device_name,mac_track_ports.port_number,mac_track_ports.scan_date,mac_track_ports.mac_address"); } / ################################ /

if (sizeof($ports)) {
    /* ############## Patch ############# */
    $message = "<table><tr><td>Switch Name</td><td>Switch Hostname</td><td>ED IP Address</td><td>ED MAC Address</td><td>Port Number</td><td>Port Name</td><td>Scan Date</td></tr>";
    foreach($ports as $port) {
        /* create the report */
        $message .= "<tr>";
        $message .= "<td>" . $port["device_name"] . "</td>";
        $message .= "<td>" . $port["hostname"] . "</td>";

        $message .= "<td>" . $port["ip_address"] . "</td>";
        $message .= "<td>" . $port["mac_address"] . "</td>";

        $message .= "<td>" . $port["port_number"] . "</td>";
        $message .= "<td>" . $port["port_name"] . "</td>";

        $message .= "<td>" . $port["scan_date"] . "</td>";

        $message .= "</tr>";
    }

    $message .= "</table>";
    $message = "Not authorized devices:<br><br>" . $message;

    /* set the subject */
    $subject = "MACAUTH Report " . date("Y-m-d H:i:s") ;

    $from     = read_config_option("mt_from_email");
    $fromname = read_config_option("mt_from_name");
    $to = read_config_option("mt_macauth_emails");

    /* email the report */
    mactrack_mail($to, $from, $fromname, $subject, $message, $headers = '');

    mactrack_debug("MACAUTH Report eMail sent.");

    /* ############################## */
}else{
    if ($mac_auth_frequency > 0) {
        /* send out an empty report */

    /* ############## Patch ############# */

    $message = "No not authorized devices found.";

    /* set the subject */
    $subject = "MACAUTH Report OK " . date("Y-m-d H:i:s") ;

    $from     = read_config_option("mt_from_email");
    $fromname = read_config_option("mt_from_name");
    $to = read_config_option("mt_macauth_emails");

    /* email the report */
    mactrack_mail($to, $from, $fromname, $subject, $message, $headers = '');

    mactrack_debug("MACAUTH Report empty eMail sent.");

    /* ############################## */

    }
}

}`

Also find "function collect_mactrack_data ("in poller_mactrack.php) and replace

/* if it's time to e-mail */ if (($last_macauth_time + ($mac_auth_frequency*60) > time()) || ($mac_auth_frequency == 0)) { mactrack_process_mac_auth_report($mac_auth_frequency, $last_macauth_time); }

with

/* if it's time to e-mail */ /* ############## Patch ############# */ /* if (($last_macauth_time + ($mac_auth_frequency*60) > time()) || ($mac_auth_frequency == 0)) { mactrack_process_mac_auth_report($mac_auth_frequency, $last_macauth_time); } */ mactrack_debug("MACAUTH Time to mail report? " . $last_macauth_time . " + " . ($mac_auth_frequency*60) ." <= " . time()); if (($last_macauth_time + ($mac_auth_frequency*60) <= time()) || ($mac_auth_frequency == 0)) { mactrack_process_mac_auth_report($mac_auth_frequency, $last_macauth_time); set_config_option("mt_last_macauth_time",time()); } /* ############################### */

Tested by me in MACTRACK 4.5 on CACTI 1.2.23 Thanks to mf2hd for the solution, you saved our lifes! https://forums.cacti.net/viewtopic.php?p=252897

TheWitness commented 1 year ago

@GrayFox14048, can you please do the following.

1) Update your branch to the latest. I usually simply delete the entire GitHub facing repository and then re-clone it. 2) Re-apply your patches 3) Re-create this pull request

The reason being is that you are applying this pull request from a very old MacTrack version. So, I can not see the forest from the tree's.

Thanks,

Larry