@cryptotaxi247 / netdata-1 / commits / 68c24f11a

added support for flock notification webhooks

Gustav Føsker committed Nov 2, 2017 at 11:59 UTC 68c24f11ae6a93fa9c6c5ac3138cb8b4070b2b36
2 files changed +124 -1
conf.d/health_alarm_notify.conf
+34 -1
@@ -7,6 +7,7 @@
7 # - e-mails (using the sendmail command),
8 # - push notifications to your mobile phone (pushover.net),
9 # - messages to your slack team (slack.com),
10 +# - messages to your flock team (flock.com),
11 # - messages to your discord guild (discordapp.com),
12 # - messages to your telegram chat / group chat (telegram.org)
13 # - sms messages to your cell phone or any sms enabled device (twilio.com)
@@ -23,7 +24,7 @@
24 # proxy configuration
25 #
26 # If you need to send curl based notifications (pushover, pushbullet, slack,
26 -# discord, telegram) via a proxy, set these to your proxy address:
27 +# flock, discord, telegram) via a proxy, set these to your proxy address:
28 #export http_proxy="http://10.0.0.1:3128/"
29 #export https_proxy="http://10.0.0.1:3128/"
30
@@ -63,6 +64,7 @@ curl=""
64 # - pushover user tokens
65 # - telegram chat ids
66 # - slack channels
67 +# - flock rooms
68 # - discord channels
69 # - hipchat rooms
70 # - sms phone numbers
@@ -77,6 +79,7 @@ curl=""
79 # pushover : "2987343...9437837 8756278...2362736|critical"
80 # telegram : "111827421 112746832|critical"
81 # slack : "alarms disasters|critical"
82 +# flock : "alarms disasters|critical"
83 # discord : "alarms disasters|critical"
84 # twilio : "+15555555555 +17777777777|critical"
85 # messagebird: "+15555555555 +17777777777|critical"
@@ -272,6 +275,26 @@ SLACK_WEBHOOK_URL=""
275 DEFAULT_RECIPIENT_SLACK=""
276
277
278 +#------------------------------------------------------------------------------
279 +# flock (flock.com) global notification options
280 +
281 +# multiple recipients can be given like this:
282 +# "CHANNEL1 CHANNEL2 ..."
283 +
284 +# enable/disable sending flock notifications
285 +SEND_FLOCK="YES"
286 +
287 +# Login to flock.com and create an incoming webhook. You need only one for all
288 +# your netdata servers (or you can have one for each of your netdata).
289 +# Without it, netdata cannot send flock notifications.
290 +FLOCK_WEBHOOK_URL=""
291 +
292 +# if a role's recipients are not configured, a notification will be send to
293 +# this flock channel (empty = do not send a notification for unconfigured
294 +# roles):
295 +DEFAULT_RECIPIENT_FLOCK=""
296 +
297 +
298 #------------------------------------------------------------------------------
299 # discord (discordapp.com) global notification options
300
@@ -424,6 +447,8 @@ role_recipients_telegram[sysadmin]="${DEFAULT_RECIPIENT_TELEGRAM}"
447
448 role_recipients_slack[sysadmin]="${DEFAULT_RECIPIENT_SLACK}"
449
450 +role_recipients_flock[sysadmin]="${DEFAULT_RECIPIENT_FLOCK}"
451 +
452 role_recipients_discord[sysadmin]="${DEFAULT_RECIPIENT_DISCORD}"
453
454 role_recipients_hipchat[sysadmin]="${DEFAULT_RECIPIENT_HIPCHAT}"
@@ -451,6 +476,8 @@ role_recipients_telegram[domainadmin]="${DEFAULT_RECIPIENT_TELEGRAM}"
476
477 role_recipients_slack[domainadmin]="${DEFAULT_RECIPIENT_SLACK}"
478
479 +role_recipients_flock[domainadmin]="${DEFAULT_RECIPIENT_FLOCK}"
480 +
481 role_recipients_discord[domainadmin]="${DEFAULT_RECIPIENT_DISCORD}"
482
483 role_recipients_hipchat[domainadmin]="${DEFAULT_RECIPIENT_HIPCHAT}"
@@ -479,6 +506,8 @@ role_recipients_telegram[dba]="${DEFAULT_RECIPIENT_TELEGRAM}"
506
507 role_recipients_slack[dba]="${DEFAULT_RECIPIENT_SLACK}"
508
509 +role_recipients_flock[dba]="${DEFAULT_RECIPIENT_FLOCK}"
510 +
511 role_recipients_discord[dba]="${DEFAULT_RECIPIENT_DISCORD}"
512
513 role_recipients_hipchat[dba]="${DEFAULT_RECIPIENT_HIPCHAT}"
@@ -507,6 +536,8 @@ role_recipients_telegram[webmaster]="${DEFAULT_RECIPIENT_TELEGRAM}"
536
537 role_recipients_slack[webmaster]="${DEFAULT_RECIPIENT_SLACK}"
538
539 +role_recipients_flock[webmaster]="${DEFAULT_RECIPIENT_FLOCK}"
540 +
541 role_recipients_discord[webmaster]="${DEFAULT_RECIPIENT_DISCORD}"
542
543 role_recipients_hipchat[webmaster]="${DEFAULT_RECIPIENT_HIPCHAT}"
@@ -535,6 +566,8 @@ role_recipients_telegram[proxyadmin]="${DEFAULT_RECIPIENT_TELEGRAM}"
566
567 role_recipients_slack[proxyadmin]="${DEFAULT_RECIPIENT_SLACK}"
568
569 +role_recipients_flock[proxyadmin]="${DEFAULT_RECIPIENT_FLOCK}"
570 +
571 role_recipients_discord[proxyadmin]="${DEFAULT_RECIPIENT_DISCORD}"
572
573 role_recipients_hipchat[proxyadmin]="${DEFAULT_RECIPIENT_HIPCHAT}"
plugins.d/alarm-notify.sh
+90
@@ -219,6 +219,7 @@ sendmail=
219
220 # enable / disable features
221 SEND_SLACK="YES"
222 +SEND_FLOCK="YES"
223 SEND_DISCORD="YES"
224 SEND_PUSHOVER="YES"
225 SEND_TWILIO="YES"
@@ -237,6 +238,11 @@ SLACK_WEBHOOK_URL=
238 DEFAULT_RECIPIENT_SLACK=
239 declare -A role_recipients_slack=()
240
241 +# flock configs
242 +FLOCK_WEBHOOK_URL=
243 +DEFAULT_RECIPIENT_FLOCK=
244 +declare -A role_recipients_flock=()
245 +
246 # discord configs
247 DISCORD_WEBHOOK_URL=
248 DEFAULT_RECIPIENT_DISCORD=
@@ -380,6 +386,7 @@ filter_recipient_by_criticality() {
386 # find the recipients' addresses per method
387
388 declare -A arr_slack=()
389 +declare -A arr_flock=()
390 declare -A arr_discord=()
391 declare -A arr_pushover=()
392 declare -A arr_pushbullet=()
@@ -472,6 +479,14 @@ do
479 [ "${r}" != "disabled" ] && filter_recipient_by_criticality slack "${r}" && arr_slack[${r/|*/}]="1"
480 done
481
482 + # flock
483 + a="${role_recipients_flock[${x}]}"
484 + [ -z "${a}" ] && a="${DEFAULT_RECIPIENT_FLOCK}"
485 + for r in ${a//,/ }
486 + do
487 + [ "${r}" != "disabled" ] && filter_recipient_by_criticality flock "${r}" && arr_flock[${r/|*/}]="1"
488 + done
489 +
490 # discord
491 a="${role_recipients_discord[${x}]}"
492 [ -z "${a}" ] && a="${DEFAULT_RECIPIENT_DISCORD}"
@@ -502,6 +517,10 @@ done
517 to_slack="${!arr_slack[*]}"
518 [ -z "${to_slack}" ] && SEND_SLACK="NO"
519
520 +# build the list of flock recipients (channels)
521 +to_flock="${!arr_flock[*]}"
522 +[ -z "${to_flock}" ] && SEND_FLOCK="NO"
523 +
524 # build the list of discord recipients (channels)
525 to_discord="${!arr_discord[*]}"
526 [ -z "${to_discord}" ] && SEND_DISCORD="NO"
@@ -558,6 +577,9 @@ done
577 # check slack
578 [ -z "${SLACK_WEBHOOK_URL}" ] && SEND_SLACK="NO"
579
580 +# check flock
581 +[ -z "${FLOCK_WEBHOOK_URL}" ] && SEND_FLOCK="NO"
582 +
583 # check discord
584 [ -z "${DISCORD_WEBHOOK_URL}" ] && SEND_DISCORD="NO"
585
@@ -602,6 +624,7 @@ fi
624 if [ \( \
625 "${SEND_PUSHOVER}" = "YES" \
626 -o "${SEND_SLACK}" = "YES" \
627 + -o "${SEND_FLOCK}" = "YES" \
628 -o "${SEND_DISCORD}" = "YES" \
629 -o "${SEND_HIPCHAT}" = "YES" \
630 -o "${SEND_TWILIO}" = "YES" \
@@ -621,6 +644,7 @@ if [ \( \
644 SEND_PUSHBULLET="NO"
645 SEND_TELEGRAM="NO"
646 SEND_SLACK="NO"
647 + SEND_FLOCK="NO"
648 SEND_DISCORD="NO"
649 SEND_TWILIO="NO"
650 SEND_HIPCHAT="NO"
@@ -647,6 +671,7 @@ if [ "${SEND_EMAIL}" != "YES" \
671 -a "${SEND_PUSHOVER}" != "YES" \
672 -a "${SEND_TELEGRAM}" != "YES" \
673 -a "${SEND_SLACK}" != "YES" \
674 + -a "${SEND_FLOCK}" != "YES" \
675 -a "${SEND_DISCORD}" != "YES" \
676 -a "${SEND_TWILIO}" != "YES" \
677 -a "${SEND_HIPCHAT}" != "YES" \
@@ -1222,6 +1247,61 @@ EOF
1247 return 1
1248 }
1249
1250 +# -----------------------------------------------------------------------------
1251 +# flock sender
1252 +
1253 +send_flock() {
1254 + local webhook="${1}" channels="${2}" httpcode sent=0 channel color payload
1255 +
1256 + [ "${SEND_FLOCK}" != "YES" ] && return 1
1257 +
1258 + case "${status}" in
1259 + WARNING) color="warning" ;;
1260 + CRITICAL) color="danger" ;;
1261 + CLEAR) color="good" ;;
1262 + *) color="#777777" ;;
1263 + esac
1264 +
1265 + for channel in ${channels}
1266 + do
1267 + httpcode=$(docurl -X POST "${webhook}" -H "Content-Type: application/json" -d "{
1268 + \"sendAs\": {
1269 + \"name\" : \"netdata on ${host}\",
1270 + \"profileImage\" : \"${images_base_url}/images/seo-performance-128.png\"
1271 + },
1272 + \"text\": \"${host} *${status_message}*\",
1273 + \"timestamp\": \"${when}\",
1274 + \"attachments\": [
1275 + {
1276 + \"description\": \"${chart} (${family}) - ${info}\",
1277 + \"color\": \"${color}\",
1278 + \"title\": \"${alarm}\",
1279 + \"url\": \"${goto_url}\",
1280 + \"text\": \"${info}\",
1281 + \"views\": {
1282 + \"image\": {
1283 + \"original\": { \"src\": \"${image}\", \"width\": 400, \"height\": 400 },
1284 + \"thumbnail\": { \"src\": \"${image}\", \"width\": 50, \"height\": 50 },
1285 + \"filename\": \"${image}\"
1286 + }
1287 + }
1288 + }
1289 + ]
1290 + }" )
1291 + if [ "${httpcode}" = "200" ]
1292 + then
1293 + info "sent flock notification for: ${host} ${chart}.${name} is ${status} to '${channel}'"
1294 + sent=$((sent + 1))
1295 + else
1296 + error "failed to send flock notification for: ${host} ${chart}.${name} is ${status} to '${channel}', with HTTP error code ${httpcode}."
1297 + fi
1298 + done
1299 +
1300 + [ ${sent} -gt 0 ] && return 0
1301 +
1302 + return 1
1303 +}
1304 +
1305 # -----------------------------------------------------------------------------
1306 # discord sender
1307
@@ -1385,6 +1465,15 @@ raised_for_html=
1465 send_slack "${SLACK_WEBHOOK_URL}" "${to_slack}"
1466 SENT_SLACK=$?
1467
1468 +# -----------------------------------------------------------------------------
1469 +# send the flock notification
1470 +
1471 +# flock aggregates posts from the same username
1472 +# so we use "${host} ${status}" as the bot username, to make them diff
1473 +
1474 +send_flock "${FLOCK_WEBHOOK_URL}" "${to_flock}"
1475 +SENT_FLOCK=$?
1476 +
1477 # -----------------------------------------------------------------------------
1478 # send the discord notification
1479
@@ -1644,6 +1733,7 @@ if [ ${SENT_EMAIL} -eq 0 \
1733 -o ${SENT_PUSHOVER} -eq 0 \
1734 -o ${SENT_TELEGRAM} -eq 0 \
1735 -o ${SENT_SLACK} -eq 0 \
1736 + -o ${SENT_FLOCK} -eq 0 \
1737 -o ${SENT_DISCORD} -eq 0 \
1738 -o ${SENT_TWILIO} -eq 0 \
1739 -o ${SENT_HIPCHAT} -eq 0 \