retire da-backup checks
[mirror/dsa-nagios.git] / dsa-nagios-checks / checks / dsa-check-dabackup-server
1 #!/bin/sh
2
3 # some tests weasel uses to check if da-backup is properly configured:
4 # Copyright 2008 Peter Palfrader
5 #
6 # Permission is hereby granted, free of charge, to any person obtaining
7 # a copy of this software and associated documentation files (the
8 # "Software"), to deal in the Software without restriction, including
9 # without limitation the rights to use, copy, modify, merge, publish,
10 # distribute, sublicense, and/or sell copies of the Software, and to
11 # permit persons to whom the Software is furnished to do so, subject to
12 # the following conditions:
13 #
14 # The above copyright notice and this permission notice shall be
15 # included in all copies or substantial portions of the Software.
16 #
17 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
25
26 set -e
27 set -u
28
29 AUTHKEYSFILE=/etc/ssh/userkeys/root
30 BASE=/srv/backups/da-backup
31
32 err=0
33
34 log() {
35         if [ "$1" = "warn" ] && [ "$err" -lt 1 ]; then
36                 err=1
37         elif [ "$1" = "critical" ] && [ "$err" -lt 2 ]; then
38                 err=2
39         elif [ "$1" = "unknown" ] && [ "$err" = 0 ]; then
40                 err=3
41         fi
42 }
43
44 cd /etc/da-backup-manager
45
46 # check that the files have proper names
47 for i in *; do
48         s=`cat "$i" | awk -F = '$1=="source" {print $2}'`
49         if [ "$s" = "master.debian.org/debian" ] && [ "$i" = "listarchive" ]; then
50                 # historical exception
51                 continue
52         fi
53         if [ "`echo $s | tr / -`" != "$i" ]; then
54                 log warn
55                 echo "Mismatch: Filename $i but backup source $s"
56         fi
57 done
58
59 # and that source == destination everywhere
60 for i in *; do
61         s=`cat $i | awk -F = '$1=="source"{print $2}'`
62         d=`cat $i | awk -F = '$1=="destination"{print $2}'`
63         if [ "$d" != "$s" ]; then
64                 log warn
65                 echo "source != dest in $i. ($s != $d)"
66         fi
67 done
68
69 # check that everything that has an entry in authorized_keys has one in /etc/da-backup-manager
70 rsync_targets=`tempfile`
71 backup_manager_sources=`tempfile`
72 trap "rm -f '$rsync_targets' '$backup_manager_sources'" 0 1 2 5 15
73 cat "$AUTHKEYSFILE" |
74         grep '^command=' |
75         sed -e 's/",no-por.*//' -e 's/.*--ignore-errors . //' -e "s#${BASE}/staging/##" |
76         grep -v 'command="/usr/lib/da-backup/da-backup-ssh-wrap ' |
77         sort > "$rsync_targets"
78
79 wildcard_hosts=`cat "$AUTHKEYSFILE" | grep 'command="/usr/lib/da-backup/da-backup-ssh-wrap ' | sed -e 's/.*da-backup-ssh-wrap \([a-z0-9.]*\)".*/\1/' | tr '\n' '|' | sed 's/|$//'`
80 grep -h '^source' /etc/da-backup-manager/* |
81         sed -e 's/source=//' |
82         egrep -v "^($wildcard_hosts)/" |
83         sort > "$backup_manager_sources"
84 if ! diff "$rsync_targets" "$backup_manager_sources" > /dev/null; then
85         log warn
86         echo "authorized_keys vs. /etc/da-backup-manage mismatch:"
87         diff "$rsync_targets" "$backup_manager_sources"
88 fi
89
90 # check that everything listed as either source or destination by da-backup-manager does exist  -  if stuff is new it might still be missing tho
91 for i in `awk -F = '$1=="source"     {print $2}' /etc/da-backup-manager/* `; do
92         if ! [ -d "${BASE}/staging/$i" ]; then
93                 log warn
94                 echo "Warning: source $i does not exist"
95         fi
96 done
97 for i in ` awk -F = '$1=="destination"{print $2}' /etc/da-backup-manager/* `; do
98         if ! [ -d "${BASE}/backups/$i" ]; then
99                 log warn
100                 echo "Warning: destination $i does not exist (if it is new, it takes a day)"
101         fi
102 done
103
104 # check that everything that does exist has an entry in da-backup-manager
105 cd "${BASE}/staging"
106 for i in */*; do
107         if ! [ -d "$i" ]; then
108                 log warn
109                 echo "WTF: staging/$i is not a dir"
110                 continue
111         fi
112         if ! grep "source=$i" /etc/da-backup-manager/* > /dev/null; then
113                 log warn
114                 echo "staging/$i is not listed anywhere in /etc/da-backup-manager"
115         fi
116 done
117 cd "${BASE}/backups"
118 for i in */*; do
119         if ! [ -d "$i" ]; then
120                 log warn
121                 echo "WTF: backups/$i is not a dir"
122                 continue
123         fi
124         if ! grep "destination=$i" /etc/da-backup-manager/* > /dev/null; then
125                 log warn
126                 echo "backups/$i is not listed anywhere in /etc/da-backup-manager"
127         fi
128 done
129
130 if [ "$err" = 0 ]; then
131         echo "da-backup seems to be properly configured"
132 fi
133 exit $err