librenms-librenms/tests/Feature/SnmpTraps/JnxDomLaneAlarmTest.php
h-barnhart 554e22d927 Juniper SNMP Trap Handlers (#10136)
* initial commit of junos handlers

* added DOM alarm test, refactored handlers for DOM alarms

* fixed some formating issues with last commit

* Created DOM alarm handlers and unit tests

* Made tests for LSP Down handler

* Added trap tests for JnxVpnSes*, JnxVpnIf*, JnxVpnPw*

* Added BGP4 trap handlers and tests

* Fixed some variable names for codeclimate

* Simplified JnxBGPM2* handlers

* updated unit tests
2019-05-01 11:12:51 -05:00

91 lines
3.8 KiB
PHP

<?php
/**
* JnxDomLaneAlarmTest.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/>.
*
*
* Tests JnxDomAlertSet and JnxDomAlertCleared traps from Juniper devices.
*
* @package LibreNMS
* @link http://librenms.org
* @copyright 2019 KanREN, Inc
* @author Heath Barnhart <hbarnhart@kanren.net>
*/
namespace LibreNMS\Tests;
use App\Models\Device;
use App\Models\Port;
use LibreNMS\Snmptrap\Dispatcher;
use LibreNMS\Snmptrap\Trap;
use Log;
class JnxDomLaneAlarmTest extends LaravelTestCase
{
public function testJnxDomLaneAlarmSetTrap()
{
$device = factory(Device::class)->create();
$port = factory(Port::class)->make(['ifAdminStatus' => 'up', 'ifOperStatus' => 'up']);
$device->ports()->save($port);
$trapText = "$device->hostname
UDP: [$device->ip]:64610->[192.168.5.5]:162
DISMAN-EVENT-MIB::sysUpTimeInstance 198:2:10:48.91
SNMPv2-MIB::snmpTrapOID.0 JUNIPER-DOM-MIB::jnxDomLaneAlarmSet
IF-MIB::ifDescr.$port->ifIndex $port->ifDescr
JUNIPER-DOM-MIB::jnxDomLaneIndex.$port->ifIndex 0
JUNIPER-DOM-MIB::jnxDomLaneLastAlarms.$port->ifIndex \"00 00 00 \"
JUNIPER-DOM-MIB::jnxDomCurrentLaneAlarms.$port->ifIndex \"40 00 00 \"
JUNIPER-DOM-MIB::jnxDomCurrentLaneAlarmDate.$port->ifIndex 2019-4-10,0:9:35.0,-5:0
SNMPv2-MIB::snmpTrapEnterprise.0 JUNIPER-CHASSIS-DEFINES-MIB::jnxProductNameMX960";
\Log::shouldReceive('warning')->never()->with("Snmptrap JnxDomLaneAlarmSet: Could not find port at ifIndex $port->ifIndex for device: $device->hostname");
$trap = new Trap($trapText);
$message = "DOM lane alarm on interface $port->ifDescr lane 0. Current alarm(s): input signal low";
\Log::shouldReceive('event')->once()->with($message, $device->device_id, 'trap', 5);
$this->assertTrue(Dispatcher::handle($trap), 'Could not handle JnxDomLaneAlarmSet');
}
public function testJnxDomLaneAlarmClearedTrap()
{
$device = factory(Device::class)->create();
$port = factory(Port::class)->make(['ifAdminStatus' => 'up', 'ifOperStatus' => 'up']);
$device->ports()->save($port);
$trapText = "$device->hostname
UDP: [$device->ip]:64610->[192.168.5.5]:162
DISMAN-EVENT-MIB::sysUpTimeInstance 198:2:10:48.91
SNMPv2-MIB::snmpTrapOID.0 JUNIPER-DOM-MIB::jnxDomLaneAlarmCleared
IF-MIB::ifDescr.$port->ifIndex $port->ifDescr
JUNIPER-DOM-MIB::jnxDomLaneIndex.$port->ifIndex 0
JUNIPER-DOM-MIB::jnxDomLaneLastAlarms.$port->ifIndex \"00 00 00 \"
JUNIPER-DOM-MIB::jnxDomCurrentLaneAlarms.$port->ifIndex \"08 00 00 \"
JUNIPER-DOM-MIB::jnxDomCurrentLaneAlarmDate.$port->ifIndex 2019-4-10,0:9:35.0,-5:0
SNMPv2-MIB::snmpTrapEnterprise.0 JUNIPER-CHASSIS-DEFINES-MIB::jnxProductNameMX960";
\Log::shouldReceive('warning')->never()->with("Snmptrap JnxDomLaneAlarmCleared: Could not find port at ifIndex $port->ifIndex for device: $device->hostname");
$trap = new Trap($trapText);
$message = "DOM lane alarm cleared on interface $port->ifDescr lane 0. Current alarm(s): output signal high";
\Log::shouldReceive('event')->once()->with($message, $device->device_id, 'trap', 1);
$this->assertTrue(Dispatcher::handle($trap), 'Could not handle JnxDomLaneAlarmCleared');
}
}