From 0a34322877c61f9e6e1ee55670a6c7e8217deaff Mon Sep 17 00:00:00 2001 From: Joe Clarke Date: Wed, 29 Jan 2020 06:59:23 -0500 Subject: [PATCH] Do not strip tags when markdown is in use. (#11075) Markdown supports limited HTML tags, which can help enrich messages. Additionally, eliminate extra whitespace when markdown is used as that will have weird output effects. --- LibreNMS/Alert/Transport/Ciscospark.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/LibreNMS/Alert/Transport/Ciscospark.php b/LibreNMS/Alert/Transport/Ciscospark.php index e106bcccbe..10aaaad5df 100644 --- a/LibreNMS/Alert/Transport/Ciscospark.php +++ b/LibreNMS/Alert/Transport/Ciscospark.php @@ -29,14 +29,28 @@ class Ciscospark extends Transport public function contactCiscospark($obj, $room_id, $token) { - $text = strip_tags($obj['msg']); + $text = null; $data = array ( 'roomId' => $room_id ); $akey = 'text'; if ($this->config['use-markdown'] === 'on') { + $lines = explode("\n", $obj['msg']); + $mlines = []; + /* Remove blank lines as they create weird markdown + * behaviors. + */ + foreach ($lines as $line) { + $line = trim($line); + if ($line != '') { + array_push($mlines, $line); + } + } + $text = implode("\n", $mlines); $akey = 'markdown'; + } else { + $text = strip_tags($obj['msg']); } $data[$akey] = $text;