@cryptotaxi247 / netdata-1 / commits / 542bc1e27

Msteams 2 (#9905)

Co-authored-by: luckman212 <luke.hamburg@gmail.com> Co-authored-by: cosmix <cosmix@users.noreply.github.com>

Thomas Bernhart committed Apr 21, 2021 at 11:29 UTC 542bc1e27f2ee93906bcfa42fd7f096b6f556dad
5 files changed +144 -48
health/notifications/Makefile.am
+1
@@ -35,6 +35,7 @@ include hangouts/Makefile.inc
35 include irc/Makefile.inc
36 include kavenegar/Makefile.inc
37 include messagebird/Makefile.inc
38 +include msteams/Makefile.inc
39 include opsgenie/Makefile.inc
40 include pagerduty/Makefile.inc
41 include pushbullet/Makefile.inc
health/notifications/alarm-notify.sh.in
+54 -20
@@ -165,7 +165,7 @@ pd
165 fleep
166 syslog
167 custom
168 -msteam
168 +msteams
169 kavenegar
170 prowl
171 irc
@@ -300,8 +300,11 @@ done
300 # slack configs
301 SLACK_WEBHOOK_URL=
302
303 -# Microsoft Team configs
304 -MSTEAM_WEBHOOK_URL=
303 +# Microsoft Teams configs
304 +MSTEAMS_WEBHOOK_URL=
305 +
306 +# Legacy Microsoft Teams configs for backwards compatability:
307 +declare -A role_recipients_msteam
308
309 # rocketchat configs
310 ROCKETCHAT_WEBHOOK_URL=
@@ -431,6 +434,37 @@ if [ "${use_fqdn}" = "YES" ] && [ "${host}" = "$(hostname -s 2>/dev/null)" ]; th
434 host="$(hostname -f 2>/dev/null)"
435 fi
436
437 +
438 +# -----------------------------------------------------------------------------
439 +# migrate old Microsoft Teams configuration keys after loading configuration
440 +
441 +msteams_migration() {
442 + SEND_MSTEAMS=${SEND_MSTEAM:-$SEND_MSTEAMS}
443 + DEFAULT_RECIPIENT_MSTEAMS=${DEFAULT_RECIPIENT_MSTEAM:-$DEFAULT_RECIPIENT_MSTEAMS}
444 + MSTEAMS_WEBHOOK_URL=${MSTEAM_WEBHOOK_URL:-$MSTEAMS_WEBHOOK_URL}
445 + MSTEAMS_ICON_DEFAULT=${MSTEAM_ICON_DEFAULT:-$MSTEAMS_ICON_DEFAULT}
446 + MSTEAMS_ICON_CLEAR=${MSTEAM_ICON_CLEAR:-$MSTEAMS_ICON_CLEAR}
447 + MSTEAMS_ICON_WARNING=${MSTEAM_ICON_WARNING:-$MSTEAMS_ICON_WARNING}
448 + MSTEAMS_ICON_CRITICAL=${MSTEAM_ICON_CRITICAL:-$MSTEAMS_ICON_CRITICAL}
449 + MSTEAMS_COLOR_DEFAULT=${MSTEAM_COLOR_DEFAULT:-$MSTEAMS_COLOR_DEFAULT}
450 + MSTEAMS_COLOR_CLEAR=${MSTEAM_COLOR_CLEAR:-$MSTEAMS_COLOR_CLEAR}
451 + MSTEAMS_COLOR_WARNING=${MSTEAM_COLOR_WARNING:-$MSTEAMS_COLOR_WARNING}
452 + MSTEAMS_COLOR_CRITICAL=${MSTEAM_COLOR_CRITICAL:-$MSTEAMS_COLOR_CRITICAL}
453 +
454 + # migrate role specific recipients:
455 + for key in "${!role_recipients_msteam[@]}"; do
456 + # Disable check, if role_recipients_msteams is ever used:
457 + # The role_recipients_$method are created and used programmatically
458 + # by iterating over $methods. shellcheck therefore doesn't realize
459 + # that role_recipients_msteams is actually used in the block
460 + # "find the recipients' addresses per method".
461 + # shellcheck disable=SC2034
462 + role_recipients_msteams["$key"]="${role_recipients_msteam["$key"]}"
463 + done
464 +}
465 +
466 +msteams_migration
467 +
468 # -----------------------------------------------------------------------------
469 # filter a recipient based on alarm event severity
470
@@ -553,8 +587,8 @@ filter_recipient_by_criticality() {
587 # check stackpulse
588 [ -z "${STACKPULSE_WEBHOOK}" ] && SEND_STACKPULSE="NO"
589
556 -# check msteam
557 -[ -z "${MSTEAM_WEBHOOK_URL}" ] && SEND_MSTEAM="NO"
590 +# check msteams
591 +[ -z "${MSTEAMS_WEBHOOK_URL}" ] && SEND_MSTEAMS="NO"
592
593 # check pd
594 [ -z "${DEFAULT_RECIPIENT_PD}" ] && SEND_PD="NO"
@@ -581,7 +615,7 @@ if [ "${SEND_PUSHOVER}" = "YES" ] ||
615 [ "${SEND_HANGOUTS}" = "YES" ] ||
616 [ "${SEND_MATRIX}" = "YES" ] ||
617 [ "${SEND_CUSTOM}" = "YES" ] ||
584 - [ "${SEND_MSTEAM}" = "YES" ] ||
618 + [ "${SEND_MSTEAMS}" = "YES" ] ||
619 [ "${SEND_DYNATRACE}" = "YES" ] ||
620 [ "${SEND_STACKPULSE}" = "YES" ] ||
621 [ "${SEND_OPSGENIE}" = "YES" ]; then
@@ -595,7 +629,7 @@ if [ "${SEND_PUSHOVER}" = "YES" ] ||
629 SEND_PUSHBULLET="NO"
630 SEND_TELEGRAM="NO"
631 SEND_SLACK="NO"
598 - SEND_MSTEAM="NO"
632 + SEND_MSTEAMS="NO"
633 SEND_ROCKETCHAT="NO"
634 SEND_ALERTA="NO"
635 SEND_PD="NO"
@@ -750,7 +784,7 @@ for method in "${SEND_EMAIL}" \
784 "${SEND_AWSSNS}" \
785 "${SEND_SYSLOG}" \
786 "${SEND_SMS}" \
753 - "${SEND_MSTEAM}" \
787 + "${SEND_MSTEAMS}" \
788 "${SEND_DYNATRACE}" \
789 "${SEND_STACKPULSE}" \
790 "${SEND_OPSGENIE}" ; do
@@ -1288,22 +1322,22 @@ send_telegram() {
1322 # -----------------------------------------------------------------------------
1323 # Microsoft Team sender
1324
1291 -send_msteam() {
1325 +send_msteams() {
1326
1327 local webhook="${1}" channels="${2}" httpcode sent=0 channel color payload
1328
1295 - [ "${SEND_MSTEAM}" != "YES" ] && return 1
1329 + [ "${SEND_MSTEAMS}" != "YES" ] && return 1
1330
1331 case "${status}" in
1298 - WARNING) icon="${MSTEAM_ICON_WARNING}" && color="${MSTEAM_COLOR_WARNING}" ;;
1299 - CRITICAL) icon="${MSTEAM_ICON_CRITICAL}" && color="${MSTEAM_COLOR_CRITICAL}" ;;
1300 - CLEAR) icon="${MSTEAM_ICON_CLEAR}" && color="${MSTEAM_COLOR_CLEAR}" ;;
1301 - *) icon="${MSTEAM_ICON_DEFAULT}" && color="${MSTEAM_COLOR_DEFAULT}" ;;
1332 + WARNING) icon="${MSTEAMS_ICON_WARNING}" && color="${MSTEAMS_COLOR_WARNING}" ;;
1333 + CRITICAL) icon="${MSTEAMS_ICON_CRITICAL}" && color="${MSTEAMS_COLOR_CRITICAL}" ;;
1334 + CLEAR) icon="${MSTEAMS_ICON_CLEAR}" && color="${MSTEAMS_COLOR_CLEAR}" ;;
1335 + *) icon="${MSTEAMS_ICON_DEFAULT}" && color="${MSTEAMS_COLOR_DEFAULT}" ;;
1336 esac
1337
1338 for channel in ${channels}; do
1339 ## More details are available here regarding the payload syntax options : https://docs.microsoft.com/en-us/outlook/actionable-messages/message-card-reference
1306 - ## Online designer : https://acdesignerbeta.azurewebsites.net/
1340 + ## Online designer : https://adaptivecards.io/designer/
1341 payload="$(
1342 cat <<EOF
1343 {
@@ -2346,13 +2380,13 @@ send_hangouts "${to_hangouts}"
2380 SENT_HANGOUTS=$?
2381
2382 # -----------------------------------------------------------------------------
2349 -# send the Microsoft notification
2383 +# send the Microsoft Teams notification
2384
2351 -# Microsoft team aggregates posts from the same username
2385 +# Microsoft teams aggregates posts from the same username
2386 # so we use "${host} ${status}" as the bot username, to make them diff
2387
2354 -send_msteam "${MSTEAM_WEBHOOK_URL}" "${to_msteam}"
2355 -SENT_MSTEAM=$?
2388 +send_msteams "${MSTEAMS_WEBHOOK_URL}" "${to_msteams}"
2389 +SENT_MSTEAMS=$?
2390
2391 # -----------------------------------------------------------------------------
2392 # send the rocketchat notification
@@ -2769,7 +2803,7 @@ for state in "${SENT_EMAIL}" \
2803 "${SENT_MATRIX}" \
2804 "${SENT_SYSLOG}" \
2805 "${SENT_SMS}" \
2772 - "${SENT_MSTEAM}" \
2806 + "${SENT_MSTEAMS}" \
2807 "${SENT_DYNATRACE}" \
2808 "${SENT_STACKPULSE}" \
2809 "${SENT_OPSGENIE}"; do
health/notifications/health_alarm_notify.conf
+32 -28
@@ -19,7 +19,7 @@
19 # - notifications to Amazon SNS topics (aws.amazon.com)
20 # - messages to your irc channel on your selected network
21 # - messages to a local or remote syslog daemon
22 -# - message to Microsoft Team (through webhook)
22 +# - message to Microsoft Teams (through webhook)
23 # - message to Rocket.Chat (through webhook)
24 # - message to Google Hangouts Chat (through webhook)
25 #
@@ -464,38 +464,42 @@ SLACK_WEBHOOK_URL=""
464 DEFAULT_RECIPIENT_SLACK=""
465
466 #------------------------------------------------------------------------------
467 -# Microsoft Team (office.com) global notification options
468 -# More details are available here regarding the payload syntax options : https://docs.microsoft.com/en-us/outlook/actionable-messages/message-card-reference
469 -# Online designer : https://acdesignerbeta.azurewebsites.net/
467 +# Microsoft Teams (office.com) global notification options
468 +# More details are available here regarding the payload syntax options:
469 +# https://docs.microsoft.com/en-us/outlook/actionable-messages/message-card-reference
470 +# Online designer : https://adaptivecards.io/designer/
471 # multiple recipients can be given like this:
472 # "CHANNEL1 CHANNEL2 ..."
473
473 -# enable/disable sending team notifications
474 -SEND_MSTEAM="YES"
474 +# enable/disable sending teams notifications
475 +SEND_MSTEAMS="YES"
476 +
477 +# In Microsoft Teams the channel name is encoded in the URI after
478 +# .../IncomingWebhook/...
479 +# You have to replace the encoded channel name by the placeholder `CHANNEL`
480 +# in `MSTEAMS_WEBHOOK_URL`. The placeholder `CHANNEL` will be replaced by the
481 +# actual encoded channel name before sending the notification.
482 +MSTEAMS_WEBHOOK_URL=""
483
484 # if a role's recipients are not configured, a notification will be send to
477 -# this slack channel (empty = do not send a notification for unconfigured
485 +# this Teams channel (empty = do not send a notification for unconfigured
486 # roles):
479 -# For team the channel name is encoded in the URI after ....IncomingWebhook/___/.....
480 -# This value will be replaced in the webhook value to publish to several channels in a same Team.
481 -# In order to get it working properly, you have to replace the value between [] ....IncomingWebhook/[___]/..... by "CHANNEL" string.
482 -DEFAULT_RECIPIENT_MSTEAM=""
483 -# Based on the way MS Teams is working, put the different channels here like : "CHANNEL1 CHANNEL2 ..."
487 +# Put the different encoded channel names here like : "CHANNEL1 CHANNEL2 ..."
488 # AT LEAST ONE CHANNEL IS MANDATORY
485 -MSTEAM_WEBHOOK_URL=""
489 +DEFAULT_RECIPIENT_MSTEAMS=""
490
487 -# Define the default color scheme for alert to MS Team - icon and color
491 +# Define the default color scheme for alert to MS Teams - icon and color
492 # Icons - go to https://emojipedia.org/bomb/
489 -MSTEAM_ICON_DEFAULT="♡"
490 -MSTEAM_ICON_CLEAR="💚"
491 -MSTEAM_ICON_WARNING="⚠️"
492 -MSTEAM_ICON_CRITICAL="🔥"
493 +MSTEAMS_ICON_DEFAULT="♡"
494 +MSTEAMS_ICON_CLEAR="💚"
495 +MSTEAMS_ICON_WARNING="⚠️"
496 +MSTEAMS_ICON_CRITICAL="🔥"
497
498 # Colors
495 -MSTEAM_COLOR_DEFAULT="0076D7"
496 -MSTEAM_COLOR_CLEAR="65A677"
497 -MSTEAM_COLOR_WARNING="FFA500"
498 -MSTEAM_COLOR_CRITICAL="D93F3C"
499 +MSTEAMS_COLOR_DEFAULT="0076D7"
500 +MSTEAMS_COLOR_CLEAR="65A677"
501 +MSTEAMS_COLOR_WARNING="FFA500"
502 +MSTEAMS_COLOR_CRITICAL="D93F3C"
503
504
505 #------------------------------------------------------------------------------
@@ -955,7 +959,7 @@ role_recipients_awssns[sysadmin]="${DEFAULT_RECIPIENT_AWSSNS}"
959
960 role_recipients_custom[sysadmin]="${DEFAULT_RECIPIENT_CUSTOM}"
961
958 -role_recipients_msteam[sysadmin]="${DEFAULT_RECIPIENT_MSTEAM}"
962 +role_recipients_msteams[sysadmin]="${DEFAULT_RECIPIENT_MSTEAMS}"
963
964 role_recipients_rocketchat[sysadmin]="${DEFAULT_RECIPIENT_ROCKETCHAT}"
965
@@ -1010,7 +1014,7 @@ role_recipients_awssns[domainadmin]="${DEFAULT_RECIPIENT_AWSSNS}"
1014
1015 role_recipients_custom[domainadmin]="${DEFAULT_RECIPIENT_CUSTOM}"
1016
1013 -role_recipients_msteam[domainadmin]="${DEFAULT_RECIPIENT_MSTEAM}"
1017 +role_recipients_msteams[domainadmin]="${DEFAULT_RECIPIENT_MSTEAMS}"
1018
1019 role_recipients_rocketchat[domainadmin]="${DEFAULT_RECIPIENT_ROCKETCHAT}"
1020
@@ -1068,7 +1072,7 @@ role_recipients_awssns[dba]="${DEFAULT_RECIPIENT_AWSSNS}"
1072
1073 role_recipients_custom[dba]="${DEFAULT_RECIPIENT_CUSTOM}"
1074
1071 -role_recipients_msteam[dba]="${DEFAULT_RECIPIENT_MSTEAM}"
1075 +role_recipients_msteams[dba]="${DEFAULT_RECIPIENT_MSTEAMS}"
1076
1077 role_recipients_rocketchat[dba]="${DEFAULT_RECIPIENT_ROCKETCHAT}"
1078
@@ -1126,7 +1130,7 @@ role_recipients_awssns[webmaster]="${DEFAULT_RECIPIENT_AWSSNS}"
1130
1131 role_recipients_custom[webmaster]="${DEFAULT_RECIPIENT_CUSTOM}"
1132
1129 -role_recipients_msteam[webmaster]="${DEFAULT_RECIPIENT_MSTEAM}"
1133 +role_recipients_msteams[webmaster]="${DEFAULT_RECIPIENT_MSTEAMS}"
1134
1135 role_recipients_rocketchat[webmaster]="${DEFAULT_RECIPIENT_ROCKETCHAT}"
1136
@@ -1184,7 +1188,7 @@ role_recipients_awssns[proxyadmin]="${DEFAULT_RECIPIENT_AWSSNS}"
1188
1189 role_recipients_custom[proxyadmin]="${DEFAULT_RECIPIENT_CUSTOM}"
1190
1187 -role_recipients_msteam[proxyadmin]="${DEFAULT_RECIPIENT_MSTEAM}"
1191 +role_recipients_msteams[proxyadmin]="${DEFAULT_RECIPIENT_MSTEAMS}"
1192
1193 role_recipients_rocketchat[proxyadmin]="${DEFAULT_RECIPIENT_ROCKETCHAT}"
1194
@@ -1240,7 +1244,7 @@ role_recipients_awssns[sitemgr]="${DEFAULT_RECIPIENT_AWSSNS}"
1244
1245 role_recipients_custom[sitemgr]="${DEFAULT_RECIPIENT_CUSTOM}"
1246
1243 -role_recipients_msteam[sitemgr]="${DEFAULT_RECIPIENT_MSTEAM}"
1247 +role_recipients_msteams[sitemgr]="${DEFAULT_RECIPIENT_MSTEAMS}"
1248
1249 role_recipients_rocketchat[sitemgr]="${DEFAULT_RECIPIENT_ROCKETCHAT}"
1250
health/notifications/msteams/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 + msteams/README.md \
10 + msteams/Makefile.inc \
11 + $(NULL)
12 +
health/notifications/msteams/README.md new
+45
@@ -0,0 +1,45 @@
1 +<!--
2 +---
3 +title: "Microsoft Teams"
4 +custom_edit_url: https://github.com/netdata/netdata/edit/master/health/notifications/msteams/README.md
5 +---
6 +-->
7 +
8 +# Microsoft Teams
9 +
10 +This is what you will get:
11 +![image](https://user-images.githubusercontent.com/1122372/92710359-0385e680-f358-11ea-8c52-f366a4fb57dd.png)
12 +
13 +You need:
14 +
15 +1. The **incoming webhook URL** as given by Microsoft Teams. You can use the same on all your Netdata servers (or you can have multiple if you like - your decision).
16 +2. One or more channels to post the messages to.
17 +
18 +In Microsoft Teams the channel name is encoded in the URI after `/IncomingWebhook/` (for clarity the marked with `[]` in the following example): `https://outlook.office.com/webhook/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX@XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX/IncomingWebhook/[XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX]/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX`
19 +
20 +You have to replace the encoded channel name by the placeholder `CHANNEL` in `MSTEAMS_WEBHOOK_URL`. The placeholder `CHANNEL` will be replaced by the actual encoded channel name before sending the notification. This makes it possible to publish to several channels in the same team.
21 +
22 +The encoded channel name must then be added to `DEFAULT_RECIPIENTS_MSTEAMS` or to one of the specific variables `role_recipients_msteams[]`. **At least one channel is mandatory for `DEFAULT_RECIPIENTS_MSTEAMS`.**
23 +
24 +Set the webhook and the recipients in `/etc/netdata/health_alarm_notify.conf` (to edit it on your system run `/etc/netdata/edit-config health_alarm_notify.conf`), like this:
25 +
26 +```
27 +SEND_MSTEAMS="YES"
28 +
29 +MSTEAMS_WEBHOOK_URL="https://outlook.office.com/webhook/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX@XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX/IncomingWebhook/CHANNEL/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"
30 +
31 +DEFAULT_RECIPIENT_MSTEAMS="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
32 +```
33 +
34 +You can define multiple recipients by listing the encoded channel names like this: `XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY`.
35 +This example will send the alarm to the two channels specified by their encoded channel names.
36 +
37 +You can give different recipients per **role** using these (in the same file):
38 +
39 +```
40 +role_recipients_msteams[sysadmin]="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
41 +role_recipients_msteams[dba]="YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY"
42 +role_recipients_msteams[webmaster]="ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ"
43 +```
44 +
45 +[![analytics](https://www.google-analytics.com/collect?v=1&aip=1&t=pageview&_s=1&ds=github&dr=https%3A%2F%2Fgithub.com%2Fnetdata%2Fnetdata&dl=https%3A%2F%2Fmy-netdata.io%2Fgithub%2Fhealth%2Fnotifications%2Fmsteams%2FREADME&_u=MAC~&cid=5792dfd7-8dc4-476b-af31-da2fdb9f93d2&tid=UA-64295674-3)](<>)