mirror of
https://github.com/mag37/dockcheck.git
synced 2026-02-15 15:58:13 +01:00
Merge 37f81de556 into 7785e869d3
This commit is contained in:
commit
2028d75c9e
4 changed files with 293 additions and 61 deletions
|
|
@ -1,4 +1,4 @@
|
|||
NOTIFY_V2_VERSION="v0.7"
|
||||
NOTIFY_V2_VERSION="v0.8"
|
||||
#
|
||||
# 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.
|
||||
|
|
@ -180,7 +180,9 @@ format_output() {
|
|||
local FormattedTextTemplate="$3"
|
||||
local tempcsv=""
|
||||
|
||||
if [[ ! "${UpdateType}" == "dockcheck_update" ]]; then
|
||||
if [[ "${UpdateType}" == "buffer" ]]; then
|
||||
tempcsv="${UpdToString//;/,}"
|
||||
elif [[ ! "${UpdateType}" == "dockcheck_update" ]]; then
|
||||
tempcsv="${UpdToString// -> /,}"
|
||||
tempcsv="${tempcsv//.sh /.sh,}"
|
||||
else
|
||||
|
|
@ -194,12 +196,17 @@ format_output() {
|
|||
FormattedOutput="${tempcsv}"
|
||||
fi
|
||||
elif [[ "${OutputFormat}" == "json" ]]; then
|
||||
if [[ -z "${UpdToString}" ]]; then
|
||||
if [[ "${UpdateType}" == "buffer" ]] && [[ -z "${UpdToString}" ]]; then
|
||||
FormattedOutput='{"buffer": []}'
|
||||
elif [[ -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}" == "buffer" ]]; then
|
||||
# buffer notification case
|
||||
FormattedOutput=$(jq --compact-output --null-input --arg buffer "${tempcsv}" '($buffer | split("\\n")) | map(split(",")) | {"events": map({"event": .[0], "result": .[1], "description": .[2]})} | 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]})}')
|
||||
|
|
@ -216,6 +223,8 @@ format_output() {
|
|||
else
|
||||
if [[ "${UpdateType}" == "container_update" ]]; then
|
||||
FormattedOutput="${FormattedTextTemplate/<insert_text_cu>/${UpdToString}}"
|
||||
elif [[ "${UpdateType}" == "buffer" ]]; then
|
||||
FormattedOutput="${FormattedTextTemplate/<insert_text_sn>/${UpdToString}}"
|
||||
elif [[ "${UpdateType}" == "notify_update" ]]; then
|
||||
FormattedOutput="${FormattedTextTemplate/<insert_text_nu>/${UpdToString}}"
|
||||
elif [[ "${UpdateType}" == "dockcheck_update" ]]; then
|
||||
|
|
@ -301,6 +310,42 @@ send_notification() {
|
|||
return 0
|
||||
}
|
||||
|
||||
### Set notification settings in dockcheck.config
|
||||
### to send buffer notifications
|
||||
send_buffer_notification() {
|
||||
Notified="false"
|
||||
|
||||
declare -n buffer="$1"
|
||||
|
||||
MessageTitle="$FromHost - ${2:-$1}"
|
||||
|
||||
UpdToString=$( printf '%s' "${buffer[@]}" )
|
||||
|
||||
for channel in "${enabled_notify_channels[@]}"; do
|
||||
local SkipNotification=$(skip_notification "${channel}" "1" "buffer")
|
||||
if [[ "${SkipNotification}" == "false" ]]; then
|
||||
local template=$(get_channel_template "${channel}")
|
||||
|
||||
# Formats UpdToString variable per channel settings
|
||||
format_output "buffer" "$(output_format "${channel}")" "🐋 ${2:-Events} on $FromHost:\n<insert_text_sn>\n"
|
||||
|
||||
# Setting the MessageBody variable here.
|
||||
printf -v MessageBody "${FormattedOutput}"
|
||||
|
||||
printf "\nSending ${channel} buffer notification"
|
||||
exec_if_exists_or_fail trigger_${template}_notification "${channel}" || \
|
||||
printf "\nAttempted to send buffer 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
|
||||
printf "\n"
|
||||
fi
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
### Set DISABLE_DOCKCHECK_NOTIFICATION=false in dockcheck.config
|
||||
### to not send notifications when dockcheck itself has updates.
|
||||
dockcheck_notification() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue