]> arthur.barton.de Git - netdata.git/blobdiff - plugins.d/alarm-notify.sh
hipchat: detect html messages
[netdata.git] / plugins.d / alarm-notify.sh
index 2bfe89e6ea722ad5f5060d9059336c8fc891407c..87ba84d3d8a9ed9725c04e235153f5c29776dfe4 100755 (executable)
@@ -865,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" ;;
@@ -885,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))
@@ -1284,9 +1290,16 @@ SENT_PD=$?
 # -----------------------------------------------------------------------------
 # send hipchat message
 
-send_hipchat "${HIPCHAT_AUTH_TOKEN}" "${to_hipchat}" "<b>${alarm}</b> ${info_html}<br/>&nbsp;<br/><small><b>${chart}</b><br/>Chart<br/>&nbsp;</small><br/><small><b>${family}</b><br/>Family<br/>&nbsp;</small><br/><small><b>${severity}</b><br/>Severity<br/>&nbsp;</small><br/><small><b>${date}${raised_for_html}</b><br/>Time<br/>&nbsp;</small><br/><a href=\"${goto_url}\">View Netdata</a><br/>&nbsp;<br/><small><small>The source of this alarm is line ${src}</small></small>"
-SENT_HIPCHAT=$?
+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=$?
 
 # -----------------------------------------------------------------------------
 # send the email