Skip to content

Fix issue where RRA files are not automatically removed #5848

@tddcacti

Description

@tddcacti

Describe the bug

After enabling Configuration > Settings > Paths > RRDfile Auto Clean, and then attempting to use the feature by deleting a Graph and all Data Source(s) reference by the Graph, I'm seeing that the RRD file is not actually deleted.

To Reproduce

Steps to reproduce the behavior:

  1. Go to Configuration > Settings > Paths. Make sure that RRDfile Auto Clean is enabled. For my testing I have set the "RRDfile Auto Clean Method" to "Delete".
  2. Under Management > Graphs, find a graph to delete. Before deleting, view the path the RRD file by clicking the graph, then enable Graph Debug Mode. Note the RRD file path and name.
  3. Under Management > Graphs, select the graph, then from the Choose an action dropdown, select Delete and hit Go.
  4. Choose the option to "Delete all Data Source(s) referenced by these Graph(s) that are not in use elsewhere." and hit Continue
  5. Allow enough time for a poller cycle or two to complete (allow time for RRDFile Autoclean to run, in theory)
  6. Check to see whether or not the RRD file still exists (use the information gathered in step 2). The file will still exist, though it should have been deleted.

Expected behavior

When the data source is deleted, we are invoking either function "api_data_source_remove" or "api_data_source_remove_multi" to perform the data source deletion(s). Within both of these functions, there is a section starting with "if ($autoclean == 'on')" (lines 71-83 and lines 300-306 in the current develop branch of lib/api_data_source.php). This section should insert a record into the table "data_source_purge_action", which queues up the RRD files to be deleted the next time poller_maintenence.php runs the "rrdfile_purge" function. That function looks for entries in data_source_purge_action and calls "remove_files" to delete them.

Root Cause Theory

Having investigated the code, I believe I see two problems. In order to populate the data_source_purge_action table we are pulling the "data_source_path" value out of the data_template_data table and removing the string "<path_cacti>/" with the replace operation. However, as I look at the data in my data_template_data table, the "data_source_path" column actually has values prefixed with "<path_rra>/". I believe we have a typo--"<path_cacti>" should be "<path_rra>" in the locations shown in the first two screenshots.

Additionally, within the function api_data_source_remove_multi, we are actually deleting the data from the data_template_data table in line 256 of api_data_source.php, which is before we even get to the autoclean logic. This causes the autoclean INSERT statement to fail to insert any data into data_source_purge_action. I would propose simply moving this section up above line 256 (third screenshot)

I've made both changes on my lab instance of Cacti, so far it seems to be working.

Screenshots

image

image

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugUndesired behaviourconfirmedBug is confirm by dev teamresolvedA fixed issueunverifiedSome days we don't have a clue

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions