Skip to content

Respect Graph Template Test Data Source in graph automation - #86

Merged
TheWitness merged 2 commits into
developfrom
fix/respect-test-data-source
Nov 9, 2026
Merged

TheWitness merged 2 commits into
developfrom
fix/respect-test-data-source

Conversation

@TheWitness

Copy link
Copy Markdown
Member

Summary

The Host MIB graph automation (poller_graphs.php) created graphs by shelling out to Cacti's cli/add_graphs.php, which calls create_complete_graph_from_template() directly and never tests the data source. As a result, the automation ignored the per–Graph Template "Test Data Source" setting (graph_templates.test_source) that Cacti's GUI graph creation honors via create_save_graph() → test_data_sources().

In practice this created Login Users and Processes graphs on devices (for example MikroTik/RouterOS) that expose the Host Resources MIB but return no valid data for hrSystemNumUsers / hrSystemProcesses.

Fix

Gate every add_graphs.php invocation on core's test_data_sources(), mirroring create_save_graph():

  • hmib_gt_graph() — the Users/Processes template path
  • the directly-assigned template loop in add_summary_graphs()
  • hmib_dq_graphs() — data-query graphs

cg graphs use test_data_sources($graph_template_id, $host_id); ds graphs use test_data_sources($graph_template_id, $host_id, $query_id, $snmp_index).

When a template's "Test Data Source" is off (the default), test_data_sources() returns true and behavior is unchanged. When it is on and the data source returns no valid data, the graph is skipped and a debug line is emitted.

Testing

  • php -l clean.
  • Existing unit suite passes.
  • Verified both branches (skip when the test fails, create when it passes) against the real functions.

Note: poller_graphs.php coverage is collected by the E2E suite (live Cacti + DB), so the skip path is best covered by an E2E "skip when Test Data Source fails" scenario. Happy to add one if preferred.

Gate add_graphs.php invocations on test_data_sources() so a Graph Template with Test Data Source enabled is not graphed on devices (e.g. MikroTik) whose Host Resources MIB data source (Login Users, Processes) returns no valid data.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 9, 2026 01:07

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The tests lack E2E coverage for all three data-source probe gates, leaving regressions undetected where failing probes create graphs or passing probes and disabled checks block creation.

1 open issue
What changed in this PR

This PR makes Host MIB graph automation honor Cacti’s per-template Test Data Source setting before creating graphs.

Changes:

  • Adds data-source checks for Users/Processes templates, directly assigned templates, and indexed data-query graphs.
  • Skips graph creation and emits a debug message when validation fails.
  • Preserves existing behavior when data-source testing is disabled.
File Description
poller_graphs.php Gates all three graph-creation paths on core test_data_sources(), including query and index arguments for data-query graphs.

Review effort: Balanced

Comment thread poller_graphs.php Resolved
Load the real hmib_gt_graph()/hmib_dq_graphs() and exercise the skip branch of each gate (device, data query, and summary paths) so the per-test coverage run attributes them to poller_graphs.php.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@sonarqubecloud

sonarqubecloud Bot commented Nov 9, 2026

Copy link
Copy Markdown

@TheWitness
TheWitness merged commit 30976be into develop Nov 9, 2026
5 checks passed
@TheWitness
TheWitness deleted the fix/respect-test-data-source branch November 9, 2026 02:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants