Fix Unifi processors (#12854)

Use HOST-RESOURCES-MIB, apparently Ubiquiti added partial HR-MIB support sometime.
Works better than the old load based value.
Also port os discovery to the new style
This commit is contained in:
Tony Murray
2021-05-11 18:28:58 -05:00
committed by GitHub
parent 729eccc81a
commit abfe62cb44
4 changed files with 8029 additions and 12 deletions

View File

@@ -24,6 +24,7 @@
namespace LibreNMS\OS;
use App\Models\Device;
use LibreNMS\Device\WirelessSensor;
use LibreNMS\Interfaces\Discovery\ProcessorDiscovery;
use LibreNMS\Interfaces\Discovery\Sensors\WirelessCcqDiscovery;
@@ -45,10 +46,37 @@ class Unifi extends OS implements
WirelessPowerDiscovery,
WirelessUtilizationDiscovery
{
use OS\Traits\FrogfootResources;
use OS\Traits\FrogfootResources {
OS\Traits\FrogfootResources::discoverProcessors as discoverFrogfootProcessors;
}
private $ccqDivisor = 10;
public function discoverOS(Device $device): void
{
// try the Unifi MIB first, then fall back to dot11manufacturer
if ($data = snmp_getnext_multi($this->getDeviceArray(), ['unifiApSystemModel', 'unifiApSystemVersion'], '-OQUs', 'UBNT-UniFi-MIB')) {
$device->hardware = $data['unifiApSystemModel'] ?? $device->hardware;
$device->version = $data['unifiApSystemVersion'] ?? $device->version;
} elseif ($data = snmp_getnext_multi($this->getDeviceArray(), ['dot11manufacturerProductName', 'dot11manufacturerProductVersion'], '-OQUs', 'IEEE802dot11-MIB')) {
$device->hardware = $data['dot11manufacturerProductName'] ?? $device->hardware;
if (preg_match('/(v[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/', $data['dot11manufacturerProductVersion'], $matches)) {
$device->version = $matches[1];
}
}
}
/**
* Discover processors.
* Returns an array of LibreNMS\Device\Processor objects that have been discovered
*
* @return array Processors
*/
public function discoverProcessors()
{
return $this->discoverHrProcessors() ?: $this->discoverFrogfootProcessors();
}
/**
* Returns an array of LibreNMS\Device\Sensor objects
*

View File

@@ -1,11 +0,0 @@
<?php
if ($data = snmp_getnext_multi($device, 'unifiApSystemModel unifiApSystemVersion', '-OQUs', 'UBNT-UniFi-MIB')) {
$hardware = $data['unifiApSystemModel'];
$version = $data['unifiApSystemVersion'];
} elseif ($data = snmp_getnext_multi($device, 'dot11manufacturerProductName dot11manufacturerProductVersion', '-OQUs', 'IEEE802dot11-MIB')) {
$hardware = $data['dot11manufacturerProductName'];
if (preg_match('/(v[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/', $data['dot11manufacturerProductVersion'], $matches)) {
$version = $matches[0];
}
}

6999
tests/data/unifi_nanohd.json Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff