forked from ckujau/nagios-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_rsnapshot-completed.sh
executable file
·59 lines (51 loc) · 1.39 KB
/
check_rsnapshot-completed.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
55
56
57
58
59
#!/bin/sh
#
# (c)2015 Christian Kujau <lists@nerdbynature.de>
# Nagios plugin to check for completed backups created with rsnapshot-wrapper.
#
# TODO: Check that enough hosts are being backed up!
#
CONFDIR="/etc/rsnapshot"
LOGFILE="/var/log/rsnapshot/rsnapshot-wrapper.log"
if [ -z "$1" ]; then
echo "Usage: $(basename "$0") [days]"
exit 3
else
DAYS="$1"
fi
# Let's create the date(1) strings to search for. It's messy, but it works
# with GNU/date
SEARCH=$(for i in $(seq 0 "$DAYS"); do
date -d "${i} days ago" +%Y-%m-%d
done | xargs echo | sed 's/ /|/g')
ERR=0
for f in "$CONFDIR"/*.conf; do
# Skip hosts where missing backups can be ignored.
grep -Fq '##Nagios:check_rsnapshot-completed:ignore' "$f" && continue
unset HOST NAME
eval "$(awk -F\# '/^##HOST=/ {print $3}' "$f" | sed 's/PORT.*//')"
# Sometimes NAME != HOST in the configuration file
if [ -n "$NAME" ]; then
host="$NAME"
else
host="$HOST"
fi
if grep "$host" "$LOGFILE" | grep -E 'finished|already has a daily backup from today' | grep -Eq "^(${SEARCH})"; then
MSG="${MSG}$host "
ERR=$((ERR+1))
fi
done
IGN=" ($(grep -Fl '##Nagios:check_rsnapshot-completed:ignore' "$CONFDIR"/*.conf | wc -l) hosts ignored)"
case $ERR in
0)
echo "OK - Every host made a backup in the last $DAYS days.${IGN}"
exit 0
;;
[1-9]*)
echo "NOK: No backups found for the last $DAYS days for: $MSG ${IGN}"
exit 2
;;
*)
echo "UNKNOWN"
;;
esac