X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=flakes%2Fprivate%2Fmonitoring%2Fplugins%2Fcheck_last_file_date;fp=flakes%2Fprivate%2Fmonitoring%2Fplugins%2Fcheck_last_file_date;h=f51a25814c08e3e161842dbb56305a12294de11c;hb=1a64deeb894dc95e2645a75771732c6cc53a79ad;hp=0000000000000000000000000000000000000000;hpb=fa25ffd4583cc362075cd5e1b4130f33306103f0;p=perso%2FImmae%2FConfig%2FNix.git diff --git a/flakes/private/monitoring/plugins/check_last_file_date b/flakes/private/monitoring/plugins/check_last_file_date new file mode 100755 index 0000000..f51a258 --- /dev/null +++ b/flakes/private/monitoring/plugins/check_last_file_date @@ -0,0 +1,28 @@ +#!/bin/bash + +STATE_OK=0 +STATE_WARNING=1 +STATE_CRITICAL=2 +STATE_UNKNOWN=3 + +base_path=$1 +hours=$2 + +last_date=$(find $base_path -mindepth 1 -maxdepth 1 -printf "%T@\n" 2>/dev/null | sort | tail -n 1) + +if [ -z "$last_date" ]; then + echo "UNKNOWN: Could not read folder" + exit $STATE_UNKNOWN +else + LC_ALL=C last_date=$(printf "%.*f" 0 $last_date) + LC_ALL=C age=$(( $(date "+%s") - $last_date)) + max_age=$(( $hours * 60 * 60 )) + min_date=$(date -d "$hours hours ago" "+%s") + if [ "$min_date" -lt "$last_date" ]; then + echo "OK: Last file $(date -d @$last_date) | age=${age}s;;$max_age;;" + exit $STATE_OK + else + echo "CRITICAL: Last file $(date -d @$last_date) | age=${age}s;;$max_age;;" + exit $STATE_CRITICAL + fi +fi