예제 #1
0
$oldchange = array_diff_assoc($oldstate, $currentstate);
// Figure out changed IPs and Tunnel Ups
$tunnelchange = "";
$tunnelup = "";
foreach ($newchange as $name => $ip) {
    if (isset($oldstate[$name])) {
        $tunnelchange .= "Tunnel connecting IP change for " . $name . " from " . $oldstate[$name] . " to " . $ip . "\r\n";
    } else {
        $tunnelup .= "Tunnel " . $name . " came up with connecting IP " . $ip . "\r\n";
    }
}
// Figure out tunnel downs
$tunneldown = "";
foreach ($oldchange as $name => $ip) {
    if (!isset($currentstate[$name])) {
        $tunneldown .= "Tunnel " . $name . " is down - last connecting IP " . $ip . "\r\n";
    }
}
// Email the alerts
if (!$tunnelup == "") {
    email_alert($tunnelup, "MikroTik Tunnels UP");
}
if (!$tunneldown == "") {
    email_alert($tunneldown, "MikroTik Tunnels DOWN");
}
if (!$tunnelchange == "") {
    email_alert($tunnelchange, "MikroTik Tunnels CHANGED IP");
}
?>

예제 #2
0
    die("Error cannot select devices");
}
// Parse out status changes for listed deviceIDs
while ($ar = mysql_fetch_array($res, MYSQL_BOTH)) {
    $dev = $ar['deviceID'];
    $devname = $ar['displayName'];
    $email = $ar['contactEmail'];
    $stati = mysql_query("SELECT deviceID,timestamp,statusCode,rawData FROM EventData WHERE deviceID='" . $dev . "' AND statusCode<>61472 AND statusCode<>64816 ORDER BY timestamp DESC LIMIT 2;");
    $idx = 0;
    while ($sr = mysql_fetch_array($stati, MYSQL_BOTH)) {
        $returnstatus[$idx][0] = $sr['statusCode'];
        $returnstatus[$idx][1] = $sr['rawData'];
        $returnstatus[$idx][2] = $sr['timestamp'];
        $idx++;
    }
    // If last two statuses are not the same and this happened in the last 5 minutes (300 seconds) then email
    if ($returnstatus[0][0] != $returnstatus[1][0] && time() - $returnstatus[0][2] < 300) {
        email_alert($devname, $returnstatus[0][1], $email);
    }
    // DEBUG - Remove after you figure out whats wrong
    /*  echo($devname." - ".$email." :\n");
      print_r($returnstatus);
      echo("\n\n");
    */
    // Clean up our mess
    unset($returnstatus);
    mysql_free_result($stati);
}
// Clean up hanging connecions
mysql_free_result($res);
mysql_close($link);