Only email if error detected

We also took the opportunity to clean up the output a little.
main
mj-saunders 2022-11-03 14:44:17 +04:00
parent b173ced7ec
commit 74a2fc4513
2 changed files with 26 additions and 6 deletions

View File

@ -1,4 +1,4 @@
Subject: [AUTOMATION TEST MAIL] [URGENT] Server Report
Subject: [URGENT] Server Report
Priority: urgent
Importance: high

View File

@ -2,8 +2,10 @@
#set -eux
RECIPIENTS="saunders@openworlds.info"
#witchescauldron@openworlds.info"
RECIPIENTS=(
saunders@openworlds.info
witchescauldron@openworlds.info
)
URLS=(
unite.openworlds.info
@ -39,14 +41,16 @@ send_mail() {
cat mail_template \
| sed "s/{ERR_LIST}/${error_string}/g" \
| msmtp -a omn_server_watch ${RECIPIENTS}
| msmtp -a omn_server_watch ${RECIPIENTS[@]} 2>/dev/null
}
declare -A FLAGGED
echo "== Checking:"
for uri in "${URLS[@]}"; do \
full_uri="https://${uri}"
echo -n "Checking: ${full_uri} ... ";
echo -n " ${full_uri} ... ";
stat="$(curl -s -o /dev/null -w "%{http_code}%{stdout}" ${full_uri})"
echo "${stat}"
@ -56,4 +60,20 @@ for uri in "${URLS[@]}"; do \
fi
done
send_mail FLAGGED
ret=0
if ((${#FLAGGED[@]} > 0)); then
echo "== Error(s) detected. Sending mail to:"
for rcp in ${RECIPIENTS[@]}; do
echo " ${rcp}"
done
send_mail FLAGGED
ret=1
else
echo "== OK"
fi
exit ${ret}