Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Passive 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:

...

Net-SNMP snmptrapd utility configured as follows:

...

/etc/snmp/snmptrapd.conf
Code Block
languagetext
traphandle default /usr/sbin/snmptthandler
disableAuthorization yes

thus, the incoming SNMP Traps redirected in  /usr/sbin/snmptthandler 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
Code Block
languagetext
...
[TrapFiles]
snmptt_conf_files = <<END
/etc/snmp/snmptt.conf
END

Content of snmpd.conf file after conversion into vutlan.mib:

...

/etc/snmp/snmptt.conf
Code Block
languagetext
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:
EDESC

ie 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
Code Block
languagetext
#!/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 created 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
Code Block
languagetext
##
# 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
}

...

And when you send a text message to the Nagios in some time the service status should be changed:


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


Example of such notification:

Unfortunately, a bunch snmptrapd and SNMPD do not accept utf 8UTF8, so names must be specified in Latin.