Watch
1
0
Fork
You've already forked RedFlag
0

device-type: layered detection + laptop/vm/container types

Replaces the flat battery x display matrix (which misclassified laptops
as phones) with layered detection: container -> vm -> SMBIOS chassis ->
ARM fallback. Adds laptop, vm, container device types across agent,
migration 062, server validation, web icons/types.
This commit is contained in:
Fimeg 2026-07-12 14:55:04 -04:00
commit 1f75bfd23a
9 changed files with 374 additions and 29 deletions

View file

@ -1555,7 +1555,7 @@ func (h *AgentHandler) ReclassifyDeviceType(c *gin.Context) {
var override *string
if req.DeviceType != nil && *req.DeviceType != "" {
if !models.ValidDeviceType(*req.DeviceType) {
c.JSON(http.StatusBadRequest, gin.H{"error": "device_type must be one of: server, desktop, phone, tablet (or null to clear)"})
c.JSON(http.StatusBadRequest, gin.H{"error": "device_type must be one of: server, desktop, laptop, phone, tablet, vm, container (or null to clear)"})
return
}
override = req.DeviceType

View file

@ -0,0 +1,15 @@
-- Migration 062 down: restore the four-type enum. New classes fold to their
-- nearest legacy type so the narrower CHECK can attach.
UPDATE agents SET device_type = 'desktop' WHERE device_type = 'laptop';
UPDATE agents SET device_type = 'server' WHERE device_type IN ('vm', 'container');
UPDATE agents SET device_type_manual = 'desktop' WHERE device_type_manual = 'laptop';
UPDATE agents SET device_type_manual = 'server' WHERE device_type_manual IN ('vm', 'container');
ALTER TABLE agents DROP CONSTRAINT IF EXISTS agents_device_type_check;
ALTER TABLE agents ADD CONSTRAINT agents_device_type_check
CHECK (device_type IN ('server', 'desktop', 'phone', 'tablet'));
ALTER TABLE agents DROP CONSTRAINT IF EXISTS agents_device_type_manual_check;
ALTER TABLE agents ADD CONSTRAINT agents_device_type_manual_check
CHECK (device_type_manual IN ('server', 'desktop', 'phone', 'tablet'));

View file

@ -0,0 +1,13 @@
-- Migration 062: widen the device_type enum (DEVICE-001 follow-up).
-- Detection grew three classes: laptop (SMBIOS chassis), vm (hypervisor DMI
-- vendor/product), container (container= in PID 1 environ or
-- /run/systemd/container). 061's inline column CHECKs carry the
-- Postgres-generated names <table>_<column>_check.
ALTER TABLE agents DROP CONSTRAINT IF EXISTS agents_device_type_check;
ALTER TABLE agents ADD CONSTRAINT agents_device_type_check
CHECK (device_type IN ('server', 'desktop', 'laptop', 'phone', 'tablet', 'vm', 'container'));
ALTER TABLE agents DROP CONSTRAINT IF EXISTS agents_device_type_manual_check;
ALTER TABLE agents ADD CONSTRAINT agents_device_type_manual_check
CHECK (device_type_manual IN ('server', 'desktop', 'laptop', 'phone', 'tablet', 'vm', 'container'));

View file

@ -40,11 +40,11 @@ type Agent struct {
}
// ValidDeviceType reports whether s is a recognized device form factor.
// Mirrors the CHECK constraint from migration 061 — validate before writing
// Mirrors the CHECK constraint from migration 062 — validate before writing
// so a bad agent report degrades to the default instead of failing the row.
func ValidDeviceType(s string) bool {
switch s {
case "server", "desktop", "phone", "tablet":
case "server", "desktop", "laptop", "phone", "tablet", "vm", "container":
return true
}
return false