From 210be6266ea4be25bfcebe6676c9abb1480e1ba9 Mon Sep 17 00:00:00 2001 From: Tony Murray Date: Mon, 5 Oct 2020 06:50:28 -0500 Subject: [PATCH] Yaml support to translate sysObjectID to get hardware (#12187) * Yaml support to translate sysObjectID to get hardware * restore ironware behavior * ... --- LibreNMS/OS/Ironware.php | 8 +++----- LibreNMS/OS/Mimosa.php | 8 -------- LibreNMS/OS/Traits/YamlOSDiscovery.php | 14 ++++++++++++++ LibreNMS/OS/Ucos.php | 3 +-- doc/Developing/os/Initial-Detection.md | 1 + includes/definitions/discovery/ironware.yaml | 1 + includes/definitions/discovery/mimosa.yaml | 1 + includes/definitions/discovery/ucos.yaml | 3 +++ misc/discovery_schema.json | 3 +++ 9 files changed, 27 insertions(+), 15 deletions(-) diff --git a/LibreNMS/OS/Ironware.php b/LibreNMS/OS/Ironware.php index 16cec4e457..fd42585ab4 100644 --- a/LibreNMS/OS/Ironware.php +++ b/LibreNMS/OS/Ironware.php @@ -33,10 +33,10 @@ class Ironware extends Foundry { parent::discoverOS($device); // yaml - $device->hardware = $this->getHardware(); + $this->rewriteHardware(); } - private function getHardware() + private function rewriteHardware() { $rewrite_ironware_hardware = [ 'snFIWGSwitch' => 'Stackable FastIron workgroup', @@ -461,8 +461,6 @@ class Ironware extends Foundry 'snFastIronStackICX7750Switch' => 'Brocade ICX 7750 Switch stack', ]; - $hardware = snmp_translate($this->getDevice()->sysObjectID, 'FOUNDRY-SN-ROOT-MIB', null, null, $this->getDeviceArray()); - - return array_str_replace($rewrite_ironware_hardware, $hardware); + $this->getDevice()->hardware = array_str_replace($rewrite_ironware_hardware, $this->getDevice()->hardware); } } diff --git a/LibreNMS/OS/Mimosa.php b/LibreNMS/OS/Mimosa.php index 7d92f0c9d3..fd438573a3 100644 --- a/LibreNMS/OS/Mimosa.php +++ b/LibreNMS/OS/Mimosa.php @@ -24,7 +24,6 @@ namespace LibreNMS\OS; -use App\Models\Device; use LibreNMS\Device\WirelessSensor; use LibreNMS\Interfaces\Discovery\Sensors\WirelessErrorRatioDiscovery; use LibreNMS\Interfaces\Discovery\Sensors\WirelessFrequencyDiscovery; @@ -42,13 +41,6 @@ class Mimosa extends OS implements WirelessRateDiscovery, WirelessSnrDiscovery { - public function discoverOS(Device $device): void - { - parent::discoverOS($device); // yaml - - $device->hardware = snmp_translate($device->sysObjectID, 'MIMOSA-NETWORKS-BASE-MIB', null, null, $this->getDeviceArray()); - } - /** * Discover wireless bit/packet error ratio. This is in percent. Type is error-ratio. * Returns an array of LibreNMS\Device\Sensor objects that have been discovered diff --git a/LibreNMS/OS/Traits/YamlOSDiscovery.php b/LibreNMS/OS/Traits/YamlOSDiscovery.php index 25bfb6f106..f37a740252 100644 --- a/LibreNMS/OS/Traits/YamlOSDiscovery.php +++ b/LibreNMS/OS/Traits/YamlOSDiscovery.php @@ -55,6 +55,10 @@ trait YamlOSDiscovery $this->parseRegex($os_yaml['sysDescr_regex'], $device->sysDescr); } + if (isset($os_yaml['hardware_mib'])) { + $this->translateSysObjectID($os_yaml['hardware_mib'], $os_yaml['hardware_regex'] ?? null); + } + $oids = Arr::only($os_yaml, $this->fields); $fetch_oids = array_unique(Arr::flatten($oids)); $numeric = $this->isNumeric($fetch_oids); @@ -118,6 +122,16 @@ trait YamlOSDiscovery }, $template)); } + private function translateSysObjectID($mib, $regex) + { + $device = $this->getDevice(); + $device->hardware = snmp_translate($device->sysObjectID, $mib, null, '-Os', $this->getDeviceArray()); + + if ($regex) { + $this->parseRegex($regex, $device->hardware); + } + } + private function isNumeric($oids) { foreach ($oids as $oid) { diff --git a/LibreNMS/OS/Ucos.php b/LibreNMS/OS/Ucos.php index ddf37b1852..056742ed28 100644 --- a/LibreNMS/OS/Ucos.php +++ b/LibreNMS/OS/Ucos.php @@ -32,8 +32,7 @@ class Ucos extends \LibreNMS\OS { public function discoverOS(Device $device): void { - $device->hardware = snmp_translate($device->sysObjectID, 'CISCO-PRODUCTS-MIB', null, null, $this->getDeviceArray()) ?: null; - $device->version = snmp_get($this->getDeviceArray(), 'SYSAPPL-MIB::sysApplInstallPkgVersion.1', '-Oqv') ?: null; + parent::discoverOS($device); // yaml $applist = snmp_walk($this->getDeviceArray(), 'SYSAPPL-MIB::sysApplInstallPkgProductName', '-OQv'); if (Str::contains($applist, 'Cisco Unified CCX Database')) { diff --git a/doc/Developing/os/Initial-Detection.md b/doc/Developing/os/Initial-Detection.md index a535de5981..a975bafd40 100644 --- a/doc/Developing/os/Initial-Detection.md +++ b/doc/Developing/os/Initial-Detection.md @@ -155,6 +155,7 @@ more complex collection is required. - `` specify an oid or list of oids to attempt to pull the data from, the first non-empty response will be used - `_regex` parse the value out of the returned oid data, must use a named group - `_template` combine multiple oid results together to create a final string value. The result is trimmed. +- `hardware_mib` MIB used to translate sysObjectID to get hardware. hardware_regex can process the result. ```yaml modules: diff --git a/includes/definitions/discovery/ironware.yaml b/includes/definitions/discovery/ironware.yaml index d51da00368..9fd0cdbbfe 100644 --- a/includes/definitions/discovery/ironware.yaml +++ b/includes/definitions/discovery/ironware.yaml @@ -1,6 +1,7 @@ mib: FOUNDRY-SN-AGENT-MIB:FOUNDRY-SN-SWITCH-GROUP-MIB:FOUNDRY-SN-STACKING-MIB modules: os: + hardware_mib: FOUNDRY-SN-ROOT-MIB sysDescr_regex: '/IronWare Version V(?.*) Compiled on/' serial: FOUNDRY-SN-AGENT-MIB::snChasSerNum.0 # version: FOUNDRY-SN-AGENT-MIB::snAgBuildVer.0 diff --git a/includes/definitions/discovery/mimosa.yaml b/includes/definitions/discovery/mimosa.yaml index bafe7126de..f7bac046e6 100644 --- a/includes/definitions/discovery/mimosa.yaml +++ b/includes/definitions/discovery/mimosa.yaml @@ -1,6 +1,7 @@ mib: MIMOSA-NETWORKS-BFIVE-MIB modules: os: + hardware_mib: MIMOSA-NETWORKS-BASE-MIB serial: MIMOSA-NETWORKS-BFIVE-MIB::mimosaSerialNumber.0 version: MIMOSA-NETWORKS-BFIVE-MIB::mimosaFirmwareVersion.0 sensors: diff --git a/includes/definitions/discovery/ucos.yaml b/includes/definitions/discovery/ucos.yaml index 246ee7477a..20756a6993 100644 --- a/includes/definitions/discovery/ucos.yaml +++ b/includes/definitions/discovery/ucos.yaml @@ -1,5 +1,8 @@ mib: CISCO-UNIFIED-COMPUTING-EQUIPMENT-MIB modules: + os: + hardware_mib: CISCO-PRODUCTS-MIB + version: SYSAPPL-MIB::sysApplInstallPkgVersion.1 sensors: pre-cache: data: diff --git a/misc/discovery_schema.json b/misc/discovery_schema.json index fca3bd8df5..fc9110d79f 100644 --- a/misc/discovery_schema.json +++ b/misc/discovery_schema.json @@ -32,6 +32,9 @@ "version_regex": { "type": "string" }, + "hardware_mib": { + "type": "string" + }, "hardware_regex": { "type": "string" },