mirror of
https://github.com/mag37/dockcheck.git
synced 2026-02-14 23:38:15 +01:00
Snooze feature, curl, and consolidation (#200)
* Snooze feature, curl, and consolidation * Added snooze feature to delay notifications * Added configurable default curl arguments * Consolidated and standardized notify template update notifications * Added curl error handling * Snooze comment fix * Grep, curl args, and variable init adjustments * Modified grep commands to make use of word boundaries in order to avoid matching on substrings * Set CurlRetryDelay, CurlRetryCount, and CurlConnectTimeout as individual variables * Used :- for variable initialization where assignment is redundant * Update dockcheck.sh change notes and fix variable collision * Remove unnecessary cat and clarify readme * reformatting --------- Co-authored-by: Matthew Oleksowicz <matt@everyoneneeds.it> Co-authored-by: mag37 <robin.ivehult@gmail.com>
This commit is contained in:
parent
272615166e
commit
a0e11de383
16 changed files with 350 additions and 118 deletions
|
|
@ -1,5 +1,5 @@
|
|||
### DISCLAIMER: This is a third party addition to dockcheck - best effort testing.
|
||||
NOTIFY_DSM_VERSION="v0.2"
|
||||
NOTIFY_DSM_VERSION="v0.3"
|
||||
# INFO: ssmtp is deprecated - consider to use msmtp instead.
|
||||
#
|
||||
# mSMTP/sSMTP has to be installed and configured manually.
|
||||
|
|
@ -45,6 +45,11 @@ Content-Transfer-Encoding: 7bit
|
|||
$MessageBody
|
||||
From $SenderName
|
||||
__EOF
|
||||
|
||||
if [[ $? -gt 0 ]]; then
|
||||
NotifyError=true
|
||||
fi
|
||||
|
||||
# This ensures DSM's container manager will also see the update
|
||||
/var/packages/ContainerManager/target/tool/image_upgradable_checker
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
### DISCLAIMER: This is a third party addition to dockcheck - best effort testing.
|
||||
NOTIFY_APPRISE_VERSION="v0.2"
|
||||
NOTIFY_APPRISE_VERSION="v0.3"
|
||||
#
|
||||
# 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.
|
||||
|
|
@ -18,6 +18,10 @@ trigger_apprise_notification() {
|
|||
if [[ -n "${APPRISE_PAYLOAD:-}" ]]; then
|
||||
apprise -vv -t "$MessageTitle" -b "$MessageBody" \
|
||||
${APPRISE_PAYLOAD}
|
||||
|
||||
if [[ $? -gt 0 ]]; then
|
||||
NotifyError=true
|
||||
fi
|
||||
fi
|
||||
|
||||
# e.g. APPRISE_PAYLOAD='mailto://myemail:mypass@gmail.com
|
||||
|
|
@ -27,6 +31,10 @@ trigger_apprise_notification() {
|
|||
|
||||
if [[ -n "${APPRISE_URL:-}" ]]; then
|
||||
AppriseURL="${APPRISE_URL}"
|
||||
curl -X POST -F "title=$MessageTitle" -F "body=$MessageBody" -F "tags=all" $AppriseURL # e.g. APPRISE_URL=http://apprise.mydomain.tld:1234/notify/apprise
|
||||
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
|
||||
NotifyError=true
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
### DISCLAIMER: This is a third party addition to dockcheck - best effort testing.
|
||||
NOTIFY_DISCORD_VERSION="v0.3"
|
||||
NOTIFY_DISCORD_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.
|
||||
|
|
@ -20,5 +20,9 @@ trigger_discord_notification() {
|
|||
--arg body "$MessageBody" \
|
||||
'{"username": $username, "content": $body}' )
|
||||
|
||||
curl -sS -o /dev/null --fail -X POST -H "Content-Type: application/json" -d "$JsonData" "$DiscordWebhookUrl"
|
||||
curl -S -o /dev/null ${CurlArgs} -X POST -H "Content-Type: application/json" -d "$JsonData" "$DiscordWebhookUrl"
|
||||
|
||||
if [[ $? -gt 0 ]]; then
|
||||
NotifyError=true
|
||||
fi
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
### DISCLAIMER: This is a third party addition to dockcheck - best effort testing.
|
||||
NOTIFY_GOTIFY_VERSION="v0.3"
|
||||
NOTIFY_GOTIFY_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.
|
||||
|
|
@ -28,5 +28,9 @@ trigger_gotify_notification() {
|
|||
--arg type "$ContentType" \
|
||||
'{message: $body, title: $title, priority: 5, extras: {"client::display": {"contentType": $type}}}' )
|
||||
|
||||
curl -s -S --data "${JsonData}" -H 'Content-Type: application/json' -X POST "${GotifyUrl}" 1> /dev/null
|
||||
curl -S -o /dev/null ${CurlArgs} --data "${JsonData}" -H 'Content-Type: application/json' -X POST "${GotifyUrl}" 1> /dev/null
|
||||
|
||||
if [[ $? -gt 0 ]]; then
|
||||
NotifyError=true
|
||||
fi
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
### DISCLAIMER: This is a third party addition to dockcheck - best effort testing.
|
||||
NOTIFY_MATRIX_VERSION="v0.2"
|
||||
NOTIFY_MATRIX_VERSION="v0.3"
|
||||
#
|
||||
# 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.
|
||||
|
|
@ -19,5 +19,9 @@ trigger_matrix_notification() {
|
|||
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 -sS -o /dev/null --fail -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/$Room_id/send/m.room.message?access_token=$AccessToken" -H 'Content-Type: application/json' -d "$MsgBody"
|
||||
|
||||
if [[ $? -gt 0 ]]; then
|
||||
NotifyError=true
|
||||
fi
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
### DISCLAIMER: This is a third party addition to dockcheck - best effort testing.
|
||||
NOTIFY_NTFY_VERSION="v0.4"
|
||||
NOTIFY_NTFYSH_VERSION="v0.5"
|
||||
#
|
||||
# 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.
|
||||
|
|
@ -24,9 +24,13 @@ trigger_ntfy_notification() {
|
|||
ContentType="Markdown: no" #text/plain
|
||||
fi
|
||||
|
||||
curl -sS -o /dev/null --show-error --fail \
|
||||
curl -S -o /dev/null ${CurlArgs} \
|
||||
-H "Title: $MessageTitle" \
|
||||
-H "$ContentType" \
|
||||
-d "$MessageBody" \
|
||||
"$NtfyUrl"
|
||||
|
||||
if [[ $? -gt 0 ]]; then
|
||||
NotifyError=true
|
||||
fi
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
### DISCLAIMER: This is a third party addition to dockcheck - best effort testing.
|
||||
NOTIFY_PUSHBULLET_VERSION="v0.2"
|
||||
NOTIFY_PUSHBULLET_VERSION="v0.3"
|
||||
#
|
||||
# Required receiving services must already be set up.
|
||||
# Requires jq installed and in PATH.
|
||||
|
|
@ -18,5 +18,9 @@ trigger_pushbullet_notification() {
|
|||
PushToken="${PUSHBULLET_TOKEN}" # 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 -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 -S -o /dev/null ${CurlArgs} -X POST -H "Access-Token: $PushToken" -H "Content-type: application/json" $PushUrl -d @-
|
||||
|
||||
if [[ $? -gt 0 ]]; then
|
||||
NotifyError=true
|
||||
fi
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
### DISCLAIMER: This is a third party addition to dockcheck - best effort testing.
|
||||
NOTIFY_PUSHOVER_VERSION="v0.2"
|
||||
NOTIFY_PUSHOVER_VERSION="v0.3"
|
||||
#
|
||||
# Required receiving services must already be set up.
|
||||
# Requires jq installed and in PATH.
|
||||
|
|
@ -19,10 +19,14 @@ trigger_pushover_notification() {
|
|||
PushoverToken="${PUSHOVER_TOKEN}" # e.g. PUSHOVER_TOKEN=token-value
|
||||
|
||||
# Sending the notification via Pushover
|
||||
curl -sS -o /dev/null --show-error --fail -X POST \
|
||||
curl -S -o /dev/null ${CurlArgs} -X POST \
|
||||
-F "token=$PushoverToken" \
|
||||
-F "user=$PushoverUserKey" \
|
||||
-F "title=$MessageTitle" \
|
||||
-F "message=$MessageBody" \
|
||||
$PushoverUrl
|
||||
|
||||
if [[ $? -gt 0 ]]; then
|
||||
NotifyError=true
|
||||
fi
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
### DISCLAIMER: This is a third party addition to dockcheck - best effort testing.
|
||||
NOTIFY_SLACK_VERSION="v0.2"
|
||||
NOTIFY_SLACK_VERSION="v0.3"
|
||||
#
|
||||
# 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.
|
||||
|
|
@ -17,8 +17,12 @@ trigger_slack_notification() {
|
|||
ChannelID="${SLACK_CHANNEL_ID}" # e.g. CHANNEL_ID=mychannel
|
||||
SlackUrl="https://slack.com/api/chat.postMessage"
|
||||
|
||||
curl -sS -o /dev/null --show-error --fail \
|
||||
curl -S -o /dev/null ${CurlArgs} \
|
||||
-d "text=$MessageBody" -d "channel=$ChannelID" \
|
||||
-H "Authorization: Bearer $AccessToken" \
|
||||
-X POST $SlackUrl
|
||||
|
||||
if [[ $? -gt 0 ]]; then
|
||||
NotifyError=true
|
||||
fi
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
### DISCLAIMER: This is a third party addition to dockcheck - best effort testing.
|
||||
NOTIFY_SMTP_VERSION="v0.2"
|
||||
NOTIFY_SMTP_VERSION="v0.3"
|
||||
# INFO: ssmtp is depcerated - consider to use msmtp instead.
|
||||
#
|
||||
# mSMTP/sSMTP has to be installed and configured manually.
|
||||
|
|
@ -40,4 +40,8 @@ Content-Transfer-Encoding: 7bit
|
|||
$MessageBody
|
||||
|
||||
__EOF
|
||||
|
||||
if [[ $? -gt 0 ]]; then
|
||||
NotifyError=true
|
||||
fi
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
### DISCLAIMER: This is a third party addition to dockcheck - best effort testing.
|
||||
NOTIFY_TELEGRAM_VERSION="v0.3"
|
||||
NOTIFY_TELEGRAM_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.
|
||||
|
|
@ -31,5 +31,9 @@ trigger_telegram_notification() {
|
|||
--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"
|
||||
curl -S -o /dev/null ${CurlArgs} -X POST "$TelegramUrl/sendMessage" -H 'Content-Type: application/json' -d "$JsonData"
|
||||
|
||||
if [[ $? -gt 0 ]]; then
|
||||
NotifyError=true
|
||||
fi
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,17 +1,28 @@
|
|||
NOTIFY_V2_VERSION="v0.2"
|
||||
NOTIFY_V2_VERSION="v0.3"
|
||||
#
|
||||
# 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.
|
||||
# If you instead wish make your own modifications, make a copy in the same directory as the main dockcheck.sh script and rename to notify.sh.
|
||||
# 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
|
||||
# GOTIFY_TOKEN=some.token
|
||||
|
||||
# Number of seconds to snooze identical update notifications based on local image name
|
||||
# or dockcheck.sh/notify.sh template file updates.
|
||||
# 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"
|
||||
|
||||
enabled_notify_channels=( ${NOTIFY_CHANNELS:-} )
|
||||
|
||||
FromHost=$(cat /etc/hostname)
|
||||
|
||||
CurrentEpochTime=$(date +"%Y-%m-%dT%H:%M:%S")
|
||||
CurrentEpochSeconds=$(date +%s)
|
||||
|
||||
NotifyError=false
|
||||
|
||||
remove_channel() {
|
||||
local temp_array=()
|
||||
for channel in "${enabled_notify_channels[@]}"; do
|
||||
|
|
@ -26,71 +37,222 @@ for channel in "${enabled_notify_channels[@]}"; do
|
|||
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 "")
|
||||
|
||||
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}")
|
||||
fi
|
||||
else
|
||||
NotifyContainers+=("${update}")
|
||||
fi
|
||||
done
|
||||
|
||||
printf "${#NotifyContainers[@]}"
|
||||
}
|
||||
|
||||
update_snooze() {
|
||||
|
||||
[[ ! -f "${SnoozeFile}" ]] && touch "${SnoozeFile}"
|
||||
|
||||
for arg in "$@"
|
||||
do
|
||||
read -a entry <<< "${arg}"
|
||||
found=$(grep -w "${entry[0]}" "${SnoozeFile}" || printf "")
|
||||
|
||||
if [[ -n "${found}" ]]; then
|
||||
sed -e "s/${entry[0]}.*/${entry[0]} ${CurrentEpochTime}/" "${SnoozeFile}" > "${SnoozeFile}.new"
|
||||
mv "${SnoozeFile}.new" "${SnoozeFile}"
|
||||
else
|
||||
printf "${entry[0]} ${CurrentEpochTime}\n" >> "${SnoozeFile}"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
cleanup_snooze() {
|
||||
unset NotifyEntries
|
||||
NotifyEntries=()
|
||||
switch=""
|
||||
|
||||
[[ ! -f "${SnoozeFile}" ]] && touch "${SnoozeFile}"
|
||||
|
||||
for arg in "$@"
|
||||
do
|
||||
read -a entry <<< "${arg}"
|
||||
NotifyEntries+=("${entry[0]}")
|
||||
done
|
||||
|
||||
if [[ ! "${NotifyEntries[@]}" == *".sh"* ]]; then
|
||||
switch="-v"
|
||||
fi
|
||||
|
||||
while read -r entry datestamp; do
|
||||
if [[ ! "${NotifyEntries[@]}" == *"$entry"* ]]; then
|
||||
sed -e "/${entry}/d" "${SnoozeFile}" > "${SnoozeFile}.new"
|
||||
mv "${SnoozeFile}.new" "${SnoozeFile}"
|
||||
fi
|
||||
done <<< "$(grep ${switch} '\.sh ' ${SnoozeFile})"
|
||||
}
|
||||
|
||||
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"
|
||||
if [[ -n "${snooze}" ]] && [[ -f "${SnoozeFile}" ]]; then
|
||||
UpdNotifyCount=$(notify_containers_count "${Updates[@]}")
|
||||
else
|
||||
UpdNotifyCount="${#Updates[@]}"
|
||||
fi
|
||||
|
||||
# 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=""
|
||||
NotifyError=false
|
||||
|
||||
MessageTitle="$FromHost - updates ${msgdaysold}available."
|
||||
# Setting the MessageBody variable here.
|
||||
printf -v MessageBody "🐋 Containers on $FromHost with updates available:\n${UpdToString}\n"
|
||||
if [[ "${UpdNotifyCount}" -gt 0 ]]; then
|
||||
UpdToString=$( printf '%s\\n' "${Updates[@]}" )
|
||||
UpdToString=${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
|
||||
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[@]}"
|
||||
}
|
||||
|
||||
### Set DISABLE_DOCKCHECK_NOTIFICATION=false in dockcheck.config
|
||||
### to not send notifications when dockcheck itself has updates.
|
||||
dockcheck_notification() {
|
||||
if [[ ! "${DISABLE_DOCKCHECK_NOTIFICATION:-}" = "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 [[ ! "${DISABLE_DOCKCHECK_NOTIFICATION:-}" == "true" ]]; then
|
||||
DockcheckNotify=false
|
||||
NotifyError=false
|
||||
|
||||
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
|
||||
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
|
||||
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
|
||||
|
||||
if [[ -n "${snooze}" ]] && [[ -f "${SnoozeFile}" ]]; then
|
||||
if [[ "${NotifyError}" == "false" ]]; then
|
||||
if [[ -n "${found}" ]]; then
|
||||
sed -e "s/dockcheck\.sh.*/dockcheck\.sh ${CurrentEpochTime}/" "${SnoozeFile}" > "${SnoozeFile}.new"
|
||||
mv "${SnoozeFile}.new" "${SnoozeFile}"
|
||||
else
|
||||
printf "dockcheck.sh ${CurrentEpochTime}\n" >> "${SnoozeFile}"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
### Set DISABLE_NOTIFY_UPDATE_NOTIFICATION=false in dockcheck.config
|
||||
### to not send notifications when notify scripts themselves have updates.
|
||||
notify_update_notification() {
|
||||
if [[ ! "${DISABLE_NOTIFY_UPDATE_NOTIFICATION:-}" = "true" ]]; then
|
||||
update_channels=( "${enabled_notify_channels[@]}" "v2" )
|
||||
if [[ ! "${DISABLE_NOTIFY_UPDATE_NOTIFICATION:-}" == "true" ]]; then
|
||||
NotifyUpdateNotify=false
|
||||
NotifyError=false
|
||||
|
||||
for notify_script in "${update_channels[@]}"; do
|
||||
upper_channel=$(tr '[:lower:]' '[:upper:]' <<< "$notify_script")
|
||||
VersionVar="NOTIFY_${upper_channel}_VERSION"
|
||||
UpdateChannels=( "${enabled_notify_channels[@]}" "v2" )
|
||||
|
||||
for NotifyScript in "${UpdateChannels[@]}"; do
|
||||
UpperChannel=$(tr '[:lower:]' '[:upper:]' <<< "$NotifyScript")
|
||||
VersionVar="NOTIFY_${UpperChannel}_VERSION"
|
||||
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}
|
||||
if [[ ! "${LatestNotifyRelease}" = "undefined" ]]; then
|
||||
if [[ "${!VersionVar}" != "$LatestNotifyRelease" ]] ; then
|
||||
MessageTitle="$FromHost - New version of notify_${notify_script}.sh available."
|
||||
|
||||
printf -v MessageBody "notify_${notify_script}.sh update available:\n ${!VersionVar} -> $LatestNotifyRelease\n"
|
||||
|
||||
for channel in "${enabled_notify_channels[@]}"; do
|
||||
printf "Sending notify_${notify_script}.sh 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
|
||||
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 [[ "${!VersionVar}" != "${LatestNotifyRelease}" ]] ; then
|
||||
Updates+=("${NotifyScript}.sh ${!VersionVar} -> ${LatestNotifyRelease}")
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
if [[ -n "${snooze}" ]] && [[ -f "${SnoozeFile}" ]]; then
|
||||
for update in "${Updates[@]}"; 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 [[ "${#Updates[@]}" -gt 0 ]]; then
|
||||
UpdToString=$( printf '%s\\n' "${Updates[@]}" )
|
||||
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 "${Updates[@]}"
|
||||
fi
|
||||
fi
|
||||
|
||||
UpdatesPlusDockcheck=("${Updates[@]}")
|
||||
UpdatesPlusDockcheck+=("dockcheck.sh")
|
||||
[[ -n "${snooze}" ]] && cleanup_snooze "${UpdatesPlusDockcheck[@]}"
|
||||
fi
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue