@cryptotaxi247 / netdata-1 / commits / 2d2e3a1e1

Implement hangouts chat notifications (#7013)

* Implement hangouts chat notifications * Fix null check in bash script * Apply suggestions from code review Co-Authored-By: Joel Hans <joel.g.hans@gmail.com>

Hendrik Hofstadt committed Oct 17, 2019 at 22:00 UTC 2d2e3a1e1483bb8acf6d669b2e9e096af87d2eea
6 files changed +211 -4
README.md
+1 -1
@@ -376,7 +376,7 @@ This is what you should expect from Netdata:
376 ### Health Monitoring & Alarms
377
378 - **Sophisticated alerting** - comes with hundreds of alarms, **out of the box**! Supports dynamic thresholds, hysteresis, alarm templates, multiple role-based notification methods.
379 -- **Notifications**: [alerta.io](health/notifications/alerta/), [amazon sns](health/notifications/awssns/), [discordapp.com](health/notifications/discord/), [email](health/notifications/email/), [flock.com](health/notifications/flock/), [irc](health/notifications/irc/), [kavenegar.com](health/notifications/kavenegar/), [messagebird.com](health/notifications/messagebird/), [pagerduty.com](health/notifications/pagerduty/), [prowl](health/notifications/prowl/), [pushbullet.com](health/notifications/pushbullet/), [pushover.net](health/notifications/pushover/), [rocket.chat](health/notifications/rocketchat/), [slack.com](health/notifications/slack/), [smstools3](health/notifications/smstools3/), [syslog](health/notifications/syslog/), [telegram.org](health/notifications/telegram/), [twilio.com](health/notifications/twilio/), [web](health/notifications/web/) and [custom notifications](health/notifications/custom/).
379 +- **Notifications**: [alerta.io](health/notifications/alerta/), [amazon sns](health/notifications/awssns/), [discordapp.com](health/notifications/discord/), [email](health/notifications/email/), [flock.com](health/notifications/flock/), [hangouts](health/notifications/hangouts/), [irc](health/notifications/irc/), [kavenegar.com](health/notifications/kavenegar/), [messagebird.com](health/notifications/messagebird/), [pagerduty.com](health/notifications/pagerduty/), [prowl](health/notifications/prowl/), [pushbullet.com](health/notifications/pushbullet/), [pushover.net](health/notifications/pushover/), [rocket.chat](health/notifications/rocketchat/), [slack.com](health/notifications/slack/), [smstools3](health/notifications/smstools3/), [syslog](health/notifications/syslog/), [telegram.org](health/notifications/telegram/), [twilio.com](health/notifications/twilio/), [web](health/notifications/web/) and [custom notifications](health/notifications/custom/).
380
381 ### Integrations
382
health/notifications/Makefile.am
+2 -1
@@ -31,6 +31,7 @@ include awssns/Makefile.inc
31 include discord/Makefile.inc
32 include email/Makefile.inc
33 include flock/Makefile.inc
34 +include hangouts/Makefile.inc
35 include irc/Makefile.inc
36 include kavenegar/Makefile.inc
37 include messagebird/Makefile.inc
@@ -44,4 +45,4 @@ include syslog/Makefile.inc
45 include telegram/Makefile.inc
46 include twilio/Makefile.inc
47 include web/Makefile.inc
47 -include custom/Makefile.inc
\ No newline at end of file
48 +include custom/Makefile.inc
health/notifications/alarm-notify.sh.in
+127
@@ -33,6 +33,7 @@
33 # - syslog messages by @Ferroin
34 # - Microsoft Team notification by @tioumen
35 # - RocketChat notifications by @Hermsi1337 #3777
36 +# - Google Hangouts Chat notifications by @EnzoAkira and @hendrikhofstadt
37
38 # -----------------------------------------------------------------------------
39 # testing notifications
@@ -166,6 +167,7 @@ prowl
167 awssns
168 rocketchat
169 sms
170 +hangouts
171 "
172
173 # -----------------------------------------------------------------------------
@@ -359,6 +361,9 @@ IRC_NICKNAME=
361 IRC_REALNAME=
362 IRC_NETWORK=
363
364 +# hangouts configs
365 +declare -A HANGOUTS_WEBHOOK_URI
366 +
367 # load the stock and user configuration files
368 # these will overwrite the variables above
369
@@ -491,6 +496,9 @@ filter_recipient_by_criticality() {
496 # check irc
497 [ -z "${IRC_NETWORK}" ] && SEND_IRC="NO"
498
499 +# check hangouts
500 +[ ${#HANGOUTS_WEBHOOK_URI[@]} -eq 0 ] && SEND_HANGOUTS="NO"
501 +
502 # check fleep
503 #shellcheck disable=SC2153
504 { [ -z "${FLEEP_SERVER}" ] || [ -z "${FLEEP_SENDER}" ]; } && SEND_FLEEP="NO"
@@ -511,6 +519,7 @@ if [ "${SEND_PUSHOVER}" = "YES" ] ||
519 [ "${SEND_KAFKA}" = "YES" ] ||
520 [ "${SEND_FLEEP}" = "YES" ] ||
521 [ "${SEND_PROWL}" = "YES" ] ||
522 + [ "${SEND_HANGOUTS}" = "YES" ] ||
523 [ "${SEND_CUSTOM}" = "YES" ] ||
524 [ "${SEND_MSTEAM}" = "YES" ]; then
525 # if we need curl, check for the curl command
@@ -536,6 +545,7 @@ if [ "${SEND_PUSHOVER}" = "YES" ] ||
545 SEND_KAFKA="NO"
546 SEND_FLEEP="NO"
547 SEND_PROWL="NO"
548 + SEND_HANGOUTS="NO"
549 SEND_CUSTOM="NO"
550 fi
551 fi
@@ -659,6 +669,7 @@ for method in "${SEND_EMAIL}" \
669 "${SEND_PROWL}" \
670 "${SEND_CUSTOM}" \
671 "${SEND_IRC}" \
672 + "${SEND_HANGOUTS}" \
673 "${SEND_AWSSNS}" \
674 "${SEND_SYSLOG}" \
675 "${SEND_SMS}" \
@@ -1770,6 +1781,112 @@ send_sms() {
1781 return 1
1782 }
1783
1784 +# -----------------------------------------------------------------------------
1785 +# hangouts sender
1786 +
1787 +send_hangouts() {
1788 + local rooms="${1}" httpcode sent=0 room color payload webhook
1789 +
1790 + [ "${SEND_HANGOUTS}" != "YES" ] && return 1
1791 +
1792 + case "${status}" in
1793 + WARNING) color="#ffa700" ;;
1794 + CRITICAL) color="#d62d20" ;;
1795 + CLEAR) color="#008744" ;;
1796 + *) color="#777777" ;;
1797 + esac
1798 +
1799 + for room in ${rooms}; do
1800 + if [ -z "${HANGOUTS_WEBHOOK_URI[$room]}" ] ; then
1801 + info "Can't send Hangouts notification for: ${host} ${chart}.${name} to room ${room}. HANGOUTS_WEBHOOK_URI[$room] not defined"
1802 + else
1803 + webhook="${HANGOUTS_WEBHOOK_URI[$room]}"
1804 + payload="$(
1805 + cat <<EOF
1806 + {
1807 + "cards": [
1808 + {
1809 + "header": {
1810 + "title": "Netdata on ${host}",
1811 + "imageUrl": "${images_base_url}/images/banner-icon-144x144.png",
1812 + "imageStyle": "IMAGE"
1813 + },
1814 + "sections": [
1815 + {
1816 + "header": "<b>${host}</b>",
1817 + "widgets": [
1818 + {
1819 + "keyValue": {
1820 + "topLabel": "Status Message",
1821 + "content": "<b>${status_message}</b>",
1822 + "contentMultiline": "true",
1823 + "iconUrl": "${image}",
1824 + "onClick": {
1825 + "openLink": {
1826 + "url": "${goto_url}"
1827 + }
1828 + }
1829 + }
1830 + },
1831 + {
1832 + "keyValue": {
1833 + "topLabel": "${chart} | ${family}",
1834 + "content": "<font color=${color}>${alarm}</font>",
1835 + "contentMultiline": "true"
1836 + }
1837 + }
1838 + ]
1839 + },
1840 + {
1841 + "widgets": [
1842 + {
1843 + "textParagraph": {
1844 + "text": "<font color=\"#0057e7\">@ ${date}\n<b>${info}</b></font>"
1845 + }
1846 + }
1847 + ]
1848 + },
1849 + {
1850 + "widgets": [
1851 + {
1852 + "buttons": [
1853 + {
1854 + "textButton": {
1855 + "text": "Go to ${host}",
1856 + "onClick": {
1857 + "openLink": {
1858 + "url": "${goto_url}"
1859 + }
1860 + }
1861 + }
1862 + }
1863 + ]
1864 + }
1865 + ]
1866 + }
1867 + ]
1868 + }
1869 + ]
1870 + }
1871 +EOF
1872 + )"
1873 +
1874 + httpcode=$(docurl -H "Content-Type: application/json" -X POST -d "${payload}" "${webhook}")
1875 +
1876 + if [ "${httpcode}" = "200" ]; then
1877 + info "sent hangouts notification for: ${host} ${chart}.${name} is ${status} to '${room}'"
1878 + sent=$((sent + 1))
1879 + else
1880 + error "failed to send hangouts notification for: ${host} ${chart}.${name} is ${status} to '${room}', with HTTP error code ${httpcode}."
1881 + fi
1882 + fi
1883 + done
1884 +
1885 + [ ${sent} -gt 0 ] && return 0
1886 +
1887 + return 1
1888 +}
1889 +
1890 # -----------------------------------------------------------------------------
1891 # prepare the content of the notification
1892
@@ -1888,6 +2005,15 @@ raised_for_html=
2005 send_slack "${SLACK_WEBHOOK_URL}" "${to_slack}"
2006 SENT_SLACK=$?
2007
2008 +# -----------------------------------------------------------------------------
2009 +# send the hangouts notification
2010 +
2011 +# hangouts aggregates posts from the same room
2012 +# so we use "${host} ${status}" as the room, to make them diff
2013 +
2014 +send_hangouts "${to_hangouts}"
2015 +SENT_HANGOUTS=$?
2016 +
2017 # -----------------------------------------------------------------------------
2018 # send the Microsoft notification
2019
@@ -2270,6 +2396,7 @@ for state in "${SENT_EMAIL}" \
2396 "${SENT_PUSHOVER}" \
2397 "${SENT_TELEGRAM}" \
2398 "${SENT_SLACK}" \
2399 + "${SENT_HANGOUTS}" \
2400 "${SENT_ROCKETCHAT}" \
2401 "${SENT_ALERTA}" \
2402 "${SENT_FLOCK}" \
health/notifications/hangouts/Makefile.inc new
+11
@@ -0,0 +1,11 @@
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 + hangouts/README.md \
10 + hangouts/Makefile.inc \
11 + $(NULL)
health/notifications/hangouts/README.md new
+33
@@ -0,0 +1,33 @@
1 +# Hangouts Chat
2 +
3 +This is what you will get:
4 +![Netdata on Hangouts](https://user-images.githubusercontent.com/1153921/66427166-47de6900-e9c8-11e9-8322-b4b03f084dc1.png)
5 +To receive notifications in Google Hangouts, you need the following in your Hangouts setup:
6 +
7 +1. One or more rooms
8 +2. An **incoming webhook** for each room
9 +
10 +How to create an incoming webhook:
11 +https://developers.google.com/hangouts/chat/how-tos/webhooks
12 +
13 +Set the webhook URIs and room names in `health_alarm_notify.conf`. To edit it on your system, run `/etc/netdata/edit-config health_alarm_notify.conf`):
14 +
15 +```
16 +#------------------------------------------------------------------------------
17 +# hangouts (google hangouts chat) global notification options
18 +# enable/disable sending hangouts notifications
19 +SEND_HANGOUTS="YES"
20 +# On Hangouts, in the room you choose, create an incoming webhook,
21 +# copy the link and paste it below and also identify the room name.
22 +# Without it, netdata cannot send hangouts notifications to that room.
23 +# HANGOUTS_WEBHOOK_URI[ROOM_NAME]="URLforroom1"
24 +HANGOUTS_WEBHOOK_URI[systems]="https://chat.googleapis.com/v1/spaces/AAAAXXXXXXX/..."
25 +HANGOUTS_WEBHOOK_URI[development]="https://chat.googleapis.com/v1/spaces/AAAAYYYYY/..."
26 +# if a DEFAULT_RECIPIENT_HANGOUTS are not configured,
27 +# notifications wouldn't be send to hangouts rooms.
28 +# DEFAULT_RECIPIENT_HANGOUTS="systems development|critical"
29 +DEFAULT_RECIPIENT_HANGOUTS="sysadmin devops alarms|critical"
30 +```
31 +You can define multiple rooms like this: `sysadmin devops alarms|critical`.
32 +
33 +The keywords `sysadmin`, `devops` and `alarms` are Hangouts rooms.
health/notifications/health_alarm_notify.conf
+37 -2
@@ -21,6 +21,7 @@
21 # - messages to a local or remote syslog daemon
22 # - message to Microsoft Team (through webhook)
23 # - message to Rocket.Chat (through webhook)
24 +# - message to Google Hangouts Chat (through webhook)
25 #
26 # The 'to' line given at netdata alarms defines a *role*, so that many
27 # people can be notified for each role.
@@ -176,6 +177,7 @@ sendsms=""
177 # kavenegar : "09155555555 09177777777|critical"
178 # pd : "<pd_service_key_1> <pd_service_key_2>|critical"
179 # irc : "<irc_channel_1> <irc_channel_2>|critical"
180 +# hangouts : "alarms disasters|critical"
181 #
182 # If a recipient is set to empty string, the default recipient of the given
183 # notification method (email, pushover, telegram, slack, alerta, etc) will be used.
@@ -227,6 +229,27 @@ DEFAULT_RECIPIENT_EMAIL="root"
229 # to not send HTML but Plain Text only emails.
230 #EMAIL_PLAINTEXT_ONLY="YES"
231
232 +#------------------------------------------------------------------------------
233 +# hangouts (google hangouts chat) global notification options
234 +
235 +# enable/disable sending hangouts notifications
236 +SEND_HANGOUTS="YES"
237 +
238 +# On Hangouts, in the room you choose, create an incoming webhook,
239 +# copy the link and paste it below and also give it a room name.
240 +# Without it, netdata cannot send hangouts notifications to that room.
241 +# You will then use the same room name in your recipients list. For each URI, you need
242 +# HANGOUTS_WEBHOOK_URI[room_name]="WEBHOOK_URI"
243 +# e.g. to define systems and development rooms/recipients:
244 +# HANGOUTS_WEBHOOK_URI[systems]="URLforroom1"
245 +# HANGOUTS_WEBHOOK_URI[development]="URLforroom2"
246 +
247 +# if a DEFAULT_RECIPIENT_HANGOUTS is not configured,
248 +# notifications won't be send to hangouts rooms. For the example above,
249 +# a valid recipients list is the following
250 +# DEFAULT_RECIPIENT_HANGOUTS="systems development|critical"
251 +DEFAULT_RECIPIENT_HANGOUTS=""
252 +
253 #------------------------------------------------------------------------------
254 # pushover (pushover.net) global notification options
255
@@ -375,10 +398,10 @@ SEND_SLACK="YES"
398 SLACK_WEBHOOK_URL=""
399
400 # if a role's recipients are not configured, a notification will be send to:
378 -# - A slack channel (syntax: '#channel' or 'channel')
401 +# - A slack channel (syntax: '#channel' or 'channel')
402 # - A slack user (syntax: '@user')
403 # - The channel or user defined in slack for the webhook (syntax: '#')
381 -# empty = do not send a notification for unconfigured roles
404 +# empty = do not send a notification for unconfigured roles
405 DEFAULT_RECIPIENT_SLACK=""
406
407 #------------------------------------------------------------------------------
@@ -808,6 +831,8 @@ custom_sender() {
831
832 role_recipients_email[sysadmin]="${DEFAULT_RECIPIENT_EMAIL}"
833
834 +role_recipients_hangouts[sysadmin]="${DEFAULT_RECIPIENT_HANGOUTS}"
835 +
836 role_recipients_pushover[sysadmin]="${DEFAULT_RECIPIENT_PUSHOVER}"
837
838 role_recipients_pushbullet[sysadmin]="${DEFAULT_RECIPIENT_PUSHBULLET}"
@@ -853,6 +878,8 @@ role_recipients_rocketchat[sysadmin]="${DEFAULT_RECIPIENT_ROCKETCHAT}"
878
879 role_recipients_email[domainadmin]="${DEFAULT_RECIPIENT_EMAIL}"
880
881 +role_recipients_hangouts[domainadmin]="${DEFAULT_RECIPIENT_HANGOUTS}"
882 +
883 role_recipients_pushover[domainadmin]="${DEFAULT_RECIPIENT_PUSHOVER}"
884
885 role_recipients_pushbullet[domainadmin]="${DEFAULT_RECIPIENT_PUSHBULLET}"
@@ -901,6 +928,8 @@ role_recipients_sms[domainadmin]="${DEFAULT_RECIPIENT_SMS}"
928
929 role_recipients_email[dba]="${DEFAULT_RECIPIENT_EMAIL}"
930
931 +role_recipients_hangouts[dba]="${DEFAULT_RECIPIENT_HANGOUTS}"
932 +
933 role_recipients_pushover[dba]="${DEFAULT_RECIPIENT_PUSHOVER}"
934
935 role_recipients_pushbullet[dba]="${DEFAULT_RECIPIENT_PUSHBULLET}"
@@ -949,6 +978,8 @@ role_recipients_sms[dba]="${DEFAULT_RECIPIENT_SMS}"
978
979 role_recipients_email[webmaster]="${DEFAULT_RECIPIENT_EMAIL}"
980
981 +role_recipients_hangouts[webmaster]="${DEFAULT_RECIPIENT_HANGOUTS}"
982 +
983 role_recipients_pushover[webmaster]="${DEFAULT_RECIPIENT_PUSHOVER}"
984
985 role_recipients_pushbullet[webmaster]="${DEFAULT_RECIPIENT_PUSHBULLET}"
@@ -997,6 +1028,8 @@ role_recipients_sms[webmaster]="${DEFAULT_RECIPIENT_SMS}"
1028
1029 role_recipients_email[proxyadmin]="${DEFAULT_RECIPIENT_EMAIL}"
1030
1031 +role_recipients_hangouts[proxyadmin]="${DEFAULT_RECIPIENT_HANGOUTS}"
1032 +
1033 role_recipients_pushover[proxyadmin]="${DEFAULT_RECIPIENT_PUSHOVER}"
1034
1035 role_recipients_pushbullet[proxyadmin]="${DEFAULT_RECIPIENT_PUSHBULLET}"
@@ -1046,6 +1079,8 @@ role_recipients_sms[proxyadmin]="${DEFAULT_RECIPIENT_SMS}"
1079
1080 role_recipients_email[sitemgr]="${DEFAULT_RECIPIENT_EMAIL}"
1081
1082 +role_recipients_hangouts[sitemgr]="${DEFAULT_RECIPIENT_HANGOUTS}"
1083 +
1084 role_recipients_pushover[sitemgr]="${DEFAULT_RECIPIENT_PUSHOVER}"
1085
1086 role_recipients_pushbullet[sitemgr]="${DEFAULT_RECIPIENT_PUSHBULLET}"