mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
* feature: Wireless Sensors Includes client counts for ios and unifi Graphing could use some improvement. Alerting and threshold ui not implemented WIP: starting OO based wireless sensors. Class based functionality working remove old functional files add schema file discovery needs to be enabled, not polling fix up schema fix Unifi discovery not returning an array Add some debug when discovering a sensor. Fix style. Add missing semicolin Add a null object (Generic) for OS. Fill out some phpdocs Re-organized code Each sensor type now has it's own discovery and polling interface Custom polling tested with Unifi CCQ Left to do: Implement UI (Graphs and Custom thresholds) Alerting Testing Fix event message text Remove runDiscovery and runPolling from OS, they are unused and don't belong there. Cleanups/docs Missed this file. Remove the requirement to fetch the current value to check validity. Do that automatically if current is not specified A few cleanups here and there First pass at graphing. device_ and wireless_ graphs added. Add RouterOS support Singleton OS instance isn't required right now. Remove that to allow some memory to be freed. Add wireless to the device list metrics. Make all metrics clickable Tweak graphs a bit Implement limit configuration page. Use sensors page as common code instead of duplicating. Clean up some javascript interactions: Allow enter on values to save. Cancel if update is not needed. Enable the clear custom button after setting a custom value. Add some wireless alert rules to the library. Add documentation. Add unifi client counts by ssid in addition to radio. Optimize Sensor polling a bit. Add HP MSM clients support (for full controller) Fix function accessibility Formalize the discovery and poller interfaces. Add Xirrus clients and noise floor move module interfaces to a more appropriate place. push caching code up to os, unsure about this do to the limitations No point in selectively enabling wireless discovery. We only discover if the device supports something. Add RSSI, Power, and Rate. Add these sensors for Ubnt Airos. Clean up some copyrights. Reduce the amount of files need to add new types. Leave graph files for consistency and to allow customization. Remove the old wifi clients graph completely. ciscowlc should have improved counts (total and per-ssid) Schema didn't get added. Impelement the rest of the AirOS sensors Reformat and re-organize the Airos.php class. Add several UBNT AirFiber sensors A few fixes add links to the section headers Add HP MSM mibs. * Schema file got dropped in rebase. * Add wireless menu to view sensors across all devices. Icons in the menu need help :/ * Add HeliOS, Mimosa, and Siklu support Sensors added SNR + Noise * Add power and utilization to Unifi * Update polling to prefetch all sensor data in a few snmp requests as possible * Add Extendair: tx+rx power, aggregate rate, frequency * Add a check for duplicate sensors in discovery. Just print an error for now. * Add Bit Error Ratio (named error-ratio to allow for bit error rate to be added if needed) Fix an incorrect link in the wireless sensors table * Add error rate and change all bps and Hz to use si units * Fixes to limits and frequency display * Fix overview graph frequency display A few decimal place tweaks * Don't allow switching sensor and wireless-sensor graphs, it doesn't work. Change individual distance graphs to use si units * Go through the OS and make sure I got all the sensors I can (probably missed some still) Because pollWirelessChannelAsFrequency() is generic and a little complex, so pull it up to OS. Message to help developers adding supports that don't return an array from discover functions. * Fix some issues * Remove noise and signal for now at least A couple more fixes Add a notification * Oopsie * Bonus AirFiber sensors
307 lines
9.7 KiB
PHP
307 lines
9.7 KiB
PHP
<?php
|
|
/**
|
|
* WirelessSensor.php
|
|
*
|
|
* Wireless Sensors
|
|
*
|
|
* 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 2017 Tony Murray
|
|
* @author Tony Murray <murraytony@gmail.com>
|
|
*/
|
|
|
|
namespace LibreNMS\Device;
|
|
|
|
use LibreNMS\OS;
|
|
|
|
class WirelessSensor extends Sensor
|
|
{
|
|
protected static $name = 'Wireless Sensor';
|
|
protected static $table = 'wireless_sensors';
|
|
protected static $data_name = 'wireless-sensor';
|
|
|
|
private $access_point_ip;
|
|
|
|
/**
|
|
* Sensor constructor. Create a new sensor to be discovered.
|
|
*
|
|
* @param string $type Class of this sensor, must be a supported class
|
|
* @param int $device_id the device_id of the device that owns this sensor
|
|
* @param array|string $oids an array or single oid that contains the data for this sensor
|
|
* @param string $subtype the type of sensor an additional identifier to separate out sensors of the same class, generally this is the os name
|
|
* @param int|string $index the index of this sensor, must be stable, generally the index of the oid
|
|
* @param string $description A user visible description of this sensor, may be truncated in some places (like graphs)
|
|
* @param int|float $current The current value of this sensor, will seed the db and may be used to guess limits
|
|
* @param int $multiplier a number to multiply the value(s) by
|
|
* @param int $divisor a number to divide the value(s) by
|
|
* @param string $aggregator an operation to combine multiple numbers. Supported: sum, avg
|
|
* @param int $access_point_id The id of the AP in the access_points sensor this belongs to (generally used for controllers)
|
|
* @param int|float $high_limit Alerting: Maximum value
|
|
* @param int|float $low_limit Alerting: Minimum value
|
|
* @param int|float $high_warn Alerting: High warning value
|
|
* @param int|float $low_warn Alerting: Low warning value
|
|
* @param int|float $entPhysicalIndex The entPhysicalIndex this sensor is associated, often a port
|
|
* @param int|float $entPhysicalMeasured the table to look for the entPhysicalIndex, for example 'ports' (maybe unused)
|
|
*/
|
|
public function __construct(
|
|
$type,
|
|
$device_id,
|
|
$oids,
|
|
$subtype,
|
|
$index,
|
|
$description,
|
|
$current = null,
|
|
$multiplier = 1,
|
|
$divisor = 1,
|
|
$aggregator = 'sum',
|
|
$access_point_id = null,
|
|
$high_limit = null,
|
|
$low_limit = null,
|
|
$high_warn = null,
|
|
$low_warn = null,
|
|
$entPhysicalIndex = null,
|
|
$entPhysicalMeasured = null
|
|
) {
|
|
$this->access_point_ip = $access_point_id;
|
|
parent::__construct(
|
|
$type,
|
|
$device_id,
|
|
$oids,
|
|
$subtype,
|
|
$index,
|
|
$description,
|
|
$current,
|
|
$multiplier,
|
|
$divisor,
|
|
$aggregator,
|
|
$high_limit,
|
|
$low_limit,
|
|
$high_warn,
|
|
$low_warn,
|
|
$entPhysicalIndex,
|
|
$entPhysicalMeasured
|
|
);
|
|
}
|
|
|
|
protected function toArray()
|
|
{
|
|
$sensor = parent::toArray();
|
|
$sensor['access_point_id'] = $this->access_point_ip;
|
|
return $sensor;
|
|
}
|
|
|
|
public static function discover(OS $os)
|
|
{
|
|
foreach (self::getTypes() as $type => $descr) {
|
|
static::discoverType($os, $type);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Return a list of valid types with metadata about each type
|
|
* $class => array(
|
|
* 'short' - short text for this class
|
|
* 'long' - long text for this class
|
|
* 'unit' - units used by this class 'dBm' for example
|
|
* 'icon' - font awesome icon used by this class
|
|
* )
|
|
* @param bool $valid filter this list by valid types in the database
|
|
* @param int $device_id when filtering, only return types valid for this device_id
|
|
* @return array
|
|
*/
|
|
public static function getTypes($valid = false, $device_id = null)
|
|
{
|
|
// Add new types here
|
|
// FIXME I'm really bad with icons, someone please help!
|
|
static $types = array(
|
|
'clients' => array(
|
|
'short' => 'Clients',
|
|
'long' => 'Client Count',
|
|
'unit' => '',
|
|
'icon' => 'tablet',
|
|
),
|
|
'quality' => array(
|
|
'short' => 'Quality',
|
|
'long' => 'Quality',
|
|
'unit' => '%',
|
|
'icon' => 'feed',
|
|
),
|
|
'capacity' => array(
|
|
'short' => 'Capacity',
|
|
'long' => 'Capacity',
|
|
'unit' => '%',
|
|
'icon' => 'feed',
|
|
),
|
|
'utilization' => array(
|
|
'short' => 'Utilization',
|
|
'long' => 'utilization',
|
|
'unit' => '%',
|
|
'icon' => 'percent',
|
|
),
|
|
'rate' => array(
|
|
'short' => 'Rate',
|
|
'long' => 'TX/RX Rate',
|
|
'unit' => 'bps',
|
|
'icon' => 'tachometer',
|
|
),
|
|
'ccq' => array(
|
|
'short' => 'CCQ',
|
|
'long' => 'Client Connection Quality',
|
|
'unit' => '%',
|
|
'icon' => 'wifi',
|
|
),
|
|
'snr' => array(
|
|
'short' => 'SNR',
|
|
'long' => 'Signal-to-Noise Ratio',
|
|
'unit' => 'dB',
|
|
'icon' => 'signal',
|
|
),
|
|
'rssi' => array(
|
|
'short' => 'RSSI',
|
|
'long' => 'Received Signal Strength Indicator',
|
|
'unit' => 'dBm',
|
|
'icon' => 'signal',
|
|
),
|
|
'power' => array(
|
|
'short' => 'Power/Signal',
|
|
'long' => 'TX/RX Power or Signal',
|
|
'unit' => 'dBm',
|
|
'icon' => 'bolt',
|
|
),
|
|
'noise-floor' => array(
|
|
'short' => 'Noise Floor',
|
|
'long' => 'Noise Floor',
|
|
'unit' => 'dBm/Hz',
|
|
'icon' => 'signal',
|
|
),
|
|
'error-ratio' => array(
|
|
'short' => 'Error Ratio',
|
|
'long' => 'Bit/Packet Error Ratio',
|
|
'unit' => '%',
|
|
'icon' => 'exclamation-triangle',
|
|
),
|
|
'error-rate' => array(
|
|
'short' => 'BER',
|
|
'long' => 'Bit Error Rate',
|
|
'unit' => 'bps',
|
|
'icon' => 'exclamation-triangle',
|
|
),
|
|
'frequency' => array(
|
|
'short' => 'Frequency',
|
|
'long' => 'Frequency',
|
|
'unit' => 'MHz',
|
|
'icon' => 'line-chart',
|
|
),
|
|
'distance' => array(
|
|
'short' => 'Distance',
|
|
'long' => 'Distance',
|
|
'unit' => 'km',
|
|
'icon' => 'space-shuttle',
|
|
),
|
|
);
|
|
|
|
if ($valid) {
|
|
$sql = 'SELECT `sensor_class` FROM `wireless_sensors`';
|
|
$params = array();
|
|
if (isset($device_id)) {
|
|
$sql .= ' WHERE `device_id`=?';
|
|
$params[] = $device_id;
|
|
}
|
|
$sql .= ' GROUP BY `sensor_class`';
|
|
|
|
$sensors = dbFetchColumn($sql, $params);
|
|
return array_intersect_key($types, array_flip($sensors));
|
|
}
|
|
|
|
return $types;
|
|
}
|
|
|
|
protected static function getDiscoveryInterface($type)
|
|
{
|
|
return str_to_class($type, 'LibreNMS\\Interfaces\\Discovery\\Sensors\\Wireless') . 'Discovery';
|
|
}
|
|
|
|
protected static function getDiscoveryMethod($type)
|
|
{
|
|
return 'discoverWireless' . str_to_class($type);
|
|
}
|
|
|
|
protected static function getPollingInterface($type)
|
|
{
|
|
return str_to_class($type, 'LibreNMS\\Interfaces\\Polling\\Sensors\\Wireless') . 'Polling';
|
|
}
|
|
|
|
protected static function getPollingMethod($type)
|
|
{
|
|
return 'pollWireless' . str_to_class($type);
|
|
}
|
|
|
|
/**
|
|
* Convert a WiFi channel to a Frequency in MHz
|
|
*
|
|
* @param $channel
|
|
* @return int
|
|
*/
|
|
public static function channelToFrequency($channel)
|
|
{
|
|
$channels = array(
|
|
1 => 2412,
|
|
2 => 2417,
|
|
3 => 2422,
|
|
4 => 2427,
|
|
5 => 2432,
|
|
6 => 2437,
|
|
7 => 2442,
|
|
8 => 2447,
|
|
9 => 2452,
|
|
10 => 2457,
|
|
11 => 2462,
|
|
12 => 2467,
|
|
13 => 2472,
|
|
14 => 2484,
|
|
34 => 5170,
|
|
36 => 5180,
|
|
38 => 5190,
|
|
40 => 5200,
|
|
42 => 5210,
|
|
44 => 5220,
|
|
46 => 5230,
|
|
48 => 5240,
|
|
52 => 5260,
|
|
56 => 5280,
|
|
60 => 5300,
|
|
64 => 5320,
|
|
100 => 5500,
|
|
104 => 5520,
|
|
108 => 5540,
|
|
112 => 5560,
|
|
116 => 5580,
|
|
120 => 5600,
|
|
124 => 5620,
|
|
128 => 5640,
|
|
132 => 5660,
|
|
136 => 5680,
|
|
140 => 5700,
|
|
149 => 5745,
|
|
153 => 5765,
|
|
157 => 5785,
|
|
161 => 5805,
|
|
);
|
|
|
|
return $channels[$channel];
|
|
}
|
|
}
|