feature: Wireless Sensors Overhaul (#6471)

* 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
This commit is contained in:
Tony Murray 2017-05-01 23:49:11 -05:00 committed by GitHub
parent ed432095e5
commit 4c0412b14d
176 changed files with 25344 additions and 4233 deletions

632
LibreNMS/Device/Sensor.php Normal file
View File

@ -0,0 +1,632 @@
<?php
/**
* Sensor.php
*
* Base Sensor class
*
* 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\Interfaces\Discovery\DiscoveryModule;
use LibreNMS\Interfaces\Polling\PollerModule;
use LibreNMS\OS;
use LibreNMS\RRD\RrdDefinition;
class Sensor implements DiscoveryModule, PollerModule
{
protected static $name = 'Sensor';
protected static $table = 'sensors';
protected static $data_name = 'sensor';
private $valid = true;
private $sensor_id;
private $type;
private $device_id;
private $oids;
private $subtype;
private $index;
private $description;
private $current;
private $multiplier;
private $divisor;
private $aggregator;
private $high_limit;
private $low_limit;
private $high_warn;
private $low_warn;
private $entPhysicalIndex;
private $entPhysicalMeasured;
/**
* 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|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',
$high_limit = null,
$low_limit = null,
$high_warn = null,
$low_warn = null,
$entPhysicalIndex = null,
$entPhysicalMeasured = null
) {
//
$this->type = $type;
$this->device_id = $device_id;
$this->oids = (array)$oids;
$this->subtype = $subtype;
$this->index = $index;
$this->description = $description;
$this->current = $current;
$this->multiplier = $multiplier;
$this->divisor = $divisor;
$this->aggregator = $aggregator;
$this->entPhysicalIndex = $entPhysicalIndex;
$this->entPhysicalMeasured = $entPhysicalMeasured;
$this->high_limit = $high_limit;
$this->low_limit = $low_limit;
$this->high_warn = $high_warn;
$this->low_warn = $low_warn;
$sensor = $this->toArray();
// validity not checked yet
if (is_null($this->current)) {
$sensor['sensor_oids'] = $this->oids;
$sensors = array($sensor);
$prefetch = self::fetchSnmpData(device_by_id_cache($device_id), $sensors);
$data = static::processSensorData($sensors, $prefetch);
$this->current = current($data);
$this->valid = is_numeric($this->current);
}
d_echo('Discovered ' . get_called_class() . ' ' . print_r($sensor, true));
}
/**
* Save this sensor to the database.
*
* @return int the sensor_id of this sensor in the database
*/
final public function save()
{
$db_sensor = $this->fetch();
$new_sensor = $this->toArray();
if ($db_sensor) {
unset($new_sensor['sensor_current']); // if updating, don't check sensor_current
$update = array_diff_assoc($new_sensor, $db_sensor);
if ($db_sensor['sensor_custom'] == 'Yes') {
unset($update['sensor_limit']);
unset($update['sensor_limit_warn']);
unset($update['sensor_limit_low']);
unset($update['sensor_limit_low_warn']);
}
if (empty($update)) {
echo '.';
} else {
dbUpdate($this->escapeNull($update), $this->getTable(), '`sensor_id`=?', array($this->sensor_id));
echo 'U';
}
} else {
$this->sensor_id = dbInsert($this->escapeNull($new_sensor), $this->getTable());
if ($this->sensor_id !== null) {
$name = static::$name;
$message = "$name Discovered: {$this->type} {$this->subtype} {$this->index} {$this->description}";
log_event($message, $this->device_id, static::$table, 3, $this->sensor_id);
echo '+';
}
}
return $this->sensor_id;
}
/**
* Fetch the sensor from the database.
* If it doesn't exist, returns null.
*
* @return array|null
*/
private function fetch()
{
$table = $this->getTable();
if (isset($this->sensor_id)) {
return dbFetchRow(
"SELECT `$table` FROM ? WHERE `sensor_id`=?",
array($this->sensor_id)
);
}
$sensor = dbFetchRow(
"SELECT * FROM `$table` " .
"WHERE `device_id`=? AND `sensor_class`=? AND `sensor_type`=? AND `sensor_index`=?",
array($this->device_id, $this->type, $this->subtype, $this->index)
);
$this->sensor_id = $sensor['sensor_id'];
return $sensor;
}
/**
* Get the table for this sensor
* @return string
*/
public function getTable()
{
return static::$table;
}
/**
* Get an array of this sensor with fields that line up with the database.
* Excludes sensor_id and current
*
* @return array
*/
protected function toArray()
{
return array(
'sensor_class' => $this->type,
'device_id' => $this->device_id,
'sensor_oids' => json_encode($this->oids),
'sensor_index' => $this->index,
'sensor_type' => $this->subtype,
'sensor_descr' => $this->description,
'sensor_divisor' => $this->divisor,
'sensor_multiplier' => $this->multiplier,
'sensor_aggregator' => $this->aggregator,
'sensor_limit' => $this->high_limit,
'sensor_limit_warn' => $this->high_warn,
'sensor_limit_low' => $this->low_limit,
'sensor_limit_low_warn' => $this->low_warn,
'sensor_current' => $this->current,
'entPhysicalIndex' => $this->entPhysicalIndex,
'entPhysicalIndex_measured' => $this->entPhysicalMeasured,
);
}
/**
* Escape null values so dbFacile doesn't mess them up
* honestly, this should be the default, but could break shit
*
* @param $array
* @return array
*/
private function escapeNull($array)
{
return array_map(function ($value) {
return is_null($value) ? array('NULL') : $value;
}, $array);
}
/**
* Run Sensors discovery for the supplied OS (device)
*
* @param OS $os
*/
public static function discover(OS $os)
{
// Add discovery types here
}
/**
* Poll sensors for the supplied OS (device)
*
* @param OS $os
*/
public static function poll(OS $os)
{
$table = static::$table;
// fetch and group sensors, decode oids
$sensors = array_reduce(
dbFetchRows("SELECT * FROM `$table` WHERE `device_id` = ?", array($os->getDeviceId())),
function ($carry, $sensor) {
$sensor['sensor_oids'] = json_decode($sensor['sensor_oids']);
$carry[$sensor['sensor_class']][] = $sensor;
return $carry;
},
array()
);
foreach ($sensors as $type => $type_sensors) {
// check for custom polling
$typeInterface = static::getPollingInterface($type);
if (!interface_exists($typeInterface)) {
echo "ERROR: Polling Interface doesn't exist! $typeInterface\n";
}
// fetch custom data
if ($os instanceof $typeInterface) {
unset($sensors[$type]); // remove from sensors array to prevent double polling
static::pollSensorType($os, $type, $type_sensors);
}
}
// pre-fetch all standard sensors
$standard_sensors = call_user_func_array('array_merge', $sensors);
$pre_fetch = self::fetchSnmpData($os->getDevice(), $standard_sensors);
// poll standard sensors
foreach ($sensors as $type => $type_sensors) {
static::pollSensorType($os, $type, $type_sensors, $pre_fetch);
}
}
/**
* Poll all sensors of a specific class
*
* @param OS $os
* @param string $type
* @param array $sensors
* @param array $prefetch
*/
protected static function pollSensorType($os, $type, $sensors, $prefetch = array())
{
echo "$type:\n";
// process data or run custom polling
$typeInterface = static::getPollingInterface($type);
if ($os instanceof $typeInterface) {
d_echo("Using OS polling for $type\n");
$function = static::getPollingMethod($type);
$data = $os->$function($sensors);
} else {
$data = static::processSensorData($sensors, $prefetch);
}
d_echo($data);
self::recordSensorData($os, $sensors, $data);
}
/**
* Fetch snmp data from the device
* Return an array keyed by oid
*
* @param array $device
* @param array $sensors
* @return array
*/
private static function fetchSnmpData($device, $sensors)
{
$oids = self::getOidsFromSensors($sensors, get_device_oid_limit($device));
$snmp_data = array();
foreach ($oids as $oid_chunk) {
$multi_data = snmp_get_multi_oid($device, $oid_chunk, '-OUQnt');
$snmp_data = array_merge($snmp_data, $multi_data);
}
// deal with string values that may be surrounded by quotes
array_walk($snmp_data, function (&$oid) {
$oid = trim($oid, '"') + 0;
});
return $snmp_data;
}
/**
* Process the snmp data for the specified sensors
* Returns an array sensor_id => value
*
* @param $sensors
* @param $prefetch
* @return array
* @internal param $device
*/
protected static function processSensorData($sensors, $prefetch)
{
$sensor_data = array();
foreach ($sensors as $sensor) {
// pull out the data for this sensor
$requested_oids = array_flip($sensor['sensor_oids']);
$data = array_intersect_key($prefetch, $requested_oids);
// if no data set null and continue to the next sensor
if (empty($data)) {
$data[$sensor['sensor_id']] = null;
continue;
}
if (count($data) > 1) {
// aggregate data
if ($sensor['sensor_aggregator'] == 'avg') {
$sensor_value = array_sum($data) / count($data);
} else {
// sum
$sensor_value = array_sum($data);
}
} else {
$sensor_value = current($data);
}
if ($sensor['sensor_divisor'] && $sensor_value !== 0) {
$sensor_value = ($sensor_value / $sensor['sensor_divisor']);
}
if ($sensor['sensor_multiplier']) {
$sensor_value = ($sensor_value * $sensor['sensor_multiplier']);
}
$sensor_data[$sensor['sensor_id']] = $sensor_value;
}
return $sensor_data;
}
/**
* Get a list of unique oids from an array of sensors and break it into chunks.
*
* @param $sensors
* @param int $chunk How many oids per chunk. Default 10.
* @return array
*/
private static function getOidsFromSensors($sensors, $chunk = 10)
{
// Sort the incoming oids and sensors
$oids = array_reduce($sensors, function ($carry, $sensor) {
return array_merge($carry, $sensor['sensor_oids']);
}, array());
// only unique oids and chunk
$oids = array_chunk(array_keys(array_flip($oids)), $chunk);
return $oids;
}
protected static function discoverType(OS $os, $type)
{
echo "$type: ";
$typeInterface = static::getDiscoveryInterface($type);
if (!interface_exists($typeInterface)) {
echo "ERROR: Discovery Interface doesn't exist! $typeInterface\n";
}
if ($os instanceof $typeInterface) {
$function = static::getDiscoveryMethod($type);
$sensors = $os->$function();
if (!is_array($sensors)) {
c_echo("%RERROR:%n $function did not return an array! Skipping discovery.");
$sensors = array();
}
} else {
$sensors = array(); // delete non existent sensors
}
self::checkForDuplicateSensors($sensors);
self::sync($os->getDeviceId(), $type, $sensors);
echo PHP_EOL;
}
private static function checkForDuplicateSensors($sensors)
{
$duplicate_check = array();
$dup = false;
foreach ($sensors as $sensor) {
/** @var Sensor $sensor */
$key = $sensor->getUniqueId();
if (isset($duplicate_check[$key])) {
c_echo("%R ERROR:%n A sensor already exists at this index $key ");
$dup = true;
}
$duplicate_check[$key] = 1;
}
return $dup;
}
/**
* Returns a string that must be unique for each sensor
* type (class), subtype (type), index (index)
*
* @return string
*/
private function getUniqueId()
{
return $this->type . '-' . $this->subtype . '-' . $this->index;
}
protected static function getDiscoveryInterface($type)
{
return str_to_class($type, 'LibreNMS\\Interfaces\\Discovery\\Sensors\\') . 'Discovery';
}
protected static function getDiscoveryMethod($type)
{
return 'discover' . str_to_class($type);
}
protected static function getPollingInterface($type)
{
return str_to_class($type, 'LibreNMS\\Interfaces\\Polling\\Sensors\\') . 'Polling';
}
protected static function getPollingMethod($type)
{
return 'poll' . str_to_class($type);
}
/**
* Is this sensor valid?
* If not, it should not be added to or in the database
*
* @return bool
*/
public function isValid()
{
return $this->valid;
}
/**
* Save sensors and remove invalid sensors
* This the sensors array should contain all the sensors of a specific class
* It may contain sensors from multiple tables and devices, but that isn't the primary use
*
* @param int $device_id
* @param string $type
* @param array $sensors
*/
final public static function sync($device_id, $type, array $sensors)
{
// save and collect valid ids
$valid_sensor_ids = array();
foreach ($sensors as $sensor) {
/** @var $this $sensor */
if ($sensor->isValid()) {
$valid_sensor_ids[] = $sensor->save();
}
}
// delete invalid sensors
self::clean($device_id, $type, $valid_sensor_ids);
}
/**
* Remove invalid sensors. Passing an empty array will remove all sensors of that class
*
* @param int $device_id
* @param string $type
* @param array $sensor_ids valid sensor ids
*/
private static function clean($device_id, $type, $sensor_ids)
{
$table = static::$table;
$params = array($device_id, $type);
$where = '`device_id`=? AND `sensor_class`=? AND `sensor_id`';
if (!empty($sensor_ids)) {
$where .= ' NOT IN ' . dbGenPlaceholders(count($sensor_ids));
$params = array_merge($params, $sensor_ids);
}
$delete = dbFetchRows("SELECT * FROM `$table` WHERE $where", $params);
foreach ($delete as $sensor) {
echo '-';
$message = static::$name;
$message .= " Deleted: $type {$sensor['sensor_type']} {$sensor['sensor_index']} {$sensor['sensor_descr']}";
log_event($message, $device_id, static::$table, 3, $sensor['sensor_id']);
}
if (!empty($delete)) {
dbDelete($table, $where, $params);
}
}
/**
* 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)
{
return array();
}
/**
* Record sensor data in the database and data stores
*
* @param $os
* @param $sensors
* @param $data
*/
protected static function recordSensorData(OS $os, $sensors, $data)
{
$types = static::getTypes();
foreach ($sensors as $sensor) {
$sensor_value = $data[$sensor['sensor_id']];
echo " {$sensor['sensor_descr']}: $sensor_value {$types[$sensor['sensor_class']]['unit']}\n";
// update rrd and database
$rrd_name = array(
static::$data_name,
$sensor['sensor_class'],
$sensor['sensor_type'],
$sensor['sensor_index']
);
$rrd_def = RrdDefinition::make()->addDataset('sensor', 'GAUGE');
$fields = array(
'sensor' => isset($sensor_value) ? $sensor_value : 'U',
);
$tags = array(
'sensor_class' => $sensor['sensor_class'],
'sensor_type' => $sensor['sensor_type'],
'sensor_descr' => $sensor['sensor_descr'],
'sensor_index' => $sensor['sensor_index'],
'rrd_name' => $rrd_name,
'rrd_def' => $rrd_def
);
data_update($os->getDevice(), static::$data_name, $tags, $fields);
$update = array(
'sensor_prev' => $sensor['sensor_current'],
'sensor_current' => $sensor_value,
'lastupdate' => array('NOW()'),
);
dbUpdate($update, static::$table, "`sensor_id` = ?", array($sensor['sensor_id']));
}
}
}

View File

@ -0,0 +1,306 @@
<?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];
}
}

View File

@ -0,0 +1,33 @@
<?php
/**
* DiscoveryModule.php
*
* LibreNMS Discovery Module
*
* 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\Interfaces\Discovery;
use LibreNMS\OS;
interface DiscoveryModule
{
public static function discover(OS $os);
}

View File

@ -0,0 +1,37 @@
<?php
/**
* WirelessCapacityDiscovery.php
*
* Discover Capacity Sensors as a percent
*
* 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\Interfaces\Discovery\Sensors;
interface WirelessCapacityDiscovery
{
/**
* Discover wireless capacity. This is a percent. Type is capacity.
* Returns an array of LibreNMS\Device\Sensor objects that have been discovered
*
* @return array Sensors
*/
public function discoverWirelessCapacity();
}

View File

@ -0,0 +1,37 @@
<?php
/**
* WirelessCcqDiscovery.php
*
* Discover Client Connection Quality Sensors as a percent
*
* 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\Interfaces\Discovery\Sensors;
interface WirelessCcqDiscovery
{
/**
* Discover wireless client connection quality. This is a percent. Type is ccq.
* Returns an array of LibreNMS\Device\Sensor objects that have been discovered
*
* @return array Sensors
*/
public function discoverWirelessCcq();
}

View File

