From 5877e94093c32677e6af45e053e7bce4d049dd9e Mon Sep 17 00:00:00 2001 From: Adam Amstrong Date: Sun, 3 Jan 2010 09:45:19 +0000 Subject: [PATCH] sid3windr fixes! git-svn-id: http://www.observium.org/svn/observer/trunk@587 61d68cd4-352d-0410-923a-c4978735b2b8 --- includes/functions.php | 25 +++++++++++++++++++++-- includes/polling/hr-mib_processor.inc.php | 2 +- poll-device.php | 3 ++- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/includes/functions.php b/includes/functions.php index 676759c0d2..74be7f934c 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -684,7 +684,7 @@ function snmp2ipv6($ipv6_snmp) function ipv62snmp($ipv6) { $ipv6_ex = explode(':',Net_IPv6::uncompress($ipv6)); - for ($i = 0;$i < 8;$i++) { $ipv6_ex[$i] = zeropad_lineno($ipv6_ex[$i]); } + for ($i = 0;$i < 8;$i++) { $ipv6_ex[$i] = zeropad_lineno($ipv6_ex[$i],4); } $ipv6_ip = implode('',$ipv6_ex); for ($i = 0;$i < 16;$i+=2) $ipv6_split[] = hexdec(substr($ipv6_ip,$i,2)); return implode('.',$ipv6_split); @@ -724,5 +724,26 @@ function discover_process_ipv6($ifIndex,$ipv6_address,$ipv6_prefixlen,$ipv6_orig } } - +function duration($seconds, $max_periods = 6) +{ + $periods = array("year" => 31536000, "month" => 2419200, "week" => 604800, "day" => 86400, "hour" => 3600, "minute" => 60, "second" => 1); + $i = 1; + foreach ( $periods as $period => $period_seconds ) + { + $period_duration = floor($seconds / $period_seconds); + $seconds = $seconds % $period_seconds; + if ( $period_duration == 0 ) + { + continue; + } + $duration[] = "{$period_duration} {$period}" . ($period_duration > 1 ? 's' : ''); + $i++; + if ( $i > $max_periods ) + { + break; + } + } + return implode(' ', $duration); +} + ?> diff --git a/includes/polling/hr-mib_processor.inc.php b/includes/polling/hr-mib_processor.inc.php index 5e16c69b61..3f7811cae1 100755 --- a/includes/polling/hr-mib_processor.inc.php +++ b/includes/polling/hr-mib_processor.inc.php @@ -30,7 +30,7 @@ while ($hrDevice = mysql_fetch_array($query)) { RRA:AVERAGE:0.5:12:2400"); } - echo($this_hrDevice['hrProcessorLoad'] . "% "); + if ($debug) echo($this_hrDevice['hrProcessorLoad'] . "% "); rrdtool_update ($procrrd, "N:".$this_hrDevice['hrProcessorLoad']); diff --git a/poll-device.php b/poll-device.php index 5741fbadfa..9994fe3f9e 100755 --- a/poll-device.php +++ b/poll-device.php @@ -169,7 +169,8 @@ while ($device = mysql_fetch_array($device_query)) { 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'] . " at " . date('l dS F Y h:i:s A'), $config['email_headers']); + mail($email, "Device Rebooted: " . $device['hostname'], "Device Rebooted : " . $device['hostname'] . " " . duration($uptime) . " ago.", $config['email_headers']); + mysql_query("INSERT INTO eventlog (`host`, `interface`, `datetime`, `message`) VALUES ('" . $device['device_id'] . "', '', NOW(), 'Device rebooted')"); } $uptimerrd = $config['rrd_dir'] . "/" . $device['hostname'] . "/uptime.rrd";