summaryrefslogtreecommitdiffstats
path: root/health/notifications
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2022-06-09 04:52:47 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2022-06-09 04:52:57 +0000
commit00151562145df50cc65e9902d52d5fa77f89fe50 (patch)
tree2737716802f6725a5074d606ec8fe5422c58a83c /health/notifications
parentReleasing debian version 1.34.1-1. (diff)
downloadnetdata-00151562145df50cc65e9902d52d5fa77f89fe50.tar.xz
netdata-00151562145df50cc65e9902d52d5fa77f89fe50.zip
Merging upstream version 1.35.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'health/notifications')
-rw-r--r--health/notifications/Makefile.am1
-rwxr-xr-xhealth/notifications/alarm-notify.sh.in69
-rw-r--r--health/notifications/gotify/Makefile.inc11
-rw-r--r--health/notifications/gotify/README.md62
-rwxr-xr-xhealth/notifications/health_alarm_notify.conf22
5 files changed, 161 insertions, 4 deletions
diff --git a/health/notifications/Makefile.am b/health/notifications/Makefile.am
index 46a6e472c..f026171a7 100644
--- a/health/notifications/Makefile.am
+++ b/health/notifications/Makefile.am
@@ -31,6 +31,7 @@ include awssns/Makefile.inc
include discord/Makefile.inc
include email/Makefile.inc
include flock/Makefile.inc
+include gotify/Makefile.inc
include hangouts/Makefile.inc
include irc/Makefile.inc
include kavenegar/Makefile.inc
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
diff --git a/health/notifications/gotify/Makefile.inc b/health/notifications/gotify/Makefile.inc
new file mode 100644
index 000000000..782559125
--- /dev/null
+++ b/health/notifications/gotify/Makefile.inc
@@ -0,0 +1,11 @@
+# SPDX-License-Identifier: GPL-3.0-or-later
+
+# THIS IS NOT A COMPLETE Makefile
+# IT IS INCLUDED BY ITS PARENT'S Makefile.am
+# IT IS REQUIRED TO REFERENCE ALL FILES RELATIVE TO THE PARENT
+
+# install these files
+dist_noinst_DATA += \
+ gotify/README.md \
+ gotify/Makefile.inc \
+ $(NULL)
diff --git a/health/notifications/gotify/README.md b/health/notifications/gotify/README.md
new file mode 100644
index 000000000..c253c845c
--- /dev/null
+++ b/health/notifications/gotify/README.md
@@ -0,0 +1,62 @@
+<!--
+title: "Send notifications to Gotify"
+description: "Send alerts to your Gotify instance when an alert gets triggered in Netdata."
+sidebar_label: "Gotify"
+custom_edit_url: https://github.com/netdata/netdata/edit/master/health/notifications/gotify/README.md
+-->
+
+# Send notifications to Gotify
+
+[Gotify](https://gotify.net/) is a self-hosted push notification service created for sending and receiving messages in real time.
+
+## Configuring Gotify
+
+### Prerequisites
+
+To use Gotify as your notification service, you need an application token.
+You can generate a new token in the Gotify Web UI.
+
+### Configuration
+
+To set up Gotify in Netdata:
+
+1. Switch to your [config
+directory](/docs/configure/nodes.md) and edit the file `health_alarm_notify.conf` using the edit config script.
+
+ ```bash
+ ./edit-config health_alarm_notify.conf
+ ```
+
+2. Change the variable `GOTIFY_APP_TOKEN` to the application token you generated in the Gotify Web UI. Change
+`GOTIFY_APP_URL` to point to your Gotify instance.
+
+ ```conf
+ SEND_GOTIFY="YES"
+
+ # Application token
+ # Gotify instance url
+ GOTIFY_APP_TOKEN=XXXXXXXXXXXXXXX
+ GOTIFY_APP_URL=https://push.example.de/
+ ```
+
+ Changes to `health_alarm_notify.conf` do not require a Netdata restart.
+
+3. Test your Gotify notifications configuration by running the following commands, replacing `ROLE` with your preferred role:
+
+ ```sh
+ # become user netdata
+ sudo su -s /bin/bash netdata
+
+ # send a test alarm
+ /usr/libexec/netdata/plugins.d/alarm-notify.sh test ROLE
+ ```
+
+ 🟢 If everything works, you'll see alarms in Gotify:
+
+ ![Example alarm notifications in Gotify](https://user-images.githubusercontent.com/103264516/162509205-1e88e5d9-96b6-4f7f-9426-182776158128.png)
+
+ 🔴 If sending the test notifications fails, check `/var/log/netdata/error.log` to find the relevant error message:
+
+ ```log
+ 2020-09-03 23:07:00: alarm-notify.sh: ERROR: failed to send Gotify notification for: hades test.chart.test_alarm is CRITICAL, with HTTP error code 401.
+ ```
diff --git a/health/notifications/health_alarm_notify.conf b/health/notifications/health_alarm_notify.conf
index 873c7c353..b69c6d538 100755
--- a/health/notifications/health_alarm_notify.conf
+++ b/health/notifications/health_alarm_notify.conf
@@ -279,6 +279,16 @@ STACKPULSE_WEBHOOK=""
DEFAULT_RECIPIENT_STACKPULSE=""
#------------------------------------------------------------------------------
+# gotify global notification options
+SEND_GOTIFY="YES"
+
+# App token and url
+GOTIFY_APP_TOKEN=""
+GOTIFY_APP_URL=""
+
+DEFAULT_RECIPIENT_GOTIFY=""
+
+#------------------------------------------------------------------------------
# opsgenie global notification options
SEND_OPSGENIE="YES"
@@ -971,6 +981,8 @@ role_recipients_matrix[sysadmin]="${DEFAULT_RECIPIENT_MATRIX}"
role_recipients_stackpulse[sysadmin]="${DEFAULT_RECIPIENT_STACKPULSE}"
+role_recipients_gotify[sysadmin]="${DEFAULT_RECIPIENT_GOTIFY}"
+
# -----------------------------------------------------------------------------
# DNS related alarms
@@ -1028,6 +1040,8 @@ role_recipients_matrix[domainadmin]="${DEFAULT_RECIPIENT_MATRIX}"
role_recipients_stackpulse[domainadmin]="${DEFAULT_RECIPIENT_STACKPULSE}"
+role_recipients_gotify[domainadmin]="${DEFAULT_RECIPIENT_GOTIFY}"
+
# -----------------------------------------------------------------------------
# database servers alarms
# mysql, redis, memcached, postgres, etc
@@ -1086,6 +1100,8 @@ role_recipients_matrix[dba]="${DEFAULT_RECIPIENT_MATRIX}"
role_recipients_stackpulse[dba]="${DEFAULT_RECIPIENT_STACKPULSE}"
+role_recipients_gotify[dba]="${DEFAULT_RECIPIENT_GOTIFY}"
+
# -----------------------------------------------------------------------------
# web servers alarms
# apache, nginx, lighttpd, etc
@@ -1144,6 +1160,8 @@ role_recipients_matrix[webmaster]="${DEFAULT_RECIPIENT_MATRIX}"
role_recipients_stackpulse[webmaster]="${DEFAULT_RECIPIENT_STACKPULSE}"
+role_recipients_gotify[webmaster]="${DEFAULT_RECIPIENT_GOTIFY}"
+
# -----------------------------------------------------------------------------
# proxy servers alarms
# squid, etc
@@ -1202,6 +1220,8 @@ role_recipients_matrix[proxyadmin]="${DEFAULT_RECIPIENT_MATRIX}"
role_recipients_stackpulse[proxyadmin]="${DEFAULT_RECIPIENT_STACKPULSE}"
+role_recipients_gotify[proxyadmin]="${DEFAULT_RECIPIENT_GOTIFY}"
+
# -----------------------------------------------------------------------------
# peripheral devices
# UPS, photovoltaics, etc
@@ -1257,3 +1277,5 @@ role_recipients_opsgenie[sitemgr]="${DEFAULT_RECIPIENT_OPSGENIE}"
role_recipients_matrix[sitemgr]="${DEFAULT_RECIPIENT_MATRIX}"
role_recipients_stackpulse[sitemgr]="${DEFAULT_RECIPIENT_STACKPULSE}"
+
+role_recipients_gotify[sitemgr]="${DEFAULT_RECIPIENT_GOTIFY}"