From 9fd77cd8840822b1abf2c7a565a0e10eb5facf16 Mon Sep 17 00:00:00 2001 From: Tom Laermans Date: Wed, 30 Mar 2011 16:28:24 +0000 Subject: [PATCH] allow disabling of alerting per device, allow override of syscontact, minor cleanups git-svn-id: http://www.observium.org/svn/observer/trunk@1995 61d68cd4-352d-0410-923a-c4978735b2b8 --- html/images/icons/alerts.png | Bin 0 -> 678 bytes html/images/icons/greyscale/alerts.png | Bin 0 -> 567 bytes html/includes/print-interface-adsl.inc.php | 3 +- html/includes/print-interface.inc.php | 9 +-- html/pages/addhost.inc.php | 2 +- html/pages/bills.inc.php | 4 +- html/pages/device/edit.inc.php | 1 + html/pages/device/edit/alerts.inc.php | 63 +++++++++++++++++++++ html/pages/device/edit/ipmi.inc.php | 12 ++-- html/pages/device/edit/snmp.inc.php | 8 +-- includes/discovery/os.inc.php | 2 +- includes/discovery/ports.inc.php | 30 +++++----- includes/functions.php | 33 ++++++----- includes/polling/os/unix.inc.php | 13 ++--- includes/polling/ports.inc.php | 4 +- includes/rewrites.php | 3 +- poll-reachability.php | 2 +- 17 files changed, 126 insertions(+), 63 deletions(-) create mode 100755 html/images/icons/alerts.png create mode 100644 html/images/icons/greyscale/alerts.png create mode 100644 html/pages/device/edit/alerts.inc.php diff --git a/html/images/icons/alerts.png b/html/images/icons/alerts.png new file mode 100755 index 0000000000000000000000000000000000000000..f640256399f046cde8dd91eb75c066902fcfca85 GIT binary patch literal 678 zcmV;X0$KfuP)&qJbow|jiS2#4N{$R0WLTZ2{0maUAKP;ba*kDOsb7Wqlp%QS1KhU;N7@5by=0s zmq6AS3WZRs)!NF8;Y8}BQWt;JWwZBmAek9~JUvF7O!F1lQ?STdk6+P4mt#iL@Kj(?SViZ@x(dovnP-+Hn95Y`kB52 zT`>FGIGz1~vGoN;+ytw=L1JPK%=PZAJe>~iAdt=J+(_9tH9m4-G(O@;Y8GggQGD_Y z!)611)4NJ>t;d0!g0AbTZfQU4Rk1%7f?;igyH%=>gVmQYa{i9yyY9o{Dh&#KClkq zZ^`-W=(`>n#l}|$Yi}RC(E2^+50BD61>-}qA41;3ZisG1`*xOo17YZXX4HXKtN;K2 M07*qoM6N<$g3c2*g#Z8m literal 0 HcmV?d00001 diff --git a/html/images/icons/greyscale/alerts.png b/html/images/icons/greyscale/alerts.png new file mode 100644 index 0000000000000000000000000000000000000000..38ca2345304aa7e78984beac8e85e96e2cabe5d0 GIT binary patch literal 567 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!60wlNoGJgf6SkfJR9T^zbpD<_bdI{t+C3(BM zF#K=tKeHdm<1FxqEC$jZVC;4>+YTgHR^XTpq`_t}#2j0Dn1O*&-_yl0MB{wz#Jyh3 zfdX#lXZbR%>onx}m#ypQc;u23hhxB+pcOxa>>4_LFf~mT*kIDSpjCm<+S<`GihHBj zMh?zh)$iwKPu!h-$>OL1k9_*RnICojx66y`PyglcQ>sFVn0z5CJ|udP@ox++qH zDdJehhWDy1&z7z0Jv${cNauKOYstyV3ct8k=gv-l>T z>C#Mx-WI4Urg$iFbTKLaNyyy%&ULx?PPvCKC-PZtDw(mgd!dg<*QKPA7k;(dmijFV z>lTSv(EGtba=uKs{HBLT@7t{Nx$}0Ju2!VMgQ>^1e*gaNv%j%SywSODKgGYr^@Sbf zSjPqoN7WM7h?11Vl2ohYqEsNoU}RuusB2)XYitl=XklewYGrJxZD3?&V8FX<>M;}z zx%nxXX_dG&)cn@10&0*1*$|wcR#Ki=l*-_klAn~S;F+74o*I;zm{M7IGSvpCh{4m< K&t;ucLK6T", $interface['graph_type'])); - echo(""); echo("".formatRates($interface['adslAturChanCurrTxRate']) . "/". formatRates($interface['adslAtucChanCurrTxRate'])); echo("
"); @@ -142,4 +141,4 @@ if ($graph_type && is_file($graph_file)) } -?> +?> \ No newline at end of file diff --git a/html/includes/print-interface.inc.php b/html/includes/print-interface.inc.php index e2344d13f..54f85132d 100644 --- a/html/includes/print-interface.inc.php +++ b/html/includes/print-interface.inc.php @@ -1,9 +1,5 @@ "); -#print_r($interface); -#echo(""); - # This file prints a table row for each interface $interface['device_id'] = $device['device_id']; @@ -32,12 +28,12 @@ echo(""); echo(" " . generate_port_link($interface, $interface['ifIndex'] . ". ".$interface['label']) . " $error_img $mac -
".$interface['ifAlias'].""); if ($interface['ifAlias']) { echo("
"); } unset ($break); + if ($port_details) { $ipdata = mysql_query("SELECT * FROM `ipv4_addresses` WHERE `interface_id` = '" . $interface['interface_id'] . "'"); @@ -271,7 +267,6 @@ if ($graph_type && is_file($graph_file)) # onmouseout=\"return nd();\"> "); echo(""); - } -?> +?> \ No newline at end of file diff --git a/html/pages/addhost.inc.php b/html/pages/addhost.inc.php index 4a10f3c76..56f9839b1 100644 --- a/html/pages/addhost.inc.php +++ b/html/pages/addhost.inc.php @@ -29,7 +29,7 @@ if ($_POST['hostname'] && $_POST['community']) ?> -
+

Devices will be checked for Ping and SNMP reachability before being probed. Only devices with recognised OSes will be added.

diff --git a/html/pages/bills.inc.php b/html/pages/bills.inc.php index c8e1d3149..d4515cad5 100644 --- a/html/pages/bills.inc.php +++ b/html/pages/bills.inc.php @@ -1,4 +1,4 @@ - "7") + { + $override_sysContact_bool = mres($_POST['override_sysContact']); + if (isset($_POST['sysContact'])) { $override_sysContact_string = mres($_POST['sysContact']); } + $disable_notify = mres($_POST['disable_notify']); + + if ($override_sysContact_bool) { set_dev_attrib($device, 'override_sysContact_bool', '1'); } else { del_dev_attrib($device, 'override_sysContact_bool'); } + if (isset($override_sysContact_string)) { set_dev_attrib($device, 'override_sysContact_string', $override_sysContact_string); }; + if ($disable_notify) { set_dev_attrib($device, 'disable_notify', '1'); } else { del_dev_attrib($device, 'disable_notify'); } + + $update_message = "Device alert settings updated."; + $updated = 1; + } +} + +if ($updated && $update_message) +{ + print_message($update_message); +} elseif ($update_message) { + print_error($update_message); +} + +$override_sysContact_bool = get_dev_attrib($device,'override_sysContact_bool'); +$override_sysContact_string = get_dev_attrib($device,'override_sysContact_string'); +$disable_notify = get_dev_attrib($device,'disable_notify'); +?> + +

Alert settings

+ + + + + + + +
+ + + + + + + + + + + + + + + + +
/>
Override sysContact: value="" />
/>
Disable all alerting for this host
+
+ +
+
+ +
diff --git a/html/pages/device/edit/ipmi.inc.php b/html/pages/device/edit/ipmi.inc.php index 829e3aa89..4cf760d95 100644 --- a/html/pages/device/edit/ipmi.inc.php +++ b/html/pages/device/edit/ipmi.inc.php @@ -26,24 +26,26 @@ if ($updated && $update_message) ?> - +

IPMI settings

+ +
- + - + - + - + diff --git a/html/pages/device/edit/snmp.inc.php b/html/pages/device/edit/snmp.inc.php index 877b40508..e5c5c039e 100644 --- a/html/pages/device/edit/snmp.inc.php +++ b/html/pages/device/edit/snmp.inc.php @@ -50,7 +50,7 @@ echo("
IPMI/BMC Hostname
IPMI/BMC Username
IPMI/BMC Password
- @@ -63,7 +63,7 @@ echo("
SNMP Community
+
- @@ -83,13 +83,13 @@ echo(" - - "); diff --git a/includes/discovery/os.inc.php b/includes/discovery/os.inc.php index 788d6bae8..b669f6648 100644 --- a/includes/discovery/os.inc.php +++ b/includes/discovery/os.inc.php @@ -6,7 +6,7 @@ if ($os != $device['os']) { $sql = mysql_query("UPDATE `devices` SET `os` = '$os' WHERE `device_id` = '".$device['device_id']."'"); echo("Changed OS! : $os\n"); - eventlog("Device OS changed ".$device['os']." => $os", $device['device_id']); + log_event("Device OS changed ".$device['os']." => $os", $device, 'system'); $device['os'] = $os; } diff --git a/includes/discovery/ports.inc.php b/includes/discovery/ports.inc.php index e0e2b5e58..ab934432b 100755 --- a/includes/discovery/ports.inc.php +++ b/includes/discovery/ports.inc.php @@ -33,11 +33,11 @@ foreach (explode("\n", $ports) as $entry) { foreach ($config['bad_if_regexp'] as $bi) { - if (preg_match($bi ."i", $if)) - { - $nullintf = 1; + if (preg_match($bi ."i", $if)) + { + $nullintf = 1; if($debug) { echo("ignored : $bi : $if"); } - } + } } } @@ -48,23 +48,25 @@ foreach (explode("\n", $ports) as $entry) if ($debug) echo("\n $if "); if ($nullintf == 0) { - if (mysql_result(mysql_query("SELECT COUNT(*) FROM `ports` WHERE `device_id` = '".$device['device_id']."' AND `ifIndex` = '$ifIndex'"), 0) == '0') { - mysql_query("INSERT INTO `ports` (`device_id`,`ifIndex`,`ifDescr`) VALUES ('".$device['device_id']."','$ifIndex','".mres($ifDescr)."')"); + if (mysql_result(mysql_query("SELECT COUNT(*) FROM `ports` WHERE `device_id` = '".$device['device_id']."' AND `ifIndex` = '$ifIndex'"), 0) == '0') + { + mysql_query("INSERT INTO `ports` (`device_id`,`ifIndex`,`ifDescr`) VALUES ('".$device['device_id']."','$ifIndex','".mres($ifDescr)."')"); # Add Interface - echo("+"); + echo("+"); } else { - mysql_query("UPDATE `ports` SET `deleted` = '0' WHERE `device_id` = '".$device['device_id']."' AND `ifIndex` = '$ifIndex'"); - echo("."); + mysql_query("UPDATE `ports` SET `deleted` = '0' WHERE `device_id` = '".$device['device_id']."' AND `ifIndex` = '$ifIndex'"); + echo("."); } $int_exists[] = "$ifIndex"; } else { # Ignored Interface - if (mysql_result(mysql_query("SELECT COUNT(*) FROM `ports` WHERE `device_id` = '".$device['device_id']."' AND `ifIndex` = '$ifIndex'"), 0) != '0') { - mysql_query("UPDATE `ports` SET `deleted` = '1' WHERE `device_id` = '".$device['device_id']."' AND `ifIndex` = '$ifIndex'"); + if (mysql_result(mysql_query("SELECT COUNT(*) FROM `ports` WHERE `device_id` = '".$device['device_id']."' AND `ifIndex` = '$ifIndex'"), 0) != '0') + { + mysql_query("UPDATE `ports` SET `deleted` = '1' WHERE `device_id` = '".$device['device_id']."' AND `ifIndex` = '$ifIndex'"); # Delete Interface - echo("-"); ## Deleted Interface + echo("-"); ## Deleted Interface } else { - echo("X"); ## Ignored Interface + echo("X"); ## Ignored Interface } } } @@ -93,4 +95,4 @@ while ($test_if = mysql_fetch_array($query)) unset($temp_exists); echo("\n"); -?> +?> \ No newline at end of file diff --git a/includes/functions.php b/includes/functions.php index 8dd545df4..9b2b7dc92 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -222,7 +222,7 @@ function renamehost($id, $new, $source = 'console') rename($config['rrd_dir']."/$host",$config['rrd_dir']."/$new"); mysql_query("UPDATE devices SET hostname = '$new' WHERE device_id = '$id'"); - eventlog("Hostname changed -> $new ($source)", $id); + log_event("Hostname changed -> $new ($source)", $id, 'system'); } function delete_port($int_id) @@ -650,7 +650,7 @@ function get_astext($asn) } } -# DEPRECATED +# FIXME DEPRECATED -- only used in dead file includes/polling/interfaces.inc.php - if we no longer need that one, this can go too. function eventlog($eventtext,$device_id = "", $interface_id = "") { $event_query = "INSERT INTO eventlog (host, interface, datetime, message) VALUES (" . ($device_id ? $device_id : "NULL"); @@ -677,20 +677,27 @@ function notify($device,$title,$message) if ($config['alerts']['email']['enable']) { - if ($config['alerts']['email']['default_only']) + if (!get_dev_attrib($device,'disable_notify')) { - $email = $config['alerts']['email']['default']; - } else { - if ($device['sysContact']) + if ($config['alerts']['email']['default_only']) { - $email = $device['sysContact']; - } else { $email = $config['alerts']['email']['default']; + } else { + if (get_dev_attrib($device,'override_sysContact_bool')) + { + $email = get_dev_attrib($device,'override_sysContact_string'); + } + elseif ($device['sysContact']) + { + $email = $device['sysContact']; + } else { + $email = $config['alerts']['email']['default']; + } + } + if ($email) + { + mail($email, $title, $message, $config['email_headers']); } - } - if ($email) - { - mail($email, $title, $message, $config['email_headers']); } } } @@ -780,4 +787,4 @@ function include_dir($dir, $regex = "") } } -?> \ No newline at end of file +?> diff --git a/includes/polling/os/unix.inc.php b/includes/polling/os/unix.inc.php index f02d75dc7..07509b8c3 100755 --- a/includes/polling/os/unix.inc.php +++ b/includes/polling/os/unix.inc.php @@ -17,10 +17,10 @@ if ($device['os'] == "linux") $features = str_replace("\"", "", $features); if (!$features) // No "extend" support, try "exec" support - { - $features = snmp_get($device, ".1.3.6.1.4.1.2021.7890.1.101.1", "-Oqv", "UCD-SNMP-MIB"); - $features = str_replace("\"", "", $features); - } + { + $features = snmp_get($device, ".1.3.6.1.4.1.2021.7890.1.101.1", "-Oqv", "UCD-SNMP-MIB"); + $features = str_replace("\"", "", $features); + } // Detect Dell hardware via OpenManage SNMP $hw = snmp_get($device, ".1.3.6.1.4.1.674.10892.1.300.10.1.9.1", "-Oqv", "MIB-Dell-10892"); @@ -63,12 +63,9 @@ elseif ($device['os'] == "monowall" || $device['os'] == "Voswall") } elseif ($device['os'] == "qnap") { - $hardware = snmp_get($device, "ENTITY-MIB::entPhysicalName.1", "-Osqnv"); $version = snmp_get($device, "ENTITY-MIB::entPhysicalFirmwareRev.1", "-Osqnv"); $serial = snmp_get($device, "ENTITY-MIB::entPhysicalSerial.1", "-Osqnv"); - - } -?> +?> \ No newline at end of file diff --git a/includes/polling/ports.inc.php b/includes/polling/ports.inc.php index e6b6ad15d..a2fd5caad 100755 --- a/includes/polling/ports.inc.php +++ b/includes/polling/ports.inc.php @@ -46,8 +46,6 @@ if ($config['enable_ports_adsl']) $device['adsl_count'] = mysql_result(mysql_query("SELECT COUNT(*) FROM `ports` WHERE `device_id` = '".$device['device_id']."' AND `ifType` = 'adsl'"),0); } - - if ($device['adsl_count'] > "0") { echo("ADSL "); @@ -321,4 +319,4 @@ while ($port = mysql_fetch_array($port_query)) #### Clear Variables Here unset($port_stats); -?> +?> \ No newline at end of file diff --git a/includes/rewrites.php b/includes/rewrites.php index 3f0e24232..1a62edca0 100644 --- a/includes/rewrites.php +++ b/includes/rewrites.php @@ -950,8 +950,6 @@ function array_preg_replace($array, $string) return $string; } - - function rewrite_adslLineType($adslLineType) { $adslLineTypes = array ('noChannel' => 'No Channel', @@ -967,6 +965,7 @@ function rewrite_adslLineType($adslLineType) $adslLineType = $text; } } + return($adslLineType); } diff --git a/poll-reachability.php b/poll-reachability.php index dacf192f1..968db5118 100755 --- a/poll-reachability.php +++ b/poll-reachability.php @@ -54,7 +54,7 @@ while ($device = mysql_fetch_array($device_query)) notify($device, "Device Down: " . $device['hostname'], "Device Down: " . $device['hostname'] . " at " . date($config['timestamp_format'])); } } - eventlog("Device status changed to $stat", $device['device_id']); + log_event("Device status changed to $stat", $device, strtolower($stat))); echo("Status Changed!\n"); } }
SNMP Port
+
SNMP Timeout
  +   seconds
SNMP Retries
+