diff --git a/docs/CHANGELOG b/docs/CHANGELOG
index d3810ef5aa..f2e70e49f6 100644
--- a/docs/CHANGELOG
+++ b/docs/CHANGELOG
@@ -12,6 +12,7 @@ Cacti CHANGELOG
1.1.30
-issue#1155: Non-secure mail setting not functional due to changes in phpmailer
-issue#1157: Resolve issue with branch permission api
+-issue#1158: Change CLOG to use regex replacement so line details are not mangled
-issue: basename function undefined during upgrade to 1.0.x
-issue: Storage API and translations required for Change password function
-issue: ALTER IGNORE still throws an error when attempting to drop the primary key
diff --git a/lib/clog_webapi.php b/lib/clog_webapi.php
index 3c43c538cd..911c862ab2 100644
--- a/lib/clog_webapi.php
+++ b/lib/clog_webapi.php
@@ -259,72 +259,16 @@ function clog_view_logfile() {
}
foreach ($logcontents as $item) {
- $host_start = strpos($item, 'Device[');
- $ds_start = strpos($item, 'DS[');
+ $new_item = html_escape($item);
- if (!$host_start && !$ds_start) {
- $new_item = html_escape($item);
- } else {
- $new_item = '';
+ $host_start = strpos($new_item, 'Device[');
+ $ds_start = strpos($new_item, 'DS[');
- // Process the host section
- if ($host_start) {
- $host_end = strpos($item, ']', $host_start);
- $host_id = substr($item, $host_start + 7, $host_end - ($host_start + 7));
- $new_item .= substr($item, 0, $host_start) . " Device[" . (isset($hostDescriptions[$host_id]) ? $hostDescriptions[$host_id]:'') . ']';
- $item = substr($item, $host_end + 1);
- }
+ $ds_regex = '~( DS\[)([, \d]+)(\])~';
+ $dev_regex = '~( Device\[)([, \d]+)(\])~';
- // Process the Data Source Section
- $ds_start = strpos($item, 'DS[');
-
- if ($ds_start) {
- $ds_end = strpos($item, ']', $ds_start);
- $ds_id = substr($item, $ds_start + 3, $ds_end - ($ds_start + 3));
- $ds_ids = explode(', ', $ds_id);
-
- if (sizeof($ds_ids)) {
- $graph_add = $config['url_path'] . 'graph_view.php?page=1&style=selective&action=preview&graph_add=';
-
- if ($new_item == '') {
- $new_item .= substr($item, 0, $ds_start);
- }
-
- $title = '';
- $i = 0;
-
- foreach($ds_ids as $ds_id) {
- $graph_ids = clog_get_graphs_from_datasource($ds_id);
-
- if (sizeof($graph_ids)) {
- $new_item .= " Graphs[" . $title . ']';
- }
- }
-
- $new_item .= ' DS[';
- $i = 0;
-
- foreach($ds_ids as $ds_id) {
- $new_item .= ($i == 0 ? '':', ') . "" . $ds_id . '';
-
- $i++;
- }
-
- $new_item .= ']';
- }
- } else {
- $new_item .= html_escape($item);
- }
- }
+ $new_item = preg_replace_callback($dev_regex,'clog_regex_device',$new_item);
+ $new_item = preg_replace_callback($ds_regex,'clog_regex_datasource',$new_item);
/* respect the exclusion filter */
if ($exclude_regex != '' && !$clogAdmin) {
@@ -578,3 +522,68 @@ function filter($clogAdmin) {
' . (isset($hostDescriptions[$host_id]) ? $hostDescriptions[$host_id]:$host_id) . '' . $matches[3];
+ }
+ }
+ return $result;
+}
+
+function clog_regex_datasource($matches) {
+ global $config;
+
+ $ds_ids = explode(',',str_replace(" ","",$matches[2]));
+
+ $result = '';
+
+ if (sizeof($ds_ids)) {
+ $graph_add = $config['url_path'] . 'graph_view.php?page=1&style=selective&action=preview&graph_add=';
+
+ $title = '';
+ $i = 0;
+
+ foreach($ds_ids as $ds_id) {
+ $graph_ids = clog_get_graphs_from_datasource($ds_id);
+
+ if (sizeof($graph_ids)) {
+ $result .= " Graphs[" . $title . ']';
+ }
+ }
+
+ $result .= $matches[1];
+ $i = 0;
+
+ foreach($ds_ids as $ds_id) {
+ $result .= ($i == 0 ? '':', ') . "" . $ds_id . '';
+
+ $i++;
+ }
+
+ $result .= $matches[3];
+ }
+ return $result;
+}