Adds Cisco DHCP Server SNMP MIB and Trap Handlers. (#14618)

* Adds API call to update port notes on devices.

* Adds Cisco IETF-DHCP Server MIB and Trap Handlers.

* Updates local permissions changed.

* Linting cleanup.

* Moves test to a single file. Updates the args to match the status.

* Fixes tests failing for Cisco DHCP server SNMP traps.
This commit is contained in:
Josh Silvas 2022-11-18 00:15:42 -06:00 committed by GitHub
parent e4b5f18d0f
commit 4107b37b9d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 1693 additions and 0 deletions

View File

@ -0,0 +1,53 @@
<?php
/**
* CiscoDHCPServerFreeAddressHigh.php
*
* Logs an event when the number of available IP addresses for a DHCP
* address pool is above the defined high threshold. Configurable
* by issuing the `utilization mark low <percent>` on the DHCP pool in
* configuration mode.
*
* 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 <https://www.gnu.org/licenses/>.
*
* @link https://www.librenms.org
*
* @copyright 2022 Josh Silvas
* @author Josh Silvas <josh@jsilvas.com>
*/
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
class CiscoDHCPServerFreeAddressHigh 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)
{
$oid_prefix = 'CISCO-IETF-DHCP-SERVER-MIB::cDhcpv4ServerSharedNetFreeAddresses.';
$oid = $trap->findOid($oid_prefix);
$pool = str_replace($oid_prefix, '', $oid);
$value = $trap->getOidData($oid);
$trap->log("SNMP Trap: DHCP pool $pool address space high. Free addresses: '$value' addresses.", 2);
}
}

View File

@ -0,0 +1,53 @@
<?php
/**
* CiscoDHCPServerFreeAddressLow.php
*
* Logs an event when the number of available IP addresses for a DHCP
* address pool has fallen below the defined low threshold. Configurable
* by issuing the `utilization mark high <percent>` on the DHCP pool in
* configuration mode.
*
* 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 <https://www.gnu.org/licenses/>.
*
* @link https://www.librenms.org
*
* @copyright 2022 Josh Silvas
* @author Josh Silvas <josh@jsilvas.com>
*/
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
class CiscoDHCPServerFreeAddressLow 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)
{
$oid_prefix = 'CISCO-IETF-DHCP-SERVER-MIB::cDhcpv4ServerSharedNetFreeAddresses.';
$oid = $trap->findOid($oid_prefix);
$pool = str_replace($oid_prefix, '', $oid);
$value = $trap->getOidData($oid);
$trap->log("SNMP Trap: DHCP pool $pool address space low. Free addresses: '$value' addresses.", 5);
}
}

View File

@ -0,0 +1,46 @@
<?php
/**
* CiscoDHCPServerStart.php
*
* Logs a LibreNMS event message when a Cisco device running dhcp-server starts.
*
* 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 <https://www.gnu.org/licenses/>.
*
* @link https://www.librenms.org
*
* @copyright 2022 Josh Silvas
* @author Josh Silvas <josh@jsilvas.com>
*/
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
class CiscoDHCPServerStart 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)
{
$trap->log('SNMP Trap: Device DHCP service started.', 2);
}
}

View File

@ -0,0 +1,46 @@
<?php
/**
* CiscoDHCPServerStop.php
*
* Logs a LibreNMS event message when a Cisco device running dhcp-server stops.
*
* 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 <https://www.gnu.org/licenses/>.
*
* @link https://www.librenms.org
*
* @copyright 2022 Josh Silvas
* @author Josh Silvas <josh@jsilvas.com>
*/
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
class CiscoDHCPServerStop 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)
{
$trap->log('SNMP Trap: Device DHCP service stopped.', 5);
}
}

View File

