Repository navigation
mactrack: tolerate transient OUI database download failures - #415
Merged
Merged
Conversation
import_oui_database() called file() directly on the IEEE OUI URL. When the remote refused the connection, PHP raised an E_WARNING that Cacti logged as an "ERROR PHP WARNING" entry. That fails the plugin CI (which greps the Cacti log for FATAL:/ERROR:/WARNING:) and raises an alert on every transient IEEE hiccup. Add mactrack_download_oui_database(), which suppresses the file() warning (Cacti's error handler honors the @ operator, so no error entry is written), retries each URL, and falls back to the alternate IEEE endpoint that was previously defined but unused. Failures are now reported with a single INFO-level log message instead of a PHP warning. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The downloader lacks automated tests required by the 100% changed-line coverage gate, and its warning suppression still allows refused connections to produce ERROR logs on PHP 8.2+.
2 open issues
What changed in this PR
This PR aims to make Device Tracking’s IEEE OUI database import tolerate transient download failures without generating PHP warning logs.
Changes:
- Adds a download helper with retries, delays, and fallback URLs.
- Attempts warning suppression and logs failed downloads at INFO level.
- Routes the importer through the helper while preserving its existing failure handling.
| File | Description |
|---|---|
lib/mactrack_functions.php |
Adds the resilient OUI downloader and integrates it into the import flow. |
Review effort: Balanced
xmacan
previously approved these changes
Nov 10, 2026
bmfmancini
previously approved these changes
Nov 10, 2026
Addresses PR review feedback: - The @ operator is unreliable across Cacti branches: 1.2.x's CactiErrorHandler checks error_reporting() == 0, which PHP 8.0+ never produces for @, so refused connections still logged an "ERROR PHP WARNING" there. Replace the @ suppression with a local set_error_handler()/restore_error_handler() (in a finally) around file(), so the warning is captured on every supported Cacti branch and PHP version and reported only as a single INFO log. - Add tests/Unit/MactrackOuiDownloadTest.php covering success, fallback ordering, retry counts, exhaustion returning false, empty-URL filtering, the retries floor, local warning capture, the inter-attempt delay, and import_oui_database() routing through the helper. This satisfies the 100% changed-line coverage gate deterministically with local file paths instead of network access. - Add a db_qstr() stub to the unit bootstrap so import_oui_database() can be exercised in isolation. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
bmfmancini
approved these changes
Nov 10, 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.




What
Make the IEEE OUI database download in
import_oui_database()tolerant of transient connectivity failures so they no longer surface as PHP warnings.Why
import_oui_database()fetched the IEEE OUI URL with a barefile($oui_file). When IEEE refuses the connection (a common transient hiccup), PHP raises anE_WARNING, which Cacti'sCactiErrorHandlerrecords as anERROR PHP WARNINGlog entry, e.g.:The plugin CI's Check Cacti Logs for Errors step runs
grep -E "FATAL:|ERROR:|WARNING:"overcacti.log, so every transient IEEE failure fails an otherwise-unrelated pull request.What changed
Added
mactrack_download_oui_database()and call it in place of the barefile():file()warning with@. Cacti'sCactiErrorHandlerhonors the@operator (if (!(error_reporting() & $level)) return true;), so no error log entry is written — the line CI greps for is never produced.cacti_log('INFO: ...', false, 'MACTRACK', POLLER_VERBOSITY_LOW). TheINFO:prefix does not match CI'sFATAL:|ERROR:|WARNING:pattern, so the message stays visible in the log without failing CI.Downstream behavior is unchanged: on total failure the helper returns
falseand the existingis_array()path prints the usual "FAILED" status.Testing
php -lpasses.false, produces 0 handler hits (no PHP warning logged), emits INFO lines, and 0 of them match CI'sFATAL:|ERROR:|WARNING:grep.Notes for reviewers
Beyond this change, consider hardening CI so third-party network flakiness can't gate PRs — e.g. seed a local OUI fixture for the poller test, or narrow the log grep to exclude
INFO:/NOTE:lines. Migrating the fetch to Cacti's cURL-based HTTP helpers (with explicit timeout/status checks) would also give cleaner transient-vs-real error handling thanfile().