diff --git a/.gitignore b/.gitignore index 11cdc7c..5a9d296 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /log/singleton.log /config.sh /crons/*.status +/distinct/*.msg diff --git a/crons/storage-alert.sh b/crons/storage-alert.sh index caedc7a..9d559de 100755 --- a/crons/storage-alert.sh +++ b/crons/storage-alert.sh @@ -4,15 +4,20 @@ LOCATION=`dirname "$0"` source "${LOCATION}/../config.sh" +COUNT=1 for index in "${!STORAGE_ALERT[@]}"; do storage=`${LOCATION}/../storage.sh $index ${STORAGE_ALERT[$index]}` alert=$? if [[ "0" != "${alert}" ]]; then echo "${storage} is below threshold ${STORAGE_ALERT[$index]}G" - ${LOCATION}/../discord.sh storage "${storage} is below threshold ${STORAGE_ALERT[$index]}G" + ${LOCATION}/../discord-if-distinct.sh storage "storage-${COUNT}" "${storage} is below threshold ${STORAGE_ALERT[$index]}G" else echo "${storage} is above threshold ${STORAGE_ALERT[$index]}G" + + ${LOCATION}/../discord-if-distinct.sh storage "storage-${COUNT}" "${storage} is above threshold ${STORAGE_ALERT[$index]}G" fi + + let "COUNT++" done diff --git a/discord-if-distinct.sh b/discord-if-distinct.sh new file mode 100755 index 0000000..73524a4 --- /dev/null +++ b/discord-if-distinct.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +LOCATION=`dirname "$0"` + +source "${LOCATION}/config.sh" + +HOOK_ARG="$1" +BOBBY="$2" +MESSAGE=`echo "${@:3}" | jq -aRs .` +HOOK="general" +HOOK_URL=$DISCORD_GENERAL_HOOK + +case $HOOK_ARG in + thermal) + HOOK="thermal" + HOOK_URL=$DISCORD_THERMAL_HOOK + ;; + storage) + HOOK="storage" + HOOK_URL=$DISCORD_STORAGE_HOOK + ;; +esac + +OLD_MSG="" +if [ -f "${LOCATION}/distinct/${BOBBY}.msg" ]; then + OLD_MSG=`cat "${LOCATION}/distinct/${BOBBY}.msg"` +fi + +if [ "${MESSAGE}" != "${OLD_MSG}" ]; then + echo "${MESSAGE}" > "${LOCATION}/distinct/${BOBBY}.msg" + + curl -s -H "Content-Type: application/json" -X POST -d "{\"username\": \"${DISCORD_SERVER_NAME}\", \"content\": ${MESSAGE}}" $HOOK_URL | jq -r '.id' +fi diff --git a/distinct/.gitkeep b/distinct/.gitkeep new file mode 100644 index 0000000..e69de29