]> arthur.barton.de Git - netdata.git/commitdiff
alarm-notify.sh configuration; alarm-notify.sh support multiple recipients per alarm...
authorCosta Tsaousis (ktsaou) <costa@tsaousis.gr>
Thu, 8 Sep 2016 21:57:34 +0000 (00:57 +0300)
committerCosta Tsaousis (ktsaou) <costa@tsaousis.gr>
Thu, 8 Sep 2016 21:57:34 +0000 (00:57 +0300)
conf.d/health_alarm_notify.conf
plugins.d/alarm-notify.sh

index e485591346cea341d0d23c6febb2b7fc8f2da1b9..d1c42bd220b752ec9f2e805ea787d8c192df78b3 100644 (file)
@@ -2,52 +2,98 @@
 
 # netdata alarms have been categorized to allow different roles to receive
 # alarms related to their work.
+#
+# This file defines the addresses for each role.
+# This file is a BASH script itself.
 
-# this file defines the email addresses for each role. if a role is not
-# defined, the email will be sent to root.
+###############################################################################
+# external commands needed
+
+# The full path to the sendmail command.
+# If empty, the system $PATH will be searched for it.
+sendmail=
+
+# The full path of the curl command.
+# If empty, the system $PATH will be searched for it.
+curl=
+
+
+###############################################################################
+# sending emails
+
+# note: multiple recipients can be given like this:
+#              "admin1@example.com, admin2@example.com, ..."
+# note it needs a comma!
+
+# enable/disable sending emails
+SEND_EMAIL="YES"
+
+# if a role recipient is not configured, an email will be send to
+DEFAULT_RECIPIENT_EMAIL="root"
 
-# you can set multiple addresses for each role, like this:
-#
-# recipients[sysadmin]="admin1@example.com, admin2@example.com"
-#
-# it is important to add the comma between email addresses.
 
-# This configuration file is a BASH script itself. The 'recipients' variable is
-# an associative array. So you can use other variables too, like this one:
+###############################################################################
+# sending pushover notifications (pushover.com)
 
-default_recipient_for_all_roles="root"
+# note: multiple recipients can be given like this:
+#                  "USERTOKEN1 USERTOKEN2 USERTOKEN3 ..."
 
+# enable/disable sending pushover notifications
+SEND_PUSHOVER="YES"
+
+# Login to pushover.com to get your pushover app token
+# You need only one for all your netdata servers.
+# Without it, netdata cannot send pushover notifications.
+PUSHOVER_APP_TOKEN=
+
+# if a role recipient is not configured, a notification will be send to
+# this pushover user token
+DEFAULT_RECIPIENT_PUSHOVER=
+
+
+###############################################################################
+# RECIPIENTS PER ROLE
 
 # -----------------------------------------------------------------------------
 # generic system alarms
 # CPU, disks, entropy, etc
 
-recipients[sysadmin]="${default_recipient_for_all_roles}"
+role_recipients_email[sysadmin]="${DEFAULT_RECIPIENT_EMAIL}"
+
+role_recipients_pushover[sysadmin]="${DEFAULT_RECIPIENT_PUSHOVER}"
 
 
 # -----------------------------------------------------------------------------
 # DNS related alarms
 
-recipients[domainadmin]="${default_recipient_for_all_roles}"
+role_recipients_email[domainadmin]="${DEFAULT_RECIPIENT_EMAIL}"
+
+role_recipients_pushover[domainadmin]="${DEFAULT_RECIPIENT_PUSHOVER}"
 
 
 # -----------------------------------------------------------------------------
 # database servers alarms
 # mysql, redis, memcached, etc
 
-recipients[dba]="${default_recipient_for_all_roles}"
+role_recipients_email[dba]="${DEFAULT_RECIPIENT_EMAIL}"
+
+role_recipients_pushover[dba]="${DEFAULT_RECIPIENT_PUSHOVER}"
 
 
 # -----------------------------------------------------------------------------
 # web servers alarms
 # apache, nginx, etc
 
-recipients[webmaster]="${default_recipient_for_all_roles}"
+role_recipients_email[webmaster]="${DEFAULT_RECIPIENT_EMAIL}"
+
+role_recipients_pushover[webmaster]="${DEFAULT_RECIPIENT_PUSHOVER}"
 
 
 # -----------------------------------------------------------------------------
 # proxy servers alarms
 # apache, nginx, etc
 
-recipients[proxyadmin]="${default_recipient_for_all_roles}"
+role_recipients_email[proxyadmin]="${DEFAULT_RECIPIENT_EMAIL}"
+
+role_recipients_pushover[proxyadmin]="${DEFAULT_RECIPIENT_PUSHOVER}"
 
index 9188b9671261e8258bd12b4bd0f25400fb9fa6a0..55d149a5d1b91e97287fc97bb22450ebd8292b48 100755 (executable)
@@ -195,27 +195,31 @@ send_email() {
 # pushover sender
 
 send_pushover() {
-    local apptoken="${1}" usertoken="${2}" title="${3}" message="${4}" httpcode
+    local apptoken="${1}" usertoken="${2}" title="${3}" message="${4}" httpcode sent=0 user
 
     if [ "${SEND_PUSHOVER}" = "YES" -a ! -z "${apptoken}" -a ! -z "${usertoken}" -a ! -z "${title}" -a ! -z "${message}" ]
         then
 
-        httpcode=$(${curl} --write-out %{http_code} --silent --output /dev/null \
-            --form-string "token=${apptoken}" \
-            --form-string "user=${usertoken}" \
-            --form-string "html=1" \
-            --form-string "title=${title}" \
-            --form-string "message=${message}" \
-            https://api.pushover.net/1/messages.json)
-
-        if [ "${httpcode}" == "200" ]
-        then
-            echo >&2 "${me}: Sent notification push for ${status} on '${chart}.${name}'"
-            return 0
-        else
-            echo >&2 "${me}: FAILED to send notification push for ${status} on '${chart}.${name}' with HTTP error code ${httpcode}."
-            return 1
-        fi
+        for user in ${usertoken//,/ }
+        do
+            httpcode=$(${curl} --write-out %{http_code} --silent --output /dev/null \
+                --form-string "token=${apptoken}" \
+                --form-string "user=${user}" \
+                --form-string "html=1" \
+                --form-string "title=${title}" \
+                --form-string "message=${message}" \
+                https://api.pushover.net/1/messages.json)
+
+            if [ "${httpcode}" == "200" ]
+            then
+                echo >&2 "${me}: Sent notification push for ${status} on '${chart}.${name}' to '${user}'"
+                sent=$((sent + 1))
+            else
+                echo >&2 "${me}: FAILED to send notification push for ${status} on '${chart}.${name}' to '${user}' with HTTP error code ${httpcode}."
+            fi
+        done
+
+        [ ${sent} -gt 0 ] && return 0
     fi
 
     return 1