Files
librenms-librenms/includes/polling/core.inc.php

68 lines
2.5 KiB
PHP
Raw Normal View History

<?php
/*
* LibreNMS 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.
*/
Refactored and update Location Geocoding (#9359) - Fix location so it is a regular database relation (this allows multiple devices to be accurately linked to one location and saves api calls) - Parse coordinates from the location more consistently - Add settings to webui - ~~Used [PHP Geocoder](http://geocoder-php.org/), which has lots of backends and is well tested. (also includes reverse and geoip)~~ - Google Maps, Bing, Mapquest, and OpenStreetMap supported initially. - Default to OpenStreetMap, which doesn't require a key. They will liberally hand out bans if you exceed 1 query per second though. - All other Geocoding APIs require an API key. (Google requires a credit card on file, but seems to be the most accurate) - Update all (I think) sql queries to handle the new structure - Remove final vestiges of override_sysLocation as a device attribute - Update existing device groups and rules in DB - Tested all APIs with good/bad location, no/bad/good key, and no connection. - Cannot fix advanced queries that use location This blocks #8868 DO NOT DELETE THIS TEXT #### Please note > Please read this information carefully. You can run `./scripts/pre-commit.php` to check your code before submitting. - [x] Have you followed our [code guidelines?](http://docs.librenms.org/Developing/Code-Guidelines/) #### Testers If you would like to test this pull request then please run: `./scripts/github-apply <pr_id>`, i.e `./scripts/github-apply 5926` After you are done testing, you can remove the changes with `./scripts/github-remove`. If there are schema changes, you can ask on discord how to revert.
2018-11-28 16:49:18 -06:00
use LibreNMS\Config;
use LibreNMS\RRD\RrdDefinition;
use LibreNMS\Util\Time;
$snmpdata = snmp_get_multi_oid($device, ['sysUpTime.0', 'sysName.0', 'sysObjectID.0', 'sysDescr.0'], '-OQnUt', 'SNMPv2-MIB');
2020-09-21 15:43:38 +02:00
$poll_device['sysUptime'] = $snmpdata['.1.3.6.1.2.1.1.3.0'];
$poll_device['sysName'] = str_replace("\n", '', strtolower($snmpdata['.1.3.6.1.2.1.1.5.0']));
$poll_device['sysObjectID'] = $snmpdata['.1.3.6.1.2.1.1.2.0'];
2020-09-21 15:43:38 +02:00
$poll_device['sysDescr'] = str_replace(chr(218), "\n", $snmpdata['.1.3.6.1.2.1.1.1.0']);
2016-03-22 16:14:56 +00:00
2020-09-21 15:43:38 +02:00
if (! empty($agent_data['uptime'])) {
[$uptime] = explode(' ', $agent_data['uptime']);
2016-10-08 20:48:11 +03:00
$uptime = round($uptime);
echo "Using UNIX Agent Uptime ($uptime)\n";
} else {
$uptime_data = snmp_get_multi($device, ['snmpEngineTime.0', 'hrSystemUptime.0'], '-OQnUst', 'HOST-RESOURCES-MIB:SNMP-FRAMEWORK-MIB');
$uptime = max(
round($poll_device['sysUptime'] / 100),
Config::get("os.{$device['os']}.bad_snmpEngineTime") ? 0 : $uptime_data[0]['snmpEngineTime'],
Config::get("os.{$device['os']}.bad_hrSystemUptime") ? 0 : round($uptime_data[0]['hrSystemUptime'] / 100)
);
d_echo("Uptime seconds: $uptime\n");
}
if ($uptime != 0 && Config::get("os.{$device['os']}.bad_uptime") !== true) {
if ($uptime < $device['uptime']) {
log_event('Device rebooted after ' . Time::formatInterval($device['uptime']) . " -> {$uptime}s", $device, 'reboot', 4, $device['uptime']);
}
2020-09-21 15:43:38 +02:00
$tags = [
'rrd_def' => RrdDefinition::make()->addDataset('uptime', 'GAUGE', 0),
2020-09-21 15:43:38 +02:00
];
data_update($device, 'uptime', $tags, $uptime);
2016-01-10 00:46:04 +00:00
$os->enableGraph('uptime');
echo 'Uptime: ' . Time::formatInterval($uptime) . PHP_EOL;
$update_array['uptime'] = $uptime;
2020-09-21 15:43:38 +02:00
$device['uptime'] = $uptime;
}//end if
// Save results of various polled values to the database
foreach (['sysObjectID', 'sysName', 'sysDescr'] as $elem) {
if ($poll_device[$elem] != $device[$elem]) {
$update_array[$elem] = $poll_device[$elem];
2020-09-21 15:43:38 +02:00
$device[$elem] = $poll_device[$elem];
log_event("$elem -> " . $poll_device[$elem], $device, 'system', 3);
}
}
unset($snmpdata, $uptime_data, $uptime, $tags, $poll_device);