| 
									
										
										
										
											2011-05-03 21:17:04 +00:00
										 |  |  | <?php | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Observium Network Management and Monitoring System | 
					
						
							|  |  |  |  * Copyright (C) 2006-2011, Observium Developers - http://www.observium.org | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is free software: you can redistribute it and/or modify | 
					
						
							|  |  |  |  * it under the terms of the GNU General Public License as published by | 
					
						
							|  |  |  |  * the Free Software Foundation, either version 3 of the License, or | 
					
						
							|  |  |  |  * (at your option) any later version. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * See COPYING for more details. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   unset($poll_device); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   $snmpdata = snmp_get_multi($device, "sysUpTime.0 sysLocation.0 sysContact.0 sysName.0", "-OQUs", "SNMPv2-MIB"); | 
					
						
							| 
									
										
										
										
											2012-05-10 15:02:57 +00:00
										 |  |  |   $poll_device = $snmpdata[0]; | 
					
						
							| 
									
										
										
										
											2011-05-03 21:17:04 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   $poll_device['sysDescr'] = snmp_get($device, "sysDescr.0", "-Oqv", "SNMPv2-MIB"); | 
					
						
							| 
									
										
										
										
											2011-10-10 15:40:54 +00:00
										 |  |  |   $poll_device['sysObjectID'] = snmp_get($device, "sysObjectID.0", "-Oqvn", "SNMPv2-MIB"); | 
					
						
							| 
									
										
										
										
											2011-05-03 21:17:04 +00:00
										 |  |  |   $poll_device['sysName'] = strtolower($poll_device['sysName']); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-07 16:23:43 +00:00
										 |  |  |   if (!empty($agent_data['uptime'])) { list($uptime) = explode(" ", $agent_data['uptime']); $uptime = round($uptime); echo("Using UNIX Agent Uptime ($uptime)\n");} | 
					
						
							| 
									
										
										
										
											2011-05-03 21:17:04 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-03 11:43:29 +00:00
										 |  |  |   if (empty($uptime)) | 
					
						
							| 
									
										
										
										
											2011-05-03 21:17:04 +00:00
										 |  |  |   { | 
					
						
							| 
									
										
										
										
											2012-05-03 11:43:29 +00:00
										 |  |  |     $hrSystemUptime = snmp_get($device, "hrSystemUptime.0", "-Oqv", "HOST-RESOURCES-MIB"); | 
					
						
							|  |  |  |     if (!empty($hrSystemUptime) && !strpos($hrSystemUptime, "No") && ($device['os'] != "windows")) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       echo("Using hrSystemUptime (".$hrSystemUptime.")\n"); | 
					
						
							|  |  |  |       $agent_uptime = $uptime; ## Move uptime into agent_uptime
 | 
					
						
							|  |  |  |       #HOST-RESOURCES-MIB::hrSystemUptime.0 = Timeticks: (63050465) 7 days, 7:08:24.65
 | 
					
						
							|  |  |  |       $hrSystemUptime = str_replace("(", "", $hrSystemUptime); | 
					
						
							|  |  |  |       $hrSystemUptime = str_replace(")", "", $hrSystemUptime); | 
					
						
							|  |  |  |       list($days,$hours, $mins, $secs) = explode(":", $hrSystemUptime); | 
					
						
							|  |  |  |       list($secs, $microsecs) = explode(".", $secs); | 
					
						
							|  |  |  |       $hours = $hours + ($days * 24); | 
					
						
							|  |  |  |       $mins = $mins + ($hours * 60); | 
					
						
							|  |  |  |       $secs = $secs + ($mins * 60); | 
					
						
							|  |  |  |       $uptime = $secs; | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |       echo("Using SNMP Agent Uptime (".$poll_device['sysUpTime'].")\n"); | 
					
						
							|  |  |  |       #SNMPv2-MIB::sysUpTime.0 = Timeticks: (2542831) 7:03:48.31
 | 
					
						
							|  |  |  |       $poll_device['sysUpTime'] = str_replace("(", "", $poll_device['sysUpTime']); | 
					
						
							|  |  |  |       $poll_device['sysUpTime'] = str_replace(")", "", $poll_device['sysUpTime']); | 
					
						
							|  |  |  |       list($days, $hours, $mins, $secs) = explode(":", $poll_device['sysUpTime']); | 
					
						
							|  |  |  |       list($secs, $microsecs) = explode(".", $secs); | 
					
						
							|  |  |  |       $hours = $hours + ($days * 24); | 
					
						
							|  |  |  |       $mins = $mins + ($hours * 60); | 
					
						
							|  |  |  |       $secs = $secs + ($mins * 60); | 
					
						
							|  |  |  |       $uptime = $secs; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2011-05-03 21:17:04 +00:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-04 17:29:51 +00:00
										 |  |  |   // Use snmpEngineTime (68 year rollover) to cross-reference for false positives in device rebooting due to sysUpTime rollover issues
 | 
					
						
							|  |  |  |   $snmpEngineTime = (integer)snmp_get($device, "snmpEngineTime.0", "-OUqv", "SNMP-FRAMEWORK-MIB"); | 
					
						
							|  |  |  |   if (!is_numeric($snmpEngineTime)) { | 
					
						
							|  |  |  |     $snmpEngineTime = 0; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-03 21:46:25 +00:00
										 |  |  |   if (is_numeric($uptime)) | 
					
						
							| 
									
										
										
										
											2011-05-03 21:17:04 +00:00
										 |  |  |   { | 
					
						
							| 
									
										
										
										
											2012-02-04 17:29:51 +00:00
										 |  |  |     if ($uptime < $device['uptime'] && $uptime >= $snmpEngineTime) | 
					
						
							| 
									
										
										
										
											2011-05-03 21:17:04 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2011-05-03 21:46:25 +00:00
										 |  |  |       notify($device,"Device rebooted: " . $device['hostname'],  "Device Rebooted : " . $device['hostname'] . " " . formatUptime($uptime) . " ago."); | 
					
						
							| 
									
										
										
										
											2011-05-03 21:17:04 +00:00
										 |  |  |       log_event('Device rebooted after '.formatUptime($device['uptime']), $device, 'reboot', $device['uptime']); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $uptime_rrd = $config['rrd_dir'] . "/" . $device['hostname'] . "/uptime.rrd"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (!is_file($uptime_rrd)) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2012-04-20 17:37:58 +00:00
										 |  |  |       rrdtool_create ($uptime_rrd, "DS:uptime:GAUGE:600:0:U ".$config['rrd_rra']); | 
					
						
							| 
									
										
										
										
											2011-05-03 21:17:04 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2011-05-03 21:46:25 +00:00
										 |  |  |     rrdtool_update($uptime_rrd, "N:".$uptime); | 
					
						
							| 
									
										
										
										
											2011-05-03 21:17:04 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     $graphs['uptime'] = TRUE; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-03 21:46:25 +00:00
										 |  |  |     echo("Uptime: ".formatUptime($uptime)."\n"); | 
					
						
							| 
									
										
										
										
											2011-05-03 21:17:04 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-13 11:42:26 +00:00
										 |  |  |     $update_array['uptime'] = $uptime; | 
					
						
							| 
									
										
										
										
											2011-05-03 21:17:04 +00:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   $poll_device['sysLocation'] = str_replace("\"","", $poll_device['sysLocation']); | 
					
						
							|  |  |  |   $poll_device['sysContact']  = str_replace("\"","", $poll_device['sysContact']); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-13 12:28:57 +00:00
										 |  |  |   if ($poll_device['sysLocation'] == "not set") | 
					
						
							|  |  |  |   { | 
					
						
							|  |  |  |     $poll_device['sysLocation'] = ""; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if ($poll_device['sysContact'] == "not set") | 
					
						
							|  |  |  |   { | 
					
						
							|  |  |  |     $poll_device['sysContact'] = ""; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-03 21:17:04 +00:00
										 |  |  |   if ($poll_device['sysContact'] && $poll_device['sysContact'] != $device['sysContact']) | 
					
						
							|  |  |  |   { | 
					
						
							| 
									
										
										
										
											2011-05-13 11:42:26 +00:00
										 |  |  |     $update_array['sysContact'] = $poll_device['sysContact']; | 
					
						
							| 
									
										
										
										
											2011-05-03 21:17:04 +00:00
										 |  |  |     log_event("Contact -> ".$poll_device['sysContact'], $device, 'system'); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if ($poll_device['sysName'] && $poll_device['sysName'] != $device['sysName']) | 
					
						
							|  |  |  |   { | 
					
						
							| 
									
										
										
										
											2011-05-13 11:42:26 +00:00
										 |  |  |     $update_array['sysName'] = $poll_device['sysName']; | 
					
						
							| 
									
										
										
										
											2011-05-03 21:17:04 +00:00
										 |  |  |     log_event("sysName -> ".$poll_device['sysName'], $device, 'system'); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if ($poll_device['sysDescr'] && $poll_device['sysDescr'] != $device['sysDescr']) | 
					
						
							|  |  |  |   { | 
					
						
							| 
									
										
										
										
											2011-05-13 11:42:26 +00:00
										 |  |  |     $update_array['sysDescr'] = $poll_device['sysDescr']; | 
					
						
							| 
									
										
										
										
											2011-05-03 21:17:04 +00:00
										 |  |  |     log_event("sysDescr -> ".$poll_device['sysDescr'], $device, 'system'); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if ($poll_device['sysLocation'] && $device['location'] != $poll_device['sysLocation']) | 
					
						
							|  |  |  |   { | 
					
						
							|  |  |  |       if (!get_dev_attrib($device,'override_sysLocation_bool')) | 
					
						
							|  |  |  |       { | 
					
						
							| 
									
										
										
										
											2011-05-13 11:42:26 +00:00
										 |  |  |         $update_array['location'] = $poll_device['sysLocation']; | 
					
						
							|  |  |  |         log_event("Location -> ".$poll_device['sysLocation'], $device, 'system'); | 
					
						
							| 
									
										
										
										
											2011-05-03 21:17:04 +00:00
										 |  |  |       } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ?>
 |