Skip to content

Commit

Permalink
FS.COM (Fiberstore) 'GBN' and 'SWITCH' devices support (#9734)
Browse files Browse the repository at this point in the history
* Basic Support for Fiberstore devices

* Basic Support for Fiberstore devices

* mib files

* sysObjectID added

* mibs added

* MIB corrections + CPU discovery + version and SN

* CodeClimate + mempools

* CodeClimate + mempools

* mempools

* 5800

* testdata

* 5800

* tests

* mempools for 5800

* CodeClimate

* CodeClimate

* Cleaning and comments

* Tests for 5800

* CodeClimate

* Update Fs.php

* init processors[]

* optimized logo

* optimized logo

* optimized logo

* optimized logo

* split FS devices

* split FS devices

* split FS devices - tests

* split FS devices - class

* split FS devices - class

* split FS devices - tests

* removing un-necessry condition

* text and comments
  • Loading branch information
PipoCanaja authored and murrant committed Feb 10, 2019
1 parent bc93d8c commit 7e18a07
Show file tree
Hide file tree
Showing 70 changed files with 149,984 additions and 0 deletions.
60 changes: 60 additions & 0 deletions LibreNMS/OS/FsGbn.php
@@ -0,0 +1,60 @@
<?php
/**
* Fs.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 2019 PipoCanaja
* @author PipoCanaja <pipocanaja@gmail.com>
*/

namespace LibreNMS\OS;

use LibreNMS\Device\Processor;
use LibreNMS\Interfaces\Discovery\ProcessorDiscovery;
use LibreNMS\OS;

class FsGbn extends OS implements ProcessorDiscovery
{
/**
* Discover processors.
* Returns an array of LibreNMS\Device\Processor objects that have been discovered
*
* @return array Processors
*/
public function discoverProcessors()
{
$processors = [];

// Test first pair of OIDs from GBNPlatformOAM-MIB
$processors_data = snmpwalk_cache_oid($this->getDevice(), 'cpuDescription', [], 'GBNPlatformOAM-MIB', 'fs');
$processors_data = snmpwalk_cache_oid($this->getDevice(), 'cpuIdle', $processors_data, 'GBNPlatformOAM-MIB', 'fs');
foreach ($processors_data as $index => $entry) {
$processors[] = Processor::discover(
$this->getName(),
$this->getDeviceId(),
'.1.3.6.1.4.1.13464.1.2.1.1.2.11.'.$index, //GBNPlatformOAM-MIB::cpuIdle.0 = INTEGER: 95
$index,
$entry['cpuDescription'],
-1,
100 - $entry['cpuIdle']
);
}
return $processors;
}
}
60 changes: 60 additions & 0 deletions LibreNMS/OS/FsSwitch.php
@@ -0,0 +1,60 @@
<?php
/**
* Fs-switch.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 2019 PipoCanaja
* @author PipoCanaja <pipocanaja@gmail.com>
*/

namespace LibreNMS\OS;

use LibreNMS\Device\Processor;
use LibreNMS\Interfaces\Discovery\ProcessorDiscovery;
use LibreNMS\OS;

class FsSwitch extends OS implements ProcessorDiscovery
{
/**
* Discover processors.
* Returns an array of LibreNMS\Device\Processor objects that have been discovered
*
* @return array Processors
*/
public function discoverProcessors()
{
$processors = [];

// Tests OID from SWITCH MIB.
$processors_data = snmpwalk_cache_oid($this->getDevice(), 'ssCpuIdle', [], 'SWITCH', 'fs');

foreach ($processors_data as $index => $entry) {
$processors[] = Processor::discover(
"fs-SWITCHMIB",
$this->getDeviceId(),
'.1.3.6.1.4.1.27975.1.2.11.' . $index,
$index,
"CPU",
-1,
100 - $entry['ssCpuIdle']
);
}
return $processors;
}
}
1 change: 1 addition & 0 deletions html/images/os/fs.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions includes/definitions/fs-gbn.yaml
@@ -0,0 +1,14 @@
os: fs-gbn
text: 'Fiberstore GBN'
type: network
icon: fs
group: fs
over:
- { graph: device_bits, text: 'Device Traffic' }
- { graph: device_processor, text: 'Processor Usage' }
- { graph: device_mempool, text: 'Memory Usage' }
mib_dir:
- fs
discovery:
- sysObjectID:
- .1.3.6.1.4.1.13464
16 changes: 16 additions & 0 deletions includes/definitions/fs-switch.yaml
@@ -0,0 +1,16 @@
os: fs-switch
text: 'Fiberstore Switch'
type: network
icon: fs
group: fs
over:
- { graph: device_bits, text: 'Device Traffic' }
- { graph: device_processor, text: 'Processor Usage' }
- { graph: device_mempool, text: 'Memory Usage' }
mib_dir:
- fs
discovery:
- sysObjectID:
- .1.3.6.1.4.1.51134
- .1.3.6.1.4.1.27975
- .1.3.6.1.4.1.12345
34 changes: 34 additions & 0 deletions includes/discovery/mempools/fs-gbn.inc.php
@@ -0,0 +1,34 @@
<?php
//
// Discovery for FS gbn devices.
//
//

if ($device['os'] == 'fs-gbn') {
echo 'FS : ';
//
// OIDs from GBNPlatformOAM-MIB
//
$mempools_array = snmpwalk_cache_oid($device, 'memorySize', $mempools_array, 'GBNPlatformOAM-MIB', 'fs');
$mempools_array = snmpwalk_cache_oid($device, 'memoryIdle', $mempools_array, 'GBNPlatformOAM-MIB', 'fs');
$mempools_array = snmpwalk_cache_oid($device, 'cpuDescription', $mempools_array, 'GBNPlatformOAM-MIB', 'fs');
d_echo($mempools_array);
foreach ($mempools_array as $index => $entry) {
//
// We keep the foreach in case multiple replies are seen here.
// We could replace it with a condition (if we suppose only 1 reply will ever come) but
// this would not change the complexity.
//
if ($entry['memorySize'] != 0) {
d_echo($index.' '.$entry['memorySize'].' -> '.$entry['memoryIdle'].' ('.$entry['cpuDescription'].")\n");
$descr = $entry['cpuDescription'];
if (empty($descr)) {
$descr = "Chassis CPU";
}
$descr .= " Memory";
$usage = $entry['memoryIdle'];
discover_mempool($valid_mempool, $device, $index, 'fs-gbn', $descr, '1', null, null);
} //end if
} //end foreach
} //end if
unset($mempools_array);
22 changes: 22 additions & 0 deletions includes/discovery/mempools/fs-switch.inc.php
@@ -0,0 +1,22 @@
<?php
//
// Discovery for FS-switch devices.
//

if ($device['os'] == 'fs-switch') {
echo 'FS : ';
$mempools_array = snmpwalk_cache_oid($device, 'memTotalReal', [], 'SWITCH', 'fs');
$mempools_array = snmpwalk_cache_oid($device, 'memTotalFree', $mempools_array, 'SWITCH', 'fs');
$mempools_array = snmpwalk_cache_oid($device, 'memTotalUsed', $mempools_array, 'SWITCH', 'fs');
d_echo($mempools_array);
foreach ($mempools_array as $index => $entry) {
if ($entry['memTotalReal'] > 0) {
d_echo($index.' '.$entry['memTotalReal'].' -> '.$entry['memTotalFree']."\n");
$descr = "Chassis";
$descr .= " Memory";
$usage = $entry['memTotalFree'];
discover_mempool($valid_mempool, $device, $index, 'fs-switch', $descr, '1', null, null);
} //end if
} //end foreach
} //end if
unset($mempools_array);
38 changes: 38 additions & 0 deletions includes/polling/mempools/fs-gbn.inc.php
@@ -0,0 +1,38 @@
<?php

//
// Polling for "fs-gbn" mempool_type, which belongs to Fiberstore devices, using
// GBNPlatformOAM-MIB mib
//
//

$oid = $mempool['mempool_index'];

d_echo('FS Mempool');

if (!is_array($mempool_cache['fs'])) {
d_echo('caching'); //only occurs the first time if multiple mempools are polled
$mempool_cache['fs'] = array();
$mempool_cache['fs'] = snmpwalk_cache_oid($device, 'memorySize', $mempool_cache['fs'], 'GBNPlatformOAM-MIB', 'fs');
$mempool_cache['fs'] = snmpwalk_cache_oid($device, 'memoryIdle', $mempool_cache['fs'], 'GBNPlatformOAM-MIB', 'fs');
d_echo($mempool_cache);
}

$entry = $mempool_cache['fs'][$oid];
//
// The mib states that it should be in bytes already, but in real life, it is not so true
// We suppose that any value below 32768 is clearly not bytes and we understand it as MBytes
//
if ($entry['memorySize'] < (32 * 1024)) {
$entry['memorySize'] = ($entry['memorySize'] * 1024 * 1024);
$entry['memoryIdle'] = ($entry['memoryIdle'] * 1024 * 1024);
}
//
// little math for usage in percents, and absolute values.
//
if ($entry['memorySize'] > 0) {
$perc = ($entry['memorySize'] - $entry['memoryIdle']) / $entry['memorySize'] * 100;
$mempool['total'] = $entry['memorySize'];
$mempool['used'] = ($entry['memorySize'] - $entry['memoryIdle']);
$mempool['free'] = ($entry['memoryIdle']);
}
27 changes: 27 additions & 0 deletions includes/polling/mempools/fs-switch.inc.php
@@ -0,0 +1,27 @@
<?php
//
// Polling for "fs-switch" mempool_type, which belongs to Fiberstore devices, using
// SWITCH mib
//
$oid = $mempool['mempool_index'];

d_echo('FS Mempool (SWITCHMIB)');

if (!is_array($mempool_cache['fs-switchmib'])) {
d_echo('caching');
$mempool_cache['fs-switchmib'] = snmpwalk_cache_oid($device, 'memTotalReal', [], 'SWITCH', 'fs');
$mempool_cache['fs-switchmib'] = snmpwalk_cache_oid($device, 'memTotalFree', $mempool_cache['fs-switchmib'], 'SWITCH', 'fs');
$mempool_cache['fs-switchmib'] = snmpwalk_cache_oid($device, 'memTotalUsed', $mempool_cache['fs-switchmib'], 'SWITCH', 'fs');
d_echo($mempool_cache);
}

$entry = $mempool_cache['fs-switchmib'][$oid];
//
// Let's do some simple calculation
//
if ($entry['memTotalReal'] > 0) {
$perc = ($entry['memTotalUsed']) / $entry['memTotalReal'] * 100;
$mempool['total'] = ($entry['memTotalReal'] * 1024);
$mempool['used'] = ($entry['memTotalUsed'] * 1024);
$mempool['free'] = ($entry['memTotalFree'] * 1024);
}
42 changes: 42 additions & 0 deletions includes/polling/os/fs-gbn.inc.php
@@ -0,0 +1,42 @@
<?php

if (!empty($matches[2])) {
$version .= " (" . trim($matches[2]) . ")";
}

// List of OIDs for HW recognition, add any potential HW OID here.
$hwOidList = [
'.1.3.6.1.4.1.13464.1.2.1.1.2.15.0', //GBNPlatformOAM-MIB::productName.0
];
foreach ($hwOidList as $oid) {
$hardware_tmp = snmp_get($device, $oid, '-OQv');
if (!empty($hardware_tmp)) {
$hardware = $hardware_tmp;
}
}

// List of OIDs for version, add any potential OID here.
// As the mib is really buggy, let's use numeric OID for now
$verOidList = [
'.1.3.6.1.4.1.13464.1.2.1.1.2.2.0', //GBNPlatformOAM-MIB::softwareVersion.0
];
foreach ($verOidList as $oid) {
$version_tmp = snmp_get($device, $oid, '-OQv');
if (!empty($version_tmp)) {
$version = $version_tmp;
break;
}
}

//List of OIDs for SN, add any potential device SN OID here
$snOidList = [
'.1.3.6.1.4.1.13464.1.2.1.1.2.19.0',
];
foreach ($snOidList as $oid) {
$serial_tmp = snmp_get($device, $oid, '-OQv');

if (!empty($serial_tmp)) {
$serial = $serial_tmp;
break;
}
}
42 changes: 42 additions & 0 deletions includes/polling/os/fs-switch.inc.php
@@ -0,0 +1,42 @@
<?php

if (!empty($matches[2])) {
$version .= " (" . trim($matches[2]) . ")";
}

// List of OIDs for HW recognition, add any potential HW OID here.
$hwOidList = [
'.1.3.6.1.4.1.27975.37.1.5.1.4.1.1',
];
foreach ($hwOidList as $oid) {
$hardware_tmp = snmp_get($device, $oid, '-OQv');
if (!empty($hardware_tmp)) {
$hardware = $hardware_tmp;
}
}

// List of OIDs for version, add any potential OID here.
// As the mib is really buggy, let's use numeric OID for now
$verOidList = [
'.1.3.6.1.4.1.27975.1.3.5.0', //SWITCH::version.0
];
foreach ($verOidList as $oid) {
$version_tmp = snmp_get($device, $oid, '-OQv');
if (!empty($version_tmp)) {
$version = $version_tmp;
break;
}
}

//List of OIDs for SN, add any potential device SN OID here
$snOidList = [
'.1.3.6.1.4.1.27975.37.1.5.1.10.1.1',
];
foreach ($snOidList as $oid) {
$serial_tmp = snmp_get($device, $oid, '-OQv');

if (!empty($serial_tmp)) {
$serial = $serial_tmp;
break;
}
}

0 comments on commit 7e18a07

Please sign in to comment.