mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
snmpwalk_cache_oid() handle multiline strings (#12254)
* snmpwalk_cache_oid handle multiline strings * remove useless function * some output has no space after equals * airos-af-ltu use hr processors * don't try to append with empty strings * fix changed test data due to fix * revert smartax * better regex additional check
This commit is contained in:
@@ -140,7 +140,7 @@ class XirrusAos extends OS implements
|
||||
private function discoverSensor($type, $oid, $oid_num_prefix)
|
||||
{
|
||||
$names = $this->getCacheByIndex('realtimeMonitorIfaceName', 'XIRRUS-MIB');
|
||||
$nf = snmp_cache_oid($oid, $this->getDeviceArray(), [], 'XIRRUS-MIB');
|
||||
$nf = snmpwalk_cache_oid($this->getDeviceArray(), $oid, [], 'XIRRUS-MIB');
|
||||
|
||||
$sensors = [];
|
||||
foreach ($nf as $index => $entry) {
|
||||
|
@@ -19,6 +19,19 @@ if ($device['os_group'] == 'printer') {
|
||||
|
||||
$raw_toner = $data['prtMarkerSuppliesLevel'];
|
||||
$descr = $data['prtMarkerSuppliesDescription'];
|
||||
|
||||
// work around weird HP bug where descriptions are on two lines and the second line is hex
|
||||
if (Str::contains($descr, "\n")) {
|
||||
$new_descr = '';
|
||||
foreach (explode("\n", $descr) as $line) {
|
||||
if (preg_match('/^([A-F\d]{2} )*[A-F\d]{1,2} ?$/', $line)) {
|
||||
$line = snmp_hexstring($line);
|
||||
}
|
||||
$new_descr .= $line;
|
||||
}
|
||||
$descr = $new_descr;
|
||||
}
|
||||
|
||||
$raw_capacity = $data['prtMarkerSuppliesMaxCapacity'];
|
||||
$raw_toner = $data['prtMarkerSuppliesLevel'];
|
||||
$toner_oid = ".1.3.6.1.2.1.43.11.1.1.9.$index";
|
||||
@@ -115,5 +128,5 @@ foreach ($toners as $test_toner) {
|
||||
}
|
||||
}
|
||||
|
||||
unset($valid_toner);
|
||||
unset($valid_toner, $line, $new_descr);
|
||||
echo PHP_EOL;
|
||||
|
@@ -467,6 +467,11 @@ function snmpwalk_cache_oid($device, $oid, $array, $mib = null, $mibdir = null,
|
||||
{
|
||||
$data = snmp_walk($device, $oid, $snmpflags, $mib, $mibdir);
|
||||
foreach (explode("\n", $data) as $entry) {
|
||||
if (! Str::contains($entry, ' =') && ! empty($entry) && isset($index, $oid)) {
|
||||
$array[$index][$oid] .= "\n$entry";
|
||||
continue;
|
||||
}
|
||||
|
||||
[$oid,$value] = explode('=', $entry, 2);
|
||||
$oid = trim($oid);
|
||||
$value = trim($value, "\" \\\n\r");
|
||||
@@ -719,13 +724,6 @@ function snmpwalk_cache_threepart_oid($device, $oid, $array, $mib = 0)
|
||||
return $array;
|
||||
}//end snmpwalk_cache_threepart_oid()
|
||||
|
||||
function snmp_cache_oid($oid, $device, $array, $mib = 0)
|
||||
{
|
||||
$array = snmpwalk_cache_oid($device, $oid, $array, $mib);
|
||||
|
||||
return $array;
|
||||
}//end snmp_cache_oid()
|
||||
|
||||
/**
|
||||
* generate snmp auth arguments
|
||||
* @param array $device
|
||||
|
@@ -408,45 +408,9 @@
|
||||
"processor_descr": "Cpu-1/0/1",
|
||||
"processor_precision": 100,
|
||||
"processor_perc_warn": 75
|
||||
},
|
||||
{
|
||||
"entPhysicalIndex": 0,
|
||||
"hrDeviceIndex": 0,
|
||||
"processor_oid": ".1.3.6.1.4.1.3807.1.8012.1.4.1.1.2.",
|
||||
"processor_index": "",
|
||||
"processor_type": "fiberhome-switch",
|
||||
"processor_usage": 0,
|
||||
"processor_descr": "cpuIndexDescr",
|
||||
"processor_precision": 100,
|
||||
"processor_perc_warn": 75
|
||||
}
|
||||
]
|
||||
},
|
||||
"poller": {
|
||||
"processors": [
|
||||
{
|
||||
"entPhysicalIndex": 0,
|
||||
"hrDeviceIndex": 0,
|
||||
"processor_oid": ".1.3.6.1.4.1.3807.1.8012.1.4.1.1.2.3222475008",
|
||||
"processor_index": "3222475008",
|
||||
"processor_type": "fiberhome-switch",
|
||||
"processor_usage": 0,
|
||||
"processor_descr": "Cpu-1/0/1",
|
||||
"processor_precision": 100,
|
||||
"processor_perc_warn": 75
|
||||
},
|
||||
{
|
||||
"entPhysicalIndex": 0,
|
||||
"hrDeviceIndex": 0,
|
||||
"processor_oid": ".1.3.6.1.4.1.3807.1.8012.1.4.1.1.2.",
|
||||
"processor_index": "",
|
||||
"processor_type": "fiberhome-switch",
|
||||
"processor_usage": 0,
|
||||
"processor_descr": "cpuIndexDescr",
|
||||
"processor_precision": 100,
|
||||
"processor_perc_warn": 75
|
||||
}
|
||||
]
|
||||
}
|
||||
"poller": "matches discovery"
|
||||
}
|
||||
}
|
||||
|
@@ -97,45 +97,9 @@
|
||||
"processor_descr": "Cpu-1",
|
||||
"processor_precision": 100,
|
||||
"processor_perc_warn": 75
|
||||
},
|
||||
{
|
||||
"entPhysicalIndex": 0,
|
||||
"hrDeviceIndex": 0,
|
||||
"processor_oid": ".1.3.6.1.4.1.3807.1.8012.1.4.1.1.2.",
|
||||
"processor_index": "",
|
||||
"processor_type": "fiberhome-switch",
|
||||
"processor_usage": 0,
|
||||
"processor_descr": "cpuIndexDescr",
|
||||
"processor_precision": 100,
|
||||
"processor_perc_warn": 75
|
||||
}
|
||||
]
|
||||
},
|
||||
"poller": {
|
||||
"processors": [
|
||||
{
|
||||
"entPhysicalIndex": 0,
|
||||
"hrDeviceIndex": 0,
|
||||
"processor_oid": ".1.3.6.1.4.1.3807.1.8012.1.4.1.1.2.1",
|
||||
"processor_index": "1",
|
||||
"processor_type": "fiberhome-switch",
|
||||
"processor_usage": 0,
|
||||
"processor_descr": "Cpu-1",
|
||||
"processor_precision": 100,
|
||||
"processor_perc_warn": 75
|
||||
},
|
||||
{
|
||||
"entPhysicalIndex": 0,
|
||||
"hrDeviceIndex": 0,
|
||||
"processor_oid": ".1.3.6.1.4.1.3807.1.8012.1.4.1.1.2.",
|
||||
"processor_index": "",
|
||||
"processor_type": "fiberhome-switch",
|
||||
"processor_usage": 0,
|
||||
"processor_descr": "cpuIndexDescr",
|
||||
"processor_precision": 100,
|
||||
"processor_perc_warn": 75
|
||||
}
|
||||
]
|
||||
}
|
||||
"poller": "matches discovery"
|
||||
}
|
||||
}
|
||||
|
@@ -651,7 +651,7 @@
|
||||
"toner_index": 1,
|
||||
"toner_type": "tonerCartridge",
|
||||
"toner_oid": ".1.3.6.1.2.1.43.11.1.1.9.1.1",
|
||||
"toner_descr": "Black Cartridge",
|
||||
"toner_descr": "Black Cartridge827A HP CF300A",
|
||||
"toner_capacity": 100,
|
||||
"toner_current": 92,
|
||||
"toner_capacity_oid": ".1.3.6.1.2.1.43.11.1.1.8.1.1"
|
||||
@@ -660,7 +660,7 @@
|
||||
"toner_index": 10,
|
||||
"toner_type": "fuser",
|
||||
"toner_oid": ".1.3.6.1.2.1.43.11.1.1.9.1.10",
|
||||
"toner_descr": "Fuser Kit HP 110",
|
||||
"toner_descr": "Fuser Kit HP 110V-C1N54A, 220V-C",
|
||||
"toner_capacity": 100,
|
||||
"toner_current": 84,
|
||||
"toner_capacity_oid": ".1.3.6.1.2.1.43.11.1.1.8.1.10"
|
||||
@@ -669,7 +669,7 @@
|
||||
"toner_index": 11,
|
||||
"toner_type": "other",
|
||||
"toner_oid": ".1.3.6.1.2.1.43.11.1.1.9.1.11",
|
||||
"toner_descr": "Document Feeder",
|
||||
"toner_descr": "Document FeederKit HP C1P70A",
|
||||
"toner_capacity": 100,
|
||||
"toner_current": 99,
|
||||
"toner_capacity_oid": ".1.3.6.1.2.1.43.11.1.1.8.1.11"
|
||||
@@ -678,7 +678,7 @@
|
||||
"toner_index": 12,
|
||||
"toner_type": "other",
|
||||
"toner_oid": ".1.3.6.1.2.1.43.11.1.1.9.1.12",
|
||||
"toner_descr": "Clean Rollers HP",
|
||||
"toner_descr": "Clean Rollers HP None",
|
||||
"toner_capacity": 100,
|
||||
"toner_current": 97,
|
||||
"toner_capacity_oid": ".1.3.6.1.2.1.43.11.1.1.8.1.12"
|
||||
@@ -687,7 +687,7 @@
|
||||
"toner_index": 13,
|
||||
"toner_type": "staples",
|
||||
"toner_oid": ".1.3.6.1.2.1.43.11.1.1.9.1.13",
|
||||
"toner_descr": "Stapler 1 HP C80",
|
||||
"toner_descr": "Stapler 1 HP C8091A",
|
||||
"toner_capacity": 100,
|
||||
"toner_current": 50,
|
||||
"toner_capacity_oid": ".1.3.6.1.2.1.43.11.1.1.8.1.13"
|
||||
@@ -696,7 +696,7 @@
|
||||
"toner_index": 14,
|
||||
"toner_type": "staples",
|
||||
"toner_oid": ".1.3.6.1.2.1.43.11.1.1.9.1.14",
|
||||
"toner_descr": "Stapler 2 HP CC3",
|
||||
"toner_descr": "Stapler 2 HP CC383A",
|
||||
"toner_capacity": 100,
|
||||
"toner_current": 50,
|
||||
"toner_capacity_oid": ".1.3.6.1.2.1.43.11.1.1.8.1.14"
|
||||
@@ -705,7 +705,7 @@
|
||||
"toner_index": 15,
|
||||
"toner_type": "staples",
|
||||
"toner_oid": ".1.3.6.1.2.1.43.11.1.1.9.1.15",
|
||||
"toner_descr": "Stapler 3 HP CC3",
|
||||
"toner_descr": "Stapler 3 HP CC383A",
|
||||
"toner_capacity": 100,
|
||||
"toner_current": 50,
|
||||
"toner_capacity_oid": ".1.3.6.1.2.1.43.11.1.1.8.1.15"
|
||||
@@ -714,7 +714,7 @@
|
||||
"toner_index": 2,
|
||||
"toner_type": "tonerCartridge",
|
||||
"toner_oid": ".1.3.6.1.2.1.43.11.1.1.9.1.2",
|
||||
"toner_descr": "Cyan Cartridge 8",
|
||||
"toner_descr": "Cyan Cartridge 827A HP CF301A",
|
||||
"toner_capacity": 100,
|
||||
"toner_current": 16,
|
||||
"toner_capacity_oid": ".1.3.6.1.2.1.43.11.1.1.8.1.2"
|
||||
@@ -723,7 +723,7 @@
|
||||
"toner_index": 3,
|
||||
"toner_type": "tonerCartridge",
|
||||
"toner_oid": ".1.3.6.1.2.1.43.11.1.1.9.1.3",
|
||||
"toner_descr": "Magenta Cartridg",
|
||||
"toner_descr": "Magenta Cartridge 827A HP CF303A",
|
||||
"toner_capacity": 100,
|
||||
"toner_current": 100,
|
||||
"toner_capacity_oid": ".1.3.6.1.2.1.43.11.1.1.8.1.3"
|
||||
@@ -732,7 +732,7 @@
|
||||
"toner_index": 4,
|
||||
"toner_type": "tonerCartridge",
|
||||
"toner_oid": ".1.3.6.1.2.1.43.11.1.1.9.1.4",
|
||||
"toner_descr": "Yellow Cartridge",
|
||||
"toner_descr": "Yellow Cartridge 827A HP CF302A",
|
||||
"toner_capacity": 100,
|
||||
"toner_current": 70,
|
||||
"toner_capacity_oid": ".1.3.6.1.2.1.43.11.1.1.8.1.4"
|
||||
@@ -741,7 +741,7 @@
|
||||
"toner_index": 5,
|
||||
"toner_type": "opc",
|
||||
"toner_oid": ".1.3.6.1.2.1.43.11.1.1.9.1.5",
|
||||
"toner_descr": "Black Drum 828A",
|
||||
"toner_descr": "Black Drum 828AHP CF358A",
|
||||
"toner_capacity": 100,
|
||||
"toner_current": 53,
|
||||
"toner_capacity_oid": ".1.3.6.1.2.1.43.11.1.1.8.1.5"
|
||||
@@ -750,7 +750,7 @@
|
||||
"toner_index": 6,
|
||||
"toner_type": "opc",
|
||||
"toner_oid": ".1.3.6.1.2.1.43.11.1.1.9.1.6",
|
||||
"toner_descr": "Cyan Drum 828A H",
|
||||
"toner_descr": "Cyan Drum 828A HP CF359A",
|
||||
"toner_capacity": 100,
|
||||
"toner_current": 58,
|
||||
"toner_capacity_oid": ".1.3.6.1.2.1.43.11.1.1.8.1.6"
|
||||
@@ -759,7 +759,7 @@
|
||||
"toner_index": 7,
|
||||
"toner_type": "opc",
|
||||
"toner_oid": ".1.3.6.1.2.1.43.11.1.1.9.1.7",
|
||||
"toner_descr": "Magenta Drum 828",
|
||||
"toner_descr": "Magenta Drum 828A HP CF365A",
|
||||
"toner_capacity": 100,
|
||||
"toner_current": 58,
|
||||
"toner_capacity_oid": ".1.3.6.1.2.1.43.11.1.1.8.1.7"
|
||||
@@ -768,7 +768,7 @@
|
||||
"toner_index": 8,
|
||||
"toner_type": "opc",
|
||||
"toner_oid": ".1.3.6.1.2.1.43.11.1.1.9.1.8",
|
||||
"toner_descr": "Yellow Drum 828A",
|
||||
"toner_descr": "Yellow Drum 828A HP CF364A",
|
||||
"toner_capacity": 100,
|
||||
"toner_current": 58,
|
||||
"toner_capacity_oid": ".1.3.6.1.2.1.43.11.1.1.8.1.8"
|
||||
@@ -777,7 +777,7 @@
|
||||
"toner_index": 9,
|
||||
"toner_type": "transferUnit",
|
||||
"toner_oid": ".1.3.6.1.2.1.43.11.1.1.9.1.9",
|
||||
"toner_descr": "Transfer Kit HP",
|
||||
"toner_descr": "Transfer Kit HPD7H14A",
|
||||
"toner_capacity": 100,
|
||||
"toner_current": 89,
|
||||
"toner_capacity_oid": ".1.3.6.1.2.1.43.11.1.1.8.1.9"
|
||||
@@ -817,15 +817,6 @@
|
||||
"toner_capacity": 2000,
|
||||
"toner_current": 20,
|
||||
"toner_capacity_oid": ".1.3.6.1.2.1.43.8.2.1.9.1.5"
|
||||
},
|
||||
{
|
||||
"toner_index": 0,
|
||||
"toner_type": "markerSupply",
|
||||
"toner_oid": ".1.3.6.1.4.1.367.3.2.1.2.24.1.1.5.",
|
||||
"toner_descr": "0",
|
||||
"toner_capacity": 100,
|
||||
"toner_current": 0,
|
||||
"toner_capacity_oid": ".1.3.6.1.2.1.43.11.1.1.8."
|
||||
}
|
||||
]
|
||||
},
|
||||
|
Reference in New Issue
Block a user