]> arthur.barton.de Git - nagcollect.git/blob - client/bin/nagcollecttest
nagcollecttest: Accept full path names to test script
[nagcollect.git] / client / bin / nagcollecttest
1 #!/bin/bash
2 #
3 # NagCollect -- Nagios Data Collector for Passive Checks
4 # Copyright (c)2009-2012 Alexander Barton, alex@barton.de
5 #
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
10 # Please read the file COPYING, README and AUTHORS for more information.
11 #
12
13 NAME=`basename "$0"`
14 VERBOSE=
15 MAXTIME=300
16
17 if [ "$1" = "-v" ]; then
18         VERBOSE=1
19         shift
20 fi
21 if [ $# -ne 1 ]; then
22         echo "Usage: $NAME [-v] <scriptname>"
23         exit 3
24 fi
25 if [ `id -u` -ne 0 ]; then
26         echo "$NAME must be run as root!"
27         exit 3
28 fi
29
30 if [ -r "$1" ]; then
31         tst="$1"
32 elif [ -r /usr/local/lib/nagcollect/"$1.tst" ]; then
33         tst=/usr/local/lib/nagcollect/"$1.tst"
34 elif [ -r /usr/local/lib/nagcollect/`uname`/"$1.tst" ]; then
35         tst=/usr/local/lib/nagcollect/`uname`/"$1.tst"
36 else
37         echo "$NAME: script \"$1\" not found!"
38         exit 3
39 fi
40
41 SERVICE=""; STATUS=""; TEXT=""
42 [ -n "$VERBOSE" ] && echo "Checking \"$tst\" ..."
43 . "$tst"
44
45 if [ "$VERBOSE" ]; then
46         [ -n "$STATUS" -o -n "$TEXT" ] \
47                 && echo "RESULT: $SERVICE=$STATUS \"$TEXT\"" \
48                 || echo "NO result ..."
49 else
50         [ -n "$TEXT" ] \
51                 && echo "$TEXT" \
52                 || echo "$NAME: \"$1\" returned no result?"
53 fi
54
55 [ -n "$STATUS" ] \
56         && exit "$STATUS" \
57         || exit 3
58
59 # -eof-