From cf9432330e0aa2b027b6f15e866985c005db23e8 Mon Sep 17 00:00:00 2001 From: pblasquez Date: Tue, 19 Jul 2016 15:15:07 -0700 Subject: [PATCH 1/3] Change slack format to attachment style As documented here: https://api.slack.com/docs/message-attachments This change also makes things compatible with simple HTML templates by using strip_tags() on the template output. --- includes/alerts/transport.slack.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/includes/alerts/transport.slack.php b/includes/alerts/transport.slack.php index 3d295b01a7..03ea1eb4b3 100644 --- a/includes/alerts/transport.slack.php +++ b/includes/alerts/transport.slack.php @@ -24,8 +24,17 @@ foreach( $opts as $tmp_api ) { $host = $tmp_api['url']; $curl = curl_init(); + $slack_msg = strip_tags($obj['msg']); + $color = ($obj['state'] == 0 ? '#00FF00' : '#FF0000'); $data = array( - 'text' => $obj['msg'], + 'attachments' => array( + 0 => array( + 'fallback' => $slack_msg, + 'color' => $color, + 'title' => $obj['title'], + 'text' => $slack_msg, + ) + ), 'channel' => $tmp_api['channel'], 'username' => $tmp_api['username'], 'icon_url' => $tmp_api['icon_url'], From c0a0faba9a53b72e1ec129e4f3efdf9f092c5e92 Mon Sep 17 00:00:00 2001 From: pblasquez Date: Tue, 19 Jul 2016 15:20:48 -0700 Subject: [PATCH 2/3] formatting error --- includes/alerts/transport.slack.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/alerts/transport.slack.php b/includes/alerts/transport.slack.php index 03ea1eb4b3..57df9ae5f2 100644 --- a/includes/alerts/transport.slack.php +++ b/includes/alerts/transport.slack.php @@ -28,7 +28,7 @@ foreach( $opts as $tmp_api ) { $color = ($obj['state'] == 0 ? '#00FF00' : '#FF0000'); $data = array( 'attachments' => array( - 0 => array( + 0 => array( 'fallback' => $slack_msg, 'color' => $color, 'title' => $obj['title'], From a5383b980653c90da6d44710b81151529c278289 Mon Sep 17 00:00:00 2001 From: pblasquez Date: Tue, 26 Jul 2016 18:03:08 -0700 Subject: [PATCH 3/3] Adding new slack information --- doc/Extensions/Alerting.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/Extensions/Alerting.md b/doc/Extensions/Alerting.md index 62d3e7bf2f..cf2061595b 100644 --- a/doc/Extensions/Alerting.md +++ b/doc/Extensions/Alerting.md @@ -268,7 +268,7 @@ $config['alert']['transports']['irc'] = true; > You can configure these options within the WebUI now, please avoid setting these options within config.php -The Slack transport will POST the alert message to your Slack Incoming WebHook, you are able to specify multiple webhooks along with the relevant options to go with it. All options are optional, the only required value is for url, without this then no call to Slack will be made. Below is an example of how to send alerts to two channels with different customised options: +The Slack transport will POST the alert message to your Slack Incoming WebHook using the [attachments](https://api.slack.com/docs/message-attachments) option, you are able to specify multiple webhooks along with the relevant options to go with it. Simple html tags are stripped from the message. All options are optional, the only required value is for url, without this then no call to Slack will be made. Below is an example of how to send alerts to two channels with different customised options: ~~ ```php