Improve healthcheck
This commit is contained in:
parent
e7c78aa678
commit
ee59f0258b
11 changed files with 20 additions and 19 deletions
healthcheck/data
47
healthcheck/data/http
Executable file
47
healthcheck/data/http
Executable file
|
@ -0,0 +1,47 @@
|
|||
#!/usr/bin/sh
|
||||
|
||||
set -e
|
||||
cd /opt/ || exit
|
||||
|
||||
hc_url="https://hc-ping.com/$HTTP_HC_UID"
|
||||
error=""
|
||||
|
||||
alias curl_hc='curl -LA "$USER_AGENT" --retry 3'
|
||||
|
||||
check_url ()
|
||||
{
|
||||
url="https://$1"
|
||||
echo "checking url $url ..."
|
||||
dig A "$1" >/dev/null
|
||||
if curl_hc -sSf "$url" >/dev/null 2>&1
|
||||
then
|
||||
echo "... good"
|
||||
else
|
||||
result=$(curl -Lv "$url" 2>&1)
|
||||
error=$(printf "%s\n==========\n%s:\n%s" "$error" "$url" "$result")
|
||||
echo "... bad"
|
||||
fi
|
||||
}
|
||||
|
||||
check_url "analytics.serguzim.me"
|
||||
check_url "auth.serguzim.me"
|
||||
check_url "ci.serguzim.me"
|
||||
check_url "cloud.serguzim.me"
|
||||
check_url "git.serguzim.me"
|
||||
check_url "graph.serguzim.me"
|
||||
check_url "hook.serguzim.me"
|
||||
check_url "mail.serguzim.me"
|
||||
check_url "msrg.cc"
|
||||
check_url "prometheus.serguzim.me/-/healthy"
|
||||
check_url "registry.serguzim.me"
|
||||
check_url "rss.serguzim.me"
|
||||
check_url "serguzim.me"
|
||||
check_url "wiki.serguzim.me"
|
||||
check_url "www.reitanlage-oranienburg.de"
|
||||
|
||||
if [ "$error" = "" ]
|
||||
then
|
||||
curl_hc "$hc_url"
|
||||
else
|
||||
curl_hc --data-raw "$error" "$hc_url/fail"
|
||||
fi
|
9
healthcheck/data/mail
Executable file
9
healthcheck/data/mail
Executable file
|
@ -0,0 +1,9 @@
|
|||
#!/usr/bin/sh
|
||||
|
||||
set -e
|
||||
cd /opt/ || exit
|
||||
|
||||
envsubst < template.msmtprc > /tmp/msmtprc
|
||||
envsubst < mailcheck.template.mail > /tmp/mailcheck.mail
|
||||
|
||||
msmtp -C /tmp/msmtprc -a default "$MAIL_HC_UID@hc-ping.com" < /tmp/mailcheck.mail
|
5
healthcheck/data/mailcheck.template.mail
Normal file
5
healthcheck/data/mailcheck.template.mail
Normal file
|
@ -0,0 +1,5 @@
|
|||
To: ${MAIL_HC_UID}@hc-ping.com
|
||||
From: ${MAIL_USER}
|
||||
Subject: Healthcheck
|
||||
|
||||
Mailserver alive
|
55
healthcheck/data/matrix
Executable file
55
healthcheck/data/matrix
Executable file
|
@ -0,0 +1,55 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
import datetime
|
||||
import os
|
||||
import requests
|
||||
import sys
|
||||
|
||||
import asyncio
|
||||
from nio import AsyncClient, RoomMessageNotice
|
||||
|
||||
healthcheck_url = "https://hc-ping.com/" + os.environ['MATRIX_HC_UID']
|
||||
|
||||
def send_ping(success, msg=""):
|
||||
url = healthcheck_url
|
||||
if not success:
|
||||
url += "/fail"
|
||||
|
||||
requests.get(url, data=msg, headers={'user-agent': os.environ['USER_AGENT']})
|
||||
|
||||
async def main():
|
||||
try:
|
||||
client = AsyncClient(os.environ['MATRIX_SERVER'])
|
||||
client.access_token = os.environ['MATRIX_TOKEN']
|
||||
client.device_id = os.environ['USER_AGENT']
|
||||
await client.room_send(
|
||||
room_id = os.environ['MATRIX_ROOM'],
|
||||
message_type = "m.room.message",
|
||||
content = {
|
||||
"msgtype": "m.text",
|
||||
"body": "!ping"
|
||||
}
|
||||
)
|
||||
except Exception as e:
|
||||
print(e)
|
||||
|
||||
print("exception during login or sending")
|
||||
send_ping(False)
|
||||
sys.exit(1)
|
||||
await client.close()
|
||||
|
||||
url = "https://federationtester.matrix.org/api/report?server_name=" \
|
||||
+ os.environ['MATRIX_SERVER_FEDTESTER']
|
||||
resp = requests.get(url)
|
||||
data = resp.json() # Check the JSON Response Content documentation below
|
||||
if data["FederationOK"] != True:
|
||||
send_ping(False)
|
||||
sys.exit(1)
|
||||
|
||||
requests.get(url=healthcheck_url)
|
||||
send_ping(True)
|
||||
sys.exit(0)
|
||||
|
||||
|
||||
|
||||
asyncio.new_event_loop().run_until_complete(main())
|
13
healthcheck/data/template.msmtprc
Normal file
13
healthcheck/data/template.msmtprc
Normal file
|
@ -0,0 +1,13 @@
|
|||
defaults
|
||||
auth on
|
||||
tls on
|
||||
tls_trust_file /etc/ssl/certs/ca-certificates.crt
|
||||
logfile /tmp/msmtp.log
|
||||
|
||||
account default
|
||||
host ${MAIL_HOST}
|
||||
port ${MAIL_PORT}
|
||||
tls_starttls on
|
||||
from ${MAIL_USER}
|
||||
user ${MAIL_USER}
|
||||
password ${MAIL_PASS}
|
Reference in a new issue