discord alert hook added, made alert crons use it
This commit is contained in:
@@ -26,4 +26,7 @@ CLOUDFLARE_FILTER_PREFIX="comment.contains=managed+by+$SERVER_DOMAIN&"
|
|||||||
DISCORD_SERVER_NAME="$SERVER_DOMAIN"
|
DISCORD_SERVER_NAME="$SERVER_DOMAIN"
|
||||||
DISCORD_TITLE_SUFFIX="· $DISCORD_SERVER_NAME"
|
DISCORD_TITLE_SUFFIX="· $DISCORD_SERVER_NAME"
|
||||||
DISCORD_GENERAL_HOOK="<WEBHOOK_URL_HERE>?wait=true"
|
DISCORD_GENERAL_HOOK="<WEBHOOK_URL_HERE>?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"
|
||||||
|
|
||||||
|
|||||||
@@ -40,5 +40,5 @@ else
|
|||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
printf "%s\n" "${messages[@]}" | "${scriptRoot}/discord.sh" -c "${color}" -t "${title}"
|
printf "%s\n" "${messages[@]}" | "${scriptRoot}/discord.sh" -a -c "${color}" -t "${title}"
|
||||||
|
|
||||||
|
|||||||
@@ -21,12 +21,12 @@ alert="$?"
|
|||||||
if [[ '0' -ne "${alert}" ]]; then
|
if [[ '0' -ne "${alert}" ]]; then
|
||||||
# if currently in an alert status
|
# if currently in an alert status
|
||||||
alertLevelF=$(echo "scale=1 ; ${alertLevel} * 9 / 5 + 32" | bc -l)
|
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"
|
touch "${HOME}/.thermal.alert"
|
||||||
elif [[ -f "${HOME}/.thermal.alert" ]]; then
|
elif [[ -f "${HOME}/.thermal.alert" ]]; then
|
||||||
# if previously in an alert status
|
# if previously in an alert status
|
||||||
alertLevelF=$(echo "scale=1 ; ${alertLevel} * 9 / 5 + 32" | bc -l)
|
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"
|
rm "${HOME}/.thermal.alert"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
+10
-2
@@ -11,6 +11,7 @@
|
|||||||
# LIGHT: pink(#ff81c0), apricot(#ffb16d), beige(#e6daa6), mint(#9ffeb0), lavender(#c79fef), white(#ffffff).
|
# LIGHT: pink(#ff81c0), apricot(#ffb16d), beige(#e6daa6), mint(#9ffeb0), lavender(#c79fef), white(#ffffff).
|
||||||
|
|
||||||
scriptRoot=$(dirname "$0")
|
scriptRoot=$(dirname "$0")
|
||||||
|
alert=false
|
||||||
quiet=false
|
quiet=false
|
||||||
skipMsg=false
|
skipMsg=false
|
||||||
declare -A colors
|
declare -A colors
|
||||||
@@ -29,11 +30,11 @@ ansiColors=(
|
|||||||
)
|
)
|
||||||
|
|
||||||
print_usage() {
|
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
|
# 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
|
case "$flag" in
|
||||||
h)
|
h)
|
||||||
if [[ "$OPTARG" == "http"*"?wait=true" ]]; then
|
if [[ "$OPTARG" == "http"*"?wait=true" ]]; then
|
||||||
@@ -84,6 +85,9 @@ while getopts ':h:c:d:t:zq' flag; do
|
|||||||
q)
|
q)
|
||||||
quiet=true
|
quiet=true
|
||||||
;;
|
;;
|
||||||
|
a)
|
||||||
|
alert=true
|
||||||
|
;;
|
||||||
*)
|
*)
|
||||||
echo "unknown option provided '$flag'"
|
echo "unknown option provided '$flag'"
|
||||||
print_usage
|
print_usage
|
||||||
@@ -101,6 +105,10 @@ if [[ -f "$configFile" ]]; then
|
|||||||
botName="$DISCORD_SERVER_NAME"
|
botName="$DISCORD_SERVER_NAME"
|
||||||
if [[ -z "$hookUrl" ]]; then
|
if [[ -z "$hookUrl" ]]; then
|
||||||
hookUrl="$DISCORD_GENERAL_HOOK"
|
hookUrl="$DISCORD_GENERAL_HOOK"
|
||||||
|
|
||||||
|
if [[ "$alert" = true ]]; then
|
||||||
|
hookUrl="$DISCORD_ALERT_HOOK"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
if [[ -n "$title" ]]; then
|
if [[ -n "$title" ]]; then
|
||||||
title="$title $DISCORD_TITLE_SUFFIX"
|
title="$title $DISCORD_TITLE_SUFFIX"
|
||||||
|
|||||||
Reference in New Issue
Block a user