Nagios - files created the last # days
Um z.B. mit Nagios die Aktualität eines Virenscanners zu überprüfen bietet es sich an zu verifizieren ob bestmmte Dateien, in diesem Fall die Signaturen für den Virenscanner, aktuell sind.Eine Möglichkeit dies zu realisieren stellt das folgende Script dar.
#!/bin/bash
# scans files that match the pattern in path for creation age in days
# and counts them. If there are no files that were created between
# today and $warning_age ago issue a warning.
# If there are no files that were created between today and $critical_age
# ago issue critial state.
#
# rs - 20160413
#
FIND=/usr/bin/find
WC=/usr/bin/wc
PROGNAME=`/usr/bin/basename $0`
PROGPATH=`echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,'`
REVISION="0.1"
. $PROGPATH/utils.sh
print_usage() {
echo "Usage: $PROGNAME <path_to_scan> <filepattern> <critical_age (days)> <warning_age (days)>"
echo "Usage: $PROGNAME --help"
echo "Usage: $PROGNAME --version"
}
if [ $# -lt 4 ]; then
print_usage
exit $STATE_UNKNOWN
fi
if [ $3 -lt $4 ]; then
echo "critical_age can't be lower than warning_age"
exit $STATE_UNKNOWN
fi
if [ ! -d $1 ]; then
echo "given path $1 does not exist"
exit $STATE_UNKNOWN
fi
exitstatus=$STATE_WARNING
SCANPATH=$1
SCANPATT=$2
SCANCRIT=$3
SCANWARN=$4
NRBELOWWARN=`$FIND $SCANPATH/$SCANPATT -ctime -$SCANWARN | $WC -l`
NRBELOWCRIT=`$FIND $SCANPATH/$SCANPATT -ctime -$SCANCRIT | $WC -l`
# echo "# < warn::"$NRBELOWWARN" # < crit::"$NRBELOWCRIT
if [ $NRBELOWCRIT -lt 1 ]; then
echo "CRITICAL: There are no files below $SCANPATH that were created the last $SCANCRIT days!"
exit $STATE_CRITICAL
elif [ $NRBELOWWARN -lt 1 ]; then
echo "WARNING: There are no files below $SCANPATH that were created the last $SCANWARN days!"
exit $STATE_WARNING
else
echo "OK: $SCANPATH contains up-to-date files matching $2"
exit $STATE_OK
fi