commit 6218e8534d4bd36ee6012d0a0e3027f18c371789 Author: mj-saunders Date: Thu Nov 3 12:39:42 2022 +0400 Initial commit We had a cheap and nasty script that could only dump a message onto a pts terminal. We have now partially set up to more sensibly send email instead. diff --git a/mail_template b/mail_template new file mode 100644 index 0000000..822fe1b --- /dev/null +++ b/mail_template @@ -0,0 +1,7 @@ +Subject: [AUTOMATION TEST MAIL] [URGENT] Server Report +Priority: urgent +Importance: high + +Status ${STATUS} detected on ${SERVER} server. + +- OMN Watchdog diff --git a/quick-status-check.sh b/quick-status-check.sh new file mode 100755 index 0000000..50d5ac3 --- /dev/null +++ b/quick-status-check.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +#set -eux + +BLUE='\e[1;38;5;33m' +GREEN='\e[0;38;5;64m' +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() { + SERVER=$1 + STATUS=$2 + cat mail_template \ + | sed "s/\${SERVER}/${SERVER}/g" \ + | sed "s/\${STATUS}/${STATUS}/g" \ + | msmtp -a omn_server_watch saunders@openworlds.info +} + +if [ "$GITEA_STATUS" -ne "200" ]; then + echo -e "[omn]${GREEN}gitea server: ${RED}error $GITEA_STATUS${RESET}" | tee /dev/pts/0 + send_mail "GITEA" "${GITEA_STATUS}" +fi +send_mail "GITEA" "${GITEA_STATUS}"