We are migrating our old OpenNMS monitoring system to a Nagios 4.4.3 and I need to send SNMP traps from Nagios to a server in my parent company. We're already doing this in OpenNMS so we need to "adapt" the script to work on Nagios. Problem that I'm new on linux enviroment and I'm pretty lost. I've been searching on google but didn't find clear solutions, so I hope you can help me with this.
We're sending 2 different traps:
1- Keepalive trap every 5 minutes:
Code: Select all
#!/bin/sh
OPENNMS_HOME="/opt/opennms"
SEND_TRAP="/usr/bin/snmptrap"
LOGFILE=log-send-event-passive2.log
PASS="CORE CdControl"
DESTINATION="0.0.0.0" #IP CdC
TIMESTAMP=`date '+%Y/%m/%d %H:%M:%S'`
COMMANDT="$SEND_TRAP -v1 -c public $DESTINATION .1.3.6.1.4.1.20006.9 1.1.1.1 6 10 ''"
COMMANDT="$COMMANDT .1.3.6.1.4.1.20006.9.1 s \"Nagios \""
COMMANDT="$COMMANDT .1.3.6.1.4.1.20006.9.2 s \"NORMAL\""
COMMANDT="$COMMANDT .1.3.6.1.4.1.20006.9.3 s \"Nagios\""
COMMANDT="$COMMANDT .1.3.6.1.4.1.20006.9.4 s \"Monitoratge\""
COMMANDT="$COMMANDT .1.3.6.1.4.1.20006.9.5 s \"$TIMESTAMP\""
COMMANDT="$COMMANDT .1.3.6.1.4.1.20006.9.6 s \"KeepAlive\""
COMMANDT="$COMMANDT .1.3.6.1.4.1.20006.9.7 s \"\""
COMMANDT="$COMMANDT .1.3.6.1.4.1.20006.9.8 s \"LAN\""
COMMANDT="$COMMANDT .1.3.6.1.4.1.20006.9.9 s \"GESTIO DE LAN\""
COMMANDT="$COMMANDT .1.3.6.1.4.1.20006.9.10 s \"OK\""
COMMANDT="$COMMANDT .1.3.6.1.4.1.20006.9.11 s \"\""
sh -c "$COMMANDT"
echo $COMMANDT >> /opt/opennms/bin/$LOGFILE
#EOFCode: Select all
#!/bin/sh
OPENNMS_HOME="/opt/opennms"
SEND_TRAP="/usr/bin/snmptrap"
EVENT_DOWN="uei.opennms.org/nodes/nodeDown"
EVENT_UP="uei.opennms.org/nodes/nodeUp"
EVENT_TRAP="uei.opennms.org/custom/event/SendTrapCdC"
LOGFILE=log-send-event-passive.log
PASS="CORE CdControl"
DESTINATION="0.0.0.0" #IP CdC
TIMESTAMP=`date '+%Y/%m/%d %H:%M:%S'`
ASSET=$1
CATEGORY=$2
SEU=$3
UEI=$4
LOGMSG=$5
DESC=$6
#Si Falten Parametres sortim
if [ $# -ne 6 ]; then
exit 0
fi
#Si no es CORE sortim
if [ "$CATEGORY" != "$PASS" ]; then
exit 0
fi
CATEGORY="Core"
#Si no es un Event catalogat Sortim
if [ "$UEI" != "$EVENT_DOWN" ] && [ "$UEI" != "$EVENT_UP" ]; then
echo "No es event down o Up"
exit 0
fi
if [ "$UEI" == "$EVENT_DOWN" ]; then
STATUS="Critical"
else
STATUS="Normal"
fi
COMMANDT="$SEND_TRAP -v1 -c public $DESTINATION2 .1.3.6.1.4.1.20006.9 1.1.1.1 6 10 ''"
COMMANDT="$COMMANDT .1.3.6.1.4.1.20006.9.1 s \"$ASSET\""
COMMANDT="$COMMANDT .1.3.6.1.4.1.20006.9.2 s \"$STATUS\""
COMMANDT="$COMMANDT .1.3.6.1.4.1.20006.9.3 s \"$CATEGORY\""
COMMANDT="$COMMANDT .1.3.6.1.4.1.20006.9.4 s \"LAN: $SEU\""
COMMANDT="$COMMANDT .1.3.6.1.4.1.20006.9.5 s \"$TIMESTAMP\""
COMMANDT="$COMMANDT .1.3.6.1.4.1.20006.9.6 s \"$LOGMSG\""
COMMANDT="$COMMANDT .1.3.6.1.4.1.20006.9.7 s \"$DESC\""
COMMANDT="$COMMANDT .1.3.6.1.4.1.20006.9.8 s \"LAN\""
COMMANDT="$COMMANDT .1.3.6.1.4.1.20006.9.9 s \"GESTIO DE LAN\""
COMMANDT="$COMMANDT .1.3.6.1.4.1.20006.9.10 s \"Disponibilitat\""
COMMANDT="$COMMANDT .1.3.6.1.4.1.20006.9.11 s \"\""
# echo "$COMMANDT"
sh -c "$COMMANDT"
echo $COMMANDT >> /opt/opennms/bin/$LOGFILE
COMMAND2="$OPENNMS_HOME/bin/send-event.pl $EVENT_TRAP --parm 'EventUEI $UEI'"
COMMAND2="$COMMAND2 --parm 'nodename $ASSET' --parm 'DateTime $TIMESTAMP'"
sh -c "$COMMAND2"
#EOF
All that variables like "ASSET, CATEGORY, STATUS, SEU…" are neccessary (demanded by my company) and I can set by hostgroups, but I don't know how to define that on this codes. And, to execute this, I think I can do it creating a new user who it's "host notification command" are executing this script instead of default "notify-host-by-email" (something like "send-trap", and create a command to do this, obviously)
I'm sorry if I'm explaining poorly, if you need some more specific info please, tell me.
Hope you can help me guys.
Thanks!