Adva SNMP Trap Handlers (#10094)

* Added SNMP Trap Handlers for Adva Ethernet devices

* Fixed formatting.

* Fixed errors from previous commit.

* Refactored AdvaAttributeChange.php

* Updated a few handlers, added test script.

* Added changes to snmptraps.php to make handlers active

* Fixed issues found by travisci

* Missed two mistakes in travisci, fixed. Should be ready for human eyes.

* Added SNMP Trap Handlers for Adva Ethernet devices

* Fixed formatting.

* Fixed errors from previous commit.

* Refactored AdvaAttributeChange.php

* Updated a few handlers, added test script.

* Added changes to snmptraps.php to make handlers active

* Fixed issues found by travisci

* Missed two mistakes in travisci, fixed. Should be ready for human eyes.

* Added two tests.

* fixed error

* Updated handlers with changes introduced in 1.50

* Refactored and added a few tests

* Added test for StateChangeTraps

* Added AdvaObjectDeletionTest, still wip as I need to recapture flow del.

* Added Network Element Alarm Trap Test

* Added more tests, but they are wip.

* Finished traps handler tests, few handler refoactors.

* fixed style errors and refactored as requested

* made requested changes to threshold trap handlers

* removed a test script

* modified adva port threshold handler

* Update AdvaAccThresholdCrossingAlert.php

* Update AdvaNetThresholdCrossingAlert.php

* removed static method

* fixed mistake in AdvaNetThresholdCrossingAlert.php
This commit is contained in:
h-barnhart
2019-04-29 08:39:20 -05:00
committed by Tony Murray
parent a7ef43359f
commit 5115fa9ca0
19 changed files with 2513 additions and 7 deletions

View File

@@ -0,0 +1,128 @@
<?php
/**
* AdvaAccThresholdCrossingAlert.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/>.
*
* Adva Threshold Exceeded Alarms.
*
* @package LibreNMS
* @link http://librenms.org
* @copyright 2018 KanREN, Inc
* @author Heath Barnhart <hbarnhart@kanren.net> & Neil Kahle <nkahle@kanren.net>
*/
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
use Log;
class AdvaAccThresholdCrossingAlert 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)
{
$interval = $trap->getOidData($trap->findOid("CM-PERFORMANCE-MIB::cmEthernetAccPortThresholdInterval"));
$ifName = $trap->getOidData($trap->findOid("IF-MIB::ifName"));
$thresholdMessage = $this->getThresholdMessage(
$trap->getOidData($trap->findOid("CM-PERFORMANCE-MIB::cmEthernetAccPortThresholdVariable"))
);
Log::event("$ifName $thresholdMessage threshold exceeded for $interval", $device->device_id, 'trap', 2);
}
public function getThresholdMessage($thresholdOid)
{
foreach ($this->getThresholds() as $oid => $descr) {
if (str_contains($thresholdOid, $oid)) {
return $descr;
}
}
return 'unknown';
}
public function getThresholds()
{
return [
'CM-PERFORMANCE-MIB::cmEthernetAccPortStatsUAS' => 'unavailable seconds',
'CM-PERFORMANCE-MIB::cmEthernetAccPortStatsESBF' => 'broadcast frames sent',
'CM-PERFORMANCE-MIB::cmEthernetAccPortStatsESBP' => 'broadcast frames received',
'CM-PERFORMANCE-MIB::cmEthernetAccPortStatsESBS' => 'bytes sent',
'CM-PERFORMANCE-MIB::cmEthernetAccPortStatsESCAE' => 'crc align errors',
'CM-PERFORMANCE-MIB::cmEthernetAccPortStatsESC' => 'collisions',
'CM-PERFORMANCE-MIB::cmEthernetAccPortStatsESDE' => 'drop events',
'CM-PERFORMANCE-MIB::cmEthernetAccPortStatsESFS' => 'frames sent',
'CM-PERFORMANCE-MIB::cmEthernetAccPortStatsESF' => 'fragments',
'CM-PERFORMANCE-MIB::cmEthernetAccPortStatsESJ' => 'jabbers',
'CM-PERFORMANCE-MIB::cmEthernetAccPortStatsESMF' => 'multicast frames sent',
'CM-PERFORMANCE-MIB::cmEthernetAccPortStatsESMP' => 'multicast pakcets received',
'CM-PERFORMANCE-MIB::cmEthernetAccPortStatsESOF' => 'oversize frames discarded',
'CM-PERFORMANCE-MIB::cmEthernetAccPortStatsESOP' => 'oversize packets received',
'CM-PERFORMANCE-MIB::cmEthernetAccPortStatsESO' => 'octets received',
'CM-PERFORMANCE-MIB::cmEthernetAccPortStatsESP64' => '64 byte octets received',
'CM-PERFORMANCE-MIB::cmEthernetAccPortStatsESP65' => '65 to 127 byte octets received',
'CM-PERFORMANCE-MIB::cmEthernetAccPortStatsESP128' => '128 to 255 byte octets received',
'CM-PERFORMANCE-MIB::cmEthernetAccPortStatsESP256' => '256 to 511 byte octets received',
'CM-PERFORMANCE-MIB::cmEthernetAccPortStatsESP512' => '512 to 1023 byte octets received',
'CM-PERFORMANCE-MIB::cmEthernetAccPortStatsESP1024' => '1024 to 1518 byte octets received',
'CM-PERFORMANCE-MIB::cmEthernetAccPortStatsESP1519' => '1519 to MTU byte octets received',
'CM-PERFORMANCE-MIB::cmEthernetAccPortStatsESP' => 'packets received',
'CM-PERFORMANCE-MIB::cmEthernetAccPortStatsESUF' => 'unicast frames sent',
'CM-PERFORMANCE-MIB::cmEthernetAccPortStatsESUP' => 'unicast frames received',
'CM-PERFORMANCE-MIB::cmEthernetAccPortStatsL2CPFD' => 'layer 2 control protocol frames discarded',
'CM-PERFORMANCE-MIB::cmEthernetAccPortStatsL2CPFP' => 'layer 2 control protocol frames discarded',
'CM-PERFORMANCE-MIB::cmEthernetAccPortStatsABRRx' => 'average bit rate received',
'CM-PERFORMANCE-MIB::cmEthernetAccPortStatsABRTx' => 'average bit rate transmitted',
'CM-PERFORMANCE-MIB::cmEthernetAccPortStatsL2PTRxFramesEncap' => 'layer 2 control protocol frames encapsulated',
'CM-PERFORMANCE-MIB::cmEthernetAccPortStatsL2PTTxFramesDecap' => 'layer 2 control protocol frames decapsulated',
'CM-PERFORMANCE-MIB::cmEthernetAccPortStatsIBRMaxRx' => 'instantaneous bit rate received max',
'CM-PERFORMANCE-MIB::cmEthernetAccPortStatsIBRMaxTx' => 'instantaneous bit rate transmitted max',
'CM-PERFORMANCE-MIB::cmEthernetAccPortStatsIBRMinRx' => 'instantaneous bit rate received min',
'CM-PERFORMANCE-MIB::cmEthernetAccPortStatsIBRMinTx' => 'instantaneous bit rate transmitted min',
'CM-PERFORMANCE-MIB::cmEthernetAccPortStatsIBRRx' => 'instantaneous bit rate received',
'CM-PERFORMANCE-MIB::cmEthernetAccPortStatsIBRTx' => 'instantaneous bit rate transmitted',
'CM-PERFORMANCE-MIB::cmEthernetAccPortStatsAclDropNoMatch' => 'acl drop no match',
'CM-PERFORMANCE-MIB::cmEthernetAccPortStatsAclFwd2Cpu' => 'acl forwarded to cpu',
'CM-PERFORMANCE-MIB::cmEthernetAccPortStatsDhcpDropNoAssocIf' => 'dhcp dropped due to no associated interface',
'cmQosFlowPolicerStatsFMG' => 'frames marked green and passed',
'cmQosFlowPolicerStatsFMY' => 'frames marked yellow and passed',
'cmQosFlowPolicerStatsFMYD' => 'frames marked yellow and discarded',
'cmQosFlowPolicerStatsFMRD' => 'frames marked red and discarded',
'cmQosFlowPolicerStatsBytesIn' => 'total bytes in',
'cmQosFlowPolicerStatsBytesOut' => 'total bytes out',
'cmQosFlowPolicerStatsABR' => 'average bit rate',
'cmAccPortQosShaperStatsBT' => 'bytes dequeued',
'cmAccPortQosShaperStatsBTD' => 'bytes tail dropped',
'cmAccPortQosShaperStatsFD' => 'frames dequeued',
'cmAccPortQosShaperStatsFTD' => 'frames tail dropped',
'cmAccPortQosShaperStatsBR' => 'bytes replicated',
'cmAccPortQosShaperStatsFR' => 'frames replicated',
'cmAccPortQosShaperStatsABRRL' => 'average bit rate - rate limited',
'cmAccPortQosShaperStatsBREDD' => 'bytes random early discard, dropped',
'cmAccPortQosShaperStatsFREDD' => 'frames random early discard, dropped',
];
}
}

View File

@@ -0,0 +1,297 @@
<?php
/**
* AdvaAtributeChange.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/>.
*
* Attribute change traps show changes to Adva configuration values after they are submitted.
* This handler only catches some of those changes and aims to provide the user with
* information about what configuration module was modified.
*
* @package LibreNMS
* @link http://librenms.org
* @copyright 2018 KanREN, Inc
* @author Heath Barnhart <hbarnhart@kanren.net>
*/
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
use Log;
class AdvaAttributeChange 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)
{
if ($trap->findOid('CM-SYSTEM-MIB::sysLog')) {
$this->handleSyslogChg($device, $trap);
} elseif ($trap->findOid('CM-SYSTEM-MIB::aclEntry')) {
$this->handleAclChg($device, $trap);
} elseif ($trap->findOid('CM-SYSTEM-MIB::securityBanner')) {
Log::event("MOTD/Banner modified", $device->device_id, 'trap', 2);
} elseif ($trap->findOid('CM-SYSTEM-MIB::sysTimeOfDayType')) {
$this->handleTimeSrcChg($device, $trap);
} elseif ($trap->findOid('F3-TIMEZONE-MIB::f3TimeZone')) {
$this->handleTimeZoneChg($device, $trap);
} elseif ($trap->findOid('CM-SYSTEM-MIB::ntp')) {
$this->handleNtpChg($device, $trap);
} elseif ($trap->findOid('CM-SECURITY-MIB::cmRemoteAuthServer')) {
$this->handleAuthSvrChg($device, $trap);
} elseif ($trap->findOid('CM-ENTITY-MIB::ne')) {
$this->handleNeChg($device, $trap);
} elseif ($trap->findOid('CM-ENTITY-MIB::ethernetNTEGE114ProCardSnmpDyingGaspEnabled')) {
$this->handleDyingGaspChg($device, $trap);
} elseif ($trap->findOid('CM-FACILITY-MIB::cmEthernetNetPort')) {
$this->handleNetPortChg($device, $trap);
} elseif ($trap->findOid('CM-FACILITY-MIB::cmEthernetAccPort')) {
$this->handleAccPortChg($device, $trap);
} elseif ($trap->findOid('CM-FACILITY-MIB::cmFlow')) {
$this->handleFlowChg($device, $trap);
} elseif ($trap->findOid('F3-LAG-MIB')) {
$this->handleLagChg($device, $trap);
} elseif ($trap->findOid('CM-FACILITY-MIB::cmQosFlow')) {
$this->handleQosFlowChg($device, $trap);
} elseif ($trap->findOid('CM-FACILITY-MIB::cmQosShaper')) {
$this->handleQosShaperChg($device, $trap);
} elseif ($trap->findOid('CM-FACILITY-MIB::cmAccPort')) {
$this->handleAccPortShaperChg($device, $trap);
}
}
public static function handleSyslogChg($device, $trap)
{
$syslogEntry = substr($trap->findOid('CM-SYSTEM-MIB::sysLog'), -1);
if ($trap->findOid('CM-SYSTEM-MIB::sysLogIpVersion')) {
$ipVer = $trap->getOidData($trap->findOid('CM-SYSTEM-MIB::sysLogIpVersion'));
Log::event("Syslog server $syslogEntry IP version set to $ipVer", $device->device_id, 'trap', 2);
}
if ($trap->findOid('CM-SYSTEM-MIB::sysLogIpAddress')) {
$ipAddr = $trap->getOidData($trap->findOid('CM-SYSTEM-MIB::sysLogIpAddress'));
Log::event("Syslog server $syslogEntry IP address changed to $ipAddr", $device->device_id, 'trap', 2);
}
if ($trap->findOid('CM-SYSTEM-MIB::sysLogIpv6Addr')) {
$ip6Addr = $trap->getOidData($trap->findOid('CM-SYSTEM-MIB::sysLogIpv6Addr'));
Log::event("Syslog server $syslogEntry IP address changed to $ip6Addr", $device->device_id, 'trap', 2);
}
if ($trap->findOid('CM-SYSTEM-MIB::sysLogPort')) {
$syslogPort = $trap->getOidData($trap->findOid('CM-SYSTEM-MIB::sysLogPort'));
Log::event("Syslog server $syslogEntry port changed to $syslogPort", $device->device_id, 'trap', 2);
}
}
public static function handleAclChg($device, $trap)
{
$aclEntry = substr($trap->findOid('CM-SYSTEM-MIB::aclEntry'), -1);
Log::event("ACL $aclEntry modified", $device->device_id, 'trap', 2);
}
public static function handleTimeSrcChg($device, $trap)
{
$timeSrc = $trap->getOidData($trap->findOid('CM-SYSTEM-MIB::sysTimeOfDayType'));
Log::event("Time source set to $timeSrc", $device->device_id, 'trap', 2);
}
public static function handleTimeZoneChg($device, $trap)
{
$enabled = $trap->getOidData($trap->findOid('F3-TIMEZONE-MIB::f3TimeZoneDstControlEnabled'));
if ('true' === $enabled && $trap->findOid('F3-TIMEZONE-MIB::f3TimeZoneDstControlEnabled')) {
Log::event('Daylight Savings Time enabled', $device->device_id, 'trap', 2);
} elseif ('false' === $enabled && $trap->findOid('F3-TIMEZONE-MIB::f3TimeZoneDstControlEnabled')) {
Log::event('Daylight Savings Time disabled', $device->device_id, 'trap', 2);
}
if ($trap->findOid("F3-TIMEZONE-MIB::f3TimeZoneUtcOffset")) {
$dstOffset = $trap->getOidData($trap->findOid('F3-TIMEZONE-MIB::f3TimeZoneUtcOffset'));
Log::event("UTC offset (timezone) change to $dstOffset", $device->device_id, 'trap', 2);
}
}
public static function handleNtpChg($device, $trap)
{
if ($trap->findOid('CM-SYSTEM-MIB::ntpPrimaryServer')) {
$primaryIP = $trap->getOidData($trap->findOid('CM-SYSTEM-MIB::ntpPrimaryServer'));
Log::event("Primary NTP server IP changed to $primaryIP", $device->device_id, 'trap', 2);
}
if ($trap->findOid('CM-SYSTEM-MIB::ntpBackupServer')) {
$backupIP = $trap->getOidData($trap->findOid('CM-SYSTEM-MIB::ntpBackupServer'));
Log::event("Backup NTP server IP changed to $backupIP", $device->device_id, 'trap', 2);
}
}
public static function handleAuthSvrChg($device, $trap)
{
if ($trap->findOid('CM-SECURITY-MIB::cmRemoteAuthServerIpAddress')) {
$serverEntry = substr($trap->findOid('CM-SECURITY-MIB::cmRemoteAuthServerIpAddress'), -1);
$serverIP = $trap->getOidData($trap->findOid('CM-SECURITY-MIB::cmRemoteAuthServerIpAddress'));
Log::event("Authentication server $serverEntry IP changed to $serverIP", $device->device_id, 'trap', 2);
}
if ($trap->findOid('CM-SECURITY-MIB::cmRemoteAuthServerSecret')) {
$serverEntry = substr($trap->findOid('CM-SECURITY-MIB::cmRemoteAuthServerSecret'), -1);
Log::event("Authentication server $serverEntry secret changed", $device->device_id, 'trap', 2);
}
if ($trap->findOid('CM-SECURITY-MIB::cmRemoteAuthServerEnabled')) {
$serverEntry = substr($trap->findOid('CM-SECURITY-MIB::cmRemoteAuthServerEnabled'), -1);
$serverEnable = $trap->getOidData($trap->findOid('CM-SECURITY-MIB::cmRemoteAuthServerEnabled'));
if ('true' === $serverEnable) {
Log::event("Authentication server $serverEntry enabled", $device->device_id, 'trap', 2);
} else {
Log::event("Authentication server $serverEntry disabled", $device->device_id, 'trap', 2);
}
}
}
public static function handleNeChg($device, $trap)
{
if ($trap->findOid('CM-ENTITY-MIB::neName')) {
$neName = $trap->getOidData($trap->findOid("CM-ENTITY-MIB::neName"));
Log::event("Network Element name changed to $neName", $device->device_id, 'trap', 2);
}
if ($trap->findOid('CM-ENTITY-MIB::neCmdPromptPrefix')) {
$neCLI = $trap->getOidData($trap->findOid('CM-ENTITY-MIB::neCmdPromptPrefix'));
Log::event("Network Element prompt changed to $neCLI", $device->device_id, 'trap', 2);
}
}
public static function handleDyingGaspChg($device, $trap)
{
$nteSDGEnable = $trap->getOidData($trap->findOid('CM-ENTITY-MIB::ethernetNTEGE114ProCardSnmpDyingGaspEnabled'));
if ('true' === $nteSDGEnable && $trap->findOid('CM-ENTITY-MIB::ethernetNTEGE114ProCardSnmpDyingGaspEnabled')) {
Log::event("SNMP Dying Gasp is enabled", $device->device_id, 'trap', 2);
} elseif ('false' === $nteSDGEnable && $trap->findOid('CM-ENTITY-MIB::ethernetNTEGE114ProCardSnmpDyingGaspEnabled')) {
Log::event("SNMP Dying Gasp is disabled", $device->device_id, 'trap', 2);
}
}
public static function handleNetPortChg($device, $trap)
{
$netPort = substr($trap->findOid('CM-FACILITY-MIB::cmEthernetNetPort'), -7);
$netPort = str_replace(".", "-", $netPort);
$neDefMessage = false;
if ($trap->findOid('CM-FACILITY-MIB::cmEthernetNetPortConfigSpeed')) {
$netSpeed = $trap->getOidData($trap->findOid('CM-FACILITY-MIB::cmEthernetNetPortConfigSpeed'));
Log::event("Network Port $netPort changed speed to $netSpeed", $device->device_id, 'trap', 2);
$neDefMessage = true;
}
if ($trap->findOid('CM-FACILITY-MIB::cmEthernetNetPortMediaType')) {
$netMedia = $trap->getOidData($trap->findOid('CM-FACILITY-MIB::cmEthernetNetPortMediaType'));
Log::event("Network Port $netPort changed media to $netMedia", $device->device_id, 'trap', 2);
$neDefMessage = true;
}
if ($trap->findOid('CM-FACILITY-MIB::cmEthernetNetPortMDIXType')) {
$netMDIX = $trap->getOidData($trap->findOid('CM-FACILITY-MIB::cmEthernetNetPortMDIXType'));
Log::event("Network Port $netPort changed MDIX to $netMDIX", $device->device_id, 'trap', 2);
$neDefMessage = true;
}
if ($trap->findOid('CM-FACILITY-MIB::cmEthernetNetPortAutoDiagEnabled')) {
$netAutoDiag = $trap->getOidData($trap->findOid('CM-FACILITY-MIB::cmEthernetNetPortAutoDiagEnabled'));
if ('true' === $netAutoDiag) {
$message = "Network Port $netPort AutoDiagnostic enabled";
} else {
$message = "Network Port $netPort AutoDiagnostic disabled";
}
Log::event($message, $device->device_id, 'trap', 2);
$neDefMessage = true;
}
if ($trap->findOid('CM-FACILITY-MIB::cmEthernetNetPortAdminState')) {
$netAdminState = $trap->getOidData($trap->findOid('CM-FACILITY-MIB::cmEthernetNetPortAdminState'));
Log::event("Network Port $netPort administrative state changed to $netAdminState", $device->device_id, 'trap', 2);
$neDefMessage = true;
}
if ($trap->findOid('CM-FACILITY-MIB::cmEthernetNetPortMTU')) {
$netMTU = $trap->getOidData($trap->findOid('CM-FACILITY-MIB::cmEthernetNetPortMTU'));
Log::event("Network Port $netPort MTU changed to $netMTU bytes", $device->device_id, 'trap', 2);
$neDefMessage = true;
}
if ($neDefMessage === false) {
/* Catch all other Access Port changes and give a generic message */
Log::event("Network Port $netPort modified", $device->device_id, 'trap', 2);
}
}
public static function handleAccPortChg($device, $trap)
{
$accPort = substr($trap->findOid('CM-FACILITY-MIB::cmEthernetAccPort'), -7);
$accPort = str_replace(".", "-", $accPort);
$accDefMessage = false;
if ($trap->findOid('CM-FACILITY-MIB::cmEthernetAccPortConfigSpeed')) {
$accSpeed = $trap->getOidData($trap->findOid('CM-FACILITY-MIB::cmEthernetAccPortConfigSpeed'));
Log::event("Access Port $accPort changed speed to $accSpeed", $device->device_id, 'trap', 2);
$accDefMessage = true;
}
if ($trap->findOid('CM-FACILITY-MIB::cmEthernetAccPortMediaType')) {
$accMedia = $trap->getOidData($trap->findOid('CM-FACILITY-MIB::cmEthernetAccPortMediaType'));
Log::event("Access Port $accPort changed media to $accMedia", $device->device_id, 'trap', 2);
$accDefMessage = true;
}
if ($trap->findOid('CM-FACILITY-MIB::cmEthernetAccPortMDIXType')) {
$accMDIX = $trap->getOidData($trap->findOid('CM-FACILITY-MIB::cmEthernetAccPortMDIXType'));
Log::event("Access Port $accPort changed MDIX to $accMDIX", $device->device_id, 'trap', 2);
$accDefMessage = true;
}
if ($trap->findOid('CM-FACILITY-MIB::cmEthernetAccPortAutoDiagEnabled')) {
$accAutoDiag = $trap->getOidData($trap->findOid('CM-FACILITY-MIB::cmEthernetAccPortAutoDiagEnabled'));
if ('true' === $accAutoDiag) {
$message = "Access Port $accPort AutoDiagnostic enabled";
} else {
$message = "Access Port $accPort AutoDiagnostic disabled";
}
Log::event($message, $device->device_id, 'trap', 2);
$accDefMessage = true;
}
if ($trap->findOid('CM-FACILITY-MIB::cmEthernetAccPortAdminState')) {
$accAdminState = $trap->getOidData($trap->findOid('CM-FACILITY-MIB::cmEthernetAccPortAdminState'));
Log::event("Access Port $accPort administrative state changed to $accAdminState", $device->device_id, 'trap', 2);
$accDefMessage = true;
}
if ($trap->findOid('CM-FACILITY-MIB::cmEthernetAccPortMTU')) {
$accMTU = $trap->getOidData($trap->findOid('CM-FACILITY-MIB::cmEthernetAccPortMTU'));
Log::event("Access Port $accPort MTU changed to $accMTU bytes", $device->device_id, 'trap', 2);
$accDefMessage = true;
}
if ($accDefMessage === false) {
/* Catch all other Access Port changes and give a generic message */
Log::event("Access Port $accPort modified", $device->device_id, 'trap', 2);
}
}
public static function handleFlowChg($device, $trap)
{
$flowID = substr($trap->findOid('CM-FACILITY-MIB::cmFlow'), -9);
$flowID = str_replace(".", "-", $flowID);
Log::event("Access Flow $flowID modified", $device->device_id, 'trap', 2);
}
public static function handleLagChg($device, $trap)
{
$lagID = substr($trap->findOid('F3-LAG-MIB::f3'), -1);
Log::event("LAG $lagID modified", $device->device_id, 'trap', 2);
}
public static function handleQosFlowChg($device, $trap)
{
$flowID = substr($trap->findOid('CM-FACILITY-MIB::cmQosFlow'), -13, 9);
$flowID = str_replace(".", "-", $flowID);
Log::event("QoS on flow $flowID modified", $device->device_id, 'trap', 2);
}
public static function handleQosShaperChg($device, $trap)
{
$flowID = substr($trap->findOid('CM-FACILITY-MIB::cmQosShaper'), -13, 9);
$flowID = str_replace(".", "-", $flowID);
Log::event("QoS on flow $flowID modified", $device->device_id, 'trap', 2);
}
public static function handleAccPortShaperChg($device, $trap)
{
$shaperID = substr($trap->findOid('CM-FACILITY-MIB::cmAccPort'), -9);
$shaperID = str_replace(".", "-", $shaperID);
Log::event("Shaper modified on access port $shaperID modified", $device->device_id, 'trap', 2);
}
}

View File

@@ -0,0 +1,125 @@
<?php
/**
* AdvaNetThresholdCrossingAlert.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/>.
*
* Adva Threshold Exceeded Alarms.
*
* @package LibreNMS
* @link http://librenms.org
* @copyright 2018 KanREN, Inc
* @author Heath Barnhart <hbarnhart@kanren.net> & Neil Kahle <nkahle@kanren.net>
*/
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
use Log;
class AdvaNetThresholdCrossingAlert 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)
{
$interval = $trap->getOidData($trap->findOid("CM-PERFORMANCE-MIB::cmEthernetNetPortThresholdInterval"));
$ifName = $trap->getOidData($trap->findOid("IF-MIB::ifName"));
$threshMessage = $this->getThresholdMessage(
$trap->getOidData($trap->findOid("CM-PERFORMANCE-MIB::cmEthernetNetPortThresholdVariable"))
);
Log::event("$ifName $threshMessage threshold exceeded for $interval", $device->device_id, 'trap', 2);
}
public function getThresholdMessage($thresholdOid)
{
foreach ($this->getThresholds() as $oid => $descr) {
if (str_contains($thresholdOid, $oid)) {
return $descr;
}
}
return 'unknown';
}
public function getThresholds()
{
return [
'CM-PERFORMANCE-MIB::cmEthernetNetPortStatsUAS' => 'unavailable seconds',
'CM-PERFORMANCE-MIB::cmEthernetNetPortStatsESBF' => 'broadcast frames sent',
'CM-PERFORMANCE-MIB::cmEthernetNetPortStatsESBP' => 'broadcast frames received',
'CM-PERFORMANCE-MIB::cmEthernetNetPortStatsESBS' => 'bytes sent',
'CM-PERFORMANCE-MIB::cmEthernetNetPortStatsESCAE' => 'crc align errors',
'CM-PERFORMANCE-MIB::cmEthernetNetPortStatsESC' => 'collisions',
'CM-PERFORMANCE-MIB::cmEthernetNetPortStatsESDE' => 'drop events',
'CM-PERFORMANCE-MIB::cmEthernetNetPortStatsESFS' => 'frames sent',
'CM-PERFORMANCE-MIB::cmEthernetNetPortStatsESF' => 'fragments',
'CM-PERFORMANCE-MIB::cmEthernetNetPortStatsESJ' => 'jabbers',
'CM-PERFORMANCE-MIB::cmEthernetNetPortStatsESMF' => 'multicast frames sent',
'CM-PERFORMANCE-MIB::cmEthernetNetPortStatsESMP' => 'multicast pakcets received',
'CM-PERFORMANCE-MIB::cmEthernetNetPortStatsESOF' => 'oversize frames discarded',
'CM-PERFORMANCE-MIB::cmEthernetNetPortStatsESOP' => 'oversize packets received',
'CM-PERFORMANCE-MIB::cmEthernetNetPortStatsESO' => 'octets received',
'CM-PERFORMANCE-MIB::cmEthernetNetPortStatsESP64' => '64 byte octets received',
'CM-PERFORMANCE-MIB::cmEthernetNetPortStatsESP65' => '65 to 127 byte octets received',
'CM-PERFORMANCE-MIB::cmEthernetNetPortStatsESP128' => '128 to 255 byte octets received',
'CM-PERFORMANCE-MIB::cmEthernetNetPortStatsESP256' => '256 to 511 byte octets received',
'CM-PERFORMANCE-MIB::cmEthernetNetPortStatsESP512' => '512 to 1023 byte octets received',
'CM-PERFORMANCE-MIB::cmEthernetNetPortStatsESP1024' => '1024 to 1518 byte octets received',
'CM-PERFORMANCE-MIB::cmEthernetNetPortStatsESP1519' => '1519 to MTU byte octets received',
'CM-PERFORMANCE-MIB::cmEthernetNetPortStatsESP' => 'packets received',
'CM-PERFORMANCE-MIB::cmEthernetNetPortStatsESUF' => 'unicast frames sent',
'CM-PERFORMANCE-MIB::cmEthernetNetPortStatsESUP' => 'unicast frames received',
'CM-PERFORMANCE-MIB::cmEthernetNetPortStatsL2CPFD' => 'layer 2 control protocol frames discarded',
'CM-PERFORMANCE-MIB::cmEthernetNetPortStatsL2CPFP' => 'layer 2 control protocol frames discarded',
'CM-PERFORMANCE-MIB::cmEthernetNetPortStatsABRRx' => 'average bit rate received',
'CM-PERFORMANCE-MIB::cmEthernetNetPortStatsABRTx' => 'average bit rate transmitted',
'CM-PERFORMANCE-MIB::cmEthernetNetPortStatsL2PTRxFramesEncap' => 'layer 2 control protocol frames encapsulated',
'CM-PERFORMANCE-MIB::cmEthernetNetPortStatsL2PTTxFramesDecap' => 'layer 2 control protocol frames decapsulated',
'CM-PERFORMANCE-MIB::cmEthernetNetPortStatsIBRMaxRx' => 'instantaneous bit rate received max',
'CM-PERFORMANCE-MIB::cmEthernetNetPortStatsIBRMaxTx' => 'instantaneous bit rate transmitted max',
'CM-PERFORMANCE-MIB::cmEthernetNetPortStatsIBRMinRx' => 'instantaneous bit rate received min',
'CM-PERFORMANCE-MIB::cmEthernetNetPortStatsIBRMinTx' => 'instantaneous bit rate transmitted min',
'CM-PERFORMANCE-MIB::cmEthernetNetPortStatsIBRRx' => 'instantaneous bit rate received',
'CM-PERFORMANCE-MIB::cmEthernetNetPortStatsIBRTx' => 'instantaneous bit rate transmitted',
'CM-PERFORMANCE-MIB::cmEthernetNetPortStatsAclDropNoMatch' => 'acl drop no match',
'CM-PERFORMANCE-MIB::cmEthernetNetPortStatsAclFwd2Cpu' => 'acl forwarded to cpu',
'CM-PERFORMANCE-MIB::cmEthernetNetPortStatsDhcpDropNoAssocIf' => 'dhcp dropped due to no associated interface',
'cmQosFlowPolicerStatsFMG' => 'frames marked green and passed',
'cmQosFlowPolicerStatsFMY' => 'frames marked yellow and passed',
'cmQosFlowPolicerStatsFMYD' => 'frames marked yellow and discarded',
'cmQosFlowPolicerStatsFMRD' => 'frames marked red and discarded',
'cmQosFlowPolicerStatsBytesIn' => 'total bytes in',
'cmQosFlowPolicerStatsBytesOut' => 'total bytes out',
'cmQosFlowPolicerStatsABR' => 'average bit rate',
'cmAccPortQosShaperStatsBT' => 'bytes dequeued',
'cmAccPortQosShaperStatsBTD' => 'bytes tail dropped',
'cmAccPortQosShaperStatsFD' => 'frames dequeued',
'cmAccPortQosShaperStatsFTD' => 'frames tail dropped',
'cmAccPortQosShaperStatsBR' => 'bytes replicated',
'cmAccPortQosShaperStatsFR' => 'frames replicated',
'cmAccPortQosShaperStatsABRRL' => 'average bit rate - rate limited',
'cmAccPortQosShaperStatsBREDD' => 'bytes random early discard, dropped',
'cmAccPortQosShaperStatsFREDD' => 'frames random early discard, dropped',
];
}
}

View File

@@ -0,0 +1,71 @@
<?php
/**
* NetworkElementAlmTrap.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/>.
*
* Adva network element is in an alarm state. Gets the alarm description
* and severity assigned by the Adva.
*
* @package LibreNMS
* @link http://librenms.org
* @copyright 2018 KanREN, Inc
* @author Heath Barnhart <hbarnhart@kanren.net> & Neil Kahle <nkahle@kanren.net>
*/
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
use Log;
class AdvaNetworkElementAlmTrap 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)
{
$alSeverity = $trap->getOidData($trap->findOid('CM-ALARM-MIB::cmNetworkElementAlmNotifCode'));
switch ($alSeverity) {
case "critical":
$logSeverity = 5;
break;
case "major":
$logSeverity = 4;
break;
case "minor":
$logSeverity = 3;
break;
case "cleared":
$logSeverity = 1;
break;
default:
$logSeverity = 2;
break;
}
$almDescr = $trap->getOidData($trap->findOid('CM-ALARM-MIB::cmNetworkElementAlmDescr'));
$almObjName = $trap->getOidData($trap->findOid('CM-ALARM-MIB::cmNetworkElementAlmObjectName'));
Log::event("Alarming Element: $almObjName Description: $almDescr Severity: $alSeverity", $device->device_id, 'trap', $logSeverity);
}
}

View File

@@ -0,0 +1,57 @@
<?php
/**
* AdvaObjectCreation.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/>.
*
* Traps when Adva objects are created. This includes Remote User Login object,
* Flow Creation object, and LAG Creation object.
*
* @package LibreNMS
* @link http://librenms.org
* @copyright 2018 KanREN, Inc
* @author Heath Barnhart <hbarnhart#kanren.net> & Neil Kahle <nkahle@kanren.net>
*/
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
use Log;
class AdvaObjectCreation 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)
{
if ($trap_oid = $trap->findOid('CM-SECURITY-MIB::cmSecurityUserName')) {
$UserName = $trap->getOidData($trap_oid);
Log::event("User object $UserName created", $device->device_id, 'trap', 2);
} elseif ($trap_oid = $trap->findOid('F3-LAG-MIB::f3LagName')) {
$lagID = substr($trap_oid, -1);
Log::event("LAG $lagID created", $device->device_id, 'trap', 2);
}
}
}

View File

@@ -0,0 +1,63 @@
<?php
/**
* AdvaObjectDeletion.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/>.
*
* Traps when Adva objects are deleted. This includes Remote User Login object,
* Flow Deletion object, LAG Member Port Removed object, and Lag Deletion object.
*
* @package LibreNMS
* @link http://librenms.org
* @copyright 2018 KanREN, Inc
* @author Heath Barnhart <hbarnhart@kanren.net> & Neil Kahle <nkahle@kanren.net>
*/
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
use Log;
class AdvaObjectDeletion 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)
{
if ($trap_oid = $trap->findOid('CM-SECURITY-MIB::cmSecurityUserName')) {
$UserName = $trap->getOidData($trap_oid);
Log::event("User object $UserName deleted", $device->device_id, 'trap', 2);
} elseif ($trap_oid = $trap->findOid('CM-FACILITY-MIB::cmFlowIndex')) {
$flowID = str_replace(".", "-", substr($trap_oid, 29));
Log::event("Flow $flowID deleted", $device->device_id, 'trap', 2);
} elseif ($trap_oid = $trap->findOid('F3-LAG-MIB::f3LagPortIndex')) {
$lagPortID = $trap->getOidData($trap_oid);
$lagID = str_replace(".", "-", substr($trap_oid, -5, 3));
Log::event("LAG member port $lagPortID removed from LAG $lagID", $device->device_id, 'trap', 2);
} elseif ($trap_oid = $trap->findOid('F3-LAG-MIB::f3LagIndex')) {
$lagID = $trap->getOidData($trap_oid);
Log::event("LAG $lagID deleted", $device->device_id, 'trap', 2);
}
}
}

View File

@@ -0,0 +1,50 @@
<?php
/**
* AdvaSnmpDyingGaspTrap.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/>.
*
* Adva SNMP Dying Gasp Trap. Trap that is sent when the Adva loses
* power and about to shut off.
*
* @package LibreNMS
* @link http://librenms.org
* @copyright 2018 KanREN, Inc.
* @author Heath Barnhart <hbarnhart@kanren.net> & Neil Kahle <nkahle@kanren.net>
*/
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
use Log;
class AdvaSnmpDyingGaspTrap 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)
{
Log::event("Dying Gasp received", $device->device_id, 'trap', 5);
}
}

View File

@@ -0,0 +1,68 @@
<?php
/**
* AdvaStateChangeTrap.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/>.
*
* Takes traps for interface state changes on Adva Ethernet Devices.
* On an interface state change serveral traps (6 observed) are sent via
* CM-SYSTEM-MIB::cmStateChangeTrap. This handler creates log entries based
* on the unit that sent the trap.
*
* @package LibreNMS
* @link http://librenms.org
* @copyright 2018 Heath Barnhart
* @author Heath Barnhart <hbarnhart@kanren.net> & Neil Kahle <nkahle@kanren.net>
*/
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
use Log;
class AdvaStateChangeTrap 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)
{
if ($trap_oid = $trap->findOid('CM-FACILITY-MIB::cmEthernetAccPortAdminState')) {
$adminState = $trap->getOidData($trap_oid);
$opState = $trap->getOidData($trap->findOid('CM-FACILITY-MIB::cmEthernetAccPortOperationalState'));
$portName = $trap->getOidData($trap->findOid('IF-MIB::ifName'));
Log::event("Port state change: $portName Admin State: $adminState Operational State: $opState", $device->device_id, 'trap', 2);
} elseif ($trap_oid = $trap->findOid('CM-FACILITY-MIB::cmFlowAdminState')) {
$adminState = $trap->getOidData($trap_oid);
$opState = $trap->getOidData($trap->findOid('CM-FACILITY-MIB::cmFlowOperationalState'));
$flowID = substr($trap->findOid('CM-FACILITY-MIB::cmFlowAdminState'), 34);
$flowID = str_replace(".", "-", $flowID);
Log::event("Flow state change: $flowID Admin State: $adminState Operational State: $opState", $device->device_id, 'trap', 2);
} elseif ($trap_oid = $trap->findOid('CM-FACILITY-MIB::cmEthernetNetPortAdminState')) {
$adminState = $trap->getOidData($trap_oid);
$opState = $trap->getOidData($trap->findOid('CM-FACILITY-MIB::cmEthernetNetPortOperationalState'));
$portName = $trap->getOidData($trap->findOid('IF-MIB::ifName'));
Log::event("Port state change: $portName Admin State: $adminState Operational State: $opState", $device->device_id, 'trap', 2);
}
}
}

View File

@@ -0,0 +1,70 @@
<?php
/**
* AdvaSysAlmTrap.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/>.
*
* Adva system alarm traps. This handler will log the description and a
* description of the alarm.
*
* @package LibreNMS
* @link http://librenms.org
* @copyright 2018 KanREN, Inc.
* @author Heath Barnhart <hbarnhart@kanren.net>
*/
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
use Log;
class AdvaSysAlmTrap 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)
{
$alSeverity = $trap->getOidData($trap->findOid('CM-ALARM-MIB::cmSysAlmNotifCode'));
switch ($alSeverity) {
case "critical":
$logSeverity = 5;
break;
case "major":
$logSeverity = 4;
break;
case "minor":
$logSeverity = 3;
break;
case "cleared":
$logSeverity = 1;
break;
default:
$logSeverity = 2;
break;
}
$sysAlmDescr = $trap->getOidData($trap->findOid('CM-ALARM-MIB::cmSysAlmDescr'));
Log::event("System Alarm: $sysAlmDescr Status: $alSeverity", $device->device_id, 'trap', $logSeverity);
}
}

View File

@@ -1,12 +1,12 @@
<?php
/*
| !!!! DO NOT EDIT THIS FILE !!!!
|
| You can change settings by setting them in the environment or .env
| If there is something you need to change, but is not available as an environment setting,
| request an environment variable to be created upstream or send a pull request.
*/
/*
| !!!! DO NOT EDIT THIS FILE !!!!
|
| You can change settings by setting them in the environment or .env
| If there is something you need to change, but is not available as an environment setting,
| request an environment variable to be created upstream or send a pull request.
*/
return [
'trap_handlers' => [
@@ -19,6 +19,16 @@ return [
'MG-SNMP-UPS-MIB::upsmgUtilityRestored' => \LibreNMS\Snmptrap\Handlers\UpsmgUtilityRestored::class,
'EQUIPMENT-MIB::equipStatusTrap' => \LibreNMS\Snmptrap\Handlers\EquipStatusTrap::class,
'LOG-MIB::logTrap' => \LibreNMS\Snmptrap\Handlers\LogTrap::class,
'CM-SYSTEM-MIB::cmObjectCreationTrap' => \LibreNMS\Snmptrap\Handlers\AdvaObjectCreation::class,
'CM-SYSTEM-MIB::cmObjectDeletionTrap' => \LibreNMS\Snmptrap\Handlers\AdvaObjectDeletion::class,
'CM-SYSTEM-MIB::cmStateChangeTrap' => \LibreNMS\Snmptrap\Handlers\AdvaStateChangeTrap::class,
'CM-PERFORMANCE-MIB::cmEthernetAccPortThresholdCrossingAlert' => \LibreNMS\Snmptrap\Handlers\AdvaAccThresholdCrossingAlert::class,
'CM-PERFORMANCE-MIB::cmEthernetNetPortThresholdCrossingAlert' => \LibreNMS\Snmptrap\Handlers\AdvaNetThresholdCrossingAlert::class,
'CM-ALARM-MIB::cmNetworkElementAlmTrap' => \LibreNMS\Snmptrap\Handlers\AdvaNetworkElementAlmTrap::class,
'CM-ALARM-MIB::cmSysAlmTrap' => \LibreNMS\Snmptrap\Handlers\AdvaSysAlmTrap::class,
'CM-SYSTEM-MIB::cmSnmpDyingGaspTrap' => \LibreNMS\Snmptrap\Handlers\AdvaSnmpDyingGaspTrap::class,
'CM-SYSTEM-MIB::cmAttributeValueChangeTrap' => \LibreNMS\Snmptrap\Handlers\AdvaAttributeChange::class,
'ENTITY-MIB::entConfigChange' => \LibreNMS\Snmptrap\Handlers\AdvaConfigChange::class,
'FORTINET-FORTIGATE-MIB::fgTrapVpnTunDown' => \LibreNMS\Snmptrap\Handlers\FgTrapVpnTunDown::class,
'FORTINET-FORTIGATE-MIB::fgTrapVpnTunUp' => \LibreNMS\Snmptrap\Handlers\FgTrapVpnTunUp::class,
'FORTINET-FORTIGATE-MIB::fgTrapIpsSignature' => \LibreNMS\Snmptrap\Handlers\FgTrapIpsSignature::class,

View File

@@ -0,0 +1,127 @@
<?php
/**
* AdvaAccThreholdCrossingAlertTest.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 Heath Barnhart
* @author Heath Barnhart <hbarnhart@kanren.net>
*/
namespace LibreNMS\Tests\Feature\SnmpTraps;
use App\Models\Device;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use LibreNMS\Snmptrap\Dispatcher;
use LibreNMS\Snmptrap\Trap;
use LibreNMS\Tests\LaravelTestCase;
class AdvaAccThresholdCrossingAlertTest extends LaravelTestCase
{
use DatabaseTransactions;
public function testAccThresholdTrap()
{
$device = factory(Device::class)->create();
$trapText = "$device->hostname
UDP: [$device->ip]:57602->[192.168.5.5]:162
DISMAN-EVENT-MIB::sysUpTimeInstance 26:19:43:37.24
SNMPv2-MIB::snmpTrapOID.0 CM-PERFORMANCE-MIB::cmEthernetAccPortThresholdCrossingAlert
CM-PERFORMANCE-MIB::cmEthernetAccPortThresholdIndex.1.1.1.2.1.37 37
CM-PERFORMANCE-MIB::cmEthernetAccPortThresholdInterval.1.1.1.2.1.37 interval-15min
CM-PERFORMANCE-MIB::cmEthernetAccPortThresholdVariable.1.1.1.2.1.37 CM-PERFORMANCE-MIB::cmEthernetAccPortStatsUAS.1.1.1.2.1
CM-PERFORMANCE-MIB::cmEthernetAccPortThresholdValueLo.1.1.1.2.1.37 10
CM-PERFORMANCE-MIB::cmEthernetAccPortThresholdValueHi.1.1.1.2.1.37 0
CM-PERFORMANCE-MIB::cmEthernetAccPortThresholdMonValue.1.1.1.2.1.37 10
IF-MIB::ifName.2 Access PORT-1-1-1-2
RMON2-MIB::probeDateTime.0 \"07 E2 0C 0A 0B 2D 0A 00 2D 06 00 \"
ADVA-MIB::neEventLogIndex.79 79
ADVA-MIB::neEventLogTimeStamp.79 2018-12-10,11:45:10.8,-6:0";
$trap = new Trap($trapText);
$message = "Access PORT-1-1-1-2 unavailable seconds threshold exceeded for interval-15min";
\Log::shouldReceive('event')->once()->with($message, $device->device_id, 'trap', 2);
$this->assertTrue(Dispatcher::handle($trap), 'Could not handle cmEthernetAccPortThresholdCrossingAlert UAS');
$trapText = "$device->hostname
UDP: [$device->ip]:57602->[192.168.5.5]:162
DISMAN-EVENT-MIB::sysUpTimeInstance 26:19:43:37.24
SNMPv2-MIB::snmpTrapOID.0 CM-PERFORMANCE-MIB::cmEthernetAccPortThresholdCrossingAlert
CM-PERFORMANCE-MIB::cmEthernetAccPortThresholdIndex.1.1.1.2.1.37 37
CM-PERFORMANCE-MIB::cmEthernetAccPortThresholdInterval.1.1.1.2.1.37 interval-1day
CM-PERFORMANCE-MIB::cmEthernetAccPortThresholdVariable.1.1.1.2.1.37 CM-PERFORMANCE-MIB::cmEthernetAccPortStatsESBP.1.1.1.2.1
CM-PERFORMANCE-MIB::cmEthernetAccPortThresholdValueLo.1.1.1.2.1.37 20
CM-PERFORMANCE-MIB::cmEthernetAccPortThresholdValueHi.1.1.1.2.1.37 0
CM-PERFORMANCE-MIB::cmEthernetAccPortThresholdMonValue.1.1.1.2.1.37 20
IF-MIB::ifName.2 Access PORT-1-1-1-2
RMON2-MIB::probeDateTime.0 \"07 E2 0C 0A 0B 2D 0A 00 2D 06 00 \"
ADVA-MIB::neEventLogIndex.79 79
ADVA-MIB::neEventLogTimeStamp.79 2018-12-10,11:45:10.8,-6:0";
$trap = new Trap($trapText);
$message = 'Access PORT-1-1-1-2 broadcast frames received threshold exceeded for interval-1day';
\Log::shouldReceive('event')->once()->with($message, $device->device_id, 'trap', 2);
$this->assertTrue(Dispatcher::handle($trap), 'Could not handle cmEthernetAccPortThresholdCrossingAlert broadcast framesent');
$trapText = "$device->hostname
UDP: [$device->ip]:57602->[192.168.5.5]:162
DISMAN-EVENT-MIB::sysUpTimeInstance 26:19:43:37.24
SNMPv2-MIB::snmpTrapOID.0 CM-PERFORMANCE-MIB::cmEthernetAccPortThresholdCrossingAlert
CM-PERFORMANCE-MIB::cmEthernetAccPortThresholdIndex.1.1.1.3.1.37 37
CM-PERFORMANCE-MIB::cmEthernetAccPortThresholdInterval.1.1.1.3.1.37 interval-1day
CM-PERFORMANCE-MIB::cmEthernetAccPortThresholdVariable.1.1.1.3.1.37 CM-PERFORMANCE-MIB::cmEthernetAccPortStatsESUP.1.1.1.2.1
CM-PERFORMANCE-MIB::cmEthernetAccPortThresholdValueLo.1.1.1.3.1.37 20
CM-PERFORMANCE-MIB::cmEthernetAccPortThresholdValueHi.1.1.1.3.1.37 0
CM-PERFORMANCE-MIB::cmEthernetAccPortThresholdMonValue.1.1.1.3.1.37 20
IF-MIB::ifName.2 Access PORT-1-1-1-3
RMON2-MIB::probeDateTime.0 \"07 E2 0C 0A 0B 2D 0A 00 2D 06 00 \"
ADVA-MIB::neEventLogIndex.79 79
ADVA-MIB::neEventLogTimeStamp.79 2018-12-10,11:45:10.8,-6:0";
$trap = new Trap($trapText);
$message = "Access PORT-1-1-1-3 unicast frames received threshold exceeded for interval-1day";
\Log::shouldReceive('event')->once()->with($message, $device->device_id, 'trap', 2);
$this->assertTrue(Dispatcher::handle($trap), 'Could not handle cmEthernetAccPortThresholdCrossingAlert unicast frames sent');
$trapText = "$device->hostname
UDP: [$device->ip]:57602->[192.168.5.5]:162
DISMAN-EVENT-MIB::sysUpTimeInstance 26:19:43:37.24
SNMPv2-MIB::snmpTrapOID.0 CM-PERFORMANCE-MIB::cmEthernetAccPortThresholdCrossingAlert
CM-PERFORMANCE-MIB::cmEthernetAccPortThresholdIndex.1.1.1.3.1.37 37
CM-PERFORMANCE-MIB::cmEthernetAccPortThresholdInterval.1.1.1.3.1.37 interval-1day
CM-PERFORMANCE-MIB::cmEthernetAccPortThresholdVariable.1.1.1.3.1.37 CM-PERFORMANCE-MIB::defaultThresholdTest.1.1.1.3.1
IF-MIB::ifName.2 Access PORT-1-1-1-3
RMON2-MIB::probeDateTime.0 \"07 E2 0C 0A 0B 2D 0A 00 2D 06 00 \"
ADVA-MIB::neEventLogIndex.79 79
ADVA-MIB::neEventLogTimeStamp.79 2018-12-10,11:45:10.8,-6:0";
$trap = new Trap($trapText);
$message = "Access PORT-1-1-1-3 unknown threshold exceeded for interval-1day";
\Log::shouldReceive('event')->once()->with($message, $device->device_id, 'trap', 2);
$this->assertTrue(Dispatcher::handle($trap), 'Could not handle cmEthernetAccPortThresholdCrossingAlert unknown threshold');
}
}

View File

@@ -0,0 +1,633 @@
<?php
/**
* AdvaAttributeChangeTest.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 Heath Barnhart
* @author Heath Barnhart <hbarnhart@kanren.net>
*/
namespace LibreNMS\Tests\Feature\SnmpTraps;
use App\Models\Device;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use LibreNMS\Snmptrap\Dispatcher;
use LibreNMS\Snmptrap\Trap;
use LibreNMS\Tests\LaravelTestCase;
class AdvaAttributeChangeTest extends LaravelTestCase
{
use DatabaseTransactions;
public function testSyslogIPVersionModified()
{
$device = factory(Device::class)->create();
$trapText = "$device->hostname
UDP: [$device->ip]:57602->[192.168.5.5]:162
DISMAN-EVENT-MIB::sysUpTimeInstance 26:19:43:37.24
SNMPv2-MIB::snmpTrapOID.0 CM-SYSTEM-MIB::cmAttributeValueChangeTrap
CM-SYSTEM-MIB::sysLogIpVersion.1 ipv6
RMON2-MIB::probeDateTime.0 \"07 E2 0C 0A 09 0B 28 00 2D 06 00 \"
ADVA-MIB::neEventLogIndex.150 150
ADVA-MIB::neEventLogTimeStamp.150 2018-12-10,9:11:40.5,-6:0";
$trap = new Trap($trapText);
$message = "Syslog server 1 IP version set to ipv6";
\Log::shouldReceive('event')->once()->with($message, $device->device_id, 'trap', 2);
$this->assertTrue(Dispatcher::handle($trap), 'Could not handle cmAttributeValueChangeTrap IP version modified');
}
public function testSyslogIP6AddrModified()
{
$device = factory(Device::class)->create();
$trapText = "$device->hostname
UDP: [$device->ip]:57602->[192.168.5.5]:162
DISMAN-EVENT-MIB::sysUpTimeInstance 26:19:43:37.24
SNMPv2-MIB::snmpTrapOID.0 CM-SYSTEM-MIB::cmAttributeValueChangeTrap
CM-SYSTEM-MIB::sysLogIpv6Addr.1 2001:49d0:3c0c:0:0:0:0:1
RMON2-MIB::probeDateTime.0 \"07 E2 0C 0A 09 0B 28 00 2D 06 00 \"
ADVA-MIB::neEventLogIndex.150 150
ADVA-MIB::neEventLogTimeStamp.150 2018-12-10,9:11:40.5,-6:0";
$trap = new Trap($trapText);
$message = "Syslog server 1 IP address changed to 2001:49d0:3c0c:0:0:0:0:1";
\Log::shouldReceive('event')->once()->with($message, $device->device_id, 'trap', 2);
$this->assertTrue(Dispatcher::handle($trap), 'Could not handle cmAttributeValueChangeTrap IPv6 address modified');
}
public function testSyslogIPAddrModified()
{
$device = factory(Device::class)->create();
$trapText = "$device->hostname
UDP: [$device->ip]:57602->[192.168.5.5]:162
DISMAN-EVENT-MIB::sysUpTimeInstance 26:19:43:37.24
SNMPv2-MIB::snmpTrapOID.0 CM-SYSTEM-MIB::cmAttributeValueChangeTrap
CM-SYSTEM-MIB::sysLogIpAddress.1 192.168.1.1
RMON2-MIB::probeDateTime.0 \"07 E2 0C 0A 09 0B 28 00 2D 06 00 \"
ADVA-MIB::neEventLogIndex.150 150
ADVA-MIB::neEventLogTimeStamp.150 2018-12-10,9:11:40.5,-6:0";
$trap = new Trap($trapText);
$message = "Syslog server 1 IP address changed to 192.168.1.1";
\Log::shouldReceive('event')->once()->with($message, $device->device_id, 'trap', 2);
$this->assertTrue(Dispatcher::handle($trap), 'Could not handle cmAttributeValueChangeTrap IPv4 address modified');
}
public function testSyslogPortModified()
{
$device = factory(Device::class)->create();
$trapText = "$device->hostname
UDP: [$device->ip]:57602->[192.168.5.5]:162
DISMAN-EVENT-MIB::sysUpTimeInstance 26:19:43:37.24
SNMPv2-MIB::snmpTrapOID.0 CM-SYSTEM-MIB::cmAttributeValueChangeTrap
CM-SYSTEM-MIB::sysLogPort.1 514
RMON2-MIB::probeDateTime.0 \"07 E2 0C 0A 09 0B 28 00 2D 06 00 \"
ADVA-MIB::neEventLogIndex.150 150
ADVA-MIB::neEventLogTimeStamp.150 2018-12-10,9:11:40.5,-6:0";
$trap = new Trap($trapText);
$message = "Syslog server 1 port changed to 514";
\Log::shouldReceive('event')->once()->with($message, $device->device_id, 'trap', 2);
$this->assertTrue(Dispatcher::handle($trap), 'Could not handle cmAttributeValueChangeTrap port modified');
}
public function testAclModified()
{
$device = factory(Device::class)->create();
$trapText = "$device->hostname
UDP: [$device->ip]:57602->[192.168.5.5]:162
DISMAN-EVENT-MIB::sysUpTimeInstance 26:19:43:37.24
SNMPv2-MIB::snmpTrapOID.0 CM-SYSTEM-MIB::cmAttributeValueChangeTrap
CM-SYSTEM-MIB::aclEntryEnabled.5 false
RMON2-MIB::probeDateTime.0 \"07 E2 0C 0A 09 11 16 00 2D 06 00 \"
ADVA-MIB::neEventLogIndex.155 155
ADVA-MIB::neEventLogTimeStamp.155 2018-12-10,9:17:22.5,-6:0";
$trap = new Trap($trapText);
$message = "ACL 5 modified";
\Log::shouldReceive('event')->once()->with($message, $device->device_id, 'trap', 2);
$this->assertTrue(Dispatcher::handle($trap), 'Could not handle cmAttributeValueChangeTrap ACL entry modified');
}
public function testBannerModified()
{
$device = factory(Device::class)->create();
$trapText = "$device->hostname
UDP: [$device->ip]:57602->[192.168.5.5]:162
DISMAN-EVENT-MIB::sysUpTimeInstance 26:19:43:37.24
SNMPv2-MIB::snmpTrapOID.0 CM-SYSTEM-MIB::cmAttributeValueChangeTrap
CM-SYSTEM-MIB::securityBanner.0 Test MoTD
RMON2-MIB::probeDateTime.0 \"07 E2 0C 0A 09 12 2B 00 2D 06 00 \"
ADVA-MIB::neEventLogIndex.157 157
ADVA-MIB::neEventLogTimeStamp.157 2018-12-10,9:18:43.6,-6:0";
$trap = new Trap($trapText);
$message = "MOTD/Banner modified";
\Log::shouldReceive('event')->once()->with($message, $device->device_id, 'trap', 2);
$this->assertTrue(Dispatcher::handle($trap), 'Could not handle cmAttributeValueChangeTrap banner modified');
}
public function testTimeSourceModified()
{
$device = factory(Device::class)->create();
$trapText = "$device->hostname
UDP: [$device->ip]:57602->[192.168.5.5]:162
DISMAN-EVENT-MIB::sysUpTimeInstance 26:19:43:37.24
SNMPv2-MIB::snmpTrapOID.0 CM-SYSTEM-MIB::cmAttributeValueChangeTrap
CM-SYSTEM-MIB::sysTimeOfDayType.0 ntp
F3-PTP-MIB::f3PtpSysTimeOfDayClock.0 SNMPv2-SMI::zeroDotZero
RMON2-MIB::probeDateTime.0 \"07 E2 0C 0A 09 1C 39 00 2D 06 00 \"
ADVA-MIB::neEventLogIndex.169 169
ADVA-MIB::neEventLogTimeStamp.169 2018-12-10,9:28:57.1,-6:0";
$trap = new Trap($trapText);
$message = "Time source set to ntp";
\Log::shouldReceive('event')->once()->with($message, $device->device_id, 'trap', 2);
$this->assertTrue(Dispatcher::handle($trap), 'Could not handle cmAttributeValueChangeTrap time source modified');
$trapText = "$device->hostname
UDP: [$device->ip]:57602->[192.168.5.5]:162
DISMAN-EVENT-MIB::sysUpTimeInstance 26:19:43:37.24
SNMPv2-MIB::snmpTrapOID.0 CM-SYSTEM-MIB::cmAttributeValueChangeTrap
CM-SYSTEM-MIB::sysTimeOfDayType.0 local
F3-PTP-MIB::f3PtpSysTimeOfDayClock.0 SNMPv2-SMI::zeroDotZero
RMON2-MIB::probeDateTime.0 \"07 E2 0C 0A 09 1C 39 00 2D 06 00 \"
ADVA-MIB::neEventLogIndex.169 169
ADVA-MIB::neEventLogTimeStamp.169 2018-12-10,9:28:57.1,-6:0";
$trap = new Trap($trapText);
$message = "Time source set to local";
\Log::shouldReceive('event')->once()->with($message, $device->device_id, 'trap', 2);
$this->assertTrue(Dispatcher::handle($trap), 'Could not handle cmAttributeValueChangeTrap time source modified');
}
public function testTimeZoneModified()
{
$device = factory(Device::class)->create();
$trapText = "$device->hostname
UDP: [$device->ip]:57602->[192.168.5.5]:162
DISMAN-EVENT-MIB::sysUpTimeInstance 26:19:43:37.24
SNMPv2-MIB::snmpTrapOID.0 CM-SYSTEM-MIB::cmAttributeValueChangeTrap
F3-TIMEZONE-MIB::f3TimeZoneDstControlEnabled.0 true
RMON2-MIB::probeDateTime.0 \"07 E2 0C 0A 09 14 21 00 2D 06 00 \"
ADVA-MIB::neEventLogIndex.158 158
ADVA-MIB::neEventLogTimeStamp.158 2018-12-10,9:20:33.5,-6:0";
$trap = new Trap($trapText);
$message = "Daylight Savings Time enabled";
\Log::shouldReceive('event')->once()->with($message, $device->device_id, 'trap', 2);
$this->assertTrue(Dispatcher::handle($trap), 'Could not handle cmAttributeValueChangeTrap DST enabled');
$trapText = "$device->hostname
UDP: [$device->ip]:57602->[192.168.5.5]:162
DISMAN-EVENT-MIB::sysUpTimeInstance 26:19:43:37.24
SNMPv2-MIB::snmpTrapOID.0 CM-SYSTEM-MIB::cmAttributeValueChangeTrap
F3-TIMEZONE-MIB::f3TimeZoneDstControlEnabled.0 false
RMON2-MIB::probeDateTime.0 \"07 E2 0C 0A 09 14 21 00 2D 06 00 \"
ADVA-MIB::neEventLogIndex.158 158
ADVA-MIB::neEventLogTimeStamp.158 2018-12-10,9:20:33.5,-6:0";
$trap = new Trap($trapText);
$message = "Daylight Savings Time disabled";
\Log::shouldReceive('event')->once()->with($message, $device->device_id, 'trap', 2);
$this->assertTrue(Dispatcher::handle($trap), 'Could not handle cmAttributeValueChangeTrap DST disabled');
$trapText = "$device->hostname
UDP: [$device->ip]:57602->[192.168.5.5]:162
DISMAN-EVENT-MIB::sysUpTimeInstance 26:19:43:37.24
SNMPv2-MIB::snmpTrapOID.0 CM-SYSTEM-MIB::cmAttributeValueChangeTrap
F3-TIMEZONE-MIB::f3TimeZoneUtcOffset.0 -05:00
RMON2-MIB::probeDateTime.0 \"07 E2 0C 0A 0A 15 1E 00 2D 05 00 \"
ADVA-MIB::neEventLogIndex.160 160
ADVA-MIB::neEventLogTimeStamp.160 2018-12-10,10:21:30.3,-5:0";
$trap = new Trap($trapText);
$message = "UTC offset (timezone) change to -05:00";
\Log::shouldReceive('event')->once()->with($message, $device->device_id, 'trap', 2);
$this->assertTrue(Dispatcher::handle($trap), 'Could not handle cmAttributeValueChangeTrap UTC offset modified');
}
public function testNtpModified()
{
$device = factory(Device::class)->create();
$trapText = "$device->hostname
UDP: [$device->ip]:57602->[192.168.5.5]:162
DISMAN-EVENT-MIB::sysUpTimeInstance 26:19:43:37.24
SNMPv2-MIB::snmpTrapOID.0 CM-SYSTEM-MIB::cmAttributeValueChangeTrap
CM-SYSTEM-MIB::ntpPrimaryServer.0 192.168.2.2
CM-SYSTEM-MIB::ntpPrimaryServerIpVersion.0 ipv4
RMON2-MIB::probeDateTime.0 \"07 E2 0C 0A 09 1E 11 00 2D 06 00 \"
ADVA-MIB::neEventLogIndex.170 170
ADVA-MIB::neEventLogTimeStamp.170 2018-12-10,9:30:17.0,-6:0";
$trap = new Trap($trapText);
$message = "Primary NTP server IP changed to 192.168.2.2";
\Log::shouldReceive('event')->once()->with($message, $device->device_id, 'trap', 2);
$this->assertTrue(Dispatcher::handle($trap), 'Could not handle cmAttributeValueChangeTrap NTP primary server modified');
$trapText = "$device->hostname
UDP: [$device->ip]:57602->[192.168.5.5]:162
DISMAN-EVENT-MIB::sysUpTimeInstance 26:19:43:37.24
SNMPv2-MIB::snmpTrapOID.0 CM-SYSTEM-MIB::cmAttributeValueChangeTrap
CM-SYSTEM-MIB::ntpBackupServer.0 192.168.2.1
CM-SYSTEM-MIB::ntpBackupServerIpVersion.0 ipv4
RMON2-MIB::probeDateTime.0 \"07 E2 0C 0A 09 1E 11 00 2D 06 00 \"
ADVA-MIB::neEventLogIndex.170 170
ADVA-MIB::neEventLogTimeStamp.170 2018-12-10,9:30:17.0,-6:0";
$trap = new Trap($trapText);
$message = "Backup NTP server IP changed to 192.168.2.1";
\Log::shouldReceive('event')->once()->with($message, $device->device_id, 'trap', 2);
$this->assertTrue(Dispatcher::handle($trap), 'Could not handle cmAttributeValueChangeTrap NTP backup server modified');
}
public function testAuthServerModified()
{
$device = factory(Device::class)->create();
$trapText = "$device->hostname
UDP: [$device->ip]:57602->[192.168.5.5]:162
DISMAN-EVENT-MIB::sysUpTimeInstance 26:19:43:37.24
SNMPv2-MIB::snmpTrapOID.0 CM-SYSTEM-MIB::cmAttributeValueChangeTrap
CM-SECURITY-MIB::cmRemoteAuthServerAccountingPort.3 1810
CM-SECURITY-MIB::cmRemoteAuthServerPort.3 1811
CM-SECURITY-MIB::cmRemoteAuthServerIpAddress.3 192.168.1.1
CM-SECURITY-MIB::cmRemoteAuthServerSecret.3 *****
CM-SECURITY-MIB::cmRemoteAuthServerEnabled.3 true
RMON2-MIB::probeDateTime.0 \"07 E2 0C 0A 09 20 12 00 2D 06 00 \"
ADVA-MIB::neEventLogIndex.173 173
ADVA-MIB::neEventLogTimeStamp.173 2018-12-10,9:32:18.1,-6:0";
$trap = new Trap($trapText);
$message = "Authentication server 3 IP changed to 192.168.1.1";
\Log::shouldReceive('event')->once()->with($message, $device->device_id, 'trap', 2);
$message = "Authentication server 3 secret changed";
\Log::shouldReceive('event')->once()->with($message, $device->device_id, 'trap', 2);
$message = "Authentication server 3 enabled";
\Log::shouldReceive('event')->once()->with($message, $device->device_id, 'trap', 2);
$this->assertTrue(Dispatcher::handle($trap), 'Could not handle cmAttributeValueChangeTrap authentication server modified');
$trapText = "$device->hostname
UDP: [$device->ip]:57602->[192.168.5.5]:162
DISMAN-EVENT-MIB::sysUpTimeInstance 26:19:43:37.24
SNMPv2-MIB::snmpTrapOID.0 CM-SYSTEM-MIB::cmAttributeValueChangeTrap
CM-SECURITY-MIB::cmRemoteAuthServerEnabled.3 false
RMON2-MIB::probeDateTime.0 \"07 E2 0C 0A 09 20 12 00 2D 06 00 \"
ADVA-MIB::neEventLogIndex.173 173
ADVA-MIB::neEventLogTimeStamp.173 2018-12-10,9:32:18.1,-6:0";
$trap = new Trap($trapText);
$message = "Authentication server 3 disabled";
\Log::shouldReceive('event')->once()->with($message, $device->device_id, 'trap', 2);
$this->assertTrue(Dispatcher::handle($trap), 'Could not handle cmAttributeValueChangeTrap authentication server disabled');
}
public function testNeModified()
{
$device = factory(Device::class)->create();
$trapText = "$device->hostname
UDP: [$device->ip]:57602->[192.168.5.5]:162
DISMAN-EVENT-MIB::sysUpTimeInstance 26:19:43:37.24
SNMPv2-MIB::snmpTrapOID.0 CM-SYSTEM-MIB::cmAttributeValueChangeTrap
CM-ENTITY-MIB::neName.1 adva-test-1
CM-ENTITY-MIB::neCmdPromptPrefix.1 adva-test-1-prompt
RMON2-MIB::probeDateTime.0 \"07 E2 0C 0A 09 22 17 00 2D 06 00 \"
ADVA-MIB::neEventLogIndex.175 175
ADVA-MIB::neEventLogTimeStamp.175 2018-12-10,9:34:23.0,-6:0";
$trap = new Trap($trapText);
$message = "Network Element name changed to adva-test-1";
\Log::shouldReceive('event')->once()->with($message, $device->device_id, 'trap', 2);
$message = "Network Element prompt changed to adva-test-1-prompt";
\Log::shouldReceive('event')->once()->with($message, $device->device_id, 'trap', 2);
$this->assertTrue(Dispatcher::handle($trap), 'Could not handle cmAttributeValueChangeTrap network element modified');
}
public function testSnmpDyingGaspStateModified()
{
$device = factory(Device::class)->create();
$trapText = "$device->hostname
UDP: [$device->ip]:57602->[192.168.5.5]:162
DISMAN-EVENT-MIB::sysUpTimeInstance 26:19:43:37.24
SNMPv2-MIB::snmpTrapOID.0 CM-SYSTEM-MIB::cmAttributeValueChangeTrap
CM-ENTITY-MIB::ethernetNTEGE114ProCardSnmpDyingGaspEnabled.1.1.1 true
RMON2-MIB::probeDateTime.0 \"07 E2 0C 0A 09 24 0E 00 2D 06 00 \"
ADVA-MIB::neEventLogIndex.177 177
ADVA-MIB::neEventLogTimeStamp.177 2018-12-10,9:36:14.5,-6:0";
$trap = new Trap($trapText);
$message = "SNMP Dying Gasp is enabled";
\Log::shouldReceive('event')->once()->with($message, $device->device_id, 'trap', 2);
$this->assertTrue(Dispatcher::handle($trap), 'Could not handle cmAttributeValueChangeTrap SNMP dying gasp enabled');
$trapText = "$device->hostname
UDP: [$device->ip]:57602->[192.168.5.5]:162
DISMAN-EVENT-MIB::sysUpTimeInstance 26:19:43:37.24
SNMPv2-MIB::snmpTrapOID.0 CM-SYSTEM-MIB::cmAttributeValueChangeTrap
CM-ENTITY-MIB::ethernetNTEGE114ProCardSnmpDyingGaspEnabled.1.1.1 false
RMON2-MIB::probeDateTime.0 \"07 E2 0C 0A 09 24 0E 00 2D 06 00 \"
ADVA-MIB::neEventLogIndex.177 177
ADVA-MIB::neEventLogTimeStamp.177 2018-12-10,9:36:14.5,-6:0";
$trap = new Trap($trapText);
$message = "SNMP Dying Gasp is disabled";
\Log::shouldReceive('event')->once()->with($message, $device->device_id, 'trap', 2);
$this->assertTrue(Dispatcher::handle($trap), 'Could not handle cmAttributeValueChangeTrap SNMP dying gasp disabled');
}
public function testNetPortModified()
{
$device = factory(Device::class)->create();
$trapText = "$device->hostname
UDP: [$device->ip]:57602->[192.168.5.5]:162
DISMAN-EVENT-MIB::sysUpTimeInstance 26:19:43:37.24
SNMPv2-MIB::snmpTrapOID.0 CM-SYSTEM-MIB::cmAttributeValueChangeTrap
CM-FACILITY-MIB::cmEthernetNetPortConfigSpeed.1.1.1.2 speed-auto-100MB-full
CM-FACILITY-MIB::cmEthernetNetPortMediaType.1.1.1.2 copper
CM-FACILITY-MIB::cmEthernetNetPortMDIXType.1.1.1.2 crossed
CM-FACILITY-MIB::cmEthernetNetPortAutoDiagEnabled.1.1.1.2 false
CM-FACILITY-MIB::cmEthernetNetPortAdminState.1.1.1.2 in-service
CM-FACILITY-MIB::cmEthernetNetPortMTU.1.1.1.2 9000
CM-FACILITY-MIB::cmEthernetNetPortConfigSpeed.1.1.1.2 speed-auto-100MB-full
RMON2-MIB::probeDateTime.0 \"07 E2 0C 0A 09 29 31 00 2D 06 00 \"
ADVA-MIB::neEventLogIndex.188 188
ADVA-MIB::neEventLogTimeStamp.188 2018-12-10,9:41:49.0,-6:0";
$trap = new Trap($trapText);
$message = "Network Port 1-1-1-2 changed speed to speed-auto-100MB-full";
\Log::shouldReceive('event')->once()->with($message, $device->device_id, 'trap', 2);
$message = "Network Port 1-1-1-2 changed media to copper";
\Log::shouldReceive('event')->once()->with($message, $device->device_id, 'trap', 2);
$message = "Network Port 1-1-1-2 changed MDIX to crossed";
\Log::shouldReceive('event')->once()->with($message, $device->device_id, 'trap', 2);
$message = "Network Port 1-1-1-2 AutoDiagnostic disabled";
\Log::shouldReceive('event')->once()->with($message, $device->device_id, 'trap', 2);
$message = "Network Port 1-1-1-2 administrative state changed to in-service";
\Log::shouldReceive('event')->once()->with($message, $device->device_id, 'trap', 2);
$message = "Network Port 1-1-1-2 MTU changed to 9000 bytes";
\Log::shouldReceive('event')->once()->with($message, $device->device_id, 'trap', 2);
$this->assertTrue(Dispatcher::handle($trap), 'Could not handle cmAttributeValueChangeTrap network port modified specific messages');
$trapText = "$device->hostname
UDP: [$device->ip]:57602->[192.168.5.5]:162
DISMAN-EVENT-MIB::sysUpTimeInstance 26:19:43:37.24
SNMPv2-MIB::snmpTrapOID.0 CM-SYSTEM-MIB::cmAttributeValueChangeTrap
CM-FACILITY-MIB::cmEthernetNetPortFakeOID.1.1.1.2 TestGenericMessage
RMON2-MIB::probeDateTime.0 \"07 E2 0C 0A 09 29 31 00 2D 06 00 \"
ADVA-MIB::neEventLogIndex.188 188
ADVA-MIB::neEventLogTimeStamp.188 2018-12-10,9:41:49.0,-6:0";
$trap = new Trap($trapText);
$message = "Network Port 1-1-1-2 modified";
\Log::shouldReceive('event')->once()->with($message, $device->device_id, 'trap', 2);
$this->assertTrue(Dispatcher::handle($trap), 'Could not handle cmAttributeValueChangeTrap network port modified generic message');
}
public function testAccPortModied()
{
$device = factory(Device::class)->create();
$trapText = "$device->hostname
UDP: [$device->ip]:57602->[192.168.5.5]:162
DISMAN-EVENT-MIB::sysUpTimeInstance 26:19:43:37.24
SNMPv2-MIB::snmpTrapOID.0 CM-SYSTEM-MIB::cmAttributeValueChangeTrap
CM-FACILITY-MIB::cmEthernetAccPortMediaType.1.1.1.4 fiber
CM-FACILITY-MIB::cmEthernetAccPortAutoDiagEnabled.1.1.1.4 false
CM-FACILITY-MIB::cmEthernetAccPortConfigSpeed.1.1.1.4 speed-auto-1000MB-full
CM-FACILITY-MIB::cmEthernetAccPortMDIXType.1.1.1.4 not-applicable
CM-FACILITY-MIB::cmEthernetAccPortMTU.1.1.1.4 9000
CM-FACILITY-MIB::cmEthernetAccPortAdminState.1.1.1.4 maintenance
CM-FACILITY-MIB::cmAccPortExtRefPrioMapProfile.1.1.1.4 SNMPv2-SMI::zeroDotZero
RMON2-MIB::probeDateTime.0 \"07 E2 0C 0A 09 2B 16 00 2D 06 00 \"
ADVA-MIB::neEventLogIndex.214 214
ADVA-MIB::neEventLogTimeStamp.214 2018-12-10,9:43:22.3,-6:0";
$trap = new Trap($trapText);
$message = "Access Port 1-1-1-4 changed speed to speed-auto-1000MB-full";
\Log::shouldReceive('event')->once()->with($message, $device->device_id, 'trap', 2);
$message = "Access Port 1-1-1-4 changed media to fiber";
\Log::shouldReceive('event')->once()->with($message, $device->device_id, 'trap', 2);
$message = "Access Port 1-1-1-4 changed MDIX to not-applicable";
\Log::shouldReceive('event')->once()->with($message, $device->device_id, 'trap', 2);
$message = "Access Port 1-1-1-4 AutoDiagnostic disabled";
\Log::shouldReceive('event')->once()->with($message, $device->device_id, 'trap', 2);
$message = "Access Port 1-1-1-4 administrative state changed to maintenance";
\Log::shouldReceive('event')->once()->with($message, $device->device_id, 'trap', 2);
$message = "Access Port 1-1-1-4 MTU changed to 9000 bytes";
\Log::shouldReceive('event')->once()->with($message, $device->device_id, 'trap', 2);
$this->assertTrue(Dispatcher::handle($trap), 'Could not handle cmAttributeValueChangeTrap access port modified specific messages');
$trapText = "$device->hostname
UDP: [$device->ip]:57602->[192.168.5.5]:162
DISMAN-EVENT-MIB::sysUpTimeInstance 26:19:43:37.24
SNMPv2-MIB::snmpTrapOID.0 CM-SYSTEM-MIB::cmAttributeValueChangeTrap
CM-FACILITY-MIB::cmEthernetAccPortA2NPushPVIDEnabled.1.1.1.4 false
CM-FACILITY-MIB::cmAccPortExtRefPrioMapProfile.1.1.1.4 SNMPv2-SMI::zeroDotZero
RMON2-MIB::probeDateTime.0 \"07 E2 0C 0A 09 2B 16 00 2D 06 00 \"
ADVA-MIB::neEventLogIndex.214 214
ADVA-MIB::neEventLogTimeStamp.214 2018-12-10,9:43:22.3,-6:0";
$trap = new Trap($trapText);
$message = "Access Port 1-1-1-4 modified";
\Log::shouldReceive('event')->once()->with($message, $device->device_id, 'trap', 2);
$this->assertTrue(Dispatcher::handle($trap), 'Could not handle cmAttributeValueChangeTrap access port modified gerneric messages');
}
public function testAccFlowModified()
{
$device = factory(Device::class)->create();
$trapText = "$device->hostname
UDP: [$device->ip]:57602->[192.168.5.5]:162
DISMAN-EVENT-MIB::sysUpTimeInstance 26:19:43:37.24
SNMPv2-MIB::snmpTrapOID.0 CM-SYSTEM-MIB::cmAttributeValueChangeTrap
CM-FACILITY-MIB::cmFlowN2AEIR.1.1.1.4.1 0
CM-FACILITY-MIB::cmFlowN2ACIR.1.1.1.4.1 0
CM-FACILITY-MIB::cmFlowN2ACIRHi.1.1.1.4.1 0
CM-FACILITY-MIB::cmFlowN2AEIRHi.1.1.1.4.1 0
RMON2-MIB::probeDateTime.0 \"07 E2 0C 0A 09 07 1C 00 2D 06 00 \"
ADVA-MIB::neEventLogIndex.147 147
ADVA-MIB::neEventLogTimeStamp.147 2018-12-10,9:7:28.1,-6:0";
$trap = new Trap($trapText);
$message = "Access Flow 1-1-1-4-1 modified";
\Log::shouldReceive('event')->once()->with($message, $device->device_id, 'trap', 2);
$this->assertTrue(Dispatcher::handle($trap), 'Could not handle cmAttributeValueChangeTrap access flow modified');
}
public function testLagModified()
{
$device = factory(Device::class)->create();
$trapText = "$device->hostname
UDP: [$device->ip]:57602->[192.168.5.5]:162
DISMAN-EVENT-MIB::sysUpTimeInstance 26:19:43:37.24
SNMPv2-MIB::snmpTrapOID.0 CM-SYSTEM-MIB::cmAttributeValueChangeTrap
F3-LAG-MIB::f3LagName.1.1 LagTest
RMON2-MIB::probeDateTime.0 \"07 E2 0C 0A 08 3A 2B 00 2D 06 00 \"
ADVA-MIB::neEventLogIndex.113 113
ADVA-MIB::neEventLogTimeStamp.113 2018-12-10,8:58:43.7,-6:0";
$trap = new Trap($trapText);
$message = "LAG 1 modified";
\Log::shouldReceive('event')->once()->with($message, $device->device_id, 'trap', 2);
$this->assertTrue(Dispatcher::handle($trap), 'Could not handle cmAttributeValueChangeTrap LAG modified');
}
public function testQosFlowPolicerModfied()
{
$device = factory(Device::class)->create();
$trapText = "$device->hostname
UDP: [$device->ip]:57602->[192.168.5.5]:162
DISMAN-EVENT-MIB::sysUpTimeInstance 26:19:43:37.24
SNMPv2-MIB::snmpTrapOID.0 CM-SYSTEM-MIB::cmAttributeValueChangeTrap
CM-FACILITY-MIB::cmQosFlowPolicerCIRLo.1.1.1.3.1.1.1 9856000
CM-FACILITY-MIB::cmQosFlowPolicerCIRHi.1.1.1.3.1.1.1 0
CM-FACILITY-MIB::cmQosFlowPolicerEntry.21.1.1.1.3.1.1.1 9856000
CM-FACILITY-MIB::cmQosFlowPolicerEntry.20.1.1.1.3.1.1.1 0
RMON2-MIB::probeDateTime.0 \"07 E2 0C 0A 09 2F 33 00 2D 06 00 \"
ADVA-MIB::neEventLogIndex.217 217
ADVA-MIB::neEventLogTimeStamp.217 2018-12-10,9:47:51.0,-6:0";
$trap = new Trap($trapText);
$message = "QoS on flow 1-1-1-3-1 modified";
\Log::shouldReceive('event')->once()->with($message, $device->device_id, 'trap', 2);
$this->assertTrue(Dispatcher::handle($trap), 'Could not handle cmAttributeValueChangeTrap QoS flow policer');
}
public function testQosShaperModified()
{
$device = factory(Device::class)->create();
$trapText = "$device->hostname
UDP: [$device->ip]:57602->[192.168.5.5]:162
DISMAN-EVENT-MIB::sysUpTimeInstance 26:19:43:37.24
SNMPv2-MIB::snmpTrapOID.0 CM-SYSTEM-MIB::cmAttributeValueChangeTrap
CM-FACILITY-MIB::cmQosShaperCIR.1.1.1.3.1.1.1 9856000
CM-FACILITY-MIB::cmQosShaperCIRHi.1.1.1.3.1.1.1 0
RMON2-MIB::probeDateTime.0 \"07 E2 0C 0A 09 2F 33 00 2D 06 00 \"
ADVA-MIB::neEventLogIndex.218 218
ADVA-MIB::neEventLogTimeStamp.218 2018-12-10,9:47:51.0,-6:0";
$trap = new Trap($trapText);
$message = "QoS on flow 1-1-1-3-1 modified";
\Log::shouldReceive('event')->once()->with($message, $device->device_id, 'trap', 2);
$this->assertTrue(Dispatcher::handle($trap), 'Could not handle cmAttributeValueChangeTrap QoS shaper');
}
public function testAccShaper()
{
$device = factory(Device::class)->create();
$trapText = "$device->hostname
UDP: [$device->ip]:57602->[192.168.5.5]:162
DISMAN-EVENT-MIB::sysUpTimeInstance 26:19:43:37.24
SNMPv2-MIB::snmpTrapOID.0 CM-SYSTEM-MIB::cmAttributeValueChangeTrap
CM-FACILITY-MIB::cmAccPortQosShaperCIRLo.1.1.1.4.1 128000
CM-FACILITY-MIB::cmAccPortQosShaperCIRHi.1.1.1.4.1 0
RMON2-MIB::probeDateTime.0 \"07 E2 0C 0A 09 07 1C 00 2D 06 00 \"
ADVA-MIB::neEventLogIndex.146 146
ADVA-MIB::neEventLogTimeStamp.146 2018-12-10,9:7:28.1,-6:0";
$trap = new Trap($trapText);
$message = "Shaper modified on access port 1-1-1-4-1 modified";
\Log::shouldReceive('event')->once()->with($message, $device->device_id, 'trap', 2);
$this->assertTrue(Dispatcher::handle($trap), 'Could not handle cmAttributeValueChangeTrap access port QoS shaper');
}
}

View File

@@ -0,0 +1,54 @@
<?php
/**
* AdvaDyingGaspTest.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 Heath Barnhart
* @author Heath Barnhart <hbarnhart@kanren.net>
*/
namespace LibreNMS\Tests\Feature\SnmpTraps;
use App\Models\Device;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use LibreNMS\Snmptrap\Dispatcher;
use LibreNMS\Snmptrap\Trap;
use LibreNMS\Tests\LaravelTestCase;
class AdvaSnmpDyingGaspTest extends LaravelTestCase
{
use DatabaseTransactions;
public function testDyingGasp()
{
$device = factory(Device::class)->create();
$trapText = "$device->hostname
UDP: [$device->ip]:57602->[192.168.5.5]:162
DISMAN-EVENT-MIB::sysUpTimeInstance 26:19:43:37.24
SNMPv2-MIB::snmpTrapOID.0 CM-SYSTEM-MIB::cmSnmpDyingGaspTrap";
$trap = new Trap($trapText);
$message = "Dying Gasp received";
\Log::shouldReceive('event')->once()->with($message, $device->device_id, 'trap', 5);
$this->assertTrue(Dispatcher::handle($trap), 'Could not handle cmSnmpDyingGaspTrap');
}
}

View File

@@ -0,0 +1,130 @@
<?php
/**
* AdvaTeholdCrossingAlertTest.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 Heath Barnhart
* @author Heath Barnhart <hbarnhart@kanren.net>
*/
namespace LibreNMS\Tests\Feature\SnmpTraps;
use App\Models\Device;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use LibreNMS\Snmptrap\Dispatcher;
use LibreNMS\Snmptrap\Trap;
use LibreNMS\Tests\LaravelTestCase;
class AdvaNetThresholdCrossingAlertTest extends LaravelTestCase
{
use DatabaseTransactions;
public function testNetThresholdTrap()
{
$device = factory(Device::class)->create();
$trapText = "$device->hostname
UDP: [$device->ip]:57602->[192.168.5.5]:162
DISMAN-EVENT-MIB::sysUpTimeInstance 26:19:43:37.24
SNMPv2-MIB::snmpTrapOID.0 CM-PERFORMANCE-MIB::cmEthernetNetPortThresholdCrossingAlert
CM-PERFORMANCE-MIB::cmEthernetNetPortThresholdIndex.1.1.1.2.1.37 37
CM-PERFORMANCE-MIB::cmEthernetNetPortThresholdInterval.1.1.1.2.1.37 interval-15min
CM-PERFORMANCE-MIB::cmEthernetNetPortThresholdVariable.1.1.1.2.1.37 CM-PERFORMANCE-MIB::cmEthernetNetPortStatsUAS.1.1.1.2.1
CM-PERFORMANCE-MIB::cmEthernetNetPortThresholdValueLo.1.1.1.2.1.37 10
CM-PERFORMANCE-MIB::cmEthernetNetPortThresholdValueHi.1.1.1.2.1.37 0
CM-PERFORMANCE-MIB::cmEthernetNetPortThresholdMonValue.1.1.1.2.1.37 10
IF-MIB::ifName.2 NETWORK PORT-1-1-1-2
RMON2-MIB::probeDateTime.0 \"07 E2 0C 0A 0B 2D 0A 00 2D 06 00 \"
ADVA-MIB::neEventLogIndex.79 79
ADVA-MIB::neEventLogTimeStamp.79 2018-12-10,11:45:10.8,-6:0";
$trap = new Trap($trapText);
$message = "NETWORK PORT-1-1-1-2 unavailable seconds threshold exceeded for interval-15min";
\Log::shouldReceive('event')->once()->with($message, $device->device_id, 'trap', 2);
$this->assertTrue(Dispatcher::handle($trap), 'Could not handle cmEthernetNetPortThresholdCrossingAlert unavailable seconds exceeded');
$trapText = "$device->hostname
UDP: [$device->ip]:57602->[192.168.5.5]:162
DISMAN-EVENT-MIB::sysUpTimeInstance 26:19:43:37.24
SNMPv2-MIB::snmpTrapOID.0 CM-PERFORMANCE-MIB::cmEthernetNetPortThresholdCrossingAlert
CM-PERFORMANCE-MIB::cmEthernetNetPortThresholdIndex.1.1.1.1.1.37 37
CM-PERFORMANCE-MIB::cmEthernetNetPortThresholdInterval.1.1.1.1.1.37 interval-15min
CM-PERFORMANCE-MIB::cmEthernetNetPortThresholdVariable.1.1.1.1.1.37 CM-PERFORMANCE-MIB::cmEthernetNetPortStatsESP1519.1.1.1.1.1
CM-PERFORMANCE-MIB::cmEthernetNetPortThresholdValueLo.1.1.1.1.1.37 10
CM-PERFORMANCE-MIB::cmEthernetNetPortThresholdValueHi.1.1.1.1.1.37 0
CM-PERFORMANCE-MIB::cmEthernetNetPortThresholdMonValue.1.1.1.1.1.37 10
IF-MIB::ifName.2 NETWORK PORT-1-1-1-1
RMON2-MIB::probeDateTime.0 \"07 E2 0C 0A 0B 2D 0A 00 2D 06 00 \"
ADVA-MIB::neEventLogIndex.79 79
ADVA-MIB::neEventLogTimeStamp.79 2018-12-10,11:45:10.8,-6:0";
$trap = new Trap($trapText);
$message = "NETWORK PORT-1-1-1-1 1519 to MTU byte octets received threshold exceeded for interval-15min";
\Log::shouldReceive('event')->once()->with($message, $device->device_id, 'trap', 2);
$this->assertTrue(Dispatcher::handle($trap), 'Could not handle cmEthernetNetPortThresholdCrossingAlert jumbo frame exceeded');
$trapText = "$device->hostname
UDP: [$device->ip]:57602->[192.168.5.5]:162
DISMAN-EVENT-MIB::sysUpTimeInstance 26:19:43:37.24
SNMPv2-MIB::snmpTrapOID.0 CM-PERFORMANCE-MIB::cmEthernetNetPortThresholdCrossingAlert
CM-PERFORMANCE-MIB::cmEthernetNetPortThresholdIndex.1.1.1.1.1.37 37
CM-PERFORMANCE-MIB::cmEthernetNetPortThresholdInterval.1.1.1.1.1.37 interval-1day
CM-PERFORMANCE-MIB::cmEthernetNetPortThresholdVariable.1.1.1.1.1.37 CM-PERFORMANCE-MIB::cmEthernetNetPortStatsAclDropNoMatch.1.1.1.1.1
CM-PERFORMANCE-MIB::cmEthernetNetPortThresholdValueLo.1.1.1.1.1.37 25
CM-PERFORMANCE-MIB::cmEthernetNetPortThresholdValueHi.1.1.1.1.1.37 0
CM-PERFORMANCE-MIB::cmEthernetNetPortThresholdMonValue.1.1.1.1.1.37 25
IF-MIB::ifName.2 NETWORK PORT-1-1-1-1
RMON2-MIB::probeDateTime.0 \"07 E2 0C 0A 0B 2D 0A 00 2D 06 00 \"
ADVA-MIB::neEventLogIndex.79 79
ADVA-MIB::neEventLogTimeStamp.79 2018-12-10,11:45:10.8,-6:0";
$trap = new Trap($trapText);
$message = "NETWORK PORT-1-1-1-1 acl drop no match threshold exceeded for interval-1day";
\Log::shouldReceive('event')->once()->with($message, $device->device_id, 'trap', 2);
$this->assertTrue(Dispatcher::handle($trap), 'Could not handle cmEthernetNetPortThresholdCrossingAlert no acl match exceeded');
$trapText = "$device->hostname
UDP: [$device->ip]:57602->[192.168.5.5]:162
DISMAN-EVENT-MIB::sysUpTimeInstance 26:19:43:37.24
SNMPv2-MIB::snmpTrapOID.0 CM-PERFORMANCE-MIB::cmEthernetNetPortThresholdCrossingAlert
CM-PERFORMANCE-MIB::cmEthernetNetPortThresholdIndex.1.1.1.1.1.37 37
CM-PERFORMANCE-MIB::cmEthernetNetPortThresholdInterval.1.1.1.1.1.37 interval-1day
CM-PERFORMANCE-MIB::cmEthernetNetPortThresholdVariable.1.1.1.1.1.37 CM-PERFORMANCE-MIB::unknownThresholdTest.1.1.1.1.1
CM-PERFORMANCE-MIB::cmEthernetNetPortThresholdValueLo.1.1.1.1.1.37 25
CM-PERFORMANCE-MIB::cmEthernetNetPortThresholdValueHi.1.1.1.1.1.37 0
CM-PERFORMANCE-MIB::cmEthernetNetPortThresholdMonValue.1.1.1.1.1.37 25
IF-MIB::ifName.2 NETWORK PORT-1-1-1-1
RMON2-MIB::probeDateTime.0 \"07 E2 0C 0A 0B 2D 0A 00 2D 06 00 \"
ADVA-MIB::neEventLogIndex.79 79
ADVA-MIB::neEventLogTimeStamp.79 2018-12-10,11:45:10.8,-6:0";
$trap = new Trap($trapText);
$message = "NETWORK PORT-1-1-1-1 unknown threshold exceeded for interval-1day";
\Log::shouldReceive('event')->once()->with($message, $device->device_id, 'trap', 2);
$this->assertTrue(Dispatcher::handle($trap), 'Could not handle cmEthernetNetPortThresholdCrossingAlert unknown exceeded');
}
}

View File

@@ -0,0 +1,165 @@
<?php
/**
* AdvaNetworkElementAlmTest.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 Heath Barnhart
* @author Heath Barnhart <hbarnhart@kanren.net>
*/
namespace LibreNMS\Tests\Feature\SnmpTraps;
use App\Models\Device;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use LibreNMS\Snmptrap\Dispatcher;
use LibreNMS\Snmptrap\Trap;
use LibreNMS\Tests\LaravelTestCase;
class AdvaNetworkElementAlmTest extends LaravelTestCase
{
use DatabaseTransactions;
public function testElementAlarmCleared()
{
$device = factory(Device::class)->create();
$trapText = "$device->hostname
UDP: [$device->ip]:57602->[192.168.5.5]:162
DISMAN-EVENT-MIB::sysUpTimeInstance 26:19:43:37.24
SNMPv2-MIB::snmpTrapOID.0 CM-ALARM-MIB::cmNetworkElementAlmTrap
CM-ALARM-MIB::cmAlmIndex.0 30
CM-ALARM-MIB::cmNetworkElementAlmNotifCode.1.30 cleared
CM-ALARM-MIB::cmNetworkElementAlmType.1.30 lnkdown
CM-ALARM-MIB::cmNetworkElementAlmSrvEff.1.30 serviceAffecting
CM-ALARM-MIB::cmNetworkElementAlmTime.1.30 2018-12-10,11:1:43.0,-6:0
CM-ALARM-MIB::cmNetworkElementAlmLocation.1.30 nearEnd
CM-ALARM-MIB::cmNetworkElementAlmDirection.1.30 receiveDirectionOnly
CM-ALARM-MIB::cmNetworkElementAlmDescr.1.30 \"Test Alarm Cleared\"
CM-ALARM-MIB::cmNetworkElementAlmObject.1.30 CM-FACILITY-MIB::cmEthernetNetPortIndex.1.1.1.2
CM-ALARM-MIB::cmNetworkElementAlmObjectName.1.30 NETWORK PORT-1-1-1-2
CM-ALARM-MIB::cmNetworkElementAlmAdditionalInfoObject.1.30 SNMPv2-SMI::zeroDotZero
CM-ALARM-MIB::cmNetworkElementAlmAdditionalInfoName.1.30
RMON2-MIB::probeDateTime.0 \"07 E2 0C 0A 0B 01 2B 00 2D 06 00 \"
ADVA-MIB::neEventLogIndex.231 231
ADVA-MIB::neEventLogTimeStamp.231 2018-12-10,11:1:43.3,-6:0";
$trap = new Trap($trapText);
$message = "Alarming Element: NETWORK PORT-1-1-1-2 Description: Test Alarm Cleared Severity: cleared";
\Log::shouldReceive('event')->once()->with($message, $device->device_id, 'trap', 1);
$this->assertTrue(Dispatcher::handle($trap), 'Could not handle cmNetworkElementAlmTrap cleared');
}
public function testElementAlarmMinor()
{
$device = factory(Device::class)->create();
$trapText = "$device->hostname
UDP: [$device->ip]:57602->[192.168.5.5]:162
DISMAN-EVENT-MIB::sysUpTimeInstance 26:19:43:37.24
SNMPv2-MIB::snmpTrapOID.0 CM-ALARM-MIB::cmNetworkElementAlmTrap
CM-ALARM-MIB::cmAlmIndex.0 30
CM-ALARM-MIB::cmNetworkElementAlmNotifCode.1.30 minor
CM-ALARM-MIB::cmNetworkElementAlmType.1.30 lnkdown
CM-ALARM-MIB::cmNetworkElementAlmSrvEff.1.30 serviceAffecting
CM-ALARM-MIB::cmNetworkElementAlmTime.1.30 2018-12-10,11:1:43.0,-6:0
CM-ALARM-MIB::cmNetworkElementAlmLocation.1.30 nearEnd
CM-ALARM-MIB::cmNetworkElementAlmDirection.1.30 receiveDirectionOnly
CM-ALARM-MIB::cmNetworkElementAlmDescr.1.30 \"Test Alarm Minor\"
CM-ALARM-MIB::cmNetworkElementAlmObject.1.30 CM-FACILITY-MIB::cmEthernetNetPortIndex.1.1.1.2
CM-ALARM-MIB::cmNetworkElementAlmObjectName.1.30 NETWORK PORT-1-1-1-2
CM-ALARM-MIB::cmNetworkElementAlmAdditionalInfoObject.1.30 SNMPv2-SMI::zeroDotZero
CM-ALARM-MIB::cmNetworkElementAlmAdditionalInfoName.1.30
RMON2-MIB::probeDateTime.0 \"07 E2 0C 0A 0B 01 2B 00 2D 06 00 \"
ADVA-MIB::neEventLogIndex.231 231
ADVA-MIB::neEventLogTimeStamp.231 2018-12-10,11:1:43.3,-6:0";
$trap = new Trap($trapText);
$message = "Alarming Element: NETWORK PORT-1-1-1-2 Description: Test Alarm Minor Severity: minor";
\Log::shouldReceive('event')->once()->with($message, $device->device_id, 'trap', 3);
$this->assertTrue(Dispatcher::handle($trap), 'Could not handle cmNetworkElementAlmTrap minor');
}
public function testElementAlarmMajor()
{
$device = factory(Device::class)->create();
$trapText = "$device->hostname
UDP: [$device->ip]:57602->[192.168.5.5]:162
DISMAN-EVENT-MIB::sysUpTimeInstance 26:19:43:37.24
SNMPv2-MIB::snmpTrapOID.0 CM-ALARM-MIB::cmNetworkElementAlmTrap
CM-ALARM-MIB::cmAlmIndex.0 30
CM-ALARM-MIB::cmNetworkElementAlmNotifCode.1.30 major
CM-ALARM-MIB::cmNetworkElementAlmType.1.30 lnkdown
CM-ALARM-MIB::cmNetworkElementAlmSrvEff.1.30 serviceAffecting
CM-ALARM-MIB::cmNetworkElementAlmTime.1.30 2018-12-10,11:1:43.0,-6:0
CM-ALARM-MIB::cmNetworkElementAlmLocation.1.30 nearEnd
CM-ALARM-MIB::cmNetworkElementAlmDirection.1.30 receiveDirectionOnly
CM-ALARM-MIB::cmNetworkElementAlmDescr.1.30 \"Test Alarm Major\"
CM-ALARM-MIB::cmNetworkElementAlmObject.1.30 CM-FACILITY-MIB::cmEthernetNetPortIndex.1.1.1.2
CM-ALARM-MIB::cmNetworkElementAlmObjectName.1.30 NETWORK PORT-1-1-1-2
CM-ALARM-MIB::cmNetworkElementAlmAdditionalInfoObject.1.30 SNMPv2-SMI::zeroDotZero
CM-ALARM-MIB::cmNetworkElementAlmAdditionalInfoName.1.30
RMON2-MIB::probeDateTime.0 \"07 E2 0C 0A 0B 01 2B 00 2D 06 00 \"
ADVA-MIB::neEventLogIndex.231 231
ADVA-MIB::neEventLogTimeStamp.231 2018-12-10,11:1:43.3,-6:0";
$trap = new Trap($trapText);
$message = "Alarming Element: NETWORK PORT-1-1-1-2 Description: Test Alarm Major Severity: major";
\Log::shouldReceive('event')->once()->with($message, $device->device_id, 'trap', 4);
$this->assertTrue(Dispatcher::handle($trap), 'Could not handle cmNetworkElementAlmTrap major');
}
public function testElementAlarmCritical()
{
$device = factory(Device::class)->create();
$trapText = "$device->hostname
UDP: [$device->ip]:57602->[192.168.5.5]:162
DISMAN-EVENT-MIB::sysUpTimeInstance 26:19:43:37.24
SNMPv2-MIB::snmpTrapOID.0 CM-ALARM-MIB::cmNetworkElementAlmTrap
CM-ALARM-MIB::cmAlmIndex.0 30
CM-ALARM-MIB::cmNetworkElementAlmNotifCode.1.30 critical
CM-ALARM-MIB::cmNetworkElementAlmType.1.30 lnkdown
CM-ALARM-MIB::cmNetworkElementAlmSrvEff.1.30 serviceAffecting
CM-ALARM-MIB::cmNetworkElementAlmTime.1.30 2018-12-10,11:1:43.0,-6:0
CM-ALARM-MIB::cmNetworkElementAlmLocation.1.30 nearEnd
CM-ALARM-MIB::cmNetworkElementAlmDirection.1.30 receiveDirectionOnly
CM-ALARM-MIB::cmNetworkElementAlmDescr.1.30 \"Test Alarm Critical\"
CM-ALARM-MIB::cmNetworkElementAlmObject.1.30 CM-FACILITY-MIB::cmEthernetNetPortIndex.1.1.1.2
CM-ALARM-MIB::cmNetworkElementAlmObjectName.1.30 NETWORK PORT-1-1-1-2
CM-ALARM-MIB::cmNetworkElementAlmAdditionalInfoObject.1.30 SNMPv2-SMI::zeroDotZero
CM-ALARM-MIB::cmNetworkElementAlmAdditionalInfoName.1.30
RMON2-MIB::probeDateTime.0 \"07 E2 0C 0A 0B 01 2B 00 2D 06 00 \"
ADVA-MIB::neEventLogIndex.231 231
ADVA-MIB::neEventLogTimeStamp.231 2018-12-10,11:1:43.3,-6:0";
$trap = new Trap($trapText);
$message = "Alarming Element: NETWORK PORT-1-1-1-2 Description: Test Alarm Critical Severity: critical";
\Log::shouldReceive('event')->once()->with($message, $device->device_id, 'trap', 5);
$this->assertTrue(Dispatcher::handle($trap), 'Could not handle cmNetworkElementAlmTrap critical');
}
}

View File

@@ -0,0 +1,92 @@
<?php
/**
* AdvaObjectCreationTest.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 Heath Barnhart
* @author Heath Barnhart <hbarnhart@kanren.net>
*/
namespace LibreNMS\Tests\Feature\SnmpTraps;
use App\Models\Device;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use LibreNMS\Snmptrap\Dispatcher;
use LibreNMS\Snmptrap\Trap;
use LibreNMS\Tests\LaravelTestCase;
class AdvaObjectCreationTest extends LaravelTestCase
{
use DatabaseTransactions;
public function testUserCreation()
{
$device = factory(Device::class)->create();
$trapText = "$device->hostname
UDP: [$device->ip]:57602->[192.168.5.5]:162
DISMAN-EVENT-MIB::sysUpTimeInstance 26:19:43:37.24
SNMPv2-MIB::snmpTrapOID.0 CM-SYSTEM-MIB::cmObjectCreationTrap
CM-SECURITY-MIB::cmSecurityUserPrivLevel.\"testuser\".false superuser
CM-SECURITY-MIB::cmSecurityUserLoginTimeout.\"testuser\".false 15
CM-SECURITY-MIB::cmSecurityUserName.\"testuser\".false testuser
CM-SECURITY-MIB::cmSecurityUserComment.\"testuser\".false Remote User
RMON2-MIB::probeDateTime.0 \"07 E2 0C 0A 08 37 29 00 2D 06 00 \"
ADVA-MIB::neEventLogIndex.91 91
ADVA-MIB::neEventLogTimeStamp.91 2018-12-10,8:55:41.1,-6:0";
$trap = new Trap($trapText);
$message = "User object testuser created";
\Log::shouldReceive('event')->once()->with($message, $device->device_id, 'trap', 2);
$this->assertTrue(Dispatcher::handle($trap), 'Could not handle cmObjectCreationTrap user created');
}
public function testLagCreation()
{
$device = factory(Device::class)->create();
$trapText = "$device->hostname
UDP: [$device->ip]:57602->[192.168.5.5]:162
DISMAN-EVENT-MIB::sysUpTimeInstance 26:19:43:37.24
SNMPv2-MIB::snmpTrapOID.0 CM-SYSTEM-MIB::cmObjectCreationTrap
IEEE8023-LAG-MIB::dot3adAggCollectorMaxDelay.9 50
IEEE8023-LAG-MIB::dot3adAggActorSystemPriority.9 32768
IEEE8023-LAG-MIB::dot3adAggActorAdminKey.9 32768
F3-LAG-MIB::f3LagProtocols.1.1 true
F3-LAG-MIB::f3LagDiscardWrongConversation.1.1 false
F3-LAG-MIB::f3LagFrameDistAlgorithm.1.1 activeStandby
F3-LAG-MIB::f3LagMode.1.1 active-standby
F3-LAG-MIB::f3LagLacpControl.1.1 true
F3-LAG-MIB::f3LagCcmDefectsDetectionEnabled.1.1 false
F3-LAG-MIB::f3LagName.1.1
F3-LAG-MIB::f3LagEntry.14.1.1 \"B0 00 \"
RMON2-MIB::probeDateTime.0 \"07 E2 0C 0A 08 3A 2B 00 2D 06 00 \"
ADVA-MIB::neEventLogIndex.110 110
ADVA-MIB::neEventLogTimeStamp.110 2018-12-10,8:58:43.7,-6:0";
$trap = new Trap($trapText);
$message = "LAG 1 created";
\Log::shouldReceive('event')->once()->with($message, $device->device_id, 'trap', 2);
$this->assertTrue(Dispatcher::handle($trap), 'Could not handle cmObjectCreationTrap LAG created');
}
}

View File

@@ -0,0 +1,121 @@
<?php
/**
* AdvaObjectDeletionTest.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 Heath Barnhart
* @author Heath Barnhart <hbarnhart@kanren.net>
*/
namespace LibreNMS\Tests\Feature\SnmpTraps;
use App\Models\Device;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use LibreNMS\Snmptrap\Dispatcher;
use LibreNMS\Snmptrap\Trap;
use LibreNMS\Tests\LaravelTestCase;
class AdvaObjectDeletionTest extends LaravelTestCase
{
use DatabaseTransactions;
public function testUserDeletion()
{
$device = factory(Device::class)->create();
$trapText = "$device->hostname
UDP: [$device->ip]:57602->[192.168.5.5]:162
DISMAN-EVENT-MIB::sysUpTimeInstance 26:19:43:37.24
SNMPv2-MIB::snmpTrapOID.0 CM-SYSTEM-MIB::cmObjectDeletionTrap
CM-SECURITY-MIB::cmSecurityUserName.\"testuser\".false testuser
RMON2-MIB::probeDateTime.0 \"07 E2 0C 0A 08 38 1B 00 2D 06 00 \"
ADVA-MIB::neEventLogIndex.92 92
ADVA-MIB::neEventLogTimeStamp.92 2018-12-10,8:56:27.5,-6:0";
$trap = new Trap($trapText);
$message = "User object testuser deleted";
\Log::shouldReceive('event')->once()->with($message, $device->device_id, 'trap', 2);
$this->assertTrue(Dispatcher::handle($trap), 'Could not handle cmObjectDeletionTrap user deletion');
}
public function testFLowDeletion()
{
$device = factory(Device::class)->create();
$trapText = "$device->hostname
UDP: [$device->ip]:57602->[192.168.5.5]:162
DISMAN-EVENT-MIB::sysUpTimeInstance 26:19:43:37.24
SNMPv2-MIB::snmpTrapOID.0 CM-SYSTEM-MIB::cmObjectDeletionTrap
CM-FACILITY-MIB::cmFlowIndex.1.1.1.4.1 1
RMON2-MIB::probeDateTime.0 \"07 E2 0C 0A 09 07 1C 00 2D 06 00 \"
ADVA-MIB::neEventLogIndex.148 148
ADVA-MIB::neEventLogTimeStamp.148 2018-12-10,9:7:28.1,-6:0";
$trap = new Trap($trapText);
$message = "Flow 1-1-1-4-1 deleted";
\Log::shouldReceive('event')->once()->with($message, $device->device_id, 'trap', 2);
$this->assertTrue(Dispatcher::handle($trap), 'Could not handle cmObjectDeletionTrap flow deletion');
}
public function testLagPortDeletion()
{
$device = factory(Device::class)->create();
$trapText = "$device->hostname
UDP: [$device->ip]:57602->[192.168.5.5]:162
DISMAN-EVENT-MIB::sysUpTimeInstance 26:19:43:37.24
SNMPv2-MIB::snmpTrapOID.0 CM-SYSTEM-MIB::cmObjectDeletionTrap
F3-LAG-MIB::f3LagPortIndex.1.1.1 1
RMON2-MIB::probeDateTime.0 \"07 E2 0C 0A 09 03 33 00 2D 06 00 \"
ADVA-MIB::neEventLogIndex.136 136
ADVA-MIB::neEventLogTimeStamp.136 2018-12-10,9:3:51.3,-6:0";
$trap = new Trap($trapText);
$message = "LAG member port 1 removed from LAG 1-1";
\Log::shouldReceive('event')->once()->with($message, $device->device_id, 'trap', 2);
$this->assertTrue(Dispatcher::handle($trap), 'Could not handle cmObjectDeletionTrap LAG port deletion');
}
public function testLagDeletion()
{
$device = factory(Device::class)->create();
$trapText = "$device->hostname
UDP: [$device->ip]:57602->[192.168.5.5]:162
DISMAN-EVENT-MIB::sysUpTimeInstance 26:19:43:37.24
SNMPv2-MIB::snmpTrapOID.0 CM-SYSTEM-MIB::cmObjectDeletionTrap
F3-LAG-MIB::f3LagIndex.1.1 1
RMON2-MIB::probeDateTime.0 \"07 E2 0C 0A 09 03 33 00 2D 06 00 \"
ADVA-MIB::neEventLogIndex.139 139
ADVA-MIB::neEventLogTimeStamp.139 2018-12-10,9:3:51.4,-6:0";
$trap = new Trap($trapText);
$message = "LAG 1 deleted";
\Log::shouldReceive('event')->once()->with($message, $device->device_id, 'trap', 2);
$this->assertTrue(Dispatcher::handle($trap), 'Could not handle cmObjectDeletionTrap LAG deletion');
}
}

View File

@@ -0,0 +1,108 @@
<?php
/**
* AdvaStateChangeTrapTest.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 Heath Barnhart
* @author Heath Barnhart <hbarnhart@kanren.net>
*/
namespace LibreNMS\Tests\Feature\SnmpTraps;
use App\Models\Device;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use LibreNMS\Snmptrap\Trap;
use LibreNMS\Snmptrap\Dispatcher;
use LibreNMS\Tests\LaravelTestCase;
class AdvaStateChangeTrapTest extends LaravelTestCase
{
use DatabaseTransactions;
public function testAccessPortChg()
{
$device = factory(Device::class)->create();
$trapText = "$device->hostname
UDP: [$device->ip]:57602->[192.168.5.5]:162
DISMAN-EVENT-MIB::sysUpTimeInstance 0:0:15:22.68
SNMPv2-MIB::snmpTrapOID.0 CM-SYSTEM-MIB::cmStateChangeTrap
CM-FACILITY-MIB::cmEthernetAccPortAdminState.1.1.1.3 maintenance
CM-FACILITY-MIB::cmEthernetAccPortOperationalState.1.1.1.3 normal
CM-FACILITY-MIB::cmEthernetAccPortSecondaryState.1.1.1.3 \"42 00 00 \"
IF-MIB::ifName.3 ACCESS PORT-1-1-1-3
RMON2-MIB::probeDateTime.0 \"07 E2 0C 0A 0B 14 28 00 2D 06 00 \"
ADVA-MIB::neEventLogIndex.48 48
ADVA-MIB::neEventLogTimeStamp.48 2018-12-10,11:20:40.7,-6:0";
$trap = new Trap($trapText);
$message = 'Port state change: ACCESS PORT-1-1-1-3 Admin State: maintenance Operational State: normal';
\Log::shouldReceive('event')->once()->with($message, $device->device_id, 'trap', 2);
$this->assertTrue(Dispatcher::handle($trap), 'Could not handle cmStateChangeTrap access port amdmin state maintenance and op state normal');
}
public function testNetworkPortChg()
{
$device = factory(Device::class)->create();
$trapText = "$device->hostname
UDP: [$device->ip]:57602->[192.168.5.5]:162
DISMAN-EVENT-MIB::sysUpTimeInstance 0:0:15:22.68
SNMPv2-MIB::snmpTrapOID.0 CM-SYSTEM-MIB::cmStateChangeTrap
CM-FACILITY-MIB::cmEthernetNetPortAdminState.1.1.1.2 maintenance
CM-FACILITY-MIB::cmEthernetNetPortOperationalState.1.1.1.2 outage
CM-FACILITY-MIB::cmEthernetNetPortSecondaryState.1.1.1.2 \"52 00 00 \"
IF-MIB::ifName.2 NETWORK PORT-1-1-1-2
RMON2-MIB::probeDateTime.0 \"07 E2 0C 0A 0B 11 07 00 2D 06 00 \"
ADVA-MIB::neEventLogIndex.19 19
ADVA-MIB::neEventLogTimeStamp.19 2018-12-10,11:17:7.9,-6:0";
$trap = new Trap($trapText);
$message = 'Port state change: NETWORK PORT-1-1-1-2 Admin State: maintenance Operational State: outage';
\Log::shouldReceive('event')->once()->with($message, $device->device_id, 'trap', 2);
$this->assertTrue(Dispatcher::handle($trap), 'Could not handle cmStateChangeTrap access port amdmin state maintenance and op state normal');
}
public function testFlowStateChg()
{
$device = factory(Device::class)->create();
$trapText = "$device->hostname
UDP: [$device->ip]:57602->[192.168.5.5]:162
DISMAN-EVENT-MIB::sysUpTimeInstance 0:0:15:22.68
SNMPv2-MIB::snmpTrapOID.0 CM-SYSTEM-MIB::cmStateChangeTrap
CM-FACILITY-MIB::cmFlowAdminState.1.1.1.3.1 management
CM-FACILITY-MIB::cmFlowOperationalState.1.1.1.3.1 normal
CM-FACILITY-MIB::cmFlowSecondaryState.1.1.1.3.1 \"40 00 00 \"
RMON2-MIB::probeDateTime.0 \"07 E2 0C 0A 0B 14 28 00 2D 06 00 \"
ADVA-MIB::neEventLogIndex.50 50
ADVA-MIB::neEventLogTimeStamp.50 2018-12-10,11:20:40.8,-6:0";
$trap = new Trap($trapText);
$message = 'Flow state change: 1-1-1-3-1 Admin State: management Operational State: normal';
\Log::shouldReceive('event')->once()->with($message, $device->device_id, 'trap', 2);
$this->assertTrue(Dispatcher::handle($trap), 'Could not handle cmStateChangeTrap access port amdmin state maintenance and op state normal');
}
}

View File

@@ -0,0 +1,137 @@
<?php
/**
* AdvaSysAlmTrapest.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 Heath Barnhart
* @author Heath Barnhart <hbarnhart@kanren.net>
*/
namespace LibreNMS\Tests\Feature\SnmpTraps;
use App\Models\Device;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use LibreNMS\Snmptrap\Dispatcher;
use LibreNMS\Snmptrap\Trap;
use LibreNMS\Tests\LaravelTestCase;
class AdvaSysAlmTrapTest extends LaravelTestCase
{
use DatabaseTransactions;
public function testCriticalAlarm()
{
$device = factory(Device::class)->create();
$trapText = "$device->hostname
UDP: [$device->ip]:57602->[192.168.5.5]:162
DISMAN-EVENT-MIB::sysUpTimeInstance 0:0:15:22.68
SNMPv2-MIB::snmpTrapOID.0 CM-ALARM-MIB::cmSysAlmTrap
CM-ALARM-MIB::cmAlmIndex.5 5
CM-ALARM-MIB::cmSysAlmNotifCode.5 critical
CM-ALARM-MIB::cmSysAlmType.5 primntpsvrFailed
CM-ALARM-MIB::cmSysAlmSrvEff.5 nonServiceAffecting
CM-ALARM-MIB::cmSysAlmTime.5 2018-12-10,11:28:20.0,-6:0
CM-ALARM-MIB::cmSysAlmLocation.5 nearEnd
CM-ALARM-MIB::cmSysAlmDirection.5 receiveDirectionOnly
CM-ALARM-MIB::cmSysAlmDescr.5 \"Critical alarm test\"";
$trap = new Trap($trapText);
$message = "System Alarm: Critical alarm test Status: critical";
\Log::shouldReceive('event')->once()->with($message, $device->device_id, 'trap', 5);
$this->assertTrue(Dispatcher::handle($trap), 'Could not handle cmSysAlmTrap critical');
}
public function testMajorAlarm()
{
$device = factory(Device::class)->create();
$trapText = "$device->hostname
UDP: [$device->ip]:57602->[192.168.5.5]:162
DISMAN-EVENT-MIB::sysUpTimeInstance 0:0:15:22.68
SNMPv2-MIB::snmpTrapOID.0 CM-ALARM-MIB::cmSysAlmTrap
CM-ALARM-MIB::cmAlmIndex.5 5
CM-ALARM-MIB::cmSysAlmNotifCode.5 major
CM-ALARM-MIB::cmSysAlmType.5 primntpsvrFailed
CM-ALARM-MIB::cmSysAlmSrvEff.5 nonServiceAffecting
CM-ALARM-MIB::cmSysAlmTime.5 2018-12-10,11:28:20.0,-6:0
CM-ALARM-MIB::cmSysAlmLocation.5 nearEnd
CM-ALARM-MIB::cmSysAlmDirection.5 receiveDirectionOnly
CM-ALARM-MIB::cmSysAlmDescr.5 \"Major alarm test\"";
$trap = new Trap($trapText);
$message = "System Alarm: Major alarm test Status: major";
\Log::shouldReceive('event')->once()->with($message, $device->device_id, 'trap', 4);
$this->assertTrue(Dispatcher::handle($trap), 'Could not handle cmSysAlmTrap major');
}
public function testMinorAlarm()
{
$device = factory(Device::class)->create();
$trapText = "$device->hostname
UDP: [$device->ip]:57602->[192.168.5.5]:162
DISMAN-EVENT-MIB::sysUpTimeInstance 0:0:15:22.68
SNMPv2-MIB::snmpTrapOID.0 CM-ALARM-MIB::cmSysAlmTrap
CM-ALARM-MIB::cmAlmIndex.5 5
CM-ALARM-MIB::cmSysAlmNotifCode.5 minor
CM-ALARM-MIB::cmSysAlmType.5 primntpsvrFailed
CM-ALARM-MIB::cmSysAlmSrvEff.5 nonServiceAffecting
CM-ALARM-MIB::cmSysAlmTime.5 2018-12-10,11:28:20.0,-6:0
CM-ALARM-MIB::cmSysAlmLocation.5 nearEnd
CM-ALARM-MIB::cmSysAlmDirection.5 receiveDirectionOnly
CM-ALARM-MIB::cmSysAlmDescr.5 \"Minor alarm test\"";
$trap = new Trap($trapText);
$message = "System Alarm: Minor alarm test Status: minor";
\Log::shouldReceive('event')->once()->with($message, $device->device_id, 'trap', 3);
$this->assertTrue(Dispatcher::handle($trap), 'Could not handle cmSysAlmTrap minor');
}
public function testClearedAlarm()
{
$device = factory(Device::class)->create();
$trapText = "$device->hostname
UDP: [$device->ip]:57602->[192.168.5.5]:162
DISMAN-EVENT-MIB::sysUpTimeInstance 0:0:15:22.68
SNMPv2-MIB::snmpTrapOID.0 CM-ALARM-MIB::cmSysAlmTrap
CM-ALARM-MIB::cmAlmIndex.5 5
CM-ALARM-MIB::cmSysAlmNotifCode.5 cleared
CM-ALARM-MIB::cmSysAlmType.5 primntpsvrFailed
CM-ALARM-MIB::cmSysAlmSrvEff.5 nonServiceAffecting
CM-ALARM-MIB::cmSysAlmTime.5 2018-12-10,11:28:20.0,-6:0
CM-ALARM-MIB::cmSysAlmLocation.5 nearEnd
CM-ALARM-MIB::cmSysAlmDirection.5 receiveDirectionOnly
CM-ALARM-MIB::cmSysAlmDescr.5 \"Cleared alarm test\"";
$trap = new Trap($trapText);
$message = "System Alarm: Cleared alarm test Status: cleared";
\Log::shouldReceive('event')->once()->with($message, $device->device_id, 'trap', 1);
$this->assertTrue(Dispatcher::handle($trap), 'Could not handle cmSysAlmTrap major');
}
}