icanhasserver/status-check.sh

49 lines
1.1 KiB
Bash
Raw Normal View History

#!/bin/bash
#set -eux
RECIPIENTS="saunders@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=(
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