From 254fa04f4337dbcb89bde3e75a1d41588b8d23dd Mon Sep 17 00:00:00 2001 From: Andrew Stowell Date: Fri, 11 Jul 2025 09:27:28 -0400 Subject: [PATCH] discord alert hook added, made alert crons use it --- config.example.sh | 3 +++ crons/storage-alert.sh | 2 +- crons/thermal-alert.sh | 4 ++-- discord.sh | 12 ++++++++++-- 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/config.example.sh b/config.example.sh index 80df10d..6674968 100644 --- a/config.example.sh +++ b/config.example.sh @@ -26,4 +26,7 @@ CLOUDFLARE_FILTER_PREFIX="comment.contains=managed+by+$SERVER_DOMAIN&" DISCORD_SERVER_NAME="$SERVER_DOMAIN" DISCORD_TITLE_SUFFIX="ยท $DISCORD_SERVER_NAME" DISCORD_GENERAL_HOOK="?wait=true" +# you can send alerts to a different channel, if desired +# via "-a" also used by the "*-alert.sh" scripts in /crons/ +DISCORD_ALERT_HOOK="$DISCORD_GENERAL_HOOK" diff --git a/crons/storage-alert.sh b/crons/storage-alert.sh index e16fbba..d21bcf2 100755 --- a/crons/storage-alert.sh +++ b/crons/storage-alert.sh @@ -40,5 +40,5 @@ else exit 0 fi -printf "%s\n" "${messages[@]}" | "${scriptRoot}/discord.sh" -c "${color}" -t "${title}" +printf "%s\n" "${messages[@]}" | "${scriptRoot}/discord.sh" -a -c "${color}" -t "${title}" diff --git a/crons/thermal-alert.sh b/crons/thermal-alert.sh index 6a07b57..432d8cf 100755 --- a/crons/thermal-alert.sh +++ b/crons/thermal-alert.sh @@ -21,12 +21,12 @@ alert="$?" if [[ '0' -ne "${alert}" ]]; then # if currently in an alert status alertLevelF=$(echo "scale=1 ; ${alertLevel} * 9 / 5 + 32" | bc -l) - "${scriptRoot}/discord.sh" -c red -t 'Thermal Alert' "${thermal}" $'\n' "above threshold ${alertLevel} C (${alertLevelF} F)" + "${scriptRoot}/discord.sh" -a -c red -t 'Thermal Alert' "${thermal}" $'\n' "above threshold ${alertLevel} C (${alertLevelF} F)" touch "${HOME}/.thermal.alert" elif [[ -f "${HOME}/.thermal.alert" ]]; then # if previously in an alert status alertLevelF=$(echo "scale=1 ; ${alertLevel} * 9 / 5 + 32" | bc -l) - "${scriptRoot}/discord.sh" -c orange -t 'Thermal Alert' "${thermal}" $'\n' "previously above threshold ${alertLevel} C (${alertLevelF} F)" + "${scriptRoot}/discord.sh" -a -c orange -t 'Thermal Alert' "${thermal}" $'\n' "previously above threshold ${alertLevel} C (${alertLevelF} F)" rm "${HOME}/.thermal.alert" fi diff --git a/discord.sh b/discord.sh index cb21a22..6ce5a1d 100755 --- a/discord.sh +++ b/discord.sh @@ -11,6 +11,7 @@ # LIGHT: pink(#ff81c0), apricot(#ffb16d), beige(#e6daa6), mint(#9ffeb0), lavender(#c79fef), white(#ffffff). scriptRoot=$(dirname "$0") +alert=false quiet=false skipMsg=false declare -A colors @@ -29,11 +30,11 @@ ansiColors=( ) print_usage() { - echo "Usage: $0 [-h hook-url] [-c color] [-d [distinct-name]] [-t title] [-q] (message... | -z | < file.msg)" + echo "Usage: $0 [[-h hook-url] | -a] [-c color] [-d [distinct-name]] [-t title] [-q] (message... | -z | < file.msg)" } # handle all arguments provided -while getopts ':h:c:d:t:zq' flag; do +while getopts ':h:c:d:t:zaq' flag; do case "$flag" in h) if [[ "$OPTARG" == "http"*"?wait=true" ]]; then @@ -84,6 +85,9 @@ while getopts ':h:c:d:t:zq' flag; do q) quiet=true ;; + a) + alert=true + ;; *) echo "unknown option provided '$flag'" print_usage @@ -101,6 +105,10 @@ if [[ -f "$configFile" ]]; then botName="$DISCORD_SERVER_NAME" if [[ -z "$hookUrl" ]]; then hookUrl="$DISCORD_GENERAL_HOOK" + + if [[ "$alert" = true ]]; then + hookUrl="$DISCORD_ALERT_HOOK" + fi fi if [[ -n "$title" ]]; then title="$title $DISCORD_TITLE_SUFFIX"