Fix network scan: return real DB data and queue PVE1 netscan instead of fabricating

This commit is contained in:
2026-05-30 03:41:54 +00:00
parent 88dbefa831
commit e189a64ddd
+34
View File
@@ -494,6 +494,40 @@ if (!$reply) {
}
}
// ── Tier 1b: Action Intents — handled directly, no LLM ──────────────────
if (!$reply) {
if (!isset($matched)) $matched = KBEngine::match($message);
if ($matched && $matched['action'] === 'action') {
switch ($matched['intent']) {
case 'network_scan':
$online = JarvisDB::single(
"SELECT COUNT(*) cnt FROM network_devices WHERE status='online' AND last_seen > DATE_SUB(NOW(), INTERVAL 15 MINUTE)"
);
$total = JarvisDB::single(
"SELECT COUNT(*) cnt FROM network_devices WHERE last_seen > DATE_SUB(NOW(), INTERVAL 15 MINUTE)"
);
// Queue netscan to PVE1 agent for immediate refresh
$pve1 = JarvisDB::single(
"SELECT agent_id FROM registered_agents WHERE ip_address='10.48.200.90' AND status='online' LIMIT 1"
);
if ($pve1) {
JarvisDB::execute(
"INSERT INTO agent_commands (agent_id, command_type, command_data, status) VALUES (?,?,?,?)",
[$pve1['agent_id'], 'shell', json_encode(['command'=>'/usr/local/bin/jarvis-netscan.sh','allowed'=>true]), 'pending']
);
}
$o = (int)($online['cnt'] ?? 0);
$t = (int)($total['cnt'] ?? 0);
$reply = "Network status as of last scan: {$o} of {$t} devices online on 10.48.200.0/24, {$userAddr}. " .
($pve1 ? 'Fresh scan dispatched to PVE1 — the network panel will update in approximately 40 seconds.' :
'Automatic scan via PVE1 runs every 3 minutes.');
$source = 'intent:network_scan';
break;
}
}
}
// ── Tier 2: Ollama local LLM (fast local fallback) ───────────────────────
if (!$reply && defined('OLLAMA_HOST') && OLLAMA_HOST) {
$ollamaHost = OLLAMA_HOST;