diff options
author | Soulou <leo.unbek@gmail.com> | 2016-06-09 14:34:01 +0200 |
---|---|---|
committer | Soulou <leo.unbek@gmail.com> | 2016-06-09 14:34:01 +0200 |
commit | d720a9cc1cbca31df7d211d5e5dce498420c4090 (patch) | |
tree | 2c39720cef5cfa1ebfe2a69d283db03539cd6d8d | |
parent | 43b9a53a91f48ebb68c98b9f0c372681462a0ffa (diff) | |
parent | 5ebec8d1b9fe51d074b351e1cfe0a307d086bc48 (diff) | |
download | munin-d720a9cc1cbca31df7d211d5e5dce498420c4090.tar.gz munin-d720a9cc1cbca31df7d211d5e5dce498420c4090.tar.bz2 munin-d720a9cc1cbca31df7d211d5e5dce498420c4090.tar.xz munin-d720a9cc1cbca31df7d211d5e5dce498420c4090.zip |
Merge pull request #5 from build-failure/master
Extended the smtp configuration
-rw-r--r-- | README.md | 6 | ||||
-rw-r--r-- | start-munin.sh | 38 |
2 files changed, 35 insertions, 9 deletions
@@ -19,6 +19,9 @@ Email credentials used to send emails (like alerts) * `SMTP_PORT` * `SMTP_USERNAME` * `SMTP_PASSWORD` +* `SMTP_USE_TLS` +* `SMTP_ALWAYS_SEND` +* `SMTP_MESSAGE` ### Alert target @@ -63,6 +66,9 @@ docker run -d \ -e SMTP_PORT=587 \ -e SMTP_USERNAME=smtp-username \ -e SMTP_PASSWORD=smtp-password \ + -e SMTP_USE_TLS=false \ + -e SMTP_ALWAYS_SEND=true \ + -e SMTP_MESSAGE='[${var:group};${var:host}] -> ${var:graph_title} -> warnings: ${loop<,>:wfields ${var:label}=${var:value}} / criticals: ${loop<,>:cfields ${var:label}=${var:value}}' \ -e ALERT_RECIPIENT=monitoring@example.com \ -e ALERT_SENDER=alerts@example.com \ -e NODES="server1:10.0.0.1 server2:10.0.0.2" \ diff --git a/start-munin.sh b/start-munin.sh index c3aa70b..8a050de 100644 --- a/start-munin.sh +++ b/start-munin.sh @@ -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" |