5 set -e |
5 set -e |
6 |
6 |
7 unset ${!LC_*} LANG |
7 unset ${!LC_*} LANG |
8 export LC_ALL=C |
8 export LC_ALL=C |
9 ME=$(basename $0) |
9 ME=$(basename $0) |
|
10 TAB=$'\x09' |
10 |
11 |
11 function send() { send_nsca "$@"; } |
12 function send() { send_nsca "$@"; } |
12 function debug_send() { echo "CMDLINE: $@"; cat; } |
13 function debug_send() { echo "CMDLINE: $@"; sed 's/\t/<<TAB>>/g'; } |
13 send=send # changed by option |
14 send=send # changed by option |
14 |
15 |
15 |
16 |
16 # read defaults, if exist |
17 # read defaults, if exist |
17 test -f /etc/defaults/$ME \ |
18 test -f /etc/defaults/$ME \ |
18 && source /etc/defaults/$ME |
19 && source /etc/defaults/$ME |
19 |
20 |
20 hostname=$(hostname -f) |
21 hostname=$(hostname -f) |
21 svcname= |
22 svcname=- |
22 nsca_host= |
23 nsca_host= |
23 nsca_port= |
24 nsca_port= |
24 |
25 |
25 tmp=$(getopt -n $0 -o H:S:p:d \ |
26 tmp=$(getopt -n $0 -o hH:S:p:d \ |
26 -l help,hostname:,servicename:,nsca-host:,nsca-port:,debug \ |
27 -l help,hostname:,servicename:,nsca-host:,nsca-port:,debug \ |
27 -- "$@") || exit 2 |
28 -- "$@") || exit 2 |
28 eval set -- "$tmp" |
29 eval set -- "$tmp" |
29 |
30 |
30 while true; do |
31 while true; do |
36 -p|--nsca-port) nsca_port="$1"; shift;; |
37 -p|--nsca-port) nsca_port="$1"; shift;; |
37 -h|--help) cat <<_USAGE |
38 -h|--help) cat <<_USAGE |
38 Usage: $ME [options] -- {test} [test-options] |
39 Usage: $ME [options] -- {test} [test-options] |
39 -H|--hostname Hostname to be sent along the result ($hostname). |
40 -H|--hostname Hostname to be sent along the result ($hostname). |
40 -S|--servicename Servicename to be sent along the result. |
41 -S|--servicename Servicename to be sent along the result. |
41 Use "-" to mark a host check. |
42 Use "" to mark a host check. |
42 Use "" (the default) to have the servicename |
43 Use "-" (the default) to have the servicename guessed |
43 guessed from the test output. |
44 from the test output (the first word). |
44 --nsca-host Destination host ($nsca_host) |
45 --nsca-host Destination host ($nsca_host) |
45 --nsca-port Destination port ($nsca_port) |
46 --nsca-port Destination port ($nsca_port) |
46 _USAGE |
47 _USAGE |
47 exit 0;; |
48 exit 0;; |
48 -d|--debug) send="debug_$send";; |
49 -d|--debug) send="debug_$send";; |
49 --) break;; |
50 --) break;; |
50 esac |
51 esac |
51 |
52 |
52 done |
53 done |
53 |
54 |
54 set +e |
55 rc=0 |
|
56 output=$("$@") || rc=$? |
55 |
57 |
56 output=$("$@") |
58 test "$svcname" = "-" && svcname="${output%% *}" |
57 rc=$? |
59 svcname="${svcname:+$TAB$svcname}" |
58 |
60 |
59 test "$svcname" || svcname="${output%% *}" |
61 echo "$hostname$svcname$TAB$rc$TAB$output" \ |
60 |
|
61 tab=$'\x09' |
|
62 echo "$hostname$tab$svcname$tab$rc$tab$output" \ |
|
63 | $send -H "$nsca_host" ${nsca_port:+-p $nsca_port} |
62 | $send -H "$nsca_host" ${nsca_port:+-p $nsca_port} |
64 |
63 |
65 # vim:sts=4 sw=4 aw ai sm et: |
64 # vim:sts=4 sw=4 aw ai sm et: |