@cryptotaxi247 / netdata-1 / commits / 01473065b

Adding suggested modifications from PR #3903

Guillaume Hospital committed Jul 3, 2018 at 13:49 UTC 01473065b2eea8bfcd6cf2a42e4088852fcd7e9d
3 files changed +61 -41
CONTRIBUTORS.md
+1
@@ -88,3 +88,4 @@ username|name|email (optional)
88 @davidak|David Kleuker|netdata-contributors+vyff@davidak.de
89 @ccremer|Christian Cremer|
90 @jimcooley|Jim Cooley|jim.cooley@healthvana.com
91 +@tioumen|Guillaume Hospital
conf.d/health_alarm_notify.conf
+25 -11
@@ -16,7 +16,7 @@
16 # - notifications to users on pagerduty.com
17 # - messages to your irc channel on your selected network
18 # - messages to a local or remote syslog daemon
19 -# - message to Microsoft Team (through webhook)
19 +# - message to Microsoft Team (thru webhook)
20 #
21 # The 'to' line given at netdata alarms defines a *role*, so that many
22 # people can be notified for each role.
@@ -334,22 +334,36 @@ SLACK_WEBHOOK_URL=""
334 DEFAULT_RECIPIENT_SLACK=""
335
336 #------------------------------------------------------------------------------
337 -# MS Team (teams.com) global notification options
337 +# Microsoft Team (office.com) global notification options
338 # More details are available here regarding the payload syntax options : https://docs.microsoft.com/en-us/outlook/actionable-messages/message-card-reference
339 # Online designer : https://acdesignerbeta.azurewebsites.net/
340 # multiple recipients can be given like this:
341 # "CHANNEL1 CHANNEL2 ..."
342
343 # enable/disable sending team notifications
344 -SEND_TEAM="YES"
344 +SEND_MSTEAM="YES"
345
346 -TEAM_WEBHOOK_URL=""
346 +MSTEAM_WEBHOOK_URL=""
347
348 # if a role's recipients are not configured, a notification will be send to
349 # this slack channel (empty = do not send a notification for unconfigured
350 # roles):
351 # For team the channel name is encoded in the URI after ....IncomingWebhook/___/.....
352 -DEFAULT_RECIPIENT_TEAM=""
352 +DEFAULT_RECIPIENT_MSTEAM=""
353 +
354 +# Define the default color scheme for alert to MS Team - icon and color
355 +# Icons - go to https://emojipedia.org/bomb/
356 +MSTEAM_ICON_DEFAULT="♡"
357 +MSTEAM_ICON_CLEAR="💚"
358 +MSTEAM_ICON_WARNING="⚠️"
359 +MSTEAM_ICON_CRITICAL="🔥"
360 +
361 +# Colors
362 +MSTEAM_COLOR_DEFAULT="0076D7"
363 +MSTEAM_COLOR_CLEAR="65A677"
364 +MSTEAM_COLOR_WARNING="FFA500"
365 +MSTEAM_COLOR_CRITICAL="D93F3C"
366 +
367
368 #------------------------------------------------------------------------------
369 # rocketchat (rocket.chat) global notification options
@@ -704,7 +718,7 @@ role_recipients_syslog[sysadmin]="${DEFAULT_RECIPIENT_SYSLOG}"
718
719 role_recipients_custom[sysadmin]="${DEFAULT_RECIPIENT_CUSTOM}"
720
707 -role_recipients_team[sysadmin]="${DEFAULT_RECIPIENT_TEAM}"
721 +role_recipients_msteam[sysadmin]="${DEFAULT_RECIPIENT_MSTEAM}"
722
723 # -----------------------------------------------------------------------------
724 # DNS related alarms
@@ -743,7 +757,7 @@ role_recipients_syslog[domainadmin]="${DEFAULT_RECIPIENT_SYSLOG}"
757
758 role_recipients_custom[domainadmin]="${DEFAULT_RECIPIENT_CUSTOM}"
759
746 -role_recipients_team[domainadmin]="${DEFAULT_RECIPIENT_TEAM}"
760 +role_recipients_msteam[domainadmin]="${DEFAULT_RECIPIENT_MSTEAM}"
761
762 # -----------------------------------------------------------------------------
763 # database servers alarms
@@ -783,7 +797,7 @@ role_recipients_syslog[dba]="${DEFAULT_RECIPIENT_SYSLOG}"
797
798 role_recipients_custom[dba]="${DEFAULT_RECIPIENT_CUSTOM}"
799
786 -role_recipients_team[dba]="${DEFAULT_RECIPIENT_TEAM}"
800 +role_recipients_msteam[dba]="${DEFAULT_RECIPIENT_MSTEAM}"
801
802 # -----------------------------------------------------------------------------
803 # web servers alarms
@@ -823,7 +837,7 @@ role_recipients_syslog[webmaster]="${DEFAULT_RECIPIENT_SYSLOG}"
837
838 role_recipients_custom[webmaster]="${DEFAULT_RECIPIENT_CUSTOM}"
839
826 -role_recipients_team[webmaster]="${DEFAULT_RECIPIENT_TEAM}"
840 +role_recipients_msteam[webmaster]="${DEFAULT_RECIPIENT_MSTEAM}"
841
842 # -----------------------------------------------------------------------------
843 # proxy servers alarms
@@ -863,7 +877,7 @@ role_recipients_syslog[proxyadmin]="${DEFAULT_RECIPIENT_SYSLOG}"
877
878 role_recipients_custom[proxyadmin]="${DEFAULT_RECIPIENT_CUSTOM}"
879
866 -role_recipients_team[proxyadmin]="${DEFAULT_RECIPIENT_TEAM}"
880 +role_recipients_msteam[proxyadmin]="${DEFAULT_RECIPIENT_MSTEAM}"
881
882 # -----------------------------------------------------------------------------
883 # peripheral devices
@@ -901,4 +915,4 @@ role_recipients_syslog[sitemgr]="${DEFAULT_RECIPIENT_SYSLOG}"
915
916 role_recipients_custom[sitemgr]="${DEFAULT_RECIPIENT_CUSTOM}"
917
904 -role_recipients_team[sitemgr]="${DEFAULT_RECIPIENT_TEAM}"
\ No newline at end of file
918 +role_recipients_msteam[sitemgr]="${DEFAULT_RECIPIENT_MSTEAM}"
\ No newline at end of file
plugins.d/alarm-notify.sh
+35 -30
@@ -29,11 +29,15 @@
29 # - fleep notifications by @Ferroin
30 # - custom notifications by @ktsaou
31 # - syslog messages by @Ferroin
32 -# - MS Team notification @tioumen @Michelin
32 +# - Microsoft Team notification by @tioumen
33
34 # -----------------------------------------------------------------------------
35 # testing notifications
36
37 +export PATH="/opt/netdata/bin:${PATH}"
38 +export NETDATA_ALARM_NOTIFY_DEBUG=1
39 +
40 +
41 if [ \( "${1}" = "test" -o "${2}" = "test" \) -a "${#}" -le 2 ]
42 then
43 if [ "${2}" = "test" ]
@@ -228,7 +232,7 @@ sendmail=
232
233 # enable / disable features
234 SEND_SLACK="YES"
231 -SEND_TEAM="YES"
235 +SEND_MSTEAM="YES"
236 SEND_ALERTA="YES"
237 SEND_FLOCK="YES"
238 SEND_DISCORD="YES"
@@ -253,9 +257,9 @@ DEFAULT_RECIPIENT_SLACK=
257 declare -A role_recipients_slack=()
258
259 # Microsoft Team configs
256 -TEAM_WEBHOOK_URL=
257 -DEFAULT_RECIPIENT_TEAM=
258 -declare -A role_recipients_team=()
260 +MSTEAM_WEBHOOK_URL=
261 +DEFAULT_RECIPIENT_MSTEAM=
262 +declare -A role_recipients_msteam=()
263
264 # rocketchat configs
265 ROCKETCHAT_WEBHOOK_URL=
@@ -433,7 +437,7 @@ filter_recipient_by_criticality() {
437 # find the recipients' addresses per method
438
439 declare -A arr_slack=()
436 -declare -A arr_team=()
440 +declare -A arr_msteam=()
441 declare -A arr_rocketchat=()
442 declare -A arr_alerta=()
443 declare -A arr_flock=()
@@ -532,12 +536,12 @@ do
536 [ "${r}" != "disabled" ] && filter_recipient_by_criticality slack "${r}" && arr_slack[${r/|*/}]="1"
537 done
538
535 - # Team
536 - a="${role_recipients_team[${x}]}"
537 - [ -z "${a}" ] && a="${DEFAULT_RECIPIENT_TEAM}"
539 + # Microsoft Team
540 + a="${role_recipients_msteam[${x}]}"
541 + [ -z "${a}" ] && a="${DEFAULT_RECIPIENT_MSTEAM}"
542 for r in ${a//,/ }
543 do
540 - [ "${r}" != "disabled" ] && filter_recipient_by_criticality team "${r}" && arr_team[${r/|*/}]="1"
544 + [ "${r}" != "disabled" ] && filter_recipient_by_criticality msteam "${r}" && arr_msteam[${r/|*/}]="1"
545 done
546
547 # rocketchat
@@ -618,9 +622,9 @@ done
622 to_slack="${!arr_slack[*]}"
623 [ -z "${to_slack}" ] && SEND_SLACK="NO"
624
621 -# build the list of team recipients (channels)
622 -to_team="${!arr_team[*]}"
623 -[ -z "${to_team}" ] && SEND_TEAM="NO"
625 +# build the list of Microsoft team recipients (channels)
626 +to_msteam="${!arr_msteam[*]}"
627 +[ -z "${to_msteam}" ] && SEND_MSTEAM="NO"
628
629 # build the list of rocketchat recipients (channels)
630 to_rocketchat="${!arr_rocketchat[*]}"
@@ -773,7 +777,7 @@ if [ \( \
777 -o "${SEND_KAFKA}" = "YES" \
778 -o "${SEND_FLEEP}" = "YES" \
779 -o "${SEND_CUSTOM}" = "YES" \
776 - -o "${SEND_TEAM}" = "YES" \
780 + -o "${SEND_MSTEAM}" = "YES" \
781 \) -a -z "${curl}" ]
782 then
783 curl="$(which curl 2>/dev/null || command -v curl 2>/dev/null)"
@@ -784,7 +788,7 @@ if [ \( \
788 SEND_PUSHBULLET="NO"
789 SEND_TELEGRAM="NO"
790 SEND_SLACK="NO"
787 - SEND_TEAM="NO"
791 + SEND_MSTEAM="NO"
792 SEND_ROCKETCHAT="NO"
793 SEND_ALERTA="NO"
794 SEND_FLOCK="NO"
@@ -841,6 +845,7 @@ if [ "${SEND_EMAIL}" != "YES" \
845 -a "${SEND_CUSTOM}" != "YES" \
846 -a "${SEND_IRC}" != "YES" \
847 -a "${SEND_SYSLOG}" != "YES" \
848 + -a "${SEND_MSTEAM}" != "YES" \
849 ]
850 then
851 fatal "All notification methods are disabled. Not sending notification for host '${host}', chart '${chart}' to '${roles}' for '${name}' = '${value}' for status '${status}'."
@@ -1361,19 +1366,19 @@ send_telegram() {
1366 }
1367
1368 # -----------------------------------------------------------------------------
1364 -# Team sender
1369 +# Microsoft Team sender
1370
1366 -send_team() {
1367 -echo "entering in send_team function"
1371 +send_msteam() {
1372 +echo "entering in send_msteam function"
1373 local webhook="${1}" channels="${2}" httpcode sent=0 channel color payload
1374
1370 - [ "${SEND_TEAM}" != "YES" ] && return 1
1375 + [ "${SEND_MSTEAM}" != "YES" ] && return 1
1376
1377 case "${status}" in
1373 - WARNING) icon="⚠️" && color="FFA500";;
1374 - CRITICAL) icon="🔥" && color="D93F3C";;
1375 - CLEAR) icon="💚" && color="65A677";;
1376 - *) icon="♡" && color="0076D7";;
1378 + WARNING) icon="${MSTEAM_ICON_WARNING}" && color="${MSTEAM_COLOR_WARNING}";;
1379 + CRITICAL) icon="${MSTEAM_ICON_CRITICAL}" && color="${MSTEAM_COLOR_CRITICAL}";;
1380 + CLEAR) icon="${MSTEAM_ICON_CLEAR}" && color="${MSTEAM_COLOR_CLEAR}";;
1381 + *) icon="${MSTEAM_ICON_DEFAULT}" && color="${MSTEAM_COLOR_DEFAULT}";;
1382 esac
1383
1384 for channels in ${channels}
@@ -1411,10 +1416,10 @@ EOF
1416
1417 if [ "${httpcode}" = "200" ]
1418 then
1414 - info "sent team notification for: ${host} ${chart}.${name} is ${status} to '${webhook}'"
1419 + info "sent Microsoft team notification for: ${host} ${chart}.${name} is ${status} to '${webhook}'"
1420 sent=$((sent + 1))
1421 else
1417 - error "failed to send team notification for: ${host} ${chart}.${name} is ${status} to '${webhook}', with HTTP error code ${httpcode}."
1422 + error "failed to send Microsoft team notification for: ${host} ${chart}.${name} is ${status} to '${webhook}', with HTTP error code ${httpcode}."
1423 fi
1424 done
1425
@@ -1960,13 +1965,13 @@ send_slack "${SLACK_WEBHOOK_URL}" "${to_slack}"
1965 SENT_SLACK=$?
1966
1967 # -----------------------------------------------------------------------------
1963 -# send the team notification
1968 +# send the Microsoft notification
1969
1965 -# team aggregates posts from the same username
1970 +# Microsoft team aggregates posts from the same username
1971 # so we use "${host} ${status}" as the bot username, to make them diff
1972
1968 -send_team "${TEAM_WEBHOOK_URL}" "${to_team}"
1969 -SENT_TEAM=$?
1973 +send_msteam "${MSTEAM_WEBHOOK_URL}" "${to_msteam}"
1974 +SENT_MSTEAM=$?
1975
1976 # -----------------------------------------------------------------------------
1977 # send the rocketchat notification
@@ -2279,7 +2284,7 @@ if [ ${SENT_EMAIL} -eq 0 \
2284 -o ${SENT_PUSHOVER} -eq 0 \
2285 -o ${SENT_TELEGRAM} -eq 0 \
2286 -o ${SENT_SLACK} -eq 0 \
2282 - -o ${SENT_TEAM} -eq 0 \
2287 + -o ${SENT_MSTEAM} -eq 0 \
2288 -o ${SENT_ROCKETCHAT} -eq 0 \
2289 -o ${SENT_ALERTA} -eq 0 \
2290 -o ${SENT_FLOCK} -eq 0 \