Skip to content

fix(automation): cap discovery network size and check address inserts - #8662

Open
somethingwithproof wants to merge 5 commits into
developfrom
fix/automation-range-cap
Open

somethingwithproof wants to merge 5 commits into
developfrom
fix/automation-range-cap

Conversation

@somethingwithproof

@somethingwithproof somethingwithproof commented Nov 8, 2026 •

Copy link
Copy Markdown
Member

Network discovery accepted ranges of any size and loaded every address into automation_ip_address in one go, without checking the inserts. With the default 16 MB max_heap_table_size the memory table fills at about 28,000 rows, and workers then read past every claimed row on each fetch.

  • New setting "Maximum Addresses per Network" (General > Automation, default 65536). api_networks_save() rejects larger networks with the address count and the limit, and priming checks the same limit so networks saved earlier are refused rather than half loaded.
  • Address inserts go through a prepared batch helper and the result is checked; on failure poller_automation.php removes that network's rows, clears its tasks and exits instead of starting workers.
  • Ignored addresses are a keyed lookup, and the loop advances past them (an ignored address inside a range looped forever).
  • New index (network_id, status, pid) in cacti.sql, the 1.3.0 upgrade and docs/audit_schema.sql; the worker fetch now leads with network_id. On MySQL 8.4 and MariaDB 10.11, after 30,000 rows the fetch went from 30,001 index reads to one.

Verification: tests/fixtures/Core/AutomationNetworkRangeLimit.php (registered in both coverage runners) plus a Pest wrapper; fails before the fix. Automation suite 32 passed; SQL interpolation baseline refreshed (9 to 7); PHPStan clean.

Merge order: this PR and #8461, #8624 change the same lines of lib/api_automation.php, and this PR and #8461 change tests/fixtures/Core/message-formatting-expected.json. This PR and #8624 change the lib/api_automation.php lines in different ways, so no order is suggested between them; they need to be reconciled. #8461 is suggested after both. This PR and #8352, #8475, #8887 change install/upgrades/1_3_0.php. Suggested order for that file: this PR, then #8887, #8475, #8352. Whichever merges later will be rebased.

@somethingwithproof
somethingwithproof requested a review from a team as a code owner November 8, 2026 21:25
@somethingwithproof
somethingwithproof requested review from TheWitness and cigamit and removed request for a team November 8, 2026 21:25
@somethingwithproof
somethingwithproof force-pushed the fix/automation-range-cap branch 2 times, most recently from a9d3853 to 60ad2d0 Compare November 12, 2026 07:52
@somethingwithproof somethingwithproof added this to the v1.3.0 milestone Nov 13, 2026
@somethingwithproof somethingwithproof added bug Undesired behaviour automation Automation related issue labels Nov 13, 2026
@github-actions
github-actions Bot force-pushed the fix/automation-range-cap branch 3 times, most recently from 52840b9 to 6a558ed Compare November 16, 2026 20:47
@somethingwithproof somethingwithproof added release:1.3 Namespaced Cacti workflow label backport:1.2.x Contains applicable fixes still needed on 1.2.x; port only maintenance-compatible changes. labels Nov 17, 2026
@github-actions
github-actions Bot force-pushed the fix/automation-range-cap branch 2 times, most recently from cb04405 to 3751851 Compare November 20, 2026 08:48
@github-actions
github-actions Bot force-pushed the fix/automation-range-cap branch from 557e97f to 3b2e64c Compare November 25, 2026 20:47
api_networks_save() summed the addresses of a network's ranges but never
limited them, so a /8 primed 16.7M rows into the MEMORY table
automation_ips. With the default 16M max_heap_table_size the table fills
after about 28,000 rows, the failed batch INSERTs were not checked, and
the master launched workers over a partial table.

- Add the Automation setting 'Maximum Addresses per Network' (default
  65536) and reject larger networks at save time with a message naming
  the count and the limit. Priming applies the same limit, so networks
  saved earlier or imported are refused instead of half primed.
- Insert primed addresses through a prepared batch helper and stop the
  master, removing its rows, when an insert fails.
- Look ignored addresses up in a keyed array instead of in_array(), and
  advance the walk past them; an ignored address inside a range never
  advanced $count and looped for ever.
- Each worker re-read its claimed row with WHERE pid = ? AND thread = ?
  AND status = 0, which walks the pid index over every address that
  worker has already scanned (30,001 handler reads after 30,000 rows on
  MySQL 8.4 and MariaDB 10.11). Lead it with network_id and add a BTREE
  index on (network_id, status, pid); claim and fetch now read one row.

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
…insert failures

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
…ller cleanup

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
automation_ips is keyed on ip_address, so an address from an overlapping range of the same network, or of another network primed at the same time, failed the whole batch insert. With the insert result now checked, that stopped the scan. Duplicates keep their existing row; a full MEMORY table still fails the insert.

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
raise_message() escapes custom messages by default, so the caller must not
pre-escape. Read the limit into a variable so the message fixture can render
the statement, and record the rendered notification in the formatting
fixture. The range-limit probe now doubles __() instead of __esc().

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
@github-actions
github-actions Bot force-pushed the fix/automation-range-cap branch from 3b2e64c to 55725be Compare November 26, 2026 08:49
@sonarqubecloud

Copy link
Copy Markdown

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

automation Automation related issue backport:1.2.x Contains applicable fixes still needed on 1.2.x; port only maintenance-compatible changes. bug Undesired behaviour release:1.3 Namespaced Cacti workflow label

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant