SNMP Traps (LibreNMS)

Hi Guys,

I’m struggling with this snmp trap handler. the how to does not really explain what to do.

Below is how I’ve set it up at the moment but no luck.

it is configured in /librenms/config.php.

Please any assistance or a point in the right direction will help alot

Thanks!!

> vi /opt/librenms/snmptrap.php

#!/usr/bin/env php
<?php

/**
 * LibreNMS
 *
 *   This file is part of LibreNMS.
 *
 * @package    LibreNMS
 * @subpackage snmptraps
 * @copyright  (C) 2006 - 2012 Adam Armstrong
 * @copyright  (C) 2018 LibreNMS
 * Adapted from old snmptrap.php handler
 */

$init_modules = [];
require __DIR__ . '/includes/init.php';

$options = getopt('d::');

if (set_debug(isset($options['d']))) {
    echo "DEBUG!\n";
}

$text = stream_get_contents(STDIN);

// create handle and send it this trap
\LibreNMS\Snmptrap\Dispatcher::handle(new \LibreNMS\Snmptrap\Trap($text));

> vi /etc/systemd/system/snmptrapd.service.d/mibs.conf

[Service]
Environment=MIBDIRS=+/opt/librenms/mibs:/opt/librenms/mibs/cisco
Environment=MIBDIRS=+/opt/librenms/mibs:/opt/librenms/mibs/sandvine/
Environment=MIBS=+ALL

> vi /etc/snmp/snmptrapd.conf

#
# EXAMPLE-trap.conf:
#   An example configuration file for configuring the Net-SNMP snmptrapd agent.
#
###############################################################################
#
# This file is intended to only be an example.
# When the snmptrapd agent starts up, this is where it will look for it.
#
# All lines beginning with a '#' are comments and are intended for you
# to read.  All other lines are configuration commands for the agent.

#
# PLEASE: read the snmptrapd.conf(5) manual page as well!
#
#authCommunity log,execute,net private 
#authCommunity log,execute,net public
#
## send mail when get any events
#traphandle default /usr/bin/traptoemail -s smtp.example.org [email protected]
#
## send mail when get linkDown
#traphandle .1.3.6.1.6.3.1.1.5.3 /usr/bin/traptoemail -s smtp.example.org [email protected]
#
traphandle default /opt/librenms/snmptrap.php
1 Like