-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_rdiff_checks
executable file
·101 lines (84 loc) · 2.65 KB
/
check_rdiff_checks
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/bin/bash
#
# Check everything on a backup server has a backup check
# based on /backupdir/customer/backup dirctory format
# Prerequisites: user and ssh keys on backup server
# Usage: command server.domain "/dir/dir" "cust1 cust2/dir1"
# - exclude is optional
function checkParam() {
local name="$1"
local param="$2"
if [ -z "$param" ]; then
MESSAGE="${MESSAGE} $name"
fi
}
function trimMessage() {
MESSAGE="$(echo -e "${MESSAGE}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' )"
}
STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3
exitCode=$STATE_UNKNOWN
MESSAGE=""
LOGIN_USER="nagioschecker"
if [ -n "$1" ] && [ -n "$2" ] && [ -n "$3" ]; then
backupServer="$1"
backupRoot="$2"
depth="$3" # directory depth to look for rdiff-backup-data folders
exclude=`echo "$4" | sed -e "s/,/ /g"`
if [ `ssh -q ${LOGIN_USER}@${backupServer} exit ; echo $?` -eq 0 ]; then
# Log in to a backup server using the backup user and get list of backup dirs
backupDirs=`ssh ${LOGIN_USER}@${backupServer} "find ${backupRoot} -mindepth $depth -maxdepth $depth -type d -name rdiff-backup-data 2> /dev/null" | sed -e "s:${backupRoot}/::" | sed -e "s:/rdiff-backup-data::" | sort`
if [ $? -eq 0 ]; then
MESSAGE=""
for dir in ${backupDirs}; do
excluded=false
for part in $(seq 1 $depth) ; do # test each part of a path for exclusions
if echo " ${exclude}" 2>/dev/null | grep -q -w `echo " $dir" | cut -f1-$part -d"/"` ; then # Skip excluded name
excluded=true
fi
done
if [ $excluded = false ]; then
if ! grep "vars.rdiffs" /etc/icinga2/conf.d/* 2>/dev/null | grep -q "${dir}" ; then # Critical on missing backup checks for host
MESSAGE="${MESSAGE} ${dir}"
exitCode=$STATE_CRITICAL
fi
fi
done
if [ ${exitCode} -eq $STATE_CRITICAL ]; then
MESSAGE="Missing backup checks for `echo $MESSAGE | sed -e 's/ *$//g'`"
else
MESSAGE="No missing backup checks"
exitCode=$STATE_OK
fi
if [ -n "$2" ]; then
MESSAGE="$MESSAGE ($exclude excluded)"
fi
else
MESSAGE="Error finding backups directories"
exitCode=$STATE_CRITICAL
fi
else
MESSAGE="Unable to connect to $backupServer"
exitCode=$STATE_WARNING
fi
else
exitCode=$STATE_UNKNOWN
checkParam "server" "$1"
checkParam "directory" "$1"
checkParam "depth" "$1"
trimMessage
MESSAGE="Missing paramaters ${MESSAGE} ($@)"
fi
trimMessage
if [ $exitCode -eq $STATE_UNKNOWN ]; then
echo "UNKNOWN - $MESSAGE"
elif [ $exitCode -eq $STATE_CRITICAL ]; then
echo "CRITICAL - $MESSAGE"
elif [ $exitCode -eq $STATE_WARNING ]; then
echo "WARNING - $MESSAGE"
elif [ $exitCode -eq $STATE_OK ]; then
echo "OK - $MESSAGE"
fi
exit $exitCode