Repository navigation
fix: show last runtime stats, keep historic VLANs in the filter, keep zero-only filters (#477, #478, #479) - #480
Merged
Conversation
… zero-only filters (#477, #478, #479) * #479: The poller stored "Time:.. ConcurrentProcesses:.. Devices:.. " with a trailing space, so splitting on single spaces gave four fields and the view's three-field check always failed, showing 0. Parse the stats by key with mactrack_parse_stats(), which accepts both the old and new format, and drop the trailing space in the poller. * #477: Every scan deleted each VLAN it did not see, while mac_track_ports and mac_track_aggregated_ports keep older sightings, so "Show: All" listed MACs whose VLAN was missing from the VLAN filter. Only remove a VLAN once no stored MAC row uses it, and backfill mac_track_vlans from stored history once (mt_vlans_backfilled) to restore VLANs already dropped. Escape the VLAN names in the filter list. * #478: Cacti 1.2 compares each request value to '0' loosely, so "00" (and "000", "0.0") was stored as '0'. Route every page through mactrack_validate_store_request_vars(), which restores zero-only text filters after core validation. Fixes #477 Fixes #478 Fixes #479 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The backfill completion flag is set even if an INSERT fails, preventing retries and potentially leaving historical VLANs missing from the filter.
1 open issue
What changed in this PR
Addresses #477–#479 in Device Tracking by correcting runtime statistics and preserving historical VLAN choices and zero-only search filters.
Changes:
- Parse runtime statistics by key and remove the poller’s trailing space.
- Retain and backfill VLANs referenced by stored MAC history; escape VLAN labels.
- Preserve zero-only text filters across 14 pages and add regression coverage.
| File | Description |
|---|---|
| tests/Unit/StatsVlanZeroFilterTest.php | Tests statistics, zero-only filters, and VLAN backfill. |
| tests/Unit/PollerSiteScopeTest.php | Updates VLAN pruning assertions. |
| tests/bootstrap-unit.php | Models core’s zero-filter behavior in test stubs. |
| poller_mactrack.php | Preserves historical VLANs and adjusts statistics output. |
| mactrack_view_sites.php | Applies the filter workaround. |
| mactrack_view_macs.php | Applies the workaround and escapes VLAN labels. |
| mactrack_view_ips.php | Applies the filter workaround. |
| mactrack_view_interfaces.php | Applies the filter workaround. |
| mactrack_view_dot1x.php | Applies the filter workaround. |
| mactrack_view_devices.php | Applies the filter workaround. |
| mactrack_view_arp.php | Applies the filter workaround. |
| mactrack_vendormacs.php | Applies the filter workaround. |
| mactrack_snmp.php | Applies the filter workaround. |
| mactrack_sites.php | Applies the filter workaround. |
| mactrack_macwatch.php | Applies the filter workaround. |
| mactrack_macauth.php | Applies the filter workaround. |
| mactrack_devices.php | Applies the filter workaround. |
| mactrack_device_types.php | Applies the filter workaround. |
| lib/mactrack_functions.php | Adds filter preservation, statistics parsing, and VLAN backfill helpers. |
Review effort: Balanced
The patch coverage gate flagged the 'clear' early return and an unreachable non-string guard in mactrack_validate_store_request_vars(). Cover the clear path and drop the guard: both allowed filters return a string from the plugin's sanitizers. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
mactrack_backfill_vlans() set mt_vlans_backfilled even when an INSERT failed, so a transient database error skipped recovery for good. Stop before setting the flag when db_execute() returns false. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add CHANGELOG entries for this pull request and move the entries added after the v5.0 tag (4c9aba9) out of the 5.0 section into a new --- develop --- section, so the 5.0 section matches what shipped. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
xmacan
approved these changes
Dec 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Fixes the three open issues reported by @CrazyNicc.
#479 – Last runtime statistics always show 0
The poller stored
Time:.. ConcurrentProcesses:.. Devices:..with a trailing space.mactrack_display_stats()split on single spaces and expected exactly three fields, so it got four and always fell back to the defaults (rendered as0).mactrack_parse_stats()parses the stored string by key (any whitespace, any order), so values already stored by older pollers display correctly right away.#477 – VLAN names missing from the MAC Addresses VLAN filter
Each collection marked every VLAN
present='0'and deleted any VLAN the current scan did not see.mac_track_ports/mac_track_aggregated_portskeep older sightings, so "Show: All" listed MACs whose VLAN was no longer in the filter.mac_track_portsormac_track_aggregated_portsstill references it (same site scoping as before).mactrack_backfill_vlans(), gated by themt_vlans_backfilledsetting) restores VLANs that existing installs have already lost. It runs in the poller (CLI), not in a web request.#478 – "00" in a filter is truncated to "0"
Cacti 1.2's
validate_store_request_vars()checksget_nfilter_request_var($variable) == '0'with a loose comparison. PHP treats"00","000","0.0"as numeric zero, so core replaces them with'0'.mactrack_validate_store_request_vars()wraps the core function and restores zero-only values for text (FILTER_CALLBACK/FILTER_DEFAULT) filters, re-running the field's own sanitizer and updating the session copy. All 14 plugin pages now use it, so every filter field is covered (IP, MAC, Portname, Search, …).=== '0'). This workaround is still needed for 1.2.x installs.Tests
tests/Unit/StatsVlanZeroFilterTest.phpcovers stats parsing (old trailing-space format), the zero-only filter workaround, and the one-time VLAN backfill.PollerSiteScopeTestupdated for the new VLAN prune statement.validate_store_request_vars()stub that reproduces core's loose'0'comparison, andget_nfilter_request_var()reads the test request store.N/AVLAN ids are skipped, and a VLAN with no stored history is still pruned.Fixes #477
Fixes #478
Fixes #479