summaryrefslogtreecommitdiffstats
path: root/start-munin.sh
diff options
context:
space:
mode:
authorSoulou <leo@unbekandt.eu>2015-04-30 22:21:27 +0200
committerSoulou <leo@unbekandt.eu>2015-04-30 22:21:27 +0200
commita48332b52967631352e0dec8a66402953cb68c10 (patch)
treef49f0f0a34b6a4de8a27cd1fa4aefffd659c64a6 /start-munin.sh
parente3504cee99dab2331df59f6463e5be5ac222dedd (diff)
downloadmunin-a48332b52967631352e0dec8a66402953cb68c10.tar.gz
munin-a48332b52967631352e0dec8a66402953cb68c10.tar.bz2
munin-a48332b52967631352e0dec8a66402953cb68c10.tar.xz
munin-a48332b52967631352e0dec8a66402953cb68c10.zip
Version v5, graceful stop, email alert and better doc
Diffstat (limited to 'start-munin.sh')
-rw-r--r--start-munin.sh36
1 files changed, 31 insertions, 5 deletions
diff --git a/start-munin.sh b/start-munin.sh
index b0fb3b0..66a2d4b 100644
--- a/start-munin.sh
+++ b/start-munin.sh
@@ -3,21 +3,41 @@ NODES=${NODES:-}
MUNIN_USER=${MUNIN_USER:-user}
MUNIN_PASSWORD=${MUNIN_PASSWORD:-password}
-htpasswd -b -c /etc/munin/htpasswd.users "$MUNIN_USER" "$MUNIN_PASSWORD"
+if [ -n "${SMTP_USERNAME}" -a -n "${SMTP_PASSWORD}" -a -n "${SMTP_HOST}" -a -n "${SMTP_PORT}" ] ; then
+ cat > /var/lib/munin/.mailrc <<EOF
+ set smtp-use-starttls
+ set ssl-verify=ignore
+ set smtp=smtp://${SMTP_HOST}:${SMTP_PORT}
+ set smtp-auth=login
+ set smtp-auth-user=${SMTP_USERNAME}
+ set smtp-auth-password=${SMTP_PASSWORD}
+EOF
+fi
+
+grep -q 'contact.mail' /etc/munin/munin.conf; rc=$?
+if [ $rc -ne 0 -a -n "${ALERT_RECIPIENT}" -a -n "${ALERT_SENDER}" ] ; then
+ echo "Setup alert email from ${ALERT_SENDER} to ${ALERT_RECIPIENT}"
+ echo 'contact.mail.command mail -r '${ALERT_SENDER}' -s "[${var:group};${var:host}] -> ${var:graph_title} -> warnings: ${loop<,>:wfields ${var:label}=${var:value}} / criticals: ${loop<,>:cfields ${var:label}=${var:value}}"' ${ALERT_RECIPIENT} >> /etc/munin/munin.conf
+fi
+
+[ -e /etc/munin/htpasswd.users ] || htpasswd -b -c /etc/munin/htpasswd.users "$MUNIN_USER" "$MUNIN_PASSWORD"
# generate node list
for NODE in $NODES
do
- NAME=`echo $NODE | cut -d ":" -f1`
- HOST=`echo $NODE | cut -d ":" -f2`
+ NAME=`echo $NODE | cut -d ":" -f1`
+ HOST=`echo $NODE | cut -d ":" -f2`
+ if ! grep -q $HOST /etc/munin/munin.conf ; then
cat << EOF >> /etc/munin/munin.conf
[$NAME]
address $HOST
use_node_name yes
EOF
+ fi
done
+[ -d /var/cache/munin/www ] || mkdir /var/cache/munin/www
# placeholder html to prevent permission error
if [ ! -e /var/cache/munin/www/index.html ]; then
cat << EOF > /var/cache/munin/www/index.html
@@ -30,7 +50,7 @@ Munin has not run yet. Please try again in a few moments.
</body>
</html>
EOF
-chown munin:munin /var/cache/munin/www/index.html
+chown munin:munin -R /var/cache/munin/www
chmod g+w /var/cache/munin/www/index.html
fi
@@ -46,4 +66,10 @@ echo $NODES
/usr/sbin/nginx
# show logs
echo "Tailing /var/log/syslog..."
-tail -F /var/log/syslog /var/log/munin/munin-update.log
+tail -F /var/log/syslog /var/log/munin/munin-update.log & pid=$!
+
+sleep 1
+
+trap "kill $pid $(cat /var/run/munin/munin-node.pid) $(cat /var/run/nginx.pid) $(cat /var/run/crond.pid) $(cat /var/run/rsyslogd.pid)" TERM QUIT INT
+
+wait