autoconfigure email

This commit is contained in:
f 2022-03-07 20:28:42 -03:00
parent 7aa9fe6d10
commit b04c169a8e
5 changed files with 32 additions and 15 deletions

View file

@ -8,14 +8,10 @@ pipeline:
- latest - latest
build_args: build_args:
- EMAIL=${MONIT_EMAIL} - EMAIL=${MONIT_EMAIL}
- EMAIL_FROM=${MONIT_EMAIL_FROM}
- ALPINE_VERSION=${ALPINE_VERSION}
- BASE_IMAGE=alpine - BASE_IMAGE=alpine
username: sutty username: sutty
secrets: secrets:
- docker_password - docker_password
- monit_email
- monit_email_from
cache_from: registry.nulo.in/sutty/monit:${ALPINE_VERSION} cache_from: registry.nulo.in/sutty/monit:${ALPINE_VERSION}
docker: docker:
purge: false purge: false

View file

@ -6,13 +6,10 @@ FROM ${BASE_IMAGE}:${ALPINE_VERSION} as build
ARG EMAIL ARG EMAIL
ARG EMAIL_FROM ARG EMAIL_FROM
RUN apk add --no-cache tzdata monit RUN apk add --no-cache tzdata
COPY ./monitrc /etc/monitrc COPY ./monitrc /etc/monitrc
RUN chmod 600 /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} FROM ${BASE_IMAGE}:${ALPINE_VERSION}
ARG 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 --from=build /etc/monitrc /etc/monitrc
COPY ./nsupdate.sh /usr/local/bin/nsupdate COPY ./nsupdate.sh /usr/local/bin/nsupdate
COPY ./whatsmyip6.sh /usr/local/bin/whatsmyip6 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 # Allow access to the web GUI
EXPOSE 2812 EXPOSE 2812

9
email.conf Normal file
View file

@ -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.
}

15
email.sh Executable file
View file

@ -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

12
monitrc
View file

@ -5,23 +5,21 @@ set pidfile /run/monit.pid
set idfile /var/lib/monit/id set idfile /var/lib/monit/id
set statefile /var/lib/monit/state set statefile /var/lib/monit/state
set eventqueue basedir /var/lib/monit/events slots 100 set eventqueue basedir /var/lib/monit/events slots 100
set mailserver postfix
set limits { programoutput: 1 MB } set limits { programoutput: 1 MB }
set alert @@EMAIL@@
set httpd port 2812 set httpd port 2812
allow localhost allow localhost
allow 172.0.0.0/8 allow 172.0.0.0/8
allow "fd00:acab::/32"
check program nsupdate check program nsupdate
with path "/usr/local/bin/nsupdate" with path "/usr/local/bin/nsupdate"
every 1 cycle every 1 cycle
if status = 0 then unmonitor if status = 0 then unmonitor
set mail-format { check program email
from: Monit <@@EMAIL_FROM@@> with path "/usr/local/bin/email"
subject: $SERVICE@$HOST every 1 cycle
message: $ACTION $SERVICE -- $DATE -- $HOST: $DESCRIPTION. if status = 0 then unmonitor
}
include /etc/monit.d/*.conf include /etc/monit.d/*.conf