Skip to content

Fix device type detection for single-criterion match patterns - #408

Merged
TheWitness merged 1 commit into
developfrom
fix/mactrack-device-type-detection
Nov 5, 2026
Merged

TheWitness merged 1 commit into
developfrom
fix/mactrack-device-type-detection

Conversation

@TheWitness

@TheWitness TheWitness commented Nov 5, 2026 •

Copy link
Copy Markdown
Member

Summary

Device type auto-detection failed when a Device Type defined only a
sysDescr match or only a sysObjectID match. find_scanning_function()
required a device to satisfy both criteria, leaning on the empty field being
treated as an implicit match. A Device Type with neither field set behaved as
a catch-all that could claim devices ahead of more specific types, and wildcard
(*) patterns let the last token decide the result instead of requiring every
token.

Fix

find_scanning_function() now matches only the criteria a Device Type actually
provides:

  • Both patterns set → the device must satisfy both.
  • Only one pattern set → the device only has to satisfy that one.
  • Neither pattern set → the type is skipped (it has no criteria to identify
    a device, and no longer steals devices from more specific types).

Matching was extracted into a small, testable helper,
mactrack_snmp_pattern_match(), which also fixes wildcard handling: a foo*bar
pattern now requires every non-empty token to be present (logical AND)
rather than letting the last token win.

Tests

  • Adds tests/Unit/FindScanningFunctionTest.php covering only-OID, only-sysDescr,
    both-required, non-matching single criterion, the no-criteria/no-steal case,
    wildcard AND semantics, and the empty/plain pattern helper behaviour.
  • Full Pest suite passes (273 tests).
  • php-cs-fixer and PHPStan (level 6) show no new issues from these changes.

Copilot AI balanced review requested due to automatic review settings November 5, 2026 20:10

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are reported for the device-type auto-detection update.

No open issues 🎉

What changed in this PR

Updates Device Tracking’s auto-detection logic to evaluate only the match criteria supplied by each device type.

Changes:

  • Handles single-criterion types explicitly, requires both criteria when present, and skips types with neither.
  • Extracts a pattern matcher that requires every non-empty wildcard token to match.
  • Adds regression tests and records the detection update in the changelog.
File Description
tests/​Unit/​FindScanningFunctionTest.php Adds coverage for criterion combinations, wildcard matching, and empty inputs.
lib/​mactrack_functions.php Extracts the pattern matcher and updates device-type selection logic.
CHANGELOG.md Documents the device-type detection update.

Review effort: Balanced

@TheWitness
TheWitness force-pushed the fix/mactrack-device-type-detection branch from 1d179d8 to 3872c2f Compare November 5, 2026 20:15
find_scanning_function() required a device to satisfy both the sysDescr
and sysObjectID match before a device type was selected. A device type
that supplied only one of the two patterns relied on the empty field
being treated as an implicit match, and an empty-on-both device type
acted as a catch-all that could claim devices ahead of more specific
types.

Match only the criteria a device type actually provides: when both
patterns are set the device must satisfy both, when only one is set the
device only has to satisfy that one, and a device type with neither is
skipped instead of matching everything. Wildcard (*) patterns now
require every token to be present rather than letting the last token win.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@TheWitness
TheWitness force-pushed the fix/mactrack-device-type-detection branch from 3872c2f to 03ef364 Compare November 5, 2026 20:18
@sonarqubecloud

sonarqubecloud Bot commented Nov 5, 2026

Copy link
Copy Markdown

@TheWitness
TheWitness merged commit 64dc70a into develop Nov 5, 2026
7 checks passed
@TheWitness
TheWitness deleted the fix/mactrack-device-type-detection branch November 5, 2026 20:44
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.

3 participants