Skip to content

Notify rewrite #104

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Oct 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@
___
## :bell: Changelog

- **v0.5.0**: Rewritten notify logic - all templates are adjusted and should be migrated!
- Copy the custom settings from your current template to the new version of the same template.
- Look into, copy and customize the `urls.list` file if that's of interest.
- Other changes:
- Added Discord notify template.
- Verbosity changed of `regctl`.
- **v0.4.9**: Added a function to enrich the notify-message with release note URLs. See [Release notes addon](https://github.com/mag37/dockcheck#date-release-notes-addon-to-notifications)
- **v0.4.8**: Rewrote prune logic to not prompt with options `-a|-y` or `-n`. Auto prune with `-p`.
- **v0.4.7**: Notification Template changes to gotify(new!), DSM(improved), SMTP(deprecation alternative).
Expand Down Expand Up @@ -117,7 +123,7 @@ Further additions are welcome - suggestions or PR!

### :date: Release notes addon to Notifications
There's a function to use a lookup-file to add release note URL's to the notification message.
Copy the notify_templates/`urls.list` file to the script directory and modify it as necessary, it will be used automatically if it's there.
Copy the notify_templates/`urls.list` file to the script directory, it will be used automatically if it's there. Modify it as necessary, the names of interest in the left column needs to match your container names.
The output of the notification will look something like this:
```
Containers on hostname with updates available:
Expand Down
14 changes: 7 additions & 7 deletions dockcheck.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash
VERSION="v0.4.9"
### ChangeNotes: Added a function to enrich the notify-message with release note URLs. See README.
VERSION="v0.5.0"
### ChangeNotes: Rewritten notify logic - all templates adjusted, transfer your current settings to a new template! See README.
Github="https://github.com/mag37/dockcheck"
RawUrl="https://raw.githubusercontent.com/mag37/dockcheck/main/dockcheck.sh"

Expand Down Expand Up @@ -126,7 +126,7 @@ choosecontainers() {
}

datecheck() {
ImageDate=$($regbin image inspect "$RepoUrl" --format='{{.Created}}' | cut -d" " -f1 )
ImageDate=$($regbin -v error image inspect "$RepoUrl" --format='{{.Created}}' | cut -d" " -f1 )
ImageAge=$(( ( $(date +%s) - $(date -d "$ImageDate" +%s) )/86400 ))
if [ "$ImageAge" -gt "$DaysOld" ] ; then
return 0
Expand All @@ -149,12 +149,12 @@ progress_bar() {

### Function to add user-provided urls to releasenotes
releasenotes() {
for update in ${Updates[@]}; do
for update in ${GotUpdates[@]}; do
found=false
while read -r container url; do
[[ $update == $container ]] && printf "%s -> %s\n" "$update" "$url" && found=true
[[ $update == $container ]] && Updates+=("$update -> $url") && found=true
done < "$ScriptWorkDir"/urls.list
[[ $found == false ]] && printf "%s -> url missing\n" "$update" || continue
[[ $found == false ]] && Updates+=("$update -> url missing") || continue
done
}

Expand Down Expand Up @@ -249,7 +249,7 @@ for i in $(docker ps $Stopped --filter "name=$SearchName" --format '{{.Names}}')
RepoUrl=$(docker inspect "$i" --format='{{.Config.Image}}')
LocalHash=$(docker image inspect "$RepoUrl" --format '{{.RepoDigests}}')
# Checking for errors while setting the variable:
if RegHash=$(${t_out} $regbin image digest --list "$RepoUrl" 2>&1) ; then
if RegHash=$(${t_out} $regbin -v error image digest --list "$RepoUrl" 2>&1) ; then
if [[ "$LocalHash" = *"$RegHash"* ]] ; then
NoUpdates+=("$i")
else
Expand Down
13 changes: 6 additions & 7 deletions notify_templates/notify_DSM.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
MSMTP=$(which msmtp)
SSMTP=$(which ssmtp)

if [ -n "$MSMPT" ] ; then
if [ -n "$MSMTP" ] ; then
MailPkg=$MSMTP
elif [ -n "$SSMTP" ] ; then
MailPkg=$SSMTP
Expand All @@ -18,8 +18,8 @@ else
fi

send_notification() {
Updates=("$@")
[ -s "$ScriptWorkDir"/urls.list ] && UpdToString=$( releasenotes ) || UpdToString=$( printf "%s\n" "${Updates[@]}" )
[ -s "$ScriptWorkDir"/urls.list ] && releasenotes || Updates=("$@")
UpdToString=$( printf '%s\\n' "${Updates[@]}" )
FromHost=$(hostname)
CfgFile="/usr/syno/etc/synosmtp.conf"

Expand All @@ -36,6 +36,8 @@ SenderMail=${SenderMail:-$(grep 'eventmail1' $CfgFile | sed -n 's/.*"\([^"]*\)".

printf "\nSending email notification.\n"

printf -v MessageBody "🐋 Containers on $FromHost with updates available:\n\n$UpdToString"

$MailPkg $SendMailTo << __EOF
From: "$SenderName" <$SenderMail>
date:$(date -R)
Expand All @@ -44,10 +46,7 @@ Subject: $SubjectTag Updates available on $FromHost
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit

The following containers on $FromHost have updates available:

$UpdToString

$MessageBody
From $SenderName
__EOF
}
11 changes: 3 additions & 8 deletions notify_templates/notify_apprise.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,15 @@
# Modify to fit your setup - if API, set AppriseURL to your Apprise ip/domain.

send_notification() {
Updates=("$@")
[ -s "$ScriptWorkDir"/urls.list ] && UpdToString=$( releasenotes ) || UpdToString=$( printf "%s\n" "${Updates[@]}" )
[ -s "$ScriptWorkDir"/urls.list ] && releasenotes || Updates=("$@")
UpdToString=$( printf '%s\\n' "${Updates[@]}" )
FromHost=$(hostname)

printf "\nSending Apprise notification\n"

MessageTitle="$FromHost - updates available."
# Setting the MessageBody variable here.
read -d '\n' MessageBody << __EOF
Containers on $FromHost with updates available:

$UpdToString

__EOF
printf -v MessageBody "🐋 Containers on $FromHost with updates available:\n$UpdToString"

# Modify to fit your setup:
apprise -vv -t "$MessageTitle" -b "$MessageBody" \
Expand Down
25 changes: 25 additions & 0 deletions notify_templates/notify_discord.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
### DISCLAIMER: This is a third party addition to dockcheck - best effort testing.
#
# Copy/rename this file to notify.sh to enable the notification snippet.
# 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"

# 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"

8 changes: 5 additions & 3 deletions notify_templates/notify_generic.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
# generic sample, the "Hello World" of notification addons

send_notification() {
Updates=("$@")
[ -s "$ScriptWorkDir"/urls.list ] && UpdToString=$( releasenotes ) || UpdToString=$( printf "%s\n" "${Updates[@]}" )
[ -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%s\n" "$FromHost" "$UpdToString"
printf "\nThe following docker containers on %s need to be updated:\n" "$FromHost"
printf "$UpdToString"
}
6 changes: 3 additions & 3 deletions notify_templates/notify_gotify.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
# Modify to fit your setup - set GotifyUrl and GotifyToken.

send_notification() {
Updates=("$@")
[ -s "$ScriptWorkDir"/urls.list ] && UpdToString=$( releasenotes ) || UpdToString=$( printf "%s\n" "${Updates[@]}" )
[ -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."
MessageBody="Containers on ${FromHost} with updates available: ${UpdToString}"
printf -v MessageBody "🐋 Containers on $FromHost with updates available:\n$UpdToString"

# Modify to fit your setup:
GotifyToken="Your Gotify token here"
Expand Down
4 changes: 2 additions & 2 deletions notify_templates/notify_matrix.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
# Modify to fit your setup - set MatrixServer, Room_id and AccessToken

send_notification() {
Updates=("$@")
[ -s "$ScriptWorkDir"/urls.list ] && UpdToString=$( releasenotes ) || UpdToString=$( printf "%s\n" "${Updates[@]}" )
[ -s "$ScriptWorkDir"/urls.list ] && releasenotes || Updates=("$@")
UpdToString=$( printf '%s\\n' "${Updates[@]}" )
FromHost=$(hostname)

# platform specific notification code would go here
Expand Down
11 changes: 3 additions & 8 deletions notify_templates/notify_ntfy-sh.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,15 @@
# Use your unique Topic Name in the URL below.

send_notification() {
Updates=("$@")
[ -s "$ScriptWorkDir"/urls.list ] && UpdToString=$( releasenotes ) || UpdToString=$( printf "%s\n" "${Updates[@]}" )
[ -s "$ScriptWorkDir"/urls.list ] && releasenotes || Updates=("$@")
UpdToString=$( printf '%s\\n' "${Updates[@]}" )
FromHost=$(hostname)

printf "\nSending ntfy.sh notification\n"

MessageTitle="$FromHost - updates available."
# Setting the MessageBody variable here.
read -d '\n' MessageBody << __EOF
Containers on $FromHost with updates available:

$UpdToString

__EOF
printf -v MessageBody "🐋 Containers on $FromHost with updates available:\n$UpdToString"

# Modify to fit your setup:
NtfyUrl="ntfy.sh/YourUniqueTopicName"
Expand Down
6 changes: 3 additions & 3 deletions notify_templates/notify_pushbullet.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
# Modify to fit your setup - set Url and Token.

send_notification() {
Updates=("$@")
[ -s "$ScriptWorkDir"/urls.list ] && UpdToString=$( releasenotes ) || UpdToString=$( printf "%s\n" "${Updates[@]}" )
[ -s "$ScriptWorkDir"/urls.list ] && releasenotes || Updates=("$@")
UpdToString=$( printf '%s\\n' "${Updates[@]}" )
FromHost=$(hostname)

# platform specific notification code would go here
printf "\nSending pushbullet notification\n"

MessageTitle="$FromHost - updates available."
# Setting the MessageBody variable here.
MessageBody="Containers on $FromHost with updates available: $UpdToString"
printf -v MessageBody "🐋 Containers on $FromHost with updates available:\n$UpdToString"

# Modify to fit your setup:
PushUrl="https://api.pushbullet.com/v2/pushes"
Expand Down
6 changes: 3 additions & 3 deletions notify_templates/notify_pushover.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
# Modify to fit your setup - set Url and Token.

send_notification() {
Updates=("$@")
[ -s "$ScriptWorkDir"/urls.list ] && UpdToString=$( releasenotes ) || UpdToString=$( printf "%s\n" "${Updates[@]}" )
[ -s "$ScriptWorkDir"/urls.list ] && releasenotes || Updates=("$@")
UpdToString=$( printf '%s\\n' "${Updates[@]}" )
FromHost=$(hostname)

# platform specific notification code would go here
printf "\nSending pushover notification\n"

MessageTitle="$FromHost - updates available."
# Setting the MessageBody variable here.
MessageBody="Containers on $FromHost with updates available: $UpdToString"
printf -v MessageBody "🐋 Containers on $FromHost with updates available:\n$UpdToString"

# Modify to fit your setup:
PushoverUrl="https://api.pushover.net/1/messages.json"
Expand Down
12 changes: 6 additions & 6 deletions notify_templates/notify_smtp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
MSMTP=$(which msmtp)
SSMTP=$(which ssmtp)

if [ -n "$MSMPT" ] ; then
if [ -n "$MSMTP" ] ; then
MailPkg=$MSMTP
elif [ -n "$SSMTP" ] ; then
MailPkg=$SSMTP
Expand All @@ -17,8 +17,8 @@ else
fi

send_notification() {
Updates=("$@")
[ -s "$ScriptWorkDir"/urls.list ] && UpdToString=$( releasenotes ) || UpdToString=$( printf "%s\n" "${Updates[@]}" )
[ -s "$ScriptWorkDir"/urls.list ] && releasenotes || Updates=("$@")
UpdToString=$( printf '%s\\n' "${Updates[@]}" )
FromHost=$(hostname)

# User variables:
Expand All @@ -28,6 +28,8 @@ SubjectTag="dockcheck"

printf "\nSending email notification.\n"

printf -v MessageBody "🐋 Containers on $FromHost with updates available:\n\n$UpdToString"

$MailPkg $SendMailTo << __EOF
From: "$FromHost" <$SendMailFrom>
date:$(date -R)
Expand All @@ -36,9 +38,7 @@ Subject: [$SubjectTag] Updates available on $FromHost
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit

The following containers on $FromHost have updates available:

$UpdToString
$MessageBody

__EOF
}
4 changes: 2 additions & 2 deletions notify_templates/notify_telegram.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
# Modify to fit your setup - set TelegramChatId and TelegramToken.

send_notification() {
Updates=("$@")
[ -s "$ScriptWorkDir"/urls.list ] && UpdToString=$( releasenotes ) || UpdToString=$( printf "%s\n" "${Updates[@]}" )
[ -s "$ScriptWorkDir"/urls.list ] && releasenotes || Updates=("$@")
UpdToString=$( printf '%s\\n' "${Updates[@]}" )
FromHost=$(hostname)

# platform specific notification code would go here
Expand Down