From 74235000be1ce586414939025aeb5007fdbe247b Mon Sep 17 00:00:00 2001 From: Geert Hauwaerts Date: Thu, 25 Feb 2010 20:40:35 +0000 Subject: [PATCH] - Send email alerts on interface flaps when $config['warn']['ifdown'] is true. - Added the setting timestamp_format: Description: The timestamp format to use in logs or emails. Default: d-m-Y H:i:s - Modified timestamp dates. git-svn-id: http://www.observium.org/svn/observer/trunk@952 61d68cd4-352d-0410-923a-c4978735b2b8 --- check-services.php | 4 ++-- includes/defaults.inc.php | 19 ++++++++++--------- includes/polling/fanspeeds.inc.php | 2 +- includes/polling/hr-mib_storage.inc.php | 2 +- includes/polling/ports.inc.php | 14 ++++++++++++++ includes/polling/temperatures.inc.php | 2 +- includes/polling/voltages.inc.php | 4 ++-- poll-reachability.php | 4 ++-- 8 files changed, 33 insertions(+), 18 deletions(-) diff --git a/check-services.php b/check-services.php index 65d02fae7..36267fbba 100755 --- a/check-services.php +++ b/check-services.php @@ -23,11 +23,11 @@ while ($service = mysql_fetch_array($query)) { if($service['sysContact']) { $email = $service['sysContact']; } else { $email = $config['email_default']; } if($status == "1") { $msg = "Service Up: " . $service['service_type'] . " on " . $service['hostname']; - $msg .= " at " . date('l dS F Y h:i:s A'); + $msg .= " at " . date($config['timestamp_format']); mail($email, "Service Up: " . $service['service_type'] . " on " . $service['hostname'], $msg, $config['email_headers']); } elseif ($status == "0") { $msg = "Service Down: " . $service['service_type'] . " on " . $service['hostname']; - $msg .= " at " . date('l dS F Y h:i:s A'); + $msg .= " at " . date($config['timestamp_format']); mail($email, "Service Down: " . $service['service_type'] . " on " . $service['hostname'], $msg, $config['email_headers']); } diff --git a/includes/defaults.inc.php b/includes/defaults.inc.php index 27a85983a..815ab5846 100644 --- a/includes/defaults.inc.php +++ b/includes/defaults.inc.php @@ -17,15 +17,16 @@ $config['nagios_plugins'] = "/usr/lib/nagios/plugins"; ### Local Specifics -$config['title_image'] = "images/observer-logo.gif"; -$config['stylesheet'] = "css/styles.css"; -$config['mono_font'] = "DejaVuSansMono"; -$config['favicon'] = "favicon.ico"; -$config['header_color'] = "#1F334E"; -$config['page_refresh'] = "30"; ## Refresh the page every xx seconds -$config['frong_page'] = "default.php"; -$config['page_title'] = "ObserverNMS"; -$config['syslog_age'] = "1 month"; +$config['title_image'] = "images/observer-logo.gif"; +$config['stylesheet'] = "css/styles.css"; +$config['mono_font'] = "DejaVuSansMono"; +$config['favicon'] = "favicon.ico"; +$config['header_color'] = "#1F334E"; +$config['page_refresh'] = "30"; ## Refresh the page every xx seconds +$config['frong_page'] = "default.php"; +$config['page_title'] = "ObserverNMS"; +$config['syslog_age'] = "1 month"; +$config['timestamp_format'] = 'd-m-Y H:i:s'; ### Cosmetics diff --git a/includes/polling/fanspeeds.inc.php b/includes/polling/fanspeeds.inc.php index 2e2d64ccb..c48b2b81a 100755 --- a/includes/polling/fanspeeds.inc.php +++ b/includes/polling/fanspeeds.inc.php @@ -30,7 +30,7 @@ while($fanspeed = mysql_fetch_array($fan_data)) { if($fanspeed['fan_current'] > $fanspeed['fan_limit'] && $fan <= $fanspeed['fan_limit']) { if($device['sysContact']) { $email = $device['sysContact']; } else { $email = $config['email_default']; } $msg = "Fan Alarm: " . $device['hostname'] . " " . $fanspeed['fan_descr'] . " is " . $fan . "rpm (Limit " . $fanspeed['fan_limit']; - $msg .= "rpm) at " . date('l dS F Y h:i:s A'); + $msg .= "rpm) at " . date($config['timestamp_format']); mail($email, "Fan Alarm: " . $device['hostname'] . " " . $fanspeed['fan_descr'], $msg, $config['email_headers']); echo("Alerting for " . $device['hostname'] . " " . $fanspeed['fan_descr'] . "\n"); eventlog('Fan speed ' . $fanspeed['fan_descr'] . " under threshold: " . $fanspeed['fan_current'] . " rpm (> " . $fanspeed['fan_limit'] . " rpm)", $device['device_id']); diff --git a/includes/polling/hr-mib_storage.inc.php b/includes/polling/hr-mib_storage.inc.php index 11e56d446..6acfa7198 100755 --- a/includes/polling/hr-mib_storage.inc.php +++ b/includes/polling/hr-mib_storage.inc.php @@ -38,7 +38,7 @@ while ($dr = mysql_fetch_array($dq)) { if (!is_numeric($dr['storage_perc_warn'])) { $dr['storage_perc_warn'] = 60; } if($dr['storage_perc'] < $dr['storage_perc_warn'] && $perc >= $dr['storage_perc_warn']) { - $msg = "Disk Alarm: " . $device['hostname'] . " " . $dr['storage_descr'] . " is " . $perc . "% at " . date('l dS F Y h:i:s A'); + $msg = "Disk Alarm: " . $device['hostname'] . " " . $dr['storage_descr'] . " is " . $perc . "% at " . date($config['timestamp_format']); notify($device, "Disk Alarm: " . $device['hostname'] . " " . $dr['storage_descr'], $msg); echo("Alerting for " . $device['hostname'] . " " . $dr['storage_descr'] . "\n"); } diff --git a/includes/polling/ports.inc.php b/includes/polling/ports.inc.php index ac8e7fd0c..309b690c2 100755 --- a/includes/polling/ports.inc.php +++ b/includes/polling/ports.inc.php @@ -162,6 +162,20 @@ // End Update MySQL unset($update_query); unset($update); + + // Send alerts for interface flaps. + if ($config['warn']['ifdown'] && ($port['ifOperStatus'] != $this_port['ifOperStatus'])) { + if ($device['sysContact']) { $email = $device['sysContact']; } else { $email = $config['email_default']; } + if ($this_port['ifAlias']) { $falias = preg_replace('/^"/', '', $this_port['ifAlias']); $falias = preg_replace('/"$/', '', $falias); $full = $this_port['ifDescr'] . " (" . $falias . ")"; } else { $full = $this_port['ifDescr']; } + switch ($this_port['ifOperStatus']) { + case "up": + mail($email, "Interface UP - " . $device['hostname'] . " - " . $full, "Device: " . $device['hostname'] . "\nInterface: " . $full . "\nTimestamp: " . date($config['timestamp_format']), $config['email_headers']); + break; + case "down": + mail($email, "Interface DOWN - " . $device['hostname'] . " - " . $full, "Device: " . $device['hostname'] . "\nInterface: " . $full . "\nTimestamp: " . date($config['timestamp_format']), $config['email_headers']); + break; + } + } } else { echo("Port Deleted?"); // Port missing from SNMP cache? } diff --git a/includes/polling/temperatures.inc.php b/includes/polling/temperatures.inc.php index c188b82fd..116dadadb 100755 --- a/includes/polling/temperatures.inc.php +++ b/includes/polling/temperatures.inc.php @@ -37,7 +37,7 @@ while($temperature = mysql_fetch_array($temp_data)) { if($temperature['temp_current'] < $temperature['temp_limit'] && $temp >= $temperature['temp_limit']) { if($device['sysContact']) { $email = $device['sysContact']; } else { $email = $config['email_default']; } $msg = "Temp Alarm: " . $device['hostname'] . " " . $temperature['temp_descr'] . " is " . $temp . " (Limit " . $temperature['temp_limit']; - $msg .= ") at " . date('l dS F Y h:i:s A'); + $msg .= ") at " . date($config['timestamp_format']); mail($email, "Temp Alarm: " . $device['hostname'] . " " . $temperature['temp_descr'], $msg, $config['email_headers']); echo("Alerting for " . $device['hostname'] . " " . $temperature['temp_descr'] . "\n"); eventlog('Temperature ' . $temperature['temp_descr'] . " over threshold: " . $temperature['temp_current'] . " °C (> " . $temperature['temp_limit'] . " °C)", $device['device_id']); diff --git a/includes/polling/voltages.inc.php b/includes/polling/voltages.inc.php index 887bd7049..a973346d7 100755 --- a/includes/polling/voltages.inc.php +++ b/includes/polling/voltages.inc.php @@ -34,7 +34,7 @@ while($voltage = mysql_fetch_array($volt_data)) { { if($device['sysContact']) { $email = $device['sysContact']; } else { $email = $config['email_default']; } $msg = "Voltage Alarm: " . $device['hostname'] . " " . $voltage['volt_descr'] . " is " . $volt . "V (Limit " . $voltage['volt_limit']; - $msg .= "V) at " . date('l dS F Y h:i:s A'); + $msg .= "V) at " . date($config['timestamp_format']); mail($email, "Voltage Alarm: " . $device['hostname'] . " " . $voltage['volt_descr'], $msg, $config['email_headers']); echo("Alerting for " . $device['hostname'] . " " . $voltage['volt_descr'] . "\n"); eventlog('Voltage ' . $voltage['volt_descr'] . " under threshold: " . $voltage['volt_current'] . " V (> " . $voltage['volt_limit'] . " V)", $device['device_id']); @@ -43,7 +43,7 @@ while($voltage = mysql_fetch_array($volt_data)) { { if($device['sysContact']) { $email = $device['sysContact']; } else { $email = $config['email_default']; } $msg = "Voltage Alarm: " . $device['hostname'] . " " . $voltage['volt_descr'] . " is " . $volt . "V (Limit " . $voltage['volt_limit']; - $msg .= "V) at " . date('l dS F Y h:i:s A'); + $msg .= "V) at " . date($config['timestamp_format']); mail($email, "Voltage Alarm: " . $device['hostname'] . " " . $voltage['volt_descr'], $msg, $config['email_headers']); echo("Alerting for " . $device['hostname'] . " " . $voltage['volt_descr'] . "\n"); eventlog('Voltage ' . $voltage['volt_descr'] . " above threshold: " . $voltage['volt_current'] . " V (> " . $voltage['volt_limit'] . " V)", $device['device_id']); diff --git a/poll-reachability.php b/poll-reachability.php index 9d03cf670..cc9c3cf4f 100755 --- a/poll-reachability.php +++ b/poll-reachability.php @@ -45,11 +45,11 @@ while ($device = mysql_fetch_array($device_query)) { if ($status == '1') { $stat = "Up"; mysql_query("INSERT INTO alerts (importance, device_id, message) VALUES ('0', '" . $device['device_id'] . "', 'Device is up\n')"); - mail($email, "DeviceUp: " . $device['hostname'], "Device Up: " . $device['hostname'] . " at " . date('l dS F Y h:i:s A'), $config['email_headers']); + mail($email, "DeviceUp: " . $device['hostname'], "Device Up: " . $device['hostname'] . " at " . date($config['timestamp_format']), $config['email_headers']); } else { $stat = "Down"; mysql_query("INSERT INTO alerts (importance, device_id, message) VALUES ('9', '" . $device['device_id'] . "', 'Device is down\n')"); - mail($email, "Device Down: " . $device['hostname'], "Device Down: " . $device['hostname'] . " at " . date('l dS F Y h:i:s A'), $config['email_headers']); + mail($email, "Device Down: " . $device['hostname'], "Device Down: " . $device['hostname'] . " at " . date($config['timestamp_format']), $config['email_headers']); } eventlog("Device status changed to $stat", $device['device_id']); echo("Status Changed!\n");