|
@@ -3,22 +3,42 @@ NODES=${NODES:-}
|
|
|
SNMP_NODES=${SNMP_NODES:-}
|
|
|
MUNIN_USER=${MUNIN_USER:-user}
|
|
|
MUNIN_PASSWORD=${MUNIN_PASSWORD:-password}
|
|
|
+MAIL_CONF_PATH='/var/lib/munin/.mailrc'
|
|
|
+SMTP_USE_TLS=${SMTP_USE_TLS:-false}
|
|
|
+SMTP_ALWAYS_SEND=${SMTP_ALWAYS_SEND:-true}
|
|
|
+SMTP_MESSAGE_DEFAULT='[${var:group};${var:host}] -> ${var:graph_title} -> warnings: ${loop<,>:wfields ${var:label}=${var:value}} / criticals: ${loop<,>:cfields ${var:label}=${var:value}}'
|
|
|
+SMTP_MESSAGE="${SMTP_MESSAGE:-$SMTP_MESSAGE_DEFAULT}"
|
|
|
|
|
|
-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}
|
|
|
+truncate -s 0 "${MAIL_CONF_PATH}"
|
|
|
+
|
|
|
+if [ "${SMTP_USE_TLS}" = true ] ; then
|
|
|
+ cat >> "${MAIL_CONF_PATH}" <<EOF
|
|
|
+set smtp-use-starttls
|
|
|
+set ssl-verify=ignore
|
|
|
+EOF
|
|
|
+fi
|
|
|
+
|
|
|
+if [ -n "${SMTP_HOST}" -a -n "${SMTP_PORT}" ] ; then
|
|
|
+ cat >> "${MAIL_CONF_PATH}" <<EOF
|
|
|
+set smtp=smtp://${SMTP_HOST}:${SMTP_PORT}
|
|
|
+EOF
|
|
|
+fi
|
|
|
+
|
|
|
+if [ -n "${SMTP_USERNAME}" -a -n "${SMTP_PASSWORD}" ] ; then
|
|
|
+ cat >> "${MAIL_CONF_PATH}" <<EOF
|
|
|
+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
|
|
|
+ echo "contact.mail.command mail -r ${ALERT_SENDER} -s '${SMTP_MESSAGE}' ${ALERT_RECIPIENT}" >> /etc/munin/munin.conf
|
|
|
+ if [ "${SMTP_ALWAYS_SEND}" = true ] ; then
|
|
|
+ echo 'contact.mail.always_send warning critical' >> /etc/munin/munin.conf
|
|
|
+ fi
|
|
|
fi
|
|
|
|
|
|
[ -e /etc/munin/htpasswd.users ] || htpasswd -b -c /etc/munin/htpasswd.users "$MUNIN_USER" "$MUNIN_PASSWORD"
|