--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/submit-via-nsca Wed Nov 02 15:03:16 2011 +0100
@@ -0,0 +1,65 @@
+#! /bin/bash
+# © 2011 Heiko Schlittermann <hs@schlittermann.de>
+# source: https://ssl.schlittermann.de/hg/check-by-nsca
+
+set -e
+
+unset ${!LC_*} LANG
+export LC_ALL=C
+ME=$(basename $0)
+
+function send() { send_nsca "$@"; }
+function debug_send() { echo "CMDLINE: $@"; cat; }
+send=send # changed by option
+
+
+# read defaults, if exist
+test -f /etc/defaults/$ME \
+ && source /etc/defaults/$ME
+
+hostname=$(hostname -f)
+svcname=
+nsca_host=
+nsca_port=
+
+tmp=$(getopt -n $0 -o H:S:p:d \
+ -l help,hostname:,servicename:,nsca-host:,nsca-port:,debug \
+ -- "$@") || exit 2
+eval set -- "$tmp"
+
+while true; do
+ opt="$1"; shift
+ case "$opt" in
+ -H|--hostname) hostname="$1"; shift;;
+ -S|--svcname) svcname="$1"; shift;;
+ --nsca-host) nsca_host="$1"; shift;;
+ -p|--nsca-port) nsca_port="$1"; shift;;
+ -h|--help) cat <<_USAGE
+Usage: $ME [options] -- {test} [test-options]
+ -H|--hostname Hostname to be sent along the result ($hostname).
+ -S|--servicename Servicename to be sent along the result.
+ Use "-" to mark a host check.
+ Use "" (the default) to have the servicename
+ guessed from the test output.
+ --nsca-host Destination host ($nsca_host)
+ --nsca-port Destination port ($nsca_port)
+_USAGE
+ exit 0;;
+ -d|--debug) send="debug_$send";;
+ --) break;;
+ esac
+
+done
+
+set +e
+
+output=$("$@")
+rc=$?
+
+test "$svcname" || svcname="${output%% *}"
+
+tab=$'\x09'
+echo "$hostname$tab$svcname$tab$rc$tab$output" \
+ | $send -H "$nsca_host" ${nsca_port:+-p $nsca_port}
+
+# vim:sts=4 sw=4 aw ai sm et: