#!/bin/sh

# SUBMIT_CHECK_RESULT_VIA_NSCA
# Written by Ethan Galstad (nagios@nagios.org)
# Last Modified: 02-19-2004
#
# This script will send passive check results to the
# nsca daemon that runs on the central Nagios server.
# If you simply want to submit passive checks from the 
# same machine that Nagios is running on, look at the
# submit_check_result script.
#
# 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 check)s
# 
#
# Note:
# Modify the NagiosHost parameter to match the name or
# IP address of the central server that has the nsca
# daemon running.

# source this to get the return status values
. /usr/lib/nagios/plugins/utils.sh

# parse the state_string into an integer return code
return_value=`eval echo "\$STATE_\`echo $3\`"`

if [ "$1" = "-H" ]; then
	NagiosHost="$2"
	shift 2
else
	NagiosHost="nagioshost"
fi

printfcmd="/usr/bin/printf"

NscaBin="/usr/sbin/send_nsca" 
NscaCfg="/etc/send_nsca.cfg"
#NagiosHost="nagioshost"

# Fire the data off to the NSCA daemon using the send_nsca script 
$printfcmd "%s\t%s\t%s\t%s\n" "$1" "$2" "$return_value" "$4" | $NscaBin $NagiosHost -c $NscaCfg

# EOF

