diff --git a/README.md b/README.md index 3a754ad..599dad4 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/monitoring/check_lastdate.sh b/monitoring/check_lastdate.sh new file mode 100755 index 0000000..9179efb --- /dev/null +++ b/monitoring/check_lastdate.sh @@ -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 ]" + 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 " + 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 +