@cryptotaxi247 / netdata-1 / commits / 780fd606e

alarm-notify: Add Prowl integration for iOS users. (#5132)

* alarm-notify: Add Prowl integration for iOS users. This adds the ability for Netdata to send push notifications to iOS devices via prowlapp.com. Delivered notifications have a similar format to that used with Fleep.io, and include a URL that links back to the Netdata system that originally issued the alert. There is a hard limit on API calls to Prowl of 1000 per IP per hour. Prowl provides support for issuing notifications to multiple recipients simultaneously by specifying more than one API key with a request, and this code takes advantage of that so that any notification only results in at most one API call. Fixes: #3788 * Numerous small fixes.

Austin S. Hemmelgarn committed Jan 22, 2019 at 08:09 UTC 780fd606ee6f71aa48777313448dabc6ec86c36a
4 files changed +119
health/notifications/alarm-notify.sh.in
+56
@@ -27,6 +27,7 @@
27 # - messagebird.com notifications by @tech_no_logical #1453
28 # - hipchat notifications by @ktsaou #1561
29 # - fleep notifications by @Ferroin
30 +# - prowlapp.com notifications by @Ferroin
31 # - custom notifications by @ktsaou
32 # - syslog messages by @Ferroin
33 # - Microsoft Team notification by @tioumen
@@ -164,6 +165,7 @@ syslog
165 custom
166 msteam
167 kavenegar
168 +prowl
169 "
170
171 # -----------------------------------------------------------------------------
@@ -519,6 +521,7 @@ if [ \( \
521 -o "${SEND_PUSHBULLET}" = "YES" \
522 -o "${SEND_KAFKA}" = "YES" \
523 -o "${SEND_FLEEP}" = "YES" \
524 + -o "${SEND_PROWL}" = "YES" \
525 -o "${SEND_CUSTOM}" = "YES" \
526 -o "${SEND_MSTEAM}" = "YES" \
527 \) -a -z "${curl}" ]
@@ -543,6 +546,7 @@ if [ \( \
546 SEND_KAVENEGAR="NO"
547 SEND_KAFKA="NO"
548 SEND_FLEEP="NO"
549 + SEND_PROWL="NO"
550 SEND_CUSTOM="NO"
551 fi
552 fi
@@ -662,6 +666,7 @@ if [ "${SEND_EMAIL}" != "YES" \
666 -a "${SEND_CUSTOM}" != "YES" \
667 -a "${SEND_IRC}" != "YES" \
668 -a "${SEND_AWSSNS}" != "YES" \
669 + -o "${SEND_PROWL}" != "YES" \
670 -a "${SEND_SYSLOG}" != "YES" \
671 -a "${SEND_MSTEAM}" != "YES" \
672 ]
@@ -1611,6 +1616,50 @@ send_fleep() {
1616 return 1
1617 }
1618
1619 +# -----------------------------------------------------------------------------
1620 +# Prowl sender
1621 +
1622 +send_prowl() {
1623 + local httpcode sent=0 data message keys prio=0 alarm_url event
1624 + if [ "${SEND_PROWL}" = "YES" ] ; then
1625 + message="$(urlencode "${host} ${status_message}, \`${chart}\` (${family}), *${alarm}*\\n${info}")"
1626 + message="description=${message}"
1627 + keys="$(urlencode "$(echo "${1}" | tr ' ' ,)")"
1628 + keys="apikey=${keys}"
1629 + app="application=Netdata"
1630 +
1631 + case "${status}" in
1632 + CRITICAL)
1633 + prio=2
1634 + ;;
1635 + WARNING)
1636 + prio=1
1637 + ;;
1638 + esac
1639 + pri="priority=${pri}"
1640 +
1641 + alarm_url="$(urlencode ${goto_url})"
1642 + alarm_url="url=${alarm_url}"
1643 + event="$(urlencode "${host} ${status_message}")"
1644 + event="event=${event}"
1645 +
1646 + data="${keys}&${pri}&${alarm_url}&${app}&${event}&${message}"
1647 +
1648 + httpcode=$(docurl -X POST --data "${data}" "https://api.prowlapp.com/publicapi/add")
1649 +
1650 + if [ "${httpcode}" = "200" ] ; then
1651 + info "sent prowl data for: ${host} ${chart}.${name} is ${status}"
1652 + sent=1
1653 + else
1654 + error "failed to send prowl data for: ${host} ${chart}.${name} is ${status} with with error code ${httpcode}."
1655 + fi
1656 +
1657 + [ ${sent} -gt 0 ] && return 0
1658 + fi
1659 +
1660 + return 1
1661 +}
1662 +
1663 # -----------------------------------------------------------------------------
1664 # irc sender
1665
@@ -1989,6 +2038,12 @@ SENT_PD=$?
2038 send_fleep "${to_fleep}"
2039 SENT_FLEEP=$?
2040
2041 +# -----------------------------------------------------------------------------
2042 +# send the Prowl message
2043 +
2044 +send_prowl "${to_prowl}"
2045 +SENT_PROWL=$?
2046 +
2047 # -----------------------------------------------------------------------------
2048 # send the irc message
2049
@@ -2215,6 +2270,7 @@ if [ ${SENT_EMAIL} -eq 0 \
2270 -o ${SENT_KAFKA} -eq 0 \
2271 -o ${SENT_PD} -eq 0 \
2272 -o ${SENT_FLEEP} -eq 0 \
2273 + -o ${SENT_PROWL} -eq 0 \
2274 -o ${SENT_IRC} -eq 0 \
2275 -o ${SENT_AWSSNS} -eq 0 \
2276 -o ${SENT_CUSTOM} -eq 0 \
health/notifications/health_alarm_notify.conf
+29
@@ -14,6 +14,7 @@
14 # - sms messages to your cell phone or any sms enabled device (twilio.com)
15 # - sms messages to your cell phone or any sms enabled device (messagebird.com)
16 # - notifications to users on pagerduty.com
17 +# - push notifications to iOS devices (via prowlapp.com)
18 # - notifications to Amazon SNS topics (aws.amazon.com)
19 # - messages to your irc channel on your selected network
20 # - messages to a local or remote syslog daemon
@@ -653,6 +654,22 @@ SYSLOG_FACILITY=''
654 #
655 DEFAULT_RECIPIENT_SYSLOG="netdata"
656
657 +#------------------------------------------------------------------------------
658 +# iOS Push Notifications
659 +
660 +# enable/disable sending iOS push notifications
661 +SEND_PROWL="YES"
662 +
663 +# If a role's recipients are not configured, use the following,
664 +# (empty = do not send a notiication for unconfigured roles)
665 +#
666 +# Recipients for iOS push notifications are Prowl API keys.
667 +#
668 +# A recipient may also consist of multiple Prowl API keys separated by
669 +# commas, in which case notifications will be simultaneously sent for all
670 +# of those API keys.
671 +DEFAULT_RECIPIENT_PROWL=""
672 +
673 #------------------------------------------------------------------------------
674 # Amazon SNS notifications
675 #
@@ -776,6 +793,8 @@ role_recipients_irc[sysadmin]="${DEFAULT_RECIPIENT_IRC}"
793
794 role_recipients_syslog[sysadmin]="${DEFAULT_RECIPIENT_SYSLOG}"
795
796 +role_recipients_prowl[sysadming]="${DEFAULT_RECIPIENT_PROWL}"
797 +
798 role_recipients_awssns[sysadmin]="${DEFAULT_RECIPIENT_AWSSNS}"
799
800 role_recipients_custom[sysadmin]="${DEFAULT_RECIPIENT_CUSTOM}"
@@ -817,6 +836,8 @@ role_recipients_irc[domainadmin]="${DEFAULT_RECIPIENT_IRC}"
836
837 role_recipients_syslog[domainadmin]="${DEFAULT_RECIPIENT_SYSLOG}"
838
839 +role_recipients_prowl[domainadmin]="${DEFAULT_RECIPIENT_PROWL}"
840 +
841 role_recipients_awssns[domainadmin]="${DEFAULT_RECIPIENT_AWSSNS}"
842
843 role_recipients_custom[domainadmin]="${DEFAULT_RECIPIENT_CUSTOM}"
@@ -859,6 +880,8 @@ role_recipients_irc[dba]="${DEFAULT_RECIPIENT_IRC}"
880
881 role_recipients_syslog[dba]="${DEFAULT_RECIPIENT_SYSLOG}"
882
883 +role_recipients_prowl[dba]="${DEFAULT_RECIPIENT_PROWL}"
884 +
885 role_recipients_awssns[dba]="${DEFAULT_RECIPIENT_AWSSNS}"
886
887 role_recipients_custom[dba]="${DEFAULT_RECIPIENT_CUSTOM}"
@@ -901,6 +924,8 @@ role_recipients_irc[webmaster]="${DEFAULT_RECIPIENT_IRC}"
924
925 role_recipients_syslog[webmaster]="${DEFAULT_RECIPIENT_SYSLOG}"
926
927 +role_recipients_prowl[webmaster]="${DEFAULT_RECIPIENT_PROWL}"
928 +
929 role_recipients_awssns[webmaster]="${DEFAULT_RECIPIENT_AWSSNS}"
930
931 role_recipients_custom[webmaster]="${DEFAULT_RECIPIENT_CUSTOM}"
@@ -943,6 +968,8 @@ role_recipients_irc[proxyadmin]="${DEFAULT_RECIPIENT_IRC}"
968
969 role_recipients_syslog[proxyadmin]="${DEFAULT_RECIPIENT_SYSLOG}"
970
971 +role_recipients_prowl[proxyadmin]="${DEFAULT_RECIPIENT_PROWL}"
972 +
973 role_recipients_awssns[porxyadmin]="${DEFAULT_RECIPIENT_AWSSNS}"
974
975 role_recipients_custom[proxyadmin]="${DEFAULT_RECIPIENT_CUSTOM}"
@@ -983,6 +1010,8 @@ role_recipients_fleep[sitemgr]="${DEFAULT_RECIPIENT_FLEEP}"
1010
1011 role_recipients_syslog[sitemgr]="${DEFAULT_RECIPIENT_SYSLOG}"
1012
1013 +role_recipients_prowl[sitemgr]="${DEFAULT_RECIPIENT_PROWL}"
1014 +
1015 role_recipients_awssns[sitemgr]="${DEFAULT_RECIPIENT_AWSSNS}"
1016
1017 role_recipients_custom[sitemgr]="${DEFAULT_RECIPIENT_CUSTOM}"
health/notifications/prowl/Makefile.inc new
+12
@@ -0,0 +1,12 @@
1 +# SPDX-License-Identifier: GPL-3.0-or-later
2 +
3 +# THIS IS NOT A COMPLETE Makefile
4 +# IT IS INCLUDED BY ITS PARENT'S Makefile.am
5 +# IT IS REQUIRED TO REFERENCE ALL FILES RELATIVE TO THE PARENT
6 +
7 +# install these files
8 +dist_noinst_DATA += \
9 + prowl/README.md \
10 + prowl/Makefile.inc \
11 + $(NULL)
12 +
health/notifications/prowl/README.md new
+22
@@ -0,0 +1,22 @@
1 +# prowl
2 +
3 +(Prowl)[1] is a push notification service for iOS devices. Netdata
4 +supprots delivering notifications to iOS devices through Prowl.
5 +
6 +Because of how Netdata integrates with Prowl, there is a hard limit of
7 +at most 1000 notifications per hour (starting from the first notification
8 +sent). Any alerts beyond the first thousand in an hour will be dropped.
9 +
10 +Warning messages will be sent with the 'High' priority, critical messages
11 +will be sent with the 'Emergency' priority, and all other messages will
12 +be sent with the normal priority. Opening the notification's associated
13 +URL will take you to the Netdata dashboard of the system that issued
14 +the alert, directly to the chart that it triggered on.
15 +
16 +## configuration
17 +
18 +To use this, you will need a Prowl API key, which can be rquested through
19 +the Prowl website after registering.
20 +
21 +Once you have an API key, simply specify that as a recipient for Prowl
22 +notifications.