@ -0,0 +1,37 @@
<?php
/**
* WirelessClients.php
*
* Discover wireless client count 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\Interfaces\Discovery\Sensors;
interface WirelessClientsDiscovery
{
/**
* 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();
}

View File

@ -0,0 +1,37 @@
<?php
/**
* WirelessDistanceDiscovery.php
*
* Discover Distance Sensors in kilometers
*
* 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\Interfaces\Discovery\Sensors;
interface WirelessDistanceDiscovery
{
/**
* Discover wireless distance. This is in Kilometers. Type is distance.
* Returns an array of LibreNMS\Device\Sensor objects that have been discovered
*
* @return array Sensors
*/
public function discoverWirelessDistance();
}

View File

@ -0,0 +1,37 @@
<?php
/**
* WirelessErrorRateDiscovery.php
*
* Discover bit error rate sensors in bps
*
* 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\Interfaces\Discovery\Sensors;
interface WirelessErrorRateDiscovery
{
/**
* Discover wireless bit error rate. This is in bps. Type is error-ratio.
* Returns an array of LibreNMS\Device\Sensor objects that have been discovered
*
* @return array Sensors
*/
public function discoverWirelessErrorRate();
}

View File

@ -0,0 +1,37 @@
<?php
/**
* WirelessErrorRatioDiscovery.php
*
* Discover bit/packet error ratio sensors in percent
*
* 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\Interfaces\Discovery\Sensors;
interface WirelessErrorRatioDiscovery
{
/**
* Discover wireless bit/packet error ratio. This is in percent. Type is error-ratio.
* Returns an array of LibreNMS\Device\Sensor objects that have been discovered
*
* @return array Sensors
*/
public function discoverWirelessErrorRatio();
}

View File

@ -0,0 +1,37 @@
<?php
/**
* WirelessFrequencyDiscovery.php
*
* Discover Frequency Sensors as MHz
*
* 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\Interfaces\Discovery\Sensors;
interface WirelessFrequencyDiscovery
{
/**
* 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();
}

View File

@ -0,0 +1,37 @@
<?php
/**
* WirelessNoiseFloorDiscovery.php
*
* Discover Noise Floor sensors in dBm/Hz
*
* 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\Interfaces\Discovery\Sensors;
interface WirelessNoiseFloorDiscovery
{
/**
* 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();
}

View File

@ -0,0 +1,37 @@
<?php
/**
* WirelessPowerDiscovery.php
*
* Discover TX or RX power sensors in dBm
*
* 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\Interfaces\Discovery\Sensors;
interface WirelessPowerDiscovery
{
/**
* 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();
}

View File

@ -0,0 +1,37 @@
<?php
/**
* WirelessQualityDiscovery.php
*
* Discover Quality Sensors as a percent
*
* 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\Interfaces\Discovery\Sensors;
interface WirelessQualityDiscovery
{
/**
* Discover wireless quality. This is a percent. Type is quality.
* Returns an array of LibreNMS\Device\Sensor objects that have been discovered
*
* @return array Sensors
*/
public function discoverWirelessQuality();
}

View File

@ -0,0 +1,37 @@
<?php
/**
* WirelessRateDiscovery.php
*
* Discover wireless rate sensors in bits per second
*
* 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\Interfaces\Discovery\Sensors;
interface WirelessRateDiscovery
{
/**
* Discover wireless rate. This is in bps. Type is rate.
* Returns an array of LibreNMS\Device\Sensor objects that have been discovered
*
* @return array
*/
public function discoverWirelessRate();
}

View File

@ -0,0 +1,37 @@
<?php
/**
* WirelessRssiDiscovery.php
*
* Discover wireless RSSI (Received Signal Strength Indicator) sensors in dBm
*
* 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\Interfaces\Discovery\Sensors;
interface WirelessRssiDiscovery
{
/**
* Discover wireless RSSI (Received Signal Strength Indicator). This is in dBm. Type is rssi.
* Returns an array of LibreNMS\Device\Sensor objects that have been discovered
*
* @return array
*/
public function discoverWirelessRssi();
}

View File

@ -0,0 +1,38 @@
<?php
/**
* WirelessSnrDiscovery.php
*
* Discover wireless Signal-to-Noise Ratio sensors in dB
*
* 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\Interfaces\Discovery\Sensors;
interface WirelessSnrDiscovery
{
/**
* Discover wireless SNR. This is in dB. Type is snr.
* Formula: SNR = Signal or Rx Power - Noise Floor
* Returns an array of LibreNMS\Device\Sensor objects that have been discovered
*
* @return array Sensors
*/
public function discoverWirelessSnr();
}

View File

@ -0,0 +1,37 @@
<?php
/**
* WirelessUtilizationDiscovery.php
*
* Discover wireless utilization sensors in percent
*
* 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\Interfaces\Discovery\Sensors;
interface WirelessUtilizationDiscovery
{
/**
* 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();
}

View File

@ -0,0 +1,33 @@
<?php
/**
* PollerModule.php
*
* LibreNMS Poller Module
*
* 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\Interfaces\Polling;
use LibreNMS\OS;
interface PollerModule
{
public static function poll(OS $os);
}

View File

@ -0,0 +1,38 @@
<?php
/**
* WirelessCapacityPolling.php
*
* Custom polling interface for wireless capacity
*
* 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\Interfaces\Polling\Sensors;
interface WirelessCapacityPolling
{
/**
* Poll wireless capacity as a percent
* 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 pollWirelessCapacity(array $sensors);
}

View File

@ -0,0 +1,38 @@
<?php
/**
* WirelessCcqPolling.php
*
* Custom polling interface for Client Connection Quality
*
* 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\Interfaces\Polling\Sensors;
interface WirelessCcqPolling
{
/**
* Poll wireless client connection quality as a percent
* 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 pollWirelessCcq(array $sensors);
}

View File

@ -0,0 +1,38 @@
<?php
/**
* WirelessClientsPolling.php
*
* Custom polling interface for wireless client counts
*
* 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\Interfaces\Polling\Sensors;
interface WirelessClientsPolling
{
/**
* Poll wireless client counts
* 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);
}

View File

@ -0,0 +1,38 @@
<?php
/**
* WirelessDistancePolling.php
*
* Custom polling interface for wireless distance
*
* 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\Interfaces\Polling\Sensors;
interface WirelessDistancePolling
{
/**
* Poll wireless frequency as kilometers
* 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 pollWirelessDistance(array $sensors);
}

View File

@ -0,0 +1,38 @@
<?php
/**
* WirelessErrorRatePolling.php
*
* Custom polling interface for wireless bit error rate in bps
*
* 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\Interfaces\Polling\Sensors;
interface WirelessErrorRatePolling
{
/**
* Poll wireless bit error rate as bps
* 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 pollWirelessErrorRatio(array $sensors);
}

View File

@ -0,0 +1,38 @@
<?php
/**
* WirlessErrorRatioPolling.php
*
* Custom polling interface for wireless bit/packet error ratio
*
* 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\Interfaces\Polling\Sensors;
interface WirelessErrorRatioPolling
{
/**
* Poll wireless bit/packet error ratio as percent
* 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 pollWirelessErrorRatio(array $sensors);
}

View File

@ -0,0 +1,38 @@
<?php
/**
* WirelessFrequencyPolling.php
*
* Custom polling interface for wireless frequency
*
* 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\Interfaces\Polling\Sensors;
interface WirelessFrequencyPolling
{
/**
* 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);
}

View File

@ -0,0 +1,38 @@
<?php
/**
* WirelessNoiseFloorPolling.php
*
* Custom polling interface for wireless noise floor
*
* 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\Interfaces\Polling\Sensors;
interface WirelessNoiseFloorPolling
{
/**
* Poll wireless noise floor
* 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 pollWirelessNoiseFloor(array $sensors);
}

View File

@ -0,0 +1,38 @@
<?php
/**
* WirelessPowerPolling.php
*
* Custom polling interface for wireless tx or rx power
*
* 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\Interfaces\Polling\Sensors;
interface WirelessPowerPolling
{
/**
* Poll wireless tx or rx power
* 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 pollWirelessPower(array $sensors);
}

View File

@ -0,0 +1,38 @@
<?php
/**
* WirelessQualityPolling.php
*
* Custom polling interface for wireless quality
*
* 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\Interfaces\Polling\Sensors;
interface WirelessQualityPolling
{
/**
* Poll wireless quality as a percent
* 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 pollWirelessQuality(array $sensors);
}

View File

@ -0,0 +1,38 @@
<?php
/**
* WirelessRatePolling.php
*
* Custom polling interface for wireless rates
*
* 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\Interfaces\Polling\Sensors;
interface WirelessRatePolling
{
/**
* Poll wireless rates in bps
* 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 pollWirelessRate(array $sensors);
}

View File

@ -0,0 +1,38 @@
<?php
/**
* WirelessRssiPolling.php
*
* Custom polling interface for wireless RSSI (Received Signal Strength Indicator)
*
* 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\Interfaces\Polling\Sensors;
interface WirelessRssiPolling
{
/**
* Poll wireless RSSI (Received Signal Strength Indicator) in dBm
* 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 pollWirelessRssi(array $sensors);
}

View File

@ -0,0 +1,38 @@
<?php
/**
* WirelessSnrPolling.php
*
* Custom polling interface for wireless Signal-to-Noise Ratio
*
* 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\Interfaces\Polling\Sensors;
interface WirelessSnrPolling
{
/**
* Poll wireless SNR in dB
* 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 pollWirelessSnr(array $sensors);
}

View File

@ -0,0 +1,38 @@
<?php
/**
* WirelessUtilizationPolling.php
*
* Custom polling interface for wireless utilization
*
* 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\Interfaces\Polling\Sensors;
interface WirelessUtilizationPolling
{
/**
* Poll wireless utilization
* 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 pollWirelessUtilization(array $sensors);
}

135
LibreNMS/OS.php Normal file
View File

@ -0,0 +1,135 @@
<?php
/**
* OS.php
*
* Base OS class
*
* 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;
use LibreNMS\Device\Discovery\Sensors\WirelessSensorDiscovery;
use LibreNMS\Device\Discovery\Sensors\WirelessSensorPolling;
use LibreNMS\Device\WirelessSensor;
use LibreNMS\OS\Generic;
class OS
{
private $device; // annoying use of references to make sure this is in sync with global $device variable
/**
* OS constructor. Not allowed to be created directly. Use OS::make()
* @param $device
*/
private function __construct(&$device)
{
$this->device = &$device;
}
/**
* Get the device array that owns this OS instance
*
* @return array
*/
public function &getDevice()
{
return $this->device;
}
/**
* Get the device_id of the device that owns this OS instance
*
* @return int
*/
public function getDeviceId()
{
return (int)$this->device['device_id'];
}
/**
* Snmpwalk the specified oid and return an array of the data indexed by the oid index.
* If the data is cached, return the cached data.
* DO NOT use numeric oids with this function! The snmp result must contain only one oid.
*
* @param string $oid textual oid
* @param string $mib mib for this oid
* @return array array indexed by the snmp index with the value as the data returned by snmp
* @throws \Exception
*/
protected function getCacheByIndex($oid, $mib = null)
{
if (str_contains($oid, '.')) {
throw new \Exception('Error: don\'t use this with numeric oids');
}
if (!isset($this->$oid)) {
$data = snmp_cache_oid($oid, $this->getDevice(), array(), $mib);
$this->$oid = array_map('current', $data);
}
return $this->$oid;
}
/**
* OS Factory, returns an instance of the OS for this device
* If no specific OS is found, returns Generic
*
* @param array $device device array, must have os set
* @return OS
*/
public static function make(&$device)
{
$class = str_to_class($device['os'], 'LibreNMS\\OS\\');
d_echo('Attempting to initialize OS: ' . $device['os'] . PHP_EOL);
if (class_exists($class)) {
d_echo("OS initialized: $class\n");
return new $class($device);
}
return new Generic($device);
}
/**
* Poll a channel based OID, but return data in MHz
*
* @param $sensors
* @return array
*/
protected function pollWirelessChannelAsFrequency($sensors)
{
if (empty($sensors)) {
return array();
}
$oids = array();
foreach ($sensors as $sensor) {
$oids[$sensor['sensor_id']] = current($sensor['sensor_oids']);
}
$snmp_data = snmp_get_multi_oid($this->getDevice(), $oids);
$data = array();
foreach ($oids as $id => $oid) {
$data[$id] = WirelessSensor::channelToFrequency($snmp_data[$oid]);
}
return $data;
}
}

211
LibreNMS/OS/Airos.php Normal file
View File

@ -0,0 +1,211 @@
<?php
/**
* Airos.php
*
* Ubiquiti AirOS
*
* 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\OS;
use LibreNMS\Device\WirelessSensor;
use LibreNMS\Interfaces\Discovery\Sensors\WirelessCapacityDiscovery;
use LibreNMS\Interfaces\Discovery\Sensors\WirelessCcqDiscovery;
use LibreNMS\Interfaces\Discovery\Sensors\WirelessClientsDiscovery;
use LibreNMS\Interfaces\Discovery\Sensors\WirelessDistanceDiscovery;
use LibreNMS\Interfaces\Discovery\Sensors\WirelessFrequencyDiscovery;
use LibreNMS\Interfaces\Discovery\Sensors\WirelessNoiseFloorDiscovery;
use LibreNMS\Interfaces\Discovery\Sensors\WirelessPowerDiscovery;
use LibreNMS\Interfaces\Discovery\Sensors\WirelessQualityDiscovery;
use LibreNMS\Interfaces\Discovery\Sensors\WirelessRateDiscovery;
use LibreNMS\Interfaces\Discovery\Sensors\WirelessRssiDiscovery;
use LibreNMS\OS;
class Airos extends OS implements
WirelessCapacityDiscovery,
WirelessCcqDiscovery,
WirelessClientsDiscovery,
WirelessDistanceDiscovery,
WirelessFrequencyDiscovery,
WirelessNoiseFloorDiscovery,
WirelessPowerDiscovery,
WirelessQualityDiscovery,
WirelessRateDiscovery,
WirelessRssiDiscovery
{
/**
* Discover wireless frequency. This is in Hz. Type is frequency.
* Returns an array of LibreNMS\Device\Sensor objects that have been discovered
*
* @return array Sensors
*/
public function discoverWirelessFrequency()
{
$oid = '.1.3.6.1.4.1.41112.1.4.1.1.4.1'; //UBNT-AirMAX-MIB::ubntRadioFreq.1
return array(
new WirelessSensor('frequency', $this->getDeviceId(), $oid, 'airos', 1, 'Radio Frequency'),
);
}
/**
* Discover wireless capacity. This is a percent. Type is capacity.
* Returns an array of LibreNMS\Device\Sensor objects that have been discovered
*
* @return array Sensors
*/
public function discoverWirelessCapacity()
{
$oid = '.1.3.6.1.4.1.41112.1.4.6.1.4.1'; //UBNT-AirMAX-MIB::ubntAirMaxCapacity.1
return array(
new WirelessSensor('capacity', $this->getDeviceId(), $oid, 'airos', 1, 'airMAX Capacity'),
);
}
/**
* Discover wireless client connection quality. This is a percent. Type is ccq.
* Returns an array of LibreNMS\Device\Sensor objects that have been discovered
*
* @return array Sensors
*/
public function discoverWirelessCcq()
{
$oid = '.1.3.6.1.4.1.41112.1.4.5.1.7.1'; //UBNT-AirMAX-MIB::ubntWlStatCcq.1
return array(
new WirelessSensor('ccq', $this->getDeviceId(), $oid, 'airos', 1, 'CCQ'),
);
}
/**
* 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()
{
$oid = '.1.3.6.1.4.1.41112.1.4.5.1.15.1'; //UBNT-AirMAX-MIB::ubntWlStatStaCount.1
return array(
new WirelessSensor('clients', $this->getDeviceId(), $oid, 'airos', 1, 'Clients'),
);
}
/**
* Discover wireless distance. This is in kilometers. Type is distance.
* Returns an array of LibreNMS\Device\Sensor objects that have been discovered
*
* @return array Sensors
*/
public function discoverWirelessDistance()
{
$oid = '.1.3.6.1.4.1.41112.1.4.1.1.7.1'; //UBNT-AirMAX-MIB::ubntRadioDistance.1
return array(
new WirelessSensor('distance', $this->getDeviceId(), $oid, 'airos', 1, 'Distance', null, 1, 1000),
);
}
/**
* 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()
{
$oid = '.1.3.6.1.4.1.41112.1.4.5.1.8.1'; //UBNT-AirMAX-MIB::ubntWlStatNoiseFloor.1
return array(
new WirelessSensor('noise-floor', $this->getDeviceId(), $oid, 'airos', 1, 'Noise Floor'),
);
}
/**
* 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()
{
$tx_oid = '.1.3.6.1.4.1.41112.1.4.1.1.6.1'; //UBNT-AirMAX-MIB::ubntRadioTxPower.1
$rx_oid = '.1.3.6.1.4.1.41112.1.4.5.1.5.1'; //UBNT-AirMAX-MIB::ubntWlStatSignal.1
return array(
new WirelessSensor('power', $this->getDeviceId(), $tx_oid, 'airos-tx', 1, 'Tx Power'),
new WirelessSensor('power', $this->getDeviceId(), $rx_oid, 'airos-rx', 1, 'Signal Level'),
);
}
/**
* Discover wireless quality. This is a percent. Type is quality.
* Returns an array of LibreNMS\Device\Sensor objects that have been discovered
*
* @return array Sensors
*/
public function discoverWirelessQuality()
{
$oid = '.1.3.6.1.4.1.41112.1.4.6.1.3.1'; //UBNT-AirMAX-MIB::ubntAirMaxQuality.1
return array(
new WirelessSensor('quality', $this->getDeviceId(), $oid, 'airos', 1, 'airMAX Quality'),
);
}
/**
* Discover wireless rate. This is in bps. Type is rate.
* Returns an array of LibreNMS\Device\Sensor objects that have been discovered
*
* @return array
*/
public function discoverWirelessRate()
{
$tx_oid = '.1.3.6.1.4.1.41112.1.4.5.1.9.1'; //UBNT-AirMAX-MIB::ubntWlStatTxRate.1
$rx_oid = '.1.3.6.1.4.1.41112.1.4.5.1.10.1'; //UBNT-AirMAX-MIB::ubntWlStatRxRate.1
return array(
new WirelessSensor('rate', $this->getDeviceId(), $tx_oid, 'airos-tx', 1, 'Tx Rate'),
new WirelessSensor('rate', $this->getDeviceId(), $rx_oid, 'airos-rx', 1, 'Rx Rate'),
);
}
/**
* Discover wireless RSSI (Received Signal Strength Indicator). This is in dBm. Type is rssi.
* Returns an array of LibreNMS\Device\Sensor objects that have been discovered
*
* @return array
*/
public function discoverWirelessRssi()
{
$oid = '.1.3.6.1.4.1.41112.1.4.5.1.6.1'; //UBNT-AirMAX-MIB::ubntWlStatRssi.1
$sensors = array(
new WirelessSensor('rssi', $this->getDeviceId(), $oid, 'airos', 0, 'Overall RSSI')
);
$data = snmpwalk_cache_oid($this->getDevice(), 'ubntRadioRssi', array(), 'UBNT-AirMAX-MIB');
foreach ($data as $index => $entry) {
$sensors[] = new WirelessSensor(
'rssi',
$this->getDeviceId(),
'.1.3.6.1.4.1.41112.1.4.2.1.2.' . $index,
'airos',
$index,
'RSSI: Chain ' . str_replace('1.', '', $index),
$entry['ubntRadioRssi.1']
);
}
return $sensors;
}
}

