Files
librenms-librenms/LibreNMS/OS/ArubaInstant.php
T
Tony MurrayandGitHub 941037e44e Convert OS discovery to new style (#12099)
* terra

* airos

* port cisco os polling
old wwan polling was broken and deprecated anyway

* enterasys

* Brother, a few changes

* AW Plus

* Fabos

* set expected test data

* 3com

* Adva FSP150

* advantech

* airos-af

* aix

* akcp

* allied

* allworx and missed mibs

* anyos

* fixup some zyxel shared stuffs
zywall graph polling

* aos

* apc

* apex

* apsoluteos

* fix copyrights

* arris

* arris

* aruba-instant

* ArubaOS

* Ascom

* asuswrt-merlin, ats

* audiocodes

* avocent

* avtech

* barracuda

* binox

* boss

* canonprinter

* cdata

* ceraos

* ciena-waveserver

* fix 3com

* fix airos

* fix brother yaml?

* fix aos more

* fix and improve apc

* fix arista test data

* yaml discovery (basic)

* cimc

* mib not used

* remove old discovery file

* ciscosat

* ciscosb fixes + improvements

* comware

* ctm

* cumulus

* cxr-ts

* cyberoam-utm

* cyberpower

* dahua-nvr

* dasan-nos

* datadomain

* dcn-software and fallback oids

* dd-wrt

* dell-laser

* d*

* e* and location

* forti, post processing, oid coalescing

* Freebsd array of sysDescr regex

* finish f*

* g*

* h*

* i* WIP

* i*

* Junos

* j*

* k*

* unix refactor previous to yaml more
inject $device

* fixes

* fixes

* l*

* m*

* n* ability to set other fields in regex
tnmsne polling to eloquent

* o*

* p*

* q* + bonus calix

* r*

* s* WIP

* s*

* t*

* u*

* v*
rework vrp to yaml (hybrid)

* w*

* x*

* z*

* a* easy no-data

* fixes

* style fixes

* missed ApexPlus

* fix signature

* Add missing location data

* rename getDevice functions

* add new cisco ftd data

* update docs

* revert sill snmp format

* fix snmp options

* update for new smartax test data

* rebase dsm

* fix voss
2020-09-18 15:12:07 +02:00

353 lines
13 KiB
PHP

<?php
/**
* ArubaInstant.php
*
* HPE Aruba Instant
*
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package LibreNMS
* @link http://librenms.org
* @copyright 2019 Timothy Willey
* @author Timothy Willey <[email protected]>
*/
namespace LibreNMS\OS;
use App\Models\Device;
use LibreNMS\Device\Processor;
use LibreNMS\Device\WirelessSensor;
use LibreNMS\Interfaces\Discovery\OSDiscovery;
use LibreNMS\Interfaces\Discovery\ProcessorDiscovery;
use LibreNMS\Interfaces\Discovery\Sensors\WirelessApCountDiscovery;
use LibreNMS\Interfaces\Discovery\Sensors\WirelessClientsDiscovery;
use LibreNMS\Interfaces\Discovery\Sensors\WirelessFrequencyDiscovery;
use LibreNMS\Interfaces\Discovery\Sensors\WirelessNoiseFloorDiscovery;
use LibreNMS\Interfaces\Discovery\Sensors\WirelessPowerDiscovery;
use LibreNMS\Interfaces\Discovery\Sensors\WirelessUtilizationDiscovery;
use LibreNMS\Interfaces\Polling\Sensors\WirelessApCountPolling;
use LibreNMS\Interfaces\Polling\Sensors\WirelessClientsPolling;
use LibreNMS\Interfaces\Polling\Sensors\WirelessFrequencyPolling;
use LibreNMS\OS;
use LibreNMS\Util\Rewrite;
class ArubaInstant extends OS implements
OSDiscovery,
ProcessorDiscovery,
WirelessApCountDiscovery,
WirelessApCountPolling,
WirelessClientsDiscovery,
WirelessClientsPolling,
WirelessFrequencyDiscovery,
WirelessFrequencyPolling,
WirelessNoiseFloorDiscovery,
WirelessPowerDiscovery,
WirelessUtilizationDiscovery
{
public function discoverOS(Device $device): void
{
parent::discoverOS($device); // yaml
$device->serial = snmp_getnext($this->getDeviceArray(), 'aiAPSerialNum', '-Oqv', 'AI-AP-MIB');
}
/**
* Discover processors.
* Returns an array of LibreNMS\Device\Processor objects that have been discovered
*
* @return array Processors
*/
public function discoverProcessors()
{
$processors = array();
$ai_mib = 'AI-AP-MIB';
$ai_ap_data = $this->getCacheTable('aiAccessPointEntry', $ai_mib);
foreach ($ai_ap_data as $ai_ap => $ai_ap_oid) {
$value = $ai_ap_oid['aiAPCPUUtilization'];
$combined_oid = sprintf('%s::%s.%s', $ai_mib, 'aiAPCPUUtilization', Rewrite::oidMac($ai_ap));
$oid = snmp_translate($combined_oid, 'ALL', 'arubaos', '-On', null);
$description = $ai_ap_data[$ai_ap]['aiAPSerialNum'];
$processors[] = Processor::discover('aruba-instant', $this->getDeviceId(), $oid, Rewrite::macToHex($ai_ap), $description, 1, $value);
} // end foreach
return $processors;
}
/**
* Discover wireless client counts. Type is clients.
* Returns an array of LibreNMS\Device\Sensor objects that have been discovered
*
* @return array Sensors
*/
public function discoverWirelessClients()
{
$sensors = array();
$device = $this->getDeviceArray();
$ai_mib = 'AI-AP-MIB';
if (intval(explode('.', $device['version'])[0]) >= 8 && intval(explode('.', $device['version'])[1]) >= 4) {
// version is at least 8.4.0.0
$ssid_data = $this->getCacheTable('aiWlanSSIDEntry', $ai_mib);
$ap_data = array_merge_recursive(
$this->getCacheTable('aiAccessPointEntry', $ai_mib),
$this->getCacheTable('aiRadioClientNum', $ai_mib)
);
$oids = array();
$total_clients = 0;
// Clients Per SSID
foreach ($ssid_data as $index => $entry) {
$combined_oid = sprintf('%s::%s.%s', $ai_mib, 'aiSSIDClientNum', $index);
$oid = snmp_translate($combined_oid, 'ALL', 'arubaos', '-On', null);
$description = sprintf('SSID %s Clients', $entry['aiSSID']);
$oids[] = $oid;
$total_clients += $entry['aiSSIDClientNum'];
$sensors[] = new WirelessSensor('clients', $this->getDeviceId(), $oid, 'aruba-instant', $index, $description, $entry['aiSSIDClientNum']);
}
// Total Clients across all SSIDs
$sensors[] = new WirelessSensor('clients', $this->getDeviceId(), $oids, 'aruba-instant', 'total-clients', 'Total Clients', $total_clients);
// Clients Per Radio
foreach ($ap_data as $index => $entry) {
foreach ($entry['aiRadioClientNum'] as $radio => $value) {
$combined_oid = sprintf('%s::%s.%s.%s', $ai_mib, 'aiRadioClientNum', Rewrite::oidMac($index), $radio);
$oid = snmp_translate($combined_oid, 'ALL', 'arubaos', '-On', null);
$description = sprintf('%s Radio %s', $entry['aiAPSerialNum'], $radio);
$sensor_index = sprintf('%s.%s', Rewrite::macToHex($index), $radio);
$sensors[] = new WirelessSensor('clients', $this->getDeviceId(), $oid, 'aruba-instant', $sensor_index, $description, $value);
}
}
} else {
// version is lower than 8.4.0.0
// fetch the MAC addresses of currently connected clients, then count them to get an overall total
$client_data = $this->getCacheTable('aiClientMACAddress', $ai_mib);
$total_clients = sizeof($client_data);
$combined_oid = sprintf('%s::%s', $ai_mib, 'aiClientMACAddress');
$oid = snmp_translate($combined_oid, 'ALL', 'arubaos', '-On', null);
$sensors[] = new WirelessSensor('clients', $this->getDeviceId(), $oid, 'aruba-instant', 'total-clients', 'Total Clients', $total_clients);
}
return $sensors;
}
/**
* Discover wireless AP counts. Type is ap-count.
* Returns an array of LibreNMS\Device\Sensor objects that have been discovered
*
* @return array Sensors
*/
public function discoverWirelessApCount()
{
$sensors = array();
$ai_mib = 'AI-AP-MIB';
$ap_data = $this->getCacheTable('aiAPSerialNum', $ai_mib);
$total_aps = sizeof($ap_data);
$combined_oid = sprintf('%s::%s', $ai_mib, 'aiAPSerialNum');
$oid = snmp_translate($combined_oid, 'ALL', 'arubaos', '-On', null);
$sensors[] = new WirelessSensor('ap-count', $this->getDeviceId(), $oid, 'aruba-instant', 'total-aps', 'Total APs', $total_aps);
return $sensors;
}
/**
* Discover wireless frequency. This is in MHz. Type is frequency.
* Returns an array of LibreNMS\Device\Sensor objects that have been discovered
*
* @return array Sensors
*/
public function discoverWirelessFrequency()
{
// instant
return $this->discoverInstantRadio('frequency', 'aiRadioChannel');
}
/**
* Discover wireless noise floor. This is in dBm/Hz. Type is noise-floor.
* Returns an array of LibreNMS\Device\Sensor objects that have been discovered
*
* @return array
*/
public function discoverWirelessNoiseFloor()
{
// instant
return $this->discoverInstantRadio('noise-floor', 'aiRadioNoiseFloor');
}
/**
* Discover wireless tx or rx power. This is in dBm. Type is power.
* Returns an array of LibreNMS\Device\Sensor objects that have been discovered
*
* @return array
*/
public function discoverWirelessPower()
{
// instant
return $this->discoverInstantRadio('power', 'aiRadioTransmitPower', "%s Radio %s: Tx Power");
}
/**
* Discover wireless utilization. This is in %. Type is utilization.
* Returns an array of LibreNMS\Device\Sensor objects that have been discovered
*
* @return array Sensors
*/
public function discoverWirelessUtilization()
{
// instant
return $this->discoverInstantRadio('utilization', 'aiRadioUtilization64');
}
/**
* Aruba Instant Radio Discovery
*
* @return array Sensors
*/
private function discoverInstantRadio($type, $mib, $desc = '%s Radio %s')
{
$ai_mib = 'AI-AP-MIB';
$ai_sg_data = array_merge_recursive(
$this->getCacheTable('aiAPSerialNum', $ai_mib),
$this->getCacheTable('aiRadioChannel', $ai_mib),
$this->getCacheTable('aiRadioNoiseFloor', $ai_mib),
$this->getCacheTable('aiRadioTransmitPower', $ai_mib),
$this->getCacheTable('aiRadioUtilization64', $ai_mib)
);
$sensors = array();
foreach ($ai_sg_data as $ai_ap => $ai_ap_oid) {
if (isset($ai_ap_oid[$mib])) {
foreach ($ai_ap_oid[$mib] as $ai_ap_radio => $value) {
$multiplier = 1;
if ($type == 'frequency') {
$value = WirelessSensor::channelToFrequency($this->decodeChannel($value));
}
if ($type == 'noise-floor') {
$multiplier = -1;
$value = $value * $multiplier;
}
$combined_oid = sprintf('%s::%s.%s.%s', $ai_mib, $mib, Rewrite::oidMac($ai_ap), $ai_ap_radio);
$oid = snmp_translate($combined_oid, 'ALL', 'arubaos', '-On', null);
$description = sprintf($desc, $ai_sg_data[$ai_ap]['aiAPSerialNum'], $ai_ap_radio);
$index = sprintf('%s.%s', Rewrite::macToHex($ai_ap), $ai_ap_radio);
$sensors[] = new WirelessSensor($type, $this->getDeviceId(), $oid, 'aruba-instant', $index, $description, $value, $multiplier);
} // end foreach
} // end if
} // end foreach
return $sensors;
}
protected function decodeChannel($channel)
{
return $channel & 255; // mask off the channel width information
}
/**
* Poll wireless frequency as MHz
* The returned array should be sensor_id => value pairs
*
* @param array $sensors Array of sensors needed to be polled
* @return array of polled data
*/
public function pollWirelessFrequency(array $sensors)
{
return $this->pollWirelessChannelAsFrequency($sensors, [$this, 'decodeChannel']);
}
/**
* Poll wireless clients
* The returned array should be sensor_id => value pairs
*
* @param array $sensors Array of sensors needed to be polled
* @return array of polled data
*/
public function pollWirelessClients(array $sensors)
{
$data = array();
if (!empty($sensors)) {
$device = $this->getDeviceArray();
if (intval(explode('.', $device['version'])[0]) >= 8 && intval(explode('.', $device['version'])[1]) >= 4) {
// version is at least 8.4.0.0
$oids = array();
foreach ($sensors as $sensor) {
$oids[$sensor['sensor_id']] = current($sensor['sensor_oids']);
}
$snmp_data = snmp_get_multi_oid($this->getDeviceArray(), $oids);
foreach ($oids as $id => $oid) {
$data[$id] = $snmp_data[$oid];
}
} else {
// version is lower than 8.4.0.0
if (!empty($sensors) && sizeof($sensors) == 1) {
$ai_mib = 'AI-AP-MIB';
$client_data = $this->getCacheTable('aiClientMACAddress', $ai_mib);
if (empty($client_data)) {
$total_clients = 0;
} else {
$total_clients = sizeof($client_data);
}
$data[$sensors[0]['sensor_id']] = $total_clients;
}
}
}
return $data;
}
/**
* Poll AP Count
* The returned array should be sensor_id => value pairs
*
* @param array $sensors Array of sensors needed to be polled
* @return array of polled data
*/
public function pollWirelessApCount(array $sensors)
{
$data = array();
if (!empty($sensors) && sizeof($sensors) == 1) {
$ai_mib = 'AI-AP-MIB';
$ap_data = $this->getCacheTable('aiAPSerialNum', $ai_mib);
$total_aps = 0;
if (!empty($ap_data)) {
$total_aps = sizeof($ap_data);
}
$data[$sensors[0]['sensor_id']] = $total_aps;
}
return $data;
}
}