blob: 13bdecca2d4ca3938028c82923f75fbc0c8c3392 (
plain)
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
|
#!/bin/bash
STALE_DIR="${HOME}/var/stale/"
get_names() {
/usr/sbin/bcfg2-reports "$@" --fields=name | sed 's/ *$//'
}
get_extra() {
get_names | while read i ; do test -z "$(/usr/sbin/bcfg2-reports -e $i)" || echo $i ; done
}
get_stale() {
get_names --stale | sed 's/ *$//'
}
get_all() {
get_names -a | sed 's/ *$//'
}
get_bad() {
get_names -d | sed 's/ *$//'
}
get_clean() {
get_names -c | sed 's/ *$//'
}
get_nagios() {
clean=$(get_clean | wc -l)
bad=$(get_bad | wc -l)
extra=$(get_extra | wc -l)
stale=$(get_stale | wc -l)
status="OK"
exit=0
if [ "$bad" != "0" -o "$stale" != "0" ]; then
status="CRITICAL"
exit=2
fi
echo "$status | clean=$clean; bad=$bad; extra=$extra; stale=$stale;"
exit $exit
}
get_stale_once() {
get_stale | while read host; do
STALE_FILE="${STALE_DIR}/${host}"
test -f "${STALE_FILE}" || (
touch "${STALE_FILE}"
echo $host
)
done
comm -13 <(get_stale | sort) <(get_all | sort) | while read host; do
STALE_FILE="${STALE_DIR}/${host}"
test -f "${STALE_FILE}" && rm -f "${STALE_FILE}"
done
}
cron() {
stale=$(get_stale_once)
if [ -n "$stale" ]; then
sendmail -t <<EOM
To: bcfg2-admins@spline.inf.fu-berlin.de
From: cron@bcfg2.spline.inf.fu-berlin.de
Subject: New stale hosts
Hallo,
die folgenden Hosts haben sich seit 24h nicht mehr bei bcfg2 gemeldet:
$(echo "$stale" | sed 's/^/ /')
Gruß,
bcfg2
EOM
fi
}
show_usage() {
cat <<EOU
Usage:
$0 [mode]
mode should be one of the following:
-a|--all display all hosts
-b|--bad display bad hosts
-s|--stale display hosts, that haven't run in the last 24 hours
-e|--extra display hosts with extra entries
-c|--cron run in cron mode (report new stale hosts)
-n|--nagios run in nagios mode (report count hosts in groups)
EOU
}
optarr=( $(getopt -o 'absecn' --long 'all,bad,stale,extra,cron,nagios' -- "$@") )
i=0
while true; do
case ${optarr[$i]} in
-a|--all)
get_all
exit 0
;;
-b|--bad)
get_bad
exit 0
;;
-s|--stale)
get_stale
exit 0
;;
-e|--extra)
get_extra
exit 0
;;
-c|--cron)
cron
exit 0
;;
-n|--nagios)
get_nagios
exit 0
;;
*)
show_usage
exit 1
;;
esac
((i++))
done
exit 0
|