Results 1 to 4 of 4

Thread: 14.04 LTS snmptrapd not handling traps, possibly not running

Hybrid View

  1. #1
    Join Date
    Oct 2016
    Beans
    4

    14.04 LTS snmptrapd not handling traps, possibly not running

    Hey everyone. Running 14.04 LTS for a Zabbix installation. I've followed several guides but I can't seem to get snmptrapd to do anything. I'm thinking it's not even running but because it's a subset of snmpd instead of its own service I don't know how to check.


    I've edited /etc/init.d/snmpd to add TRAPDRUN=yes (also tried with quotes to match SNMPDRUN's option), and I have tried logging to syslog, a dedicated log file and straight to the output stream. The best I've gotten is to get an incoming UDP connection in the log but never an actual trap.

    Below are my configuration files:

    /etc/init.d/snmpd:

    Code:
    #! /bin/sh -e
    ### BEGIN INIT INFO
    # Provides:           snmpd snmptrapd
    # Required-Start:     $network $remote_fs $syslog
    # Required-Stop:      $network $remote_fs $syslog
    # Default-Start:      2 3 4 5
    # Default-Stop:       0 1 6
    # Short-Description:  SNMP agents
    # Description:        NET SNMP (Simple Network Management Protocol) Agents
    ### END INIT INFO
    #
    # Author:    Jochen Friedrich <jochen@scram.de>
    #
    set -e
    
    . /lib/lsb/init-functions
    
    export PATH=/sbin:/usr/sbin:/bin:/usr/bin
    
    test -x /usr/sbin/snmpd || exit 0
    test -x /usr/sbin/snmptrapd || exit 0
    
    # Defaults
    OLD_MIBS_DIR="/usr/share/mibs/site:/usr/share/snmp/mibs:/usr/share/mibs/iana:/usr/share/mibs/ietf:/usr/share/mibs/netsnmp"
    MIBS_DIR="/usr/share/snmp/mibs:/usr/share/snmp/mibs/iana:/usr/share/snmp/mibs/ietf"
    export MIBDIRS="$MIBS_DIR:$OLD_MIBS_DIR"
    
    SNMP_PID="/run/snmpd.pid"
    TRAPD_PID="/run/snmptrapd.pid"
    SNMPDRUN="yes"
    SNMPDOPTS="-Lsd -Lf /dev/null -p $SNMP_PID"
    TRAPDRUN=Yes
    TRAPDOPTS="-Lsd -Lo -p $TRAPD_PID"
    
    # Reads config file (will override defaults above)
    [ -r /etc/default/snmpd ] && . /etc/default/snmpd
    
    # Cd to / before starting any daemons.
    cd /
    
    case "$1" in
      start)
        log_daemon_msg "Starting network management services:"
        # remove old symlink with previous version
        if [ -L /var/run/agentx ]; then
                rm -f /var/run/agentx
        fi
        if [ ! -d /var/run/agentx ]; then
                mkdir -p /var/run/agentx
        fi
        if [ "$SNMPDRUN" = "yes" -a -f /etc/snmp/snmpd.conf ]; then
            start-stop-daemon --quiet --start --oknodo --exec /usr/sbin/snmpd \
                -- $SNMPDOPTS
            log_progress_msg " snmpd"
        fi
        if [ "$TRAPDRUN" = "yes" -a -f /etc/snmp/snmptrapd.conf ]; then
            start-stop-daemon --quiet --start --oknodo --exec /usr/sbin/snmptrapd \
                -- $TRAPDOPTS
            log_progress_msg " snmptrapd"
        fi
        ;;
      stop)
        log_daemon_msg "Stopping network management services:"
        start-stop-daemon --quiet --stop --oknodo --exec /usr/sbin/snmpd && [ ! -f $SNMP_PID ] || rm $SNMP_PID
        log_progress_msg " snmpd"
        start-stop-daemon --quiet --stop --oknodo --exec /usr/sbin/snmptrapd && [ ! -f $TRAPD_PID ] || rm $TRAPD_PID
        log_progress_msg " snmptrapd"
        ;;
      restart)
        log_daemon_msg "Restarting network management services:"
        start-stop-daemon --quiet --stop --oknodo --exec /usr/sbin/snmpd  && [ ! -f $SNMP_PID ] || rm $SNMP_PID
        start-stop-daemon --quiet --stop --oknodo --exec /usr/sbin/snmptrapd  && [ ! -f $TRAPD_PID ] || rm $TRAPD_PID
        # Allow the daemons time to exit completely.
        sleep 2
        if [ "$SNMPDRUN" = "yes" -a -f /etc/snmp/snmpd.conf ]; then
            start-stop-daemon --quiet --start --exec /usr/sbin/snmpd -- $SNMPDOPTS
            log_progress_msg " snmpd"
        fi
        if [ "$TRAPDRUN" = "yes" -a -f /etc/snmp/snmptrapd.conf ]; then
            # Allow snmpd time to start up.
            sleep 1
            start-stop-daemon --quiet --start --exec /usr/sbin/snmptrapd -- $TRAPDOPTS
            log_progress_msg " snmptrapd"
        fi
        ;;
      reload|force-reload)
        log_daemon_msg "Reloading network management services:"
        if [ "$SNMPDRUN" = "yes" -a -f /etc/snmp/snmpd.conf ]; then
            start-stop-daemon --quiet --stop --signal 1 \
                --pidfile /var/run/snmpd.pid --exec /usr/sbin/snmpd
            log_progress_msg " snmpd"
        fi
        ;;
      status)
        status=0
        if [ "$SNMPDRUN" = "yes" -a -f /etc/snmp/snmpd.conf ]; then
            status_of_proc /usr/sbin/snmpd snmpd || status=$?
        fi
        if [ "$TRAPDRUN" = "yes" -a -f /etc/snmp/snmptrapd.conf ]; then
            status_of_proc /usr/sbin/snmptrapd snmptrapd || status=$?
        fi
        exit $status
        ;;
      *)
        echo "Usage: /etc/init.d/snmpd {start|stop|restart|reload|force-reload|status}"
        exit 1
    esac
    
    exit 0
    /etc/snmp/snmp.conf (comments trimmed):
    Code:
    agentAddress udp:161,udp6:[::1]:161,udp:162
    
    view   systemonly  included   .1.3.6.1.2.1.1
    view   systemonly  included   .1.3.6.1.2.1.25.1
    
                                                     #  Full access from the local host
    #rocommunity public  localhost
                                                     #  Default access to basic system info
     rocommunity public  default    -V systemonly
    
    
                                                     #  Full read-only access for SNMPv3
     rouser   authOnlyUser
                                                     #  Full write access for encrypted requests
                                                     #     Remember to activate the 'createUser' lines above
    #rwuser   authPrivUser   priv
    
    
    
    ###############################################################################
    #
    #  SYSTEM INFORMATION
    #
    
    #  Note that setting these values here, results in the corresponding MIB objects being 'read-only'
    #  See snmpd.conf(5) for more details
    sysLocation    Sitting on the Dock of the Bay
    sysContact     Me <me@example.org>
                                                     # Application + End-to-End layers
    sysServices    72
    
    
    #
    #  Process Monitoring
    #
                                   # At least one  'mountd' process
    proc  mountd
                                   # No more than 4 'ntalkd' processes - 0 is OK
    proc  ntalkd    4
                                   # At least one 'sendmail' process, but no more than 10
    proc  sendmail 10 1
    
    #  Walk the UCD-SNMP-MIB::prTable to see the resulting output
    #  Note that this table will be empty if there are no "proc" entries in the snmpd.conf file
    
    
    #
    #  Disk Monitoring
    #
                                   # 10MBs required on root disk, 5% free on /var, 10% free on all other disks
    disk       /     10000
    disk       /var  5%
    includeAllDisks  10%
    
    #  Walk the UCD-SNMP-MIB::dskTable to see the resulting output
    #  Note that this table will be empty if there are no "disk" entries in the snmpd.conf file
    
    
    #
    #  System Load
    #
                                   # Unacceptable 1-, 5-, and 15-minute load averages
    load   12 10 5
    
    #  Walk the UCD-SNMP-MIB::laTable to see the resulting output
    #  Note that this table *will* be populated, even without a "load" entry in the snmpd.conf file
    
    
    
    ###############################################################################
    #
    #  ACTIVE MONITORING
    #
    
                                        #   send SNMPv1  traps
     trapsink     localhost public
    
    #trap2sink    localhost public
                                        #   send SNMPv2c INFORMs
    #informsink   localhost public
    
    #  Note that you typically only want *one* of these three lines
    #  Uncommenting two (or all three) will result in multiple copies of each notification.
    
    
    #
    #  Event MIB - automatically generate alerts
    #
                                       # Remember to activate the 'createUser' lines above
    iquerySecName   internalUser
    rouser          internalUser
                                       # generate traps on UCD error conditions
    defaultMonitors          yes
                                       # generate traps on linkUp/Down
    linkUpDownNotifications  yes
    
    
    
    #
    #  Arbitrary extension commands
    #
     extend    test1   /bin/echo  Hello, world!
     extend-sh test2   echo Hello, world! ; echo Hi there ; exit 35
    #extend-sh test3   /bin/sh /tmp/shtest
    
    
    #
    #  AgentX Sub-agents
    #
                                               #  Run as an AgentX master agent
     master          agentx
                                               #  Listen for network connections (from localhost)
                                               #    rather than the default named socket /var/agentx/master
    #agentXSocket    tcp:localhost:705
    /etc/snmp/snmptrapd.conf:

    Code:
    authCommunity execute (our snmpv3 community)
    authCommunity execute (our snmpv3 private community)
    authCommunity log,execute,net public
    
    snmpTrapdAddr udp:162
    
    logOption -Lf /var/log/syslog
    
    #perl do "/usr/bin/zabbix_trap_receiver.pl"
    
    #logoption f /var/log/snmptrap.log
    logoption s 1
    traphandle default /usr/bin/zabbix_trap_receiver.pl
    disableAuthorization yes
    /etc/default/snmpd:

    Code:
    # This file controls the activity of snmpd and snmptrapd
    
    # Don't load any MIBs by default.
    # You might comment this lines once you have the MIBs downloaded.
    #export MIBS=
    
    # snmpd control (yes means start daemon).
    SNMPDRUN=yes
    
    # snmpd options (use syslog, close stdin/out/err).
    SNMPDOPTS='-Lsd -Lf /dev/null -u snmp -g snmp -I -smux,mteTrigger,mteTriggerConf -p /var/run/snmpd.pid'
    
    # snmptrapd control (yes means start daemon).  As of net-snmp version
    # 5.0, master agentx support must be enabled in snmpd before snmptrapd
    # can be run.  See snmpd.conf(5) for how to do this.
    TRAPDRUN=YES
    
    # snmptrapd options (use syslog).
    #TRAPDOPTS='-Lsd -p /var/run/snmptrapd.pid'
    TRAPDOPTS='-n -On -t -Lf /var/log/snmptrap.log -p /var/run/snmptrapd.pid'
    Trap I am using to test:

    Code:
    snmptrap -v1 -c public localhost .1.3.6.1.6.3.1.1.5.2 0 0 "" "" .1.3.6.1.4.1 s "hello"
    System log entry whenever I do a test:
    Code:
    Oct 18 10:10:00 ms02 snmpd[12240]: Connection from UDP: [127.0.0.1]:53079->[127.0.0.1]:162
    Any help would be appreciated. I must be missing something really obvious but I've spent too long down this rabbit hole to see where I'm going wrong. Thanks in advance.

  2. #2
    Join Date
    Oct 2016
    Beans
    4

    Re: 14.04 LTS snmptrapd not handling traps, possibly not running

    Also, if there's a better place to post this I'd appreciate it. Not sure if this is really a ubuntu problem, or ubuntu server, or what.

  3. #3
    Join Date
    Oct 2016
    Beans
    4

    Re: 14.04 LTS snmptrapd not handling traps, possibly not running

    Found the problem. It was what appears to be a bug in the init.d script - the logic for starting snmptrapd appeared to not be firing at all. I copied the commands out of that branch of the if clause and dumped it right after the snmpd portion that was working.

    The server immediately terminated my ssh connection and rebooted.... but now it works. O_O

    Hacked up /etc/init.d/snmpd script below:

    Code:
    #! /bin/sh -e
    ### BEGIN INIT INFO
    # Provides:           snmpd snmptrapd
    # Required-Start:     $network $remote_fs $syslog
    # Required-Stop:      $network $remote_fs $syslog
    # Default-Start:      2 3 4 5
    # Default-Stop:       0 1 6
    # Short-Description:  SNMP agents
    # Description:        NET SNMP (Simple Network Management Protocol) Agents
    ### END INIT INFO
    #
    # Author:    Jochen Friedrich <jochen@scram.de>
    #
    set -e
    
    . /lib/lsb/init-functions
    
    export PATH=/sbin:/usr/sbin:/bin:/usr/bin
    
    test -x /usr/sbin/snmpd || exit 0
    test -x /usr/sbin/snmptrapd || exit 0
    
    # Defaults
    OLD_MIBS_DIR="/usr/share/mibs/site:/usr/share/snmp/mibs:/usr/share/mibs/iana:/usr/share/mibs/ietf:/usr/share/mibs/netsnmp"
    MIBS_DIR="/usr/share/snmp/mibs:/usr/share/snmp/mibs/iana:/usr/share/snmp/mibs/ietf"
    export MIBDIRS="$MIBS_DIR:$OLD_MIBS_DIR"
    
    SNMP_PID="/run/snmpd.pid"
    TRAPD_PID="/run/snmptrapd.pid"
    SNMPDRUN="yes"
    SNMPDOPTS="-Lsd -Lf /dev/null -p $SNMP_PID"
    TRAPDRUN="yes"
    TRAPDOPTS="-Lsd -p $TRAPD_PID"
    
    # Reads config file (will override defaults above)
    [ -r /etc/default/snmpd ] && . /etc/default/snmpd
    
    # Cd to / before starting any daemons.
    cd /
    
    case "$1" in
      start)
        log_daemon_msg "Starting network management services:"
        # remove old symlink with previous version
        if [ -L /var/run/agentx ]; then
                rm -f /var/run/agentx
        fi
        if [ ! -d /var/run/agentx ]; then
                mkdir -p /var/run/agentx
        fi
        if [ "$SNMPDRUN" = "yes" -a -f /etc/snmp/snmpd.conf ]; then
            start-stop-daemon --quiet --start --oknodo --exec /usr/sbin/snmpd \
                -- $SNMPDOPTS
            log_progress_msg " snmpd"
            start-stop-daemon --start --oknodo --exec /usr/sbin/snmptrapd \
                -- $TRAPDOPTS
            log_progress_msg " snmptrapd"
    
        fi
        if [ "$TRAPDRUN" = "yes" -a -f /etc/snmp/snmptrapd.conf ]; then
            log_daemon_msg "Starting snmptrapd"
            start-stop-daemon --start --oknodo --exec /usr/sbin/snmptrapd \
                -- $TRAPDOPTS
            log_progress_msg " snmptrapd"
        fi
        ;;
      stop)
        log_daemon_msg "Stopping network management services:"
        start-stop-daemon --quiet --stop --oknodo --exec /usr/sbin/snmpd && [ ! -f $SNMP_PID ] || rm $SNMP_PID
        log_progress_msg " snmpd"
        start-stop-daemon --stop --oknodo --exec /usr/sbin/snmptrapd && [ ! -f $TRAPD_PID ] || rm $TRAPD_PID
        log_progress_msg " snmptrapd"
        ;;
      restart)
        log_daemon_msg "Restarting network management services:"
        start-stop-daemon --quiet --stop --oknodo --exec /usr/sbin/snmpd  && [ ! -f $SNMP_PID ] || rm $SNMP_PID
        start-stop-daemon --stop --oknodo --exec /usr/sbin/snmptrapd  && [ ! -f $TRAPD_PID ] || rm $TRAPD_PID
        # Allow the daemons time to exit completely.
        sleep 2
        if [ "$SNMPDRUN" = "yes" -a -f /etc/snmp/snmpd.conf ]; then
            start-stop-daemon --quiet --start --exec /usr/sbin/snmpd -- $SNMPDOPTS
            log_progress_msg " snmpd"
        fi
        if [ "$TRAPDRUN" = "yes" -a -f /etc/snmp/snmptrapd.conf ]; then
            # Allow snmpd time to start up.
            sleep 1
            log_daemon_msg "Attempting to start snmptrapd"
            start-stop-daemon  --start --exec /usr/sbin/snmptrapd -- $TRAPDOPTS
            log_progress_msg " snmptrapd"
        fi
        ;;
      reload|force-reload)
        log_daemon_msg "Reloading network management services:"
        if [ "$SNMPDRUN" = "yes" -a -f /etc/snmp/snmpd.conf ]; then
            start-stop-daemon --quiet --stop --signal 1 \
                --pidfile /var/run/snmpd.pid --exec /usr/sbin/snmpd
            log_progress_msg " snmpd"
        fi
        ;;
      status)
        status=0
        if [ "$SNMPDRUN" = "yes" -a -f /etc/snmp/snmpd.conf ]; then
            status_of_proc /usr/sbin/snmpd snmpd || status=$?
        fi
        if [ "$TRAPDRUN" = "yes" -a -f /etc/snmp/snmptrapd.conf ]; then
            status_of_proc /usr/sbin/snmptrapd snmptrapd || status=$?
        fi
        exit $status
        ;;
      *)
        echo "Usage: /etc/init.d/snmpd {start|stop|restart|reload|force-reload|status}"
        exit 1
    esac
    
    exit 0

  4. #4
    Join Date
    Oct 2016
    Beans
    4

    Re: 14.04 LTS snmptrapd not handling traps, possibly not running

    Tried removing and purging the package, clean install with basic options set. Still can't get the traps to show up. Doesn't seem to be a firewall issue as the syslog shows an incoming connection on port 162 whenever I send a trap.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •