Skip to content

Commit

Permalink
New OS: Ekinops (librenms#12088)
Browse files Browse the repository at this point in the history
* Initial push

* renamed mib files

* adding eki mgmt event trap handler

* Adding handler to config/snmptraps.php

* added slot state monitoring

* Ekinops port discovery script

* cleanup

* moved ifDescr change from discovery to poller

* simplified port poller script

* fixed poller array

* add Mgnt2TrapNMSEvent handler

* Adding nms alarm handler

* adding handler to snmptrap.php

* Updated handler names, exapanded event traphandler

* beginning tests and cleanup

* adding snmpsim data

* making tests

* finished trap tests

* fixed ekinops.yaml

* style and lint pass

* new snmpsim data and fixes

* adding correct snmpsim

* fixed test data

* Update ekinops.svg

* Update ekinops.svg

* Update ekinops.yaml

* new os discovery method

* remove unneeded precache line

* removing unneccesary pre-cache script

* styleci fixes

* few more style fixes

* trim whitespace in discovery

* remove unused mibs

Co-authored-by: Tony Murray <[email protected]>
  • Loading branch information
h-barnhart and murrant authored Sep 23, 2020
1 parent 0e0e80c commit 8a92156
Show file tree
Hide file tree
Showing 18 changed files with 19,288 additions and 0 deletions.
65 changes: 65 additions & 0 deletions LibreNMS/OS/Ekinops.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php
/**
* Ekinops.php
*
* Ekinops Optical Network
*
* 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/>.
*
* @link http://librenms.org
* @copyright KanREN, Inc 2020
* @author Heath Barnhart <[email protected]>
*/

namespace LibreNMS\OS;

use App\Models\Device;
use LibreNMS\Interfaces\Discovery\OSDiscovery;
use LibreNMS\OS;

class Ekinops extends OS implements OSDiscovery
{
public function discoverOS(Device $device): void
{
$sysDescr = $device->sysDescr;
$info = explode(',', $sysDescr);

$device->hardware = trim($info[1]);
$device->version = trim($info[2]);

$mgmtCard = snmp_get($this->getDeviceArray(), 'mgnt2RinvHwPlatform.0', '-OQv', 'EKINOPS-MGNT2-MIB');
$mgmtInfo = self::ekinopsInfo($mgmtCard);
$device->serial = $mgmtInfo['Serial Number'];
}

/**
* Parses Ekinops inventory returned in a tabular format within a single OID
* @param string $ekiInfo
* @return array $inv
*/
public static function ekinopsInfo($ekiInfo)
{
$info = explode("\n", $ekiInfo);
unset($info[0]);
$inv = [];
foreach ($info as $line) {
[$attr, $value] = explode(':', $line);
$attr = trim($attr);
$value = trim($value);
$inv[$attr] = $value;
}

return $inv;
}
}
98 changes: 98 additions & 0 deletions LibreNMS/Snmptrap/Handlers/Mgnt2TrapNmsAlarm.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<?php
/**
* Mgnt2TrapNMSEvent.php
*
* -Description-
*
* Ekinops managment module alarms
*
* 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/>.
*
* @link http://librenms.org
* @copyright 2020 KanREN, Inc.
* @author Heath Barnhart <[email protected]>
*/

namespace LibreNMS\Snmptrap\Handlers;

use App\Models\Device;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
use Log;

class Mgnt2TrapNmsAlarm implements SnmptrapHandler
{
/**
* Handle snmptrap.
* Data is pre-parsed and delivered as a Trap.
*
* @param Device $device
* @param Trap $trap
* @return void
*/
public function handle(Device $device, Trap $trap)
{
$alarmObj = $trap->getOidData($trap->findOid('EKINOPS-MGNT2-NMS-MIB::mgnt2AlmLogObjectClassIdentifier'));
$sourcePm = $trap->getOidData($trap->findOid('EKINOPS-MGNT2-NMS-MIB::mgnt2AlmLogSourcePm'));
$slot = $trap->getOidData($trap->findOid('EKINOPS-MGNT2-NMS-MIB::mgnt2AlmLogBoardNumber'));
$portType = $trap->getOidData($trap->findOid('EKINOPS-MGNT2-NMS-MIB::mgnt2AlmLogSourcePortType'));
$portNum = $trap->getOidData($trap->findOid('EKINOPS-MGNT2-NMS-MIB::mgnt2AlmLogSourcePortNumber'));
$probCause = $trap->getOidData($trap->findOid('EKINOPS-MGNT2-NMS-MIB::mgnt2AlmLogProbableCause'));
$probSpecific = $trap->getOidData($trap->findOid('EKINOPS-MGNT2-NMS-MIB::mgnt2AlmLogSpecificProblem'));
$probAdd = $trap->getOidData($trap->findOid('EKINOPS-MGNT2-NMS-MIB::mgnt2AlmLogAdditionalText'));
$alarmSeverity = $trap->getOidData($trap->findOid('EKINOPS-MGNT2-NMS-MIB::mgnt2AlmLogSeverity'));

// Adding additional info if it exists.
if (! empty($probAdd)) {
$probSpecific = "$probSpecific Additional info: $probAdd";
}

// Changing other to unknown
if ($probCause == 'other') {
$probCause = 'Unknown';
}

if ($alarmObj == 'port') {
$msg = "Alarm on slot $slot, $sourcePm Port: $portType $portNum Issue: $probSpecific Possible Cause: $probCause";
} else {
$msg = "Alarm on slot $slot, $sourcePm Issue: $probSpecific Possible Cause: $probCause";
}

switch ($alarmSeverity) {
case 'cleared':
$severity = 1;
break;
case 'critical':
$severity = 5;
break;
case 'major':
$severity = 5;
break;
case 'minor':
$severity = 4;
break;
case 'warning':
$severity = 4;
break;
case 'indeterminate':
$severity = 0;
break;
default:
$severity = 2;
break;
}

Log::event($msg, $device->device_id, 'trap', $severity);
}
}
66 changes: 66 additions & 0 deletions LibreNMS/Snmptrap/Handlers/Mgnt2TrapNmsEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php
/**
* Mgnt2TrapNMSEvent.php
*
* -Description-
*
* Ekinops managment module events
*
* 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/>.
*
* @link http://librenms.org
* @copyright 2020 KanREN, Inc.
* @author Heath Barnhart <[email protected]>
*/

namespace LibreNMS\Snmptrap\Handlers;

use App\Models\Device;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
use Log;

class Mgnt2TrapNmsEvent implements SnmptrapHandler
{
/**
* Handle snmptrap.
* Data is pre-parsed and delivered as a Trap.
*
* @param Device $device
* @param Trap $trap
* @return void
*/
public function handle(Device $device, Trap $trap)
{
$eventObj = $trap->getOidData($trap->findOid('EKINOPS-MGNT2-NMS-MIB::mgnt2EventLogObjectClassIdentifier'));
$sourcePm = $trap->getOidData($trap->findOid('EKINOPS-MGNT2-NMS-MIB::mgnt2EventLogSourcePm'));
$slot = $trap->getOidData($trap->findOid('EKINOPS-MGNT2-NMS-MIB::mgnt2EventLogBoardNumber'));
$portType = $trap->getOidData($trap->findOid('EKINOPS-MGNT2-NMS-MIB::mgnt2EventLogSourcePortType'));
$portNum = $trap->getOidData($trap->findOid('EKINOPS-MGNT2-NMS-MIB::mgnt2EventLogSourcePortNumber'));
$logReason = $trap->getOidData($trap->findOid('EKINOPS-MGNT2-NMS-MIB::mgnt2EventLogReason'));
$logAdd = $trap->getOidData($trap->findOid('EKINOPS-MGNT2-NMS-MIB::mgnt2EventLogAdditionalText'));

// Adding additional info if it exists.
if (! empty($logAdd)) {
$logReason = "$logReason Additional info: $logAdd";
}

if ($eventObj == 'port') {
$msg = "Event on slot $slot, $sourcePm Port: $portType $portNum. Reason: $logReason";
} else {
$msg = "Event on slot $slot, $sourcePm Reason: $logReason";
}
Log::event($msg, $device->device_id, 'trap', 2);
}
}
2 changes: 2 additions & 0 deletions config/snmptraps.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
'CPS-MIB::upsStartBatteryTest' => \LibreNMS\Snmptrap\Handlers\CpUpsStartBatteryTest::class,
'CPS-MIB::upsTurnedOff' => \LibreNMS\Snmptrap\Handlers\CpUpsTurnedOff::class,
'CPS-MIB::upsWokeUp' => \LibreNMS\Snmptrap\Handlers\CpUpsWokeUp::class,
'EKINOPS-MGNT2-NMS-MIB::mgnt2TrapNMSEvent' => \LibreNMS\Snmptrap\Handlers\Mgnt2TrapNmsEvent::class,
'EKINOPS-MGNT2-NMS-MIB::mgnt2TrapNMSAlarm' => \LibreNMS\Snmptrap\Handlers\Mgnt2TrapNmsAlarm::class,
'ENTITY-MIB::entConfigChange' => \LibreNMS\Snmptrap\Handlers\EntityDatabaseConfigChanged::class,
'EQUIPMENT-MIB::equipStatusTrap' => \LibreNMS\Snmptrap\Handlers\EquipStatusTrap::class,
'FORTINET-CORE-MIB::fnTrapMemThreshold' => \LibreNMS\Snmptrap\Handlers\FnTrapMemThreshold::class,
Expand Down
1 change: 1 addition & 0 deletions html/images/logos/ekinops.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions html/images/os/ekinops.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 8a92156

Please sign in to comment.