120
LibreNMS/OS/AirosAf.php Normal file
View File

@ -0,0 +1,120 @@
<?php
/**
* AirosAf.php
*
* Ubiquiti AirFiber
*
* 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\OS;
use LibreNMS\Device\WirelessSensor;
use LibreNMS\Interfaces\Discovery\Sensors\WirelessDistanceDiscovery;
use LibreNMS\Interfaces\Discovery\Sensors\WirelessFrequencyDiscovery;
use LibreNMS\Interfaces\Discovery\Sensors\WirelessPowerDiscovery;
use LibreNMS\Interfaces\Discovery\Sensors\WirelessRateDiscovery;
use LibreNMS\OS;
class AirosAf extends OS implements
WirelessFrequencyDiscovery,
WirelessPowerDiscovery,
WirelessDistanceDiscovery,
WirelessRateDiscovery
{
/**
* Discover wireless distance. This is in Kilometers. Type is distance.
* Returns an array of LibreNMS\Device\Sensor objects that have been discovered
*
* @return array Sensors
*/
public function discoverWirelessDistance()
{
$oid = '.1.3.6.1.4.1.41112.1.3.2.1.4.1'; // UBNT-AirFIBER-MIB::radioLinkDistM.1
return array(
new WirelessSensor('distance', $this->getDeviceId(), $oid, 'airos-af', 1, 'Distance', null, 1, 1000)
);
}
/**
* Discover wireless frequency. This is in GHz. Type is frequency.
* Returns an array of LibreNMS\Device\Sensor objects that have been discovered
*
* @return array Sensors
*/
public function discoverWirelessFrequency()
{
$tx_oid = '.1.3.6.1.4.1.41112.1.3.1.1.5.1'; // UBNT-AirFIBER-MIB::txFrequency.1
$rx_oid = '.1.3.6.1.4.1.41112.1.3.1.1.6.1'; // UBNT-AirFIBER-MIB::rxFrequency.1
return array(
new WirelessSensor(
'frequency',
$this->getDeviceId(),
$tx_oid,
'airos-af-tx',
1,
'Tx Frequency'
),
new WirelessSensor(
'frequency',
$this->getDeviceId(),
$rx_oid,
'airos-af-rx',
1,
'Rx Frequency'
),
);
}
/**
* 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()
{
$tx_oid = '.1.3.6.1.4.1.41112.1.3.1.1.9.1'; // UBNT-AirFIBER-MIB::txPower.1
$rx0_oid = '.1.3.6.1.4.1.41112.1.3.2.1.11.1'; // UBNT-AirFIBER-MIB::rxPower0.1
$rx1_oid = '.1.3.6.1.4.1.41112.1.3.2.1.14.1'; // UBNT-AirFIBER-MIB::rxPower1.1
return array(
new WirelessSensor('power', $this->getDeviceId(), $tx_oid, 'airos-af-tx', 1, 'Tx Power'),
new WirelessSensor('power', $this->getDeviceId(), $rx0_oid, 'airos-af-rx', 0, 'Rx Chain 0 Power'),
new WirelessSensor('power', $this->getDeviceId(), $rx1_oid, 'airos-af-rx', 1, 'Rx Chain 1 Power'),
);
}
/**
* Discover wireless rate. This is in Mbps. Type is rate.
* Returns an array of LibreNMS\Device\Sensor objects that have been discovered
*
* @return array
*/
public function discoverWirelessRate()
{
$tx_oid = '.1.3.6.1.4.1.41112.1.3.2.1.6.1'; // UBNT-AirFIBER-MIB::txCapacity.1
$rx_oid = '.1.3.6.1.4.1.41112.1.3.2.1.5.1'; // UBNT-AirFIBER-MIB::rxCapacity.1
return array(
new WirelessSensor('rate', $this->getDeviceId(), $tx_oid, 'airos-tx', 1, 'Tx Capacity'),
new WirelessSensor('rate', $this->getDeviceId(), $rx_oid, 'airos-rx', 1, 'Rx Capacity'),
);
}
}

47
LibreNMS/OS/Airport.php Normal file
View File

@ -0,0 +1,47 @@
<?php
/**
* Airport.php
*
* Apple Airport
*
* 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\OS;
use LibreNMS\Device\WirelessSensor;
use LibreNMS\Interfaces\Discovery\Sensors\WirelessClientsDiscovery;
use LibreNMS\OS;
class Airport extends OS implements WirelessClientsDiscovery
{
/**
* 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()
{
$oid = '.1.3.6.1.4.1.63.501.3.2.1.0'; //AIRPORT-BASESTATION-3-MIB::wirelessNumber.0
return array(
new WirelessSensor('clients', $this->getDeviceId(), $oid, 'airport', 0, 'Clients')
);
}
}

47
LibreNMS/OS/Arubaos.php Normal file
View File

@ -0,0 +1,47 @@
<?php
/**
* Arubaos.php
*
* HPE ArubaOS
*
* 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\OS;
use LibreNMS\Device\WirelessSensor;
use LibreNMS\Interfaces\Discovery\Sensors\WirelessClientsDiscovery;
use LibreNMS\OS;
class Arubaos extends OS implements WirelessClientsDiscovery
{
/**
* 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()
{
$oid = '.1.3.6.1.4.1.14823.2.2.1.1.3.2'; // WLSX-SWITCH-MIB::wlsxSwitchTotalNumStationsAssociated
return array(
new WirelessSensor('clients', $this->getDeviceId(), $oid, 'arubaos', 1, 'Clients')
);
}
}

78
LibreNMS/OS/Ciscowlc.php Normal file
View File

@ -0,0 +1,78 @@
<?php
/**
* Ciscowlc.php
*
* Cisco Wireless LAN Controller
*
* 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\OS;
use LibreNMS\Device\WirelessSensor;
use LibreNMS\Interfaces\Discovery\Sensors\WirelessClientsDiscovery;
use LibreNMS\OS;
class Ciscowlc extends OS implements WirelessClientsDiscovery
{
/**
* 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()
{
$ssids = $this->getCacheByIndex('bsnDot11EssSsid', 'AIRESPACE-WIRELESS-MIB');
$counts = $this->getCacheByIndex('bsnDot11EssNumberOfMobileStations', 'AIRESPACE-WIRELESS-MIB');
$sensors = array();
$total_oids = array();
$total = 0;
foreach ($counts as $index => $count) {
$oid = '.1.3.6.1.4.1.14179.2.1.1.1.38.' . $index;
$total_oids[] = $oid;
$total += $count;
$sensors[] = new WirelessSensor(
'clients',
$this->getDeviceId(),
$oid,
'ciscowlc-ssid',
$index,
'SSID: ' . $ssids[$index],
$count
);
}
if (!empty($counts)) {
$sensors[] = new WirelessSensor(
'clients',
$this->getDeviceId(),
$total_oids,
'ciscowlc',
0,
'Clients: Total',
$total
);
}
return $sensors;
}
}

View File

@ -0,0 +1,59 @@
<?php
/**
* Deliberant.php
*
* LigoWave Deliberant
*
* 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\OS;
use LibreNMS\Device\WirelessSensor;
use LibreNMS\Interfaces\Discovery\Sensors\WirelessClientsDiscovery;
use LibreNMS\OS;
class Deliberant extends OS implements WirelessClientsDiscovery
{
/**
* 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()
{
$device = $this->getDevice();
$clients_data = snmpwalk_cache_oid($device, 'dlbDot11IfAssocNodeCount', array(), 'DLB-802DOT11-EXT-MIB');
$sensors = array();
foreach ($clients_data as $index => $entry) {
$sensors[] = new WirelessSensor(
'clients',
$device['device_id'],
'.1.3.6.1.4.1.32761.3.5.1.2.1.1.16.' . $index,
'deliberant',
$index,
'Clients'
);
}
return $sensors;
}
}

139
LibreNMS/OS/Extendair.php Normal file
View File

@ -0,0 +1,139 @@
<?php
/**
* Extendair.php
*
* Exalt ExtendAir
*
* 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\OS;
use LibreNMS\Device\WirelessSensor;
use LibreNMS\Interfaces\Discovery\Sensors\WirelessErrorRatioDiscovery;
use LibreNMS\Interfaces\Discovery\Sensors\WirelessFrequencyDiscovery;
use LibreNMS\Interfaces\Discovery\Sensors\WirelessPowerDiscovery;
use LibreNMS\Interfaces\Discovery\Sensors\WirelessRateDiscovery;
use LibreNMS\OS;
class Extendair extends OS implements
WirelessErrorRatioDiscovery,
WirelessFrequencyDiscovery,
WirelessPowerDiscovery,
WirelessRateDiscovery
{
/**
* Discover wireless bit/packet error ratio. This is in percent. Type is error-ratio.
* Returns an array of LibreNMS\Device\Sensor objects that have been discovered
*
* @return array Sensors
*/
public function discoverWirelessErrorRatio()
{
$oid = '.1.3.6.1.4.1.25651.1.2.4.3.1.1.0'; // ExaltComProducts::locCurrentBER.0
return array(
new WirelessSensor(
'error-ratio',
$this->getDeviceId(),
$oid,
'extendair',
0,
'Bit Error Ratio',
null,
1,
1000000
),
);
}
/**
* Discover wireless frequency. This is in GHz. Type is frequency.
* Returns an array of LibreNMS\Device\Sensor objects that have been discovered
*
* @return array Sensors
*/
public function discoverWirelessFrequency()
{
$tx_oid = '.1.3.6.1.4.1.25651.1.2.3.1.57.4.0'; // ExtendAirG2::extendAirG2TXfrequency.0
$rx_oid = '.1.3.6.1.4.1.25651.1.2.3.1.57.5.0'; // ExtendAirG2::extendAirG2RXfrequency.0
return array(
new WirelessSensor(
'frequency',
$this->getDeviceId(),
$tx_oid,
'extendair-tx',
0,
'Tx Frequency',
null,
1,
1000
),
new WirelessSensor(
'frequency',
$this->getDeviceId(),
$rx_oid,
'extendair-rx',
0,
'Rx Frequency',
null,
1,
1000
),
);
}
/**
* 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()
{
$tx_oid = '.1.3.6.1.4.1.25651.1.2.3.1.57.1.0'; // ExtendAirG2::extendAirG2TxPower.0
$rx_oid = '.1.3.6.1.4.1.25651.1.2.4.3.1.3.0'; // ExaltComProducts::locCurrentRSL.0
return array(
new WirelessSensor('power', $this->getDeviceId(), $tx_oid, 'extendair-tx', 0, 'Tx Power', null, 1, 10),
new WirelessSensor('power', $this->getDeviceId(), $rx_oid, 'extendair-rx', 0, 'Signal Level'),
);
}
/**
* Discover wireless rate. This is in Mbps. Type is rate.
* Returns an array of LibreNMS\Device\Sensor objects that have been discovered
*
* @return array
*/
public function discoverWirelessRate()
{
$oid = '.1.3.6.1.4.1.25651.1.2.4.5.1.0'; // ExaltComProducts::aggregateUserThroughput.0
return array(
new WirelessSensor(
'rate',
$this->getDeviceId(),
$oid,
'extendair',
0,
'Aggregate User Throughput',
null,
1000000
),
);
}
}

33
LibreNMS/OS/Generic.php Normal file
View File

@ -0,0 +1,33 @@
<?php
/**
* Generic.php
*
* Generic OS Class, used when no specific OS is found
*
* 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\OS;
use LibreNMS\OS;
class Generic extends OS
{
}

88
LibreNMS/OS/Helios.php Normal file
View File

@ -0,0 +1,88 @@
<?php
/**
* Ignitenet.php
*
* Ignitenet HeliOS
*
* 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\OS;
use LibreNMS\Device\WirelessSensor;
use LibreNMS\Interfaces\Discovery\Sensors\WirelessFrequencyDiscovery;
use LibreNMS\Interfaces\Discovery\Sensors\WirelessPowerDiscovery;
use LibreNMS\Interfaces\Discovery\Sensors\WirelessRssiDiscovery;
use LibreNMS\OS;
class Helios extends OS implements WirelessFrequencyDiscovery, WirelessPowerDiscovery, WirelessRssiDiscovery
{
/**
* Discover wireless frequency. This is in GHz. Type is frequency.
* Returns an array of LibreNMS\Device\Sensor objects that have been discovered
*
* @return array Sensors
*/
public function discoverWirelessFrequency()
{
return $this->discoverOid('frequency', 'mlRadioInfoFrequency', '.1.3.6.1.4.1.47307.1.4.2.1.4.');
}
/**
* 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()
{
return $this->discoverOid('power', 'mlRadioInfoTxPower', '.1.3.6.1.4.1.47307.1.4.2.1.7.');
}
/**
* Discover wireless RSSI (Received Signal Strength Indicator). This is in dBm. Type is rssi.
* Returns an array of LibreNMS\Device\Sensor objects that have been discovered
*
* @return array
*/
public function discoverWirelessRssi()
{
return $this->discoverOid('rssi', 'mlRadioInfoRSSILocal', '.1.3.6.1.4.1.47307.1.4.2.1.10.');
}
private function discoverOid($type, $oid, $oid_prefix)
{
$oids = snmpwalk_cache_oid($this->getDevice(), $oid, array(), 'IGNITENET-MIB');
$sensors = array();
foreach ($oids as $index => $data) {
$sensors[] = new WirelessSensor(
$type,
$this->getDeviceId(),
$oid_prefix . $index,
'ignitenet',
$index,
"Radio $index",
$data[$oid]
);
}
return $sensors;
}
}

52
LibreNMS/OS/Hpmsm.php Normal file
View File

