| 
									
										
										
										
											2015-12-16 20:56:58 +00:00
										 |  |  | <?php | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* | 
					
						
							| 
									
										
										
										
											2016-09-08 14:12:23 +01:00
										 |  |  |  * LibreNMS Network Management and Monitoring System | 
					
						
							| 
									
										
										
										
											2015-12-16 20:56:58 +00:00
										 |  |  |  * 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); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-08 20:48:11 +03:00
										 |  |  | $snmpdata = snmp_get_multi($device, 'sysUpTime.0 sysLocation.0 sysContact.0 sysName.0 sysObjectID.0', '-OQnUst', 'SNMPv2-MIB:HOST-RESOURCES-MIB:SNMP-FRAMEWORK-MIB'); | 
					
						
							| 
									
										
										
										
											2015-12-16 20:56:58 +00:00
										 |  |  | $poll_device = $snmpdata[0]; | 
					
						
							| 
									
										
										
										
											2016-10-08 20:48:11 +03:00
										 |  |  | $poll_device['sysName'] = strtolower($poll_device['sysName']); | 
					
						
							| 
									
										
										
										
											2015-12-16 20:56:58 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-08 20:48:11 +03:00
										 |  |  | $poll_device['sysDescr'] = snmp_get($device, 'sysDescr.0', '-OvQ', 'SNMPv2-MIB:HOST-RESOURCES-MIB:SNMP-FRAMEWORK-MIB'); | 
					
						
							| 
									
										
										
										
											2016-03-22 16:14:56 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-16 20:56:58 +00:00
										 |  |  | if (!empty($agent_data['uptime'])) { | 
					
						
							|  |  |  |     list($uptime) = explode(' ', $agent_data['uptime']); | 
					
						
							| 
									
										
										
										
											2016-10-08 20:48:11 +03:00
										 |  |  |     $uptime = round($uptime); | 
					
						
							| 
									
										
										
										
											2015-12-16 20:56:58 +00:00
										 |  |  |     echo "Using UNIX Agent Uptime ($uptime)\n"; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if (empty($uptime)) { | 
					
						
							| 
									
										
										
										
											2016-02-16 23:46:31 -06:00
										 |  |  |     $snmp_data = snmp_get_multi($device, 'snmpEngineTime.0 hrSystemUptime.0', '-OQnUst', 'HOST-RESOURCES-MIB:SNMP-FRAMEWORK-MIB'); | 
					
						
							| 
									
										
										
										
											2016-01-16 20:02:42 +00:00
										 |  |  |     $uptime_data = $snmp_data[0]; | 
					
						
							| 
									
										
										
										
											2016-10-08 20:48:11 +03:00
										 |  |  |     $snmp_uptime = (integer)$uptime_data['snmpEngineTime']; | 
					
						
							| 
									
										
										
										
											2016-01-16 20:02:42 +00:00
										 |  |  |     $hrSystemUptime = $uptime_data['hrSystemUptime']; | 
					
						
							| 
									
										
										
										
											2015-12-16 20:56:58 +00:00
										 |  |  |     if (!empty($hrSystemUptime) && !strpos($hrSystemUptime, 'No') && ($device['os'] != 'windows')) { | 
					
						
							|  |  |  |         // Move uptime into agent_uptime
 | 
					
						
							| 
									
										
										
										
											2016-02-16 23:46:31 -06:00
										 |  |  |         $agent_uptime = $uptime; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $uptime = floor($hrSystemUptime / 100); | 
					
						
							| 
									
										
										
										
											2016-10-08 20:48:11 +03:00
										 |  |  |         echo 'Using hrSystemUptime (' . $uptime . "s)\n"; | 
					
						
							| 
									
										
										
										
											2016-08-28 12:32:58 -05:00
										 |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2016-02-16 23:46:31 -06:00
										 |  |  |         $uptime = floor($poll_device['sysUpTime'] / 100); | 
					
						
							| 
									
										
										
										
											2016-10-08 20:48:11 +03:00
										 |  |  |         echo 'Using SNMP Agent Uptime (' . $uptime . "s)\n  "; | 
					
						
							| 
									
										
										
										
											2015-12-16 20:56:58 +00:00
										 |  |  |     }//end if
 | 
					
						
							|  |  |  | }//end if
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-17 18:06:38 +03:00
										 |  |  | if ($device["os"] != "edgeswitch") { | 
					
						
							| 
									
										
										
										
											2016-09-17 03:49:39 +03:00
										 |  |  |     if ($snmp_uptime > $uptime && is_numeric($snmp_uptime)) { | 
					
						
							|  |  |  |         $uptime = $snmp_uptime; | 
					
						
							|  |  |  |         d_echo('hrSystemUptime or sysUpTime looks like to have rolled, using snmpEngineTime instead'); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-12-16 20:56:58 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-08 20:48:11 +03:00
										 |  |  | if (is_numeric($uptime) && ($config['os'][$device['os']]['bad_uptime'] !== true)) { | 
					
						
							| 
									
										
										
										
											2015-12-16 20:56:58 +00:00
										 |  |  |     if ($uptime < $device['uptime']) { | 
					
						
							| 
									
										
										
										
											2016-10-08 20:48:11 +03:00
										 |  |  |         log_event('Device rebooted after ' . formatUptime($device['uptime']), $device, 'reboot', $device['uptime']); | 
					
						
							| 
									
										
										
										
											2015-12-16 20:56:58 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-15 21:52:09 +10:00
										 |  |  |     $tags = array( | 
					
						
							|  |  |  |         'rrd_def' => 'DS:uptime:GAUGE:600:0:U', | 
					
						
							| 
									
										
										
										
											2015-12-16 20:56:58 +00:00
										 |  |  |     ); | 
					
						
							| 
									
										
										
										
											2016-01-15 21:52:09 +10:00
										 |  |  |     data_update($device, 'uptime', $tags, $uptime); | 
					
						
							| 
									
										
										
										
											2016-01-10 00:46:04 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-16 20:56:58 +00:00
										 |  |  |     $graphs['uptime'] = true; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-08 20:48:11 +03:00
										 |  |  |     echo 'Uptime: ' . formatUptime($uptime) . "\n"; | 
					
						
							| 
									
										
										
										
											2015-12-16 20:56:58 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     $update_array['uptime'] = $uptime; | 
					
						
							|  |  |  | }//end if
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | $poll_device['sysLocation'] = str_replace('"', '', $poll_device['sysLocation']); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Remove leading & trailing backslashes added by VyOS/Vyatta/EdgeOS
 | 
					
						
							|  |  |  | $poll_device['sysLocation'] = trim($poll_device['sysLocation'], '\\'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Rewrite sysLocation if there is a mapping array (database too?)
 | 
					
						
							| 
									
										
										
										
											2016-02-09 19:02:38 +00:00
										 |  |  | if (!empty($poll_device['sysLocation']) && (is_array($config['location_map']) || is_array($config['location_map_regex']))) { | 
					
						
							| 
									
										
										
										
											2015-12-16 20:56:58 +00:00
										 |  |  |     $poll_device['sysLocation'] = rewrite_location($poll_device['sysLocation']); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | $poll_device['sysContact'] = str_replace('"', '', $poll_device['sysContact']); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Remove leading & trailing backslashes added by VyOS/Vyatta/EdgeOS
 | 
					
						
							|  |  |  | $poll_device['sysContact'] = trim($poll_device['sysContact'], '\\'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | foreach (array('sysLocation', 'sysContact') as $elem) { | 
					
						
							|  |  |  |     if ($poll_device[$elem] == 'not set') { | 
					
						
							|  |  |  |         $poll_device[$elem] = ''; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Save results of various polled values to the database
 | 
					
						
							|  |  |  | foreach (array('sysContact', 'sysObjectID', 'sysName', 'sysDescr') as $elem) { | 
					
						
							|  |  |  |     if ($poll_device[$elem] && $poll_device[$elem] != $device[$elem]) { | 
					
						
							|  |  |  |         $update_array[$elem] = $poll_device[$elem]; | 
					
						
							| 
									
										
										
										
											2016-10-08 20:48:11 +03:00
										 |  |  |         log_event("$elem -> " . $poll_device[$elem], $device, 'system'); | 
					
						
							| 
									
										
										
										
											2015-12-16 20:56:58 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if ($poll_device['sysLocation'] && $device['location'] != $poll_device['sysLocation'] && $device['override_sysLocation'] == 0) { | 
					
						
							|  |  |  |     $update_array['location'] = $poll_device['sysLocation']; | 
					
						
							| 
									
										
										
										
											2016-10-08 20:48:11 +03:00
										 |  |  |     log_event('Location -> ' . $poll_device['sysLocation'], $device, 'system'); | 
					
						
							| 
									
										
										
										
											2015-12-16 20:56:58 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if ($config['geoloc']['latlng'] === true) { | 
					
						
							|  |  |  |     location_to_latlng($device); | 
					
						
							|  |  |  | } |