From Ungracious Owl, 4 Years ago, written in Plain Text.
Embed
  1. <?php
  2. /**
  3.  * Ios.php - cpcat
  4.  *
  5.  * Cisco IOS
  6.  *
  7.  * This program is free software: you can redistribute it and/or modify
  8.  * it under the terms of the GNU General Public License as published by
  9.  * the Free Software Foundation, either version 3 of the License, or
  10.  * (at your option) any later version.
  11.  *
  12.  * This program is distributed in the hope that it will be useful,
  13.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
  15.  * GNU General Public License for more details.
  16.  *
  17.  * You should have received a copy of the GNU General Public License
  18.  * along with this program.  If not, see <http>.
  19.  *
  20.  * @package    LibreNMS
  21.  * @link       http://librenms.org
  22.  * @copyright  2017 Tony Murray
  23.  * @author     Tony Murray <murraytony>
  24.  */
  25.  
  26. namespace LibreNMS\OS;
  27.  
  28. use LibreNMS\Device\WirelessSensor;
  29. use LibreNMS\Interfaces\Discovery\Sensors\WirelessClientsDiscovery;
  30. use LibreNMS\Interfaces\Discovery\Sensors\WirelessRssiDiscovery;
  31. use LibreNMS\OS\Shared\Cisco;
  32.  
  33. class Ios extends Cisco implements
  34.     WirelessClientsDiscovery,
  35.     WirelessRssiDiscovery
  36. {
  37. //    use CiscoCellular;
  38.  
  39.     /**
  40.      * @return array Sensors
  41.      */
  42.     public function discoverWirelessClients()
  43.     {
  44.         $device = $this->getDevice();
  45.  
  46.         if (!starts_with($device['hardware'], 'AIR-') && !str_contains($device['hardware'], 'ciscoAIR')) {
  47.             // unsupported IOS hardware
  48.             return array();
  49.         }
  50.  
  51.         $data = snmpwalk_cache_oid($device, 'cDot11ActiveBridges', array(), 'CISCO-DOT11-ASSOCIATION-MIB');
  52.         $entPhys = snmpwalk_cache_oid($device, 'entPhysicalDescr', array(), 'ENTITY-MIB');
  53.  
  54.         // fixup incorrect/missing entPhysicalIndex mapping
  55.         foreach ($data as $index => $_unused) {
  56.             foreach ($entPhys as $entIndex => $ent) {
  57.                 $descr = $ent['entPhysicalDescr'];
  58.                 unset($entPhys[$entIndex]); // only use each one once
  59.  
  60.                 if (ends_with($descr, 'Radio')) {
  61.                     d_echo("Mapping entPhysicalIndex $entIndex to ifIndex $index\n");
  62.                     $data[$index]['entPhysicalIndex'] = $entIndex;
  63.                     $data[$index]['entPhysicalDescr'] = $descr;
  64.                     break;
  65.                 }
  66.             }
  67.         }
  68.  
  69.         $sensors = array();
  70.         foreach ($data as $index => $entry) {
  71.             $sensors[] = new WirelessSensor(
  72.                 'clients',
  73.                 $device['device_id'],
  74.                 ".1.3.6.1.4.1.9.9.273.1.1.2.1.2.$index",
  75.                 'ios',
  76.                 $index,
  77.                 $entry['entPhysicalDescr'],
  78.                 $entry['cDot11ActiveBridges'],
  79.                 1,
  80.                 1,
  81.                 'sum',
  82.                 null,
  83.                 null,
  84.                 0,
  85.                 null,
  86.                 null,
  87.                 $entry['entPhysicalIndex'],
  88.                 'ports'
  89.             );
  90.         }
  91.         return $sensors;
  92.     }
  93.  
  94.  
  95.     public function discoverWirelessRssi()
  96.     {
  97.         function gen_descr ($index) {
  98. //            $descr = "RSSI: ";
  99.             $raw = explode(".", str_replace ("1.3.6.1.4.1.9.9.273.1.3.1.1.3.", "", $index));
  100.             for ($i=0; $i &lt; $raw[1]; $i++) { // bridge name
  101.                 $descr = $descr . chr($raw[$i+2]);
  102.                 }
  103.             $descr = $descr . " ";
  104.             for ($i=6; $i > 0; $i--) { // MAC address of client
  105.                 $descr = $descr . ($raw[count($raw)-$i] > 15 ? "" : "0") . dechex($raw[count($raw)-$i]);
  106.                 }
  107.             return $descr;
  108.             }
  109.  
  110.         $device = $this->getDevice();
  111.  
  112.         if (!starts_with($device['hardware'], 'AIR-') && !str_contains($device['hardware'], 'ciscoAIR')) {
  113.             // unsupported IOS hardware
  114.             return array();
  115.         }
  116.  
  117.         $sensors = array();
  118.         $data = snmpwalk_cache_multi_oid($this->getDevice(), 'cDot11ClientSignalStrength', array(), 'CISCO-DOT11-ASSOCIATION-MIB', null, '-OQUn');
  119.  
  120.         foreach ($data as $index => $entry) {
  121.             $sensors[] = new WirelessSensor(
  122.                 'rssi', // $type
  123.                 $device['device_id'], // $device_id
  124.                 $index, // $oids
  125.                 'ios', // $subtype
  126.                 $index, // $index
  127.                 gen_descr($index), // $description
  128.                 $entry['.1.3.6.1.4.1.9.9.273.1.3.1.1.3.1.1'], // $current
  129.                 1, // $multiplier
  130.                 1, // $divisor
  131.                 'avg', // $aggregator
  132.                 null, // $access_point_id
  133.                 -10, // $low_limit
  134.                 -80, // $high_warn
  135.                 -20, // $high_warn
  136.                 -70, // $low_warn
  137.             );
  138.         }
  139.  
  140.         return $sensors;
  141.     }
  142.  
  143. }
  144.