3 # NagCollect -- Nagios Data Collector for Passive Checks
4 # Copyright (c)2009-2011 Alexander Barton, alex@barton.de
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.
23 logger -t "$NAME" "$*"
28 function refreshTestScripts()
30 tmp=`mktemp /tmp/nagcollect.XXXXXX`
31 Msg "Downloading scripts from ${SERVER_URL} ..."
32 curl --insecure --fail --output "$tmp" --silent --max-time $MAXTIME \
33 "${SERVER_URL}/nagcollecttestscripts.tgz" ; r=$?
35 # Update local test scripts
36 Msg "Extracting scripts ..."
37 mkdir -p /usr/local/lib/nagcollect
38 tar xzf "$tmp" -C /usr/local/lib/nagcollect -po \
39 --exclude "._*" --exclude ".DS_Store" ; r=$?
41 chmod -R a+rX /usr/local/lib/nagcollect
46 function submitService()
48 curl --insecure --fail --output /dev/null --silent --max-time $MAXTIME \
49 --data "key=$CLIENT_KEY" \
50 --data "host=$CLIENT_ID" \
54 "${SERVER_URL}/nagcollect.php" ; r=$?
58 [ -r "/usr/local/etc/nagcollect.conf" ] && . /usr/local/etc/nagcollect.conf
59 [ -r "/etc/nagcollect.conf" ] && . /etc/nagcollect.conf
61 [ -n "$SERVER_URL" -a -n "$CLIENT_KEY" -a -n "$CLIENT_ID" ] || \
62 Error "Configuration invalid, check SERVER_URL, CLIENT_KEY and CLIENT_ID variables!"
64 if [ "$AUTOUPDATE" = 1 ]; then
65 Msg "Updating local test scripts:"
66 refreshTestScripts || \
67 Error "Failed to refresh test scripts from \"$SERVER_URL\" ($?)!"
70 Msg "Running test scripts:"
73 /usr/local/lib/nagcollect/*.tst \
74 /usr/local/lib/nagcollect/`uname`/*.tst \
75 2>/dev/null | while read tst; do
76 [ -r "$tst" ] || continue
77 SERVICE=""; STATUS=""; TEXT=""
78 Msg "Checking \"$tst\" ..."
80 [ -n "$SERVICE" -a -n "$STATUS" ] || continue
81 submitService "$SERVICE" "$STATUS" "$TEXT"
82 Msg "RESULT: $SERVICE=$STATUS \"$TEXT\" ($?)"