зеркало из https://github.com/mozilla/pjs.git
105 строки
2.0 KiB
Bash
Executable File
105 строки
2.0 KiB
Bash
Executable File
#! /bin/bash
|
|
#
|
|
# Checks to see if data has been updated recently.
|
|
#
|
|
# Copyright 2005 Robert Helmer
|
|
# Author: Robert Helmer <robert@roberthelmer.com>
|
|
|
|
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
|
|
|
|
PROGNAME=`basename $0`
|
|
PROGPATH=`echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,'`
|
|
NAGIOS_PLUGIN_PATH='/usr/lib/nagios/plugins'
|
|
REVISION=`echo '$Revision 1.2 $' | sed -e 's/[^0-9.]//g'`
|
|
# current date in unix time
|
|
DATE=`perl -e 'print time'`
|
|
|
|
. $NAGIOS_PLUGIN_PATH/utils.sh
|
|
|
|
while getopts "f:a:" options
|
|
do
|
|
case "$options" in
|
|
f)
|
|
# data to check
|
|
DATAFILE=$OPTARG
|
|
if test -f $DATAFILE
|
|
then
|
|
echo -n
|
|
else
|
|
echo "CRITICAL: `basename $DATAFILE` does not exist!"
|
|
exit 127
|
|
fi
|
|
;;
|
|
a)
|
|
# allowed age of file, in seconds
|
|
ALLOWED_AGE=$OPTARG
|
|
;;
|
|
esac
|
|
done
|
|
|
|
print_usage() {
|
|
echo "Usage: $PROGNAME -a <age> -f <filename_to_check>"
|
|
}
|
|
|
|
print_help() {
|
|
print_revision $PROGNAME $REVISION
|
|
echo ""
|
|
print_usage
|
|
echo ""
|
|
echo "This plugin checks file modification time to see if we're getting"
|
|
echo "new data consistently."
|
|
echo ""
|
|
support
|
|
exit 0
|
|
}
|
|
|
|
case "$1" in
|
|
--help)
|
|
print_help
|
|
exit 0
|
|
;;
|
|
-h)
|
|
print_help
|
|
exit 0
|
|
;;
|
|
--version)
|
|
print_revision $PROGNAME $REVISION
|
|
exit 0
|
|
;;
|
|
-V)
|
|
print_revision $PROGNAME $REVISION
|
|
exit 0
|
|
;;
|
|
*)
|
|
if test -z $DATAFILE
|
|
then
|
|
print_usage
|
|
exit 1
|
|
fi
|
|
|
|
if test -z $ALLOWED_AGE
|
|
then
|
|
print_usage
|
|
exit 1
|
|
fi
|
|
|
|
# mtime of file in unix time
|
|
MTIME=`perl -e '$c=(stat "'$DATAFILE'")[10] ; print "$c"'`
|
|
DIFF=`expr $DATE - $MTIME`
|
|
TIMER=`expr $ALLOWED_AGE - $DIFF`
|
|
if test $TIMER -gt 0
|
|
then
|
|
ALLOWED_AGE=`expr $ALLOWED_AGE / 3600`
|
|
DIFF=`expr $DIFF / 3600`
|
|
echo "OK: `basename $DATAFILE` is $DIFF hours old (threshold = $ALLOWED_AGE hours)"
|
|
exit 0
|
|
else
|
|
ALLOWED_AGE=`expr $ALLOWED_AGE / 3600`
|
|
DIFF=`expr $DIFF / 3600`
|
|
echo "CRITICAL: `basename $DATAFILE` is $DIFF hours old (threshold = $ALLOWED_AGE hours)"
|
|
exit 2
|
|
fi
|
|
;;
|
|
esac
|
|
|