Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to send authorization header to webhook #5871

Open
wants to merge 1 commit into
base: staging
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion data/Dockerfiles/watchdog/watchdog.sh
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,13 @@ function notify_error() {
# Replace subject and body placeholders
WEBHOOK_BODY=$(echo ${WATCHDOG_NOTIFY_WEBHOOK_BODY} | sed "s/\$SUBJECT\|\${SUBJECT}/$SUBJECT/g" | sed "s/\$BODY\|\${BODY}/$BODY/g")

WEBHOOK_COMMAND="curl -X POST -H \"Content-Type: application/json\" ${CURL_VERBOSE} -d '${WEBHOOK_BODY}' ${WATCHDOG_NOTIFY_WEBHOOK}"
if [[ ! -z ${WATCHDOG_NOTIFY_WEBHOOK_AUTH_HEADER} ]]; then
WEBHOOK_COMMAND="${WEBHOOK_COMMAND} -H '${WATCHDOG_NOTIFY_WEBHOOK_AUTH_HEADER}'"
fi

# POST to webhook
curl -X POST -H "Content-Type: application/json" ${CURL_VERBOSE} -d "${WEBHOOK_BODY}" ${WATCHDOG_NOTIFY_WEBHOOK}
eval $WEBHOOK_COMMAND

log_msg "Sent notification using webhook"
fi
Expand Down
3 changes: 2 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ services:
- /lib/modules:/lib/modules:ro

watchdog-mailcow:
image: mailcow/watchdog:2.02
image: mailcow/watchdog:2.03
dns:
- ${IPV4_NETWORK:-172.22.1}.254
tmpfs:
Expand Down Expand Up @@ -493,6 +493,7 @@ services:
- WATCHDOG_SUBJECT=${WATCHDOG_SUBJECT:-Watchdog ALERT}
- WATCHDOG_NOTIFY_WEBHOOK=${WATCHDOG_NOTIFY_WEBHOOK:-}
- WATCHDOG_NOTIFY_WEBHOOK_BODY=${WATCHDOG_NOTIFY_WEBHOOK_BODY:-}
- WATCHDOG_NOTIFY_WEBHOOK_AUTH_HEADER=${WATCHDOG_NOTIFY_WEBHOOK_AUTH_HEADER:-}
- WATCHDOG_EXTERNAL_CHECKS=${WATCHDOG_EXTERNAL_CHECKS:-n}
- WATCHDOG_MYSQL_REPLICATION_CHECKS=${WATCHDOG_MYSQL_REPLICATION_CHECKS:-n}
- WATCHDOG_VERBOSE=${WATCHDOG_VERBOSE:-n}
Expand Down
2 changes: 2 additions & 0 deletions generate_config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,8 @@ USE_WATCHDOG=y
# JSON body included in the webhook POST request. Needs to be in single quotes.
# Following variables are available: SUBJECT, BODY
#WATCHDOG_NOTIFY_WEBHOOK_BODY='{"username": "mailcow Watchdog", "content": "**${SUBJECT}**\n${BODY}"}'
# If the watchdog webhook you are calling needs headers for authentication configure it as follow, putting 'name: value'in quotes:
#WATCHDOG_NOTIFY_WEBHOOK_AUTH_HEADER='authorization: Bearer allYourTokensAreBelongToUs'

# Notify about banned IP (includes whois lookup)
WATCHDOG_NOTIFY_BAN=n
Expand Down
8 changes: 8 additions & 0 deletions update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,7 @@ CONFIG_ARRAY=(
"WATCHDOG_NOTIFY_EMAIL"
"WATCHDOG_NOTIFY_WEBHOOK"
"WATCHDOG_NOTIFY_WEBHOOK_BODY"
"WATCHDOG_NOTIFY_WEBHOOK_AUTH_HEADER"
"WATCHDOG_NOTIFY_BAN"
"WATCHDOG_NOTIFY_START"
"WATCHDOG_EXTERNAL_CHECKS"
Expand Down Expand Up @@ -643,6 +644,13 @@ for option in ${CONFIG_ARRAY[@]}; do
WEBHOOK_BODY='{"username": "mailcow Watchdog", "content": "**${SUBJECT}**\n${BODY}"}'
echo "#WATCHDOG_NOTIFY_WEBHOOK_BODY='${WEBHOOK_BODY}'" >> mailcow.conf
fi
elif [[ ${option} == "WATCHDOG_NOTIFY_WEBHOOK_AUTH_HEADER" ]]; then
if ! grep -q ${option} mailcow.conf; then
echo "Adding new option \"${option}\" to mailcow.conf"
echo '# If the watchdog webhook you are calling needs headers for authentication configure it as follow, putting 'name: value'in quotes:' >> mailcow.conf
WATCHDOG_NOTIFY_WEBHOOK_AUTH_HEADER='authorization: Bearer allYourTokensAreBelongToUs'
echo "#WATCHDOG_NOTIFY_WEBHOOK_AUTH_HEADER='${WATCHDOG_NOTIFY_WEBHOOK_AUTH_HEADER}'" >> mailcow.conf
fi
elif [[ ${option} == "WATCHDOG_NOTIFY_BAN" ]]; then
if ! grep -q ${option} mailcow.conf; then
echo "Adding new option \"${option}\" to mailcow.conf"
Expand Down