cacti icon indicating copy to clipboard operation
cacti copied to clipboard

Changes to graph template like add new Comment will cause the graph being marked as "Damaged" in Management->Graphs.

Open chtay opened this issue 5 years ago • 14 comments

Problem: Changes to graph template like add new Comment will cause the graph being marked as "Damaged" in Management->Graphs. The data source used by the graph, will not be updated by the poller afterward. Version: 1.2.16

I believe this bug was reported before.. Anyway, this is what I notice: In the "graph_local" table, the snmp_query_graph_id value now become 0 (instead of the Mapping ID number) for that related graph. Can be seen from: SELECT * FROM 'graph_local' WHERE host_id = "The Host ID for that graph" AND id = "That Damaged Graph ID"

The possible bug/fault that cause the "snmp_query_graph_id" to be 0 value, is coming from "lib/template.php"

In the template.php (v1.2.16), on line #514, there is one function called "update_graph_data_source_output_type" (See below). When adding COMMENT to the graph template, that function is executed. The variable "$output_type_id" is actually = 0 during that time and because of that, the "db_execute_prepared" is executed and that will update the "graph_local" table and set the snmp_query_graph_id = 0.

Compare to the previous version of the template, and it looks like since v1.1.8, the "db_execute_prepared('UPDATE graph_local" was implemented.

