Apprise & New option -i

Added new option -i, inform - to send notifications.
This commit is contained in:
mag37 2024-01-06 20:45:34 +01:00 committed by GitHub
commit 77d7340e5b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 137 additions and 24 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
# ignore users custom notify.sh
/notify.sh

View File

@ -15,7 +15,8 @@
<h4 align="center">With features like excluding specific containers, filter by name, auto-prune dangling images and more.</h4</h3>
### :bell: Recent changes
### :bell: Changelog
- **v0.3.3**: Added Apprise template and the option `-i` inform - to send notifications.
- **v0.3.2**: Added a notify function to wrap a notify-script, currently DSM/Ssmtp + template script.
- **v0.3.1**: Addded option `-m` , monochrome mode - no printf color codes.
- **v0.3.0**: Added option `-d N`, age (days) new images have to be before being pulled and updated.
@ -31,9 +32,10 @@
___
## Dependencies
Running docker (duh) and compose, either standalone or plugin.
[`regclient/regctl`](https://github.com/regclient/regclient) (Licensed under [Apache-2.0 License](http://www.apache.org/licenses/LICENSE-2.0))
User will be prompted to download `regctl` if not in `PATH` or `PWD`
- Running docker (duh) and compose, either standalone or plugin.
- [`regclient/regctl`](https://github.com/regclient/regclient) (Licensed under [Apache-2.0 License](http://www.apache.org/licenses/LICENSE-2.0))
- User will be prompted to download `regctl` if not in `PATH` or `PWD`.
- regctl requires `amd64/arm64` - see [workaround](#workaround-for-non-amd64--arm64) if other architecture is used.
___
@ -42,18 +44,20 @@ ___
## `dockcheck.sh`
```
$ ./dockcheck.sh -h
Syntax: dockcheck.sh [OPTION] [part of name to filter]
Syntax: dockcheck.sh [OPTION] [part of name to filter]
Example: dockcheck.sh -y -d 10 -e nextcloud,heimdall
Options:
-h Print this Help.
-a|y Automatic updates, without interaction.
-n No updates, only checking availability.
-d N Only update to new images that are N+ days old. Lists too recent with +prefix and age. 2xSlower.
-e X Exclude containers, separated by comma.
-d N Only update to new images that are N+ days old. Lists too recent with +prefix. 2xSlower.
-h Print this Help.
-i Inform - send a preconfigured notification.
-m Monochrome mode, no printf color codes.
-n No updates, only checking availability.
-p Auto-Prune dangling images after update.
-r Allow updating images for docker run, wont update the container.
-s Include stopped containers in the check. (Logic: docker ps -a).
-s Include stopped containers in the check. (Logic: docker ps -a)
```
Basic example:
@ -75,9 +79,20 @@ Enter number(s) separated by comma, [a] for all - [q] to quit:
Then it proceedes to run `pull` and `up -d` on every container with updates.
After the updates are complete, you'll get prompted if you'd like to prune dangling images.
### Notifications:
### :loudspeaker: Notifications
Trigger with the `-i` flag.
Run it scheduled with `-ni` to only get notified when there's updates available!
Use a `notify_X.sh` template file, copy it to `notify.sh`, modify it to your needs!
Current templates:
- Synology [DSM](https://www.synology.com/en-global/dsm)
- Email with [sSMTP](https://wiki.debian.org/sSMTP)
- Apprise (with it's [multitude](https://github.com/caronc/apprise#supported-notifications) of notifications)
- both native [caronc/apprise](https://github.com/caronc/apprise) and the standalone [linuxserver/docker-apprise-api](https://github.com/linuxserver/docker-apprise-api)
Further additions are welcome - suggestions or PR!
Initiated and first contributed by [yoyoma2](https://github.com/yoyoma2).
A simple email notification function is added, with a generic example and DSM/Ssmtp script by [yoyoma2](https://github.com/yoyoma2). Further addons are welcome, suggestions or PR!
### :warning: `-r flag` disclaimer and warning
**Wont auto-update the containers, only their images. (compose is recommended)**
@ -89,6 +104,27 @@ Containers need to be manually stopped, removed and created again to run on the
- Not respecting `--profile` options when re-creating the container.
- Not working well with containers created by Portainer.
### Workaround for non **amd64** / **arm64**
`regctl` provides binaries for amd64/arm64, to use on other architecture you could try this workaround.
Run regctl in a contianer wrapped in a shell script. Copied from [regclient/docs/install.md](https://github.com/regclient/regclient/blob/main/docs/install.md):
```sh
cat >regctl <<EOF
#!/bin/sh
opts=""
case "\$*" in
"registry login"*) opts="-t";;
esac
docker container run \$opts -i --rm --net host \\
-u "\$(id -u):\$(id -g)" -e HOME -v \$HOME:\$HOME \\
-v /etc/docker/certs.d:/etc/docker/certs.d:ro \\
ghcr.io/regclient/regctl:latest "\$@"
EOF
chmod 755 regctl
```
Test it with `./regctl --help` and then either add the file to the same path as *dockcheck.sh* or in your path (eg. `~/.local/bin/regctl`).
## `dc_brief.sh`
Just a brief, slimmed down version of the script to only print what containers got updates, no updates or errors.

View File

@ -1,6 +1,6 @@
#!/usr/bin/env bash
VERSION="v0.3.2"
### ChangeNotes: Added a notify function - template and email script (DSM etc)
VERSION="v0.3.3"
### ChangeNotes: Added option -i, inform - notify. Added Appraise template.
Github="https://github.com/mag37/dockcheck"
RawUrl="https://raw.githubusercontent.com/mag37/dockcheck/main/dockcheck.sh"
@ -14,7 +14,6 @@ ScriptWorkDir="$(dirname "$ScriptPath")"
LatestRelease="$(curl -s -r 0-50 $RawUrl | sed -n "/VERSION/s/VERSION=//p" | tr -d '"')"
LatestChanges="$(curl -s -r 0-200 $RawUrl | sed -n "/ChangeNotes/s/### ChangeNotes: //p")"
[ -s $ScriptWorkDir/notify.sh ] && source $ScriptWorkDir/notify.sh
### Help Function:
Help() {
@ -26,6 +25,7 @@ Help() {
echo "-d N Only update to new images that are N+ days old. Lists too recent with +prefix and age. 2xSlower."
echo "-e X Exclude containers, separated by comma."
echo "-h Print this Help."
echo "-i Inform - send a preconfigured notification."
echo "-m Monochrome mode, no printf color codes."
echo "-n No updates, only checking availability."
echo "-p Auto-Prune dangling images after update."
@ -41,14 +41,14 @@ c_blue="\033[0;34m"
c_teal="\033[0;36m"
c_reset="\033[0m"
Stopped=""
while getopts "aynprhsme:d:" options; do
while getopts "aynprhisme:d:" options; do
case "${options}" in
a|y) AutoUp="yes" ;;
n) AutoUp="no" ;;
r) DRunUp="yes" ;;
p) AutoPrune="yes" ;;
i) [ -s $ScriptWorkDir/notify.sh ] && { source $ScriptWorkDir/notify.sh ; Notify="yes" ; } ;;
e) Exclude=${OPTARG} ;;
m) declare c_{red,green,yellow,blue,teal,reset}="" ;;
s) Stopped="-a" ;;
@ -234,7 +234,7 @@ fi
if [[ -n ${GotUpdates[*]} ]] ; then
printf "\n%bContainers with updates available:%b\n" "$c_yellow" "$c_reset"
[[ -z "$AutoUp" ]] && options || printf "%s\n" "${GotUpdates[@]}"
[[ $(type -t send_notification) == function ]] && send_notification "${GotUpdates[@]}"
[[ ! -z "$Notify" ]] && { [[ $(type -t send_notification) == function ]] && send_notification "${GotUpdates[@]}" || printf "Could not source notification function.\n" ; }
fi
### Optionally get updates if there's any

View File

@ -1,25 +1,30 @@
### DISCLAIMER: This is a third party addition to dockcheck - best effort testing.
# Copy/rename this file to notify.sh to enable email notifications on synology DSM
#
# Copy/rename this file to notify.sh to enable email notifications on Synology DSM
# DSM Notification Email has to be configured manually.
# Modify to your liking - changing SendMailTo and Subject and content.
send_notification() {
Updates=("$@")
UpdToString=$( printf "%s\n" "${Updates[@]}" )
# change this to your usual destination for synology DSM notification emails
SendMailTo=me@mydomain.com
FromHost=$(hostname)
printf "\nSending email notification\n"
# User variables:
# change this to your usual destination for synology DSM notification emails
SendMailTo="me@mydomain.com"
SubjectTag="diskstation"
printf "\nSending email notification.\n"
ssmtp $SendMailTo << __EOF
From: "$FromHost" <$SendMailTo>
date:$(date -R)
To: <$SendMailTo>
Subject: [diskstation] Some docker containers need to be updated
Subject: [$SubjectTag] Updates available on $FromHost
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
The following docker containers on $FromHost need to be updated:
The following containers on $FromHost have updates available:
$UpdToString

37
notify_apprise.sh Normal file
View File

@ -0,0 +1,37 @@
### 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 - if API, set AppriseURL to your Apprise ip/domain.
send_notification() {
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
# 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
}

View File

@ -1,5 +1,6 @@
### DISCLAIMER: This is a third party addition to dockcheck - best effort testing.
# Copy/rename this file to notify.sh to enable email/text notifications
#
# Copy/rename this file to notify.sh to enable the notification snippet.
# generic sample, the "Hello World" of notification addons
send_notification() {

32
notify_ssmtp.sh Normal file
View File

@ -0,0 +1,32 @@
### DISCLAIMER: This is a third party addition to dockcheck - best effort testing.
#
# Copy/rename this file to notify.sh to enable the notification snipppet.
# sSMTP has to be installed and configured manually.
# Modify to fit your setup - changing SendMailFrom, SendMailTo, SubjectTag
send_notification() {
Updates=("$@")
UpdToString=$( printf "%s\n" "${Updates[@]}" )
FromHost=$(hostname)
# User variables:
SendMailFrom="me@mydomain.tld"
SendMailTo="me@mydomain.tld"
SubjectTag="dockcheck"
printf "\nSending email notification.\n"
ssmtp $SendMailTo << __EOF
From: "$FromHost" <$SendMailFrom>
date:$(date -R)
To: <$SendMailTo>
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
__EOF
}