autoconfigure email
This commit is contained in:
parent
7aa9fe6d10
commit
b04c169a8e
5 changed files with 32 additions and 15 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
9
email.conf
Normal file
9
email.conf
Normal 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
15
email.sh
Executable 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
12
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
|
||||
|
|
Loading…
Reference in a new issue