Fix an issue with the APC current discovery (#13837)

* Fix an issue with the APC current discovery

* Formatting fixes

* Formatting fixes

* Added test data for APC PDU sensors
This commit is contained in:
eskyuu
2022-03-14 05:55:08 +08:00
committed by GitHub
parent 85b19ce99e
commit c13975524c
3 changed files with 404 additions and 25 deletions

View File

@@ -2,9 +2,6 @@
// PDU - Phase
$oids = snmp_walk($device, 'rPDUStatusPhaseIndex', '-OsqnU', 'PowerNet-MIB');
if (empty($oids)) {
$oids = snmp_walk($device, 'rPDULoadPhaseConfigIndex', '-OsqnU', 'PowerNet-MIB');
}
if ($oids) {
d_echo($oids . "\n");
$oids = trim($oids);
@@ -47,10 +44,57 @@ if ($oids) {
}
}
unset($oids);
$oids = snmp_walk($device, 'rPDULoadStatusPhaseNumber', '-OsqnU', 'PowerNet-MIB');
if ($oids) {
d_echo($oids . "\n");
$oids = trim($oids);
if ($oids) {
echo 'APC PowerNet-MIB Phase ';
}
$type = 'apc';
$precision = '10';
foreach (explode("\n", $oids) as $data) {
$data = trim($data);
if ($data) {
[$oid,$phasenum] = explode(' ', $data);
// If the phasenum is 0, we can ignore becuase it's bank data
if ($phasenum == 0) {
continue;
}
$split_oid = explode('.', $oid);
$index = $split_oid[(count($split_oid) - 1)];
$current_oid = '.1.3.6.1.4.1.318.1.1.12.2.3.1.1.2.' . $index;
// rPDULoadStatusLoad
$phase_oid = '.1.3.6.1.4.1.318.1.1.12.2.3.1.1.4.' . $index;
// rPDULoadStatusPhaseNumber
$limit_oid = '.1.3.6.1.4.1.318.1.1.12.2.2.1.1.4.' . $phasenum;
// rPDULoadPhaseConfigOverloadThreshold
$lowlimit_oid = '.1.3.6.1.4.1.318.1.1.12.2.2.1.1.2.' . $phasenum;
// rPDULoadPhaseConfigLowLoadThreshold
$warnlimit_oid = '.1.3.6.1.4.1.318.1.1.12.2.2.1.1.3.' . $phasenum;
// rPDULoadPhaseConfigNearOverloadThreshold
$phase = snmp_get($device, $phase_oid, '-Oqv', '');
$current = (snmp_get($device, $current_oid, '-Oqv', '') / $precision);
$limit = snmp_get($device, $limit_oid, '-Oqv', '');
// No / $precision here! Nice, APC!
$lowlimit = snmp_get($device, $lowlimit_oid, '-Oqv', '');
// No / $precision here! Nice, APC!
$warnlimit = snmp_get($device, $warnlimit_oid, '-Oqv', '');
// No / $precision here! Nice, APC!
if (count(explode("\n", $oids)) != 1) {
$descr = "Phase $phase";
} else {
$descr = 'Output';
}
discover_sensor($valid['sensor'], 'current', $device, $current_oid, $index, $type, $descr, '10', '1', $lowlimit, null, $warnlimit, $limit, $current);
}
}
}
unset($oids);
// v2 firmware- first bank is total, v3 firmware, 3rd bank is total
$bank_count = snmp_get($device, 'rPDULoadDevNumBanks.0', '-Oqv', 'PowerNet-MIB');
if ($bank_count > 0) {
$oids = snmp_walk($device, 'rPDULoadStatusIndex', '-OsqnU', 'PowerNet-MIB');
$oids = snmp_walk($device, 'rPDULoadStatusBankNumber', '-OsqnU', 'PowerNet-MIB');
}
// should work with firmware v2 and v3
if ($oids) {
@@ -59,39 +103,26 @@ if ($oids) {
$oids = trim($oids);
$type = 'apc';
$precision = '10';
// version 2 does some stuff differently- total power is first oid in index instead of the last.
// will look something like "AOS v2.6.4 / App v2.6.5"
$baseversion = '3';
if (stristr($device['version'], 'AOS v2') == true) {
$baseversion = '2';
}
foreach (explode("\n", $oids) as $data) {
$data = trim($data);
if ($data) {
[$oid,$kind] = explode(' ', $data);
[$oid,$banknum] = explode(' ', $data);
// If the banknum is 0, we can ignore becuase it's phase data
if ($banknum == 0) {
continue;
}
$split_oid = explode('.', $oid);
$index = $split_oid[(count($split_oid) - 1)];
$banknum = ($index - 1);
$descr = 'Bank ' . $banknum;
if ($baseversion == '3') {
if ($index == '1') {
$descr = 'Bank Total';
}
}
if ($baseversion == '2') {
if ($index == '1') {
$descr = 'Bank Total';
}
}
$current_oid = '.1.3.6.1.4.1.318.1.1.12.2.3.1.1.2.' . $index;
// rPDULoadStatusLoad
$bank_oid = '.1.3.6.1.4.1.318.1.1.12.2.3.1.1.5.' . $index;
// rPDULoadStatusBankNumber
$limit_oid = '.1.3.6.1.4.1.318.1.1.12.2.4.1.1.4.' . $index;
$limit_oid = '.1.3.6.1.4.1.318.1.1.12.2.4.1.1.4.' . $banknum;
// rPDULoadBankConfigOverloadThreshold
$lowlimit_oid = '.1.3.6.1.4.1.318.1.1.12.2.4.1.1.2.' . $index;
$lowlimit_oid = '.1.3.6.1.4.1.318.1.1.12.2.4.1.1.2.' . $banknum;
// rPDULoadBankConfigLowLoadThreshold
$warnlimit_oid = '.1.3.6.1.4.1.318.1.1.12.2.4.1.1.3.' . $index;
$warnlimit_oid = '.1.3.6.1.4.1.318.1.1.12.2.4.1.1.3.' . $banknum;
// rPDULoadBankConfigNearOverloadThreshold
$bank = snmp_get($device, $bank_oid, '-Oqv', '');
$current = (snmp_get($device, $current_oid, '-Oqv', '') / $precision);

280
tests/data/apc_ap8853.json Normal file
View File

@@ -0,0 +1,280 @@
{
"sensors": {
"discovery": {
"sensors": [
{
"sensor_deleted": 0,
"sensor_class": "current",
"poller_type": "snmp",
"sensor_oid": ".1.3.6.1.4.1.318.1.1.12.2.3.1.1.2.1",
"sensor_index": "1",
"sensor_type": "apc",
"sensor_descr": "Phase 1",
"group": null,
"sensor_divisor": 10,
"sensor_multiplier": 1,
"sensor_current": 4.9,
"sensor_limit": 32,
"sensor_limit_warn": 26,
"sensor_limit_low": 0,
"sensor_limit_low_warn": null,
"sensor_alert": 1,
"sensor_custom": "No",
"entPhysicalIndex": null,
"entPhysicalIndex_measured": null,
"sensor_prev": null,
"user_func": null,
"state_name": null
},
{
"sensor_deleted": 0,
"sensor_class": "current",
"poller_type": "snmp",
"sensor_oid": ".1.3.6.1.4.1.318.1.1.12.2.3.1.1.2.2",
"sensor_index": "2",
"sensor_type": "apc",
"sensor_descr": "Bank 1",
"group": null,
"sensor_divisor": 10,
"sensor_multiplier": 1,
"sensor_current": 0,
"sensor_limit": 8,
"sensor_limit_warn": 6,
"sensor_limit_low": 0,
"sensor_limit_low_warn": null,
"sensor_alert": 1,
"sensor_custom": "No",
"entPhysicalIndex": null,
"entPhysicalIndex_measured": null,
"sensor_prev": null,
"user_func": null,
"state_name": null
},
{
"sensor_deleted": 0,
"sensor_class": "current",
"poller_type": "snmp",
"sensor_oid": ".1.3.6.1.4.1.318.1.1.12.2.3.1.1.2.3",
"sensor_index": "3",
"sensor_type": "apc",
"sensor_descr": "Bank 2",
"group": null,
"sensor_divisor": 10,
"sensor_multiplier": 1,
"sensor_current": 4.7,
"sensor_limit": 8,
"sensor_limit_warn": 6,
"sensor_limit_low": 0,
"sensor_limit_low_warn": null,
"sensor_alert": 1,
"sensor_custom": "No",
"entPhysicalIndex": null,
"entPhysicalIndex_measured": null,
"sensor_prev": null,
"user_func": null,
"state_name": null
},
{
"sensor_deleted": 0,
"sensor_class": "power",
"poller_type": "snmp",
"sensor_oid": ".1.3.6.1.4.1.318.1.1.26.4.3.1.5.1",
"sensor_index": "rPDU2DeviceStatusPower.1",
"sensor_type": "apc",
"sensor_descr": "Power, Total",
"group": null,
"sensor_divisor": 1,
"sensor_multiplier": 10,
"sensor_current": 1140,
"sensor_limit": null,
"sensor_limit_warn": null,
"sensor_limit_low": null,
"sensor_limit_low_warn": null,
"sensor_alert": 1,
"sensor_custom": "No",
"entPhysicalIndex": null,
"entPhysicalIndex_measured": null,
"sensor_prev": null,
"user_func": null,
"state_name": null
},
{
"sensor_deleted": 0,
"sensor_class": "state",
"poller_type": "snmp",
"sensor_oid": ".1.3.6.1.4.1.318.1.1.26.4.3.1.4.1",
"sensor_index": "rPDU2DeviceStatusLoadState.1",
"sensor_type": "rPDU2DeviceStatusLoadState",
"sensor_descr": "Device State",
"group": null,
"sensor_divisor": 1,
"sensor_multiplier": 1,
"sensor_current": 2,
"sensor_limit": null,
"sensor_limit_warn": null,
"sensor_limit_low": null,
"sensor_limit_low_warn": null,
"sensor_alert": 1,
"sensor_custom": "No",
"entPhysicalIndex": null,
"entPhysicalIndex_measured": null,
"sensor_prev": null,
"user_func": null,
"state_name": "rPDU2DeviceStatusLoadState"
},
{
"sensor_deleted": 0,
"sensor_class": "state",
"poller_type": "snmp",
"sensor_oid": ".1.3.6.1.4.1.318.1.1.26.4.3.1.12.1",
"sensor_index": "rPDU2DeviceStatusPowerSupplyAlarm.1",
"sensor_type": "rPDU2DeviceStatusPowerSupplyAlarm",
"sensor_descr": "Power Supply State",
"group": null,
"sensor_divisor": 1,
"sensor_multiplier": 1,
"sensor_current": 1,
"sensor_limit": null,
"sensor_limit_warn": null,
"sensor_limit_low": null,
"sensor_limit_low_warn": null,
"sensor_alert": 1,
"sensor_custom": "No",
"entPhysicalIndex": null,
"entPhysicalIndex_measured": null,
"sensor_prev": null,
"user_func": null,
"state_name": "rPDU2DeviceStatusPowerSupplyAlarm"
},
{
"sensor_deleted": 0,
"sensor_class": "state",
"poller_type": "snmp",
"sensor_oid": ".1.3.6.1.4.1.318.1.1.26.6.3.1.4.1",
"sensor_index": "rPDU2PhaseStatusLoadState.1",
"sensor_type": "rPDU2PhaseStatusLoadState",
"sensor_descr": "Load State, Phase #1",
"group": null,
"sensor_divisor": 1,
"sensor_multiplier": 1,
"sensor_current": 2,
"sensor_limit": null,
"sensor_limit_warn": null,
"sensor_limit_low": null,
"sensor_limit_low_warn": null,
"sensor_alert": 1,
"sensor_custom": "No",
"entPhysicalIndex": null,
"entPhysicalIndex_measured": null,
"sensor_prev": null,
"user_func": null,
"state_name": "rPDU2PhaseStatusLoadState"
},
{
"sensor_deleted": 0,
"sensor_class": "voltage",
"poller_type": "snmp",
"sensor_oid": ".1.3.6.1.4.1.318.1.1.26.6.3.1.6.1",
"sensor_index": "1",
"sensor_type": "apc",
"sensor_descr": "Input",
"group": null,
"sensor_divisor": 1,
"sensor_multiplier": 1,
"sensor_current": 242,
"sensor_limit": 278.3,
"sensor_limit_warn": null,
"sensor_limit_low": 205.7,
"sensor_limit_low_warn": null,
"sensor_alert": 1,
"sensor_custom": "No",
"entPhysicalIndex": null,
"entPhysicalIndex_measured": null,
"sensor_prev": null,
"user_func": null,
"state_name": null
}
],
"state_indexes": [
{
"state_name": "rPDU2DeviceStatusLoadState",
"state_descr": "lowLoad",
"state_draw_graph": 1,
"state_value": 1,
"state_generic_value": 0
},
{
"state_name": "rPDU2DeviceStatusLoadState",
"state_descr": "normal",
"state_draw_graph": 1,
"state_value": 2,
"state_generic_value": 0
},
{
"state_name": "rPDU2DeviceStatusLoadState",
"state_descr": "nearOverload",
"state_draw_graph": 1,
"state_value": 3,
"state_generic_value": 1
},
{
"state_name": "rPDU2DeviceStatusLoadState",
"state_descr": "overload",
"state_draw_graph": 1,
"state_value": 4,
"state_generic_value": 2
},
{
"state_name": "rPDU2DeviceStatusLoadState",
"state_descr": "notsupported",
"state_draw_graph": 1,
"state_value": 5,
"state_generic_value": 3
},
{
"state_name": "rPDU2DeviceStatusPowerSupplyAlarm",
"state_descr": "normal",
"state_draw_graph": 1,
"state_value": 1,
"state_generic_value": 0
},
{
"state_name": "rPDU2DeviceStatusPowerSupplyAlarm",
"state_descr": "alarm",
"state_draw_graph": 1,
"state_value": 2,
"state_generic_value": 2
},
{
"state_name": "rPDU2PhaseStatusLoadState",
"state_descr": "lowLoad",
"state_draw_graph": 1,
"state_value": 1,
"state_generic_value": 0
},
{
"state_name": "rPDU2PhaseStatusLoadState",
"state_descr": "normal",
"state_draw_graph": 1,
"state_value": 2,
"state_generic_value": 0
},
{
"state_name": "rPDU2PhaseStatusLoadState",
"state_descr": "nearOverload",
"state_draw_graph": 1,
"state_value": 3,
"state_generic_value": 1
},
{
"state_name": "rPDU2PhaseStatusLoadState",
"state_descr": "overload",
"state_draw_graph": 1,
"state_value": 4,
"state_generic_value": 2
}
]
},
"poller": "matches discovery"
}
}

View File

@@ -0,0 +1,68 @@
1.3.6.1.2.1.1.1.0|4|APC Web/SNMP Management Card (MB:v4.1.0 PF:v6.8.2 PN:apc_hw05_aos_682.bin AF1:v6.8.0 AN1:apc_hw05_rpdu2g_680.bin MN:AP8853 HR:02 SN: ZA2001002384 MD:01/03/2020)
1.3.6.1.2.1.1.2.0|6|1.3.6.1.4.1.318.1.3.4.6
1.3.6.1.2.1.1.5.0|4|<private>
1.3.6.1.4.1.318.1.1.12.1.15.0|2|-1
1.3.6.1.4.1.318.1.1.12.2.1.4.0|2|2
1.3.6.1.4.1.318.1.1.12.2.2.1.1.2.1|2|0
1.3.6.1.4.1.318.1.1.12.2.2.1.1.3.1|2|26
1.3.6.1.4.1.318.1.1.12.2.2.1.1.4.1|2|32
1.3.6.1.4.1.318.1.1.12.2.3.1.1.2.1|66|49
1.3.6.1.4.1.318.1.1.12.2.3.1.1.2.2|66|0
1.3.6.1.4.1.318.1.1.12.2.3.1.1.2.3|66|47
1.3.6.1.4.1.318.1.1.12.2.3.1.1.4.1|2|1
1.3.6.1.4.1.318.1.1.12.2.3.1.1.4.2|2|0
1.3.6.1.4.1.318.1.1.12.2.3.1.1.4.3|2|0
1.3.6.1.4.1.318.1.1.12.2.3.1.1.5.1|2|0
1.3.6.1.4.1.318.1.1.12.2.3.1.1.5.2|2|1
1.3.6.1.4.1.318.1.1.12.2.3.1.1.5.3|2|2
1.3.6.1.4.1.318.1.1.12.2.4.1.1.2.1|2|0
1.3.6.1.4.1.318.1.1.12.2.4.1.1.2.2|2|0
1.3.6.1.4.1.318.1.1.12.2.4.1.1.3.1|2|6
1.3.6.1.4.1.318.1.1.12.2.4.1.1.3.2|2|6
1.3.6.1.4.1.318.1.1.12.2.4.1.1.4.1|2|8
1.3.6.1.4.1.318.1.1.12.2.4.1.1.4.2|2|8
1.3.6.1.4.1.318.1.1.26.4.3.1.1.1|2|1
1.3.6.1.4.1.318.1.1.26.4.3.1.2.1|2|1
1.3.6.1.4.1.318.1.1.26.4.3.1.3.1|4|dc-np2-pdu_1a_03_04_a
1.3.6.1.4.1.318.1.1.26.4.3.1.4.1|2|2
1.3.6.1.4.1.318.1.1.26.4.3.1.5.1|2|114
1.3.6.1.4.1.318.1.1.26.4.3.1.6.1|2|143
1.3.6.1.4.1.318.1.1.26.4.3.1.7.1|4|03/04/2022 09:20:45
1.3.6.1.4.1.318.1.1.26.4.3.1.8.1|4|01/02/2020 13:26:52
1.3.6.1.4.1.318.1.1.26.4.3.1.9.1|2|35128
1.3.6.1.4.1.318.1.1.26.4.3.1.10.1|4|01/02/2020 13:27:05
1.3.6.1.4.1.318.1.1.26.4.3.1.11.1|2|2
1.3.6.1.4.1.318.1.1.26.4.3.1.12.1|2|1
1.3.6.1.4.1.318.1.1.26.4.3.1.13.1|2|1
1.3.6.1.4.1.318.1.1.26.4.3.1.14.1|2|3
1.3.6.1.4.1.318.1.1.26.4.3.1.15.1|4|01/02/2020 13:27:05
1.3.6.1.4.1.318.1.1.26.4.3.1.16.1|2|119
1.3.6.1.4.1.318.1.1.26.4.3.1.17.1|2|96
1.3.6.1.4.1.318.1.1.26.4.3.1.18.1|2|1
1.3.6.1.4.1.318.1.1.26.6.3.1.1.1|2|1
1.3.6.1.4.1.318.1.1.26.6.3.1.2.1|2|1
1.3.6.1.4.1.318.1.1.26.6.3.1.3.1|2|1
1.3.6.1.4.1.318.1.1.26.6.3.1.4.1|2|2
1.3.6.1.4.1.318.1.1.26.6.3.1.5.1|2|49
1.3.6.1.4.1.318.1.1.26.6.3.1.6.1|2|242
1.3.6.1.4.1.318.1.1.26.6.3.1.7.1|2|114
1.3.6.1.4.1.318.1.1.26.6.3.1.8.1|2|119
1.3.6.1.4.1.318.1.1.26.6.3.1.9.1|2|96
1.3.6.1.4.1.318.1.1.26.6.3.1.10.1|2|60
1.3.6.1.4.1.318.1.1.26.6.3.1.11.1|4|03/04/2022 09:20:45
1.3.6.1.4.1.318.1.1.26.6.3.1.12.1|4|01/02/2020 13:26:52
1.3.6.1.4.1.318.1.1.26.10.2.2.1.1.1|2|1
1.3.6.1.4.1.318.1.1.26.10.2.2.1.2.1|2|1
1.3.6.1.4.1.318.1.1.26.10.2.2.1.3.1|4|
1.3.6.1.4.1.318.1.1.26.10.2.2.1.4.1|2|1
1.3.6.1.4.1.318.1.1.26.10.2.2.1.5.1|2|4
1.3.6.1.4.1.318.1.1.26.10.2.2.1.6.1|2|1
1.3.6.1.4.1.318.1.1.26.10.2.2.1.7.1|2|-1
1.3.6.1.4.1.318.1.1.26.10.2.2.1.8.1|2|-1
1.3.6.1.4.1.318.1.1.26.10.2.2.1.9.1|2|1
1.3.6.1.4.1.318.1.1.26.10.2.2.1.10.1|2|-1
1.3.6.1.4.1.318.1.1.26.10.2.2.1.11.1|2|1
1.3.6.1.4.1.318.1.1.26.10.2.2.1.12.1|2|-1
1.3.6.1.4.1.318.1.1.26.10.2.2.1.13.1|2|-1
1.3.6.1.4.1.318.1.1.26.10.2.2.1.14.1|4|noTempSensorInstalled
1.3.6.1.4.1.318.1.1.26.10.2.2.1.15.1|4|noTempSensorInstalled