@ -0,0 +1,52 @@
<?php
/**
* Hpmsm.php
*
* HP Msm Wireless
*
* 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\OS;
use LibreNMS\Device\WirelessSensor;
use LibreNMS\Interfaces\Discovery\Sensors\WirelessClientsDiscovery;
use LibreNMS\OS;
class Hpmsm extends OS implements WirelessClientsDiscovery
{
/**
* Returns an array of LibreNMS\Device\Sensor objects that have been discovered
*
* @return array Sensors
*/
public function discoverWirelessClients()
{
return array(
new WirelessSensor(
'clients',
$this->getDeviceId(),
'.1.3.6.1.4.1.8744.5.25.1.7.2.0',
'hpmsm',
0,
'Clients: Total'
)
);
}
}

87
LibreNMS/OS/Ios.php Normal file
View File

@ -0,0 +1,87 @@
<?php
/**
* Ios.php
*
* Cisco IOS
*
* 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\OS;
use LibreNMS\Device\WirelessSensor;
use LibreNMS\Interfaces\Discovery\Sensors\WirelessClientsDiscovery;
use LibreNMS\OS;
class Ios extends OS implements WirelessClientsDiscovery
{
/**
* @return array Sensors
*/
public function discoverWirelessClients()
{
$device = $this->getDevice();
if (!starts_with($device['hardware'], 'AIR-') && !str_contains($device['hardware'], 'ciscoAIR')) {
// unsupported IOS hardware
return array();
}
$data = snmpwalk_cache_oid($device, 'cDot11ActiveWirelessClients', array(), 'CISCO-DOT11-ASSOCIATION-MIB');
$entPhys = snmpwalk_cache_oid($device, 'entPhysicalDescr', array(), 'ENTITY-MIB');
// fixup incorrect/missing entPhysicalIndex mapping
foreach ($data as $index => $_unused) {
foreach ($entPhys as $entIndex => $ent) {
$descr = $ent['entPhysicalDescr'];
unset($entPhys[$entIndex]); // only use each one once
if (ends_with($descr, 'Radio')) {
d_echo("Mapping entPhysicalIndex $entIndex to ifIndex $index\n");
$data[$index]['entPhysicalIndex'] = $entIndex;
$data[$index]['entPhysicalDescr'] = $descr;
break;
}
}
}
$sensors = array();
foreach ($data as $index => $entry) {
$sensors[] = new WirelessSensor(
'clients',
$device['device_id'],
".1.3.6.1.4.1.9.9.273.1.1.2.1.1.$index",
'ios',
$index,
$entry['entPhysicalDescr'],
$entry['cDot11ActiveWirelessClients'],
1,
1,
'sum',
null,
40,
null,
30,
$entry['entPhysicalIndex'],
'ports'
);
}
return $sensors;
}
}

247
LibreNMS/OS/Mimosa.php Normal file
View File

@ -0,0 +1,247 @@
<?php
/**
* Mimosa.php
*
* Mimosa Networks
*
* 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\OS;
use LibreNMS\Device\WirelessSensor;
use LibreNMS\Interfaces\Discovery\Sensors\WirelessErrorRatioDiscovery;
use LibreNMS\Interfaces\Discovery\Sensors\WirelessFrequencyDiscovery;
use LibreNMS\Interfaces\Discovery\Sensors\WirelessNoiseFloorDiscovery;
use LibreNMS\Interfaces\Discovery\Sensors\WirelessPowerDiscovery;
use LibreNMS\Interfaces\Discovery\Sensors\WirelessRateDiscovery;
use LibreNMS\Interfaces\Discovery\Sensors\WirelessSnrDiscovery;
use LibreNMS\OS;
class Mimosa extends OS implements
WirelessErrorRatioDiscovery,
WirelessFrequencyDiscovery,
WirelessNoiseFloorDiscovery,
WirelessPowerDiscovery,
WirelessRateDiscovery,
WirelessSnrDiscovery
{
/**
* Discover wireless bit/packet error ratio. This is in percent. Type is error-ratio.
* Returns an array of LibreNMS\Device\Sensor objects that have been discovered
*
* @return array Sensors
*/
public function discoverWirelessErrorRatio()
{
$tx_oid = '.1.3.6.1.4.1.43356.2.1.2.7.3.0'; // MIMOSA-NETWORKS-BFIVE-MIB::mimosaPerTxRate
$rx_oid = '.1.3.6.1.4.1.43356.2.1.2.7.4.0'; // MIMOSA-NETWORKS-BFIVE-MIB::mimosaPerRxRate
return array(
new WirelessSensor(
'error-ratio',
$this->getDeviceId(),
$tx_oid,
'mimosa-tx',
0,
'Tx Packet Error Ratio',
null,
1,
100
),
new WirelessSensor(
'error-ratio',
$this->getDeviceId(),
$rx_oid,
'mimosa-rx',
0,
'Rx Packet Error Ratio',
null,
1,
100
),
);
}
/**
* Discover wireless frequency. This is in GHz. Type is frequency.
* Returns an array of LibreNMS\Device\Sensor objects that have been discovered
*
* @return array Sensors
*/
public function discoverWirelessFrequency()
{
$polar = $this->getCacheByIndex('mimosaPolarization', 'MIMOSA-NETWORKS-BFIVE-MIB');
$freq = $this->getCacheByIndex('mimosaCenterFreq', 'MIMOSA-NETWORKS-BFIVE-MIB');
// both chains should be the same frequency, make sure
$freq = array_flip($freq);
if (count($freq) == 1) {
$descr = 'Frequency';
} else {
$descr = 'Frequency: $s Chain';
}
foreach ($freq as $frequency => $index) {
return array(
new WirelessSensor(
'frequency',
$this->getDeviceId(),
'.1.3.6.1.4.1.43356.2.1.2.6.1.1.6.' . $index,
'mimosa',
$index,
sprintf($descr, $this->getPolarization($polar[$index])),
$frequency
)
);
}
}
private function getPolarization($polarization)
{
return $polarization == 'horizontal' ? 'Horiz.' : 'Vert.';
}
/**
* Discover wireless noise floor. This is in dBm. Type is noise-floor.
* Returns an array of LibreNMS\Device\Sensor objects that have been discovered
*
* @return array Sensors
*/
public function discoverWirelessNoiseFloor()
{
// FIXME: is Noise different from Noise Floor?
$polar = $this->getCacheByIndex('mimosaPolarization', 'MIMOSA-NETWORKS-BFIVE-MIB');
$oids = snmpwalk_cache_oid($this->getDevice(), 'mimosaRxNoise', array(), 'MIMOSA-NETWORKS-BFIVE-MIB');
$sensors = array();
foreach ($oids as $index => $entry) {
$sensors[] = new WirelessSensor(
'noise-floor',
$this->getDeviceId(),
'.1.3.6.1.4.1.43356.2.1.2.6.1.1.4.' . $index,
'mimosa',
$index,
sprintf('Rx Noise: %s Chain', $this->getPolarization($polar[$index])),
$entry['mimosaRxNoise']
);
}
return $sensors;
}
/**
* 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()
{
$polar = $this->getCacheByIndex('mimosaPolarization', 'MIMOSA-NETWORKS-BFIVE-MIB');
$oids = snmpwalk_cache_oid($this->getDevice(), 'mimosaTxPower', array(), 'MIMOSA-NETWORKS-BFIVE-MIB');
$oids = snmpwalk_cache_oid($this->getDevice(), 'mimosaRxPower', $oids, 'MIMOSA-NETWORKS-BFIVE-MIB');
$sensors = array();
foreach ($oids as $index => $entry) {
$sensors[] = new WirelessSensor(
'power',
$this->getDeviceId(),
'.1.3.6.1.4.1.43356.2.1.2.6.1.1.2.' . $index,
'mimosa-tx',
$index,
sprintf('Tx Power: %s Chain', $this->getPolarization($polar[$index])),
$entry['mimosaTxPower']
);
$sensors[] = new WirelessSensor(
'power',
$this->getDeviceId(),
'.1.3.6.1.4.1.43356.2.1.2.6.1.1.3.' . $index,
'mimosa-rx',
$index,
sprintf('Rx Power: %s Chain', $this->getPolarization($polar[$index])),
$entry['mimosaRxPower']
);
}
return $sensors;
}
/**
* Discover wireless rate. This is in bps. Type is rate.
* Returns an array of LibreNMS\Device\Sensor objects that have been discovered
*
* @return array
*/
public function discoverWirelessRate()
{
$oids = snmpwalk_cache_oid($this->getDevice(), 'mimosaTxPhy', array(), 'MIMOSA-NETWORKS-BFIVE-MIB');
$oids = snmpwalk_cache_oid($this->getDevice(), 'mimosaRxPhy', $oids, 'MIMOSA-NETWORKS-BFIVE-MIB');
$sensors = array();
foreach ($oids as $index => $entry) {
$sensors[] = new WirelessSensor(
'rate',
$this->getDeviceId(),
'.1.3.6.1.4.1.43356.2.1.2.6.2.1.2.' . $index,
'mimosa-tx',
$index,
"Stream $index Tx Rate",
$entry['mimosaTxPhy'],
1000000
);
$sensors[] = new WirelessSensor(
'rate',
$this->getDeviceId(),
'.1.3.6.1.4.1.43356.2.1.2.6.2.1.5.' . $index,
'mimosa-rx',
$index,
"Stream $index Rx Rate",
$entry['mimosaRxPhy'],
1000000
);
}
return $sensors;
}
/**
* Discover wireless SNR. This is in dB. Type is snr.
* Returns an array of LibreNMS\Device\Sensor objects that have been discovered
*
* @return array Sensors
*/
public function discoverWirelessSnr()
{
$polar = $this->getCacheByIndex('mimosaPolarization', 'MIMOSA-NETWORKS-BFIVE-MIB');
$oids = snmpwalk_cache_oid($this->getDevice(), 'mimosaSNR', array(), 'MIMOSA-NETWORKS-BFIVE-MIB');
$sensors = array();
foreach ($oids as $index => $entry) {
$sensors[] = new WirelessSensor(
'snr',
$this->getDeviceId(),
'.1.3.6.1.4.1.43356.2.1.2.6.1.1.5.' . $index,
'mimosa',
$index,
sprintf('SNR: %s Chain', $this->getPolarization($polar[$index])),
$entry['mimosaSNR']
);
}
return $sensors;
}
}

165
LibreNMS/OS/Routeros.php Normal file
View File

@ -0,0 +1,165 @@
<?php
/**
* Routeros.php
*
* Mikrotik RouterOS
*
* 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\OS;
use LibreNMS\Device\WirelessSensor;
use LibreNMS\Interfaces\Discovery\Sensors\WirelessCcqDiscovery;
use LibreNMS\Interfaces\Discovery\Sensors\WirelessClientsDiscovery;
use LibreNMS\Interfaces\Discovery\Sensors\WirelessFrequencyDiscovery;
use LibreNMS\Interfaces\Discovery\Sensors\WirelessNoiseFloorDiscovery;
use LibreNMS\Interfaces\Discovery\Sensors\WirelessRateDiscovery;
use LibreNMS\OS;
class Routeros extends OS implements
WirelessCcqDiscovery,
WirelessClientsDiscovery,
WirelessFrequencyDiscovery,
WirelessNoiseFloorDiscovery,
WirelessRateDiscovery
{
private $data;
/**
* Returns an array of LibreNMS\Device\Sensor objects that have been discovered
*
* @return array Sensors
*/
public function discoverWirelessCcq()
{
return $this->discoverSensor(
'ccq',
'mtxrWlApOverallTxCCQ',
'.1.3.6.1.4.1.14988.1.1.1.3.1.10.'
);
}
/**
* Returns an array of LibreNMS\Device\Sensor objects that have been discovered
*
* @return array Sensors
*/
public function discoverWirelessClients()
{
return $this->discoverSensor(
'clients',
'mtxrWlApClientCount',
'.1.3.6.1.4.1.14988.1.1.1.3.1.6.'
);
}
/**
* 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()
{
return $this->discoverSensor(
'frequency',
'mtxrWlApFreq',
'.1.3.6.1.4.1.14988.1.1.1.3.1.7.'
);
}
/**
* Returns an array of LibreNMS\Device\Sensor objects that have been discovered
*
* @return array Sensors
*/
public function discoverWirelessNoiseFloor()
{
return $this->discoverSensor(
'noise-floor',
'mtxrWlApNoiseFloor',
'.1.3.6.1.4.1.14988.1.1.1.3.1.9.'
);
}
/**
* Discover wireless rate. This is in bps. Type is rate.
* Returns an array of LibreNMS\Device\Sensor objects that have been discovered
*
* @return array
*/
public function discoverWirelessRate()
{
$data = $this->fetchData();
$sensors = array();
foreach ($data as $index => $entry) {
$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',
$entry['mtxrWlApTxRate']
);
$sensors[] = new WirelessSensor(
'rate',
$this->getDeviceId(),
'.1.3.6.1.4.1.14988.1.1.1.3.1.3.' . $index,
'mikrotik-rx',
$index,
'SSID: ' . $entry['mtxrWlApSsid'] . ' Rx',
$entry['mtxrWlApRxRate']
);
}
return $sensors;
}
private function fetchData()
{
if (is_null($this->data)) {
$this->data = snmpwalk_cache_oid($this->getDevice(), 'mtxrWlApTable', array(), 'MIKROTIK-MIB');
}
return $this->data;
}
private function discoverSensor($type, $oid, $num_oid_base)
{
$data = $this->fetchData();
$sensors = array();
foreach ($data as $index => $entry) {
$sensors[] = new WirelessSensor(
$type,
$this->getDeviceId(),
$num_oid_base . $index,
'mikrotik',
$index,
'SSID: ' . $entry['mtxrWlApSsid'],
$entry[$oid]
);
}
return $sensors;
}
}

97
LibreNMS/OS/Siklu.php Normal file
View File

@ -0,0 +1,97 @@
<?php
/**
* Siklu.php
*
* Siklu Communication
*
* 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\OS;
use LibreNMS\Device\WirelessSensor;
use LibreNMS\Interfaces\Discovery\Sensors\WirelessFrequencyDiscovery;
use LibreNMS\Interfaces\Discovery\Sensors\WirelessPowerDiscovery;
use LibreNMS\Interfaces\Discovery\Sensors\WirelessRssiDiscovery;
use LibreNMS\Interfaces\Discovery\Sensors\WirelessSnrDiscovery;
use LibreNMS\OS;
class Siklu extends OS implements
WirelessFrequencyDiscovery,
WirelessPowerDiscovery,
WirelessRssiDiscovery,
WirelessSnrDiscovery
{
/**
* Discover wireless frequency. This is in GHz. Type is frequency.
* Returns an array of LibreNMS\Device\Sensor objects that have been discovered
*
* @return array Sensors
*/
public function discoverWirelessFrequency()
{
$oid = '.1.3.6.1.4.1.31926.2.1.1.4.1'; // RADIO-BRIDGE-MIB::rfOperationalFrequency.1
return array(
new WirelessSensor('frequency', $this->getDeviceId(), $oid, 'siklu', 1, 'Frequency', null, 1, 1000),
);
}
/**
* 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()
{
$oid = '.1.3.6.1.4.1.31926.2.1.1.42.1'; // RADIO-BRIDGE-MIB::rfTxPower.1
return array(
new WirelessSensor('power', $this->getDeviceId(), $oid, 'siklu', 1, 'Tx Power'),
);
}
/**
* Discover wireless RSSI (Received Signal Strength Indicator). This is in dBm. Type is rssi.
* Returns an array of LibreNMS\Device\Sensor objects that have been discovered
*
* @return array
*/
public function discoverWirelessRssi()
{
$oid = '.1.3.6.1.4.1.31926.2.1.1.19.1'; // RADIO-BRIDGE-MIB::rfAverageRssi.1
return array(
new WirelessSensor('rssi', $this->getDeviceId(), $oid, 'siklu', 1, 'RSSI'),
);
}
/**
* Discover wireless SNR. This is in dB. Type is snr.
* Returns an array of LibreNMS\Device\Sensor objects that have been discovered
*
* @return array Sensors
*/
public function discoverWirelessSnr()
{
$oid = '.1.3.6.1.4.1.31926.2.1.1.18.1'; // RADIO-BRIDGE-MIB::rfAverageCinr.1
return array(
new WirelessSensor('snr', $this->getDeviceId(), $oid, 'siklu', 1, 'CINR'),
);
}
}

53
LibreNMS/OS/Symbol.php Normal file
View File

@ -0,0 +1,53 @@
<?php
/**
* Symbol.php
*
* Symbol Technologies
*
* 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\OS;
use LibreNMS\Device\WirelessSensor;
use LibreNMS\Interfaces\Discovery\Sensors\WirelessClientsDiscovery;
use LibreNMS\OS;
class Symbol extends OS implements WirelessClientsDiscovery
{
/**
* 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()
{
$device = $this->getDevice();
if (str_contains($device['hardware'], 'AP', true)) {
$oid = '.1.3.6.1.4.1.388.11.2.4.2.100.10.1.18.1';
return array(
new WirelessSensor('clients', $device['device_id'], $oid, 'symbol', 1, 'Clients')
);
}
return array();
}
}

295
LibreNMS/OS/Unifi.php Normal file
View File

@ -0,0 +1,295 @@
<?php
/**
* Unifi.php
*
* Ubiquiti Unifi
*
* 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\OS;
use LibreNMS\Device\WirelessSensor;
use LibreNMS\Interfaces\Discovery\Sensors\WirelessCcqDiscovery;
use LibreNMS\Interfaces\Discovery\Sensors\WirelessClientsDiscovery;
use LibreNMS\Interfaces\Discovery\Sensors\WirelessFrequencyDiscovery;
use LibreNMS\Interfaces\Discovery\Sensors\WirelessPowerDiscovery;
use LibreNMS\Interfaces\Discovery\Sensors\WirelessUtilizationDiscovery;
use LibreNMS\Interfaces\Polling\Sensors\WirelessCcqPolling;
use LibreNMS\Interfaces\Polling\Sensors\WirelessFrequencyPolling;
use LibreNMS\OS;
class Unifi extends OS implements
WirelessClientsDiscovery,
WirelessCcqDiscovery,
WirelessCcqPolling,
WirelessFrequencyDiscovery,
WirelessFrequencyPolling,
WirelessPowerDiscovery,
WirelessUtilizationDiscovery
{
private $ccqDivisor = 10;
/**
* Returns an array of LibreNMS\Device\Sensor objects
*
* @return array Sensors
*/
public function discoverWirelessClients()
{
$client_oids = snmpwalk_cache_oid($this->getDevice(), 'unifiVapNumStations', array(), 'UBNT-UniFi-MIB');
if (empty($client_oids)) {
return array();
}
$vap_radios = $this->getCacheByIndex('unifiVapRadio', 'UBNT-UniFi-MIB');
$ssids = $this->getCacheByIndex('unifiVapEssId', 'UBNT-UniFi-MIB');
$radios = array();
foreach ($client_oids as $index => $entry) {
$radio_name = $vap_radios[$index];
$radios[$radio_name]['oids'][] = '.1.3.6.1.4.1.41112.1.6.1.2.1.8.' . $index;
if (isset($radios[$radio_name]['count'])) {
$radios[$radio_name]['count'] += $entry['unifiVapNumStations'];
} else {
$radios[$radio_name]['count'] = $entry['unifiVapNumStations'];
}
}
$sensors = array();
// discover client counts by radio
foreach ($radios as $name => $data) {
$sensors[] = new WirelessSensor(
'clients',
$this->getDeviceId(),
$data['oids'],
'unifi',
$name,
strtoupper($name) . ' Radio Clients',
$data['count'],
1,
1,
'sum',
null,
40,
null,
30
);
}
// discover client counts by SSID
foreach ($client_oids as $index => $entry) {
$sensors[] = new WirelessSensor(
'clients',
$this->getDeviceId(),
'.1.3.6.1.4.1.41112.1.6.1.2.1.8.' . $index,
'unifi',
$index,
'SSID: ' . $ssids[$index],
$entry['unifiVapNumStations']
);
}
return $sensors;
}
/**
* Returns an array of LibreNMS\Device\Sensor objects that have been discovered
*
* @return array
*/
public function discoverWirelessCcq()
{
$ccq_oids = snmpwalk_cache_oid($this->getDevice(), 'unifiVapCcq', array(), 'UBNT-UniFi-MIB');
if (empty($ccq_oids)) {
return array();
}
$ssids = $this->getCacheByIndex('unifiVapEssId', 'UBNT-UniFi-MIB');
$sensors = array();
foreach ($ccq_oids as $index => $entry) {
if ($ssids[$index]) { // don't discover ssids with empty names
$sensors[] = new WirelessSensor(
'ccq',
$this->getDeviceId(),
'.1.3.6.1.4.1.41112.1.6.1.2.1.3.' . $index,
'unifi',
$index,
'SSID: ' . $ssids[$index],
min($entry['unifiVapCcq'] / $this->ccqDivisor, 100),
1,
$this->ccqDivisor
);
}
}
return $sensors;
}
/**
* Poll wireless client connection quality
* 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 pollWirelessCcq(array $sensors)
{
if (empty($sensors)) {
return array();
}
$ccq_oids = snmpwalk_cache_oid($this->getDevice(), 'unifiVapCcq', array(), 'UBNT-UniFi-MIB');
$data = array();
foreach ($sensors as $sensor) {
$index = $sensor['sensor_index'];
$data[$sensor['sensor_id']] = min($ccq_oids[$index]['unifiVapCcq'] / $this->ccqDivisor, 100);
}
return $data;
}
/**
* 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()
{
$data = snmpwalk_cache_oid($this->getDevice(), 'unifiVapChannel', array(), 'UBNT-UniFi-MIB');
$vap_radios = $this->getCacheByIndex('unifiVapRadio', 'UBNT-UniFi-MIB');
$sensors = array();
foreach ($data as $index => $entry) {
$radio = $vap_radios[$index];
if (isset($sensors[$radio])) {
continue;
}
$sensors[$radio] = new WirelessSensor(
'frequency',
$this->getDeviceId(),
'.1.3.6.1.4.1.41112.1.6.1.2.1.4.' . $index,
'unifi',
$radio,
strtoupper($radio) . ' Radio Frequency',
WirelessSensor::channelToFrequency($entry['unifiVapChannel'])
);
}
return $sensors;
}
/**
* 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);
}
/**
* 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()
{
$power_oids = snmpwalk_cache_oid($this->getDevice(), 'unifiVapTxPower', array(), 'UBNT-UniFi-MIB');
if (empty($power_oids)) {
return array();
}
$vap_radios = $this->getCacheByIndex('unifiVapRadio', 'UBNT-UniFi-MIB');
// pick one oid for each radio, hopefully ssids don't change... not sure why this is supplied by vap
$sensors = array();
foreach ($power_oids as $index => $entry) {
$radio_name = $vap_radios[$index];
if (!isset($sensors[$radio_name])) {
$sensors[$radio_name] = new WirelessSensor(
'power',
$this->getDeviceId(),
'.1.3.6.1.4.1.41112.1.6.1.2.1.21.' . $index,
'unifi-tx',
$radio_name,
'Tx Power: ' . strtoupper($radio_name) . ' Radio',
$entry['unifiVapTxPower']
);
}
}
return $sensors;
}
/**
* 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()
{
$util_oids = snmpwalk_cache_oid($this->getDevice(), 'unifiRadioCuTotal', array(), 'UBNT-UniFi-MIB');
if (empty($util_oids)) {
return array();
}
$util_oids = snmpwalk_cache_oid($this->getDevice(), 'unifiRadioCuSelfRx', $util_oids, 'UBNT-UniFi-MIB');
$util_oids = snmpwalk_cache_oid($this->getDevice(), 'unifiRadioCuSelfTx', $util_oids, 'UBNT-UniFi-MIB');
$radio_names = $this->getCacheByIndex('unifiRadioRadio', 'UBNT-UniFi-MIB');
$sensors = array();
foreach ($radio_names as $index => $name) {
$radio_name = strtoupper($name) . ' Radio';
$sensors[] = new WirelessSensor(
'utilization',
$this->getDeviceId(),
'.1.3.6.1.4.1.41112.1.6.1.1.1.6.' . $index,
'unifi-total',
$index,
'Total Util: ' . $radio_name,
$util_oids[$index]['unifiRadioCuTotal']
);
$sensors[] = new WirelessSensor(
'utilization',
$this->getDeviceId(),
'.1.3.6.1.4.1.41112.1.6.1.1.1.7.' . $index,
'unifi-rx',
$index,
'Self Rx Util: ' . $radio_name,
$util_oids[$index]['unifiRadioCuSelfRx']
);
$sensors[] = new WirelessSensor(
'utilization',
$this->getDeviceId(),
'.1.3.6.1.4.1.41112.1.6.1.1.1.8.' . $index,
'unifi-tx',
$index,
'Self Tx Util: ' . $radio_name,
$util_oids[$index]['unifiRadioCuSelfTx']
);
}
return $sensors;
}
}

135
LibreNMS/OS/XirrusAos.php Normal file
View File

@ -0,0 +1,135 @@
<?php
/**
* XirrusAos.php
*
* Xirrus AOS OS
*
* 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\OS;
use LibreNMS\Device\WirelessSensor;
use LibreNMS\Interfaces\Discovery\Sensors\WirelessClientsDiscovery;
use LibreNMS\Interfaces\Discovery\Sensors\WirelessFrequencyDiscovery;
use LibreNMS\Interfaces\Discovery\Sensors\WirelessNoiseFloorDiscovery;
use LibreNMS\Interfaces\Discovery\Sensors\WirelessSnrDiscovery;
use LibreNMS\Interfaces\Discovery\Sensors\WirelessUtilizationDiscovery;
use LibreNMS\Interfaces\Polling\Sensors\WirelessFrequencyPolling;
use LibreNMS\OS;
class XirrusAos extends OS implements
WirelessClientsDiscovery,
WirelessFrequencyDiscovery,
WirelessFrequencyPolling,
WirelessNoiseFloorDiscovery,
WirelessUtilizationDiscovery,
WirelessSnrDiscovery
{
/**
* Returns an array of LibreNMS\Device\Sensor objects that have been discovered
*
* @return array Sensors
*/
public function discoverWirelessClients()
{
$oid = '.1.3.6.1.4.1.21013.1.2.12.1.2.22.0'; // XIRRUS-MIB::globalNumStations.0
return array(
new WirelessSensor('clients', $this->getDeviceId(), $oid, 'xirrus', 0, 'Clients'),
);
}
/**
* 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()
{
return $this->discoverSensor('frequency', 'realtimeMonitorChannel', '.1.3.6.1.4.1.21013.1.2.24.7.1.3.');
}
/**
* 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);
}
/**
* Returns an array of LibreNMS\Device\Sensor objects that have been discovered
*
* @return array
*/
public function discoverWirelessNoiseFloor()
{
return $this->discoverSensor('noise-floor', 'realtimeMonitorNoiseFloor', '.1.3.6.1.4.1.21013.1.2.24.7.1.10.');
}
/**
* Discover wireless SNR. This is in dB. Type is snr.
* Formula: SNR = Signal or Rx Power - Noise Floor
* Returns an array of LibreNMS\Device\Sensor objects that have been discovered
*
* @return array Sensors
*/
public function discoverWirelessSnr()
{
return $this->discoverSensor('snr', 'realtimeMonitorSignalToNoiseRatio', '.1.3.6.1.4.1.21013.1.2.24.7.1.9.');
}
/**
* 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()
{
return $this->discoverSensor('utilization', 'realtimeMonitorDot11Busy', '.1.3.6.1.4.1.21013.1.2.24.7.1.11.');
}
private function discoverSensor($type, $oid, $oid_num_prefix)
{
$names = $this->getCacheByIndex('realtimeMonitorIfaceName', 'XIRRUS-MIB');
$nf = snmp_cache_oid($oid, $this->getDevice(), array(), 'XIRRUS-MIB');
$sensors = array();
foreach ($nf as $index => $entry) {
$sensors[] = new WirelessSensor(
$type,
$this->getDeviceId(),
$oid_num_prefix . $index,
'xirrus',
$index,
$names[$index],
$type == 'frequency' ? WirelessSensor::channelToFrequency($entry[$oid]) :$entry[$oid]
);
}
return $sensors;
}
}

View File

@ -6,5 +6,6 @@ During all of these examples we will be using the OS of `pulse` as the example O
> - [Adding the initial detection.](os/Initial-Detection.md)
> - [Adding Memory and CPU information.](os/Mem-CPU-Information.md)
> - [Adding Health / Sensor information.](os/Health-Information.md)
> - [Adding Wireless Sensor information.](os/Wireless-Sensors.md)
> - [Adding custom graphs.](os/Custom-Graphs.md)
> - [Adding Unit tests (required).](os/Test-Units.md)
> - [Adding Unit tests (required).](os/Test-Units.md)

View File

@ -35,7 +35,7 @@ exception of state which requires additional code.
Typically it's the index from the table being walked or it could be the name of the OID if it's a single value.
- $type = Required. This should be the OS name, i.e pulse.
- $descr = Required. This is a descriptive value for the sensor. Some devices will provide names to use.
- $divisor = Defaults to 1. This is used to divied the returned value.
- $divisor = Defaults to 1. This is used to divided the returned value.
- $multiplier = Defaults to 1. This is used to multiply the returned value.
- $low_limit = Defaults to null. Sets the low threshold limit for the sensor, used in alerting to report out range sensors.
- $low_warn_limit = Defaults to null. Sets the low warning limit for the sensor, used in alerting to report near out of range sensors.

View File

@ -0,0 +1,66 @@
source: Developing/os/Wireless-Sensors.md
This document will guide you through adding wireless sensors for your new wireless device.
Currently we have support for the following wireless metrics along with the values we expect to see the data in:
| Type | Measurement | Interface |
| ------------------------------- | --------------------------- | ----------------------------- |
| ccq | % | WirelessCcqDiscovery |
| clients | count | WirelessClientsDiscovery |
| noise-floor | dBm/Hz | WirelessNoiseFloorDiscovery |
You will need to create a new OS class for your os if one doen't exist under `LibreNMS/OS`. The name of this file
should be the os name in camel case for example `airos -> Airos`, `ios-wlc -> IosWlc`.
Your new OS class should extend LibreNMS\OS and implement the interfaces for the sensors your os supports.
```php
namespace LibreNMS\OS;
use LibreNMS\Interfaces\Discovery\Sensors\WirelessClientsDiscovery;
use LibreNMS\OS;
class Airos extends OS implements WirelessClientsDiscovery
{
public functon discoverWirelessClients()
{
$oid = '.1.3.6.1.4.1.41112.1.4.5.1.15.1'; //UBNT-AirMAX-MIB::ubntWlStatStaCount.1
return array(
new WirelessSensor('clients', $this->getDeviceId(), $oid, 'airos', 1, 'Clients')
);
}
}
```
All discovery interfaces will require you to return an array of WirelessSensor objects.
`new WirelessSensor()` Accepts the following arguments:
- $type = Required. This is the sensor class from the table above (i.e humidity).
- $device_id = Required. You can get this value with $this->getDeviceId()
- $oids = Required. This must be the numerical OID for where the data can be found, i.e .1.2.3.4.5.6.7.0.
If this is an array of oids, you should probably specify an $aggregator.
- $index = Required. This must be unique for this sensor type, device and subtype.
Typically it's the index from the table being walked or it could be the name of the OID if it's a single value.
- $subtype = Required. This should be the OS name, i.e airos.
- $description = Required. This is a descriptive value for the sensor.
Shown to the user, if this is a per-ssid statistic, using `SSID: $ssid` here is appropriate
- $current = Defaults to null. Can be used to set the current value on discovery.
If this is null the values will be polled right away and if they do not return valid value(s), the sensor will not be discovered.
Supplying a value here implies you have already verified this sensor is valid.
- $divisor = Defaults to 1. This is used to divided the returned value.
- $multiplier = Defaults to 1. This is used to multiply the returned value.
- $aggregator = Defaults to sum. Valid values: sum, avg. This will combine multiple values from multiple oids into one.
- $access_point_id = Defaults to null. If this is a wireless controller, you can link sensors to entries in the access_points table.
- $high_limit = Defaults to null. Sets the high limit for the sensor, used in alerting to report out range sensors.
- $low_limit = Defaults to null. Sets the low threshold limit for the sensor, used in alerting to report out range sensors.
- $high_warn = Defaults to null. Sets the high warning limit for the sensor, used in alerting to report near out of range sensors.
- $low_warn = Defaults to null. Sets the low warning limit for the sensor, used in alerting to report near out of range sensors.
- $entPhysicalIndex = Defaults to null. Sets the entPhysicalIndex to be used to look up further hardware if available.
- $entPhysicalIndexMeasured = Defaults to null. Sets the type of entPhysicalIndex used, i.e ports.
Polling is done automatically based on the discovered data. If for some reason you need to override polling, you can implement
the required polling interface in `LibreNMS/Interfaces/Polling/Sensors`. Using the polling interfaces should be avoided if possible.
Graphing is performed automatically for wireless sensors, no custom graphing is required or supported.

View File

@ -2106,18 +2106,18 @@ label {
background-color: #f5f5f5;
}
.device-table-header-status {
width: 100px;
text-align: center;
.device-table-metrics span {
display: inline-block;
white-space: nowrap;
}
.device-table-header-vendor {
width: 100px;
text-align: center;
.device-table-metrics>a {
color:#000;
text-decoration:none;
}
.device-table-header-actions {
min-width: 120px;
min-width: 110px;
text-align: center;
}

View File

@ -23,7 +23,12 @@ if (!is_numeric($_POST['device_id']) || !is_numeric($_POST['sensor_id']) || !iss
echo 'error with data';
exit;
} else {
$update = dbUpdate(array($_POST['value_type'] => $_POST['data'], 'sensor_custom' => 'Yes'), 'sensors', '`sensor_id` = ? AND `device_id` = ?', array($_POST['sensor_id'], $_POST['device_id']));
$update = dbUpdate(
array($_POST['value_type'] => $_POST['data'], 'sensor_custom' => 'Yes'),
'sensors',
'`sensor_id` = ? AND `device_id` = ?',
array($_POST['sensor_id'], $_POST['device_id'])
);
if (!empty($update) || $update == '0') {
echo 'success';
exit;

View File

@ -0,0 +1,34 @@
<?php
/*
* LibreNMS
*
* Copyright (c) 2014 Neil Lathwood <https://github.com/laf/ http://www.lathwood.co.uk>
* Copyright (c) 2017 Tony Murray <https://github.com/murrant>
*
* 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. Please see LICENSE.txt at the top level of
* the source code distribution for details.
*/
header('Content-type: text/plain');
// FUA
if (is_admin() === false) {
die('ERROR: You need to be admin');
}
for ($x = 0; $x < count($_POST['sensor_id']); $x++) {
dbUpdate(
array(
'sensor_limit' => $_POST['sensor_limit'][$x],
'sensor_limit_low' => $_POST['sensor_limit_low'][$x],
'sensor_alert' => $_POST['sensor_alert'][$x]
),
'wireless_sensors',
'`sensor_id` = ?',
array($_POST['sensor_id'][$x])
);
}

