]> arthur.barton.de Git - nagcollect.git/blobdiff - client/bin/nagcollecttest
Remove OS X packaging scripts
[nagcollect.git] / client / bin / nagcollecttest
index e31644fccd4a56b09124bb3af7b79658032fe467..84d66bf0c90ebb0b6766d4dd1f07d47b9f4c1a16 100755 (executable)
@@ -1,7 +1,7 @@
 #!/bin/bash
 #
 # NagCollect -- Nagios Data Collector for Passive Checks
-# Copyright (c)2009-2011 Alexander Barton, alex@barton.de
+# Copyright (c)2009-2012 Alexander Barton, alex@barton.de
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 #
 
 NAME=`basename "$0"`
+VERBOSE=
 MAXTIME=300
 
+if [ "$1" = "-v" ]; then
+       VERBOSE=1
+       shift
+fi
 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!"
-       exit 2
+       exit 3
 fi
 
-if [ -r /usr/local/lib/nagcollect/"$1.tst" ]; then
+if [ -r "$1" ]; then
+       tst="$1"
+elif [ -r /usr/local/lib/nagcollect/"$1.tst" ]; then
        tst=/usr/local/lib/nagcollect/"$1.tst"
 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"
-echo "RESULT: $SERVICE=$STATUS \"$TEXT\""
+
+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-