diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2022-06-09 04:52:39 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2022-06-09 04:52:39 +0000 |
commit | 89f3604407aff8f4cb2ed958252c61e23c767e24 (patch) | |
tree | 7fbf408102cab051557d38193524d8c6e991d070 /health/notifications/alarm-notify.sh.in | |
parent | Adding upstream version 1.34.1. (diff) | |
download | netdata-89f3604407aff8f4cb2ed958252c61e23c767e24.tar.xz netdata-89f3604407aff8f4cb2ed958252c61e23c767e24.zip |
Adding upstream version 1.35.0.upstream/1.35.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'health/notifications/alarm-notify.sh.in')
-rwxr-xr-x | health/notifications/alarm-notify.sh.in | 69 |
1 files changed, 65 insertions, 4 deletions
diff --git a/health/notifications/alarm-notify.sh.in b/health/notifications/alarm-notify.sh.in index 287cabfef..38a69a0f3 100755 --- a/health/notifications/alarm-notify.sh.in +++ b/health/notifications/alarm-notify.sh.in @@ -38,6 +38,7 @@ # - Dynatrace Event by @illumine # - Stackpulse Event by @thiagoftsm # - Opsgenie by @thiaoftsm #9858 +# - Gotify by @coffeegrind123 # ----------------------------------------------------------------------------- # testing notifications @@ -243,6 +244,7 @@ else total_crit_alarms="${26}" # List of alarms in critical state classification="${27}" # The class field from .conf files edit_command_line="${28}" # The command to edit the alarm, with the line number + child_machine_guid="${29}" # If populated, the notification is sent for a child fi # ----------------------------------------------------------------------------- @@ -400,6 +402,10 @@ SEND_DYNATRACE= # stackpulse configs STACKPULSE_WEBHOOK= +# gotify configs +GOTIFY_APP_URL= +GOTIFY_APP_TOKEN= + # opsgenie configs OPSGENIE_API_KEY= @@ -589,6 +595,9 @@ filter_recipient_by_criticality() { # check matrix { [ -z "${MATRIX_HOMESERVER}" ] || [ -z "${MATRIX_ACCESSTOKEN}" ]; } && SEND_MATRIX="NO" +# check gotify +{ [ -z "${GOTIFY_APP_TOKEN}" ] || [ -z "${GOTIFY_APP_URL}" ]; } && SEND_GOTIFY="NO" + # check stackpulse [ -z "${STACKPULSE_WEBHOOK}" ] && SEND_STACKPULSE="NO" @@ -626,7 +635,8 @@ if [ "${SEND_PUSHOVER}" = "YES" ] || [ "${SEND_MSTEAMS}" = "YES" ] || [ "${SEND_DYNATRACE}" = "YES" ] || [ "${SEND_STACKPULSE}" = "YES" ] || - [ "${SEND_OPSGENIE}" = "YES" ]; then + [ "${SEND_OPSGENIE}" = "YES" ] || + [ "${SEND_GOTIFY}" = "YES" ]; then # if we need curl, check for the curl command if [ -z "${curl}" ]; then curl="$(command -v curl 2>/dev/null)" @@ -656,6 +666,7 @@ if [ "${SEND_PUSHOVER}" = "YES" ] || SEND_DYNATRACE="NO" SEND_STACKPULSE="NO" SEND_OPSGENIE="NO" + SEND_GOTIFY="NO" fi fi @@ -795,7 +806,8 @@ for method in "${SEND_EMAIL}" \ "${SEND_MSTEAMS}" \ "${SEND_DYNATRACE}" \ "${SEND_STACKPULSE}" \ - "${SEND_OPSGENIE}" ; do + "${SEND_OPSGENIE}" \ + "${SEND_GOTIFY}" ; do if [ "${method}" == "YES" ]; then proceed=1 @@ -2278,6 +2290,45 @@ EOF } # ----------------------------------------------------------------------------- +# Gotify sender + +send_gotify() { + local payload httpcode priority + [ "${SEND_GOTIFY}" != "YES" ] && return 1 + + if [ -z "${GOTIFY_APP_TOKEN}" ] ; then + info "Can't send Gotify notification, because GOTIFY_APP_TOKEN is not defined" + return 1 + fi + + # priority for Gotify Android app + case "${status}" in + CRITICAL) priority=10 ;; # sound + vibration + WARNING) priority=4 ;; # sound + *) priority=1 ;; # notification only + esac + + payload=$(cat <<EOF + { + "title" : "${status}, ${name} = ${value_string}, on ${host}", + "message" : "${date}: ${chart} ${value_string}", + "priority" : ${priority} + } +EOF +) + + httpcode=$(docurl -X POST -H "Content-Type: application/json" -d "${payload}" "${GOTIFY_APP_URL}/message?token=${GOTIFY_APP_TOKEN}") + if [ "${httpcode}" = "200" ]; then + info "sent gotify notification for: ${host} ${chart}.${name} is ${status}" + else + error "failed to send gotify notification for: ${host} ${chart}.${name} is ${status}, with HTTP error code ${httpcode}." + return 1 + fi + + return 0 +} + +# ----------------------------------------------------------------------------- # prepare the content of the notification # the url to send the user on click @@ -2311,7 +2362,11 @@ if [ ${GOTOCLOUD} -eq 0 ]; then else # Temporarily disable alarm redirection, as the cloud endpoint no longer exists. This functionality will be restored after discussion on #9487. For now, just lead to netdata.cloud # Re-allow alarm redirection, for alarms 2.0, new template - goto_url="${NETDATA_REGISTRY_CLOUD_BASE_URL}/alarms/redirect?agentId=${NETDATA_REGISTRY_UNIQUE_ID}&${redirect_params}" + if [ -z "${child_machine_guid}" ]; then + goto_url="${NETDATA_REGISTRY_CLOUD_BASE_URL}/alarms/redirect?agentId=${NETDATA_REGISTRY_UNIQUE_ID}&${redirect_params}" + else + goto_url="${NETDATA_REGISTRY_CLOUD_BASE_URL}/alarms/redirect?agentId=${NETDATA_REGISTRY_UNIQUE_ID}&childId=${child_machine_guid}&${redirect_params}" + fi fi # the severity of the alarm @@ -3467,6 +3522,11 @@ send_opsgenie SENT_OPSGENIE=$? # ----------------------------------------------------------------------------- +# send messages to Gotify +send_gotify +SENT_GOTIFY=$? + +# ----------------------------------------------------------------------------- # let netdata know for state in "${SENT_EMAIL}" \ "${SENT_PUSHOVER}" \ @@ -3495,7 +3555,8 @@ for state in "${SENT_EMAIL}" \ "${SENT_MSTEAMS}" \ "${SENT_DYNATRACE}" \ "${SENT_STACKPULSE}" \ - "${SENT_OPSGENIE}"; do + "${SENT_OPSGENIE}" \ + "${SENT_GOTIFY}"; do if [ "${state}" -eq 0 ]; then # we sent something exit 0 |