Handle multiple servers

The current approach is only useful for services delivered over http.
We are sending an individual email per fault detected - we can improve
this.
main
mj-saunders 2022-11-03 13:48:53 +04:00
parent 63cb4e7256
commit 7eff14d01f
2 changed files with 39 additions and 20 deletions

View File

@ -2,6 +2,6 @@ Subject: [AUTOMATION TEST MAIL] [URGENT] Server Report
Priority: urgent
Importance: high
Status ${STATUS} detected on ${SERVER} server.
Status {STATUS} detected on {SERVER} server.
- OMN Watchdog

View File

@ -2,28 +2,47 @@
#set -eux
BLUE='\e[1;38;5;33m'
GREEN='\e[0;38;5;64m'
ORANGE='\e[0;38;5;166m'
RED='\e[0;38;5;160m'
ITALIC='\e[1;3m'
RESET='\e[0m'
GITEA_STATUS="$(curl -s -o /dev/null -w "%{http_code}%{stdout}" https://unite.openworlds.info/)"
#GITEA_STATUS=$(echo ${CURL_RESULT} | grep HTTP | sed -E 's/HTTP\/[0-9]\.[0-9]\s([0-9]{3})\s/\1/')
RECIPIENTS="saunders@openworlds.info"
#witchescauldron@openworlds.info"
send_mail() {
SERVER=$1
# Use bash's awful syntax to escape any / in the server string
SERVER=${1//\//\\\/}
STATUS=$2
cat mail_template \
| sed "s/\${SERVER}/${SERVER}/g" \
| sed "s/\${STATUS}/${STATUS}/g" \
| msmtp -a omn_server_watch saunders@openworlds.info
| sed "s/{SERVER}/${SERVER}/g" \
| sed "s/{STATUS}/${STATUS}/g" \
| msmtp -a omn_server_watch ${RECIPIENTS}
}
if [ "$GITEA_STATUS" -ne "200" ]; then
echo -e "[omn]${GREEN}gitea server: ${RED}error $GITEA_STATUS${RESET}" | tee /dev/pts/0
send_mail "GITEA" "${GITEA_STATUS}"
fi
send_mail "GITEA" "${GITEA_STATUS}"
URLS=(
unite.openworlds.info
openworlds.info
pad.openworlds.info
visionon.tv
)
# TODO: How to check these sensibly?
SERVICES=(
chat.openworlds.info
conference.openworlds.info
# Not much point checking the mail server
# as this script relies on it to send reports
#mail.openworlds.info
)
declare -A FLAGGED
for uri in "${URLS[@]}"; do \
full_uri="https://${uri}"
echo -n "Checking: ${full_uri} ... ";
stat="$(curl -s -o /dev/null -w "%{http_code}%{stdout}" ${full_uri})"
echo "${stat}"
if [ "${stat}" -ne "200" ]; then
FLAGGED[${full_uri}]=${stat}
fi
done
for i in "${!FLAGGED[@]}"; do \
send_mail "${i}" "${FLAGGED[$i]}"
done