From 5dfa2918f428958bd31ba9911041928b4e49948f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A1ll=20Gu=C3=B0j=C3=B3n=20Sigur=C3=B0sson?= Date: Tue, 2 Mar 2010 03:00:09 +0000 Subject: [PATCH] check_time added --- check_time/trunk/check_time | 93 ++++++++++++++++++++++++++ check_time/trunk/nrpe.d/check_time.cfg | 4 ++ 2 files changed, 97 insertions(+) create mode 100755 check_time/trunk/check_time create mode 100644 check_time/trunk/nrpe.d/check_time.cfg diff --git a/check_time/trunk/check_time b/check_time/trunk/check_time new file mode 100755 index 0000000..5d609c5 --- /dev/null +++ b/check_time/trunk/check_time @@ -0,0 +1,93 @@ +#!/bin/sh + + + +# Nagios exit codes +OK=0 +WARN=1 +CRIT=2 +UNKNOWN=3 + +# Default warning thresholds +warning=60 +critical=86400 + + +print_help() { + echo "check_time version $VERSION" + echo "This plugin checks the time of a remote host via NRPE" + echo "" + echo "Usage: $0 -H [-w seconds] [-c seconds]" + echo "" + echo "Example: check time of host examplehost, warn if time difference is" + echo "more than 60 seconds, critical if difference is more than 86400 seconds" + echo "# check_time -H examplehost -w 60 -c 86400" +} + +if [ $# -eq 0 ]; then + print_help ; + exit $UNKNOWN +fi + + +# Parse arguments +while [ $# -gt 0 ] +do + case $1 + in + -H) + hostaddress=$2 + shift 2 + ;; + + + -w) + warning=$2 + shift 2 + ;; + + -c) + critical=$2 + shift 2 + ;; + + *) + print_help ; + exit $UNKNOWN + ;; + esac +done + +LOCALTIME=`/bin/date +%s` +REMOTETIME=`/usr/lib/nagios/plugins/check_nrpe -H $hostaddress -c get_time` + +for i in $warning $critical ; do + if [ ! $i -ge 0 ]; then + echo "$i is not a valid value. Should be in seconds. See --help for usage." + exit $UNKNOWN + fi +done + + + +DIFF=$(echo $LOCALTIME-$REMOTETIME | bc ) + +if [ $DIFF -lt 0 ]; then + DIFF=$(echo $DIFF*-1|bc) +fi + +RESULT="timedrift=$DIFF seconds | timedrift=${DIFF}s;$warning;$critical" + +if [ $DIFF -gt $critical ]; then + echo "CRITICAL - $RESULT" + exit $CRIT +fi + +if [ $DIFF -gt $warning ]; then + echo "WARNING - $RESULT" + exit $WARN +fi + + +echo "OK - $RESULT" +exit 0 diff --git a/check_time/trunk/nrpe.d/check_time.cfg b/check_time/trunk/nrpe.d/check_time.cfg new file mode 100644 index 0000000..f09c86f --- /dev/null +++ b/check_time/trunk/nrpe.d/check_time.cfg @@ -0,0 +1,4 @@ + +# Connect to a remote host via nrpe and check time +# warning and critical are in seconds +command[check_time]=/usr/lib/nagios/plugins/check_time -H $ARG1$ -w $ARG2$ -c $ARG3$