aboutsummaryrefslogtreecommitdiff
path: root/flakes/private/monitoring/plugins/check_last_file_date
diff options
context:
space:
mode:
Diffstat (limited to 'flakes/private/monitoring/plugins/check_last_file_date')
-rwxr-xr-xflakes/private/monitoring/plugins/check_last_file_date28
1 files changed, 28 insertions, 0 deletions
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 @@
1#!/bin/bash
2
3STATE_OK=0
4STATE_WARNING=1
5STATE_CRITICAL=2
6STATE_UNKNOWN=3
7
8base_path=$1
9hours=$2
10
11last_date=$(find $base_path -mindepth 1 -maxdepth 1 -printf "%T@\n" 2>/dev/null | sort | tail -n 1)
12
13if [ -z "$last_date" ]; then
14 echo "UNKNOWN: Could not read folder"
15 exit $STATE_UNKNOWN
16else
17 LC_ALL=C last_date=$(printf "%.*f" 0 $last_date)
18 LC_ALL=C age=$(( $(date "+%s") - $last_date))
19 max_age=$(( $hours * 60 * 60 ))
20 min_date=$(date -d "$hours hours ago" "+%s")
21 if [ "$min_date" -lt "$last_date" ]; then
22 echo "OK: Last file $(date -d @$last_date) | age=${age}s;;$max_age;;"
23 exit $STATE_OK
24 else
25 echo "CRITICAL: Last file $(date -d @$last_date) | age=${age}s;;$max_age;;"
26 exit $STATE_CRITICAL
27 fi
28fi