blob: 36623f90a3e7b6bab3b1c0c493b7c9e772fa94ce (
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
|
#!/bin/sh
#
# Author: Petter Reinholdtsen
set -e
daylimit=120
makewebreport=/usr/sbin/sitesummary-makewebreport
nodes=/usr/sbin/sitesummary-nodes
nagiosopts=-r
# Modify this in collector.cfg to /etc/munin/ to automatically replace
# the default munin configuration.
MUNINDIR=/var/lib/sitesummary
# Specifies where to save the automatically generated nagios
# configuration. Add NAGIOSCFG="/etc/nagios3/sitesummary.cfg" to
# /etc/default/nagios3 toget Nagios to use this automatically
# generated configuration
NAGIOSDIR=/var/lib/sitesummary
[ -f /etc/sitesummary/collector.cfg ] && . /etc/sitesummary/collector.cfg
# Exit imediately if the package is removed but nor purged
if [ ! -x $nodes ] ; then
exit 0
fi
# The storage area is not configurable, because too many scripts have
# it hardcoded
entriesdir=/var/lib/sitesummary/entries
remove_old_entries() {
find $entriesdir/. -mindepth 1 -maxdepth 1 -type d \
-daystart -mtime +$daylimit \
-exec /usr/lib/sitesummary/expire-entry '{}' \;
}
generate_munin_config() {
# Generate munin config. Edit /etc/cron.d/munin to enable it.
# Add -c /var/lib/sitesummary/sitesummary-munin.conf to the calls
# to the munin scripts, or change MUNINDIR above.
(
if [ -f $MUNINDIR/munin.conf.pre ] ; then
cat $MUNINDIR/munin.conf.pre
else
# Copy of active config from munin version 1.2.5-1
cat <<EOF
# Munin server configuration generated from cron using sitesummary
# data by $0
# Do not edit, it will be overwritten.
# Edit $MUNINDIR/munin.conf.pre and
# $MUNINDIR/munin.conf.post instead.
dbdir /var/lib/munin
htmldir /var/www/munin
logdir /var/log/munin
rundir /var/run/munin
tmpldir /etc/munin/templates
EOF
fi
sitesummary-nodes -m
[ -f $MUNINDIR/munin.conf.post ] && cat $MUNINDIR/munin.conf.post
# Make sure the subshell return true to trigger the mv below.
true
) > $MUNINDIR/munin.conf.new && \
chown root:root $MUNINDIR/munin.conf.new && \
chmod a+r $MUNINDIR/munin.conf.new && \
mv $MUNINDIR/munin.conf.new $MUNINDIR/munin.conf
}
generate_nagios_config() {
(
sitesummary-nodes -n $nagiosopts
if [ -f $NAGIOSDIR/nagios-generated.cfg.post ] ; then
cat $NAGIOSDIR/nagios-generated.cfg.post
fi
true
) > $NAGIOSDIR/nagios-generated.cfg.new && \
chmod a+r $NAGIOSDIR/nagios-generated.cfg.new
if cmp -s $NAGIOSDIR/nagios-generated.cfg.new $NAGIOSDIR/nagios-generated.cfg
then
rm $NAGIOSDIR/nagios-generated.cfg.new
false
else
mv $NAGIOSDIR/nagios-generated.cfg.new $NAGIOSDIR/nagios-generated.cfg
true
fi
}
# Only enable if munin and sitesummary is installed.
if [ -f /etc/munin/munin.conf ] && [ -x /usr/sbin/sitesummary-nodes ]; then
generate_munin_config
fi
# Only enable if nagios v3 and sitesummary is installed.
if [ -f /etc/init.d/nagios3 ] && [ -x /usr/sbin/sitesummary-nodes ]; then
# Only reload nagios if the configuration changed
if generate_nagios_config ; then
# subshell to avoid passing all variables from
# /etc/default/nagios3 to other parts of this script
(
if [ -r /etc/default/nagios3 ] ; then
. /etc/default/nagios3
fi
# Only reload nagios if the sitesummary config is the active
# one and nagios3 is currently running.
if [ /etc/nagios3/sitesummary.cfg = "$NAGIOSCFG" ] && \
invoke-rc.d nagios3 status >/dev/null ; then
invoke-rc.d nagios3 reload >/dev/null
fi
)
fi
fi
[ -d $entriesdir ] && remove_old_entries
# Update the web report once a day
[ -x $makewebreport ] && nice $makewebreport
|