This commit is contained in:
2024-02-18 12:48:18 +01:00
parent ceb467ca60
commit a3eb0b1fea
8 changed files with 79 additions and 43 deletions

29
etc/matrix.sh Executable file
View File

@ -0,0 +1,29 @@
#!/bin/sh
baseurl="https://matrix.br0tkasten.de"
roomId="!30E9BL9QJp3BJqWp:matrix.br0tkasten.de"
message="${MONIT_HOST} (${MONIT_SERVICE}) ${MONIT_EVENT}: ${MONIT_DESCRIPTION}"
if [ "x$message" = "x" ]
then
exit 1
fi
# login
token=$(curl --connect-timeout 5 -m 10 -s $baseurl/_matrix/client/r0/login -H 'Accept: application/json' -X POST -d @/etc/monit/matrix_login.json | jq -r .access_token)
# send message
msgId=$(date +%s%N)
#curl --connect-timeout 5 -m 10 -s -XPUT -H "Content-Type: application/json;charset=utf-8" -d "{ \"msgtype\": \"m.text\", \"body\": \"$message\" }" "$baseurl/_matrix/client/r0/rooms/$roomId/send/m.room.message/$msgId?access_token=$token" >/dev/null
curl --connect-timeout 5 -m 10 -s -XPUT -H "Content-Type: application/json;charset=utf-8" "$baseurl/_matrix/client/r0/rooms/$roomId/send/m.room.message/$msgId?access_token=$token" --data-binary @- << EOF >/dev/null
{
"msgtype": "m.text",
"body": "$message"
}
EOF
# logout
curl --connect-timeout 5 -m 10 -s $baseurl/_matrix/client/r0/logout?access_token=$token -X POST >/dev/null
logger "alert: $message"

6
etc/monit.d/01_httpd.cfg Normal file
View File

@ -0,0 +1,6 @@
set httpd
port 2812
allow "192.168.178.0/24"
allow "10.4.0.1/32"
allow "10.3.0.1/32"
allow "10.5.0.0/24"

6
etc/monit.d/02_alert.cfg Normal file
View File

@ -0,0 +1,6 @@
set alert arne@br0tkasten.de
set mailserver mail.lxc.br0tkasten.de using hostname monit.br0tkasten.de
set mail-format {
from: Monit Support <monit@br0tkasten.de>
}
check system monit.br0tkasten.de

7
etc/monit.d/1_httpd.cfg Normal file
View File

@ -0,0 +1,7 @@
# Generated by entrypoint.sh
# Generated by entrypoint.sh
set httpd
port 2812
allow 127.0.0.1
allow "::1"
allow admin:buhNu0Oewais

37
etc/monit.d/99_checks.cfg Normal file
View File

@ -0,0 +1,37 @@
check host br0tkasten.de with address br0tkasten.de
if failed ping for 3 cycles then exec "/etc/monit/matrix.sh"
check host git.br0tkasten.de with address git.br0tkasten.de
if failed port 443 protocol https for 3 cycles then exec "/etc/monit/matrix.sh"
if failed port 4848 protocol ssh for 3 cycles then exec "/etc/monit/matrix.sh"
check host mail.br0tkasten.de with address mail.br0tkasten.de
if failed port 25 protocol smtp for 3 cycles then exec "/etc/monit/matrix.sh"
if failed port 143 protocol imap for 3 cycles then exec "/etc/monit/matrix.sh"
if failed port 443 protocol https for 3 cycles then exec "/etc/monit/matrix.sh"
check host matrix.br0tkasten.de with address matrix.br0tkasten.de
if failed port 443 protocol https for 3 cycles then exec "/etc/monit/matrix.sh"
check host motion.br0tkasten.de with address motion.br0tkasten.de
if failed port 443 protocol https for 3 cycles then exec "/etc/monit/matrix.sh"
check host mrtg.br0tkasten.de with address mrtg.br0tkasten.de
if failed port 443 protocol https status = 401 for 3 cycles then exec "/etc/monit/matrix.sh"
check host www.br0tkasten.de with address www.br0tkasten.de
if failed port 443 protocol https for 3 cycles then exec "/etc/monit/matrix.sh"
check host www.br0tcraft.de with address www.br0tcraft.de
if failed port 443 protocol https for 3 cycles then exec "/etc/monit/matrix.sh"
check host www.creative-crafter.de with address www.creative-crafter.de
if failed port 443 protocol https for 3 cycles then exec "/etc/monit/matrix.sh"
check host www.familienhilfe-baeumler.de with address www.familienhilfe-baeumler.de
if failed port 443 protocol https for 3 cycles then exec "/etc/monit/matrix.sh"
check host www.somachtstefaniedas.de with address www.somachtstefaniedas.de
if failed port 443 protocol https for 3 cycles then exec "/etc/monit/matrix.sh"

26
etc/monitrc Executable file
View File

@ -0,0 +1,26 @@
set daemon 300
set pidfile /var/run/monit.pid
set idfile /var/.monit.id
set statefile /var/.monit.state
set limits {
programOutput: 512 B,
sendExpectBuffer: 256 B,
fileContentBuffer: 512 B,
httpContentBuffer: 1 MB,
networkTimeout: 5 seconds
programTimeout: 300 seconds
stopTimeout: 30 seconds
startTimeout: 30 seconds
restartTimeout: 30 seconds
}
set ssl {
verify : enable,
selfsigned : allow
}
set eventqueue
basedir /var/monit
slots 100
include /etc/monit/monit.d/*.cfg