Send SNMP Traps in Nagios
A passive check is used in Nagios for SNMP Trap notifications, ie the device notifies Nagios about the events. To create a trap on the device, read the documentation: SNMP Traps notification.
To receive and interpret SNMP Traps requires the following tools:
1) Net-SNMP snmptrapd SNMP Trap receive service (http://www.net-snmp.org/)
2) SNMPTTSNMP Trap messages interpretation service (http://snmptt.sourceforge.net/)
Net-SNMP snmptrapd utility configured as follows:
/etc/snmp/snmptrapd.conf
traphandle default /usr/sbin/snmptthandler
disableAuthorization yesthus, the incoming SNMP Traps redirected in “/usr/sbin/snmptt” handler of SNMPTT translator
SNMPTT translator is used for the collection of information received in the SNMP Trap.
For processing of Traps with SNMPTT service, SNMP Trap OID must be converted with a mib file into a file with extension .conf conversion utility snmpttconvertmib and plugged to a file /etc/snmp/snmptt.ini:
/etc/snmp/snmptt.ini
...
[TrapFiles]
snmptt_conf_files = <<END
/etc/snmp/snmptt.conf
ENDContent of snmpd.conf file after conversion into vutlan.mib:
/etc/snmp/snmptt.conf
EVENT ctlUnitTrapNotification .1.3.6.1.4.1.39052.1.5 "Status Events" Normal
FORMAT $*
EXEC /usr/lib/nagios/plugins/eventhandlers/submit_check_result $r TRAP 1 "$*"
SDESC
Vutlan EMS trap
Variables:
EDESCie all Trap messages are sent to the script submit_check_result, which interprets the state of the element in the logic, formats the message and sends it to the Nagios passive checks pipe:
/etc/snmp/snmptt.conf
#!/bin/sh
# SUBMIT_CHECK_RESULT
# Written by Ethan Galstad (egalstad@nagios.org)
# Last Modified: 02-18-2002
#
# This script will write a command to the Nagios command
# file to cause Nagios to process a passive service check
# result. Note: This script is intended to be run on the
# same host that is running Nagios. If you want to
# submit passive check results from a remote machine, look
# at using the nsca addon.
#
# Arguments:
# $1 = host_name (Short name of host that the service is
# associated with)
# $2 = svc_description (Description of the service)
# $3 = return_code (An integer that determines the state
# of the service check, 0=OK, 1=WARNING, 2=CRITICAL,
# 3=UNKNOWN).
# $4 = plugin_output (A text string that should be used
# as the plugin output for the service check)
#
echocmd="/bin/echo"
CommandFile="/var/spool/nagios/cmd/nagios.cmd"
# get the current date/time in seconds since UNIX epoch
datetime=`date +%s`
name=$4
name=${name#*name: }
name=${name%%','*}
name=`echo -n $name`
state=$4
state=${state#*state:}
state=${state%%','*}
state=`echo -n $state`
status="UNKNOWN"
# check state
case "$state" in
normal| on | off)
#echo "OK"
status=0
;;
warning | 'low warning' | 'high warning')
#echo "WARNING"
status=1
;;
alarm | 'low alarm' | 'high alarm')
#echo "CRITICAL"
status=2
;;
*)
#echo "UNKNOWN"
status=3
esac
# check test and reset to OK
if [[ $4 =~ "test message" ]] ; then
#echo "OK"
status=0
fi
# create the command line to add to the command file
cmdline="[$datetime] PROCESS_SERVICE_CHECK_RESULT;$1;$name;$status;$4" #$2;$3;$4"
# append the command to the end of the command file
`$echocmd $cmdline >> $CommandFile`This script defines the name set when the SNMP Trap notification in the master module is created, as well as the state of the element, which led to the triggering logic.
In the Nagios configuration file, you must add a template for passive testing and tie this pattern, for example, with a group of hosts:
/etc/nagios/objects/schosts.cfg
##
# Trap
##
define service{
name trap-service
use generic-service
register 0
is_volatile 1
check_command check-host-alive ;Used to reset the status to OK when 'Schedule an immediate check of this service' is selected
flap_detection_enabled 0 ; Flap detection is disabled
process_perf_data 0 ; Do not Process performance data
max_check_attempts 1
normal_check_interval 1
retry_check_interval 1
passive_checks_enabled 1
active_checks_enabled 0 ; Prevent active checks from occuring as we are only using passive checks
check_period none
notification_interval 31536000
notification_options w,u,c ; Notify on warning, unknown and critical
contact_groups admins
}
define service{
use trap-service
service_description Trap1
hostgroup_name sc-hosts
}'Trap1' name must match the SNMP Trap notification name in the master module.
Unknown Attachment
And when you send a text message to the Nagios in some the service status should be changed:
Unknown Attachment
To send a notification, you must create a logic circuit in a master unit interface, the result of which is associated with sending SNMP Trap1 notification
Unknown Attachment
Example of such notification:
Unknown Attachment
Unfortunately, a bunch snmptrapd and SNMPD do not accept UTF8, so names must be specified in Latin.