mirror of
https://github.com/mag37/dockcheck.git
synced 2026-02-22 19:24:16 +01:00
Notify_v2.sh bug fixes (#188)
* Notify_v2.sh bug fixes * Clarify notify_v2.sh usage in README.md * Fix JSON newline handling in Discord and Telegram channels * Additional error messages when notification templates fail to be sourced * Additional variable for self-hosted ntfy.sh domain * Notify_v2.sh additional fixes * Clarify usage in README.md and notify template comments * Support sourcing template files from project root * Add days old message to notification title * Handle JSON with jq in Discord and Telegram templates * Tweak notify_v2.sh usage docs and comments * Remove extra newline from notification body * replaced jq with jqbin, reodered setting of jqbin, changed source for hostname var * moved the setting of jqbin a bit further up after further testing --------- Co-authored-by: Matthew Oleksowicz <matt@everyoneneeds.it> Co-authored-by: mag37 <robin.ivehult@gmail.com>
This commit is contained in:
parent
22871442db
commit
57650f1673
16 changed files with 109 additions and 38 deletions
|
|
@ -4,7 +4,9 @@ NOTIFY_DSM_VERSION="v0.2"
|
|||
#
|
||||
# mSMTP/sSMTP has to be installed and configured manually.
|
||||
# The existing DSM Notification Email configuration will be used automatically.
|
||||
# Do not modify this file directly. Set DSM_SENDMAILTO and DSM_SUBJECTTAG in your dockcheck.config file.
|
||||
# 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 DSM_SENDMAILTO and DSM_SUBJECTTAG in your dockcheck.config file.
|
||||
|
||||
MSMTP=$(which msmtp)
|
||||
SSMTP=$(which ssmtp)
|
||||
|
|
|
|||
|
|
@ -2,7 +2,9 @@
|
|||
NOTIFY_APPRISE_VERSION="v0.2"
|
||||
#
|
||||
# Required receiving services must already be set up.
|
||||
# Do not modify this file directly. Set APPRISE_PAYLOAD in your dockcheck.config file.
|
||||
# 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 APPRISE_PAYLOAD in your dockcheck.config file.
|
||||
# If API, set APPRISE_URL instead.
|
||||
|
||||
if [[ -z "${APPRISE_PAYLOAD:-}" ]] && [[ -z "${APPRISE_URL:-}" ]]; then
|
||||
|
|
|
|||
|
|
@ -1,8 +1,10 @@
|
|||
### DISCLAIMER: This is a third party addition to dockcheck - best effort testing.
|
||||
NOTIFY_DISCORD_VERSION="v0.2"
|
||||
NOTIFY_DISCORD_VERSION="v0.3"
|
||||
#
|
||||
# Required receiving services must already be set up.
|
||||
# Do not modify this file directly. Set DISCORD_WEBHOOK_URL in your dockcheck.config file.
|
||||
# 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"
|
||||
|
|
@ -13,6 +15,10 @@ fi
|
|||
trigger_discord_notification() {
|
||||
DiscordWebhookUrl="${DISCORD_WEBHOOK_URL}" # e.g. DISCORD_WEBHOOK_URL=https://discord.com/api/webhooks/<token string>
|
||||
|
||||
MsgBody="{\"username\":\"$FromHost\",\"content\":\"$MessageBody\"}"
|
||||
curl -sS -o /dev/null --fail -X POST -H "Content-Type: application/json" -d "$MsgBody" "$DiscordWebhookUrl"
|
||||
JsonData=$( "$jqbin" -n \
|
||||
--arg username "$FromHost" \
|
||||
--arg body "$MessageBody" \
|
||||
'{"username": $username, "content": $body}' )
|
||||
|
||||
curl -sS -o /dev/null --fail -X POST -H "Content-Type: application/json" -d "$JsonData" "$DiscordWebhookUrl"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,9 @@
|
|||
NOTIFY_GOTIFY_VERSION="v0.3"
|
||||
#
|
||||
# Required receiving services must already be set up.
|
||||
# Do not modify this file directly. Set GOTIFY_TOKEN and GOTIFY_DOMAIN in your dockcheck.config file.
|
||||
# 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"
|
||||
|
|
@ -20,7 +22,7 @@ trigger_gotify_notification() {
|
|||
ContentType="text/plain"
|
||||
fi
|
||||
|
||||
JsonData=$( jq -n \
|
||||
JsonData=$( "$jqbin" -n \
|
||||
--arg body "$MessageBody" \
|
||||
--arg title "$MessageTitle" \
|
||||
--arg type "$ContentType" \
|
||||
|
|
|
|||
|
|
@ -2,7 +2,9 @@
|
|||
NOTIFY_MATRIX_VERSION="v0.2"
|
||||
#
|
||||
# Required receiving services must already be set up.
|
||||
# Do not modify this file directly. Set MATRIX_ACCESS_TOKEN, MATRIX_ROOM_ID, and MATRIX_SERVER_URL in your dockcheck.config file.
|
||||
# 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"
|
||||
|
|
|
|||
|
|
@ -1,17 +1,22 @@
|
|||
### DISCLAIMER: This is a third party addition to dockcheck - best effort testing.
|
||||
NOTIFY_NTFYSH_VERSION="v0.3"
|
||||
NOTIFY_NTFYSH_VERSION="v0.4"
|
||||
#
|
||||
# Setup app and subscription at https://ntfy.sh
|
||||
# Do not modify this file directly. Set NTFY_TOPIC_NAME in your dockcheck.config file.
|
||||
# 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_TOPIC_NAME:-}" ]]; then
|
||||
if [[ -z "${NTFY_DOMAIN:-}" ]] || [[ -z "${NTFY_TOPIC_NAME:-}" ]]; then
|
||||
printf "Ntfy.sh notification channel enabled, but required configuration variables are missing. Ntfy.sh notifications will not be sent.\n"
|
||||
|
||||
remove_channel ntfy-sh
|
||||
fi
|
||||
|
||||
trigger_ntfy-sh_notification() {
|
||||
NtfyUrl="ntfy.sh/${NTFY_TOPIC_NAME}" # e.g. NTFY_TOPIC_NAME=YourUniqueTopicName
|
||||
NtfyUrl="${NTFY_DOMAIN}/${NTFY_TOPIC_NAME}"
|
||||
# e.g.
|
||||
# NTFY_DOMAIN=ntfy.sh
|
||||
# NTFY_TOPIC_NAME=YourUniqueTopicName
|
||||
|
||||
if [[ "$PrintMarkdownURL" == true ]]; then
|
||||
ContentType="Markdown: yes"
|
||||
|
|
|
|||
|
|
@ -3,7 +3,9 @@ NOTIFY_PUSHBULLET_VERSION="v0.2"
|
|||
#
|
||||
# Required receiving services must already be set up.
|
||||
# Requires jq installed and in PATH.
|
||||
# Do not modify this file directly. Set PUSHBULLET_TOKEN and PUSHBULLET_URL in your dockcheck.config file.
|
||||
# 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 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"
|
||||
|
|
@ -16,5 +18,5 @@ trigger_pushbullet_notification() {
|
|||
PushToken="${PUSHBULLET_TOKEN}" # e.g. PUSHBULLET_TOKEN=token-value
|
||||
|
||||
# Requires jq to process json data
|
||||
jq -n --arg title "$MessageTitle" --arg body "$MessageBody" '{body: $body, title: $title, type: "note"}' | curl -sS -o /dev/null --show-error --fail -X POST -H "Access-Token: $PushToken" -H "Content-type: application/json" $PushUrl -d @-
|
||||
}
|
||||
"$jqbin" -n --arg title "$MessageTitle" --arg body "$MessageBody" '{body: $body, title: $title, type: "note"}' | curl -sS -o /dev/null --show-error --fail -X POST -H "Access-Token: $PushToken" -H "Content-type: application/json" $PushUrl -d @-
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,9 @@ NOTIFY_PUSHOVER_VERSION="v0.2"
|
|||
#
|
||||
# Required receiving services must already be set up.
|
||||
# Requires jq installed and in PATH.
|
||||
# Do not modify this file directly. Set PUSHOVER_USER_KEY, PUSHOVER_TOKEN, and PUSHOVER_URL in your dockcheck.config file.
|
||||
# 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 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"
|
||||
|
|
|
|||
|
|
@ -2,7 +2,9 @@
|
|||
NOTIFY_SLACK_VERSION="v0.2"
|
||||
#
|
||||
# Setup app and token at https://api.slack.com/tutorials/tracks/posting-messages-with-curl
|
||||
# Do not modify this file directly. Set SLACK_ACCESS_TOKEN, and SLACK_CHANNEL_ID in your dockcheck.config file.
|
||||
# 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"
|
||||
|
|
|
|||
|
|
@ -3,7 +3,9 @@ NOTIFY_SMTP_VERSION="v0.2"
|
|||
# INFO: ssmtp is depcerated - consider to use msmtp instead.
|
||||
#
|
||||
# mSMTP/sSMTP has to be installed and configured manually.
|
||||
# Do not modify this file directly. Set SMTP_MAIL_FROM, SMTP_MAIL_TO, and SMTP_SUBJECT_TAG in your dockcheck.config file.
|
||||
# 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 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"
|
||||
|
|
|
|||
|
|
@ -1,8 +1,10 @@
|
|||
### DISCLAIMER: This is a third party addition to dockcheck - best effort testing.
|
||||
NOTIFY_TELEGRAM_VERSION="v0.2"
|
||||
NOTIFY_TELEGRAM_VERSION="v0.3"
|
||||
#
|
||||
# Required receiving services must already be set up.
|
||||
# Do not modify this file directly. Set TELEGRAM_CHAT_ID and TELEGRAM_TOKEN in your dockcheck.config file.
|
||||
# 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"
|
||||
|
|
@ -21,7 +23,13 @@ trigger_telegram_notification() {
|
|||
TelegramChatId="${TELEGRAM_CHAT_ID}" # e.g. TELEGRAM_CHAT_ID=mychatid
|
||||
TelegramUrl="https://api.telegram.org/bot$TelegramToken"
|
||||
TelegramTopicID=${TELEGRAM_TOPIC_ID:="0"}
|
||||
TelegramData="{\"chat_id\":\"$TelegramChatId\",\"text\":\"$MessageBody\",\"message_thread_id\":\"$TelegramTopicID\",\"disable_notification\": false}"
|
||||
|
||||
curl -sS -o /dev/null --fail -X POST "$TelegramUrl/sendMessage" -H 'Content-Type: application/json' -d "$TelegramData"
|
||||
JsonData=$( "$jqbin" -n \
|
||||
--arg chatid "$TelegramChatId" \
|
||||
--arg text "$MessageBody" \
|
||||
--arg thread "$TelegramTopicID" \
|
||||
--arg parse_mode "$ParseMode" \
|
||||
'{"chat_id": $chatid, "text": $text, "message_thread_id": $thread, "disable_notification": false, "parse_mode": $parse_mode, "disable_web_page_preview": true}' )
|
||||
|
||||
curl -sS -o /dev/null --fail -X POST "$TelegramUrl/sendMessage" -H 'Content-Type: application/json' -d "$JsonData"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
NOTIFY_V2_VERSION="v0.1"
|
||||
NOTIFY_V2_VERSION="v0.2"
|
||||
#
|
||||
# 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.
|
||||
# If you instead wish make your own modifications, make a copy in the same directory as the main dockcheck.sh script.
|
||||
# Enable and configure all required notification variables in your dockcheck.config file, e.g.:
|
||||
# NOTIFY_CHANNELS=apprise gotify slack
|
||||
# SLACK_TOKEN=xoxb-some-token-value
|
||||
|
|
@ -8,7 +10,7 @@ NOTIFY_V2_VERSION="v0.1"
|
|||
|
||||
enabled_notify_channels=( ${NOTIFY_CHANNELS:-} )
|
||||
|
||||
FromHost=$(hostname)
|
||||
FromHost=$(cat /etc/hostname)
|
||||
|
||||
remove_channel() {
|
||||
local temp_array=()
|
||||
|
|
@ -19,21 +21,29 @@ remove_channel() {
|
|||
}
|
||||
|
||||
for channel in "${enabled_notify_channels[@]}"; do
|
||||
source_if_exists "${ScriptWorkDir}/notify_templates/notify_${channel}.sh"
|
||||
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
|
||||
|
||||
send_notification() {
|
||||
[[ -s "$ScriptWorkDir"/urls.list ]] && releasenotes || Updates=("$@")
|
||||
UpdToString=$( printf '%s\\n' "${Updates[@]}" )
|
||||
UpdToString=${UpdToString%\\n}
|
||||
|
||||
for channel in "${enabled_notify_channels[@]}"; do
|
||||
printf "\nSending ${channel} notification\n"
|
||||
|
||||
MessageTitle="$FromHost - updates available."
|
||||
# Setting the MessageBody variable here.
|
||||
printf -v MessageBody "🐋 Containers on $FromHost with updates available:\n$UpdToString\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=""
|
||||
|
||||
exec_if_exists trigger_${channel}_notification "$@"
|
||||
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
|
||||
}
|
||||
|
||||
|
|
@ -48,7 +58,8 @@ dockcheck_notification() {
|
|||
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 trigger_${channel}_notification
|
||||
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
|
||||
fi
|
||||
}
|
||||
|
|
@ -62,7 +73,7 @@ notify_update_notification() {
|
|||
for notify_script in "${update_channels[@]}"; do
|
||||
upper_channel=$(tr '[:lower:]' '[:upper:]' <<< "$notify_script")
|
||||
VersionVar="NOTIFY_${upper_channel}_VERSION"
|
||||
if [[ -n "${!VersionVar}" ]]; then
|
||||
if [[ -n "${!VersionVar:-}" ]]; then
|
||||
RawNotifyUrl="https://raw.githubusercontent.com/mag37/dockcheck/main/notify_templates/notify_${notify_script}.sh"
|
||||
LatestNotifyRelease="$(curl -s -r 0-150 $RawNotifyUrl | sed -n "/NOTIFY_${upper_channel}_VERSION/s/NOTIFY_${upper_channel}_VERSION=//p" | tr -d '"')"
|
||||
LatestNotifyRelease=${LatestNotifyRelease:-undefined}
|
||||
|
|
@ -74,7 +85,8 @@ notify_update_notification() {
|
|||
|
||||
for channel in "${enabled_notify_channels[@]}"; do
|
||||
printf "Sending notify_${notify_script}.sh update notification - ${channel}\n"
|
||||
exec_if_exists trigger_${channel}_notification
|
||||
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
|
||||
fi
|
||||
fi
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue