Repository navigation
Harmonize the ss_mikrotik scripts with Cacti 1.2.x and develop - #140
Merged
Merged
Conversation
The ss_mikrotik_*.php scripts had drifted three ways between Cacti 1.2.x, Cacti develop and plugin_mikrotik. They are now byte-identical in all three, PHP 5.4 compatible for 1.2.x, and pass the develop PHPStan and php-cs-fixer rules. - Every script checks that its plugin table exists, returns U when there is no data, and validates requested columns against an allow-list. - ss_mikrotik_health.php takes the Hl* column names the shipped health graph templates pass. It prefers the RouterOS 7 gauge sensor in plugin_mikrotik_health_sensors when that table exists (plugin schema 3.4) and falls back to the legacy column for pre RouterOS 7 devices and older plugin versions. - ss_mikrotik_interfaces.php keeps the numeric interface index used by the shipped templates and reads the real cur* counter columns. - num_indexes is returned, not printed, so script server reindex checks see it, and the queue tree and user queries support it too. - ss_mikrotik_wireless_reg.php maps RxStrengthCh1 to the RxStrengthChl column and graphs registration uptime in seconds for both the SNMP and RouterOS API collectors. - ss_mikrotik_snmpget.php validates the OID, polls with SNMP_POLLER and returns U when the get fails. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Member
Author
|
Cacti companions: Cacti/cacti#8859 (1.2.x) and Cacti/cacti#8860 (develop). The 17 scripts are byte-identical across all three. |
Pest runs from the Cacti root, so mikrotik_test_load_functions() resolved scripts/ss_mikrotik_*.php to Cacti's own copies, which sit outside the plugin root, and the suite aborted with "Unable to resolve required plugin source". Try the plugin root first. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved collector regressions can overstate wireless uptime, select stale interface rows, and break existing interface, queue-tree, and health data sources.
5 open issues
What changed in this PR
Aligns the MikroTik script-server backends with coordinated Cacti 1.2.x and develop changes, restoring template-compatible data collection while preserving PHP 5.4 compatibility.
Changes:
- Standardizes table checks, column allow-lists, parameter binding, and unknown-value handling across 17 scripts.
- Updates health metric mapping, numeric interface indexes, wireless uptime conversion, and index-count returns.
- Adds backend regression tests and configurable table-existence mocks.
| File | Description |
|---|---|
tests/Unit/ScriptServerBackendsTest.php |
Adds health, wireless, and interface regression tests. |
tests/bootstrap-unit.php |
Makes table-existence checks configurable through fixtures. |
scripts/ss_mikrotik_wrcount.php |
Guards wireless registration counts. |
scripts/ss_mikrotik_wireless_reg.php |
Updates field mapping, uptime conversion, and missing-data handling. |
scripts/ss_mikrotik_wapcount.php |
Guards wireless access-point counts. |
scripts/ss_mikrotik_users.php |
Normalizes user-count results. |
scripts/ss_mikrotik_uptime.php |
Handles unavailable device uptime. |
scripts/ss_mikrotik_trees.php |
Guards queue-tree counts. |
scripts/ss_mikrotik_snmpget.php |
Validates numeric OIDs and handles failed reads. |
scripts/ss_mikrotik_qusers.php |
Standardizes user queries and index-count returns. |
scripts/ss_mikrotik_queues.php |
Standardizes queue queries and column validation. |
scripts/ss_mikrotik_qtrees.php |
Parameterizes tree lookups and changes index handling. |
scripts/ss_mikrotik_qcount.php |
Guards recent simple-queue counts. |
scripts/ss_mikrotik_procs.php |
Normalizes process-count results. |
scripts/ss_mikrotik_mem.php |
Handles unavailable memory measurements. |
scripts/ss_mikrotik_interfaces.php |
Uses numeric indexes and actual counter columns. |
scripts/ss_mikrotik_health.php |
Supports legacy health columns, aliases, and gauge sensors. |
scripts/ss_mikrotik_disk.php |
Handles unavailable storage measurements. |
scripts/ss_mikrotik_cpu.php |
Handles missing processor-load aggregates. |
CHANGELOG.md |
Documents script compatibility and collection changes. |
Review effort: Balanced
- The friendly health aliases keep their own RouterOS 7 sensor lists (processorTemperature reads cpu-temperature, temperature falls back to board-temperature) and their legacy fallback columns. - Interface data sources created by name still resolve, and a renamed interface's absent row no longer shadows the present one sharing its index; discovery only lists present interfaces. - Queue trees are indexed with spaces replaced by underscores, as the queues are, and the value lookup tries every stored name form, so existing customer_tree data sources keep collecting. - Numeric wireless registration uptimes are SNMP TimeTicks and are now divided by 100. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…dexes to trees and users - num_indexes runs a COUNT with the same filters as the index list rather than fetching every row on each recheck. - The queue tree and user data queries declare arg_num_indexes so index count changes trigger a reindex. - Wireless registration values come only from present registrations, so a disconnected client graphs U instead of zeroed or stale values. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
bmfmancini
approved these changes
Nov 20, 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.




Summary
The MikroTik script server data collection scripts (
scripts/ss_mikrotik_*.php) had drifted three ways between Cacti 1.2.x, Cacti develop and plugin_mikrotik. This makes all 17 scripts byte-identical in Cacti 1.2.x, Cacti develop and plugin_mikrotik. One PR goes to each of those three branches.The differences trace back to plugin_mikrotik #135 (RouterOS 7 support). It moved health collection to the
mtxrGaugeTableand wireless collection to the RouterOS API, and it copied the develop scripts into the plugin. Along the way:ss_mikrotik_health.phpwas changed to accept friendly names (voltage, ...). The shipped health data templates pass the legacy column names (HlTwelveVoltage,HlCpuTemperature,HlPower, ...), so every health data source returnedU.curInOctets, ...). The shipped templates index interfaces by the numericindex, and the table storescurRxBytes,curTxBytes, and so on, so every interfacegetreturnedU.0,falseor a fallback column instead ofUin several places.Changes
Uwhen there is no data (so health graphs aren't created with fabricated zeros), and validates requested columns against an allow-list, with values bound as parameters.Hl*column names the templates pass, plus the friendly aliases from Support RouterOS 7.x (WifiWave2 wireless + mtxrGaugeTable health) alongside 6.x, and add a Health tab #135. Ifplugin_mikrotik_health_sensorsexists (plugin schema 3.4 and later), it prefers the RouterOS 7 gauge sensor, using the same sensor→column map as the poller'smikrotik_gauge_health_column(). Otherwise, and for pre RouterOS 7 devices, it reads the legacy column.num_indexes: returned rather than printed, so script server reindex checks see it.RxStrengthCh1→RxStrengthChl(a historical column-name typo) and converts the storedd:h:m:suptime to seconds, so the SNMP and RouterOS API collectors both graph it.SNMP_POLLER, and returnsUwhen the get fails.The device template packages (
templates/*.xml.gz) are not regenerated here. That stays the final step once these scripts are merged everywhere.Testing
ScriptServerBackendsTestcovers health on pre-3.4 and 3.4+ schemas,Uwhen there's no data, the column allow-lists, the wireless uptime/column mapping, the interfaces index andnum_indexes, and a drift guard against the poller's gauge map. The new tests fail against the previous scripts.ScriptServerHardeningProbeTest(both modes) andInstallerKeepsShippedScriptsTestpass.ScriptsHardeningTest,InstallerKeepsShippedScriptsTestandMikrotikSqlParameterizationTestpass. PHPStan reports no errors on the scripts, php-cs-fixer is clean, and the hardening-pattern, sink-inventory and hotspot guards report nothing new for these files.The unit-test
db_table_exists()stub now uses the existing db fixture mechanism (still defaults tofalse), so the schema detection can be tested.