Send a single email only
Gather any detected errors into a list and send them all at once.main
parent
7eff14d01f
commit
b173ced7ec
|
@ -2,6 +2,8 @@ Subject: [AUTOMATION TEST MAIL] [URGENT] Server Report
|
||||||
Priority: urgent
|
Priority: urgent
|
||||||
Importance: high
|
Importance: high
|
||||||
|
|
||||||
Status {STATUS} detected on {SERVER} server.
|
An error was detected on the following server(s):
|
||||||
|
|
||||||
|
{ERR_LIST}
|
||||||
|
|
||||||
- OMN Watchdog
|
- OMN Watchdog
|
||||||
|
|
|
@ -5,21 +5,16 @@
|
||||||
RECIPIENTS="saunders@openworlds.info"
|
RECIPIENTS="saunders@openworlds.info"
|
||||||
#witchescauldron@openworlds.info"
|
#witchescauldron@openworlds.info"
|
||||||
|
|
||||||
send_mail() {
|
|
||||||
# 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 ${RECIPIENTS}
|
|
||||||
}
|
|
||||||
|
|
||||||
URLS=(
|
URLS=(
|
||||||
unite.openworlds.info
|
unite.openworlds.info
|
||||||
openworlds.info
|
openworlds.info
|
||||||
pad.openworlds.info
|
pad.openworlds.info
|
||||||
visionon.tv
|
visionon.tv
|
||||||
|
activism.openworlds.info
|
||||||
|
campaign.openworlds.info
|
||||||
|
#indymedia.openworlds.info
|
||||||
|
#roadstonowhere.openworlds.info
|
||||||
|
#indymedia.hs2rebellion.earth
|
||||||
)
|
)
|
||||||
# TODO: How to check these sensibly?
|
# TODO: How to check these sensibly?
|
||||||
SERVICES=(
|
SERVICES=(
|
||||||
|
@ -27,9 +22,26 @@ SERVICES=(
|
||||||
conference.openworlds.info
|
conference.openworlds.info
|
||||||
# Not much point checking the mail server
|
# Not much point checking the mail server
|
||||||
# as this script relies on it to send reports
|
# as this script relies on it to send reports
|
||||||
|
# TODO: Separate local check just for this?
|
||||||
#mail.openworlds.info
|
#mail.openworlds.info
|
||||||
)
|
)
|
||||||
|
|
||||||
|
send_mail() {
|
||||||
|
local -n error_list=$1
|
||||||
|
local error_string=""
|
||||||
|
|
||||||
|
for i in "${!error_list[@]}"; do
|
||||||
|
# Use bash's awful syntax to escape any / in the server string
|
||||||
|
code=${i//\//\\\/}
|
||||||
|
server=${error_list[$i]}
|
||||||
|
error_string+=" ${code}: ${server}\n"
|
||||||
|
done
|
||||||
|
|
||||||
|
cat mail_template \
|
||||||
|
| sed "s/{ERR_LIST}/${error_string}/g" \
|
||||||
|
| msmtp -a omn_server_watch ${RECIPIENTS}
|
||||||
|
}
|
||||||
|
|
||||||
declare -A FLAGGED
|
declare -A FLAGGED
|
||||||
|
|
||||||
for uri in "${URLS[@]}"; do \
|
for uri in "${URLS[@]}"; do \
|
||||||
|
@ -38,11 +50,10 @@ for uri in "${URLS[@]}"; do \
|
||||||
stat="$(curl -s -o /dev/null -w "%{http_code}%{stdout}" ${full_uri})"
|
stat="$(curl -s -o /dev/null -w "%{http_code}%{stdout}" ${full_uri})"
|
||||||
echo "${stat}"
|
echo "${stat}"
|
||||||
|
|
||||||
if [ "${stat}" -ne "200" ]; then
|
# All other HTTP responses should not technically be errors
|
||||||
|
if ((${stat} >= 400 && ${stat} <= 599)); then
|
||||||
FLAGGED[${full_uri}]=${stat}
|
FLAGGED[${full_uri}]=${stat}
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
for i in "${!FLAGGED[@]}"; do \
|
send_mail FLAGGED
|
||||||
send_mail "${i}" "${FLAGGED[$i]}"
|
|
||||||
done
|
|
||||||
|
|
Loading…
Reference in New Issue