diff -r b8c814c738cf -r e81beebd168f submit-via-nsca.sh --- a/submit-via-nsca.sh Wed Nov 02 15:03:39 2011 +0100 +++ b/submit-via-nsca.sh Wed Nov 02 17:05:02 2011 +0100 @@ -7,9 +7,10 @@ unset ${!LC_*} LANG export LC_ALL=C ME=$(basename $0) +TAB=$'\x09' function send() { send_nsca "$@"; } -function debug_send() { echo "CMDLINE: $@"; cat; } +function debug_send() { echo "CMDLINE: $@"; sed 's/\t/<>/g'; } send=send # changed by option @@ -18,11 +19,11 @@ && source /etc/defaults/$ME hostname=$(hostname -f) -svcname= +svcname=- nsca_host= nsca_port= -tmp=$(getopt -n $0 -o H:S:p:d \ +tmp=$(getopt -n $0 -o hH:S:p:d \ -l help,hostname:,servicename:,nsca-host:,nsca-port:,debug \ -- "$@") || exit 2 eval set -- "$tmp" @@ -38,9 +39,9 @@ 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. + Use "" to mark a host check. + Use "-" (the default) to have the servicename guessed + from the test output (the first word). --nsca-host Destination host ($nsca_host) --nsca-port Destination port ($nsca_port) _USAGE @@ -51,15 +52,13 @@ done -set +e - -output=$("$@") -rc=$? +rc=0 +output=$("$@") || rc=$? -test "$svcname" || svcname="${output%% *}" +test "$svcname" = "-" && svcname="${output%% *}" +svcname="${svcname:+$TAB$svcname}" -tab=$'\x09' -echo "$hostname$tab$svcname$tab$rc$tab$output" \ +echo "$hostname$svcname$TAB$rc$TAB$output" \ | $send -H "$nsca_host" ${nsca_port:+-p $nsca_port} # vim:sts=4 sw=4 aw ai sm et: