Custom SNMPtrap handler - no longer working

Hi
I seem to be having problems with my snmptrap handlers since Aug 19 update.
They worked fine before that.
I have my own dying gasp trap handlers for Huawei equipment. If a DG trap comes in i should get a trap in librenms. This is no longer working.
In logs i see the following when a dying gasp message hits the server:

Sep 6 13:42:48 librenms.local.net snmptrapd[750657]: In Trap.php line 133:
Sep 6 13:42:48 librenms.local.net snmptrapd[750657]: LibreNMS\Snmptrap\Trap::log(): Argument #2 ($severity) must be of type LibreNMS\Enum\Severity, int given, called in /opt/librenms/LibreNMS/Snmptrap/Handlers/HuaDG.php on line 14

This is my previously working handler:


<?php

namespace LibreNMS\Snmptrap\Handlers;

use App\Models\Device;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
use Log;

class HuaDG implements SnmptrapHandler
{
        public function handle(Device $device, Trap $trap)
        {
                $dyinggasp = $trap->getOidData($trap->findOid('HUAWEI-BASE-TRAP-MIB::hwEntityDyingGasp'));
                Log::event("Dying Gasp received", $device->device_id, 'trap', 5);
        }
}
?>

Ive tried several combinations of using “5” and “Severity::Warning”, ive also tried having
“use LibreNMS\Enum\Severity;” in the code.
To no avail. Still getting the same error about Argument #2 being an integer.

Is this a bug with latest release? How do i alter my handler to work correctly?

Severity::warning should be correct. Look at the system shipped traps for reference.

Feel free to submit your trap for inclusion to LibreNMS and when changes like this happen, it will get updated.

Updated HuaDG.php to this:

<?php

namespace LibreNMS\Snmptrap\Handlers;

use App\Models\Device;
use LibreNMS\Enum\Severity;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
use Log;

class HuaDG implements SnmptrapHandler
{
        public function handle(Device $device, Trap $trap)
        {
                $dyinggasp = $trap->getOidData($trap->findOid('HUAWEI-BASE-TRAP-MIB::hwEntityDyingGasp'));
                $trap->log("Dying Gasp received", $device->device_id, 'trap', Severity::Warning);
        }
}

I THINK this is correct according to: SNMP Traps - LibreNMS Docs

Still getting this in logs:

Sep 6 14:42:33 librenms.local.net snmptrapd[1038237]: In Trap.php line 133:
Sep 6 14:42:33 librenms.local.net snmptrapd[1038237]: LibreNMS\Snmptrap\Trap::log(): Argument #2 ($severity) must be of type LibreNMS\Enum\Severity, int given, called in /opt/librenms/LibreNMS/Snmptrap/Handlers/HuaDG.php on line 16

Its complaning about Argument #2. What part of that is argument 2? I cant find that in docs.

$trap->log() has different arguments than Eventlog::log().

This is what you want:

$trap->log("Dying Gasp received", Severity::Warning);

I find it a bit odd you don’t report which ONT sent the dying gasp.

I tried that too but gives the same error in log.

It can’t be the same error, it might look similar though, can you post it?

WOW. Thanks Murrant lol.
It worked now…no clue what was wrong before. I swear i did exactly what you just said earlier today.
Ah well. Phew.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.