Cacti 1.1.28 clog plugin cuts off lines of the original log

General discussion about Plugins for Cacti

Moderators: Developers, Moderators

Post Reply
ivan-impuls
Posts: 23
Joined: Mon Jun 15, 2009 1:09 am

Cacti 1.1.28 clog plugin cuts off lines of the original log

Post by ivan-impuls »

Hello all,
My system:

Code: Select all

Linux 4.13.0-1-686-pae #1 SMP Debian 4.13.13-1 (2017-11-16) i686 GNU/Linux
Debian GNU/Linux 9.2 (stretch)
cacti 1.1.28+ds1-2
cacti-spine 1.1.21-1
PHP 7.0.26-1
Apache/2.4.25 (Debian)
mariadb  Ver 15.1 Distrib 10.1.26-MariaDB, for debian-linux-gnu (i686) using readline 5.2
I have passed to this system from debian 8.0 jessie and cacti 0.8.8h in the way of upgrade.
After upgrade the plugin clog doesn't show full information (cuts off lines of values).
Generic Log Level – MEDIUM – Statistics, Errors and Results
Clog log in Web-GUI:
2017-12-08 16:49:00 - SPINE: Poller[1] Device[borri-galileo] Graphs[borri-galileo - UPS on Battery, borri-galileo - UPS on Battery] DS[1108]
2017-12-08 16:49:00 - SPINE: Poller[1] Device[borri-galileo] Graphs[borri-galileo - UPS on Battery, borri-galileo - UPS on Battery] DS[1107]
2017-12-08 16:49:00 - SPINE: Poller[1] Device[hp-1920] Graphs[hp-1920 - Traffic - GigabitEthernet1/0/25, hp-1920 - Traffic - GigabitEthernet1/0/25] DS[1001]
2017-12-08 16:49:00 - SPINE: Poller[1] Device[hp-1920] Graphs[hp-1920 - Traffic - GigabitEthernet1/0/25, hp-1920 - Traffic - GigabitEthernet1/0/25] DS[1001]
2017-12-08 16:49:00 - SPINE: Poller[1] Device[hp-1920] Graphs[hp-1920 - Traffic - GigabitEthernet1/0/24, hp-1920 - Traffic - GigabitEthernet1/0/24] DS[1000]
2017-12-08 16:49:00 - SPINE: Poller[1] Device[hp-1920] Graphs[hp-1920 - Traffic - GigabitEthernet1/0/24, hp-1920 - Traffic - GigabitEthernet1/0/24] DS[1000]
2017-12-08 16:49:00 - SPINE: Poller[1] Device[hp-1920] Graphs[hp-1920 - Traffic - GigabitEthernet1/0/23, hp-1920 - Traffic - GigabitEthernet1/0/23] DS[999]
2017-12-08 16:49:00 - SPINE: Poller[1] Device[hp-1920] Graphs[hp-1920 - Traffic - GigabitEthernet1/0/23, hp-1920 - Traffic - GigabitEthernet1/0/23] DS[999]
2017-12-08 16:49:00 - SPINE: Poller[1] Device[hp-1920] Graphs[hp-1920 - Traffic - GigabitEthernet1/0/22, hp-1920 - Traffic - GigabitEthernet1/0/22] DS[998]
2017-12-08 16:49:00 - SPINE: Poller[1] Device[hp-1920] Graphs[hp-1920 - Traffic - GigabitEthernet1/0/22, hp-1920 - Traffic - GigabitEthernet1/0/22] DS[998]
2017-12-08 16:49:00 - SPINE: Poller[1] Device[hp-1920] Graphs[hp-1920 - Traffic - GigabitEthernet1/0/21, hp-1920 - Traffic - GigabitEthernet1/0/21] DS[997]
2017-12-08 16:49:00 - SPINE: Poller[1] Device[hp-1920] Graphs[hp-1920 - Traffic - GigabitEthernet1/0/21, hp-1920 - Traffic - GigabitEthernet1/0/21] DS[997]
2017-12-08 16:49:00 - SPINE: Poller[1] Device[borri-galileo] Graphs[borri-galileo - UPS on Battery, borri-galileo - UPS on Battery] DS[1106]
2017-12-08 16:49:00 - SPINE: Poller[1] Device[borri-galileo] Graphs[borri-galileo - Estimated Minutes Remaining, borri-galileo - Estimated Minutes Remaining] DS[1105]
clog_log.png
clog_log.png (380.66 KiB) Viewed 1591 times
Original file cacti.log:
2017-12-08 16:49:00 - SPINE: Poller[1] Device[51] TH[1] DS[1105]SNMP: v1: 172.18.48.17, dsname: ups_ipponmc_estm, oid: .1.3.6.1.2.1.33.1.2.3.0, value: 0
2017-12-08 16:49:00 - SPINE: Poller[1] Device[51] TH[1] DS[1106]SNMP: v1: 172.18.48.17, dsname: ups_ipponmc_rtrem, oid: .1.3.6.1.4.1.935.1.1.1.2.2.4.0, value: 0
2017-12-08 16:49:00 - SPINE: Poller[1] Device[49] TH[1] DS[997] SNMP: v1: 172.18.48.5, dsname: traffic_in, oid: .1.3.6.1.2.1.2.2.1.10.21, value: 0
2017-12-08 16:49:00 - SPINE: Poller[1] Device[49] TH[1] DS[997] SNMP: v1: 172.18.48.5, dsname: traffic_out, oid: .1.3.6.1.2.1.2.2.1.16.21, value: 0
2017-12-08 16:49:00 - SPINE: Poller[1] Device[49] TH[1] DS[998] SNMP: v1: 172.18.48.5, dsname: traffic_in, oid: .1.3.6.1.2.1.2.2.1.10.22, value: 0
2017-12-08 16:49:00 - SPINE: Poller[1] Device[49] TH[1] DS[998] SNMP: v1: 172.18.48.5, dsname: traffic_out, oid: .1.3.6.1.2.1.2.2.1.16.22, value: 0
2017-12-08 16:49:00 - SPINE: Poller[1] Device[49] TH[1] DS[999] SNMP: v1: 172.18.48.5, dsname: traffic_in, oid: .1.3.6.1.2.1.2.2.1.10.23, value: 2359346704
2017-12-08 16:49:00 - SPINE: Poller[1] Device[49] TH[1] DS[999] SNMP: v1: 172.18.48.5, dsname: traffic_out, oid: .1.3.6.1.2.1.2.2.1.16.23, value: 1023701341
2017-12-08 16:49:00 - SPINE: Poller[1] Device[49] TH[1] DS[1000]SNMP: v1: 172.18.48.5, dsname: traffic_in, oid: .1.3.6.1.2.1.2.2.1.10.24, value: 0
2017-12-08 16:49:00 - SPINE: Poller[1] Device[49] TH[1] DS[1000]SNMP: v1: 172.18.48.5, dsname: traffic_out, oid: .1.3.6.1.2.1.2.2.1.16.24, value: 0
2017-12-08 16:49:00 - SPINE: Poller[1] Device[49] TH[1] DS[1001]SNMP: v1: 172.18.48.5, dsname: traffic_in, oid: .1.3.6.1.2.1.2.2.1.10.25, value: 0
2017-12-08 16:49:00 - SPINE: Poller[1] Device[49] TH[1] DS[1001]SNMP: v1: 172.18.48.5, dsname: traffic_out, oid: .1.3.6.1.2.1.2.2.1.16.25, value: 0
2017-12-08 16:49:00 - SPINE: Poller[1] Device[51] TH[1] DS[1107]SNMP: v1: 172.18.48.17, dsname: ups_ipponmc_secbat, oid: .1.3.6.1.2.1.33.1.2.2.0, value: 0
2017-12-08 16:49:00 - SPINE: Poller[1] Device[51] TH[1] DS[1108]SNMP: v1: 172.18.48.17, dsname: ups_ipponmc_tonbat, oid: .1.3.6.1.4.1.935.1.1.1.2.1.2.0, value: 0

