aboutsummaryrefslogtreecommitdiff
path: root/modules/profile/files/monitoring/check_last_file_date
diff options
context:
space:
mode:
authorIsmaël Bouya <ismael.bouya@normalesup.org>2018-07-11 09:31:24 +0200
committerIsmaël Bouya <ismael.bouya@normalesup.org>2018-07-11 09:31:24 +0200
commit2bdbb0213a0f70705f81ac2eaf8349668b2c29b4 (patch)
tree06b1e40db99815133dcc40e3e68531d45e1bd228 /modules/profile/files/monitoring/check_last_file_date
parent25c99a635507abfe6af4a1f0a9fc5a103d1880c0 (diff)
parentd8bc769648c1528f5d749deee060d70e326ef431 (diff)
downloadPuppet-2bdbb0213a0f70705f81ac2eaf8349668b2c29b4.tar.gz
Puppet-2bdbb0213a0f70705f81ac2eaf8349668b2c29b4.tar.zst
Puppet-2bdbb0213a0f70705f81ac2eaf8349668b2c29b4.zip
Merge branch 'monitoring' into dev
Diffstat (limited to 'modules/profile/files/monitoring/check_last_file_date')
-rw-r--r--modules/profile/files/monitoring/check_last_file_date31
1 files changed, 31 insertions, 0 deletions
diff --git a/modules/profile/files/monitoring/check_last_file_date b/modules/profile/files/monitoring/check_last_file_date
new file mode 100644
index 0000000..8eabb57
--- /dev/null
+++ b/modules/profile/files/monitoring/check_last_file_date
@@ -0,0 +1,31 @@
1#!/bin/bash
2
3STATE_OK=0
4STATE_WARNING=1
5STATE_CRITICAL=2
6STATE_UNKNOWN=3
7
8base_path=$1
9hours=$2
10as_user=$3
11
12if [ -z "$as_user" ]; then
13 last_date=$(find $base_path -mindepth 1 -maxdepth 1 -printf "%T@\n" 2>/dev/null | sort | tail -n 1)
14else
15 last_date=$(sudo -u "$as_user" find $base_path -mindepth 1 -maxdepth 1 -printf "%T@\n" 2>/dev/null | sort | tail -n 1)
16fi
17
18if [ -z "$last_date" ]; then
19 echo "UNKNOWN: Could not read folder"
20 exit $STATE_UNKNOWN
21else
22 LC_ALL=C last_date=$(printf "%.*f" 0 $last_date)
23 min_date=$(date -d "$hours hours ago" "+%s")
24 if [ "$min_date" -lt "$last_date" ]; then
25 echo "OK: Last backup $(date -d @$last_date)"
26 exit $STATE_OK
27 else
28 echo "CRITICAL: Last backup $(date -d @$last_date)"
29 exit $STATE_CRITICAL
30 fi
31fi