From e8bcbfd9446bb58866cf6efe05834932e29291a5 Mon Sep 17 00:00:00 2001 From: Peca Nesovanovic <59750439+Npeca75@users.noreply.github.com> Date: Wed, 10 Aug 2022 14:12:17 +0200 Subject: [PATCH] Mikrotik wifi station mode sensors (#14193) * add WlStat wifi sensors * test data --- LibreNMS/OS/Routeros.php | 78 +++++++- tests/data/routeros_station.json | 243 +++++++++++++++++++++++++ tests/snmpsim/routeros_station.snmprec | 12 ++ 3 files changed, 329 insertions(+), 4 deletions(-) create mode 100644 tests/data/routeros_station.json create mode 100644 tests/snmpsim/routeros_station.snmprec diff --git a/LibreNMS/OS/Routeros.php b/LibreNMS/OS/Routeros.php index 54abc7c170..92083113ca 100644 --- a/LibreNMS/OS/Routeros.php +++ b/LibreNMS/OS/Routeros.php @@ -83,6 +83,33 @@ class Routeros extends OS implements ); } + $data = $this->getCacheTable('MIKROTIK-MIB::mtxrWlStatTable'); + foreach ($data as $index => $entry) { + $freq = $entry['mtxrWlStatFreq'] ? substr($entry['mtxrWlStatFreq'], 0, 1) . 'G' : 'SSID'; + if (empty($entry['mtxrWlStatTxCCQ']) && empty($entry['mtxrWlStatRxCCQ'])) { + continue; + } + + $sensors[] = new WirelessSensor( + 'ccq', + $this->getDeviceId(), + '.1.3.6.1.4.1.14988.1.1.1.1.1.9.' . $index, + 'mikrotik-tx-ccq', + $index, + "$freq: " . $entry['mtxrWlStatSsid'] . ' Tx', + $entry['mtxrWlStatTxCCQ'] + ); + $sensors[] = new WirelessSensor( + 'ccq', + $this->getDeviceId(), + '.1.3.6.1.4.1.14988.1.1.1.1.1.10.' . $index, + 'mikrotik-rx-ccq', + $index, + "$freq: " . $entry['mtxrWlStatSsid'] . ' Rx', + $entry['mtxrWlStatRxCCQ'] + ); + } + return $sensors; } @@ -127,7 +154,6 @@ class Routeros extends OS implements continue; } $freq = substr($entry['mtxrWlApFreq'], 0, 1) . 'G'; - $sensors[] = new WirelessSensor( 'frequency', $this->getDeviceId(), @@ -139,6 +165,23 @@ class Routeros extends OS implements ); } + $data = $this->getCacheTable('MIKROTIK-MIB::mtxrWlStatTable'); + foreach ($data as $index => $entry) { + if ($entry['mtxrWlStatFreq'] === '0') { + continue; + } + $freq = substr($entry['mtxrWlStatFreq'], 0, 1) . 'G'; + $sensors[] = new WirelessSensor( + 'frequency', + $this->getDeviceId(), + '.1.3.6.1.4.1.14988.1.1.1.1.1.7.' . $index, + 'mikrotik', + $index, + "$freq: " . $entry['mtxrWlStatSsid'], + $entry['mtxrWlStatFreq'] + ); + } + $data = $this->getCacheTable('MIKROTIK-MIB::mtxrWl60GTable'); foreach ($data as $index => $entry) { $sensors[] = new WirelessSensor( @@ -243,19 +286,21 @@ class Routeros extends OS implements public function discoverWirelessRate() { $sensors = []; + $data = $this->getCacheTable('MIKROTIK-MIB::mtxrWlApTable'); foreach ($data as $index => $entry) { if ($entry['mtxrWlApTxRate'] === '0' && $entry['mtxrWlApRxRate'] === '0') { continue; // no data } + $freq = $entry['mtxrWlApFreq'] ? substr($entry['mtxrWlApFreq'], 0, 1) . 'G' : 'SSID'; $sensors[] = new WirelessSensor( 'rate', $this->getDeviceId(), '.1.3.6.1.4.1.14988.1.1.1.3.1.2.' . $index, 'mikrotik-tx', $index, - 'SSID: ' . $entry['mtxrWlApSsid'] . ' Tx', + "$freq: " . $entry['mtxrWlApSsid'] . ' Tx', $entry['mtxrWlApTxRate'] ); $sensors[] = new WirelessSensor( @@ -264,13 +309,38 @@ class Routeros extends OS implements '.1.3.6.1.4.1.14988.1.1.1.3.1.3.' . $index, 'mikrotik-rx', $index, - 'SSID: ' . $entry['mtxrWlApSsid'] . ' Rx', + "$freq: " . $entry['mtxrWlApSsid'] . ' Rx', $entry['mtxrWlApRxRate'] ); } - $data = $this->getCacheTable('MIKROTIK-MIB::mtxrWl60GTable'); + $data = $this->getCacheTable('MIKROTIK-MIB::mtxrWlStatTable'); + foreach ($data as $index => $entry) { + if ($entry['mtxrWlStatTxRate'] === '0' && $entry['mtxrWlStatRxRate'] === '0') { + continue; // no data + } + $freq = $entry['mtxrWlStatFreq'] ? substr($entry['mtxrWlStatFreq'], 0, 1) . 'G' : 'SSID'; + $sensors[] = new WirelessSensor( + 'rate', + $this->getDeviceId(), + '.1.3.6.1.4.1.14988.1.1.1.1.1.2.' . $index, + 'mikrotik-tx', + $index, + "$freq: " . $entry['mtxrWlStatSsid'] . ' Tx', + $entry['mtxrWlStatTxRate'] + ); + $sensors[] = new WirelessSensor( + 'rate', + $this->getDeviceId(), + '.1.3.6.1.4.1.14988.1.1.1.1.1.3.' . $index, + 'mikrotik-rx', + $index, + "$freq: " . $entry['mtxrWlStatSsid'] . ' Rx', + $entry['mtxrWlStatRxRate'] + ); + } + $data = $this->getCacheTable('MIKROTIK-MIB::mtxrWl60GTable'); foreach ($data as $index => $entry) { $sensors[] = new WirelessSensor( 'rate', diff --git a/tests/data/routeros_station.json b/tests/data/routeros_station.json new file mode 100644 index 0000000000..9f5ff135a4 --- /dev/null +++ b/tests/data/routeros_station.json @@ -0,0 +1,243 @@ +{ + "os": { + "discovery": { + "devices": [ + { + "sysName": "", + "sysObjectID": ".1.3.6.1.4.1.14988.1", + "sysDescr": "RouterOS RBDynaDishG-5HacD", + "sysContact": null, + "version": null, + "hardware": "RBDynaDishG-5HacD", + "features": null, + "os": "routeros", + "type": "network", + "serial": null, + "icon": "mikrotik.svg", + "location": null + } + ] + }, + "poller": "matches discovery" + }, + "wireless": { + "discovery": { + "wireless_sensors": [ + { + "sensor_deleted": 0, + "sensor_class": "rate", + "sensor_index": "23", + "sensor_type": "mikrotik-tx", + "sensor_descr": "5G: pikjo88 Tx", + "sensor_divisor": 1, + "sensor_multiplier": 1, + "sensor_aggregator": "sum", + "sensor_current": 150000000, + "sensor_prev": null, + "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_oids": "[\".1.3.6.1.4.1.14988.1.1.1.1.1.2.23\"]" + }, + { + "sensor_deleted": 0, + "sensor_class": "rate", + "sensor_index": "23", + "sensor_type": "mikrotik-rx", + "sensor_descr": "5G: pikjo88 Rx", + "sensor_divisor": 1, + "sensor_multiplier": 1, + "sensor_aggregator": "sum", + "sensor_current": 90000000, + "sensor_prev": null, + "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_oids": "[\".1.3.6.1.4.1.14988.1.1.1.1.1.3.23\"]" + }, + { + "sensor_deleted": 0, + "sensor_class": "ccq", + "sensor_index": "23", + "sensor_type": "mikrotik-tx-ccq", + "sensor_descr": "5G: pikjo88 Tx", + "sensor_divisor": 1, + "sensor_multiplier": 1, + "sensor_aggregator": "sum", + "sensor_current": 100, + "sensor_prev": null, + "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_oids": "[\".1.3.6.1.4.1.14988.1.1.1.1.1.9.23\"]" + }, + { + "sensor_deleted": 0, + "sensor_class": "ccq", + "sensor_index": "23", + "sensor_type": "mikrotik-rx-ccq", + "sensor_descr": "5G: pikjo88 Rx", + "sensor_divisor": 1, + "sensor_multiplier": 1, + "sensor_aggregator": "sum", + "sensor_current": 80, + "sensor_prev": null, + "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_oids": "[\".1.3.6.1.4.1.14988.1.1.1.1.1.10.23\"]" + }, + { + "sensor_deleted": 0, + "sensor_class": "frequency", + "sensor_index": "23", + "sensor_type": "mikrotik", + "sensor_descr": "5G: pikjo88", + "sensor_divisor": 1, + "sensor_multiplier": 1, + "sensor_aggregator": "sum", + "sensor_current": 5745, + "sensor_prev": null, + "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_oids": "[\".1.3.6.1.4.1.14988.1.1.1.1.1.7.23\"]" + } + ] + }, + "poller": { + "wireless_sensors": [ + { + "sensor_deleted": 0, + "sensor_class": "rate", + "sensor_index": "23", + "sensor_type": "mikrotik-tx", + "sensor_descr": "5G: pikjo88 Tx", + "sensor_divisor": 1, + "sensor_multiplier": 1, + "sensor_aggregator": "sum", + "sensor_current": 150000000, + "sensor_prev": 150000000, + "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_oids": "[\".1.3.6.1.4.1.14988.1.1.1.1.1.2.23\"]" + }, + { + "sensor_deleted": 0, + "sensor_class": "rate", + "sensor_index": "23", + "sensor_type": "mikrotik-rx", + "sensor_descr": "5G: pikjo88 Rx", + "sensor_divisor": 1, + "sensor_multiplier": 1, + "sensor_aggregator": "sum", + "sensor_current": 90000000, + "sensor_prev": 90000000, + "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_oids": "[\".1.3.6.1.4.1.14988.1.1.1.1.1.3.23\"]" + }, + { + "sensor_deleted": 0, + "sensor_class": "ccq", + "sensor_index": "23", + "sensor_type": "mikrotik-tx-ccq", + "sensor_descr": "5G: pikjo88 Tx", + "sensor_divisor": 1, + "sensor_multiplier": 1, + "sensor_aggregator": "sum", + "sensor_current": 100, + "sensor_prev": 100, + "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_oids": "[\".1.3.6.1.4.1.14988.1.1.1.1.1.9.23\"]" + }, + { + "sensor_deleted": 0, + "sensor_class": "ccq", + "sensor_index": "23", + "sensor_type": "mikrotik-rx-ccq", + "sensor_descr": "5G: pikjo88 Rx", + "sensor_divisor": 1, + "sensor_multiplier": 1, + "sensor_aggregator": "sum", + "sensor_current": 80, + "sensor_prev": 80, + "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_oids": "[\".1.3.6.1.4.1.14988.1.1.1.1.1.10.23\"]" + }, + { + "sensor_deleted": 0, + "sensor_class": "frequency", + "sensor_index": "23", + "sensor_type": "mikrotik", + "sensor_descr": "5G: pikjo88", + "sensor_divisor": 1, + "sensor_multiplier": 1, + "sensor_aggregator": "sum", + "sensor_current": 5745, + "sensor_prev": 5745, + "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_oids": "[\".1.3.6.1.4.1.14988.1.1.1.1.1.7.23\"]" + } + ] + } + } +} diff --git a/tests/snmpsim/routeros_station.snmprec b/tests/snmpsim/routeros_station.snmprec new file mode 100644 index 0000000000..6f93486a9d --- /dev/null +++ b/tests/snmpsim/routeros_station.snmprec @@ -0,0 +1,12 @@ +1.3.6.1.2.1.1.1.0|4|RouterOS RBDynaDishG-5HacD +1.3.6.1.2.1.1.2.0|6|1.3.6.1.4.1.14988.1 +1.3.6.1.2.1.1.5.0|4| +1.3.6.1.4.1.14988.1.1.1.1.1.2.23|66|150000000 +1.3.6.1.4.1.14988.1.1.1.1.1.3.23|66|90000000 +1.3.6.1.4.1.14988.1.1.1.1.1.4.23|2|-47 +1.3.6.1.4.1.14988.1.1.1.1.1.5.23|4|pikjo88 +1.3.6.1.4.1.14988.1.1.1.1.1.6.23|4x|00804870703F +1.3.6.1.4.1.14988.1.1.1.1.1.7.23|2|5745 +1.3.6.1.4.1.14988.1.1.1.1.1.8.23|4|5745/20-Ce/an +1.3.6.1.4.1.14988.1.1.1.1.1.9.23|65|100 +1.3.6.1.4.1.14988.1.1.1.1.1.10.23|65|80