mirror of
https://github.com/mag37/dockcheck.git
synced 2026-02-14 23:38:15 +01:00
Merge pull request #104 from mag37/notify-rewrite
Complete rewrite of notify function, all templates adjusted + more.
This commit is contained in:
commit
a9f2433fab
13 changed files with 74 additions and 52 deletions
|
|
@ -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).
|
||||
|
|
@ -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:
|
||||
|
|
|
|||
14
dockcheck.sh
14
dockcheck.sh
|
|
@ -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"
|
||||
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -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"
|
||||
|
||||
|
|
@ -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)
|
||||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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" \
|
||||
|
|
|
|||
25
notify_templates/notify_discord.sh
Normal file
25
notify_templates/notify_discord.sh
Normal file
|
|
@ -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"
|
||||
|
||||
|
|
@ -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"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,8 +5,8 @@
|
|||
# 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
|
||||
|
|
@ -14,7 +14,7 @@ send_notification() {
|
|||
|
||||
# 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"
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -6,8 +6,8 @@
|
|||
# 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
|
||||
|
|
@ -15,7 +15,7 @@ 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"
|
||||
|
|
|
|||
|
|
@ -6,8 +6,8 @@
|
|||
# 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
|
||||
|
|
@ -15,7 +15,7 @@ send_notification() {
|
|||
|
||||
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"
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
@ -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)
|
||||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue