Page 2 of 2
Re: Setting up SNMP trap
Posted: Mon Sep 14, 2015 8:07 am
by yunushaikh
Is there any possible way for defining custom MIB and then using bash script for checking my JSP. And then monitoring the snmp trap alert for that string.
Please let me know if it is possible
Re: Setting up SNMP trap
Posted: Mon Sep 14, 2015 8:14 am
by eloyd
SNMP traps are handled by an SNMP trap handler. You can send it to anything you want, including a shell script. In fact, handling SNMP traps with Nagios is best done by doing this, parsing the information, and then dropping commands (with results) into the Nagios command file.
Re: Setting up SNMP trap
Posted: Mon Sep 14, 2015 8:52 am
by yunushaikh
can you give me one configuration example for this please?
I am doing this now from quite a few weeks but not yet getting correct example.
Re: Setting up SNMP trap
Posted: Mon Sep 14, 2015 9:20 am
by eloyd
This is a somewhat complex topic that is better explained by someone else. I can set it up for you but I can't give you a quick example.
Well, actually, I can. Assuming you're using snmptrapd to deal with traps (and if you do not have that working, then you will need to do so - Google is your friend), then you could do this in /etc/snmptrapd.conf:
Code: Select all
traphandle IPAM-DEV-NOTIFICATION-MIB::chooseMIBhere /usr/local/nagios/libexec/trapforward.sh <trapType>
Update the MIB appropriately, and change the last parameter to be a key to what you want to trigger in the trapforward.sh shell script, /usr/local/nagios/libexec/trapforward.sh:
Code: Select all
#!/bin/sh
# Arguments:
# $1 = trap type
COMMAND_FILE=/usr/local/nagios/var/rw/nagios.cmd
NAGIOS_TABLE=/usr/local/nagios/libexec/nagios_messg.table
message=$1
# First line passed from snmptrapd is FQDN of host that sent the trap
read host
read ip
read varbinds0
read varbinds1
read varbinds2
read varbinds3
read varbinds4
read varbinds5
# Given a FQDN, get the short name of the host as it is setup in Nagios
IPaddr=`echo ${varbinds2#*SourceIP:}| tr \" ' '`
hostname=`echo ${varbinds3#*SourceHostname:}| sed 's/"//' | cut -d\. -f1`
output=`grep -v ^" *#" $NAGIOS_TABLE | grep ^"${message}#" | cut -d'#' -f2`
service=`grep -v ^" *#" $NAGIOS_TABLE | grep ^"${message}#" | cut -d'#' -f3`
state=`grep -v ^" *#" $NAGIOS_TABLE | grep ^"${message}#" | cut -d'#' -f4`
grep -q ^"${message}#" $NAGIOS_TABLE
if [ $? -ne 0 ]; then
output="Warning: Wrong script - Unknown state"
state=1
fi
ext_cmd_str="`date +[%s]` PROCESS_SERVICE_CHECK_RESULT;$hostname;$service;$state;$output"
echo $ext_cmd_str > $COMMAND_FILE
exit 0
Note that this script relies on /usr/local/nagios/libexec/nagios_messg.table, which looks something like this:
Code: Select all
# Comments are ignored
trapType1#This gets used as the output of the service check#servicename1#hostname1
trapType2#This gets used as the output of the service check#servicename2#hostname1
trapType3#This gets used as the output of the service check#servicename1#hostname2
trapType4#This gets used as the output of the service check#servicename2#hostname2
# etc
In other words, the script looks up the trapType as a key in the table, which then converts that into a specific output, service, and host to send to the Nagios processor command file. You can do something different or similar by changing snmptrapd.conf to send trap results to your shell script that checks JSP information instead, and then sends data to Nagios's command file.
Re: Setting up SNMP trap
Posted: Mon Sep 14, 2015 4:24 pm
by ssax
Just for reference you could use a MATCH statement in your /etc/snmp/snmptt.conf file to search for text in order for it to match:
You can read more here:
http://snmptt.sourceforge.net/docs/snmp ... CONF-MATCH