Please help.
netniV
Cacti Guru User
Posts: 3441
Joined: Sun Aug 27, 2017 12:05 am

Re: Cacti 1.1.28 clog plugin cuts off lines of the original

Post by netniV »

The display may be down to the logging level you have set. Do you have it set to display values? If not, it's probably parsing them off. Any ID fields tend to be automatically changed to provide a link to the appropriate device/graph.
Cacti Developer & Release Manager
The Cacti Group

Director
BV IT Solutions Ltd

+--------------------------------------------------------------------------+

Cacti Resources:
Cacti Website (including releases)
Cacti Issues
Cacti Development Releases
Cacti Development Documentation
ivan-impuls
Posts: 23
Joined: Mon Jun 15, 2009 1:09 am

Re: Cacti 1.1.28 clog plugin cuts off lines of the original

Post by ivan-impuls »

netniV wrote:The display may be down to the logging level you have set. Do you have it set to display values? If not, it's probably parsing them off. Any ID fields tend to be automatically changed to provide a link to the appropriate device/graph.
Yes. I did logging level to

Code: Select all

Medium - Statistics,errors and Results
or even

Code: Select all

Devel
This clog log:
clog_log.png
clog_log.png (38.9 KiB) Viewed 1530 times
And this Admin Log:
admin_log.png
admin_log.png (27.88 KiB) Viewed 1530 times
Question not such important as it is possible to look at the necessary values in the Admin Log.
But can be somewhere there are separate clog settings which I haven't found?
netniV
Cacti Guru User
Posts: 3441
Joined: Sun Aug 27, 2017 12:05 am

Re: Cacti 1.1.28 clog plugin cuts off lines of the original

Post by netniV »

