Skip to content

Commit

Permalink
Improve LinkUp and LinkDown trap handling incomplete traps (#14385)
Browse files Browse the repository at this point in the history
* fix LinkUp and LinkDown trap parsing
These traps do not always include 'ifAdminStatus' and 'ifOperStatus' from IF-MIB,
which causes the fields to become NULL when traps are received.

Add checks that values exist, and add default value for ifOperStatus.

* Fix styleci complaint

* Update LinkDown.php

* Update LinkUp.php

* Update LinkUp.php

Co-authored-by: Tony Murray <murraytony@gmail.com>
  • Loading branch information
tuomari and murrant committed Oct 12, 2022
1 parent 4efbb83 commit 5255da8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
7 changes: 5 additions & 2 deletions LibreNMS/Snmptrap/Handlers/LinkDown.php
Expand Up @@ -52,9 +52,12 @@ public function handle(Device $device, Trap $trap)
return;
}

$port->ifOperStatus = $trap->getOidData("IF-MIB::ifOperStatus.$ifIndex");
$port->ifAdminStatus = $trap->getOidData("IF-MIB::ifAdminStatus.$ifIndex");
$port->ifOperStatus = $trap->getOidData("IF-MIB::ifOperStatus.$ifIndex") ?: 'down';

$trapAdminStatus = $trap->getOidData("IF-MIB::ifAdminStatus.$ifIndex");
if ($trapAdminStatus) {
$port->ifAdminStatus = $trapAdminStatus;
}
Log::event("SNMP Trap: linkDown $port->ifAdminStatus/$port->ifOperStatus " . $port->ifDescr, $device->device_id, 'interface', 5, $port->port_id);

if ($port->isDirty('ifAdminStatus')) {
Expand Down
4 changes: 2 additions & 2 deletions LibreNMS/Snmptrap/Handlers/LinkUp.php
Expand Up @@ -52,8 +52,8 @@ public function handle(Device $device, Trap $trap)
return;
}

$port->ifOperStatus = $trap->getOidData("IF-MIB::ifAdminStatus.$ifIndex");
$port->ifAdminStatus = $trap->getOidData("IF-MIB::ifOperStatus.$ifIndex");
$port->ifOperStatus = $trap->getOidData("IF-MIB::ifOperStatus.$ifIndex") ?: 'up';
$port->ifAdminStatus = $trap->getOidData("IF-MIB::ifAdminStatus.$ifIndex") ?: 'up'; // If we receive LinkUp trap, we can safely assume that the ifAdminStatus is also up.

Log::event("SNMP Trap: linkUp $port->ifAdminStatus/$port->ifOperStatus " . $port->ifDescr, $device->device_id, 'interface', 1, $port->port_id);

Expand Down

0 comments on commit 5255da8

Please sign in to comment.