forked from ckujau/nagios-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_crashplan_backup.sh
executable file
·54 lines (47 loc) · 1.58 KB
/
check_crashplan_backup.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/bin/sh
#
# (c)2016 Christian Kujau <lists@nerdbynature.de>
# Check for the last completed Crashplan Backup
#
# ACLs needed:
# > setfacl -m u:nrpe:x /opt/crashplan{,/cache{,/42}}
# > setfacl -m u:nrpe:r /opt/crashplan/cache/42/cp.properties
#
while getopts "f:w:c:" opt; do
case $opt in
f) file="$OPTARG" ;;
w) warn="$OPTARG" ;;
c) crit="$OPTARG" ;;
*) exit 3;;
esac
done
# Sanity checks
if [ ! -f "$file" ] || [ -z "$warn" ] || [ -z "$crit" ]; then
echo "Usage: $(basename "$0") -f [cp.properties] -w [hours] -c [hours]"
exit 3
fi
# The cp.properties file appears to provide some status information, but
# it's not documented by Code42 nor does it seem to be well structured:
# $ cat ../cp.properties
# [...]
# lastCompletedBackupTimestamp_1=2017-02-14T23\:34\:26\:582
# lastCompletedBackupTimestamp=2017-02-14T23\:34\:26\:582
# lastBackupTimestamp=2017-02-14T23\:34\:26\:582
# lastBackupTimestamp_1=2017-02-14T23\:34\:26\:582
#
# Let's use "lastCompletedBackupTimestamp" for now, until it breaks.
last=$(date -d "$(awk -F= '/^lastCompletedBackupTimestamp=/ {print $2}' "$file" | sed 's|T| |;s|\\||g;s|:[0-9]*$||')" +%s)
# Get the current time & date in epoch time
curr=$(date +%s)
# Difference in hours (rounded down, w/o decimals)
diff=$(((curr - last) / 60 / 60))
if [ $diff -ge "$crit" ]; then
echo "CRITICAL: Last backup completed $diff hours ago! ($(date -d @"$last"))"
exit 2
elif [ $diff -ge "$warn" ]; then
echo "WARNING: Last backup completed $diff hours ago! ($(date -d @"$last"))"
exit 1
else
echo "OK: Last backup completed $diff hours ago. ($(date -d @"$last"))"
exit 0
fi