]> arthur.barton.de Git - nagcollect.git/blob - client/bin/nagcollecttest
94df17a5c95e7cf273d2d5715bba3c19eef1fa5e
[nagcollect.git] / client / bin / nagcollecttest
1 #!/bin/bash
2 #
3 # NagCollect -- Nagios Data Collector for Passive Checks
4 # Copyright (c)2009-2011 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 /usr/local/lib/nagcollect/"$1.tst" ]; then
31         tst=/usr/local/lib/nagcollect/"$1.tst"
32 elif [ -r /usr/local/lib/nagcollect/`uname`/"$1.tst" ]; then
33         tst=/usr/local/lib/nagcollect/`uname`/"$1.tst"
34 else
35         echo "$NAME: script \"$1\" not found!"
36         exit 3
37 fi
38
39 SERVICE=""; STATUS=""; TEXT=""
40 [ -n "$VERBOSE" ] && echo "Checking \"$tst\" ..."
41 . "$tst"
42
43 if [ "$VERBOSE" ]; then
44         [ -n "$STATUS" -o -n "$TEXT" ] \
45                 && echo "RESULT: $SERVICE=$STATUS \"$TEXT\"" \
46                 || echo "NO result ..."
47 else
48         [ -n "$TEXT" ] \
49                 && echo "$TEXT" \
50                 || echo "$NAME: \"$1\" returned no result?"
51 fi
52
53 [ -n "$STATUS" ] \
54         && exit "$STATUS" \
55         || exit 3
56
57 # -eof-