Modify the template.php, by comment out the "db_execute_prepared('UPDATE graph_local" portion (line #561 to #565) and try it again with fresh graph. No more damaged graph BUT the data source still not updated.

To make the data source "active" again, go to that data source template, and set the "Data Source Active" to inactive, save, set it back to active again and save. After that, the data source will be updated by the poller again and everything back to normal.

#514: function update_graph_data_source_output_type($local_graph_id, $output_type_id) { $graph_local = db_fetch_row_prepared('SELECT * FROM graph_local WHERE id = ?', array($local_graph_id)); .. .. #554 if ($snmp_query_graph_id != $output_type_id) { db_execute_prepared('UPDATE data_input_data SET value = ? WHERE data_template_data_id = ? AND data_input_field_id = ?', array($output_type_id, $data['id'], $output_type_field_id));

#561 db_execute_prepared('UPDATE graph_local SET snmp_query_graph_id = ? WHERE graph_template_id = ? AND id = ?', array($output_type_id, $graph_local['graph_template_id'], $local_graph_id));

chtay avatar Apr 15 '21 09:04 chtay

This is fixed in 1.2.17. It might be possible to run rerun the upgrade from 0.8.8h to 1.2.16 and the problem could be fixed.

TheWitness avatar Apr 15 '21 11:04 TheWitness

Run this query, and the problem will be fixed:

UPDATE graph_local AS gl
        INNER JOIN (
            SELECT DISTINCT local_graph_id, task_item_id
            FROM graph_templates_item
        ) AS gti
        ON gl.id = gti.local_graph_id
        INNER JOIN data_template_rrd AS dtr
        ON gti.task_item_id = dtr.id
        INNER JOIN data_template_data AS dtd
        ON dtr.local_data_id = dtd.local_data_id
        INNER JOIN data_input_fields AS dif
        ON dif.data_input_id = dtd.data_input_id
        INNER JOIN (
            SELECT *
            FROM data_input_data
            WHERE value RLIKE '^([0-9]+)$'
        ) AS did
        ON did.data_template_data_id = dtd.id
        AND did.data_input_field_id = dif.id
        INNER JOIN snmp_query_graph_rrd AS sqgr
        ON sqgr.snmp_query_graph_id = did.value
        SET gl.snmp_query_graph_id = did.value
        WHERE input_output = 'in'
        AND type_code = 'output_type'
        AND gl.snmp_query_id > 0
        AND gl.snmp_query_graph_id = 0;

TheWitness avatar Apr 16 '21 01:04 TheWitness

@TheWitness Facing currently the same issue in our environment .. i had added a "NaN" marker-area to lots of graph templates, which caused several of those graphs to be marked as "Damaged". Also those graphs are not properly filled with data any more.

Is it safe to run that query of yours on the current set of data? Would it repair also the connection between data objects and the RRDs? Apparently the graphs are still connected fine, they are generated properly, but they are not populated any more since i applied the changes.

bernisys avatar Apr 19 '21 09:04 bernisys

ok, took my chances .. i saw the query is executed anyway during the 17 upgrade ... results are disappointing:

Query OK, 0 rows affected (4 min 46.44 sec) Rows matched: 0 Changed: 0 Warnings: 0

but at least it should not have broken anything then >_<

bernisys avatar Apr 19 '21 09:04 bernisys

Your "snmp_query_graph_id" already overwritten with "0" value. That is why nothing happen. To solve your problem, u can either:

  1. Note down the existing rra file, and recreate the graph again. Then either copy the old rra to the new rra file (override) it or change the rra to point to the old one.
  2. Manually change the snmp_query_graph_id value in graph_local database to the correct value.

chtay avatar Apr 19 '21 09:04 chtay

The query is supposed to reset the ID back to the correct one, but no changes means it didn't find any that it could reset. I will have to confer with @TheWitness on that one.

netniV avatar Apr 19 '21 12:04 netniV

@netniV: If it helps, i can provide our DB content before and after this happened. This way maybe you can analyze the DB and compare the changes that happened. I was absolutely not expecting such kind of impact, as i never saw this before that changing a graph template would break the connection between data source and RRD file.

We've now restored the older DB-backup from FRI early morning and indeed most of the graphs are operational again, but unfortunately all my changes to the templates are all lost ... Wish i could just restore the newer graph templates table and have all changes back ... is there a way to do that, or does it need a deeper dive into the table dependencies?

Is this the related fix or do i need more? #4175 https://github.com/Cacti/cacti/commit/4739ad5969b1c9f049c0c407d3884cd77e4336b7

  • Syncing Templates can results in False 'Damaged Graph' notification on Graph Management page
  • Also corrects a few spurious errors when working with orphans and Change Template

bernisys avatar Apr 19 '21 13:04 bernisys

Dump the database to a file and send along, and then restore from a database backup since fefore the change.

TheWitness avatar Apr 20 '21 11:04 TheWitness

Are the graphs data query graphs or non-data query? Did you modify only the graph template or the data template too?

TheWitness avatar Apr 20 '21 11:04 TheWitness

Hi TheWitness Your solution of the "UPDATE graph_local AS gl" SQL is working very well, and it is considered solved. Thank you! I replaced back the original template.php, and try changing one of the graph template (with working graph), by adding Comment on it, and so far, the graph is not marked as "Damaged".

For bernisys situation, what I believe that bernisys's database (table: graph_local), the column "snmp_query_graph_id", already filled with '0' value. That is why applying the SQL will not help.

That SQL patch/solution is only to prevent any graph from going "Damaged" by any future changing to the graph template.

chtay avatar Apr 20 '21 11:04 chtay

Hi

Previously I tried modifying the Graph Template again by adding new Comment, onto the same template that I tested after I applied your SQL patch. It work well. No damaged graph.

Today, I give it another try, with another graph template (that I haven't modify, after applying the SQL patch), the graph related to that graph template now showing "Damaged Graph". I reapply the the SQL patch again, and this time shows 0 modified. Graph still shows as damaged graph.

Doing SELECT * FROM graph_local WHERE host_id = ThatRelatedHost AND graph_template_id = ThatNewlyModifiedGraphTemplateID, The return results shows everything there, except the snmp_query_graph_id = 0

I then update the graph_local by changing the snmp_query_graph_id = MappingIDOfThatAssociatedGraph (ID I got from viewing the Data Collection->Data Queries, choose the related Data Query, and look for the Mapping ID in the Associated Graph Template)

UPDATE graph_local SET snmp_query_graph_id = ThatMappingID WHERE host_id = ThatRelatedHost AND graph_template_id = ThatGraphTemplateID

I also set the data template (of that graph) to deactive, save, active and save again.

The graphs are now back to normal and is plotting.

I modify the graph template again, by adding another comment. This time the graph (same graph as above) still working and do not have "damaged graph". Interesting!

Sorry for all the confusion.

chtay avatar Apr 21 '21 01:04 chtay

@TheWitness Could be that only graphs linked to data queries were affected. I changed too many to be 100% sure, though this rings a bell. We had similar problems in the past already with DQ related graph templates, that had stopped the graphs from being filled - and i think when the device was rescanned, the graphs were duplicated. This would explain a lot .. and if this is somehow fixable with a SQL query, that would be really helpful, as we have still lost about 80k or so graphs. BU from last week is already restored, but i have detected several graphs that i edited even earlier were also affected - those were DQ related too.

@chtay Did you find a solution to make your graphs working properly again? If it can be scripted, i'll be volunteering to the job and provide something in my github repo. We have about 80k graphs to recover ...

bernisys avatar Apr 21 '21 18:04 bernisys

@bernisys The damaged graph can be recovered by updating the "snmp_query_graph_id" column in graph_local table...like I mentioned above. UPDATE graph_local SET snmp_query_graph_id = ThatMappingID WHERE host_id = ThatRelatedHost AND graph_template_id = ThatGraphTemplateID Or UPDATE graph_local SET snmp_query_graph_id = ThatMappingID WHERE graph_template_id = ThatGraphTemplateID

Then do a de-active, save, active and save on the related Data Source Template (this step is just to be sure the poller will update the data source).

But this does not solve the bug issue in the first place. This is just to fix the problem when the graph goes "damaged".

chtay avatar Apr 22 '21 07:04 chtay

It's already fixed in the 1.2.x branch.

TheWitness avatar Apr 22 '21 11:04 TheWitness