Skip to content

feat: ship the DigitalOcean Cacti templates and import them on install - #84

Merged
somethingwithproof merged 2 commits into
mainfrom
feat/m3-templates
Nov 15, 2026
Merged

somethingwithproof merged 2 commits into
mainfrom
feat/m3-templates

Conversation

@somethingwithproof

@somethingwithproof somethingwithproof commented Nov 15, 2026 •

Copy link
Copy Markdown
Owner

Stacked on #82: the base is feat/m3-digitalocean. I'll retarget it to main once #82 merges.

Closes #42

What ships

  • The catalog names its graphs. DigitalOceanCatalog::GRAPHS puts every metric, and each resource type's collection age (ADR 0006), in exactly one graph: 5 for Droplets and 10 for load balancers.

  • tests/bin/generate-templates.php turns that into templates/cloud_digitalocean.xml, laid out like Cacti's own export. The package contains:

    • a "Cloud: DigitalOcean Scope" device template with both data queries (ADR 0010);
    • a script server data query per resource type, whose indexes are resource IDs;
    • a data template and a graph template per graph.

    A graph's data source holds only that graph's metrics, so creating a CPU graph doesn't start collecting bandwidth or the agent-only metrics (ADR 0005). Every hash is fixed: the first 32 hex digits of a SHA-256 over a fixed key.

  • templates/resource/*.xml are the data query definitions, pointing at ss_cloud() in ss_cloud.php. That script server function is Script server input for cloud data sources #44; until it exists, no graphs can be created. Scope devices and resource data queries #43 adds the scope devices.

Install and upgrade

  • Templates::install() takes a lock, so two processes never import at once.
  • It copies the data query files into <path_cacti>/resource/script_server/. Cacti 1.2 refuses data query XML outside <path_cacti>/resource. Each copy is written to a temporary file and renamed into place, and a link at the target is replaced rather than written through.
  • It imports the package when its SHA-256 differs from the recorded one or any object is missing. It records the checksum only after every object resolves by hash.
  • import_xml_data() signals failure through its return value, the global $import_messages, and per-object results, so all three are checked. That check lives in setup.php, because lib/ may not read globals.
  • A failed import is logged and doesn't block the install, the same choice plugin_cloudflare made. The upgrade check compares the checksum, so a changed package is imported from the next admin page view.
  • Uninstall leaves the templates and the copied files alone. Devices and graphs may still use them.

Testing

  • Unit:
    • The shipped files equal the generator's output (REQ-OBJ-003).
    • Every metric is in one graph of its type, and each data template holds only its graph's names.
    • Each data query's output fields match its graphs.
    • Every object the repository looks up is in the package, and no hash is defined twice.
    • The installer: imports and records; skips when current; re-imports when an object is missing; records nothing on importer failure or a missing profile; defers on the lock; always releases it; replaces a link instead of writing through it.
  • Integration, against real Cacti 1.2.31 and 1.2.x:
    • Install imports all 15 graph templates and copies both files.
    • A re-import leaves the row counts of all ten template tables unchanged (Ship device, data query, data, and graph templates as template XML #42's acceptance criterion).
    • An unchanged package is skipped.
    • A graph template deleted the way Cacti's Graph Templates page deletes it is restored with the same row counts.
    • A stale checksum is re-imported on upgrade.
  • Mutation checks: dropping the post-import object check, or the skip, each makes a test fail.
  • Local runs on both versions: 250 unit tests, 20 integration tests and 21 page checks pass. PHPStan level 9, the PHP 8.0 lint, REUSE and the gettext check are clean.

@coderabbitai

coderabbitai Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 29 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: f0ad6259-81e0-4e4f-a462-58f9ea158940
Commits

Reviewing files that changed from the base of the PR and between abf19d9 and 6855265.

Files selected for processing: 14

  • REUSE.toml
  • docs/PLAN.md
  • lib/DigitalOceanCatalog.php
  • lib/TemplateRepository.php
  • lib/Templates.php
  • setup.php
  • templates/cloud_digitalocean.xml
  • templates/resource/cloud_do_droplet.xml
  • templates/resource/cloud_do_load_balancer.xml
  • tests/Integration/TemplatesTest.php
  • tests/Unit/TemplateInstallTest.php
  • tests/Unit/TemplatesTest.php
  • tests/bin/generate-templates.php
  • tests/bin/lifecycle.php
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Comment thread lib/TemplateRepository.php Fixed
Comment thread tests/bin/generate-templates.php Fixed
Comment thread lib/Templates.php Fixed
@gitar-bot

gitar-bot Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

Gitar is working

Verification

Rules No rules evaluated

Functional validation Not enabled

Set up

Auto-approval Not enabled

Set up

Gitar

The catalog now names its graphs: each metric and each resource type's
collection age sits in exactly one graph. tests/bin/generate-templates.php
turns that into Cacti template XML laid out like Cacti's own export: a
"Cloud: DigitalOcean Scope" device template, a script server data query
per resource type, and a data template and graph template per graph, so
a graph's data source holds only its own metrics (ADR 0005). Every hash
is fixed, so a re-import updates the objects it created.

Install and upgrade copy the data query definitions into
<path_cacti>/resource/script_server, where Cacti 1.2 requires them, and
import the package under a lock when it changed or an object is missing.
A failed import is logged and does not hold back the install.

Unit tests compare the shipped XML with the generator's output and check
the installer's decisions. Integration tests import into a real Cacti and
show a re-import adds no rows and a deleted graph template is restored.

Closes #42

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
Cacti needs 32 hex digits to identify a template object; the first 32
of a SHA-256 over the fixed key serve as well as an MD5 and avoid a weak
hash algorithm, which SonarQube Cloud flags regardless of use. The
templates are regenerated; nothing has shipped with the old hashes.

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
@sonarqubecloud

Copy link
Copy Markdown

@somethingwithproof
somethingwithproof merged commit 988b4cc into main Nov 15, 2026
17 checks passed
@somethingwithproof
somethingwithproof deleted the feat/m3-templates branch November 15, 2026 12:48
@somethingwithproof somethingwithproof mentioned this pull request Nov 15, 2026
2 tasks
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.

Ship device, data query, data, and graph templates as template XML

2 participants