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.
|
|
|
|
*/
|
|
|
|
|
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;
|
2017-02-23 22:45:50 +00:00
|
|
|
use LibreNMS\RRD\RrdDefinition;
|
2019-03-18 03:09:58 +01:00
|
|
|
use LibreNMS\Util\Time;
|
2017-02-23 22:45:50 +00:00
|
|
|
|
2021-02-12 02:04:45 +01:00
|
|
|
$snmpdata = snmp_get_multi_oid($device, ['sysUpTime.0', 'sysName.0', 'sysObjectID.0', 'sysDescr.0'], '-OQnUt', 'SNMPv2-MIB');
|
2015-12-16 20:56:58 +00:00
|
|
|
|
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']));
|
2018-01-07 05:00:47 +00:00
|
|
|
$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);
|
2015-12-16 20:56:58 +00:00
|
|
|
echo "Using UNIX Agent Uptime ($uptime)\n";
|
2017-05-22 11:55:52 -05:00
|
|
|
} else {
|
2018-12-16 07:42:50 -06:00
|
|
|
$uptime_data = snmp_get_multi($device, ['snmpEngineTime.0', 'hrSystemUptime.0'], '-OQnUst', 'HOST-RESOURCES-MIB:SNMP-FRAMEWORK-MIB');
|
2015-12-16 20:56:58 +00:00
|
|
|
|
2017-05-22 11:55:52 -05:00
|
|
|
$uptime = max(
|
2018-01-09 16:11:17 -06:00
|
|
|
round($poll_device['sysUptime'] / 100),
|
2019-06-23 00:29:12 -05:00
|
|
|
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)
|
2017-05-22 11:55:52 -05:00
|
|
|
);
|
|
|
|
d_echo("Uptime seconds: $uptime\n");
|
2015-12-16 20:56:58 +00:00
|
|
|
}
|
|
|
|
|
2019-06-23 00:29:12 -05:00
|
|
|
if ($uptime != 0 && Config::get("os.{$device['os']}.bad_uptime") !== true) {
|
2015-12-16 20:56:58 +00:00
|
|
|
if ($uptime < $device['uptime']) {
|
2019-03-18 03:09:58 +01:00
|
|
|
log_event('Device rebooted after ' . Time::formatInterval($device['uptime']) . " -> {$uptime}s", $device, 'reboot', 4, $device['uptime']);
|
2015-12-16 20:56:58 +00:00
|
|
|
}
|
|
|
|
|
2020-09-21 15:43:38 +02:00
|
|
|
$tags = [
|
2017-02-23 22:45:50 +00:00
|
|
|
'rrd_def' => RrdDefinition::make()->addDataset('uptime', 'GAUGE', 0),
|
2020-09-21 15:43:38 +02:00
|
|
|
];
|
2016-01-15 21:52:09 +10:00
|
|
|
data_update($device, 'uptime', $tags, $uptime);
|
2016-01-10 00:46:04 +00:00
|
|
|
|
2020-07-23 09:57:22 -05:00
|
|
|
$os->enableGraph('uptime');
|
2015-12-16 20:56:58 +00:00
|
|
|
|
2019-03-18 03:09:58 +01:00
|
|
|
echo 'Uptime: ' . Time::formatInterval($uptime) . PHP_EOL;
|
2015-12-16 20:56:58 +00:00
|
|
|
|
|
|
|
$update_array['uptime'] = $uptime;
|
2020-09-21 15:43:38 +02:00
|
|
|
$device['uptime'] = $uptime;
|
2015-12-16 20:56:58 +00:00
|
|
|
}//end if
|
|
|
|
|
|
|
|
// Save results of various polled values to the database
|
2021-02-12 02:04:45 +01:00
|
|
|
foreach (['sysObjectID', 'sysName', 'sysDescr'] as $elem) {
|
2017-02-10 20:42:46 +00:00
|
|
|
if ($poll_device[$elem] != $device[$elem]) {
|
2015-12-16 20:56:58 +00:00
|
|
|
$update_array[$elem] = $poll_device[$elem];
|
2020-09-21 15:43:38 +02:00
|
|
|
$device[$elem] = $poll_device[$elem];
|
2017-02-14 00:32:02 +02:00
|
|
|
log_event("$elem -> " . $poll_device[$elem], $device, 'system', 3);
|
2015-12-16 20:56:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-07 05:00:47 +00:00
|
|
|
unset($snmpdata, $uptime_data, $uptime, $tags, $poll_device);
|