From: Alexander Barton Date: Wed, 22 Aug 2012 14:00:15 +0000 (+0200) Subject: Ehnance nagcollecttest, now it is a "nagios plugin wrapper" X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?p=nagcollect.git;a=commitdiff_plain;h=ad66976e79c7d292b250a9148c85835e5d93c096 Ehnance nagcollecttest, now it is a "nagios plugin wrapper" Now the client/bin/nagcollecttest script can be used as a "nagios plugin wrapper", for example you can use define command { command_name nagcollect command_line /usr/local/sbin/nagcollecttest $ARG1$ } define command { command_name ssh_nagcollect command_line /usr/lib/nagios/plugins/check_by_ssh -t 60 -l root \ -H '$HOSTADDRESS$' -C '/usr/local/sbin/nagcollecttest $ARG1$' } in your Nagios configuration to define check commands that use the NagCollect plugins on the local and remote hosts. --- diff --git a/client/bin/nagcollecttest b/client/bin/nagcollecttest index 4bcba08..94df17a 100755 --- a/client/bin/nagcollecttest +++ b/client/bin/nagcollecttest @@ -11,15 +11,20 @@ # NAME=`basename "$0"` +VERBOSE= MAXTIME=300 +if [ "$1" = "-v" ]; then + VERBOSE=1 + shift +fi if [ $# -ne 1 ]; then - echo "Usage: $NAME " - exit 2 + echo "Usage: $NAME [-v] " + exit 3 fi if [ `id -u` -ne 0 ]; then echo "$NAME must be run as root!" - exit 2 + exit 3 fi if [ -r /usr/local/lib/nagcollect/"$1.tst" ]; then @@ -28,15 +33,25 @@ elif [ -r /usr/local/lib/nagcollect/`uname`/"$1.tst" ]; then tst=/usr/local/lib/nagcollect/`uname`/"$1.tst" else echo "$NAME: script \"$1\" not found!" - exit 2 + exit 3 fi SERVICE=""; STATUS=""; TEXT="" -echo "Checking \"$tst\" ..." +[ -n "$VERBOSE" ] && echo "Checking \"$tst\" ..." . "$tst" -[ -n "$STATUS" -o -n "$TEXT" ] \ - && echo "RESULT: $SERVICE=$STATUS \"$TEXT\"" \ - || echo "NO result ..." +if [ "$VERBOSE" ]; then + [ -n "$STATUS" -o -n "$TEXT" ] \ + && echo "RESULT: $SERVICE=$STATUS \"$TEXT\"" \ + || echo "NO result ..." +else + [ -n "$TEXT" ] \ + && echo "$TEXT" \ + || echo "$NAME: \"$1\" returned no result?" +fi + +[ -n "$STATUS" ] \ + && exit "$STATUS" \ + || exit 3 # -eof-