From c9bd48c9d2a26c3020cb9d330a7898ab9bf010fd Mon Sep 17 00:00:00 2001 From: Tom Laermans Date: Wed, 13 Jan 2010 15:54:03 +0000 Subject: [PATCH] notify() test + indent cleanup + html cleanup git-svn-id: http://www.observium.org/svn/observer/trunk@677 61d68cd4-352d-0410-923a-c4978735b2b8 --- includes/functions.php | 81 +++++++++++++++++++++++------------------- poll-device.php | 3 +- 2 files changed, 46 insertions(+), 38 deletions(-) diff --git a/includes/functions.php b/includes/functions.php index 0d9c2f97d..e8a8441f9 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -336,17 +336,17 @@ function devclass($device) function getImage($host) { -global $config; -$sql = "SELECT * FROM `devices` WHERE `device_id` = '$host'"; -$data = mysql_fetch_array(mysql_query($sql)); -$type = strtolower($data['os']); - if(file_exists($config['html_dir'] . "/images/os/$type" . ".png")){ $image = ""; - } elseif(file_exists($config['html_dir'] . "/images/os/$type" . ".gif")){ $image = ""; } + global $config; + $sql = "SELECT * FROM `devices` WHERE `device_id` = '$host'"; + $data = mysql_fetch_array(mysql_query($sql)); + $type = strtolower($data['os']); + if(file_exists($config['html_dir'] . "/images/os/$type" . ".png")){ $image = ''; + } elseif(file_exists($config['html_dir'] . "/images/os/$type" . ".gif")){ $image = ''; } if($type == "linux") { $features = strtolower(trim($data['features'])); list($distro) = split(" ", $features); - if(file_exists($config['html_dir'] . "/images/os/$distro" . ".png")){ $image = ""; - } elseif(file_exists($config['html_dir'] . "/images/os/$distro" . ".gif")){ $image = ""; } + if(file_exists($config['html_dir'] . "/images/os/$distro" . ".png")){ $image = ''; + } elseif(file_exists($config['html_dir'] . "/images/os/$distro" . ".gif")){ $image = ''; } } return $image; } @@ -464,27 +464,26 @@ function scanUDP ($host, $port, $timeout) function humanmedia($media) { - array_preg_replace($rewrite_iftype, $media); - return $media; + array_preg_replace($rewrite_iftype, $media); + return $media; } function humanspeed($speed) { - $speed = formatRates($speed); - if($speed == "") { $speed = "-"; } - return $speed; + $speed = formatRates($speed); + if($speed == "") { $speed = "-"; } + return $speed; } function netmask2cidr($netmask) { - list ($network, $cidr) = explode("/", trim(`ipcalc $address/$mask | grep Network | cut -d" " -f 4`)); - return $cidr; + list ($network, $cidr) = explode("/", trim(`ipcalc $address/$mask | grep Network | cut -d" " -f 4`)); + return $cidr; } function cidr2netmask() { - return (long2ip(ip2long("255.255.255.255") - << (32-$netmask))); + return (long2ip(ip2long("255.255.255.255") << (32-$netmask))); } function formatUptime($diff, $format="long") @@ -522,11 +521,10 @@ function isSNMPable($hostname, $community, $snmpver, $port) global $config; $pos = shell_exec($config['snmpget'] ." -m SNMPv2-MIB -$snmpver -c $community -t 1 $hostname:$port sysDescr.0"); if($pos == '') { - $status='0'; + return false; } else { - $status='1'; + return true; } - return $status; } function isPingable($hostname) { @@ -563,18 +561,19 @@ function isValidInterface($if) { function ifclass($ifOperStatus, $ifAdminStatus) { - $ifclass = "interface-upup"; - if ($ifAdminStatus == "down") { $ifclass = "interface-admindown"; } - if ($ifAdminStatus == "up" && $ifOperStatus== "down") { $ifclass = "interface-updown"; } - if ($ifAdminStatus == "up" && $ifOperStatus== "up") { $ifclass = "interface-upup"; } - return $ifclass; + $ifclass = "interface-upup"; + if ($ifAdminStatus == "down") { $ifclass = "interface-admindown"; } + if ($ifAdminStatus == "up" && $ifOperStatus== "down") { $ifclass = "interface-updown"; } + if ($ifAdminStatus == "up" && $ifOperStatus== "up") { $ifclass = "interface-upup"; } + return $ifclass; } -function utime() { - $time = explode( " ", microtime()); - $usec = (double)$time[0]; - $sec = (double)$time[1]; - return $sec + $usec; +function utime() +{ + $time = explode( " ", microtime()); + $usec = (double)$time[0]; + $sec = (double)$time[1]; + return $sec + $usec; } function fixIOSFeatures($features) @@ -645,14 +644,16 @@ function createHost ($host, $community, $snmpver, $port = 161){ } } -function isDomainResolves($domain){ - return gethostbyname($domain) != $domain; +function isDomainResolves($domain) +{ + return gethostbyname($domain) != $domain; } -function hoststatus($id) { - $sql = mysql_query("SELECT `status` FROM `devices` WHERE `device_id` = '$id'"); - $result = @mysql_result($sql, 0); - return $result; +function hoststatus($id) +{ + $sql = mysql_query("SELECT `status` FROM `devices` WHERE `device_id` = '$id'"); + $result = @mysql_result($sql, 0); + return $result; } function match_network ($nets, $ip, $first=false) { @@ -761,5 +762,13 @@ function eventlog($eventtext,$device_id = "", $interface_id = "") $event_query .= ", " . ($interface_id ? $interface_id : "NULL") . ", NOW(), '" . mysql_escape_string($eventtext) . "')"; mysql_query($event_query); } + +function notify($device,$title,$message) +{ + global $config; + + if ($device['sysContact']) { $email = $device['sysContact']; } else { $email = $config['email_default']; } + mail($email, $title, $message, $config['email_headers']); +} ?> diff --git a/poll-device.php b/poll-device.php index fff2b4e5b..d5e665cc3 100755 --- a/poll-device.php +++ b/poll-device.php @@ -157,8 +157,7 @@ while ($device = mysql_fetch_array($device_query)) { if ($uptime) { if ( $uptime < $device['uptime'] ) { - if ($device['sysContact']) { $email = $device['sysContact']; } else { $email = $config['email_default']; } - mail($email, "Device Rebooted: " . $device['hostname'], "Device Rebooted : " . $device['hostname'] . " " . formatUptime($uptime) . " ago.", $config['email_headers']); + notify($device,"Device rebooted: " . $device['hostname'], "Device Rebooted : " . $device['hostname'] . " " . formatUptime($uptime) . " ago."); eventlog('Device rebooted', $device['device_id']); }