Handler scripts - HeisSpiter/nsca_handler GitHub Wiki

Possible handler scripts (to place in /usr/share/icinga/plugins/eventhandlers/ for instance) to use feed nsca_handler with data for both service & host checks.

Commands

You will have then to define two commands in Icinga. One for services:

define command{
    command_name  obsessive_svc_handler
    command_line  /usr/share/icinga/plugins/eventhandlers/obsessive_svc_handler $HOSTNAME$ '$SERVICEDESC$' $SERVICESTATE$ '$SERVICEOUTPUT$'
}

And one for hosts:

define command{
    command_name  obsessive_host_handler
    command_line  /usr/share/icinga/plugins/eventhandlers/obsessive_host_handler $HOSTNAME$ $HOSTSTATE$ '$HOSTOUTPUT$'
}

Scripts

Here is the obsessive_svc_handler script (inspired from Icinga doc):

#!/bin/sh

# Arguments:
#  $1 = host_name (Short name of host that the service is
#       associated with)
#  $2 = svc_description (Description of the service)
#  $3 = state_string (A string representing the status of
#       the given service - "OK", "WARNING", "CRITICAL"
#       or "UNKNOWN")
#  $4 = plugin_output (A text string that should be used
#       as the plugin output for the service checks)
#

# Convert the state string to the corresponding return code
return_code=-1

case "$3" in
    OK)
        return_code=0
        ;;
    WARNING)
        return_code=1
        ;;
    CRITICAL)
        return_code=2
        ;;
    UNKNOWN)
        return_code=-1
        ;;
esac

# Write the data into a nearly unique file
 /usr/bin/printf "%s\t%s\t%s\t%s\n" "$1" "$2" "$return_code" "$4" > /var/lib/icinga/nsca_spool/NSCA_DATA.$$

Here is the obsessive_svc_handler script (inspired from Icinga doc):

 #!/bin/sh

 # Arguments:
 #  $1 = host_name (Short name of host)
 #  $2 = state_string (A string representing the status of
 #       the given host - "UP", "DOWN" or "UNREACHABLE")
 #  $3 = plugin_output (A text string that should be used
 #       as the plugin output for the host checks)
 #
 
 # Convert the state string to the corresponding return code
 return_code=-1
 
 case "$2" in
     UP)
         return_code=0
         ;;
     DOWN)
         return_code=1
         ;;
     UNREACHABLE)
         return_code=2
         ;;
 esac

 # Write the data into a nearly unique file
 /usr/bin/printf "%s\t%s\t%s\n" "$1" "$return_code" "$3" > /var/lib/icinga/nsca_spool/NSCA_DATA.$$