View File

@ -0,0 +1,52 @@
<?php
/*
* LibreNMS
*
* Copyright (c) 2014 Neil Lathwood <https://github.com/laf/ http://www.lathwood.co.uk>
* Copyright (c) 2017 Tony Murray <https://github.com/murrant>
*
* 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. Please see LICENSE.txt at the top level of
* the source code distribution for details.
*/
header('Content-type: text/plain');
// FUA
if (is_admin() === false) {
die('ERROR: You need to be admin');
}
if (isset($_POST['sub_type']) && !empty($_POST['sub_type'])) {
dbUpdate(array('sensor_custom' => 'No'), 'wireless_sensors', '`sensor_id` = ?', array($_POST['sensor_id']));
} else {
if (!is_numeric($_POST['device_id']) || !is_numeric($_POST['sensor_id'])) {
echo 'error with data';
exit;
} else {
if ($_POST['state'] == 'true') {
$state = 1;
} elseif ($_POST['state'] == 'false') {
$state = 0;
} else {
$state = 0;
}
$update = dbUpdate(
array('sensor_alert' => $state),
'wireless_sensors',
'`sensor_id` = ? AND `device_id` = ?',
array($_POST['sensor_id'], $_POST['device_id'])
);
if (!empty($update) || $update == '0') {
echo 'success';
exit;
} else {
echo 'error';
exit;
}
}
}

View File

@ -0,0 +1,40 @@
<?php
/*
* LibreNMS
*
* Copyright (c) 2014 Neil Lathwood <https://github.com/laf/ http://www.lathwood.co.uk>
* Copyright (c) 2017 Neil Lathwood <https://github.com/murrant>
*
* 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. Please see LICENSE.txt at the top level of
* the source code distribution for details.
*/
header('Content-type: text/plain');
// FUA
if (is_admin() === false) {
die('ERROR: You need to be admin');
}
if (!is_numeric($_POST['device_id']) || !is_numeric($_POST['sensor_id']) || !isset($_POST['data'])) {
echo 'error with data';
exit;
} else {
$update = dbUpdate(
array($_POST['value_type'] => $_POST['data'], 'sensor_custom' => 'Yes'),
'wireless_sensors',
'`sensor_id` = ? AND `device_id` = ?',
array($_POST['sensor_id'], $_POST['device_id'])
);
if (!empty($update) || $update == '0') {
echo 'success';
exit;
} else {
echo 'error';
exit;
}
}

View File

@ -1,21 +0,0 @@
<?php
$colours = 'mixed';
$unit_text = 'Clients';
$scale_min = '0';
$i = 1;
$rrd_filename = rrd_name($device['hostname'], "wificlients-radio$i");
while (rrdtool_check_rrd_exists($rrd_filename)) {
$rrd_list[$i] =
array(
'filename' => $rrd_filename,
'ds' => 'wificlients',
'descr' => "Radio$i Clients",
);
$i++;
$rrd_filename = rrd_name($device['hostname'], "wificlients-radio$i");
};
require 'includes/graphs/generic_multi_line.inc.php';

View File

@ -0,0 +1,73 @@
<?php
/**
* wireless-sensor.inc.php
*
* Common file for Wireless Sensor Graphs
*
* 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>
*/
require 'includes/graphs/common.inc.php';
// escape % characters
$unit = preg_replace('/(?<!%)%(?!%)/', '%%', $unit);
$output_def = 'sensor';
$num = '%5.1lf'; // default: float
if ($unit === '') {
$num = '%5.0lf';
} elseif ($unit == 'bps') {
$num .= '%s';
} elseif ($unit == 'Hz') {
$output_def = 'sensorhz';
$num = '%5.3lf%s';
}
$sensors = dbFetchRows(
'SELECT * FROM `wireless_sensors` WHERE `sensor_class` = ? AND `device_id` = ? ORDER BY `sensor_index`',
array($class, $device['device_id'])
);
if (count($sensors) == 1 && $unit_long == $sensors[0]['sensor_descr']) {
$unit_long = '';
}
$col_w = 7 + strlen($unit);
$rrd_options .= " COMMENT:'". str_pad($unit_long, 35) . str_pad("Cur", $col_w). str_pad("Min", $col_w) . "Max\\n'";
foreach ($sensors as $index => $sensor) {
$sensor_id = $sensor['sensor_id'];
$colour_index = $index % count($config['graph_colours']['mixed']);
$colour = $config['graph_colours']['mixed'][$colour_index];
$sensor_descr_fixed = rrdtool_escape($sensor['sensor_descr'], 28);
$rrd_file = rrd_name($device['hostname'], array('wireless-sensor', $sensor['sensor_class'], $sensor['sensor_type'], $sensor['sensor_index']));
$rrd_options .= " DEF:sensor$sensor_id=$rrd_file:sensor:AVERAGE";
if ($unit == 'Hz') {
$rrd_options .= " CDEF:sensorhz$sensor_id=sensor$sensor_id,1000000,*";
}
$rrd_options .= " LINE1.5:$output_def$sensor_id#$colour:'$sensor_descr_fixed'";
$rrd_options .= " GPRINT:$output_def$sensor_id:LAST:'$num$unit'";
$rrd_options .= " GPRINT:$output_def$sensor_id:MIN:'$num$unit'";
$rrd_options .= " GPRINT:$output_def$sensor_id:MAX:'$num$unit'\\l ";
$iter++;
}//end foreach

View File

@ -0,0 +1,10 @@
<?php
$scale_min = '0';
$scale_max = '100';
$class = 'capacity';
$unit = '%';
$unit_long = '';
require 'includes/graphs/device/wireless-sensor.inc.php';

View File

@ -0,0 +1,10 @@
<?php
$scale_min = '0';
$scale_max = '100';
$class = 'ccq';
$unit = '%%';
$unit_long = 'CCQ';
require 'includes/graphs/device/wireless-sensor.inc.php';

View File

@ -0,0 +1,10 @@
<?php
$scale_min = '0';
//$scale_max = '40';
$class = 'clients';
$unit = '';
$unit_long = 'Clients';
require 'includes/graphs/device/wireless-sensor.inc.php';

View File

@ -0,0 +1,9 @@
<?php
$scale_min = '0';
$class = 'distance';
$unit = 'km';
$unit_long = '';
require 'includes/graphs/device/wireless-sensor.inc.php';

View File

@ -0,0 +1,9 @@
<?php
$scale_min = '0';
$class = 'error-rate';
$unit = 'bps';
$unit_long = 'Error Rate';
require 'includes/graphs/device/wireless-sensor.inc.php';

View File

@ -0,0 +1,10 @@
<?php
$scale_min = '0';
$scale_max = '100';
$class = 'error-ratio';
$unit = '%%';
$unit_long = 'Error Ratio';
require 'includes/graphs/device/wireless-sensor.inc.php';

View File

@ -0,0 +1,9 @@
<?php
$scale_min = '0';
$class = 'frequency';
$unit = 'Hz';
$unit_long = 'Hz';
require 'includes/graphs/device/wireless-sensor.inc.php';

View File

@ -0,0 +1,10 @@
<?php
$scale_min = '-175';
$scale_max = '0';
$class = 'noise-floor';
$unit = '';
$unit_long = 'dBm/Hz';
require 'includes/graphs/device/wireless-sensor.inc.php';

View File

@ -0,0 +1,10 @@
<?php
$scale_min = '0';
$scale_max = '40';
$class = 'power';
$unit = '';
$unit_long = 'dBm';
require 'includes/graphs/device/wireless-sensor.inc.php';

View File

@ -0,0 +1,10 @@
<?php
$scale_min = '0';
$scale_max = '100';
$class = 'quality';
$unit = '%';
$unit_long = '';
require 'includes/graphs/device/wireless-sensor.inc.php';

View File

@ -0,0 +1,8 @@
<?php
$scale_min = '0';
$class = 'rate';
$unit = 'bps';
require 'includes/graphs/device/wireless-sensor.inc.php';

View File

@ -0,0 +1,10 @@
<?php
$scale_min = '0';
//$scale_max = '100';
$class = 'rssi';
$unit = '';
$unit_long = 'dBm';
require 'includes/graphs/device/wireless-sensor.inc.php';

View File

@ -0,0 +1,10 @@
<?php
$scale_min = '0';
$class = 'snr';
$unit = '';
$unit_long = 'dB';
require 'includes/graphs/device/wireless-sensor.inc.php';

View File

@ -0,0 +1,10 @@
<?php
$scale_min = '0';
$scale_max = '100';
$class = 'utilization';
$unit = '%%';
$unit_long = 'Utilization';
require 'includes/graphs/device/wireless-sensor.inc.php';

View File

@ -0,0 +1,15 @@
<?php
if (is_numeric($vars['id'])) {
$sensor = dbFetchRow('SELECT * FROM `wireless_sensors` WHERE `sensor_id` = ?', array($vars['id']));
if (is_numeric($sensor['device_id']) && ($auth || device_permitted($sensor['device_id']))) {
$device = device_by_id_cache($sensor['device_id']);
$rrd_filename = rrd_name($device['hostname'], array('wireless-sensor', $sensor['sensor_class'], $sensor['sensor_type'], $sensor['sensor_index']));
$title = generate_device_link($device);
$title .= ' :: Wireless Sensor :: '.htmlentities($sensor['sensor_descr']);
$auth = true;
}
}

View File

@ -0,0 +1,9 @@
<?php
$scale_min = '0';
$scale_max = '100';
$unit_long = 'Capacity (%)';
$unit = '%';
include 'wireless-sensor.inc.php';

View File

@ -0,0 +1,9 @@
<?php
$scale_min = '0';
$scale_max = '100';
$unit_long = 'CCQ (%)';
$unit = '%';
include 'wireless-sensor.inc.php';

View File

@ -0,0 +1,32 @@
<?php
/**
* clients.inc.php
*
* -Description-
*
* 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>
*/
$scale_min = '0';
//$scale_max = '40';
$unit_long = 'Clients';
$unit = '';
include 'wireless-sensor.inc.php';

View File

@ -0,0 +1,8 @@
<?php
$scale_min = '0';
$unit_long = 'Distance (m)';
$unit = 'm';
include 'wireless-sensor.inc.php';

View File

@ -0,0 +1,8 @@
<?php
$scale_min = '0';
$unit_long = 'Error Ratio (bps)';
$unit = 'bps';
include 'wireless-sensor.inc.php';

View File

@ -0,0 +1,9 @@
<?php
$scale_min = '0';
$scale_max = '100';
$unit_long = 'Error Ratio (%)';
$unit = '%';
include 'wireless-sensor.inc.php';

View File

@ -0,0 +1,8 @@
<?php
$scale_min = '0';
$unit_long = 'Frequency (Hz)';
$unit = 'Hz';
include 'wireless-sensor.inc.php';

View File

@ -0,0 +1,8 @@
<?php
$scale_min = '-175';
$scale_max = '0';
$unit_long = 'Noise Floor (dBm/Hz)';
$unit = 'dBm/Hz';
include 'wireless-sensor.inc.php';

View File

@ -0,0 +1,9 @@
<?php
//$scale_min = '-40';
//$scale_max = '40';
$unit_long = 'Power (dBm)';
$unit = 'dBm';
include 'wireless-sensor.inc.php';

View File

@ -0,0 +1,9 @@
<?php
$scale_min = '0';
$scale_max = '100';
$unit_long = 'Quality (%)';
$unit = '%';
include 'wireless-sensor.inc.php';

View File

@ -0,0 +1,9 @@
<?php
$scale_min = '0';
//$scale_max = '1000';
$unit_long = 'Rate (bps)';
$unit = 'bps';
include 'wireless-sensor.inc.php';

View File

@ -0,0 +1,32 @@
<?php
/**
* rssi.inc.php
*
* -Description-
*
* 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>
*/
$scale_min = '0';
//$scale_max = '100';
$unit_long = 'RSSI (dBm)';
$unit = 'dBm';
include 'wireless-sensor.inc.php';

View File

@ -0,0 +1,8 @@
<?php
$scale_min = '0';
$unit_long = 'SNR (dB)';
$unit = 'dB';
include 'wireless-sensor.inc.php';

View File

@ -0,0 +1,9 @@
<?php
$scale_min = '0';
$scale_max = '100';
$unit_long = 'Utilization (%)';
$unit = '%';
include 'wireless-sensor.inc.php';

View File

@ -0,0 +1,82 @@
<?php
/**
* wireless-sensor.inc.php
*
* Common file for Wireless Sensor Graphs
*
* 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>
*/
require 'includes/graphs/common.inc.php';
// escape % characters
$unit = preg_replace('/(?<!%)%(?!%)/', '%%', $unit);
if ($unit_long == $sensor['sensor_descr']) {
$unit_long = '';
}
$col_w = 7 + strlen($unit);
$sensor_descr_fixed = rrdtool_escape($sensor['sensor_descr'], 28);
$rrd_options .= " COMMENT:'". str_pad($unit_long, 35) . str_pad("Cur", $col_w). str_pad("Min", $col_w) . "Max\\n'";
$rrd_options .= " DEF:sensor=$rrd_filename:sensor:AVERAGE";
$num = '%5.2lf'; // default: float
$output_def = 'sensor';
$factor = 1;
if ($unit === '') {
$num = '%5.0lf';
} elseif ($unit == 'bps') {
$num = '%5.3lf%s';
} elseif ($unit == 'Hz') {
$num = '%5.3lf%s';
$factor = 1000000;
$output_def = 'sensorhz';
$rrd_options .= " CDEF:$output_def=sensor,$factor,*";
} elseif ($unit == 'm') {
$num = '%5.3lf%s';
$factor = 1000;
$output_def = 'sensorm';
$rrd_options .= " CDEF:$output_def=sensor,$factor,*";
}
$rrd_options .= " LINE1.5:$output_def#0000cc:'$sensor_descr_fixed'";
if (isset($scale_min) && $scale_min >= 0) {
$rrd_options .= " AREA:$output_def#0000cc55";
}
// ---- limits ----
if ($vars['width'] > 300) {
if (is_numeric($sensor['sensor_limit'])) {
$rrd_options .= ' LINE1:'.$sensor['sensor_limit']*$factor.'#cc000060::dashes';
}
if (is_numeric($sensor['sensor_limit_low'])) {
$rrd_options .= ' LINE1:'.$sensor['sensor_limit_low']*$factor.'#cc000060::dashes';
}
}
// ---- legend ----
$rrd_options .= " GPRINT:$output_def:LAST:'$num$unit'";
$rrd_options .= " GPRINT:$output_def:MIN:'$num$unit'";
$rrd_options .= " GPRINT:$output_def:MAX:'$num$unit'\\l";

View File

@ -1,6 +1,7 @@
<?php
// FIXME - this could do with some performance improvements, i think. possible rearranging some tables and setting flags at poller time (nothing changes outside of then anyways)
use LibreNMS\Device\WirelessSensor;
use LibreNMS\ObjectCache;
$service_status = get_service_status();
@ -410,6 +411,25 @@ foreach (array_keys($menu_sensors) as $item) {
</li>
<?php
$valid_wireless_types = WirelessSensor::getTypes(true);
if (!empty($valid_wireless_types)) {
echo '<li class="dropdown">
<a href="wireless/" class="dropdown-toggle" data-hover="dropdown" data-toggle="dropdown">
<i class="fa fa-wifi fa-fw fa-lg fa-nav-icons hidden-md" aria-hidden="true"></i> <span class="hidden-sm">Wireless</span></a>
<ul class="dropdown-menu">';
foreach ($valid_wireless_types as $type => $meta) {
echo '<li><a href="wireless/metric='.$type.'/">';
echo '<i class="fa fa-'.$meta['icon'].' fa-fw fa-lg" aria-hidden="true"></i> ';
echo $meta['short'];
echo '</a></li>';
}
echo '</ul></li>';
}
$app_list = dbFetchRows("SELECT DISTINCT(`app_type`) AS `app_type` FROM `applications` ORDER BY `app_type`");
if ($_SESSION['userlevel'] >= '5' && count($app_list) > "0") {

View File

@ -162,6 +162,7 @@ foreach (dbFetchRows($sql, $param) as $device) {
$device['os_text'] = $config['os'][$device['os']]['text'];
$port_count = dbFetchCell('SELECT COUNT(*) FROM `ports` WHERE `device_id` = ?', array($device['device_id']));
$sensor_count = dbFetchCell('SELECT COUNT(*) FROM `sensors` WHERE `device_id` = ?', array($device['device_id']));
$wireless_count = dbFetchCell('SELECT COUNT(*) FROM `wireless_sensors` WHERE `device_id` = ?', array($device['device_id']));
$actions = '
<div class="container-fluid">
@ -203,21 +204,37 @@ foreach (dbFetchRows($sql, $param) as $device) {
} elseif ($device['hostname'] !== $device['ip']) {
$hostname .= '<br />' . $device['hostname'];
}
if (empty($port_count)) {
$port_count = 0;
$col_port = '';
}
$metrics = array();
if ($port_count) {
$col_port = '<i class="fa fa-link fa-lg icon-theme"></i> ' . $port_count . '<br>';
$port_widget = '<a href="' . generate_device_url($device, array('tab' => 'ports')) . '">';
$port_widget .= '<span><i class="fa fa-link fa-lg icon-theme"></i> ' . $port_count;
$port_widget .= '</span></a> ';
$metrics[] = $port_widget;
}
if ($sensor_count) {
$col_port .= '<i class="fa fa-dashboard fa-lg icon-theme"></i> ' . $sensor_count;
$sensor_widget = '<a href="' . generate_device_url($device, array('tab' => 'health')) . '">';
$sensor_widget .= '<span><i class="fa fa-dashboard fa-lg icon-theme"></i> ' . $sensor_count;
$sensor_widget .= '</span></a> ';
$metrics[] = $sensor_widget;
}
if ($wireless_count) {
$wireless_widget = '<a href="' . generate_device_url($device, array('tab' => 'wireless')) . '">';
$wireless_widget .= '<span><i class="fa fa-wifi fa-lg icon-theme"></i> ' . $wireless_count;
$wireless_widget .= '</span></a> ';
$metrics[] = $wireless_widget;
}
$col_port = '<div class="device-table-metrics">';
$col_port .= implode(count($metrics) == 2 ? '<br />' : '', $metrics);
$col_port .= '</div>';
} else {
$platform = $device['hardware'];
$os = $device['os_text'] . ' ' . $device['version'];
$uptime = formatUptime($device['uptime'], 'short');
$col_port = '';
}
$response[] = array(

View File

@ -0,0 +1,141 @@
<?php
$graph_type = mres($_POST['graph_type']);
$unit = mres($_POST['unit']);
$class = mres($_POST['class']);
$sql = " FROM `$table` AS S, `devices` AS D";
if (is_admin() === false && is_read() === false) {
$sql .= ', devices_perms as P';
}
$sql .= " WHERE S.sensor_class=? AND S.device_id = D.device_id ";
$param[] = mres($_POST['class']);
if (is_admin() === false && is_read() === false) {
$sql .= " AND D.device_id = P.device_id AND P.user_id = ?";
$param[] = $_SESSION['user_id'];
}
if (isset($searchPhrase) && !empty($searchPhrase)) {
$sql .= " AND (`D`.`hostname` LIKE '%$searchPhrase%' OR `sensor_descr` LIKE '%$searchPhrase%' OR `sensor_current` LIKE '%searchPhrase')";
}
$count_sql = "SELECT COUNT(`sensor_id`) $sql";
$count = dbFetchCell($count_sql, $param);
if (empty($count)) {
$count = 0;
}
if (!isset($sort) || empty($sort)) {
$sort = '`D`.`hostname`, `S`.`sensor_descr`';
}
$sql .= " ORDER BY $sort";
if (isset($current)) {
$limit_low = (($current * $rowCount) - ($rowCount));
$limit_high = $rowCount;
}
if ($rowCount != -1) {
$sql .= " LIMIT $limit_low,$limit_high";
}
$sql = "SELECT * $sql";
foreach (dbFetchRows($sql, $param) as $sensor) {
if (!isset($sensor['sensor_current'])) {
$sensor['sensor_current'] = 'NaN';
} else {
if ($sensor['sensor_current'] >= $sensor['sensor_limit']) {
$alert = '<i class="fa fa-flag fa-lg" style="color:red" aria-hidden="true"></i>';
} else {
$alert = '';
}
}
// FIXME - make this "four graphs in popup" a function/include and "small graph" a function.
// FIXME - So now we need to clean this up and move it into a function. Isn't it just "print-graphrow"?
// FIXME - DUPLICATED IN device/overview/sensors
$graph_colour = str_replace('#', '', $row_colour);
$graph_array = array();
$graph_array['height'] = '100';
$graph_array['width'] = '210';
$graph_array['to'] = $config['time']['now'];
$graph_array['id'] = $sensor['sensor_id'];
$graph_array['type'] = $graph_type;
$graph_array['from'] = $config['time']['day'];
$graph_array['legend'] = 'no';
$link_array = $graph_array;
$link_array['page'] = 'graphs';
unset($link_array['height'], $link_array['width'], $link_array['legend']);
$link_graph = generate_url($link_array);
$link = generate_url(array('page' => 'device', 'device' => $sensor['device_id'], 'tab' => $tab, 'metric' => $sensor['sensor_class']));
$overlib_content = '<div style="width: 580px;"><h2>'.$sensor['hostname'].' - '.$sensor['sensor_descr'].'</h1>';
foreach (array('day', 'week', 'month', 'year') as $period) {
$graph_array['from'] = $config['time'][$period];
$overlib_content .= str_replace('"', "\'", generate_graph_tag($graph_array));
}
$overlib_content .= '</div>';
$graph_array['width'] = 80;
$graph_array['height'] = 20;
$graph_array['bg'] = 'ffffff00';
// the 00 at the end makes the area transparent.
$graph_array['from'] = $config['time']['day'];
$sensor_minigraph = generate_lazy_graph_tag($graph_array);
$sensor['sensor_descr'] = substr($sensor['sensor_descr'], 0, 48);
$response[] = array(
'hostname' => generate_device_link($sensor),
'sensor_descr' => overlib_link($link, $sensor['sensor_descr'], $overlib_content, null),
'graph' => overlib_link($link_graph, $sensor_minigraph, $overlib_content, null),
'alert' => $alert,
'sensor_current' => $sensor['sensor_current'].$unit,
'sensor_range' => round($sensor['sensor_limit_low'], 2).$unit.' - '.round($sensor['sensor_limit'], 2).$unit,
);
if ($_POST['view'] == 'graphs') {
$daily_graph = 'graph.php?id='.$sensor['sensor_id'].'&amp;type='.$graph_type.'&amp;from='.$config['time']['day'].'&amp;to='.$config['time']['now'].'&amp;width=211&amp;height=100';
$daily_url = 'graph.php?id='.$sensor['sensor_id'].'&amp;type='.$graph_type.'&amp;from='.$config['time']['day'].'&amp;to='.$config['time']['now'].'&amp;width=400&amp;height=150';
$weekly_graph = 'graph.php?id='.$sensor['sensor_id'].'&amp;type='.$graph_type.'&amp;from='.$config['time']['week'].'&amp;to='.$config['time']['now'].'&amp;width=211&amp;height=100';
$weekly_url = 'graph.php?id='.$sensor['sensor_id'].'&amp;type='.$graph_type.'&amp;from='.$config['time']['week'].'&amp;to='.$config['time']['now'].'&amp;width=400&amp;height=150';
$monthly_graph = 'graph.php?id='.$sensor['sensor_id'].'&amp;type='.$graph_type.'&amp;from='.$config['time']['month'].'&amp;to='.$config['time']['now'].'&amp;width=211&amp;height=100';
$monthly_url = 'graph.php?id='.$sensor['sensor_id'].'&amp;type='.$graph_type.'&amp;from='.$config['time']['month'].'&amp;to='.$config['time']['now'].'&amp;width=400&amp;height=150';
$yearly_graph = 'graph.php?id='.$sensor['sensor_id'].'&amp;type='.$graph_type.'&amp;from='.$config['time']['year'].'&amp;to='.$config['time']['now'].'&amp;width=211&amp;height=100';
$yearly_url = 'graph.php?id='.$sensor['sensor_id'].'&amp;type='.$graph_type.'&amp;from='.$config['time']['year'].'&amp;to='.$config['time']['now'].'&amp;width=400&amp;height=150';
$response[] = array(
'hostname' => "<a onmouseover=\"return overlib('<img src=\'$daily_url\'>', LEFT);\" onmouseout=\"return nd();\">
<img src='$daily_graph' border=0></a> ",
'sensor_descr' => "<a onmouseover=\"return overlib('<img src=\'$weekly_url\'>', LEFT);\" onmouseout=\"return nd();\">
<img src='$weekly_graph' border=0></a> ",
'graph' => "<a onmouseover=\"return overlib('<img src=\'$monthly_url\'>', LEFT);\" onmouseout=\"return nd();\">
<img src='$monthly_graph' border=0></a>",
'alert' => '',
'sensor_current' => "<a onmouseover=\"return overlib('<img src=\'$yearly_url\'>', LEFT);\" onmouseout=\"return nd();\">
<img src='$yearly_graph' border=0></a>",
'sensor_range' => '',
);
} //end if
}//end foreach
$output = array(
'current' => $current,
'rowCount' => $rowCount,
'rows' => $response,
'total' => $count,
);
echo _json_encode($output);

View File

@ -1,141 +1,6 @@
<?php
$graph_type = mres($_POST['graph_type']);
$unit = mres($_POST['unit']);
$class = mres($_POST['class']);
$table = 'sensors';
$tab = 'health';
$sql = ' FROM `sensors` AS S, `devices` AS D';
if (is_admin() === false && is_read() === false) {
$sql .= ', devices_perms as P';
}
$sql .= " WHERE S.sensor_class=? AND S.device_id = D.device_id ";
$param[] = mres($_POST['class']);
if (is_admin() === false && is_read() === false) {
$sql .= " AND D.device_id = P.device_id AND P.user_id = ?";
$param[] = $_SESSION['user_id'];
}
if (isset($searchPhrase) && !empty($searchPhrase)) {
$sql .= " AND (`D`.`hostname` LIKE '%$searchPhrase%' OR `sensor_descr` LIKE '%$searchPhrase%' OR `sensor_current` LIKE '%searchPhrase')";
}
$count_sql = "SELECT COUNT(`sensor_id`) $sql";
$count = dbFetchCell($count_sql, $param);
if (empty($count)) {
$count = 0;
}
if (!isset($sort) || empty($sort)) {
$sort = '`D`.`hostname`, `S`.`sensor_descr`';
}
$sql .= " ORDER BY $sort";
if (isset($current)) {
$limit_low = (($current * $rowCount) - ($rowCount));
$limit_high = $rowCount;
}
if ($rowCount != -1) {
$sql .= " LIMIT $limit_low,$limit_high";
}
$sql = "SELECT * $sql";
foreach (dbFetchRows($sql, $param) as $sensor) {
if (!isset($sensor['sensor_current'])) {
$sensor['sensor_current'] = 'NaN';
} else {
if ($sensor['sensor_current'] >= $sensor['sensor_limit']) {
$alert = '<i class="fa fa-flag fa-lg" style="color:red" aria-hidden="true"></i>';
} else {
$alert = '';
}
}
// FIXME - make this "four graphs in popup" a function/include and "small graph" a function.
// FIXME - So now we need to clean this up and move it into a function. Isn't it just "print-graphrow"?
// FIXME - DUPLICATED IN device/overview/sensors
$graph_colour = str_replace('#', '', $row_colour);
$graph_array = array();
$graph_array['height'] = '100';
$graph_array['width'] = '210';
$graph_array['to'] = $config['time']['now'];
$graph_array['id'] = $sensor['sensor_id'];
$graph_array['type'] = $graph_type;
$graph_array['from'] = $config['time']['day'];
$graph_array['legend'] = 'no';
$link_array = $graph_array;
$link_array['page'] = 'graphs';
unset($link_array['height'], $link_array['width'], $link_array['legend']);
$link_graph = generate_url($link_array);
$link = generate_url(array('page' => 'device', 'device' => $sensor['device_id'], 'tab' => 'health', 'metric' => $sensor['sensor_class']));
$overlib_content = '<div style="width: 580px;"><h2>'.$sensor['hostname'].' - '.$sensor['sensor_descr'].'</h1>';
foreach (array('day', 'week', 'month', 'year') as $period) {
$graph_array['from'] = $config['time'][$period];
$overlib_content .= str_replace('"', "\'", generate_graph_tag($graph_array));
}
$overlib_content .= '</div>';
$graph_array['width'] = 80;
$graph_array['height'] = 20;
$graph_array['bg'] = 'ffffff00';
// the 00 at the end makes the area transparent.
$graph_array['from'] = $config['time']['day'];
$sensor_minigraph = generate_lazy_graph_tag($graph_array);
$sensor['sensor_descr'] = substr($sensor['sensor_descr'], 0, 48);
$response[] = array(
'hostname' => generate_device_link($sensor),
'sensor_descr' => overlib_link($link, $sensor['sensor_descr'], $overlib_content, null),
'graph' => overlib_link($link_graph, $sensor_minigraph, $overlib_content, null),
'alert' => $alert,
'sensor_current' => $sensor['sensor_current'].$unit,
'sensor_range' => round($sensor['sensor_limit_low'], 2).$unit.' - '.round($sensor['sensor_limit'], 2).$unit,
);
if ($_POST['view'] == 'graphs') {
$daily_graph = 'graph.php?id='.$sensor['sensor_id'].'&amp;type='.$graph_type.'&amp;from='.$config['time']['day'].'&amp;to='.$config['time']['now'].'&amp;width=211&amp;height=100';
$daily_url = 'graph.php?id='.$sensor['sensor_id'].'&amp;type='.$graph_type.'&amp;from='.$config['time']['day'].'&amp;to='.$config['time']['now'].'&amp;width=400&amp;height=150';
$weekly_graph = 'graph.php?id='.$sensor['sensor_id'].'&amp;type='.$graph_type.'&amp;from='.$config['time']['week'].'&amp;to='.$config['time']['now'].'&amp;width=211&amp;height=100';
$weekly_url = 'graph.php?id='.$sensor['sensor_id'].'&amp;type='.$graph_type.'&amp;from='.$config['time']['week'].'&amp;to='.$config['time']['now'].'&amp;width=400&amp;height=150';
$monthly_graph = 'graph.php?id='.$sensor['sensor_id'].'&amp;type='.$graph_type.'&amp;from='.$config['time']['month'].'&amp;to='.$config['time']['now'].'&amp;width=211&amp;height=100';
$monthly_url = 'graph.php?id='.$sensor['sensor_id'].'&amp;type='.$graph_type.'&amp;from='.$config['time']['month'].'&amp;to='.$config['time']['now'].'&amp;width=400&amp;height=150';
$yearly_graph = 'graph.php?id='.$sensor['sensor_id'].'&amp;type='.$graph_type.'&amp;from='.$config['time']['year'].'&amp;to='.$config['time']['now'].'&amp;width=211&amp;height=100';
$yearly_url = 'graph.php?id='.$sensor['sensor_id'].'&amp;type='.$graph_type.'&amp;from='.$config['time']['year'].'&amp;to='.$config['time']['now'].'&amp;width=400&amp;height=150';
$response[] = array(
'hostname' => "<a onmouseover=\"return overlib('<img src=\'$daily_url\'>', LEFT);\" onmouseout=\"return nd();\">
<img src='$daily_graph' border=0></a> ",
'sensor_descr' => "<a onmouseover=\"return overlib('<img src=\'$weekly_url\'>', LEFT);\" onmouseout=\"return nd();\">
<img src='$weekly_graph' border=0></a> ",
'graph' => "<a onmouseover=\"return overlib('<img src=\'$monthly_url\'>', LEFT);\" onmouseout=\"return nd();\">
<img src='$monthly_graph' border=0></a>",
'alert' => '',
'sensor_current' => "<a onmouseover=\"return overlib('<img src=\'$yearly_url\'>', LEFT);\" onmouseout=\"return nd();\">
<img src='$yearly_graph' border=0></a>",
'sensor_range' => '',
);
} //end if
}//end foreach
$output = array(
'current' => $current,
'rowCount' => $rowCount,
'rows' => $response,
'total' => $count,
);
echo _json_encode($output);
include 'sensors-common.php';

View File

@ -0,0 +1,6 @@
<?php
$table = 'wireless_sensors';
$tab = 'wireless';
include 'sensors-common.php';

View File

@ -125,6 +125,14 @@ if (device_permitted($vars['device']) || $permitted_by_port) {
</li>';
}
if (@dbFetchCell('SELECT COUNT(*) FROM `wireless_sensors` WHERE `device_id`=?', array($device['device_id'])) > '0') {
echo '<li role="presentation" '.$select['wireless'].'>
<a href="'.generate_device_url($device, array('tab' => 'wireless')).'">
<i class="fa fa-wifi fa-lg icon-theme" aria-hidden="true"></i> Wireless
</a>
</li>';
}
if (@dbFetchCell("SELECT COUNT(accesspoint_id) FROM access_points WHERE device_id = '".$device['device_id']."'") > '0') {
echo '<li role="presentation" '.$select['accesspoints'].'>
<a href="'.generate_device_url($device, array('tab' => 'accesspoints')).'">

View File

@ -29,10 +29,14 @@ if ($_SESSION['userlevel'] < '7') {
$panes['ipmi'] = 'IPMI';
if (dbFetchCell("SELECT COUNT(sensor_id) FROM `sensors` WHERE device_id = ? AND sensor_deleted='0' LIMIT 1", array($device['device_id'])) > 0) {
if (dbFetchCell("SELECT COUNT(*) FROM `sensors` WHERE `device_id` = ? AND `sensor_deleted`='0' LIMIT 1", array($device['device_id'])) > 0) {
$panes['health'] = 'Health';
}
if (dbFetchCell("SELECT COUNT(*) FROM `wireless_sensors` WHERE `device_id` = ? AND `sensor_deleted`='0' LIMIT 1", array($device['device_id'])) > 0) {
$panes['wireless-sensors'] = 'Wireless Sensors';
}
$panes['storage'] = 'Storage';
$panes['processors'] = 'Processors';
$panes['mempools'] = 'Memory';

View File

@ -1,189 +1,7 @@
<?php
/*
* LibreNMS
*
* Copyright (c) 2014 Neil Lathwood <https://github.com/laf/ http://www.lathwood.co.uk>
*
* 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. Please see LICENSE.txt at the top level of
* the source code distribution for details.
*/
$title = 'Health settings';
$table = 'sensors';
$ajax_prefix = 'sensor';
// FUA
?>
<h3>Health settings</h3>
<form class="form-inline">
<table class="table table-hover table-condensed table-bordered">
<tr class="info">
<th>Class</th>
<th>Type</th>
<th>Desc</th>
<th>Current</th>
<th class="col-sm-1">High</th>
<th class="col-sm-1">Low</th>
<th class="col-sm-2">Alerts</th>
<th></th>
</tr>
<?php
foreach (dbFetchRows("SELECT * FROM sensors WHERE device_id = ? AND sensor_deleted='0'", array($device['device_id'])) as $sensor) {
$rollback[] = array(
'sensor_id' => $sensor['sensor_id'],
'sensor_limit' => $sensor['sensor_limit'],
'sensor_limit_low' => $sensor['sensor_limit_low'],
'sensor_alert' => $sensor['sensor_alert'],
);
if ($sensor['sensor_alert'] == 1) {
$alert_status = 'checked';
} else {
$alert_status = '';
}
if ($sensor['sensor_custom'] == 'No') {
$custom = 'disabled';
} else {
$custom = '';
}
echo '
<tr>
<td>'.$sensor['sensor_class'].'</td>
<td>'.$sensor['sensor_type'].'</td>
<td>'.$sensor['sensor_descr'].'</td>
<td>'.$sensor['sensor_current'].'</td>
<td>
<div class="form-group has-feedback">
<input type="text" class="form-control input-sm sensor" id="high-'.$sensor['device_id'].'" data-device_id="'.$sensor['device_id'].'" data-value_type="sensor_limit" data-sensor_id="'.$sensor['sensor_id'].'" value="'.$sensor['sensor_limit'].'">
<span class="form-control-feedback">
<i class="fa" aria-hidden="true"></i>
</span>
</div>
</td>
<td>
<div class="form-group has-feedback">
<input type="text" class="form-control input-sm sensor" id="low-'.$sensor['device_id'].'" data-device_id="'.$sensor['device_id'].'" data-value_type="sensor_limit_low" data-sensor_id="'.$sensor['sensor_id'].'" value="'.$sensor['sensor_limit_low'].'">
<span class="form-control-feedback">
<i class="fa" aria-hidden="true"></i>
</span>
</div>
</td>
<td>
<input type="checkbox" name="alert-status" data-device_id="'.$sensor['device_id'].'" data-sensor_id="'.$sensor['sensor_id'].'" '.$alert_status.'>
</td>
<td>
<a type="button" class="btn btn-danger btn-sm '.$custom.' remove-custom" id="remove-custom" name="remove-custom" data-sensor_id="'.$sensor['sensor_id'].'">Clear custom</a>
</td>
</tr>
';
}
?>
</table>
</form>
<form id="alert-reset">
<?php
foreach ($rollback as $reset_data) {
echo '
<input type="hidden" name="sensor_id[]" value="'.$reset_data['sensor_id'].'">
<input type="hidden" name="sensor_limit[]" value="'.$reset_data['sensor_limit'].'">
<input type="hidden" name="sensor_limit_low[]" value="'.$reset_data['sensor_limit_low'].'">
<input type="hidden" name="sensor_alert[]" value="'.$reset_data['sensor_alert'].'">
';
}
?>
<input type="hidden" name="type" value="sensor-alert-reset">
<button id = "newThread" class="btn btn-primary btn-sm" type="submit">Reset values</button>
</form>
<script>
$('#newThread').on('click', function(e){
e.preventDefault(); // preventing default click action
var form = $('#alert-reset');
$.ajax({
type: 'POST',
url: 'ajax_form.php',
data: form.serialize(),
dataType: "html",
success: function(data){
//alert(data);
location.reload(true);
},
error:function(){
//alert('bad');
}
});
});
</script>
<script>
$( ".sensor" ).blur(function() {
var sensor_type = $(this).attr('id');
var device_id = $(this).data("device_id");
var sensor_id = $(this).data("sensor_id");
var value_type = $(this).data("value_type");
var data = $(this).val();
var $this = $(this);
$.ajax({
type: 'POST',
url: 'ajax_form.php',
data: { type: "health-update", device_id: device_id, data: data, sensor_id: sensor_id , value_type: value_type},
dataType: "html",
success: function(data){
$this.closest('.form-group').addClass('has-success');
$this.next().find('.fa').addClass('fa-check');
setTimeout(function(){
$this.closest('.form-group').removeClass('has-success');
$this.next().find('.fa').removeClass('fa-check');
}, 2000);
},
error:function(){
$this.closest('.form-group').addClass('has-error');
$this.next().find('.fa').addClass('fa-times');
setTimeout(function(){
$this.closest('.form-group').removeClass('has-error');
$this.next().find('.fa').removeClass('fa-times');
}, 2000);
}
});
});
$("[name='alert-status']").bootstrapSwitch('offColor','danger');
$('input[name="alert-status"]').on('switchChange.bootstrapSwitch', function(event, state) {
event.preventDefault();
var $this = $(this);
var device_id = $(this).data("device_id");
var sensor_id = $(this).data("sensor_id");
$.ajax({
type: 'POST',
url: 'ajax_form.php',
data: { type: "sensor-alert-update", device_id: device_id, sensor_id: sensor_id, state: state},
dataType: "html",
success: function(data){
//alert('good');
},
error:function(){
//alert('bad');
}
});
});
$("[name='remove-custom']").on('click', function(event) {
event.preventDefault();
var $this = $(this);
var sensor_id = $(this).data("sensor_id");
$.ajax({
type: 'POST',
url: 'ajax_form.php',
data: { type: "sensor-alert-update", sensor_id: sensor_id, sub_type: "remove-custom" },
dataType: "html",
success: function(data){
$this.addClass('disabled');
},
error:function(){
//alert('bad');
}
});
});
</script>
include 'sensors-common.php';

View File

@ -0,0 +1,201 @@
<?php
/*
* LibreNMS
*
* Copyright (c) 2014 Neil Lathwood <https://github.com/laf/ http://www.lathwood.co.uk>
* Copyright (c) 2017 Tony Murray <https://github.com/murrant>
*
* 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. Please see LICENSE.txt at the top level of
* the source code distribution for details.
*/
// FUA
echo "<h3>$title</h3>";
?>
<form class="form-inline">
<table class="table table-hover table-condensed table-bordered">
<tr class="info">
<th>Class</th>
<th>Type</th>
<th>Desc</th>
<th>Current</th>
<th class="col-sm-1">High</th>
<th class="col-sm-1">Low</th>
<th class="col-sm-2">Alerts</th>
<th></th>
</tr>
<?php
$rollback = array();
foreach (dbFetchRows("SELECT * FROM `$table` WHERE `device_id` = ? AND `sensor_deleted`='0'", array($device['device_id'])) as $sensor) {
$rollback[] = array(
'sensor_id' => $sensor['sensor_id'],
'sensor_limit' => $sensor['sensor_limit'],
'sensor_limit_low' => $sensor['sensor_limit_low'],
'sensor_alert' => $sensor['sensor_alert'],
);
if ($sensor['sensor_alert'] == 1) {
$alert_status = 'checked';
} else {
$alert_status = '';
}
if ($sensor['sensor_custom'] == 'No') {
$custom = 'disabled';
} else {
$custom = '';
}
echo '
<tr>
<td>'.$sensor['sensor_class'].'</td>
<td>'.$sensor['sensor_type'].'</td>
<td>'.$sensor['sensor_descr'].'</td>
<td>'.$sensor['sensor_current'].'</td>
<td>
<div class="form-group has-feedback">
<input type="text" class="form-control input-sm sensor" id="high-'.$sensor['device_id'].'" data-device_id="'.$sensor['device_id'].'" data-value_type="sensor_limit" data-sensor_id="'.$sensor['sensor_id'].'" value="'.$sensor['sensor_limit'].'">
<span class="form-control-feedback">
<i class="fa" aria-hidden="true"></i>
</span>
</div>
</td>
<td>
<div class="form-group has-feedback">
<input type="text" class="form-control input-sm sensor" id="low-'.$sensor['device_id'].'" data-device_id="'.$sensor['device_id'].'" data-value_type="sensor_limit_low" data-sensor_id="'.$sensor['sensor_id'].'" value="'.$sensor['sensor_limit_low'].'">
<span class="form-control-feedback">
<i class="fa" aria-hidden="true"></i>
</span>
</div>
</td>
<td>
<input type="checkbox" name="alert-status" data-device_id="'.$sensor['device_id'].'" data-sensor_id="'.$sensor['sensor_id'].'" '.$alert_status.'>
</td>
<td>
<a type="button" class="btn btn-danger btn-sm '.$custom.' remove-custom" id="remove-custom" name="remove-custom" data-sensor_id="'.$sensor['sensor_id'].'">Clear custom</a>
</td>
</tr>
';
}
?>
</table>
</form>
<form id="alert-reset">
<?php
foreach ($rollback as $reset_data) {
echo '
<input type="hidden" name="sensor_id[]" value="'.$reset_data['sensor_id'].'">
<input type="hidden" name="sensor_limit[]" value="'.$reset_data['sensor_limit'].'">
<input type="hidden" name="sensor_limit_low[]" value="'.$reset_data['sensor_limit_low'].'">
<input type="hidden" name="sensor_alert[]" value="'.$reset_data['sensor_alert'].'">
';
}
?>
<input type="hidden" name="type" value="sensor-alert-reset">
<button id = "newThread" class="btn btn-primary btn-sm" type="submit">Reset values</button>
</form>
<script>
$('#newThread').on('click', function(e){
e.preventDefault(); // preventing default click action
var form = $('#alert-reset');
$.ajax({
type: 'POST',
url: 'ajax_form.php',
data: form.serialize(),
dataType: "html",
success: function(data){
//alert(data);
location.reload(true);
},
error:function(){
//alert('bad');
}
});
});
</script>
<script>
$('.sensor').on('focusin', function(){
console.log("Saving value " + $(this).val());
$(this).data('val', $(this).val());
});
$( ".sensor" ).bind('blur keyup',function(e) {
if (e.type === 'keyup' && e.keyCode !== 13) return;
var prev = $(this).data('val');
var data = $(this).val();
if(prev === data) return;
var sensor_type = $(this).attr('id');
var device_id = $(this).data("device_id");
var sensor_id = $(this).data("sensor_id");
var value_type = $(this).data("value_type");
var $this = $(this);
$.ajax({
type: 'POST',
url: 'ajax_form.php',
data: { type: "<?php echo $ajax_prefix; ?>-update", device_id: device_id, data: data, sensor_id: sensor_id , value_type: value_type},
dataType: "html",
success: function(data){
$this.closest('.form-group').addClass('has-success');
$this.next().find('.fa').addClass('fa-check');
$this.data('val', $this.val());
$('.remove-custom[data-sensor_id='+sensor_id+']').removeClass('disabled');
setTimeout(function(){
$this.closest('.form-group').removeClass('has-success');
$this.next().find('.fa').removeClass('fa-check');
}, 2000);
},
error:function(){
$this.closest('.form-group').addClass('has-error');
$this.next().find('.fa').addClass('fa-times');
setTimeout(function(){
$this.closest('.form-group').removeClass('has-error');
$this.next().find('.fa').removeClass('fa-times');
}, 2000);
}
});
});
$("[name='alert-status']").bootstrapSwitch('offColor','danger');
$('input[name="alert-status"]').on('switchChange.bootstrapSwitch', function(event, state) {
event.preventDefault();
var $this = $(this);
var device_id = $(this).data("device_id");
var sensor_id = $(this).data("sensor_id");
$.ajax({
type: 'POST',
url: 'ajax_form.php',
data: { type: "<?php echo $ajax_prefix; ?>-alert-update", device_id: device_id, sensor_id: sensor_id, state: state},
dataType: "html",
success: function(data){
//alert('good');
},
error:function(){
//alert('bad');
}
});
});
$("[name='remove-custom']").on('click', function(event) {
event.preventDefault();
var $this = $(this);
var sensor_id = $(this).data("sensor_id");
$.ajax({
type: 'POST',
url: 'ajax_form.php',
data: { type: "<?php echo $ajax_prefix; ?>-alert-update", sensor_id: sensor_id, sub_type: "remove-custom" },
dataType: "html",
success: function(data){
$this.addClass('disabled');
},
error:function(){
//alert('bad');
}
});
});
</script>

View File

@ -0,0 +1,7 @@
<?php
$title = 'Wireless sensor settings';
$table = 'wireless_sensors';
$ajax_prefix = 'wireless-sensor';
include 'sensors-common.php';

Some files were not shown because too many files have changed in this diff Show More