Quantcast
Channel: Ubuntu Forums - Networking & Wireless
Viewing all articles
Browse latest Browse all 23300

[ubuntu] Trouble with setting up an SNMP trap receiver

$
0
0
Hi, I'm currently trying to receive SNMP traps on my Ubuntu machine (server 24.04), using snmptrapd. I then want the service to launch a script, which will create a line of text from some of the OIDs in the trap, and then send that line of text to an other address.
I have set up the snmptrapd.conf file like so:

Quote:

authCommunity log,execute,net public
agentAddress udp:162
mibs +ALL
disableAuthorization yes
traphandle default /usr/local/bin/trap_handler.sh
trap_handler.sh is the script I want to call when a trap is received. Here is what it looks like:

Code:

#!/bin/bash


# Default values for sysLocation, sysContact and source
sysLocation="Unknown"
sysContact="Unknown"
source="Unknown"


# Read the SNMP trap from stdin
while read line
do
    # Extract sysLocation and sysContact from the trap
    if [[ "$line" == *"1.3.6.1.2.1.1.6"* ]]; then
        sysLocation=$(echo "$line" | awk '{print $NF}')
    fi


    if [[ "$line" == *"1.3.6.1.2.1.1.4"* ]]; then
        sysContact=$(echo "$line" | awk '{print $NF}')
    fi


    if [[ "$line" == *"UDP:"* ]]; then
        source=$(echo "$line" | awk -F'[()]' '{print $2}')
    fi
done


# Send a line of text containing sysLocation and sysContact to some address
echo "source: $source, sysLocation: $sysLocation, sysContact: $sysContact" | nc -u localhost 5555

Running the script itself seems to work, however when I try to send a trap nothing happens in the script's destination. I'm using the following command to simulate an SNMP trap:

Quote:

snmptrap -v 2c -c public localhost '' .1.3.6.1.6.3.1.1.5.1 .1.3.6.1.2.1.1.1.0 s "This is a test trap"
Is there something that is obviously wrong in what I'm trying to do? Also, I'm not sure how to go about debugging the whole thing, to see where something goes wrong. Any help would be greatly appreciated.

Viewing all articles
Browse latest Browse all 23300

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>