@cryptotaxi247 / netdata-1 / commits / 1856bbc38

Made requested changes and adjustments. Changed error detection approach.

manosf committed Feb 25, 2018 at 16:21 UTC 1856bbc38558fbfcdf012bf6203de389a6aa71ff
2 files changed +61 -14
conf.d/health_alarm_notify.conf
+45
@@ -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 +# - messages to your irc channel on your selected network
18 #
19 # The 'to' line given at netdata alarms defines a *role*, so that many
20 # people can be notified for each role.
@@ -55,6 +56,10 @@ sendmail=""
56 # If not found, most notifications will be silently disabled.
57 curl=""
58
59 +# The full path of the nc command.
60 +# If empty, the system $PATH will be searched for it.
61 +# If not found, irc notifications will be silently disabled.
62 +nc=""
63
64 #------------------------------------------------------------------------------
65 # NOTE ABOUT RECIPIENTS
@@ -71,6 +76,7 @@ curl=""
76 # - hipchat rooms
77 # - sms phone numbers
78 # - pagerduty.com (pd) services
79 +# - irc channels
80 #
81 # You can append |critical to limit the notifications to be sent.
82 #
@@ -88,6 +94,7 @@ curl=""
94 # messagebird: "+15555555555 +17777777777|critical"
95 # kavenegar : "09155555555 09177777777|critical"
96 # pd : "<pd_service_key_1> <pd_service_key_2>|critical"
97 +# irc : "<irc_channel_1> <irc_channel_2>|critical"
98 #
99 # If a recipient is set to empty string, the default recipient of the given
100 # notification method (email, pushover, telegram, slack, alerta, etc) will be used.
@@ -392,6 +399,34 @@ SEND_PD="YES"
399 DEFAULT_RECIPIENT_PD=""
400
401
402 +#------------------------------------------------------------------------------
403 +# irc notification options
404 +#
405 +# irc notifications require only the nc utility to be installed.
406 +
407 +# multiple recipients can be given like this:
408 +# "<irc_channel_1> <irc_channel_2> ..."
409 +
410 +# enable/disable sending irc notifications
411 +SEND_PD="YES"
412 +
413 +# if a role's recipients are not configured, a notification will not be sent.
414 +# (empty = do not send a notification for unconfigured roles):
415 +DEFAULT_RECIPIENT_IRC=""
416 +
417 +# The irc network to which the recipients belong. It must be the full network.
418 +# e.g. "irc.freenode.net"
419 +IRC_NETWORK=""
420 +
421 +# The irc nickname which is required to send the notification. It must not be
422 +# an already registered name as the connection's MODE is defined as a 'guest'.
423 +IRC_NICKNAME=""
424 +
425 +# The irc realname which is required in order to make the connection and is an
426 +# extra identifier.
427 +IRC_REALNAME=""
428 +
429 +
430 #------------------------------------------------------------------------------
431 # custom notifications
432 #
@@ -487,6 +522,8 @@ role_recipients_kavenegar[sysadmin]="${DEFAULT_RECIPIENT_KAVENEGAR}"
522
523 role_recipients_pd[sysadmin]="${DEFAULT_RECIPIENT_PD}"
524
525 +role_recipients_irc[sysadmin]="${DEFAULT_RECIPIENT_IRC}"
526 +
527 role_recipients_custom[sysadmin]="${DEFAULT_RECIPIENT_CUSTOM}"
528
529 # -----------------------------------------------------------------------------
@@ -518,6 +555,8 @@ role_recipients_kavenegar[domainadmin]="${DEFAULT_RECIPIENT_KAVENEGAR}"
555
556 role_recipients_pd[domainadmin]="${DEFAULT_RECIPIENT_PD}"
557
558 +role_recipients_irc[domainadmin]="${DEFAULT_RECIPIENT_IRC}"
559 +
560 role_recipients_custom[domainadmin]="${DEFAULT_RECIPIENT_CUSTOM}"
561
562 # -----------------------------------------------------------------------------
@@ -550,6 +589,8 @@ role_recipients_kavenegar[dba]="${DEFAULT_RECIPIENT_KAVENEGAR}"
589
590 role_recipients_pd[dba]="${DEFAULT_RECIPIENT_PD}"
591
592 +role_recipients_irc[dba]="${DEFAULT_RECIPIENT_IRC}"
593 +
594 role_recipients_custom[dba]="${DEFAULT_RECIPIENT_CUSTOM}"
595
596 # -----------------------------------------------------------------------------
@@ -582,6 +623,8 @@ role_recipients_kavenegar[webmaster]="${DEFAULT_RECIPIENT_KAVENEGAR}"
623
624 role_recipients_pd[webmaster]="${DEFAULT_RECIPIENT_PD}"
625
626 +role_recipients_irc[webmaster]="${DEFAULT_RECIPIENT_IRC}"
627 +
628 role_recipients_custom[webmaster]="${DEFAULT_RECIPIENT_CUSTOM}"
629
630 # -----------------------------------------------------------------------------
@@ -614,4 +657,6 @@ role_recipients_kavenegar[proxyadmin]="${DEFAULT_RECIPIENT_KAVENEGAR}"
657
658 role_recipients_pd[proxyadmin]="${DEFAULT_RECIPIENT_PD}"
659
660 +role_recipients_irc[proxyadmin]="${DEFAULT_RECIPIENT_IRC}"
661 +
662 role_recipients_custom[proxyadmin]="${DEFAULT_RECIPIENT_CUSTOM}"
plugins.d/alarm-notify.sh
+16 -14
@@ -321,7 +321,7 @@ declare -A role_recipients_email=()
321 IRC_NICKNAME=
322 IRC_REALNAME=
323 DEFAULT_RECIPIENT_IRC=
324 -DEFAULT_IRC_NETWORK="irc.freenode.net"
324 +IRC_NETWORK=
325 declare -A role_recipients_irc=()
326
327 # load the user configuration
@@ -652,7 +652,7 @@ to_irc="${!arr_irc[*]}"
652 [ -z "${KAFKA_URL}" -o -z "${KAFKA_SENDER_IP}" ] && SEND_KAFKA="NO"
653
654 # check irc
655 -[ -z "${DEFAULT_IRC_NETWORK}" -o -z "${DEFAULT_RECIPIENT_IRC}" ] && SEND_IRC="NO"
655 +[ -z "${IRC_NETWORK}" ] && SEND_IRC="NO"
656
657 # check pagerduty.com
658 # if we need pd-send, check for the pd-send command
@@ -682,7 +682,6 @@ if [ \( \
682 -o "${SEND_PUSHBULLET}" = "YES" \
683 -o "${SEND_KAFKA}" = "YES" \
684 -o "${SEND_CUSTOM}" = "YES" \
685 - -o "${SEND_IRC}" = "YES" \
685 \) -a -z "${curl}" ]
686 then
687 curl="$(which curl 2>/dev/null || command -v curl 2>/dev/null)"
@@ -702,7 +701,6 @@ if [ \( \
701 SEND_KAVENEGAR="NO"
702 SEND_KAFKA="NO"
703 SEND_CUSTOM="NO"
705 - SEND_IRC="NO"
704 fi
705 fi
706
@@ -1473,7 +1471,7 @@ EOF
1471 # irc sender
1472
1473 send_irc() {
1476 - local NICKNAME="${1}" REALNAME="${2}" CHANNELS="${3}" NETWORK="${4}" MESSAGE="${5}" httpcode sent=0 channel color
1474 + local NICKNAME="${1}" REALNAME="${2}" CHANNELS="${3}" NETWORK="${4}" MESSAGE="${5}" sent=0 channel color send_alarm reply_codes
1475
1476 case "${status}" in
1477 WARNING) color="warning" ;;
@@ -1486,14 +1484,18 @@ send_irc() {
1484 then
1485 for channel in ${CHANNELS}
1486 do
1489 - sentcheck=$(echo -e "USER ${NICKNAME} guest ${REALNAME} ${SERVERNAME}\nNICK ${NICKNAME}\nJOIN ${CHANNEL}\nPRIVMSG ${CHANNEL}> :${MESSAGE}\nQUIT\n" \ | nc ${NETWORK} 6667)
1490 - if [ $(echo ${sentcheck} | grep --fixed-strings --count ":${nickname} MODE ${nickname} :+i") -gt 0 ]
1491 - then
1492 - info "sent irc notification for: ${host} ${chart}.${name} is ${status} to '${channel}'"
1493 - sent=$((sent + 1))
1494 - else
1495 - error "failed to send irc notification for: ${host} ${chart}.${name} is ${status} to '${channel}', with HTTP error code ${httpcode}."
1496 - fi
1487 + send_alarm=$(echo -e "USER ${NICKNAME} guest ${REALNAME} ${SERVERNAME}\nNICK ${NICKNAME}\nJOIN ${CHANNEL}\nPRIVMSG ${CHANNEL}> :${MESSAGE}\nQUIT\n" \ | nc ${NETWORK} 6667)
1488 + reply_codes=$(echo ${send_alarm} | cut -d ' ' -f 2 | grep -o '[0-9]*')
1489 + for code in ${reply_codes}
1490 + do
1491 + if [ "${code}" -ge 400 -a "${code}" -le 599 ]
1492 + then
1493 + info "sent irc notification for: ${host} ${chart}.${name} is ${status} to '${channel}'"
1494 + sent=$((sent + 1))
1495 + else
1496 + error "failed to send irc notification for: ${host} ${chart}.${name} is ${status} to '${channel}', with error code ${code}."
1497 + fi
1498 + done
1499 done
1500 fi
1501
@@ -1719,7 +1721,7 @@ SENT_PD=$?
1721 # -----------------------------------------------------------------------------
1722 # send the irc message
1723
1722 -send_irc "${IRC_NICKNAME}" "${IRC_REALNAME}" "${to_irc}" "${DEFAULT_IRC_NETWORK}" "${host}" "${host} ${status_message} - ${name//_/ } - ${chart} ----- ${alarm}
1724 +send_irc "${IRC_NICKNAME}" "${IRC_REALNAME}" "${to_irc}" "${IRC_NETWORK}" "${host}" "${host} ${status_message} - ${name//_/ } - ${chart} ----- ${alarm}
1725 Severity: ${severity}
1726 Chart: ${chart}
1727 Family: ${family}