Implement OS specific information discovery (#11446)
* Implement OS specific information discovery
That way it doesn't have to be fetched during polling
Also improve discovery process, os is only detected once, in the core module.
EXA is the test os, a couple improvements there.
* Use local variable, then unset it so we don't pollute.
* fix style issues
* test and other fixes
* attribute update fixes
* Update exa data, need new source data
* null missing "os" values
* fix ftos odd character
* fix ftos odd character
* only null for new style or we will reset to null every discovery
* Move device observer to own class
* Handle location, relocate event logging
* update exa e7-2 data
* update ird test data, apparently unicode is now working.
* update Linux ntc, now uses correct icon
* Only load all os on the web, also, we can't load existing the the database isn't connected.
* only for devices that have a location
* revert ftos test data apparently
* revert ird
2020-05-14 11:27:59 -05:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* OS.php
|
|
|
|
*
|
|
|
|
* -Description-
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2021-02-09 00:29:04 +01:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
Implement OS specific information discovery (#11446)
* Implement OS specific information discovery
That way it doesn't have to be fetched during polling
Also improve discovery process, os is only detected once, in the core module.
EXA is the test os, a couple improvements there.
* Use local variable, then unset it so we don't pollute.
* fix style issues
* test and other fixes
* attribute update fixes
* Update exa data, need new source data
* null missing "os" values
* fix ftos odd character
* fix ftos odd character
* only null for new style or we will reset to null every discovery
* Move device observer to own class
* Handle location, relocate event logging
* update exa e7-2 data
* update ird test data, apparently unicode is now working.
* update Linux ntc, now uses correct icon
* Only load all os on the web, also, we can't load existing the the database isn't connected.
* only for devices that have a location
* revert ftos test data apparently
* revert ird
2020-05-14 11:27:59 -05:00
|
|
|
*
|
2021-02-09 00:29:04 +01:00
|
|
|
* @link https://www.librenms.org
|
2021-09-10 20:09:53 +02:00
|
|
|
*
|
Implement OS specific information discovery (#11446)
* Implement OS specific information discovery
That way it doesn't have to be fetched during polling
Also improve discovery process, os is only detected once, in the core module.
EXA is the test os, a couple improvements there.
* Use local variable, then unset it so we don't pollute.
* fix style issues
* test and other fixes
* attribute update fixes
* Update exa data, need new source data
* null missing "os" values
* fix ftos odd character
* fix ftos odd character
* only null for new style or we will reset to null every discovery
* Move device observer to own class
* Handle location, relocate event logging
* update exa e7-2 data
* update ird test data, apparently unicode is now working.
* update Linux ntc, now uses correct icon
* Only load all os on the web, also, we can't load existing the the database isn't connected.
* only for devices that have a location
* revert ftos test data apparently
* revert ird
2020-05-14 11:27:59 -05:00
|
|
|
* @copyright 2020 Tony Murray
|
|
|
|
* @author Tony Murray <murraytony@gmail.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace LibreNMS\Modules;
|
|
|
|
|
2021-02-14 20:36:55 -06:00
|
|
|
use App\Models\Location;
|
Implement OS specific information discovery (#11446)
* Implement OS specific information discovery
That way it doesn't have to be fetched during polling
Also improve discovery process, os is only detected once, in the core module.
EXA is the test os, a couple improvements there.
* Use local variable, then unset it so we don't pollute.
* fix style issues
* test and other fixes
* attribute update fixes
* Update exa data, need new source data
* null missing "os" values
* fix ftos odd character
* fix ftos odd character
* only null for new style or we will reset to null every discovery
* Move device observer to own class
* Handle location, relocate event logging
* update exa e7-2 data
* update ird test data, apparently unicode is now working.
* update Linux ntc, now uses correct icon
* Only load all os on the web, also, we can't load existing the the database isn't connected.
* only for devices that have a location
* revert ftos test data apparently
* revert ird
2020-05-14 11:27:59 -05:00
|
|
|
use LibreNMS\Interfaces\Module;
|
|
|
|
use LibreNMS\Interfaces\Polling\OSPolling;
|
|
|
|
use LibreNMS\Util\Url;
|
|
|
|
|
2021-11-17 19:23:55 -06:00
|
|
|
class Os implements Module
|
Implement OS specific information discovery (#11446)
* Implement OS specific information discovery
That way it doesn't have to be fetched during polling
Also improve discovery process, os is only detected once, in the core module.
EXA is the test os, a couple improvements there.
* Use local variable, then unset it so we don't pollute.
* fix style issues
* test and other fixes
* attribute update fixes
* Update exa data, need new source data
* null missing "os" values
* fix ftos odd character
* fix ftos odd character
* only null for new style or we will reset to null every discovery
* Move device observer to own class
* Handle location, relocate event logging
* update exa e7-2 data
* update ird test data, apparently unicode is now working.
* update Linux ntc, now uses correct icon
* Only load all os on the web, also, we can't load existing the the database isn't connected.
* only for devices that have a location
* revert ftos test data apparently
* revert ird
2020-05-14 11:27:59 -05:00
|
|
|
{
|
2021-11-17 19:23:55 -06:00
|
|
|
public function discover(\LibreNMS\OS $os): void
|
Implement OS specific information discovery (#11446)
* Implement OS specific information discovery
That way it doesn't have to be fetched during polling
Also improve discovery process, os is only detected once, in the core module.
EXA is the test os, a couple improvements there.
* Use local variable, then unset it so we don't pollute.
* fix style issues
* test and other fixes
* attribute update fixes
* Update exa data, need new source data
* null missing "os" values
* fix ftos odd character
* fix ftos odd character
* only null for new style or we will reset to null every discovery
* Move device observer to own class
* Handle location, relocate event logging
* update exa e7-2 data
* update ird test data, apparently unicode is now working.
* update Linux ntc, now uses correct icon
* Only load all os on the web, also, we can't load existing the the database isn't connected.
* only for devices that have a location
* revert ftos test data apparently
* revert ird
2020-05-14 11:27:59 -05:00
|
|
|
{
|
2020-09-18 08:12:07 -05:00
|
|
|
$this->updateLocation($os);
|
2021-02-12 02:04:45 +01:00
|
|
|
$this->sysContact($os);
|
2021-02-14 20:36:55 -06:00
|
|
|
|
|
|
|
// null out values in case they aren't filled.
|
|
|
|
$os->getDevice()->fill([
|
|
|
|
'hardware' => null,
|
|
|
|
'version' => null,
|
|
|
|
'features' => null,
|
|
|
|
'serial' => null,
|
|
|
|
'icon' => null,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$os->discoverOS($os->getDevice());
|
Implement OS specific information discovery (#11446)
* Implement OS specific information discovery
That way it doesn't have to be fetched during polling
Also improve discovery process, os is only detected once, in the core module.
EXA is the test os, a couple improvements there.
* Use local variable, then unset it so we don't pollute.
* fix style issues
* test and other fixes
* attribute update fixes
* Update exa data, need new source data
* null missing "os" values
* fix ftos odd character
* fix ftos odd character
* only null for new style or we will reset to null every discovery
* Move device observer to own class
* Handle location, relocate event logging
* update exa e7-2 data
* update ird test data, apparently unicode is now working.
* update Linux ntc, now uses correct icon
* Only load all os on the web, also, we can't load existing the the database isn't connected.
* only for devices that have a location
* revert ftos test data apparently
* revert ird
2020-05-14 11:27:59 -05:00
|
|
|
$this->handleChanges($os);
|
|
|
|
}
|
|
|
|
|
2021-11-17 19:23:55 -06:00
|
|
|
public function poll(\LibreNMS\OS $os): void
|
Implement OS specific information discovery (#11446)
* Implement OS specific information discovery
That way it doesn't have to be fetched during polling
Also improve discovery process, os is only detected once, in the core module.
EXA is the test os, a couple improvements there.
* Use local variable, then unset it so we don't pollute.
* fix style issues
* test and other fixes
* attribute update fixes
* Update exa data, need new source data
* null missing "os" values
* fix ftos odd character
* fix ftos odd character
* only null for new style or we will reset to null every discovery
* Move device observer to own class
* Handle location, relocate event logging
* update exa e7-2 data
* update ird test data, apparently unicode is now working.
* update Linux ntc, now uses correct icon
* Only load all os on the web, also, we can't load existing the the database isn't connected.
* only for devices that have a location
* revert ftos test data apparently
* revert ird
2020-05-14 11:27:59 -05:00
|
|
|
{
|
2021-07-13 16:35:43 -05:00
|
|
|
$deviceModel = $os->getDevice(); /** @var \App\Models\Device $deviceModel */
|
Implement OS specific information discovery (#11446)
* Implement OS specific information discovery
That way it doesn't have to be fetched during polling
Also improve discovery process, os is only detected once, in the core module.
EXA is the test os, a couple improvements there.
* Use local variable, then unset it so we don't pollute.
* fix style issues
* test and other fixes
* attribute update fixes
* Update exa data, need new source data
* null missing "os" values
* fix ftos odd character
* fix ftos odd character
* only null for new style or we will reset to null every discovery
* Move device observer to own class
* Handle location, relocate event logging
* update exa e7-2 data
* update ird test data, apparently unicode is now working.
* update Linux ntc, now uses correct icon
* Only load all os on the web, also, we can't load existing the the database isn't connected.
* only for devices that have a location
* revert ftos test data apparently
* revert ird
2020-05-14 11:27:59 -05:00
|
|
|
if ($os instanceof OSPolling) {
|
|
|
|
$os->pollOS();
|
|
|
|
} else {
|
|
|
|
// legacy poller files
|
2020-05-30 17:42:50 -05:00
|
|
|
global $graphs, $device;
|
2021-11-17 19:23:55 -06:00
|
|
|
|
|
|
|
if (empty($device)) {
|
|
|
|
$device = $os->getDeviceArray();
|
|
|
|
}
|
|
|
|
|
2021-07-13 16:35:43 -05:00
|
|
|
$location = null;
|
|
|
|
|
Implement OS specific information discovery (#11446)
* Implement OS specific information discovery
That way it doesn't have to be fetched during polling
Also improve discovery process, os is only detected once, in the core module.
EXA is the test os, a couple improvements there.
* Use local variable, then unset it so we don't pollute.
* fix style issues
* test and other fixes
* attribute update fixes
* Update exa data, need new source data
* null missing "os" values
* fix ftos odd character
* fix ftos odd character
* only null for new style or we will reset to null every discovery
* Move device observer to own class
* Handle location, relocate event logging
* update exa e7-2 data
* update ird test data, apparently unicode is now working.
* update Linux ntc, now uses correct icon
* Only load all os on the web, also, we can't load existing the the database isn't connected.
* only for devices that have a location
* revert ftos test data apparently
* revert ird
2020-05-14 11:27:59 -05:00
|
|
|
if (is_file(base_path('/includes/polling/os/' . $device['os'] . '.inc.php'))) {
|
|
|
|
// OS Specific
|
|
|
|
include base_path('/includes/polling/os/' . $device['os'] . '.inc.php');
|
2021-11-14 14:58:13 -06:00
|
|
|
} elseif (! empty($device['os_group']) && is_file(base_path('/includes/polling/os/' . $device['os_group'] . '.inc.php'))) {
|
Implement OS specific information discovery (#11446)
* Implement OS specific information discovery
That way it doesn't have to be fetched during polling
Also improve discovery process, os is only detected once, in the core module.
EXA is the test os, a couple improvements there.
* Use local variable, then unset it so we don't pollute.
* fix style issues
* test and other fixes
* attribute update fixes
* Update exa data, need new source data
* null missing "os" values
* fix ftos odd character
* fix ftos odd character
* only null for new style or we will reset to null every discovery
* Move device observer to own class
* Handle location, relocate event logging
* update exa e7-2 data
* update ird test data, apparently unicode is now working.
* update Linux ntc, now uses correct icon
* Only load all os on the web, also, we can't load existing the the database isn't connected.
* only for devices that have a location
* revert ftos test data apparently
* revert ird
2020-05-14 11:27:59 -05:00
|
|
|
// OS Group Specific
|
|
|
|
include base_path('/includes/polling/os/' . $device['os_group'] . '.inc.php');
|
|
|
|
} else {
|
|
|
|
echo "Generic :(\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
// handle legacy variables, sometimes they are false
|
|
|
|
$deviceModel->version = ($version ?? $deviceModel->version) ?: null;
|
|
|
|
$deviceModel->hardware = ($hardware ?? $deviceModel->hardware) ?: null;
|
|
|
|
$deviceModel->features = ($features ?? $deviceModel->features) ?: null;
|
|
|
|
$deviceModel->serial = ($serial ?? $deviceModel->serial) ?: null;
|
2021-03-31 17:29:22 +02:00
|
|
|
|
2021-02-22 11:17:40 +01:00
|
|
|
if (! empty($location)) { // legacy support, remove when no longer needed
|
|
|
|
$deviceModel->setLocation($location);
|
|
|
|
optional($deviceModel->location)->save();
|
2020-09-18 08:12:07 -05:00
|
|
|
}
|
Implement OS specific information discovery (#11446)
* Implement OS specific information discovery
That way it doesn't have to be fetched during polling
Also improve discovery process, os is only detected once, in the core module.
EXA is the test os, a couple improvements there.
* Use local variable, then unset it so we don't pollute.
* fix style issues
* test and other fixes
* attribute update fixes
* Update exa data, need new source data
* null missing "os" values
* fix ftos odd character
* fix ftos odd character
* only null for new style or we will reset to null every discovery
* Move device observer to own class
* Handle location, relocate event logging
* update exa e7-2 data
* update ird test data, apparently unicode is now working.
* update Linux ntc, now uses correct icon
* Only load all os on the web, also, we can't load existing the the database isn't connected.
* only for devices that have a location
* revert ftos test data apparently
* revert ird
2020-05-14 11:27:59 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
$this->handleChanges($os);
|
|
|
|
}
|
|
|
|
|
2021-11-17 19:23:55 -06:00
|
|
|
public function cleanup(\LibreNMS\OS $os): void
|
Implement OS specific information discovery (#11446)
* Implement OS specific information discovery
That way it doesn't have to be fetched during polling
Also improve discovery process, os is only detected once, in the core module.
EXA is the test os, a couple improvements there.
* Use local variable, then unset it so we don't pollute.
* fix style issues
* test and other fixes
* attribute update fixes
* Update exa data, need new source data
* null missing "os" values
* fix ftos odd character
* fix ftos odd character
* only null for new style or we will reset to null every discovery
* Move device observer to own class
* Handle location, relocate event logging
* update exa e7-2 data
* update ird test data, apparently unicode is now working.
* update Linux ntc, now uses correct icon
* Only load all os on the web, also, we can't load existing the the database isn't connected.
* only for devices that have a location
* revert ftos test data apparently
* revert ird
2020-05-14 11:27:59 -05:00
|
|
|
{
|
|
|
|
// no cleanup needed?
|
|
|
|
}
|
|
|
|
|
2021-11-17 19:23:55 -06:00
|
|
|
private function handleChanges(\LibreNMS\OS $os): void
|
Implement OS specific information discovery (#11446)
* Implement OS specific information discovery
That way it doesn't have to be fetched during polling
Also improve discovery process, os is only detected once, in the core module.
EXA is the test os, a couple improvements there.
* Use local variable, then unset it so we don't pollute.
* fix style issues
* test and other fixes
* attribute update fixes
* Update exa data, need new source data
* null missing "os" values
* fix ftos odd character
* fix ftos odd character
* only null for new style or we will reset to null every discovery
* Move device observer to own class
* Handle location, relocate event logging
* update exa e7-2 data
* update ird test data, apparently unicode is now working.
* update Linux ntc, now uses correct icon
* Only load all os on the web, also, we can't load existing the the database isn't connected.
* only for devices that have a location
* revert ftos test data apparently
* revert ird
2020-05-14 11:27:59 -05:00
|
|
|
{
|
2020-09-18 08:12:07 -05:00
|
|
|
$device = $os->getDevice();
|
Implement OS specific information discovery (#11446)
* Implement OS specific information discovery
That way it doesn't have to be fetched during polling
Also improve discovery process, os is only detected once, in the core module.
EXA is the test os, a couple improvements there.
* Use local variable, then unset it so we don't pollute.
* fix style issues
* test and other fixes
* attribute update fixes
* Update exa data, need new source data
* null missing "os" values
* fix ftos odd character
* fix ftos odd character
* only null for new style or we will reset to null every discovery
* Move device observer to own class
* Handle location, relocate event logging
* update exa e7-2 data
* update ird test data, apparently unicode is now working.
* update Linux ntc, now uses correct icon
* Only load all os on the web, also, we can't load existing the the database isn't connected.
* only for devices that have a location
* revert ftos test data apparently
* revert ird
2020-05-14 11:27:59 -05:00
|
|
|
|
|
|
|
$device->icon = basename(Url::findOsImage($device->os, $device->features, null, 'images/os/'));
|
|
|
|
|
2021-02-14 20:36:55 -06:00
|
|
|
echo trans('device.attributes.location') . ': ' . optional($device->location)->display() . PHP_EOL;
|
Implement OS specific information discovery (#11446)
* Implement OS specific information discovery
That way it doesn't have to be fetched during polling
Also improve discovery process, os is only detected once, in the core module.
EXA is the test os, a couple improvements there.
* Use local variable, then unset it so we don't pollute.
* fix style issues
* test and other fixes
* attribute update fixes
* Update exa data, need new source data
* null missing "os" values
* fix ftos odd character
* fix ftos odd character
* only null for new style or we will reset to null every discovery
* Move device observer to own class
* Handle location, relocate event logging
* update exa e7-2 data
* update ird test data, apparently unicode is now working.
* update Linux ntc, now uses correct icon
* Only load all os on the web, also, we can't load existing the the database isn't connected.
* only for devices that have a location
* revert ftos test data apparently
* revert ird
2020-05-14 11:27:59 -05:00
|
|
|
foreach (['hardware', 'version', 'features', 'serial'] as $attribute) {
|
|
|
|
echo \App\Observers\DeviceObserver::attributeChangedMessage($attribute, $device->$attribute, $device->getOriginal($attribute)) . PHP_EOL;
|
|
|
|
}
|
|
|
|
|
|
|
|
$device->save();
|
|
|
|
}
|
|
|
|
|
2021-11-17 19:23:55 -06:00
|
|
|
private function updateLocation(\LibreNMS\OS $os): void
|
Implement OS specific information discovery (#11446)
* Implement OS specific information discovery
That way it doesn't have to be fetched during polling
Also improve discovery process, os is only detected once, in the core module.
EXA is the test os, a couple improvements there.
* Use local variable, then unset it so we don't pollute.
* fix style issues
* test and other fixes
* attribute update fixes
* Update exa data, need new source data
* null missing "os" values
* fix ftos odd character
* fix ftos odd character
* only null for new style or we will reset to null every discovery
* Move device observer to own class
* Handle location, relocate event logging
* update exa e7-2 data
* update ird test data, apparently unicode is now working.
* update Linux ntc, now uses correct icon
* Only load all os on the web, also, we can't load existing the the database isn't connected.
* only for devices that have a location
* revert ftos test data apparently
* revert ird
2020-05-14 11:27:59 -05:00
|
|
|
{
|
2020-09-18 08:12:07 -05:00
|
|
|
$device = $os->getDevice();
|
2021-02-22 11:17:40 +01:00
|
|
|
$new_location = $device->override_sysLocation ? new Location() : $os->fetchLocation(); // fetch location data from device
|
|
|
|
$device->setLocation($new_location, true); // set location and lookup coordinates if needed
|
2021-02-14 20:36:55 -06:00
|
|
|
optional($device->location)->save();
|
Implement OS specific information discovery (#11446)
* Implement OS specific information discovery
That way it doesn't have to be fetched during polling
Also improve discovery process, os is only detected once, in the core module.
EXA is the test os, a couple improvements there.
* Use local variable, then unset it so we don't pollute.
* fix style issues
* test and other fixes
* attribute update fixes
* Update exa data, need new source data
* null missing "os" values
* fix ftos odd character
* fix ftos odd character
* only null for new style or we will reset to null every discovery
* Move device observer to own class
* Handle location, relocate event logging
* update exa e7-2 data
* update ird test data, apparently unicode is now working.
* update Linux ntc, now uses correct icon
* Only load all os on the web, also, we can't load existing the the database isn't connected.
* only for devices that have a location
* revert ftos test data apparently
* revert ird
2020-05-14 11:27:59 -05:00
|
|
|
}
|
2021-02-12 02:04:45 +01:00
|
|
|
|
2021-11-17 19:23:55 -06:00
|
|
|
private function sysContact(\LibreNMS\OS $os): void
|
2021-02-12 02:04:45 +01:00
|
|
|
{
|
|
|
|
$device = $os->getDevice();
|
|
|
|
$device->sysContact = snmp_get($os->getDeviceArray(), 'sysContact.0', '-Ovq', 'SNMPv2-MIB');
|
2021-04-08 15:14:49 +02:00
|
|
|
$device->sysContact = str_replace(['', '"', '\n', 'not set'], '', $device->sysContact);
|
2021-02-12 02:04:45 +01:00
|
|
|
if (empty($device->sysContact)) {
|
|
|
|
$device->sysContact = null;
|
|
|
|
}
|
|
|
|
}
|
Implement OS specific information discovery (#11446)
* Implement OS specific information discovery
That way it doesn't have to be fetched during polling
Also improve discovery process, os is only detected once, in the core module.
EXA is the test os, a couple improvements there.
* Use local variable, then unset it so we don't pollute.
* fix style issues
* test and other fixes
* attribute update fixes
* Update exa data, need new source data
* null missing "os" values
* fix ftos odd character
* fix ftos odd character
* only null for new style or we will reset to null every discovery
* Move device observer to own class
* Handle location, relocate event logging
* update exa e7-2 data
* update ird test data, apparently unicode is now working.
* update Linux ntc, now uses correct icon
* Only load all os on the web, also, we can't load existing the the database isn't connected.
* only for devices that have a location
* revert ftos test data apparently
* revert ird
2020-05-14 11:27:59 -05:00
|
|
|
}
|