From 71967277aaa291e48561379b9f0aa1b0421c38a3 Mon Sep 17 00:00:00 2001 From: mag37 Date: Sun, 9 Feb 2025 22:01:08 +0100 Subject: [PATCH] new notification structure --- notify_templates/notify_DSM.sh | 2 -- notify_templates/notify_apprise.sh | 47 ++++++++++++++---------------- notify_templates/notify_discord.sh | 35 +++++++++++++--------- notify_templates/notify_generic.sh | 28 ++++++++++++++++-- notify_templates/notify_gotify.sh | 40 +++++++++++++++++-------- notify_templates/notify_matrix.sh | 39 +++++++++++++++++-------- 6 files changed, 123 insertions(+), 68 deletions(-) diff --git a/notify_templates/notify_DSM.sh b/notify_templates/notify_DSM.sh index eec76b8..cc2de13 100644 --- a/notify_templates/notify_DSM.sh +++ b/notify_templates/notify_DSM.sh @@ -59,7 +59,6 @@ MessageTitle="Updates available on" printf -v MessageBody "🐋 Containers on $FromHost with updates available:\n\n$UpdToString" trigger_notification - } ### Remove or comment out the following function @@ -72,5 +71,4 @@ MessageTitle="New version of dockcheck available on" printf -v MessageBody "Installed version: $1 \nLatest version: $2 \n\nChangenotes: $3" trigger_notification - } diff --git a/notify_templates/notify_apprise.sh b/notify_templates/notify_apprise.sh index 377dd73..3e20475 100644 --- a/notify_templates/notify_apprise.sh +++ b/notify_templates/notify_apprise.sh @@ -8,43 +8,40 @@ FromHost=$(hostname) trigger_notification() { -### Modify to fit your setup: -apprise -vv -t "$MessageTitle" -b "$MessageBody" \ - mailto://myemail:mypass@gmail.com \ - mastodons://{token}@{host} \ - pbul://o.gn5kj6nfhv736I7jC3cj3QLRiyhgl98b \ - tgram://{bot_token}/{chat_id}/ - -### If you use the Apprise-API - Comment out the apprise command above. -### Uncomment the AppriseURL and the curl-line below: -# AppriseURL="http://apprise.mydomain.tld:1234/notify/apprise" -# curl -X POST -F "title=$MessageTitle" -F "body=$MessageBody" -F "tags=all" $AppriseURL + ### Modify to fit your setup: + apprise -vv -t "$MessageTitle" -b "$MessageBody" \ + mailto://myemail:mypass@gmail.com \ + mastodons://{token}@{host} \ + pbul://o.gn5kj6nfhv736I7jC3cj3QLRiyhgl98b \ + tgram://{bot_token}/{chat_id}/ + ### If you use the Apprise-API - Comment out the apprise command above. + ### Uncomment the AppriseURL and the curl-line below: + # AppriseURL="http://apprise.mydomain.tld:1234/notify/apprise" + # curl -X POST -F "title=$MessageTitle" -F "body=$MessageBody" -F "tags=all" $AppriseURL } send_notification() { -[ -s "$ScriptWorkDir"/urls.list ] && releasenotes || Updates=("$@") -UpdToString=$( printf '%s\\n' "${Updates[@]}" ) + [ -s "$ScriptWorkDir"/urls.list ] && releasenotes || Updates=("$@") + UpdToString=$( printf '%s\\n' "${Updates[@]}" ) -printf "\nSending Apprise notification\n" + printf "\nSending Apprise notification\n" -MessageTitle="$FromHost - updates available." -# Setting the MessageBody variable here. -printf -v MessageBody "🐋 Containers on $FromHost with updates available:\n$UpdToString" - -trigger_notification + MessageTitle="$FromHost - updates available." + # Setting the MessageBody variable here. + printf -v MessageBody "🐋 Containers on $FromHost with updates available:\n$UpdToString" + trigger_notification } ### Remove or comment out the following function ### to not send notifications when dockcheck itself has updates. dockcheck_notification() { -printf "\nSending Apprise dockcheck notification\n" + printf "\nSending Apprise dockcheck notification\n" -MessageTitle="$FromHost - New version of dockcheck available." -# Setting the MessageBody variable here. -printf -v MessageBody "Installed version: $1 \nLatest version: $2 \n\nChangenotes: $3" - -trigger_notification + MessageTitle="$FromHost - New version of dockcheck available." + # Setting the MessageBody variable here. + printf -v MessageBody "Installed version: $1 \nLatest version: $2 \n\nChangenotes: $3" + trigger_notification } diff --git a/notify_templates/notify_discord.sh b/notify_templates/notify_discord.sh index b29966a..e63c237 100644 --- a/notify_templates/notify_discord.sh +++ b/notify_templates/notify_discord.sh @@ -4,25 +4,32 @@ # Required receiving services must already be set up. # Modify to fit your setup - set DiscordWebhookUrl -send_notification() { - [ -s "$ScriptWorkDir"/urls.list ] && releasenotes || Updates=("$@") - UpdToString=$( printf '%s\\n' "${Updates[@]}" ) - - echo "$UpdToString" - FromHost=$(hostname) - - # platform specific notification code would go here - printf "\nSending Discord notification\n" - - # Setting the MessageBody variable here. - MessageBody="🐋 Containers on $FromHost with updates available: \n$UpdToString" +FromHost=$(hostname) +trigger_notification() { # Modify to fit your setup: DiscordWebhookUrl="PasteYourFullDiscordWebhookURL" MsgBody="{\"username\":\"$FromHost\",\"content\":\"$MessageBody\"}" - curl -sS -o /dev/null --fail -X POST -H "Content-Type: application/json" -d "$MsgBody" "$DiscordWebhookUrl" - } +send_notification() { + [ -s "$ScriptWorkDir"/urls.list ] && releasenotes || Updates=("$@") + UpdToString=$( printf '%s\\n' "${Updates[@]}" ) + + printf "\nSending Discord notification\n" + # Setting the MessageBody variable here. + MessageBody="🐋 Containers on $FromHost with updates available: \n$UpdToString" + + trigger_notification +} + +### Remove or comment out the following function +### to not send notifications when dockcheck itself has updates. +dockcheck_notification() { + printf "\nSending Discord dockcheck notification\n" + MessageBody="$FromHost - New version of dockcheck available: \n Installed version: $1 \nLatest version: $2 \n\nChangenotes: $3" + + trigger_notification +} diff --git a/notify_templates/notify_generic.sh b/notify_templates/notify_generic.sh index e74d806..5766a41 100644 --- a/notify_templates/notify_generic.sh +++ b/notify_templates/notify_generic.sh @@ -3,14 +3,36 @@ # Copy/rename this file to notify.sh to enable the notification snippet. # generic sample, the "Hello World" of notification addons +FromHost=$(hostname) + +trigger_notification() { + + printf "\n$MessageTitle\n" + printf "\n$MessageBody\n" +} + send_notification() { [ -s "$ScriptWorkDir"/urls.list ] && releasenotes || Updates=("$@") UpdToString=$( printf '%s\\n' "${Updates[@]}" ) - FromHost=$(hostname) # platform specific notification code would go here printf "\n%bGeneric notification addon:%b" "$c_green" "$c_reset" - printf "\nThe following docker containers on %s need to be updated:\n" "$FromHost" - printf "$UpdToString" + + MessageTitle="$FromHost - updates available." + printf -v MessageBody "🐋 Containers on $FromHost with updates available:\n$UpdToString" + + trigger_notification +} + +### Remove or comment out the following function +### to not send notifications when dockcheck itself has updates. +dockcheck_notification() { + printf "\nGeneric dockcheck notification\n" + + MessageTitle="$FromHost - New version of dockcheck available." + # Setting the MessageBody variable here. + printf -v MessageBody "Installed version: $1 \nLatest version: $2 \n\nChangenotes: $3" + + trigger_notification } diff --git a/notify_templates/notify_gotify.sh b/notify_templates/notify_gotify.sh index 49d07ae..7fc10b1 100644 --- a/notify_templates/notify_gotify.sh +++ b/notify_templates/notify_gotify.sh @@ -4,18 +4,9 @@ # Required receiving services must already be set up. # Modify to fit your setup - set GotifyUrl and GotifyToken. -send_notification() { - [ -s "$ScriptWorkDir"/urls.list ] && releasenotes || Updates=("$@") - UpdToString=$( printf '%s\\n' "${Updates[@]}" ) - FromHost=$(hostname) - - # platform specific notification code would go here - printf "\nSending Gotify notification\n" - - # Setting the MessageTitle and MessageBody variable here. - MessageTitle="${FromHost} - updates available." - printf -v MessageBody "Containers on $FromHost with updates available:\n$UpdToString" +FromHost=$(hostname) +trigger_notification() { # Modify to fit your setup: GotifyToken="Your Gotify token here" GotifyUrl="https://api.gotify/message?token=${GotifyToken}" @@ -25,5 +16,30 @@ send_notification() { -F "message=${MessageBody}" \ -F "priority=5" \ -X POST "${GotifyUrl}" 1> /dev/null - +} + +send_notification() { + [ -s "$ScriptWorkDir"/urls.list ] && releasenotes || Updates=("$@") + UpdToString=$( printf '%s\\n' "${Updates[@]}" ) + + # platform specific notification code would go here + printf "\nSending Gotify notification\n" + + # Setting the MessageTitle and MessageBody variable here. + MessageTitle="${FromHost} - updates available." + printf -v MessageBody "Containers on $FromHost with updates available:\n$UpdToString" + + trigger_notification +} + +### Remove or comment out the following function +### to not send notifications when dockcheck itself has updates. +dockcheck_notification() { + printf "\nSending Apprise dockcheck notification\n" + + MessageTitle="$FromHost - New version of dockcheck available." + # Setting the MessageBody variable here. + printf -v MessageBody "Installed version: $1 \nLatest version: $2 \n\nChangenotes: $3" + + trigger_notification } diff --git a/notify_templates/notify_matrix.sh b/notify_templates/notify_matrix.sh index acbcb34..2a93a1e 100644 --- a/notify_templates/notify_matrix.sh +++ b/notify_templates/notify_matrix.sh @@ -4,17 +4,9 @@ # Required receiving services must already be set up. # Modify to fit your setup - set MatrixServer, Room_id and AccessToken -send_notification() { - [ -s "$ScriptWorkDir"/urls.list ] && releasenotes || Updates=("$@") - UpdToString=$( printf '%s\\n' "${Updates[@]}" ) - FromHost=$(hostname) - - # platform specific notification code would go here - printf "\nSending Matrix notification\n" - - # Setting the MessageBody variable here. - MessageBody="🐋 Containers on $FromHost with updates available: \n$UpdToString" +FromHost=$(hostname) +trigger_notification() { # Modify to fit your setup: AccessToken="Your Matrix token here" Room_id="Enter Room_id here" @@ -22,7 +14,30 @@ send_notification() { MsgBody="{\"msgtype\":\"m.text\",\"body\":\"$MessageBody\"}" # URL Example: https://matrix.org/_matrix/client/r0/rooms/!xxxxxx:example.com/send/m.room.message?access_token=xxxxxxxx - curl -sS -o /dev/null --fail -X POST "$MatrixServer/_matrix/client/r0/rooms/$Room_id/send/m.room.message?access_token=$AccessToken" -H 'Content-Type: application/json' -d "$MsgBody" - +} + +send_notification() { + [ -s "$ScriptWorkDir"/urls.list ] && releasenotes || Updates=("$@") + UpdToString=$( printf '%s\\n' "${Updates[@]}" ) + + # platform specific notification code would go here + printf "\nSending Matrix notification\n" + + # Setting the MessageBody variable here. + MessageBody="🐋 Containers on $FromHost with updates available: \n$UpdToString" + + trigger_notification +} + +### Remove or comment out the following function +### to not send notifications when dockcheck itself has updates. +dockcheck_notification() { + printf "\nSending Matrix dockcheck notification\n" + + MessageTitle="$FromHost - New version of dockcheck available." + # Setting the MessageBody variable here. + printf -v MessageBody "Installed version: $1 \nLatest version: $2 \n\nChangenotes: $3" + + trigger_notification }