]> arthur.barton.de Git - nagcollect.git/commitdiff
Ehnance nagcollecttest, now it is a "nagios plugin wrapper"
authorAlexander Barton <alex@barton.de>
Wed, 22 Aug 2012 14:00:15 +0000 (16:00 +0200)
committerAlexander Barton <alex@barton.de>
Wed, 22 Aug 2012 14:00:15 +0000 (16:00 +0200)
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.

client/bin/nagcollecttest

index 4bcba08f81923d29c0e145d12ac5a1e834516153..94df17a5c95e7cf273d2d5715bba3c19eef1fa5e 100755 (executable)
 #
 
 NAME=`basename "$0"`
 #
 
 NAME=`basename "$0"`
+VERBOSE=
 MAXTIME=300
 
 MAXTIME=300
 
+if [ "$1" = "-v" ]; then
+       VERBOSE=1
+       shift
+fi
 if [ $# -ne 1 ]; then
 if [ $# -ne 1 ]; then
-       echo "Usage: $NAME <scriptname>"
-       exit 2
+       echo "Usage: $NAME [-v] <scriptname>"
+       exit 3
 fi
 if [ `id -u` -ne 0 ]; then
        echo "$NAME must be run as root!"
 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
 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!"
        tst=/usr/local/lib/nagcollect/`uname`/"$1.tst"
 else
        echo "$NAME: script \"$1\" not found!"
-       exit 2
+       exit 3
 fi
 
 SERVICE=""; STATUS=""; TEXT=""
 fi
 
 SERVICE=""; STATUS=""; TEXT=""
-echo "Checking \"$tst\" ..."
+[ -n "$VERBOSE" ] && echo "Checking \"$tst\" ..."
 . "$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-
 
 # -eof-