Skip to content

Commit

Permalink
VRP - Fix SSID Client count (#12629)
Browse files Browse the repository at this point in the history
* Fix Client count

* style

* no caching

* style

* snmpwalk_cache_oid

* Include total of all STA connected

* style

* Update Vrp.php

* fix GHz casing

Co-authored-by: Tony Murray <murraytony@gmail.com>
  • Loading branch information
PipoCanaja and murrant committed Mar 26, 2021
1 parent 77d21c1 commit aac57e6
Show file tree
Hide file tree
Showing 3 changed files with 288 additions and 71 deletions.
85 changes: 64 additions & 21 deletions LibreNMS/OS/Vrp.php
Expand Up @@ -404,28 +404,71 @@ public function discoverWirelessApCount()
public function discoverWirelessClients()
{
$sensors = [];
$total_oids = [];

$vapInfoTable = $this->getCacheTable('hwWlanVapInfoTable', 'HUAWEI-WLAN-VAP-MIB', 3);

foreach ($vapInfoTable as $a_index => $ap) {
//Convert mac address (hh:hh:hh:hh:hh:hh) to dec OID (ddd.ddd.ddd.ddd.ddd.ddd)
$a_index_oid = implode('.', array_map('hexdec', explode(':', $a_index)));
foreach ($ap as $r_index => $radio) {
foreach ($radio as $s_index => $ssid) {
$oid = '.1.3.6.1.4.1.2011.6.139.17.1.1.1.9.' . $a_index_oid . '.' . $r_index . '.' . $s_index;
$total_oids[] = $oid;
$sensors[] = new WirelessSensor(
'clients',
$this->getDeviceId(),
$oid,
'vrp',
$a_index_oid . '.' . $r_index . '.' . $s_index,
'Radio:' . $r_index . ' SSID:' . $ssid['hwWlanVapProfileName'],
$ssid['hwWlanVapStaOnlineCnt']
);
}

$staTable = snmpwalk_cache_oid($this->getDeviceArray(), 'hwWlanSsid2gStaCnt', [], 'HUAWEI-WLAN-VAP-MIB');
$staTable = snmpwalk_cache_oid($this->getDeviceArray(), 'hwWlanSsid5gStaCnt', $staTable, 'HUAWEI-WLAN-VAP-MIB');

//Map OIDs and description
$oidMap = [
'hwWlanSsid5gStaCnt' => '.1.3.6.1.4.1.2011.6.139.17.1.2.1.3.',
'hwWlanSsid2gStaCnt' => '.1.3.6.1.4.1.2011.6.139.17.1.2.1.2.',
];
$descrMap = [
'hwWlanSsid5gStaCnt' => '5 GHz',
'hwWlanSsid2gStaCnt' => '2.4 GHz',
];
$ssid_total_oid_array = []; // keep all OIDs so we can compute the total of all STA

foreach ($staTable as $ssid => $sta) {
//Convert string to num_oid
$numSsid = strlen($ssid) . '.' . implode('.', unpack('c*', $ssid));
$ssid_oid_array = []; // keep all OIDs of different freqs for a single SSID, to compute each SSID sta count, all freqs included
foreach ($sta as $staFreq => $count) {
$oid = $oidMap[$staFreq] . $numSsid;
$ssid_oid_array[] = $oid;
$ssid_total_oid_array[] = $oid;
$sensors[] = new WirelessSensor(
'clients',
$this->getDeviceId(),
$oid,
'vrpi-clients',
$staFreq . '-' . $ssid,
'SSID: ' . $ssid . ' (' . $descrMap[$staFreq] . ')',
$count,
1,
1,
'sum'
);
}

// And we add a sensor with all frequencies for each SSID
$sensors[] = new WirelessSensor(
'clients',
$this->getDeviceId(),
$ssid_oid_array,
'vrp-clients',
'total-' . $ssid,
'SSID: ' . $ssid,
0,
1,
1,
'sum'
);
}
if (count($ssid_total_oid_array) > 0) {
// We have at least 1 SSID, so we can count the total of STA
$sensors[] = new WirelessSensor(
'clients',
$this->getDeviceId(),
$ssid_total_oid_array,
'vrp-clients',
'total-all-ssids',
'Total Clients',
0,
1,
1,
'sum'
);
}

return $sensors;
Expand Down

0 comments on commit aac57e6

Please sign in to comment.