Yaml support to translate sysObjectID to get hardware (#12187)

* Yaml support to translate sysObjectID to get hardware

* restore ironware behavior

* ...
This commit is contained in:
Tony Murray
2020-10-05 06:50:28 -05:00
committed by GitHub
parent f6e3397a80
commit 210be6266e
9 changed files with 27 additions and 15 deletions

View File

@@ -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);
}
}

View File

@@ -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

View File

@@ -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) {

View File

@@ -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')) {

View File

@@ -155,6 +155,7 @@ more complex collection is required.
- `<field>` specify an oid or list of oids to attempt to pull the data from, the first non-empty response will be used
- `<field>_regex` parse the value out of the returned oid data, must use a named group
- `<field>_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:

View File

@@ -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(?<version>.*) Compiled on/'
serial: FOUNDRY-SN-AGENT-MIB::snChasSerNum.0
# version: FOUNDRY-SN-AGENT-MIB::snAgBuildVer.0

View File

@@ -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:

View File

@@ -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:

View File

@@ -32,6 +32,9 @@
"version_regex": {
"type": "string"
},
"hardware_mib": {
"type": "string"
},
"hardware_regex": {
"type": "string"
},