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
parent
63cb4e7256
commit
7eff14d01f
|
@ -2,6 +2,6 @@ Subject: [AUTOMATION TEST MAIL] [URGENT] Server Report
|
||||||
Priority: urgent
|
Priority: urgent
|
||||||
Importance: high
|
Importance: high
|
||||||
|
|
||||||
Status ${STATUS} detected on ${SERVER} server.
|
Status {STATUS} detected on {SERVER} server.
|
||||||
|
|
||||||
- OMN Watchdog
|
- OMN Watchdog
|
||||||
|
|
|
@ -2,28 +2,47 @@
|
||||||
|
|
||||||
#set -eux
|
#set -eux
|
||||||
|
|
||||||
BLUE='\e[1;38;5;33m'
|
RECIPIENTS="saunders@openworlds.info"
|
||||||
GREEN='\e[0;38;5;64m'
|
#witchescauldron@openworlds.info"
|
||||||
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/')
|
|
||||||
|
|
||||||
send_mail() {
|
send_mail() {
|
||||||
SERVER=$1
|
# Use bash's awful syntax to escape any / in the server string
|
||||||
|
SERVER=${1//\//\\\/}
|
||||||
STATUS=$2
|
STATUS=$2
|
||||||
cat mail_template \
|
cat mail_template \
|
||||||
| sed "s/\${SERVER}/${SERVER}/g" \
|
| sed "s/{SERVER}/${SERVER}/g" \
|
||||||
| sed "s/\${STATUS}/${STATUS}/g" \
|
| sed "s/{STATUS}/${STATUS}/g" \
|
||||||
| msmtp -a omn_server_watch saunders@openworlds.info
|
| msmtp -a omn_server_watch ${RECIPIENTS}
|
||||||
}
|
}
|
||||||
|
|
||||||
if [ "$GITEA_STATUS" -ne "200" ]; then
|
URLS=(
|
||||||
echo -e "[omn]${GREEN}gitea server: ${RED}error $GITEA_STATUS${RESET}" | tee /dev/pts/0
|
unite.openworlds.info
|
||||||
send_mail "GITEA" "${GITEA_STATUS}"
|
openworlds.info
|
||||||
fi
|
pad.openworlds.info
|
||||||
send_mail "GITEA" "${GITEA_STATUS}"
|
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
|
||||||
|
|
Loading…
Reference in New Issue