feat(scanner): device-type classifier (P2-03 / 26.11)#14
Merged
Conversation
Pure heuristic that maps (vendor, os fingerprint, open TCP + UDP
ports) to a coarse DeviceType label: printer / router / hypervisor /
windows-host / windows-server / windows-dc / mail-server / dns-server
/ database (mysql|postgres|mssql|mongodb|redis|memcached) / iot-broker
/ embedded / linux-host / appliance. Conservative — returns "" rather
than guess when no rule fires confidently.
The admin console templates already had {{.DeviceType}} blocks
plumbed since 26.06; they just had no data to show. Now they do.
Mechanism:
- internal/scanner/classify.go: 27 rules in priority order, with a
table-driven test for every one
- deepScan / udpScan now return their open-port lists so the per-
host goroutine has the full picture for classify()
- Re-upsert the host with DeviceType after probing completes if the
classifier returned non-empty; one extra small SQL write per live
host per cycle
Bug caught in passing:
- mockHostStore.Upsert returned the existing row unchanged on
conflict instead of mirroring the real INSERT … ON CONFLICT
UPDATE. The classifier path would have silently lost the
device_type write against any real store. Fixed.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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
Populates `Host.DeviceType` automatically. Until now the field existed in the schema and was rendered by all three admin templates, but nothing ever wrote it. After this PR the admin console shows tags like `printer`, `router`, `windows-server`, `database (postgres)`, `linux-host`, …
Pure heuristic — no new daemons, no new deps, no new network calls beyond the ones already happening. Just rules over the (vendor, os fingerprint, open-port set) tuple the scanner already collects.
Classifier rules (in priority order)
Conservative: "" beats a wrong tag.
Test plan
Notes
🤖 Generated with Claude Code