]> arthur.barton.de Git - netdata.git/blobdiff - plugins.d/alarm-notify.sh
hipchat: detect html messages
[netdata.git] / plugins.d / alarm-notify.sh
index b54fd556bedd80d3db245be5e8c66433fdf7006a..87ba84d3d8a9ed9725c04e235153f5c29776dfe4 100755 (executable)
@@ -24,7 +24,7 @@
 #  - kafka notifications by @ktsaou #1342
 #  - pagerduty.com notifications by Jim Cooley @jimcooley PR #1373
 #  - messagebird.com notifications by @tech_no_logical #1453
-#  - hipchart notifications by @ktsaou #1561
+#  - hipchat notifications by @ktsaou #1561
 
 # -----------------------------------------------------------------------------
 # testing notifications
@@ -47,7 +47,7 @@ then
         echo >&2
         echo >&2 "# SENDING TEST ${x} ALARM TO ROLE: ${recipient}"
 
-        "${0}" "${recipient}" "$(hostname)" 1 1 "${id}" "$(date +%s)" "test_alarm" "test.chart" "test.family" "${x}" "${last}" 100 90 "${0}" 1 $((0 + id)) "units" "this is a test alarm to verify notifications work"
+        "${0}" "${recipient}" "$(hostname)" 1 1 "${id}" "$(date +%s)" "test_alarm" "test.chart" "test.family" "${x}" "${last}" 100 90 "${0}" 1 $((0 + id)) "units" "this is a test alarm to verify notifications work" "new value" "old value"
         if [ $? -ne 0 ]
         then
             echo >&2 "# FAILED"
@@ -139,6 +139,8 @@ duration="${15}"   # the duration in seconds of the previous alarm state
 non_clear_duration="${16}" # the total duration in seconds this is/was non-clear
 units="${17}"      # the units of the value
 info="${18}"       # a short description of the alarm
+value_string="${19}"        # friendly value (with units)
+old_value_string="${20}"    # friendly old value (with units)
 
 # -----------------------------------------------------------------------------
 # screen statuses we don't need to send a notification
@@ -773,13 +775,13 @@ send_pd() {
         then
         for PD_SERVICE_KEY in ${recipients}
         do
-            d="${status} ${name}=${value} ${units} - ${host}, ${family}"
+            d="${status} ${name} = ${value_string} - ${host}, ${family}"
             ${pd_send} -k ${PD_SERVICE_KEY} \
                        -t ${t} \
                        -d "${d}" \
                        -i ${alarm_id} \
                        -f 'info'="${info}" \
-                       -f 'value_w_units'="${value} ${units}" \
+                       -f 'value_w_units'="${value_string}" \
                        -f 'when'="${when}" \
                        -f 'duration'="${duration}" \
                        -f 'roles'="${roles}" \
@@ -863,6 +865,12 @@ send_hipchat() {
         # Defaults to 'html'.
         msg_format="text"
 
+        # Detect html messages
+        if echo "${message}" | tr -d '\n' | grep -q "<[a-z]\+>.*</[a-z]\+>\|<[a-z]\+/>"
+        then
+            msg_format="html"
+        fi
+
         # Background color for message. Valid values: yellow, green, red, purple, gray, random. Defaults to 'yellow'.
         case "${status}" in
             WARNING)  color="yellow" ;;
@@ -883,8 +891,8 @@ send_hipchat() {
                     -H "Authorization: Bearer ${authtoken}" \
                     -d "{\"color\": \"${color}\", \"from\": \"${netdata}\", \"message_format\": \"${msg_format}\", \"message\": \"${message}\", \"notify\": \"${notify}\"}" \
                     "https://api.hipchat.com/v2/room/${room}/notification")
-
-            if [ "${httpcode}" == "200" ]
+            if [ "${httpcode}" == "204" ]
             then
                 info "sent HipChat notification for: ${host} ${chart}.${name} is ${status} to '${room}'"
                 sent=$((sent + 1))
@@ -1056,7 +1064,7 @@ send_discord() {
             "channel": "#${channel}",
             "username": "netdata on ${host}",
             "text": "${host} ${status_message}, \`${chart}\` (_${family}_), *${alarm}*",
-            "icon_url": "https://discordapp.com/assets/f78426a064bc9dd24847519259bc42af.png",
+            "icon_url": "${images_base_url}/images/seo-performance-128.png",
             "attachments": [
                 {
                     "color": "${color}",
@@ -1120,7 +1128,7 @@ status_message="status unknown"
 color="grey"
 
 # the alarm value
-alarm="${name//_/ } = ${value} ${units}"
+alarm="${name//_/ } = ${value_string}"
 
 # the image of the alarm
 image="${images_base_url}/images/seo-performance-128.png"
@@ -1282,14 +1290,13 @@ SENT_PD=$?
 # -----------------------------------------------------------------------------
 # send hipchat message
 
-send_hipchat "${HIPCHAT_AUTH_TOKEN}" "${to_hipchat}" "
-<b>${alarm}</b> ${info_html}<br/>&nbsp;
-<small><b>${chart}</b><br/>Chart<br/>&nbsp;</small>
-<small><b>${family}</b><br/>Family<br/>&nbsp;</small>
-<small><b>${severity}</b><br/>Severity<br/>&nbsp;</small>
-<small><b>${date}${raised_for_html}</b><br/>Time<br/>&nbsp;</small>
-<a href=\"${goto_url}\">View Netdata</a><br/>&nbsp;
-<small><small>The source of this alarm is line ${src}</small></small>
+send_hipchat "${HIPCHAT_AUTH_TOKEN}" "${to_hipchat}" " \
+${host} ${status_message}<br/> \
+<b>${alarm}</b> ${info_html}<br/> \
+<b>${chart}</b> (family <b>${family}</b>)<br/> \
+<b>${date}${raised_for_html}</b><br/> \
+<a href=\\\"${goto_url}\\\">View netdata dashboard</a> \
+(source of alarm ${src}) \
 "
 
 SENT_HIPCHAT=$?