check_lastdate.sh: check for a +%Y-%m-%d %H:%M:%S-formated date in the last two lines of a file

This commit is contained in:
n 2021-02-25 23:01:34 +01:00
parent b833384de9
commit ba55b6f6c7
Signed by: n
GPG key ID: E96086FC951DAE30
2 changed files with 68 additions and 0 deletions

View file

@ -41,6 +41,7 @@ Monitoring
* [check_postgresql_replication.sh](https://forge.tourmentine.com/n/scripts/src/master/monitoring/check_postgresql_replication.sh) => check postgresql's replication lag.
* [check_rspamc](https://forge.tourmentine.com/n/scripts/src/master/monitoring/check_rspamc) => Check rspamd status. Heavily based on [check_spamc](https://www.vanheusden.com/Linux/check_spamc-0.1.tgz).
* [check_gemini.sh](https://forge.tourmentine.com/n/scripts/src/master/monitoring/check_gemini.sh) => Nagios/Icinga check for Gemini capsule availability. Requires gnutls for now (not tested with other tls clients).
* [check_lastdate.sh](https://forge.tourmentine.com/n/scripts/src/master/monitoring/check_lastdate.sh) => Check for a +%Y-%m-%d %H:%M:%S-formated date in the last two lines of a file.
* [GonKyrellM](https://forge.tourmentine.com/n/scripts/src/master/monitoring/GonKyrellM) => Conky, GKrellM style - with "invisible" theme (well, sort of)
* [collectweather.sh](https://forge.tourmentine.com/n/scripts/src/master/monitoring/collectweather.sh) => get weather data from https://darksky.net/ and feed collectd with it. needs jq as Dark Sky provides data in json format.

67
monitoring/check_lastdate.sh Executable file
View file

@ -0,0 +1,67 @@
#!/bin/sh
# checks for a +%Y-%m-%d %H:%M:%S-formated date in the last two lines of a file
# default values:
# 60s*60m*4h
warning=14400
# 60s+60m*24h
critical=86400
OPTIND=1
while getopts "hF:C:W:" opt; do
case "$opt" in
h)
echo "Usage: $0 [-h] [-w warning (default: $warning)] [-c critical (default: $critical) -F <filename>]"
exit 3
;;
W)
warning=$OPTARG
;;
C)
critical=$OPTARG
;;
F)
file=$OPTARG
;;
esac
done
shift $((OPTIND-1))
[ "$1" = "--" ] && shift
if [ -z ${file} ]
then
echo "ERROR: please provide filename to parse with $0 -F <filename>"
exit 3
fi
lastdate=$(tail -2 ${file} | grep -o -E '^[[:digit:]]{4}-[[:digit:]]{2}-[[:digit:]]{2} [[:digit:]]{2}:[[:digit:]]{2}:[[:digit:]]{2}')
lastts=$(date -d "${lastdate}" +%s)
currentts=$(date +%s)
if [ "x${lastts}" != "x" ]
then
delay=$(echo "${currentts}-${lastts}" | bc)
else
echo "UNKNOWN: date not found"
exit 3
fi
message=$(echo "${file} not updated since ${delay} seconds")
if [ ${delay} -gt ${critical} ]
then
echo "CRITICAL: ${message}"
exit 2
elif [ ${delay} -gt ${warning} ]
then
echo "WARNING: ${message}"
exit 1
else
echo "OK: ${message}"
exit 0
fi