Skip to content

When performing maintenance, various errors may sometimes be seen #3827

Closed
@leonardocuei

Description

@leonardocuei

Describe the bug

rrdcleaner.php purging old rrd files logging is not being made as expected

A clear and concise description of what the bug is.

just upgraded cacti from 1.1.30 to 1.2.14, no problem on that, everything seems to work fine (polling/graphing)
while cleaning some old graphs, I noticed rrdcleaner actions were not logged as expected. I was getting some "undefined variable" errors and the actual "RRDMAINT STATS" was bringing weird and some empty numbers

26/Sep/2020 15:50:31 - ERROR PHP NOTICE: Undefined variable: poller_start in file: /home/httpd/html/admin/cacti/poller_maintenance.php on line: 206
26/Sep/2020 15:50:31 - CMDPHP PHP ERROR NOTICE Backtrace: (/poller_maintenance.php[97]:rrdfile_purge(), /poller_maintenance.php[206]:CactiErrorHandler())
26/Sep/2020 15:50:31 - ERROR PHP NOTICE: Undefined variable: purged in file: /home/httpd/html/admin/cacti/poller_maintenance.php on line: 206
26/Sep/2020 15:50:31 - CMDPHP PHP ERROR NOTICE Backtrace: (/poller_maintenance.php[97]:rrdfile_purge(), /poller_maintenance.php[206]:CactiErrorHandler())
26/Sep/2020 15:50:31 - ERROR PHP NOTICE: Undefined variable: archived in file: /home/httpd/html/admin/cacti/poller_maintenance.php on line: 206
26/Sep/2020 15:50:31 - CMDPHP PHP ERROR NOTICE Backtrace: (/poller_maintenance.php[97]:rrdfile_purge(), /poller_maintenance.php[206]:CactiErrorHandler())
26/Sep/2020 15:50:31 - SYSTEM RRDMAINT STATS: Time:1601146231.1344 Purged: Archived:

To Reproduce

Steps to reproduce the behavior:

I just got some RRD files to delete, and errors are there on the next poller run

Expected behavior

I expect RRD to be cleaned (that's happening) and a log line to be reported (this is not happening)

Additional context

After some debug on poller_maintenance.php file, I believe I found what's wrong ... some variables on function rrdfile_purge() need to be declared as global, so they could be used from the global environment. They were being used but not declared as such, so "undefined variable" was being generated.

On the main part of the file, the $poller_start wasn't being declared as global, I also believe it needs to be declared as such, so it can be used inside the functions. And it needs to be declared as global inside the functions as well, to be used.

That being said, after some minor tweaks, I could get log to work as expected (and just added a string "sec" to indicate the unit of "time")

26/Sep/2020 17:20:29 - SYSTEM RRDMAINT STATS: Time:0.0022 sec Purged:2 Archived:0
26/Sep/2020 17:25:30 - SYSTEM RRDMAINT STATS: Time:0.0024 sec Purged:2 Archived:0

patch to poller_maintenance.php is:

[root@cacti cacti]# diff -Naur poller_maintenance.1.2.14.php  poller_maintenance.php
--- poller_maintenance.1.2.14.php       2020-08-02 19:30:13.000000000 -0300
+++ poller_maintenance.php      2020-09-26 17:40:24.616788683 -0300
@@ -38,11 +38,11 @@
 $dir = dirname(__FILE__);
 chdir($dir);

+global $config, $database_default, $archived, $purged, $disable_log_rotation, $poller_start;
+
 /* record the start time */
 $poller_start = microtime(true);

-global $config, $database_default, $archived, $purged, $disable_log_rotation;
-
 /* process calling arguments */
 $parms = $_SERVER['argv'];
 array_shift($parms);
@@ -170,6 +170,8 @@
 }

 function rrdfile_purge() {
+       global $archived, $purged, $poller_start, $force;
+
        /* are my tables already present? */
        $purge = db_fetch_cell('SELECT count(*)
                FROM data_source_purge_action');
@@ -203,7 +205,7 @@

                /* record the start time */
                $poller_end = microtime(true);
-               $string = sprintf('RRDMAINT STATS: Time:%4.4f Purged:%s Archived:%s', ($poller_end - $poller_start), $purged, $archived);
+               $string = sprintf('RRDMAINT STATS: Time:%4.4f sec Purged:%s Archived:%s', ($poller_end - $poller_start), $purged, $archived);
                cacti_log($string, true, 'SYSTEM');
        }
 }
[root@cacti cacti]#

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugUndesired behaviourresolvedA fixed issue

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions