mirror of
https://github.com/mag37/dockcheck.git
synced 2026-02-14 15:28:22 +01:00
Add file notification channel (#222)
* Add file notification channel * Bypass file channel notifications for dockcheck.sh script * Implement notification channel template reuse and advanced configuration variables. * Fix text insertion formatting for dockcheck script and container updates. * Fix dockcheck.sh notification csv and text output. * Fix ntfy variable references and replace tr for uppercase conversion. * Fix ALLOWEMPTY logic, undefined snippet case, and README formatting. * Refactor notification send/skip logic. Adjust missing variable return codes. * Adjust notifications README section for clarity and readability. --------- Co-authored-by: Matthew Oleksowicz <matt@everyoneneeds.it>
This commit is contained in:
parent
37f33d7a06
commit
31a45f1d84
18 changed files with 620 additions and 267 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -7,3 +7,5 @@
|
|||
regctl
|
||||
# ignore snooze file
|
||||
snooze.list
|
||||
# ignore updates file
|
||||
updates_available.txt
|
||||
82
README.md
82
README.md
|
|
@ -22,6 +22,16 @@
|
|||
___
|
||||
## :bell: Changelog
|
||||
|
||||
- **v0.7.1**:
|
||||
- Added support for multiple notifications using the same template
|
||||
- Added support for notification output format
|
||||
- Added support for file output
|
||||
- Added optional configuration variables per channel to (replace <channel> with any channel name):
|
||||
- <channel>\_TEMPLATE : Specify a template
|
||||
- <channel>\_SKIPSNOOZE : Skip snooze
|
||||
- <channel>\_CONTAINERSONLY : Only notify for docker container related updates
|
||||
- <channel>\_ALLOWEMPTY : Always send notifications, even when empty
|
||||
- <channel>\_OUTPUT : Define output format
|
||||
- **v0.7.0**:
|
||||
- Bugfix: snooze dockcheck.sh-self-notification and some config clarification.
|
||||
- Added authentication support to Ntfy.sh.
|
||||
|
|
@ -126,13 +136,15 @@ Alternatively create an alias where specific flags and values are set.
|
|||
Example `alias dc=dockcheck.sh -p -x 10 -t 3`.
|
||||
|
||||
## :loudspeaker: Notifications
|
||||
Trigger with the `-i` flag.
|
||||
If `notify.sh` is present and configured, it will be used. Otherwise, `notify_v2.sh` will be enabled.
|
||||
Will send a list of containers with updates available and a notification when `dockcheck.sh` itself has an update.
|
||||
Run it scheduled with `-ni` to only get notified when there's updates available!
|
||||
Triggered with the `-i` flag. Will send a list of containers with updates available and a notification when `dockcheck.sh` itself has an update.
|
||||
`notify_templates/notify_v2.sh` is the default notification wrapper, if `notify.sh` is present and configured, it will override.
|
||||
|
||||
Example of a cron scheduled job running non-interactive at 10'oclock excluding 1 container and sending notifications:
|
||||
`0 10 * * * /home/user123/.local/bin/dockcheck.sh -nix 10 -e excluded_container1`
|
||||
|
||||
#### Installation and configuration:
|
||||
Make certain your project directory is laid out as below. You only need the notify_v2.sh file and any notification templates you wish to enable, but there is no harm in having all of them present.
|
||||
Set up a directory structure as below.
|
||||
You only need the `notify_templates/notify_v2.sh` file and any notification templates you wish to enable, but there is no harm in having all of them present.
|
||||
```
|
||||
.
|
||||
├── notify_templates/
|
||||
|
|
@ -154,27 +166,27 @@ Make certain your project directory is laid out as below. You only need the noti
|
|||
├── dockcheck.sh
|
||||
└── urls.list # optional
|
||||
```
|
||||
Uncomment and set the NOTIFY_CHANNELS environment variable in `dockcheck.config` to a space separated string of your desired notification channels to enable.
|
||||
Uncomment and set the environment variables related to the enabled notification channels.
|
||||
It is recommended to only edit the environmental variables in `dockcheck.config` and not make changes directly to the `notify_X.sh` template files within the `notify_templates` subdirectory.
|
||||
If you wish to customize the notify templates yourself, you may copy them to your project root directory alongside the main `dockcheck.sh` script (where they will also be ignored by git).
|
||||
- Uncomment and set the `NOTIFY_CHANNELS=""` environment variable in `dockcheck.config` to a space separated string of your desired notification channels to enable.
|
||||
- Uncomment and set the environment variables related to the enabled notification channels. Eg. `GOTIFY_DOMAIN=""` + `GOTIFY_TOKEN=""`.
|
||||
|
||||
It's recommended to only do configuration with variables within `dockcheck.config` and not modify `notify_templates/notify_X.sh` directly.
|
||||
If you wish to customize the notify templates yourself, you may copy them to your project root directory alongside the main `dockcheck.sh` (where they're also ignored by git).
|
||||
Customizing `notify_v2.sh` is handled the same as customizing the templates, but it must be renamed to `notify.sh` within the `dockcheck.sh` root directory.
|
||||
|
||||
|
||||
#### Legacy installation and configuration:
|
||||
Use a previous version of a `notify_X.sh` template file (tag v0.6.4 or earlier) from the **notify_templates** directory,
|
||||
copy it to `notify.sh` alongside the script, modify it to your needs! (notify.sh is added to .gitignore)
|
||||
|
||||
#### Snooze feature:
|
||||
**Use case:** You wish to be notified of available updates in a timely manner, but do not require reminders after the initial notification with the same frequency.
|
||||
e.g. *Dockcheck is scheduled to run every hour. You will receive an update notification within an hour of availability.*
|
||||
**Snooze enabled:** you will not receive another notification about updates for this container for a configurable period of time.
|
||||
**Snooze disabled:** you will receive additional notifications every hour.
|
||||
Configure to receive scheduled notifications only if they're new since the last notification - within a set time frame.
|
||||
|
||||
**Example:** *Dockcheck is scheduled to run every hour. You will receive an update notification within an hour of availability.*
|
||||
**Snooze enabled:** You will not receive a repeated notification about an already notified update within the snooze duration.
|
||||
**Snooze disabled:** You will receive additional (possibly repeated) notifications every hour.
|
||||
|
||||
To enable snooze uncomment the `SNOOZE_SECONDS` variable in your `dockcheck.config` and set it to the number of seconds you wish to prevent duplicate alerts.
|
||||
Snooze is split into three categories; container updates, `dockcheck.sh` self updates and notification template updates.
|
||||
|
||||
To enable snooze, uncomment the `SNOOZE_SECONDS` variable in your `dockcheck.config` file and set it to the number of seconds you wish to prevent duplicate alerts.
|
||||
The true snooze duration will be 60 seconds less than your configure value to account for minor scheduling or script run time issues.
|
||||
If an update becomes available for an item that is not snoozed, notifications will be sent and include all available updates for that item's category, even snoozed items.
|
||||
`dockcheck.sh` updates, notification template updates, and container updates are considered three separate categories.
|
||||
|
||||
The actual snooze duration will be 60 seconds less than `SNOOZE_SECONDS` to account for minor scheduling or run time issues.
|
||||
|
||||
|
||||
#### Current notify templates:
|
||||
|
|
@ -193,15 +205,31 @@ If an update becomes available for an item that is not snoozed, notifications wi
|
|||
- [Discord](https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks) - Discord webhooks.
|
||||
- [Slack](https://api.slack.com/tutorials/tracks/posting-messages-with-curl) - Slack curl api
|
||||
|
||||
Further additions are welcome - suggestions or PRs!
|
||||
<sub><sup>Initiated and first contributed by [yoyoma2](https://github.com/yoyoma2).</sup></sub>
|
||||
Further additions are welcome - suggestions or PRs!
|
||||
<sub><sup>Initiated and first contributed by [yoyoma2](https://github.com/yoyoma2).</sup></sub>
|
||||
|
||||
#### Notification channel configuration:
|
||||
All required environment variables for each notification channel are provided in the default.config file as comments and must be uncommented and modified for your requirements.
|
||||
For advanced users, additional functionality is available via custom configurations and environment variables.
|
||||
Use cases - all configured in `dockcheck.config`:
|
||||
(replace `<channel>` with the upper case name of the of the channel as listed in `NOTIFY_CHANNELS` variable, eg `TELEGRAM_SKIPSNOOZE`)
|
||||
- To bypass the snooze feature, even when enabled, add the variable `<channel>_SKIPSNOOZE` and set it to `true`.
|
||||
- To configure the channel to only send container update notifications, add the variable `<channel>_CONTAINERSONLY` and set it to `true`.
|
||||
- To send notifications even when there are no updates available, add the variable `<channel>_ALLOWEMPTY` and set it to `true`.
|
||||
- To use another notification output format, add the variable `<channel>_OUTPUT` and set it to `csv`, `json`, or `text`. If unset or set to an invalid value, defaults to `text`.
|
||||
- To send multiple notifications using the same notification template:
|
||||
- Strings in the `NOTIFY_CHANNELS` list are now treated as unique names and do not necessarily refer to the notification template that will be called, though they do by default.
|
||||
- Add another notification channel to `NOTIFY_CHANNELS` in `dockcheck.config`. The name can contain upper and lower case letters, numbers and underscores, but can't start with a number.
|
||||
- Add the variable `<channel>_TEMPLATE` to `dockcheck.config` where `<channel>` is the name of the channel added above and set the value to an available notification template script (`slack`, `apprise`, `gotify`, etc.)
|
||||
- Add all other environment variables required for the chosen template to function with `<channel>` in upper case as the prefix rather than the template name.
|
||||
- For example, if `<channel>` is `mynotification` and the template configured is `slack`, you would need to set `MYNOTIFICATION_CHANNEL_ID` and `MYNOTIFICATION_ACCESS_TOKEN`.
|
||||
|
||||
### :date: Release notes addon
|
||||
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, 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.
|
||||
To also list the URL's in the CLI output (choose containers list) use the `-I` option or variable config.
|
||||
For Markdown formatting also add the `-M` option. (**this requires the template to be compatible - see gotify for example**)
|
||||
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, 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.
|
||||
To also list the URL's in the CLI output (choose containers list) use the `-I` option or variable config.
|
||||
For Markdown formatting also add the `-M` option. (**this requires the template to be compatible - see gotify for example**)
|
||||
|
||||
The output of the notification will look something like this:
|
||||
```
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@
|
|||
## All commented values are examples only. Modify as needed.
|
||||
##
|
||||
## Uncomment the line below and specify the notification channels you wish to enable in a space separated string
|
||||
# NOTIFY_CHANNELS="apprise discord DSM generic HA gotify matrix ntfy pushbullet pushover slack smtp telegram"
|
||||
# NOTIFY_CHANNELS="apprise discord DSM file generic HA gotify matrix ntfy pushbullet pushover slack smtp telegram file"
|
||||
#
|
||||
## Uncomment the line below and specify the number of seconds to delay notifications to enable snooze
|
||||
# SNOOZE_SECONDS=86400
|
||||
|
|
@ -87,4 +87,6 @@
|
|||
# TELEGRAM_CHAT_ID="mychatid"
|
||||
# TELEGRAM_TOKEN="token-value"
|
||||
# TELEGRAM_TOPIC_ID="0"
|
||||
#
|
||||
# FILE_PATH="${ScriptWorkDir}/updates_available.txt"
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
#!/usr/bin/env bash
|
||||
VERSION="v0.7.0"
|
||||
# ChangeNotes: Snooze bugfix, added auth support to ntfy.sh and sendmail support to SMTP
|
||||
VERSION="v0.7.1"
|
||||
# ChangeNotes: Add support for multiple notifications of the same type, output formatting, and file output
|
||||
Github="https://github.com/mag37/dockcheck"
|
||||
RawUrl="https://raw.githubusercontent.com/mag37/dockcheck/main/dockcheck.sh"
|
||||
|
||||
|
|
@ -507,6 +507,8 @@ if [[ -n ${GotUpdates[*]:-} ]]; then
|
|||
if [[ -s "$ScriptWorkDir/urls.list" ]] && [[ "$PrintReleaseURL" == true ]]; then releasenotes; else Updates=("${GotUpdates[@]}"); fi
|
||||
[[ "$AutoMode" == false ]] && list_options || printf "%s\n" "${Updates[@]}"
|
||||
[[ "$Notify" == true ]] && { exec_if_exists_or_fail send_notification "${GotUpdates[@]}" || printf "\nCould not source notification function.\n"; }
|
||||
else
|
||||
[[ "$Notify" == true ]] && [[ ! -s "${ScriptWorkDir}/notify.sh" ]] && { exec_if_exists_or_fail send_notification "${GotUpdates[@]}" || printf "\nCould not source notification function.\n"; }
|
||||
fi
|
||||
|
||||
# Optionally get updates if there's any
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
### DISCLAIMER: This is a third party addition to dockcheck - best effort testing.
|
||||
NOTIFY_DSM_VERSION="v0.4"
|
||||
NOTIFY_DSM_VERSION="v0.5"
|
||||
# INFO: ssmtp is deprecated - consider to use msmtp instead.
|
||||
#
|
||||
# mSMTP/sSMTP has to be installed and configured manually.
|
||||
|
|
@ -23,15 +23,26 @@ else
|
|||
fi
|
||||
|
||||
trigger_DSM_notification() {
|
||||
if [[ -n "$1" ]]; then
|
||||
DSM_channel="$1"
|
||||
else
|
||||
DSM_channel="DSM"
|
||||
fi
|
||||
|
||||
UpperChannel="${DSM_channel^^}"
|
||||
|
||||
DSMSendmailToVar="${UpperChannel}_SENDMAILTO"
|
||||
DSMSubjectTagVar="${UpperChannel}_SUBJECTTAG"
|
||||
|
||||
CfgFile="/usr/syno/etc/synosmtp.conf"
|
||||
|
||||
# User variables:
|
||||
# Automatically sends to your usual destination for synology DSM notification emails.
|
||||
# You can also manually override by assigning something else to DSM_SENDMAILTO in dockcheck.config.
|
||||
SendMailTo=${DSM_SENDMAILTO:-$(grep 'eventmail1' $CfgFile | sed -n 's/.*"\([^"]*\)".*/\1/p')}
|
||||
SendMailTo=${!DSMSendmailToVar:-$(grep 'eventmail1' $CfgFile | sed -n 's/.*"\([^"]*\)".*/\1/p')}
|
||||
# e.g. DSM_SENDMAILTO="me@mydomain.com"
|
||||
|
||||
SubjectTag=${DSM_SUBJECTTAG:-$(grep 'eventsubjectprefix' $CfgFile | sed -n 's/.*"\([^"]*\)".*/\1/p')}
|
||||
SubjectTag=${!DSMSubjectTagVar:-$(grep 'eventsubjectprefix' $CfgFile | sed -n 's/.*"\([^"]*\)".*/\1/p')}
|
||||
# e.g. DSM_SUBJECTTAG="Email Subject Prefix"
|
||||
SenderName=$(grep 'smtp_from_name' $CfgFile | sed -n 's/.*"\([^"]*\)".*/\1/p')
|
||||
SenderMail=$(grep 'smtp_from_mail' $CfgFile | sed -n 's/.*"\([^"]*\)".*/\1/p')
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
### DISCLAIMER: This is a third party addition to dockcheck - best effort testing.
|
||||
NOTIFY_HA_VERSION="v0.1"
|
||||
NOTIFY_HA_VERSION="v0.2"
|
||||
#
|
||||
# This is an integration that makes it possible to send notifications via Home Assistant (https://www.home-assistant.io/integrations/notify/)
|
||||
# You need to generate a long-lived access token in Home Sssistant to be used here (https://developers.home-assistant.io/docs/auth_api/#long-lived-access-token)
|
||||
|
|
@ -7,15 +7,28 @@ NOTIFY_HA_VERSION="v0.1"
|
|||
# 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 HA_ENTITY, HA_URL and HA_TOKEN in your dockcheck.config file.
|
||||
|
||||
if [[ -z "${HA_ENTITY:-}" ]] || [[ -z "${HA_URL:-}" ]] || [[ -z "${HA_TOKEN:-}" ]]; then
|
||||
printf "Home Assistant notification channel enabled, but required configuration variables are missing. Home assistant notifications will not be sent.\n"
|
||||
|
||||
remove_channel HA
|
||||
fi
|
||||
|
||||
trigger_HA_notification() {
|
||||
AccessToken="${HA_TOKEN}"
|
||||
Url="${HA_URL}/api/services/notify/${HA_ENTITY}"
|
||||
if [[ -n "$1" ]]; then
|
||||
HA_channel="$1"
|
||||
else
|
||||
HA_channel="HA"
|
||||
fi
|
||||
|
||||
UpperChannel="${HA_channel^^}"
|
||||
|
||||
HAEntityVar="${UpperChannel}_ENTITY"
|
||||
HAUrlVar="${UpperChannel}_URL"
|
||||
HATokenVar="${UpperChannel}_TOKEN"
|
||||
|
||||
if [[ -z "${!HAEntityVar:-}" ]] || [[ -z "${!HAUrlVar:-}" ]] || [[ -z "${!HATokenVar:-}" ]]; then
|
||||
printf "The ${HA_channel} notification channel is enabled, but required configuration variables are missing. Home assistant notifications will not be sent.\n"
|
||||
|
||||
remove_channel HA
|
||||
return 0
|
||||
fi
|
||||
|
||||
AccessToken="${!HATokenVar}"
|
||||
Url="${!HAUrlVar}/api/services/notify/${!HAEntityVar}"
|
||||
JsonData=$( "$jqbin" -n \
|
||||
--arg body "$MessageBody" \
|
||||
'{"title": "dockcheck update", "message": $body}' )
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
### DISCLAIMER: This is a third party addition to dockcheck - best effort testing.
|
||||
NOTIFY_APPRISE_VERSION="v0.3"
|
||||
NOTIFY_APPRISE_VERSION="v0.4"
|
||||
#
|
||||
# Required receiving services must already be set up.
|
||||
# Leave (or place) this file in the "notify_templates" subdirectory within the same directory as the main dockcheck.sh script.
|
||||
|
|
@ -7,17 +7,28 @@ NOTIFY_APPRISE_VERSION="v0.3"
|
|||
# Do not modify this file directly within the "notify_templates" subdirectory. Set APPRISE_PAYLOAD in your dockcheck.config file.
|
||||
# If API, set APPRISE_URL instead.
|
||||
|
||||
if [[ -z "${APPRISE_PAYLOAD:-}" ]] && [[ -z "${APPRISE_URL:-}" ]]; then
|
||||
printf "Apprise notification channel enabled, but required configuration variables are missing. Apprise notifications will not be sent.\n"
|
||||
|
||||
remove_channel apprise
|
||||
fi
|
||||
|
||||
trigger_apprise_notification() {
|
||||
if [[ -n "$1" ]]; then
|
||||
apprise_channel="$1"
|
||||
else
|
||||
apprise_channel="apprise"
|
||||
fi
|
||||
|
||||
if [[ -n "${APPRISE_PAYLOAD:-}" ]]; then
|
||||
UpperChannel="${apprise_channel^^}"
|
||||
|
||||
ApprisePayloadVar="${UpperChannel}_PAYLOAD"
|
||||
AppriseUrlVar="${UpperChannel}_URL"
|
||||
|
||||
if [[ -z "${!ApprisePayloadVar:-}" ]] && [[ -z "${!AppriseUrlVar:-}" ]]; then
|
||||
printf "The ${apprise_channel} notification channel is enabled, but required configuration variables are missing. Apprise notifications will not be sent.\n"
|
||||
|
||||
remove_channel apprise
|
||||
return 0
|
||||
fi
|
||||
|
||||
if [[ -n "${!ApprisePayloadVar:-}" ]]; then
|
||||
apprise -vv -t "$MessageTitle" -b "$MessageBody" \
|
||||
${APPRISE_PAYLOAD}
|
||||
${!ApprisePayloadVar}
|
||||
|
||||
if [[ $? -gt 0 ]]; then
|
||||
NotifyError=true
|
||||
|
|
@ -29,8 +40,8 @@ trigger_apprise_notification() {
|
|||
# pbul://o.gn5kj6nfhv736I7jC3cj3QLRiyhgl98b
|
||||
# tgram://{bot_token}/{chat_id}/'
|
||||
|
||||
if [[ -n "${APPRISE_URL:-}" ]]; then
|
||||
AppriseURL="${APPRISE_URL}"
|
||||
if [[ -n "${!AppriseUrlVar:-}" ]]; then
|
||||
AppriseURL="${!AppriseUrlVar}"
|
||||
curl -S -o /dev/null ${CurlArgs} -X POST -F "title=$MessageTitle" -F "body=$MessageBody" -F "tags=all" $AppriseURL # e.g. APPRISE_URL=http://apprise.mydomain.tld:1234/notify/apprise
|
||||
|
||||
if [[ $? -gt 0 ]]; then
|
||||
|
|
|
|||
|
|
@ -1,19 +1,30 @@
|
|||
### DISCLAIMER: This is a third party addition to dockcheck - best effort testing.
|
||||
NOTIFY_DISCORD_VERSION="v0.4"
|
||||
NOTIFY_DISCORD_VERSION="v0.5"
|
||||
#
|
||||
# Required receiving services must already be set up.
|
||||
# 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.
|
||||
|
||||
if [[ -z "${DISCORD_WEBHOOK_URL:-}" ]]; then
|
||||
printf "Discord notification channel enabled, but required configuration variables are missing. Discord notifications will not be sent.\n"
|
||||
|
||||
remove_channel discord
|
||||
fi
|
||||
|
||||
trigger_discord_notification() {
|
||||
DiscordWebhookUrl="${DISCORD_WEBHOOK_URL}" # e.g. DISCORD_WEBHOOK_URL=https://discord.com/api/webhooks/<token string>
|
||||
if [[ -n "$1" ]]; then
|
||||
discord_channel="$1"
|
||||
else
|
||||
discord_channel="discord"
|
||||
fi
|
||||
|
||||
UpperChannel="${discord_channel^^}"
|
||||
|
||||
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>
|
||||
|
||||
JsonData=$( "$jqbin" -n \
|
||||
--arg username "$FromHost" \
|
||||
|
|
|
|||
22
notify_templates/notify_file.sh
Normal file
22
notify_templates/notify_file.sh
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
### DISCLAIMER: This is a third party addition to dockcheck - best effort testing.
|
||||
NOTIFY_FILE_VERSION="v0.1"
|
||||
#
|
||||
# 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.
|
||||
|
||||
trigger_file_notification() {
|
||||
if [[ -n "$1" ]]; then
|
||||
file_channel="$1"
|
||||
UpperChannel=$(tr '[:lower:]' '[:upper:]' <<< "$file_channel")
|
||||
else
|
||||
file_channel="file"
|
||||
UpperChannel="FILE"
|
||||
fi
|
||||
|
||||
FilePathVar="${UpperChannel}_PATH"
|
||||
|
||||
NotifyFile="${!FilePathVar:=${ScriptWorkDir}/updates_available.txt}"
|
||||
|
||||
echo "${MessageBody}" > ${NotifyFile}
|
||||
|
||||
}
|
||||
|
|
@ -1,20 +1,32 @@
|
|||
### DISCLAIMER: This is a third party addition to dockcheck - best effort testing.
|
||||
NOTIFY_GOTIFY_VERSION="v0.4"
|
||||
NOTIFY_GOTIFY_VERSION="v0.5"
|
||||
#
|
||||
# Required receiving services must already be set up.
|
||||
# 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 GOTIFY_TOKEN and GOTIFY_DOMAIN in your dockcheck.config file.
|
||||
|
||||
if [[ -z "${GOTIFY_TOKEN:-}" ]] || [[ -z "${GOTIFY_DOMAIN:-}" ]]; then
|
||||
printf "Gotify notification channel enabled, but required configuration variables are missing. Gotify notifications will not be sent.\n"
|
||||
|
||||
remove_channel gotify
|
||||
fi
|
||||
|
||||
trigger_gotify_notification() {
|
||||
GotifyToken="${GOTIFY_TOKEN}" # e.g. GOTIFY_TOKEN=token-value
|
||||
GotifyUrl="${GOTIFY_DOMAIN}/message?token=${GotifyToken}" # e.g. GOTIFY_URL=https://gotify.domain.tld
|
||||
if [[ -n "$1" ]]; then
|
||||
gotify_channel="$1"
|
||||
else
|
||||
gotify_channel="gotify"
|
||||
fi
|
||||
|
||||
UpperChannel="${gotify_channel^^}"
|
||||
|
||||
GotifyTokenVar="${UpperChannel}_TOKEN"
|
||||
GotifyUrlVar="${UpperChannel}_DOMAIN"
|
||||
|
||||
if [[ -z "${!GotifyTokenVar:-}" ]] || [[ -z "${!GotifyUrlVar:-}" ]]; then
|
||||
printf "The ${gotify_channel} notification channel is enabled, but required configuration variables are missing. Gotify notifications will not be sent.\n"
|
||||
|
||||
remove_channel gotify
|
||||
return 0
|
||||
fi
|
||||
|
||||
GotifyToken="${!GotifyTokenVar}" # e.g. GOTIFY_TOKEN=token-value
|
||||
GotifyUrl="${!GotifyUrlVar}/message?token=${GotifyToken}" # e.g. GOTIFY_URL=https://gotify.domain.tld
|
||||
|
||||
if [[ "$PrintMarkdownURL" == true ]]; then
|
||||
ContentType="text/markdown"
|
||||
|
|
|
|||
|
|
@ -1,25 +1,38 @@
|
|||
### DISCLAIMER: This is a third party addition to dockcheck - best effort testing.
|
||||
NOTIFY_MATRIX_VERSION="v0.3"
|
||||
NOTIFY_MATRIX_VERSION="v0.4"
|
||||
#
|
||||
# Required receiving services must already be set up.
|
||||
# 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 MATRIX_ACCESS_TOKEN, MATRIX_ROOM_ID, and MATRIX_SERVER_URL in your dockcheck.config file.
|
||||
|
||||
if [[ -z "${MATRIX_ACCESS_TOKEN:-}" ]] || [[ -z "${MATRIX_ROOM_ID}:-" ]] || [[ -z "${MATRIX_SERVER_URL}:-" ]]; then
|
||||
printf "Matrix notification channel enabled, but required configuration variables are missing. Matrix notifications will not be sent.\n"
|
||||
|
||||
remove_channel matrix
|
||||
fi
|
||||
|
||||
trigger_matrix_notification() {
|
||||
AccessToken="${MATRIX_ACCESS_TOKEN}" # e.g. MATRIX_ACCESS_TOKEN=token-value
|
||||
Room_id="${MATRIX_ROOM_ID}" # e.g. MATRIX_ROOM_ID=myroom
|
||||
MatrixServer="${MATRIX_SERVER_URL}" # e.g. MATRIX_SERVER_URL=http://matrix.yourdomain.tld
|
||||
if [[ -n "$1" ]]; then
|
||||
matrix_channel="$1"
|
||||
else
|
||||
matrix_channel="matrix"
|
||||
fi
|
||||
|
||||
UpperChannel="${matrix_channel^^}"
|
||||
|
||||
AccessTokenVar="${UpperChannel}_ACCESS_TOKEN"
|
||||
RoomIdVar="${UpperChannel}_ROOM_ID"
|
||||
MatrixServerVar="${UpperChannel}_SERVER_URL"
|
||||
|
||||
if [[ -z "${!AccessTokenVar:-}" ]] || [[ -z "${!RoomIdVar:-}" ]] || [[ -z "${!MatrixServerVar:-}" ]]; then
|
||||
printf "The ${matrix_channel} notification channel is enabled, but required configuration variables are missing. Matrix notifications will not be sent.\n"
|
||||
|
||||
remove_channel matrix
|
||||
return 0
|
||||
fi
|
||||
|
||||
AccessToken="${!AccessTokenVar}" # e.g. MATRIX_ACCESS_TOKEN=token-value
|
||||
RoomId="${!RoomIdVar}" # e.g. MATRIX_ROOM_ID=myroom
|
||||
MatrixServer="${!MatrixServerVar}" # e.g. MATRIX_SERVER_URL=http://matrix.yourdomain.tld
|
||||
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 -S -o /dev/null ${CurlArgs} -X POST "$MatrixServer/_matrix/client/r0/rooms/$Room_id/send/m.room.message?access_token=$AccessToken" -H 'Content-Type: application/json' -d "$MsgBody"
|
||||
curl -S -o /dev/null ${CurlArgs} -X POST "$MatrixServer/_matrix/client/r0/rooms/$RoomId/send/m.room.message?access_token=$AccessToken" -H 'Content-Type: application/json' -d "$MsgBody"
|
||||
|
||||
if [[ $? -gt 0 ]]; then
|
||||
NotifyError=true
|
||||
|
|
|
|||
|
|
@ -1,19 +1,32 @@
|
|||
### DISCLAIMER: This is a third party addition to dockcheck - best effort testing.
|
||||
NOTIFY_NTFYSH_VERSION="v0.6"
|
||||
NOTIFY_NTFYSH_VERSION="v0.7"
|
||||
#
|
||||
# Setup app and subscription at https://ntfy.sh
|
||||
# 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 NTFY_DOMAIN and NTFY_TOPIC_NAME in your dockcheck.config file.
|
||||
|
||||
if [[ -z "${NTFY_DOMAIN:-}" ]] || [[ -z "${NTFY_TOPIC_NAME:-}" ]]; then
|
||||
printf "Ntfy notification channel enabled, but required configuration variables are missing. Ntfy notifications will not be sent.\n"
|
||||
|
||||
remove_channel ntfy
|
||||
fi
|
||||
|
||||
trigger_ntfy_notification() {
|
||||
NtfyUrl="${NTFY_DOMAIN}/${NTFY_TOPIC_NAME}"
|
||||
if [[ -n "$1" ]]; then
|
||||
ntfy_channel="$1"
|
||||
else
|
||||
ntfy_channel="ntfy"
|
||||
fi
|
||||
|
||||
UpperChannel="${ntfy_channel^^}"
|
||||
|
||||
NtfyDomainVar="${UpperChannel}_DOMAIN"
|
||||
NtfyTopicNameVar="${UpperChannel}_TOPIC_NAME"
|
||||
NtfyAuthVar="${UpperChannel}_AUTH"
|
||||
|
||||
if [[ -z "${!NtfyDomainVar:-}" ]] || [[ -z "${!NtfyTopicNameVar:-}" ]]; then
|
||||
printf "The ${ntfy_channel} notification channel is enabled, but required configuration variables are missing. Ntfy notifications will not be sent.\n"
|
||||
|
||||
remove_channel ntfy
|
||||
return 0
|
||||
fi
|
||||
|
||||
NtfyUrl="${!NtfyDomainVar}/${!NtfyTopicNameVar}"
|
||||
# e.g.
|
||||
# NTFY_DOMAIN=ntfy.sh
|
||||
# NTFY_TOPIC_NAME=YourUniqueTopicName
|
||||
|
|
@ -24,8 +37,8 @@ trigger_ntfy_notification() {
|
|||
ContentType="Markdown: no" #text/plain
|
||||
fi
|
||||
|
||||
if [[ -n "${NTFY_AUTH:-}" ]]; then
|
||||
NtfyAuth="-u $NTFY_AUTH"
|
||||
if [[ -n "${!NtfyAuthVar:-}" ]]; then
|
||||
NtfyAuth="-u ${!NtfyAuthVar}"
|
||||
else
|
||||
NtfyAuth=""
|
||||
fi
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
### DISCLAIMER: This is a third party addition to dockcheck - best effort testing.
|
||||
NOTIFY_PUSHBULLET_VERSION="v0.3"
|
||||
NOTIFY_PUSHBULLET_VERSION="v0.4"
|
||||
#
|
||||
# Required receiving services must already be set up.
|
||||
# Requires jq installed and in PATH.
|
||||
|
|
@ -7,15 +7,27 @@ NOTIFY_PUSHBULLET_VERSION="v0.3"
|
|||
# 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 PUSHBULLET_TOKEN and PUSHBULLET_URL in your dockcheck.config file.
|
||||
|
||||
if [[ -z "${PUSHBULLET_URL:-}" ]] || [[ -z "${PUSHBULLET_TOKEN:-}" ]]; then
|
||||
printf "Pushbullet notification channel enabled, but required configuration variables are missing. Pushbullet notifications will not be sent.\n"
|
||||
|
||||
remove_channel pushbullet
|
||||
fi
|
||||
|
||||
trigger_pushbullet_notification() {
|
||||
PushUrl="${PUSHBULLET_URL}" # e.g. PUSHBULLET_URL=https://api.pushbullet.com/v2/pushes
|
||||
PushToken="${PUSHBULLET_TOKEN}" # e.g. PUSHBULLET_TOKEN=token-value
|
||||
if [[ -n "$1" ]]; then
|
||||
pushbullet_channel="$1"
|
||||
else
|
||||
pushbullet_channel="pushbullet"
|
||||
fi
|
||||
|
||||
UpperChannel="${pushbullet_channel^^}"
|
||||
|
||||
PushUrlVar="${UpperChannel}_URL"
|
||||
PushTokenVar="${UpperChannel}_TOKEN"
|
||||
|
||||
if [[ -z "${!PushUrlVar:-}" ]] || [[ -z "${!PushTokenVar:-}" ]]; then
|
||||
printf "The ${pushbullet_channel} notification channel is enabled, but required configuration variables are missing. Pushbullet notifications will not be sent.\n"
|
||||
|
||||
remove_channel pushbullet
|
||||
return 0
|
||||
fi
|
||||
|
||||
PushUrl="${!PushUrlVar}" # e.g. PUSHBULLET_URL=https://api.pushbullet.com/v2/pushes
|
||||
PushToken="${!PushTokenVar}" # e.g. PUSHBULLET_TOKEN=token-value
|
||||
|
||||
# Requires jq to process json data
|
||||
"$jqbin" -n --arg title "$MessageTitle" --arg body "$MessageBody" '{body: $body, title: $title, type: "note"}' | curl -S -o /dev/null ${CurlArgs} -X POST -H "Access-Token: $PushToken" -H "Content-type: application/json" $PushUrl -d @-
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
### DISCLAIMER: This is a third party addition to dockcheck - best effort testing.
|
||||
NOTIFY_PUSHOVER_VERSION="v0.3"
|
||||
NOTIFY_PUSHOVER_VERSION="v0.4"
|
||||
#
|
||||
# Required receiving services must already be set up.
|
||||
# Requires jq installed and in PATH.
|
||||
|
|
@ -7,16 +7,29 @@ NOTIFY_PUSHOVER_VERSION="v0.3"
|
|||
# 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 PUSHOVER_USER_KEY, PUSHOVER_TOKEN, and PUSHOVER_URL in your dockcheck.config file.
|
||||
|
||||
if [[ -z "${PUSHOVER_URL:-}" ]] || [[ -z "${PUSHOVER_USER_KEY:-}" ]] || [[ -z "${PUSHOVER_TOKEN:-}" ]]; then
|
||||
printf "Pushover notification channel enabled, but required configuration variables are missing. Pushover notifications will not be sent.\n"
|
||||
|
||||
remove_channel pushover
|
||||
fi
|
||||
|
||||
trigger_pushover_notification() {
|
||||
PushoverUrl="${PUSHOVER_URL}" # e.g. PUSHOVER_URL=https://api.pushover.net/1/messages.json
|
||||
PushoverUserKey="${PUSHOVER_USER_KEY}" # e.g. PUSHOVER_USER_KEY=userkey
|
||||
PushoverToken="${PUSHOVER_TOKEN}" # e.g. PUSHOVER_TOKEN=token-value
|
||||
if [[ -n "$1" ]]; then
|
||||
pushover_channel="$1"
|
||||
else
|
||||
pushover_channel="pushover"
|
||||
fi
|
||||
|
||||
UpperChannel="${pushover_channel^^}"
|
||||
|
||||
PushoverUrlVar="${UpperChannel}_URL"
|
||||
PushoverUserKeyVar="${UpperChannel}_USER_KEY"
|
||||
PushoverTokenVar="${UpperChannel}_TOKEN"
|
||||
|
||||
if [[ -z "${!PushoverUrlVar:-}" ]] || [[ -z "${!PushoverUserKeyVar:-}" ]] || [[ -z "${!PushoverTokenVar:-}" ]]; then
|
||||
printf "The ${pushover_channel} notification channel is enabled, but required configuration variables are missing. Pushover notifications will not be sent.\n"
|
||||
|
||||
remove_channel pushover
|
||||
return 0
|
||||
fi
|
||||
|
||||
PushoverUrl="${!PushoverUrlVar}" # e.g. PUSHOVER_URL=https://api.pushover.net/1/messages.json
|
||||
PushoverUserKey="${!PushoverUserKeyVar}" # e.g. PUSHOVER_USER_KEY=userkey
|
||||
PushoverToken="${!PushoverTokenVar}" # e.g. PUSHOVER_TOKEN=token-value
|
||||
|
||||
# Sending the notification via Pushover
|
||||
curl -S -o /dev/null ${CurlArgs} -X POST \
|
||||
|
|
|
|||
|
|
@ -1,20 +1,32 @@
|
|||
### DISCLAIMER: This is a third party addition to dockcheck - best effort testing.
|
||||
NOTIFY_SLACK_VERSION="v0.3"
|
||||
NOTIFY_SLACK_VERSION="v0.4"
|
||||
#
|
||||
# Setup app and token at https://api.slack.com/tutorials/tracks/posting-messages-with-curl
|
||||
# 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 SLACK_ACCESS_TOKEN, and SLACK_CHANNEL_ID in your dockcheck.config file.
|
||||
|
||||
if [[ -z "${SLACK_ACCESS_TOKEN:-}" ]] || [[ -z "${SLACK_CHANNEL_ID:-}" ]]; then
|
||||
printf "Slack notification channel enabled, but required configuration variables are missing. Slack notifications will not be sent.\n"
|
||||
|
||||
remove_channel slack
|
||||
fi
|
||||
|
||||
trigger_slack_notification() {
|
||||
AccessToken="${SLACK_ACCESS_TOKEN}" # e.g. SLACK_ACCESS_TOKEN=some-token
|
||||
ChannelID="${SLACK_CHANNEL_ID}" # e.g. CHANNEL_ID=mychannel
|
||||
if [[ -n "$1" ]]; then
|
||||
slack_channel="$1"
|
||||
else
|
||||
slack_channel="slack"
|
||||
fi
|
||||
|
||||
UpperChannel="${slack_channel^^}"
|
||||
|
||||
AccessTokenVar="${UpperChannel}_ACCESS_TOKEN"
|
||||
ChannelIDVar="${UpperChannel}_CHANNEL_ID"
|
||||
|
||||
if [[ -z "${!AccessTokenVar:-}" ]] || [[ -z "${!ChannelIDVar:-}" ]]; then
|
||||
printf "The ${slack_channel} notification channel is enabled, but required configuration variables are missing. Slack notifications will not be sent.\n"
|
||||
|
||||
remove_channel slack
|
||||
return 0
|
||||
fi
|
||||
|
||||
AccessToken="${!AccessTokenVar}" # e.g. SLACK_ACCESS_TOKEN=some-token
|
||||
ChannelID="${!ChannelIDVar}" # e.g. CHANNEL_ID=mychannel
|
||||
SlackUrl="https://slack.com/api/chat.postMessage"
|
||||
|
||||
curl -S -o /dev/null ${CurlArgs} \
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
### DISCLAIMER: This is a third party addition to dockcheck - best effort testing.
|
||||
NOTIFY_SMTP_VERSION="v0.4"
|
||||
NOTIFY_SMTP_VERSION="v0.5"
|
||||
# INFO: ssmtp is depcerated - consider to use msmtp instead.
|
||||
#
|
||||
# mSMTP/sSMTP has to be installed and configured manually.
|
||||
|
|
@ -7,12 +7,6 @@ NOTIFY_SMTP_VERSION="v0.4"
|
|||
# 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 SMTP_MAIL_FROM, SMTP_MAIL_TO, and SMTP_SUBJECT_TAG in your dockcheck.config file.
|
||||
|
||||
if [[ -z "${SMTP_MAIL_FROM:-}" ]] || [[ -z "${SMTP_MAIL_TO:-}" ]] || [[ -z "${SMTP_SUBJECT_TAG:-}" ]]; then
|
||||
printf "SMTP notification channel enabled, but required configuration variables are missing. SMTP notifications will not be sent.\n"
|
||||
|
||||
remove_channel smtp
|
||||
fi
|
||||
|
||||
MSMTP=$(which msmtp)
|
||||
SSMTP=$(which ssmtp)
|
||||
SENDMAIL=$(which sendmail)
|
||||
|
|
@ -28,9 +22,28 @@ else
|
|||
fi
|
||||
|
||||
trigger_smtp_notification() {
|
||||
SendMailFrom="${SMTP_MAIL_FROM}" # e.g. MAIL_FROM=me@mydomain.tld
|
||||
SendMailTo="${SMTP_MAIL_TO}" # e.g. MAIL_TO=me@mydomain.tld
|
||||
SubjectTag="${SMTP_SUBJECT_TAG}" # e.g. SUBJECT_TAG=dockcheck
|
||||
if [[ -n "$1" ]]; then
|
||||
smtp_channel="$1"
|
||||
else
|
||||
smtp_channel="smtp"
|
||||
fi
|
||||
|
||||
UpperChannel="${smtp_channel^^}"
|
||||
|
||||
SendMailFromVar="${UpperChannel}_MAIL_FROM"
|
||||
SendMailToVar="${UpperChannel}_MAIL_TO"
|
||||
SubjectTagVar="${UpperChannel}_SUBJECT_TAG"
|
||||
|
||||
if [[ -z "${!SendMailFromVar:-}" ]] || [[ -z "${!SendMailToVar:-}" ]] || [[ -z "${!SubjectTagVar:-}" ]]; then
|
||||
printf "The ${smtp_channel} notification channel is enabled, but required configuration variables are missing. SMTP notifications will not be sent.\n"
|
||||
|
||||
remove_channel smtp
|
||||
return 0
|
||||
fi
|
||||
|
||||
SendMailFrom="${!SendMailFromVar}" # e.g. MAIL_FROM=me@mydomain.tld
|
||||
SendMailTo="${!SendMailToVar}" # e.g. MAIL_TO=me@mydomain.tld
|
||||
SubjectTag="${!SubjectTagVar}" # e.g. SUBJECT_TAG=dockcheck
|
||||
|
||||
$MailPkg $SendMailTo << __EOF
|
||||
From: "$FromHost" <$SendMailFrom>
|
||||
|
|
|
|||
|
|
@ -1,28 +1,41 @@
|
|||
### DISCLAIMER: This is a third party addition to dockcheck - best effort testing.
|
||||
NOTIFY_TELEGRAM_VERSION="v0.4"
|
||||
NOTIFY_TELEGRAM_VERSION="v0.5"
|
||||
#
|
||||
# Required receiving services must already be set up.
|
||||
# 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 TELEGRAM_CHAT_ID and TELEGRAM_TOKEN in your dockcheck.config file.
|
||||
|
||||
if [[ -z "${TELEGRAM_CHAT_ID:-}" ]] || [[ -z "${TELEGRAM_TOKEN:-}" ]]; then
|
||||
printf "Telegram notification channel enabled, but required configuration variables are missing. Telegram notifications will not be sent.\n"
|
||||
|
||||
remove_channel telegram
|
||||
fi
|
||||
|
||||
trigger_telegram_notification() {
|
||||
if [[ -n "$1" ]]; then
|
||||
telegram_channel="$1"
|
||||
else
|
||||
telegram_channel="telegram"
|
||||
fi
|
||||
|
||||
UpperChannel="${telegram_channel^^}"
|
||||
|
||||
TelegramTokenVar="${UpperChannel}_TOKEN"
|
||||
TelegramChatIdVar="${UpperChannel}_CHAT_ID"
|
||||
TelegramTopicIdVar="${UpperChannel}_TOPIC_ID"
|
||||
|
||||
if [[ -z "${!TelegramChatIdVar:-}" ]] || [[ -z "${!TelegramTokenVar:-}" ]]; then
|
||||
printf "The ${telegram_channel} notification channel is enabled, but required configuration variables are missing. Telegram notifications will not be sent.\n"
|
||||
|
||||
remove_channel telegram
|
||||
return 0
|
||||
fi
|
||||
|
||||
if [[ "$PrintMarkdownURL" == true ]]; then
|
||||
ParseMode="Markdown"
|
||||
else
|
||||
ParseMode="HTML"
|
||||
fi
|
||||
|
||||
TelegramToken="${TELEGRAM_TOKEN}" # e.g. TELEGRAM_TOKEN=token-value
|
||||
TelegramChatId="${TELEGRAM_CHAT_ID}" # e.g. TELEGRAM_CHAT_ID=mychatid
|
||||
TelegramToken="${!TelegramTokenVar}" # e.g. TELEGRAM_TOKEN=token-value
|
||||
TelegramChatId="${!TelegramChatIdVar}" # e.g. TELEGRAM_CHAT_ID=mychatid
|
||||
TelegramUrl="https://api.telegram.org/bot$TelegramToken"
|
||||
TelegramTopicID=${TELEGRAM_TOPIC_ID:="0"}
|
||||
TelegramTopicID=${!TelegramTopicIdVar:="0"}
|
||||
|
||||
JsonData=$( "$jqbin" -n \
|
||||
--arg chatid "$TelegramChatId" \
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
NOTIFY_V2_VERSION="v0.5"
|
||||
NOTIFY_V2_VERSION="v0.6"
|
||||
#
|
||||
# If migrating from an older notify template, remove your existing notify.sh file.
|
||||
# Leave (or place) this file in the "notify_templates" subdirectory within the same directory as the main dockcheck.sh script.
|
||||
|
|
@ -13,9 +13,33 @@ NOTIFY_V2_VERSION="v0.5"
|
|||
# Actual snooze will be 60 seconds less to avoid the chance of missed notifications due to minor scheduling or script run time issues.
|
||||
snooze="${SNOOZE_SECONDS:-}"
|
||||
SnoozeFile="${ScriptWorkDir}/snooze.list"
|
||||
[[ ! -f "${SnoozeFile}" ]] && touch "${SnoozeFile}"
|
||||
|
||||
enabled_notify_channels=( ${NOTIFY_CHANNELS:-} )
|
||||
|
||||
# Global output string variable for modification by functions
|
||||
UpdToString=""
|
||||
FormattedOutput=""
|
||||
|
||||
get_channel_template() {
|
||||
local UpperChannel="${1^^}"
|
||||
local TemplateVar="${UpperChannel}_TEMPLATE"
|
||||
if [[ -n "${!TemplateVar:-}" ]]; then
|
||||
printf "${!TemplateVar}"
|
||||
else
|
||||
printf "$1"
|
||||
fi
|
||||
}
|
||||
|
||||
declare -A unique_templates
|
||||
|
||||
for channel in "${enabled_notify_channels[@]}"; do
|
||||
template=$(get_channel_template "${channel}")
|
||||
unique_templates["${template}"]=1
|
||||
done
|
||||
|
||||
enabled_notify_templates=( "${!unique_templates[@]}" )
|
||||
|
||||
FromHost=$(cat /etc/hostname)
|
||||
|
||||
CurrentEpochTime=$(date +"%Y-%m-%dT%H:%M:%S")
|
||||
|
|
@ -23,49 +47,96 @@ CurrentEpochSeconds=$(date +%s)
|
|||
|
||||
NotifyError=false
|
||||
|
||||
for template in "${enabled_notify_templates[@]}"; do
|
||||
source_if_exists_or_fail "${ScriptWorkDir}/notify_${template}.sh" || \
|
||||
source_if_exists_or_fail "${ScriptWorkDir}/notify_templates/notify_${template}.sh" || \
|
||||
printf "The notification channel template ${template} is enabled, but notify_${template}.sh was not found. Check the ${ScriptWorkDir} directory or the notify_templates subdirectory.\n"
|
||||
done
|
||||
|
||||
skip_snooze() {
|
||||
local UpperChannel="${1^^}"
|
||||
local SkipSnoozeVar="${UpperChannel}_SKIPSNOOZE"
|
||||
if [[ "${!SkipSnoozeVar:-}" == "true" ]]; then
|
||||
printf "true"
|
||||
else
|
||||
printf "false"
|
||||
fi
|
||||
}
|
||||
|
||||
allow_empty() {
|
||||
local UpperChannel="${1^^}"
|
||||
local AllowEmptyVar="${UpperChannel}_ALLOWEMPTY"
|
||||
if [[ "${!AllowEmptyVar:-}" == "true" ]]; then
|
||||
printf "true"
|
||||
else
|
||||
printf "false"
|
||||
fi
|
||||
}
|
||||
|
||||
containers_only() {
|
||||
local UpperChannel="${1^^}"
|
||||
local ContainersOnlyVar="${UpperChannel}_CONTAINERSONLY"
|
||||
if [[ "${!ContainersOnlyVar:-}" == "true" ]]; then
|
||||
printf "true"
|
||||
else
|
||||
printf "false"
|
||||
fi
|
||||
}
|
||||
|
||||
output_format() {
|
||||
local UpperChannel="${1^^}"
|
||||
local OutputFormatVar="${UpperChannel}_OUTPUT"
|
||||
if [[ -z "${!OutputFormatVar:-}" ]]; then
|
||||
printf "text"
|
||||
else
|
||||
printf "${!OutputFormatVar:-}"
|
||||
fi
|
||||
}
|
||||
|
||||
remove_channel() {
|
||||
local temp_array=()
|
||||
for channel in "${enabled_notify_channels[@]}"; do
|
||||
[[ "${channel}" != "$1" ]] && temp_array+=("${channel}")
|
||||
local channel_template=$(get_channel_template "${channel}")
|
||||
[[ "${channel_template}" != "$1" ]] && temp_array+=("${channel}")
|
||||
done
|
||||
enabled_notify_channels=( "${temp_array[@]}" )
|
||||
}
|
||||
|
||||
for channel in "${enabled_notify_channels[@]}"; do
|
||||
source_if_exists_or_fail "${ScriptWorkDir}/notify_${channel}.sh" || \
|
||||
source_if_exists_or_fail "${ScriptWorkDir}/notify_templates/notify_${channel}.sh" || \
|
||||
printf "The notification channel ${channel} is enabled, but notify_${channel}.sh was not found. Check the ${ScriptWorkDir} directory or the notify_templates subdirectory.\n"
|
||||
done
|
||||
|
||||
notify_containers_count() {
|
||||
unset NotifyContainers
|
||||
NotifyContainers=()
|
||||
|
||||
[[ ! -f "${SnoozeFile}" ]] && touch "${SnoozeFile}"
|
||||
|
||||
for update in "$@"
|
||||
do
|
||||
read -a container <<< "${update}"
|
||||
found=$(grep -w "${container[0]}" "${SnoozeFile}" || printf "")
|
||||
|
||||
is_snoozed() {
|
||||
if [[ -n "${snooze}" ]] && [[ -f "${SnoozeFile}" ]]; then
|
||||
local found=$(grep -w "$1" "${SnoozeFile}" || printf "")
|
||||
if [[ -n "${found}" ]]; then
|
||||
read -a arr <<< "${found}"
|
||||
CheckEpochSeconds=$(( $(date -d "${arr[1]}" +%s 2>/dev/null) + ${snooze} - 60 )) || CheckEpochSeconds=$(( $(date -f "%Y-%m-%d" -j "${arr[1]}" +%s) + ${snooze} - 60 ))
|
||||
if [[ "${CurrentEpochSeconds}" -gt "${CheckEpochSeconds}" ]]; then
|
||||
NotifyContainers+=("${update}")
|
||||
if [[ "${CurrentEpochSeconds}" -le "${CheckEpochSeconds}" ]]; then
|
||||
printf "true"
|
||||
else
|
||||
printf "false"
|
||||
fi
|
||||
else
|
||||
NotifyContainers+=("${update}")
|
||||
printf "false"
|
||||
fi
|
||||
else
|
||||
printf "false"
|
||||
fi
|
||||
}
|
||||
|
||||
unsnoozed_count() {
|
||||
unset Unsnoozed
|
||||
Unsnoozed=()
|
||||
|
||||
for element in "$@"
|
||||
do
|
||||
read -a item <<< "${element}"
|
||||
if [[ $(is_snoozed "${item[0]}") == "false" ]]; then
|
||||
Unsnoozed+=("${element}")
|
||||
fi
|
||||
done
|
||||
|
||||
printf "${#NotifyContainers[@]}"
|
||||
printf "${#Unsnoozed[@]}"
|
||||
}
|
||||
|
||||
update_snooze() {
|
||||
|
||||
[[ ! -f "${SnoozeFile}" ]] && touch "${SnoozeFile}"
|
||||
|
||||
for arg in "$@"
|
||||
do
|
||||
read -a entry <<< "${arg}"
|
||||
|
|
@ -85,8 +156,6 @@ cleanup_snooze() {
|
|||
NotifyEntries=()
|
||||
switch=""
|
||||
|
||||
[[ ! -f "${SnoozeFile}" ]] && touch "${SnoozeFile}"
|
||||
|
||||
for arg in "$@"
|
||||
do
|
||||
read -a entry <<< "${arg}"
|
||||
|
|
@ -105,41 +174,130 @@ cleanup_snooze() {
|
|||
done <<< "$(grep ${switch} '\.sh ' ${SnoozeFile})"
|
||||
}
|
||||
|
||||
format_output() {
|
||||
local UpdateType="$1"
|
||||
local OutputFormat="$2"
|
||||
local FormattedTextTemplate="$3"
|
||||
local tempcsv=""
|
||||
|
||||
if [[ ! "${UpdateType}" == "dockcheck_update" ]]; then
|
||||
tempcsv="${UpdToString// -> /,}"
|
||||
tempcsv="${tempcsv//.sh /.sh,}"
|
||||
else
|
||||
tempcsv="${UpdToString}"
|
||||
fi
|
||||
|
||||
if [[ "${OutputFormat}" == "csv" ]]; then
|
||||
if [[ -z "${UpdToString}" ]]; then
|
||||
FormattedOutput="None"
|
||||
else
|
||||
FormattedOutput="${tempcsv}"
|
||||
fi
|
||||
elif [[ "${OutputFormat}" == "json" ]]; then
|
||||
if [[ -z "${UpdToString}" ]]; then
|
||||
FormattedOutput='{"updates": []}'
|
||||
else
|
||||
if [[ "${UpdateType}" == "container_update" ]]; then
|
||||
# container updates case
|
||||
FormattedOutput=$(jq --compact-output --null-input --arg updates "${tempcsv}" '($updates | split("\\n")) | map(split(",")) | {"updates": map({"container_name": .[0], "release_notes": .[1]})} | del(..|nulls)')
|
||||
elif [[ "${UpdateType}" == "notify_update" ]]; then
|
||||
# script updates case
|
||||
FormattedOutput=$(jq --compact-output --null-input --arg updates "${tempcsv}" '($updates | split("\\n")) | map(split(",")) | {"updates": map({"script_name": .[0], "installed_version": .[1], "latest_version": .[2]})}')
|
||||
elif [[ "${UpdateType}" == "dockcheck_update" ]]; then
|
||||
# dockcheck update case
|
||||
FormattedOutput=$(jq --compact-output --null-input --arg updates "${tempcsv}" '($updates | split("\\n")) | map(split(",")) | {"updates": map({"script_name": .[0], "installed_version": .[1], "latest_version": .[2], "release_notes": (.[3:] | join(","))})}')
|
||||
else
|
||||
FormattedOutput="Invalid input"
|
||||
fi
|
||||
fi
|
||||
else
|
||||
if [[ -z "${UpdToString}" ]]; then
|
||||
FormattedOutput="None"
|
||||
else
|
||||
if [[ "${UpdateType}" == "container_update" ]]; then
|
||||
FormattedOutput="${FormattedTextTemplate/<insert_text_cu>/${UpdToString}}"
|
||||
elif [[ "${UpdateType}" == "notify_update" ]]; then
|
||||
FormattedOutput="${FormattedTextTemplate/<insert_text_nu>/${UpdToString}}"
|
||||
elif [[ "${UpdateType}" == "dockcheck_update" ]]; then
|
||||
FormattedOutput="${FormattedTextTemplate/<insert_text_iv>/$4}"
|
||||
FormattedOutput="${FormattedOutput/<insert_text_lv>/$5}"
|
||||
FormattedOutput="${FormattedOutput/<insert_text_rn>/$6}"
|
||||
else
|
||||
FormattedOutput="Invalid input"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
skip_notification() {
|
||||
# Skip notification logic. Default to false. Handle all cases, and only those cases, where notifications should be skipped.
|
||||
local SkipNotification="false"
|
||||
local Channel="$1"
|
||||
local UnsnoozedCount="$2"
|
||||
local NotificationType="$3"
|
||||
|
||||
if [[ $(containers_only "${Channel}") == "true" ]] && [[ "${NotificationType}" != "container" ]]; then
|
||||
# Do not send notifications through channels only configured for container update notifications
|
||||
SkipNotification="true"
|
||||
else
|
||||
# Handle empty update cases separately
|
||||
if [[ -z "${UpdToString}" ]]; then
|
||||
if [[ $(allow_empty "${Channel}") == "false" ]]; then
|
||||
# Do not send notifications if there are none and allow_empty is false
|
||||
SkipNotification="true"
|
||||
fi
|
||||
else
|
||||
if [[ $(skip_snooze "${Channel}") == "false" ]] && [[ ${UnsnoozedCount} -eq 0 ]]; then
|
||||
# Do not send notifications if there are any, they are all snoozed, and skip_snooze is false
|
||||
SkipNotification="true"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
printf "${SkipNotification}"
|
||||
}
|
||||
|
||||
send_notification() {
|
||||
[[ -s "$ScriptWorkDir"/urls.list ]] && releasenotes || Updates=("$@")
|
||||
|
||||
if [[ -n "${snooze}" ]] && [[ -f "${SnoozeFile}" ]]; then
|
||||
UpdNotifyCount=$(notify_containers_count "${Updates[@]}")
|
||||
else
|
||||
UpdNotifyCount="${#Updates[@]}"
|
||||
fi
|
||||
|
||||
NotifyError=false
|
||||
|
||||
if [[ "${UpdNotifyCount}" -gt 0 ]]; then
|
||||
UpdToString=$( printf '%s\\n' "${Updates[@]}" )
|
||||
UpdToString=${UpdToString%\\n}
|
||||
|
||||
for channel in "${enabled_notify_channels[@]}"; do
|
||||
printf "\nSending ${channel} notification\n"
|
||||
|
||||
# To be added in the MessageBody if "-d X" was used
|
||||
# leading space is left intentionally for clean output
|
||||
[[ -n "$DaysOld" ]] && msgdaysold="with images ${DaysOld}+ days old " || msgdaysold=""
|
||||
|
||||
MessageTitle="$FromHost - updates ${msgdaysold}available."
|
||||
# Setting the MessageBody variable here.
|
||||
printf -v MessageBody "🐋 Containers on $FromHost with updates available:\n${UpdToString}\n"
|
||||
|
||||
exec_if_exists_or_fail trigger_${channel}_notification || \
|
||||
printf "Attempted to send notification to channel ${channel}, but the function was not found. Make sure notify_${channel}.sh is available in the ${ScriptWorkDir} directory or notify_templates subdirectory.\n"
|
||||
done
|
||||
|
||||
[[ -n "${snooze}" ]] && [[ "${NotifyError}" == "false" ]] && update_snooze "${Updates[@]}"
|
||||
fi
|
||||
|
||||
[[ -n "${snooze}" ]] && cleanup_snooze "${Updates[@]}"
|
||||
|
||||
UnsnoozedContainers=$(unsnoozed_count "${Updates[@]}")
|
||||
NotifyError=false
|
||||
Notified="false"
|
||||
|
||||
# To be added in the MessageBody if "-d X" was used
|
||||
# Trailing space is left intentionally for clean output
|
||||
[[ -n "$DaysOld" ]] && msgdaysold="with images ${DaysOld}+ days old " || msgdaysold=""
|
||||
MessageTitle="$FromHost - updates ${msgdaysold}available."
|
||||
|
||||
UpdToString=$( printf '%s\\n' "${Updates[@]}" )
|
||||
UpdToString="${UpdToString%, }"
|
||||
UpdToString=${UpdToString%\\n}
|
||||
|
||||
for channel in "${enabled_notify_channels[@]}"; do
|
||||
local SkipNotification=$(skip_notification "${channel}" "${UnsnoozedContainers}" "container")
|
||||
if [[ "${SkipNotification}" == "false" ]]; then
|
||||
local template=$(get_channel_template "${channel}")
|
||||
|
||||
# Formats UpdToString variable per channel settings
|
||||
format_output "container_update" "$(output_format "${channel}")" "🐋 Containers on $FromHost with updates available:\n<insert_text_cu>\n"
|
||||
|
||||
# Setting the MessageBody variable here.
|
||||
printf -v MessageBody "${FormattedOutput}"
|
||||
|
||||
printf "\nSending ${channel} notification"
|
||||
exec_if_exists_or_fail trigger_${template}_notification "${channel}" || \
|
||||
printf "\nAttempted to send notification to channel ${channel}, but the function was not found. Make sure notify_${template}.sh is available in the ${ScriptWorkDir} directory or notify_templates subdirectory."
|
||||
Notified="true"
|
||||
fi
|
||||
done
|
||||
|
||||
if [[ "${Notified}" == "true" ]]; then
|
||||
[[ -n "${snooze}" ]] && [[ -n "${UpdToString}" ]] && [[ "${NotifyError}" == "false" ]] && update_snooze "${Updates[@]}"
|
||||
printf "\n"
|
||||
fi
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
|
|
@ -147,37 +305,34 @@ send_notification() {
|
|||
### to not send notifications when dockcheck itself has updates.
|
||||
dockcheck_notification() {
|
||||
if [[ ! "${DISABLE_DOCKCHECK_NOTIFICATION:-}" == "true" ]]; then
|
||||
DockcheckNotify=false
|
||||
UnsnoozedDockcheck=$(unsnoozed_count "dockcheck\.sh")
|
||||
NotifyError=false
|
||||
Notified=false
|
||||
|
||||
if [[ -n "${snooze}" ]] && [[ -f "${SnoozeFile}" ]]; then
|
||||
found=$(grep -w "dockcheck\.sh" "${SnoozeFile}" || printf "")
|
||||
if [[ -n "${found}" ]]; then
|
||||
read -a arr <<< "${found}"
|
||||
CheckEpochSeconds=$(( $(date -d "${arr[1]}" +%s 2>/dev/null) + ${snooze} - 60 )) || CheckEpochSeconds=$(( $(date -f "%Y-%m-%d" -j "${arr[1]}" +%s) + ${snooze} - 60 ))
|
||||
if [[ "${CurrentEpochSeconds}" -gt "${CheckEpochSeconds}" ]]; then
|
||||
DockcheckNotify=true
|
||||
fi
|
||||
else
|
||||
DockcheckNotify=true
|
||||
MessageTitle="$FromHost - New version of dockcheck available."
|
||||
UpdToString="dockcheck.sh,$1,$2,\"$3\""
|
||||
|
||||
for channel in "${enabled_notify_channels[@]}"; do
|
||||
local SkipNotification=$(skip_notification "${channel}" "${UnsnoozedDockcheck}" "dockcheck")
|
||||
if [[ "${SkipNotification}" == "false" ]]; then
|
||||
local template=$(get_channel_template "${channel}")
|
||||
|
||||
# Formats UpdToString variable per channel settings
|
||||
format_output "dockcheck_update" "$(output_format "${channel}")" "Installed version: <insert_text_iv>\nLatest version: <insert_text_lv>\n\nChangenotes: <insert_text_rn>\n" "$1" "$2" "$3"
|
||||
|
||||
# Setting the MessageBody variable here.
|
||||
printf -v MessageBody "${FormattedOutput}"
|
||||
|
||||
printf "\nSending dockcheck update notification - ${channel}"
|
||||
exec_if_exists_or_fail trigger_${template}_notification "${channel}" || \
|
||||
printf "\nAttempted to send notification to channel ${channel}, but the function was not found. Make sure notify_${template}.sh is available in the ${ScriptWorkDir} directory or notify_templates subdirectory."
|
||||
Notified="true"
|
||||
fi
|
||||
else
|
||||
DockcheckNotify=true
|
||||
fi
|
||||
|
||||
if [[ "${DockcheckNotify}" == "true" ]]; then
|
||||
MessageTitle="$FromHost - New version of dockcheck available."
|
||||
# Setting the MessageBody variable here.
|
||||
printf -v MessageBody "Installed version: $1\nLatest version: $2\n\nChangenotes: $3\n"
|
||||
|
||||
if [[ ${#enabled_notify_channels[@]} -gt 0 ]]; then printf "\n"; fi
|
||||
for channel in "${enabled_notify_channels[@]}"; do
|
||||
printf "Sending dockcheck update notification - ${channel}\n"
|
||||
exec_if_exists_or_fail trigger_${channel}_notification || \
|
||||
printf "Attempted to send notification to channel ${channel}, but the function was not found. Make sure notify_${channel}.sh is available in the ${ScriptWorkDir} directory or notify_templates subdirectory.\n"
|
||||
done
|
||||
done
|
||||
|
||||
if [[ "${Notified}" == "true" ]]; then
|
||||
[[ -n "${snooze}" ]] && [[ "${NotifyError}" == "false" ]] && update_snooze "dockcheck.sh"
|
||||
printf "\n"
|
||||
fi
|
||||
fi
|
||||
|
||||
|
|
@ -188,68 +343,63 @@ dockcheck_notification() {
|
|||
### to not send notifications when notify scripts themselves have updates.
|
||||
notify_update_notification() {
|
||||
if [[ ! "${DISABLE_NOTIFY_NOTIFICATION:-}" == "true" ]]; then
|
||||
NotifyUpdateNotify=false
|
||||
NotifyError=false
|
||||
NotifyUpdates=()
|
||||
Notified=false
|
||||
|
||||
UpdateChannels=( "${enabled_notify_channels[@]}" "v2" )
|
||||
UpdateChannels=( "${enabled_notify_templates[@]}" "v2" )
|
||||
|
||||
for NotifyScript in "${UpdateChannels[@]}"; do
|
||||
UpperChannel=$(tr '[:lower:]' '[:upper:]' <<< "$NotifyScript")
|
||||
UpperChannel="${NotifyScript^^}"
|
||||
VersionVar="NOTIFY_${UpperChannel}_VERSION"
|
||||
if [[ -n "${!VersionVar:-}" ]]; then
|
||||
RawNotifyUrl="https://raw.githubusercontent.com/mag37/dockcheck/main/notify_templates/notify_${NotifyScript}.sh"
|
||||
LatestNotifySnippet="$(curl ${CurlArgs} -r 0-150 "$RawNotifyUrl" || printf "undefined")"
|
||||
LatestNotifyRelease="$(echo "$LatestNotifySnippet" | sed -n "/${VersionVar}/s/${VersionVar}=//p" | tr -d '"')"
|
||||
if [[ ! "${LatestNotifyRelease}" == "undefined" ]]; then
|
||||
if [[ ! "${LatestNotifySnippet}" == "undefined" ]]; then
|
||||
LatestNotifyRelease="$(echo "$LatestNotifySnippet" | sed -n "/${VersionVar}/s/${VersionVar}=//p" | tr -d '"')"
|
||||
|
||||
if [[ "${!VersionVar}" != "${LatestNotifyRelease}" ]] ; then
|
||||
NotifyUpdates+=("${NotifyScript}.sh ${!VersionVar} -> ${LatestNotifyRelease}")
|
||||
NotifyUpdates+=("${NotifyScript}.sh ${!VersionVar} -> ${LatestNotifyRelease}")
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
if [[ -n "${snooze}" ]] && [[ -f "${SnoozeFile}" ]]; then
|
||||
for update in "${NotifyUpdates[@]}"; do
|
||||
read -a NotifyScript <<< "${update}"
|
||||
found=$(grep -w "${NotifyScript}" "${SnoozeFile}" || printf "")
|
||||
if [[ -n "${found}" ]]; then
|
||||
read -a arr <<< "${found}"
|
||||
CheckEpochSeconds=$(( $(date -d "${arr[1]}" +%s 2>/dev/null) + ${snooze} - 60 )) || CheckEpochSeconds=$(( $(date -f "%Y-%m-%d" -j "${arr[1]}" +%s) + ${snooze} - 60 ))
|
||||
if [[ "${CurrentEpochSeconds}" -gt "${CheckEpochSeconds}" ]]; then
|
||||
NotifyUpdateNotify=true
|
||||
fi
|
||||
else
|
||||
NotifyUpdateNotify=true
|
||||
fi
|
||||
done
|
||||
else
|
||||
NotifyUpdateNotify=true
|
||||
fi
|
||||
|
||||
if [[ "${NotifyUpdateNotify}" == "true" ]]; then
|
||||
if [[ "${#NotifyUpdates[@]}" -gt 0 ]]; then
|
||||
UpdToString=$( printf '%s\\n' "${NotifyUpdates[@]}" )
|
||||
UpdToString=${UpdToString%\\n}
|
||||
NotifyError=false
|
||||
|
||||
MessageTitle="$FromHost - New version of notify templates available."
|
||||
|
||||
printf -v MessageBody "Notify templates on $FromHost with updates available:\n${UpdToString}\n"
|
||||
|
||||
for channel in "${enabled_notify_channels[@]}"; do
|
||||
printf "Sending notify template update notification - ${channel}\n"
|
||||
exec_if_exists_or_fail trigger_${channel}_notification || \
|
||||
printf "Attempted to send notification to channel ${channel}, but the function was not found. Make sure notify_${channel}.sh is available in the ${ScriptWorkDir} directory or notify_templates subdirectory.\n"
|
||||
done
|
||||
|
||||
[[ -n "${snooze}" ]] && [[ "${NotifyError}" == "false" ]] && update_snooze "${NotifyUpdates[@]}"
|
||||
fi
|
||||
fi
|
||||
|
||||
UpdatesPlusDockcheck=("${NotifyUpdates[@]}")
|
||||
UpdatesPlusDockcheck+=("dockcheck.sh")
|
||||
[[ -n "${snooze}" ]] && cleanup_snooze "${UpdatesPlusDockcheck[@]}"
|
||||
|
||||
UnsnoozedTemplates=$(unsnoozed_count "${NotifyUpdates[@]}")
|
||||
|
||||
MessageTitle="$FromHost - New version of notify templates available."
|
||||
|
||||
UpdToString=$( printf '%s\\n' "${NotifyUpdates[@]}" )
|
||||
UpdToString="${UpdToString%, }"
|
||||
UpdToString=${UpdToString%\\n}
|
||||
|
||||
for channel in "${enabled_notify_channels[@]}"; do
|
||||
local SkipNotification=$(skip_notification "${channel}" "${UnsnoozedTemplates}" "notify")
|
||||
|
||||
if [[ "${SkipNotification}" == "false" ]]; then
|
||||
local template=$(get_channel_template "${channel}")
|
||||
|
||||
# Formats UpdToString variable per channel settings
|
||||
format_output "notify_update" "$(output_format "${channel}")" "Notify templates on $FromHost with updates available:\n<insert_text_nu>\n"
|
||||
|
||||
# Setting the MessageBody variable here.
|
||||
printf -v MessageBody "${FormattedOutput}"
|
||||
|
||||
printf "\nSending notify template update notification - ${channel}"
|
||||
exec_if_exists_or_fail trigger_${template}_notification "${channel}" || \
|
||||
printf "\nAttempted to send notification to channel ${channel}, but the function was not found. Make sure notify_${template}.sh is available in the ${ScriptWorkDir} directory or notify_templates subdirectory."
|
||||
Notified="true"
|
||||
fi
|
||||
done
|
||||
|
||||
if [[ "${Notified}" == "true" ]]; then
|
||||
[[ -n "${snooze}" ]] && [[ -n "${UpdToString}" ]] && [[ "${NotifyError}" == "false" ]] && update_snooze "${NotifyUpdates[@]}"
|
||||
printf "\n"
|
||||
fi
|
||||
fi
|
||||
|
||||
return 0
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue