diff --git a/LibreNMS/Snmptrap/Handlers/WarmBoot.php b/LibreNMS/Snmptrap/Handlers/WarmBoot.php new file mode 100644 index 0000000000..64cac44bab --- /dev/null +++ b/LibreNMS/Snmptrap/Handlers/WarmBoot.php @@ -0,0 +1,45 @@ +. + * + * @package LibreNMS + * @link http://librenms.org + */ + +namespace LibreNMS\Snmptrap\Handlers; + +use App\Models\Device; +use LibreNMS\Interfaces\SnmptrapHandler; +use LibreNMS\Snmptrap\Trap; +use Log; + +class WarmBoot 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('SNMP Trap: Device ' . $device->displayName() . ' warm booted', $device->device_id, 'reboot', 4); + } +} diff --git a/config/snmptraps.php b/config/snmptraps.php index 8723eb57db..62b9496b14 100644 --- a/config/snmptraps.php +++ b/config/snmptraps.php @@ -93,6 +93,7 @@ return [ 'RUCKUS-SZ-EVENT-MIB::ruckusSZClusterBackToInServiceTrap' => \LibreNMS\Snmptrap\Handlers\RuckusSzClusterInService::class, 'SNMPv2-MIB::authenticationFailure' => \LibreNMS\Snmptrap\Handlers\AuthenticationFailure::class, 'SNMPv2-MIB::coldStart' => \LibreNMS\Snmptrap\Handlers\ColdBoot::class, + 'SNMPv2-MIB::warmStart' => \LibreNMS\Snmptrap\Handlers\WarmBoot::class, 'VMWARE-VMINFO-MIB::vmwVmHBDetected' => \LibreNMS\Snmptrap\Handlers\VmwVmHBDetected::class, 'VMWARE-VMINFO-MIB::vmwVmHBLost' => \LibreNMS\Snmptrap\Handlers\VmwVmHBLost::class, 'VMWARE-VMINFO-MIB::vmwVmPoweredOn' => \LibreNMS\Snmptrap\Handlers\VmwVmPoweredOn::class, diff --git a/tests/Feature/SnmpTraps/CommonTrapTest.php b/tests/Feature/SnmpTraps/CommonTrapTest.php index 448f1f287e..4d6f99a745 100644 --- a/tests/Feature/SnmpTraps/CommonTrapTest.php +++ b/tests/Feature/SnmpTraps/CommonTrapTest.php @@ -163,6 +163,23 @@ SNMPv2-MIB::snmpTrapOID.0 SNMPv2-MIB::coldStart"; $this->assertEquals($device->hostname, $trap->getDevice()->hostname); } + public function testWarmStart() + { + $device = factory(Device::class)->create(); + + $trapText = "$device->hostname +UDP: [$device->ip]:44298->[192.168.5.5]:162 +DISMAN-EVENT-MIB::sysUpTimeInstance 0:0:2:12.7 +SNMPv2-MIB::snmpTrapOID.0 SNMPv2-MIB::warmStart"; + + Log::shouldReceive('event')->once()->with('SNMP Trap: Device ' . $device->displayName() . ' warm booted', $device->device_id, 'reboot', 4); + + $trap = new Trap($trapText); + $this->assertTrue(Dispatcher::handle($trap)); + + // check that the device was found + $this->assertEquals($device->hostname, $trap->getDevice()->hostname); + } public function testEntityDatabaseChanged() {