@ -30,6 +30,10 @@ return [
'BRIDGE-MIB::topologyChange' => \LibreNMS\Snmptrap\Handlers\BridgeTopologyChanged::class,
'CISCO-PORT-SECURITY-MIB::cpsSecureMacAddrViolation' => \LibreNMS\Snmptrap\Handlers\CiscoMacViolation::class,
'CISCO-ERR-DISABLE-MIB::cErrDisableInterfaceEventRev1' => \LibreNMS\Snmptrap\Handlers\CiscoErrDisableInterfaceEvent::class,
'CISCO-IETF-DHCP-SERVER-MIB::cDhcpv4ServerStartTime' => \LibreNMS\Snmptrap\Handlers\CiscoDHCPServerStart::class,
'CISCO-IETF-DHCP-SERVER-MIB::cDhcpv4ServerStopTime' => \LibreNMS\Snmptrap\Handlers\CiscoDHCPServerStop::class,
'CISCO-IETF-DHCP-SERVER-MIB::cDhcpv4ServerFreeAddressLow' => \LibreNMS\Snmptrap\Handlers\CiscoDHCPServerFreeAddressLow::class,
'CISCO-IETF-DHCP-SERVER-MIB::cDhcpv4ServerFreeAddressHigh' => \LibreNMS\Snmptrap\Handlers\CiscoDHCPServerFreeAddressHigh::class,
'CM-ALARM-MIB::cmNetworkElementAlmTrap' => \LibreNMS\Snmptrap\Handlers\AdvaNetworkElementAlmTrap::class,
'CM-ALARM-MIB::cmSysAlmTrap' => \LibreNMS\Snmptrap\Handlers\AdvaSysAlmTrap::class,
'CM-PERFORMANCE-MIB::cmEthernetAccPortThresholdCrossingAlert' => \LibreNMS\Snmptrap\Handlers\AdvaAccThresholdCrossingAlert::class,

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,86 @@
<?php
/**
* CiscoDHCPServerTrapTest.php
*
* 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 <https://www.gnu.org/licenses/>.
*
* @link https://www.librenms.org
*
* @copyright 2022 Josh Silvas
* @author Josh Silvas <josh@jsilvas.com>
*/
namespace LibreNMS\Tests\Feature\SnmpTraps;
class CiscoDHCPServerTrapTest extends SnmpTrapTestCase
{
/**
* Test CiscoDHCPServer trap handles
*
* @return void
*/
public function testCiscoDHCPServerFreeAddressHigh(): void
{
$this->assertTrapLogsMessage('{{ hostname }}
[UDP: [{{ ip }}]:49563->[10.0.0.1]:162]:
SNMPv2-MIB::sysUpTime.0 = Timeticks: (1714266504) 198 days, 9:51:05.04
SNMPv2-MIB::snmpTrapOID.0 CISCO-IETF-DHCP-SERVER-MIB::cDhcpv4ServerFreeAddressHigh
CISCO-IETF-DHCP-SERVER-MIB::cDhcpv4ServerSharedNetFreeAddrHighThreshold."some-dhcp-pool" = INTEGER: 228
CISCO-IETF-DHCP-SERVER-MIB::cDhcpv4ServerSharedNetFreeAddresses."some-dhcp-pool" = INTEGER: 99',
'SNMP Trap: DHCP pool "some-dhcp-pool" address space high. Free addresses: \'= INTEGER: 99\' addresses.',
'Could not handle CiscoDHCPServerFreeAddressHigh Test trap',
[2],
);
}
public function testCiscoDHCPServerFreeAddressLow(): void
{
$this->assertTrapLogsMessage('{{ hostname }}
[UDP: [{{ ip }}]:49563->[10.0.0.1]:162]:
SNMPv2-MIB::sysUpTime.0 = Timeticks: (1714275597) 198 days, 9:52:35.97
SNMPv2-MIB::snmpTrapOID.0 CISCO-IETF-DHCP-SERVER-MIB::cDhcpv4ServerFreeAddressLow
CISCO-IETF-DHCP-SERVER-MIB::cDhcpv4ServerSharedNetFreeAddrLowThreshold."some-dhcp-pool" = INTEGER: 7
CISCO-IETF-DHCP-SERVER-MIB::cDhcpv4ServerSharedNetFreeAddresses."some-dhcp-pool" = INTEGER: 99',
'SNMP Trap: DHCP pool "some-dhcp-pool" address space low. Free addresses: \'= INTEGER: 99\' addresses.',
'Could not handle CiscoDHCPServerFreeAddressHigh Test trap',
[5],
);
}
public function testCiscoDHCPServerStart(): void
{
$this->assertTrapLogsMessage('{{ hostname }}
[UDP: [{{ ip }}]:51988->[10.0.0.1]:162]:
SNMPv2-MIB::sysUpTime.0 = Timeticks: (45460476) 5 days, 6:16:44.76
SNMPv2-MIB::snmpTrapOID.0 CISCO-IETF-DHCP-SERVER-MIB::cDhcpv4ServerStartTime
CISCO-IETF-DHCP-SERVER-MIB::cDhcpv4ServerStartTime = Hex-STRING: 07 E6 0B 0A 03 0F 25 00 2B 00',
'SNMP Trap: Device DHCP service started.',
'Could not handle CiscoDHCPServerStart Test trap',
[2],
);
}
public function testCiscoDHCPServerStop(): void
{
$this->assertTrapLogsMessage('{{ hostname }}
[UDP: [{{ ip }}]:51988->[10.0.0.1]:162]:
SNMPv2-MIB::sysUpTime.0 = Timeticks: (45460476) 5 days, 6:16:44.76
SNMPv2-MIB::snmpTrapOID.0 CISCO-IETF-DHCP-SERVER-MIB::cDhcpv4ServerStopTime
CISCO-IETF-DHCP-SERVER-MIB::cDhcpv4ServerStopTime = Hex-STRING: 07 E6 0B 0A 03 0F 25 00 2B 00',
'SNMP Trap: Device DHCP service stopped.',
'Could not handle CiscoDHCPServerStop Test trap',
[5],
);
}
}