]> git.immae.eu Git - perso/Immae/Config/Nix.git/blob - modules/private/monitoring/plugins/check_last_file_date
Add monitoring for backup-2
[perso/Immae/Config/Nix.git] / modules / private / monitoring / plugins / check_last_file_date
1 #!/bin/bash
2
3 STATE_OK=0
4 STATE_WARNING=1
5 STATE_CRITICAL=2
6 STATE_UNKNOWN=3
7
8 base_path=$1
9 hours=$2
10
11 last_date=$(find $base_path -mindepth 1 -maxdepth 1 -printf "%T@\n" 2>/dev/null | sort | tail -n 1)
12
13 if [ -z "$last_date" ]; then
14 echo "UNKNOWN: Could not read folder"
15 exit $STATE_UNKNOWN
16 else
17 LC_ALL=C last_date=$(printf "%.*f" 0 $last_date)
18 min_date=$(date -d "$hours hours ago" "+%s")
19 if [ "$min_date" -lt "$last_date" ]; then
20 echo "OK: Last file $(date -d @$last_date)"
21 exit $STATE_OK
22 else
23 echo "CRITICAL: Last file $(date -d @$last_date)"
24 exit $STATE_CRITICAL
25 fi
26 fi