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

View File

@ -1,3 +0,0 @@
set httpd
port 2812
allow "192.168.178.0/24"

View File

@ -1,40 +0,0 @@
check host br0tkasten.de with address br0tkasten.de
if failed ping then alert
check host git.br0tkasten.de with address git.br0tkasten.de
if failed port 443 protocol https then alert
if failed port 4848 protocol ssh then alert
check host ha.br0tkasten.de with address ha.br0tkasten.de
if failed port 443 protocol https then alert
check host jitsi.br0tkasten.de with address jitsi.br0tkasten.de
if failed port 443 protocol https then alert
check host mail.br0tkasten.de with address mail.br0tkasten.de
if failed port 25 protocol smtp then alert
if failed port 143 protocol imap then alert
if failed port 443 protocol https then alert
check host matrix.br0tkasten.de with address matrix.br0tkasten.de
if failed port 443 protocol https then alert
check host motion.br0tkasten.de with address motion.br0tkasten.de
if failed port 443 protocol https then alert
check host mrtg.br0tkasten.de with address mrtg.br0tkasten.de
if failed port 443 protocol https status = 401 then alert
check host www.br0tkasten.de with address www.br0tkasten.de
if failed port 443 protocol https then alert
check host www.br0tcraft.de with address www.br0tcraft.de
if failed port 443 protocol https then alert
check host www.familienhilfe-baeumler.de with address www.familienhilfe-baeumler.de
if failed port 443 protocol https then alert
check host www.somachtstefaniedas.de with address www.somachtstefaniedas.de
if failed port 443 protocol https then alert

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"

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"