From d97a3456721245d14cc74d6d38a3e03f2b3446a1 Mon Sep 17 00:00:00 2001 From: Myron Blair Date: Sat, 18 Jul 2026 19:52:34 -0500 Subject: [PATCH] Fix network map duplicate-device bug: drop nmap --send-ip (was causing MAC misattribution/stale ARP entries) and dedupe network_devices by MAC on every scan push so IP changes don't leave orphaned rows Co-Authored-By: Claude Sonnet 5 --- agent/pve1-probes/jarvis-netscan.sh | 2 +- api/endpoints/netscan.php | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/agent/pve1-probes/jarvis-netscan.sh b/agent/pve1-probes/jarvis-netscan.sh index 57ecbab..7b66277 100644 --- a/agent/pve1-probes/jarvis-netscan.sh +++ b/agent/pve1-probes/jarvis-netscan.sh @@ -12,7 +12,7 @@ fi SUBNET="10.48.200.0/24" TMPFILE=$(mktemp) -nmap -sn --send-ip "$SUBNET" 2>/dev/null > "$TMPFILE" +nmap -sn "$SUBNET" 2>/dev/null > "$TMPFILE" if [ ! -s "$TMPFILE" ]; then echo "$(date): nmap produced no output" >&2 diff --git a/api/endpoints/netscan.php b/api/endpoints/netscan.php index ed71a56..5bb6628 100644 --- a/api/endpoints/netscan.php +++ b/api/endpoints/netscan.php @@ -35,6 +35,11 @@ foreach ($devices as $d) { if (!$ip) continue; $discoveredIPs[] = $ip; + if ($mac) { + // Device likely moved to a new IP (DHCP) — drop the stale row so it + // doesn't linger as an orphaned duplicate under the old address. + JarvisDB::execute('DELETE FROM network_devices WHERE mac=? AND ip<>?', [$mac, $ip]); + } JarvisDB::execute( 'INSERT INTO network_devices (ip, mac, hostname, status, last_seen) VALUES (?,?,?,?,NOW())