Files

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

501 lines
16 KiB
PHP
Raw Permalink Normal View History

2017-05-01 23:49:11 -05:00
<?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
2021-02-09 00:29:04 +01:00
* along with this program. If not, see <https://www.gnu.org/licenses/>.
2017-05-01 23:49:11 -05:00
*
2021-02-09 00:29:04 +01:00
* @link https://www.librenms.org
2021-09-10 20:09:53 +02:00
*
2017-05-01 23:49:11 -05:00
* @copyright 2017 Tony Murray
* @author Tony Murray <murraytony@gmail.com>
*/
namespace LibreNMS\OS;
use LibreNMS\Device\WirelessSensor;
2023-10-04 10:32:59 -05:00
use LibreNMS\Interfaces\Data\DataStorageInterface;
2017-05-01 23:49:11 -05:00
use LibreNMS\Interfaces\Discovery\Sensors\WirelessCcqDiscovery;
use LibreNMS\Interfaces\Discovery\Sensors\WirelessClientsDiscovery;
2020-09-18 08:12:07 -05:00
use LibreNMS\Interfaces\Discovery\Sensors\WirelessDistanceDiscovery;
2017-05-01 23:49:11 -05:00
use LibreNMS\Interfaces\Discovery\Sensors\WirelessFrequencyDiscovery;
use LibreNMS\Interfaces\Discovery\Sensors\WirelessNoiseFloorDiscovery;
2020-09-18 08:12:07 -05:00
use LibreNMS\Interfaces\Discovery\Sensors\WirelessQualityDiscovery;
2017-05-01 23:49:11 -05:00
use LibreNMS\Interfaces\Discovery\Sensors\WirelessRateDiscovery;
use LibreNMS\Interfaces\Discovery\Sensors\WirelessRsrpDiscovery;
2020-09-18 08:12:07 -05:00
use LibreNMS\Interfaces\Discovery\Sensors\WirelessRsrqDiscovery;
use LibreNMS\Interfaces\Discovery\Sensors\WirelessRssiDiscovery;
use LibreNMS\Interfaces\Discovery\Sensors\WirelessSinrDiscovery;
2020-09-18 08:12:07 -05:00
use LibreNMS\Interfaces\Polling\OSPolling;
2017-05-01 23:49:11 -05:00
use LibreNMS\OS;
2020-09-18 08:12:07 -05:00
use LibreNMS\RRD\RrdDefinition;
2017-05-01 23:49:11 -05:00
class Routeros extends OS implements
2020-09-18 08:12:07 -05:00
OSPolling,
2017-05-01 23:49:11 -05:00
WirelessCcqDiscovery,
WirelessClientsDiscovery,
WirelessFrequencyDiscovery,
WirelessNoiseFloorDiscovery,
WirelessRateDiscovery,
2018-11-05 18:21:32 +10:30
WirelessRssiDiscovery,
WirelessDistanceDiscovery,
WirelessRsrqDiscovery,
WirelessRsrpDiscovery,
WirelessSinrDiscovery,
WirelessQualityDiscovery
2017-05-01 23:49:11 -05:00
{
/**
* Returns an array of LibreNMS\Device\Sensor objects that have been discovered
*
* @return array Sensors
*/
public function discoverWirelessCcq()
{
$sensors = [];
$data = $this->getCacheTable('MIKROTIK-MIB::mtxrWlApTable');
foreach ($data as $index => $entry) {
// skip sensors with no data (nv2 should report 1 client, but doesn't report ccq)
if ($entry['mtxrWlApClientCount'] > 0 && $entry['mtxrWlApOverallTxCCQ'] == 0) {
continue;
}
$freq = $entry['mtxrWlApFreq'] ? substr($entry['mtxrWlApFreq'], 0, 1) . 'G' : 'SSID';
$sensors[] = new WirelessSensor(
'ccq',
$this->getDeviceId(),
'.1.3.6.1.4.1.14988.1.1.1.3.1.10.' . $index,
'mikrotik',
$index,
"$freq: " . $entry['mtxrWlApSsid'],
$entry['mtxrWlApOverallTxCCQ']
);
}
2020-09-21 14:54:51 +02:00
2022-08-10 14:12:17 +02:00
$data = $this->getCacheTable('MIKROTIK-MIB::mtxrWlStatTable');
foreach ($data as $index => $entry) {
$freq = $entry['mtxrWlStatFreq'] ? substr($entry['mtxrWlStatFreq'], 0, 1) . 'G' : 'SSID';
if (empty($entry['mtxrWlStatTxCCQ']) && empty($entry['mtxrWlStatRxCCQ'])) {
continue;
}
$sensors[] = new WirelessSensor(
'ccq',
$this->getDeviceId(),
'.1.3.6.1.4.1.14988.1.1.1.1.1.9.' . $index,
'mikrotik-tx-ccq',
$index,
"$freq: " . $entry['mtxrWlStatSsid'] . ' Tx',
$entry['mtxrWlStatTxCCQ']
);
$sensors[] = new WirelessSensor(
'ccq',
$this->getDeviceId(),
'.1.3.6.1.4.1.14988.1.1.1.1.1.10.' . $index,
'mikrotik-rx-ccq',
$index,
"$freq: " . $entry['mtxrWlStatSsid'] . ' Rx',
$entry['mtxrWlStatRxCCQ']
);
}
return $sensors;
2017-05-01 23:49:11 -05:00
}
2020-09-21 14:54:51 +02:00
2017-05-01 23:49:11 -05:00
/**
* Returns an array of LibreNMS\Device\Sensor objects that have been discovered
*
* @return array Sensors
*/
public function discoverWirelessClients()
{
$sensors = [];
$data = $this->getCacheTable('MIKROTIK-MIB::mtxrWlApTable');
foreach ($data as $index => $entry) {
$freq = $entry['mtxrWlApFreq'] ? substr($entry['mtxrWlApFreq'], 0, 1) . 'G' : 'SSID';
$sensors[] = new WirelessSensor(
'clients',
$this->getDeviceId(),
'.1.3.6.1.4.1.14988.1.1.1.3.1.6.' . $index,
'mikrotik',
$index,
"$freq: " . $entry['mtxrWlApSsid'],
$entry['mtxrWlApClientCount']
);
}
return $sensors;
2017-05-01 23:49:11 -05:00
}
2020-09-21 14:54:51 +02:00
2017-05-01 23:49:11 -05:00
/**
* 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()
{
$sensors = [];
$data = $this->getCacheTable('MIKROTIK-MIB::mtxrWlApTable');
foreach ($data as $index => $entry) {
if ($entry['mtxrWlApFreq'] === '0') {
continue;
}
$freq = substr($entry['mtxrWlApFreq'], 0, 1) . 'G';
$sensors[] = new WirelessSensor(
'frequency',
$this->getDeviceId(),
'.1.3.6.1.4.1.14988.1.1.1.3.1.7.' . $index,
'mikrotik',
$index,
"$freq: " . $entry['mtxrWlApSsid'],
$entry['mtxrWlApFreq']
);
}
2022-08-10 14:12:17 +02:00
$data = $this->getCacheTable('MIKROTIK-MIB::mtxrWlStatTable');
foreach ($data as $index => $entry) {
if ($entry['mtxrWlStatFreq'] === '0') {
continue;
}
$freq = substr($entry['mtxrWlStatFreq'], 0, 1) . 'G';
$sensors[] = new WirelessSensor(
'frequency',
$this->getDeviceId(),
'.1.3.6.1.4.1.14988.1.1.1.1.1.7.' . $index,
'mikrotik',
$index,
"$freq: " . $entry['mtxrWlStatSsid'],
$entry['mtxrWlStatFreq']
);
}
$data = $this->getCacheTable('MIKROTIK-MIB::mtxrWl60GTable');
foreach ($data as $index => $entry) {
$sensors[] = new WirelessSensor(
'frequency',
$this->getDeviceId(),
'.1.3.6.1.4.1.14988.1.1.1.8.1.6.' . $index,
'mikrotik-60g',
$index,
'60G: ' . $entry['mtxrWl60GSsid'],
$entry['mtxrWl60GFreq']
);
}
2021-04-23 04:49:33 +02:00
return $sensors;
}
2020-09-21 14:54:51 +02:00
/**
* Discover wireless Rssi. This is in Dbm. Type is Dbm.
* Returns an array of LibreNMS\Device\Sensor objects that have been discovered
*
* @return array Sensors
*/
public function discoverWirelessRssi()
2017-05-01 23:49:11 -05:00
{
$sensors = [];
$data = $this->getCacheTable('MIKROTIK-MIB::mtxrWl60GTable');
foreach ($data as $index => $entry) {
$sensors[] = new WirelessSensor(
'rssi',
$this->getDeviceId(),
'.1.3.6.1.4.1.14988.1.1.1.8.1.12.' . $index,
'mikrotik',
$index,
'60G: ' . $entry['mtxrWl60GSsid'],
$entry['mtxrWl60GRssi']
);
}
return $sensors;
2017-05-01 23:49:11 -05:00
}
2020-09-21 14:54:51 +02:00
/**
* Discover wireless Quality. This is in Dbm. Type is Dbm.
* Returns an array of LibreNMS\Device\Sensor objects that have been discovered
*
* @return array Sensors
*/
public function discoverWirelessQuality()
{
$sensors = [];
$data = $this->getCacheTable('MIKROTIK-MIB::mtxrWl60GTable');
foreach ($data as $index => $entry) {
$sensors[] = new WirelessSensor(
'quality',
$this->getDeviceId(),
'.1.3.6.1.4.1.14988.1.1.1.8.1.8.' . $index,
'mikrotik',
$index,
'60G: ' . $entry['mtxrWl60GSsid'],
$entry['mtxrWl60GSignal']
);
}
return $sensors;
}
2020-09-21 14:54:51 +02:00
2017-05-01 23:49:11 -05:00
/**
* Returns an array of LibreNMS\Device\Sensor objects that have been discovered
*
* @return array Sensors
*/
public function discoverWirelessNoiseFloor()
{
$sensors = [];
$data = $this->getCacheTable('MIKROTIK-MIB::mtxrWlApTable');
foreach ($data as $index => $entry) {
$freq = $entry['mtxrWlApFreq'] ? substr($entry['mtxrWlApFreq'], 0, 1) . 'G' : 'SSID';
$sensors[] = new WirelessSensor(
'noise-floor',
$this->getDeviceId(),
'.1.3.6.1.4.1.14988.1.1.1.3.1.9.' . $index,
'mikrotik',
$index,
"$freq: " . $entry['mtxrWlApSsid'],
$entry['mtxrWlApNoiseFloor']
);
}
return $sensors;
2017-05-01 23:49:11 -05:00
}
2020-09-21 14:54:51 +02:00
2017-05-01 23:49:11 -05:00
/**
* 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()
{
$sensors = [];
2022-08-10 14:12:17 +02:00
$data = $this->getCacheTable('MIKROTIK-MIB::mtxrWlApTable');
2017-05-01 23:49:11 -05:00
foreach ($data as $index => $entry) {
if ($entry['mtxrWlApTxRate'] === '0' && $entry['mtxrWlApRxRate'] === '0') {
continue; // no data
}
2022-08-10 14:12:17 +02:00
$freq = $entry['mtxrWlApFreq'] ? substr($entry['mtxrWlApFreq'], 0, 1) . 'G' : 'SSID';
2017-05-01 23:49:11 -05:00
$sensors[] = new WirelessSensor(
'rate',
$this->getDeviceId(),
'.1.3.6.1.4.1.14988.1.1.1.3.1.2.' . $index,
'mikrotik-tx',
$index,
2022-08-10 14:12:17 +02:00
"$freq: " . $entry['mtxrWlApSsid'] . ' Tx',
2017-05-01 23:49:11 -05:00
$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,
2022-08-10 14:12:17 +02:00
"$freq: " . $entry['mtxrWlApSsid'] . ' Rx',
2017-05-01 23:49:11 -05:00
$entry['mtxrWlApRxRate']
);
}
2022-08-10 14:12:17 +02:00
$data = $this->getCacheTable('MIKROTIK-MIB::mtxrWlStatTable');
foreach ($data as $index => $entry) {
if ($entry['mtxrWlStatTxRate'] === '0' && $entry['mtxrWlStatRxRate'] === '0') {
continue; // no data
}
$freq = $entry['mtxrWlStatFreq'] ? substr($entry['mtxrWlStatFreq'], 0, 1) . 'G' : 'SSID';
$sensors[] = new WirelessSensor(
'rate',
$this->getDeviceId(),
'.1.3.6.1.4.1.14988.1.1.1.1.1.2.' . $index,
'mikrotik-tx',
$index,
"$freq: " . $entry['mtxrWlStatSsid'] . ' Tx',
$entry['mtxrWlStatTxRate']
);
$sensors[] = new WirelessSensor(
'rate',
$this->getDeviceId(),
'.1.3.6.1.4.1.14988.1.1.1.1.1.3.' . $index,
'mikrotik-rx',
$index,
"$freq: " . $entry['mtxrWlStatSsid'] . ' Rx',
$entry['mtxrWlStatRxRate']
);
}
2022-08-10 14:12:17 +02:00
$data = $this->getCacheTable('MIKROTIK-MIB::mtxrWl60GTable');
foreach ($data as $index => $entry) {
$sensors[] = new WirelessSensor(
'rate',
$this->getDeviceId(),
'.1.3.6.1.4.1.14988.1.1.1.8.1.13.' . $index,
2018-11-05 18:21:32 +10:30
'mikrotik-60g-tx',
$index,
'60G: ' . $entry['mtxrWl60GSsid'],
$entry['mtxrWl60GPhyRate'],
1000000
);
2017-05-01 23:49:11 -05:00
}
2020-09-21 14:54:51 +02:00
2017-05-01 23:49:11 -05:00
return $sensors;
}
2020-09-21 14:54:51 +02:00
/**
* 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
*/
2018-11-05 18:21:32 +10:30
public function discoverWirelessDistance()
{
$sensors = [];
$data = $this->getCacheTable('MIKROTIK-MIB::mtxrWl60GStaTable');
2018-11-05 18:21:32 +10:30
foreach ($data as $index => $entry) {
$sensors[] = new WirelessSensor(
'distance',
$this->getDeviceId(),
'.1.3.6.1.4.1.14988.1.1.1.9.1.10.' . $index,
2018-11-05 18:21:32 +10:30
'mikrotik',
$index,
'60G: Sta > ' . $entry['mtxrWl60GStaRemote'],
$entry['mtxrWl60GStaDistance'],
1,
100000
2018-11-05 18:21:32 +10:30
);
}
2020-09-21 14:54:51 +02:00
2018-11-05 18:21:32 +10:30
return $sensors;
}
2020-09-21 14:54:51 +02:00
/**
* Discover LTE RSRQ. This is in Dbm. Type is Dbm.
* Returns an array of LibreNMS\Device\Sensor objects that have been discovered
*
* @return array Sensors
*/
public function discoverWirelessRsrq()
{
$data = $this->getCacheTable('MIKROTIK-MIB::mtxrLTEModemTable');
2020-09-21 14:54:51 +02:00
$sensors = [];
foreach ($data as $index => $entry) {
$name = $this->getCacheByIndex('MIKROTIK-MIB::mtxrInterfaceStatsName');
$sensors[] = new WirelessSensor(
'rsrq',
$this->getDeviceId(),
'.1.3.6.1.4.1.14988.1.1.16.1.1.3.' . $index,
'routeros',
$index,
$name[$index] . ': Signal RSRQ',
$entry['mtxrLTEModemSignalRSRQ']
);
}
return $sensors;
}
2020-09-21 14:54:51 +02:00
/**
* Discover LTE RSRP. This is in Dbm. Type is Dbm.
* Returns an array of LibreNMS\Device\Sensor objects that have been discovered
*
* @return array Sensors
*/
public function discoverWirelessRsrp()
{
$data = $this->getCacheTable('MIKROTIK-MIB::mtxrLTEModemTable');
2020-09-21 14:54:51 +02:00
$sensors = [];
foreach ($data as $index => $entry) {
$name = $this->getCacheByIndex('MIKROTIK-MIB::mtxrInterfaceStatsName');
$sensors[] = new WirelessSensor(
'rsrp',
$this->getDeviceId(),
'.1.3.6.1.4.1.14988.1.1.16.1.1.4.' . $index,
'routeros',
$index,
$name[$index] . ': Signal RSRP',
$entry['mtxrLTEModemSignalRSRP']
);
}
return $sensors;
}
2020-09-21 14:54:51 +02:00
/**
* Discover LTE SINR. This is in Dbm. Type is Dbm.
* Returns an array of LibreNMS\Device\Sensor objects that have been discovered
*
* @return array Sensors
*/
public function discoverWirelessSinr()
{
$data = $this->getCacheTable('MIKROTIK-MIB::mtxrLTEModemTable');
2020-09-21 14:54:51 +02:00
$sensors = [];
foreach ($data as $index => $entry) {
$name = $this->getCacheByIndex('MIKROTIK-MIB::mtxrInterfaceStatsName');
$sensors[] = new WirelessSensor(
'sinr',
$this->getDeviceId(),
'.1.3.6.1.4.1.14988.1.1.16.1.1.7.' . $index,
'routeros',
$index,
$name[$index] . ': Signal SINR',
$entry['mtxrLTEModemSignalSINR']
);
}
return $sensors;
}
2020-09-18 08:12:07 -05:00
2023-10-04 10:32:59 -05:00
public function pollOS(DataStorageInterface $datastore): void
2020-09-18 08:12:07 -05:00
{
$leases = snmp_get($this->getDeviceArray(), 'mtxrDHCPLeaseCount.0', '-OQv', 'MIKROTIK-MIB');
if (is_numeric($leases)) {
$rrd_def = RrdDefinition::make()->addDataset('leases', 'GAUGE', 0);
$fields = [
'leases' => $leases,
];
$tags = compact('rrd_def');
2023-10-04 10:32:59 -05:00
$datastore->put($this->getDeviceArray(), 'routeros_leases', $tags, $fields);
2020-09-18 08:12:07 -05:00
$this->enableGraph('routeros_leases');
}
$pppoe_sessions = snmp_get($this->getDeviceArray(), '1.3.6.1.4.1.9.9.150.1.1.1.0', '-OQv', '', '');
if (is_numeric($pppoe_sessions)) {
$rrd_def = RrdDefinition::make()->addDataset('pppoe_sessions', 'GAUGE', 0);
$fields = [
'pppoe_sessions' => $pppoe_sessions,
];
$tags = compact('rrd_def');
2023-10-04 10:32:59 -05:00
$datastore->put($this->getDeviceArray(), 'routeros_pppoe_sessions', $tags, $fields);
2020-09-18 08:12:07 -05:00
$this->enableGraph('routeros_pppoe_sessions');
}
}
2017-05-01 23:49:11 -05:00
}