icanhasserver/status-check.sh

80 lines
1.7 KiB
Bash
Executable File

#!/bin/bash
#set -eux
RECIPIENTS=(
saunders@openworlds.info
witchescauldron@openworlds.info
)
URLS=(
unite.openworlds.info
openworlds.info
pad.openworlds.info
visionon.tv
activism.openworlds.info
campaign.openworlds.info
#indymedia.openworlds.info
#roadstonowhere.openworlds.info
#indymedia.hs2rebellion.earth
)
# 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
# TODO: Separate local check just for this?
#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[@]} 2>/dev/null
}
declare -A FLAGGED
echo "== Checking:"
for uri in "${URLS[@]}"; do \
full_uri="https://${uri}"
echo -n " ${full_uri} ... ";
stat="$(curl -s -o /dev/null -w "%{http_code}%{stdout}" ${full_uri})"
echo "${stat}"
# All other HTTP responses should not technically be errors
if ((${stat} >= 400 && ${stat} <= 599)); then
FLAGGED[${full_uri}]=${stat}
fi
done
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}