diff options
author | havner | 2005-08-09 13:36:42 (GMT) |
---|---|---|
committer | cvs2git | 2012-06-24 12:13:13 (GMT) |
commit | 023d5658c280517e0f9aadeb091907d946dc86ad (patch) | |
tree | 9ab55dd4a6c6f501988162cb1661c26527d0b4d9 | |
parent | 254cee00b0a2398e040a32e36ef5dbecb79ac836 (diff) | |
download | nagios-nsca-023d5658c280517e0f9aadeb091907d946dc86ad.zip nagios-nsca-023d5658c280517e0f9aadeb091907d946dc86ad.tar.gz |
- allow also for host submits (3 parameters instead of 4)
- more talkative
- more errors checks
- host type return codes (DOWN, UNREACHABLE)
Changed files:
nagios-nsca.submit -> 1.3
-rw-r--r-- | nagios-nsca.submit | 58 |
1 files changed, 48 insertions, 10 deletions
diff --git a/nagios-nsca.submit b/nagios-nsca.submit index 5a6c575..fe11f47 100644 --- a/nagios-nsca.submit +++ b/nagios-nsca.submit @@ -1,6 +1,6 @@ #!/bin/sh -# Arguments: +# Arguments for service: # $1 = host_name (Short name of host that the service is # associated with) # $2 = svc_description (Description of the service) @@ -11,21 +11,54 @@ # as the plugin output for the service checks) # +# Arguments for host: +# $1 = host_name (Short name of host we check for status) +# $2 = state_string (A string representing the status of +# the given service - "OK", "DOWN", "UNREACHABLE" +# or "UNKNOWN") +# $3 = plugin_output (A text string that should be used +# as the plugin output for the host checks) +# + +if [ "$#" = 4 ]; then + TYPE=SERVICE + CODE=$3 +elif [ "$#" = 3 ]; then + TYPE=HOST + CODE=$2 +else + echo "You must specify exactly 3 or 4 arguments" + exit 1 +fi + +CENTRAL=`cat /etc/send_nsca-central 2>/dev/null | grep -v '^#'` + +if [ -z $CENTRAL ]; then + echo "You must specify nagios NSCA host in /etc/send_nsca-central" + exit 1 +fi + # Convert the state string to the corresponding return code -return_code=3 +RETURN_CODE=3 -case "$3" in +case "$CODE" in OK) - return_code=0 + RETURN_CODE=0 ;; WARNING) - return_code=1 + RETURN_CODE=1 + ;; + DOWN) + RETURN_CODE=1 ;; CRITICAL) - return_code=2 + RETURN_CODE=2 + ;; + UNREACHABLE) + RETURN_CODE=2 ;; UNKNOWN) - return_code=3 + RETURN_CODE=3 ;; esac @@ -33,6 +66,11 @@ esac # in turn transmits the data to the nsca daemon on the central # monitoring server -central=`cat /etc/send_nsca-central | grep -v '^#'` - -echo -e "$1\t$2\t$return_code\t$4\n" | /usr/sbin/send_nsca $central -c /etc/send_nsca.cfg +if [ "$TYPE" = "SERVICE" ]; then + echo -e "$1\t$2\t$RETURN_CODE\t$4\n" | /usr/sbin/send_nsca $CENTRAL -c /etc/send_nsca.cfg +elif [ "$TYPE" = "HOST" ]; then + echo -e "$1\t$RETURN_CODE\t$3\n" | /usr/sbin/send_nsca $CENTRAL -c /etc/send_nsca.cfg +else + echo "This cannot happen" + exit 1 +fi |