From d46b38ddad1b263d18a623b33e95b600f6416fff Mon Sep 17 00:00:00 2001 From: jHund Date: Thu, 5 Mar 2026 18:27:54 +0000 Subject: [PATCH] Support for notifications via XMPP (#268) * Add files via upload Added support for XMPP using go-sendxmpp. * Add files via upload Added support for XMPP using go-sendxmpp. --- default.config | 4 +++ notify_templates/notify_xmpp.sh | 47 +++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 notify_templates/notify_xmpp.sh diff --git a/default.config b/default.config index f9076a2..0db0980 100644 --- a/default.config +++ b/default.config @@ -95,3 +95,7 @@ # TELEGRAM_CHAT_ID="mychatid" # TELEGRAM_TOKEN="token-value" # TELEGRAM_TOPIC_ID="0" +# +# XMPP_SOURCE_JID="mybotaccount@mydomain.tld" +# XMPP_SOURCE_PWD="password" +# XMPP_DEST_JID="myusername@mydomain.tld" diff --git a/notify_templates/notify_xmpp.sh b/notify_templates/notify_xmpp.sh new file mode 100644 index 0000000..4c37a91 --- /dev/null +++ b/notify_templates/notify_xmpp.sh @@ -0,0 +1,47 @@ +### DISCLAIMER: This is a third party addition to dockcheck - best effort testing. +NOTIFY_XMPP_VERSION="v0.1" +# +# Requires the package "go-sendxmpp" to be installed and in $PATH. +# +# 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 XMPP_SOURCE_ID, XMPP_SOURCE_PWD and XMPP_DEST_JID in your dockcheck.config file. + +trigger_xmpp_notification() { + if [[ -n "$1" ]]; then + xmpp_channel="$1" + else + xmpp_channel="xmpp" + fi + + if ! command -v go-sendxmpp &>/dev/null; then + printf "\nRequired binary go-sendxmpp missing. XMPP notification will not be sent.\n" + remove_channel xmpp + return 0 + fi + + UpperChannel="${xmpp_channel^^}" + + SourceJidVar="${UpperChannel}_SOURCE_JID" + SourcePwdVar="${UpperChannel}_SOURCE_PWD" + DestJidVar="${UpperChannel}_DEST_JID" + + + if [[ -z "${!SourceJidVar:-}" ]] || [[ -z "${!DestJidVar:-}" ]] || [[ -z "${!SourcePwdVar:-}" ]]; then + printf "\nRequired configuration variables are missing. XMPP notifications will not be sent.\n" + remove_channel xmpp + return 0 + fi + + SourceJid="${!SourceJidVar}" # E.g `mybotaccount@mydomain.tld` + SourcePwd="${!SourcePwdVar}" # The password for the account `mybotaccount@mydomain.tld` + DestJid="${!DestJidVar}" # E.g `myusername@mydomain.tld` + + echo "$MessageBody" | go-sendxmpp --suppress-root-warning -u "$SourceJid" -p "$SourcePwd" "$DestJid" + + if [[ $? -gt 0 ]]; then + NotifyError=true + fi + +} \ No newline at end of file