From b04c169a8e42e41f7a66c6649240cae2261e6751 Mon Sep 17 00:00:00 2001 From: f Date: Mon, 7 Mar 2022 20:28:42 -0300 Subject: [PATCH] autoconfigure email --- .woodpecker.yml | 4 ---- Dockerfile | 7 +++---- email.conf | 9 +++++++++ email.sh | 15 +++++++++++++++ monitrc | 12 +++++------- 5 files changed, 32 insertions(+), 15 deletions(-) create mode 100644 email.conf create mode 100755 email.sh diff --git a/.woodpecker.yml b/.woodpecker.yml index a59b24a..5544db3 100644 --- a/.woodpecker.yml +++ b/.woodpecker.yml @@ -8,14 +8,10 @@ pipeline: - latest build_args: - EMAIL=${MONIT_EMAIL} - - EMAIL_FROM=${MONIT_EMAIL_FROM} - - ALPINE_VERSION=${ALPINE_VERSION} - BASE_IMAGE=alpine username: sutty secrets: - docker_password - - monit_email - - monit_email_from cache_from: registry.nulo.in/sutty/monit:${ALPINE_VERSION} docker: purge: false diff --git a/Dockerfile b/Dockerfile index e4135f9..bf34f7a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,13 +6,10 @@ FROM ${BASE_IMAGE}:${ALPINE_VERSION} as build ARG EMAIL ARG EMAIL_FROM -RUN apk add --no-cache tzdata monit +RUN apk add --no-cache tzdata COPY ./monitrc /etc/monitrc RUN chmod 600 /etc/monitrc -RUN sed -re "s/@@EMAIL@@/${EMAIL}/" -i /etc/monitrc -RUN sed -re "s/@@EMAIL_FROM@@/${EMAIL_FROM}/" -i /etc/monitrc -RUN monit -t FROM ${BASE_IMAGE}:${ALPINE_VERSION} ARG ALPINE_VERSION @@ -37,6 +34,8 @@ RUN install -dm 2750 -o root -g root /var/lib/monit COPY --from=build /etc/monitrc /etc/monitrc COPY ./nsupdate.sh /usr/local/bin/nsupdate COPY ./whatsmyip6.sh /usr/local/bin/whatsmyip6 +COPY ./email.sh /usr/local/bin/email +COPY ./email.conf /etc/email.conf # Allow access to the web GUI EXPOSE 2812 diff --git a/email.conf b/email.conf new file mode 100644 index 0000000..d5868eb --- /dev/null +++ b/email.conf @@ -0,0 +1,9 @@ +set mailserver postfix port 25 using hostname @@HOSTNAME@@ + +set alert @@EMAIL@@ + +set mail-format { + from: Monit <@@EMAIL_FROM@@> + subject: $SERVICE@$HOST + message: $ACTION $SERVICE -- $DATE -- $HOST: $DESCRIPTION. +} diff --git a/email.sh b/email.sh new file mode 100755 index 0000000..288376b --- /dev/null +++ b/email.sh @@ -0,0 +1,15 @@ +#!/bin/sh +set -e + +test ! -f /etc/monit.d/email.conf || exit 0 + +test -n "${EMAIL}" +test -n "${EMAIL_FROM}" + +sed -re "s/@@EMAIL@@/${EMAIL}/" \ + -e "s/@@EMAIL_FROM@@/${EMAIL_FROM}/" \ + -e "s/@@HOSTNAME@@/${EMAIL_FROM#*@}/" \ + /etc/email.conf > /etc/monit.d/email.conf + +monit -t +monit reload diff --git a/monitrc b/monitrc index 2408173..6129533 100644 --- a/monitrc +++ b/monitrc @@ -5,23 +5,21 @@ set pidfile /run/monit.pid set idfile /var/lib/monit/id set statefile /var/lib/monit/state set eventqueue basedir /var/lib/monit/events slots 100 -set mailserver postfix set limits { programoutput: 1 MB } -set alert @@EMAIL@@ set httpd port 2812 allow localhost allow 172.0.0.0/8 + allow "fd00:acab::/32" check program nsupdate with path "/usr/local/bin/nsupdate" every 1 cycle if status = 0 then unmonitor -set mail-format { - from: Monit <@@EMAIL_FROM@@> - subject: $SERVICE@$HOST - message: $ACTION $SERVICE -- $DATE -- $HOST: $DESCRIPTION. -} +check program email + with path "/usr/local/bin/email" + every 1 cycle + if status = 0 then unmonitor include /etc/monit.d/*.conf