2024-10-07 21:31:33 +02:00
### DISCLAIMER: This is a third party addition to dockcheck - best effort testing.
2025-09-15 05:25:23 -04:00
NOTIFY_DISCORD_VERSION = "v0.5"
2024-10-07 21:31:33 +02:00
#
# Required receiving services must already be set up.
2025-05-29 16:43:34 -04:00
# Leave (or place) this file in the "notify_templates" subdirectory within the same directory as the main dockcheck.sh script.
# If you instead wish make your own modifications, make a copy in the same directory as the main dockcheck.sh script.
# Do not modify this file directly within the "notify_templates" subdirectory. Set DISCORD_WEBHOOK_URL in your dockcheck.config file.
2024-10-07 21:31:33 +02:00
2025-09-15 05:25:23 -04:00
trigger_discord_notification( ) {
if [ [ -n " $1 " ] ] ; then
discord_channel = " $1 "
else
discord_channel = "discord"
fi
2025-02-09 22:01:08 +01:00
2025-09-15 05:25:23 -04:00
UpperChannel = " ${ discord_channel ^^ } "
2025-02-09 22:01:08 +01:00
2025-09-15 05:25:23 -04:00
DiscordWebhookUrlVar = " ${ UpperChannel } _WEBHOOK_URL "
if [ [ -z " ${ !DiscordWebhookUrlVar :- } " ] ] ; then
printf " The ${ discord_channel } notification channel is enabled, but required configuration variables are missing. Discord notifications will not be sent.\n "
remove_channel discord
return 0
fi
DiscordWebhookUrl = " ${ !DiscordWebhookUrlVar } " # e.g. DISCORD_WEBHOOK_URL=https://discord.com/api/webhooks/<token string>
2025-03-16 20:47:46 +01:00
2025-05-29 16:43:34 -04:00
JsonData = $( " $jqbin " -n \
--arg username " $FromHost " \
--arg body " $MessageBody " \
'{"username": $username, "content": $body}' )
2025-06-24 09:16:48 -04:00
curl -S -o /dev/null ${ CurlArgs } -X POST -H "Content-Type: application/json" -d " $JsonData " " $DiscordWebhookUrl "
if [ [ $? -gt 0 ] ] ; then
NotifyError = true
fi
2024-10-14 06:28:35 +02:00
}