Currently, if CLOG finds 'Device[' or 'DS[' in the line being parsed, it creates a new item which contains the links to the devices/data sources in question. It does not then transfer the rest of the contents (which includes the value) to the newly created line item.
Cacti Developer & Release Manager
The Cacti Group

Director
BV IT Solutions Ltd

+--------------------------------------------------------------------------+

Cacti Resources:
Cacti Website (including releases)
Cacti Issues
Cacti Development Releases
Cacti Development Documentation
netniV
Cacti Guru User
Posts: 3441
Joined: Sun Aug 27, 2017 12:05 am

Re: Cacti 1.1.28 clog plugin cuts off lines of the original

Post by netniV »

A fix for this has now been added to the develop branch of cacti. If you wish to add this to your own code, use the following patch with

Code: Select all

git apply <patchfile>
The patch file should contain:

Code: Select all

diff --git a/lib/clog_webapi.php b/lib/clog_webapi.php
index 3c43c53..aec7e45 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 = '';
-
-                       // 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[<a href='" . html_escape($config['url_path'] . 'host.php?action=edit&id=' . $host_id) . "'>" . (isset($hostDescriptions[$host_id]) ? $hostDescriptions[$host_id]:'') . '</a>]';
-                               $item      = substr($item, $host_end + 1);
-                       }
-
-                       // 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[<a href='";
-
-                                                       foreach($graph_ids as $key => $title) {
-                                                               $graph_add .= ($i > 0 ? '%2C' : '') . $key;
-                                                               $title     .= ($title != '' ? ', ':'') . html_escape($title);
-
-                                                               $i++;
-                                                       }
+               $host_start = strpos($new_item, 'Device[');
+               $ds_start   = strpos($new_item, 'DS[');

-                                                       $new_item .= html_escape($graph_add) . "' title='" . __esc('View Graphs') . "'>" . $title . '</a>]';
-                                               }
-                                       }
-
-                                       $new_item .= ' DS[';
-                                       $i         = 0;
-
-                                       foreach($ds_ids as $ds_id) {
-                                               $new_item .= ($i == 0 ? '':', ') . "<a href='" . html_escape($config['url_path'] . 'data_sources.php?action=ds_edit&id=' . $ds_id) . "'>" . $ds_id . '</a>';
+               $ds_regex = '~( DS\[)([,\d]+)(\])~';
+               $dev_regex = '~( Device\[)([,\d]+)(\])~';

-                                               $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,67 @@ function filter($clogAdmin) {
        </tr>
        <?php
 }
+
+function clog_regex_device($matches) {
+       global $config;
+       $dev_ids = explode(',',$matches[2]);
+       $result = '';
+       if (sizeof($dev_ids)) {
+               $hosts = db_fetch_assoc_prepared('SELECT id, description
+                                                 FROM host
+                                                 WHERE id in ('.implode(',',$dev_ids).')');
+               $hostDescriptions = array();
+               foreach ($hosts as $host) {
+                       $hostDescriptions[$host['id']] = html_escape($host['description']);
+               }
+
+               foreach ($dev_ids as $host_id) {
+                       $result .= $matches[1].'<a href=\'' . html_escape($config['url_path'] . 'host.php?action=edit&id=' . $host_id) . '\'>' . (isset($hostDescriptions[$host_id]) ? $hostDescriptions[$host_id]:$host_id) . '</a>' . $matches[3];
+               }
+       }
+       return $result;
+}
+
+function clog_regex_datasource($matches) {
+       global $config;
+
+       $ds_ids = explode(',',$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[<a href='";
+
+                               foreach($graph_ids as $key => $title) {
+                                       $graph_add .= ($i > 0 ? '%2C' : '') . $key;
+                                       $title     .= ($title != '' ? ', ':'') . html_escape($title);
+
+                                       $i++;
+                               }
+
+                               $result .= html_escape($graph_add) . "' title='" . __esc('View Graphs') . "'>" . $title . '</a>]';
+                       }
+               }
+
+               $result .= $matches[1];
+               $i         = 0;
+
+               foreach($ds_ids as $ds_id) {
+                       $result .= ($i == 0 ? '':', ') . "<a href='" . html_escape($config['url_path'] . 'data_sources.php?action=ds_edit&id=' . $ds_id) . "'>" . $ds_id . '</a>';
+
+                       $i++;
+               }
+
+               $result .= $matches[3];
+       }
+       return $result;
+}
Cacti Developer & Release Manager
The Cacti Group

Director
BV IT Solutions Ltd

+--------------------------------------------------------------------------+

Cacti Resources:
Cacti Website (including releases)
Cacti Issues
Cacti Development Releases
Cacti Development Documentation
ivan-impuls
Posts: 23
Joined: Mon Jun 15, 2009 1:09 am

Re: Cacti 1.1.28 clog plugin cuts off lines of the original

Post by ivan-impuls »

Ok. Thank you very much!
And also I have installed version cacti 1.1.34. In this version everything is corrected.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest