mirror of
https://github.com/myronblair/jarvis
synced 2026-06-30 17:50:23 -05:00
Fix intent placeholders, add alert/agent/deploy action intents, admin search+tester
- Restore {user_title} in ~200 intents where placeholder was stripped (comma-period, em-dash variants)
- Replace 20 hardcoded Mr. Blair with {user_title} token
- Remove duplicate pve_storage and tech_ssh intents
- Add action intents: alerts_show, alerts_count, alerts_clear, agents_offline, agents_all, agents_count, deploy_status, deploy_force, pbx_status, pbx_extension
- Admin KB Intents: add search/filter bar (name/pattern/response + type/status dropdowns)
- Admin KB Intents: add TEST PATTERN button — tests any phrase client-side against full intent list
This commit is contained in:
@@ -1102,6 +1102,93 @@ if (!$reply) {
|
||||
'Automatic scan via PVE1 runs every 3 minutes.');
|
||||
$source = 'intent:network_scan';
|
||||
break;
|
||||
|
||||
case 'alerts_show':
|
||||
$activeAlerts = JarvisDB::query(
|
||||
"SELECT title, severity, message FROM alerts WHERE resolved=0 ORDER BY created_at DESC LIMIT 10"
|
||||
);
|
||||
if (!$activeAlerts) {
|
||||
$reply = "No active alerts, {$userAddr}. All systems appear nominal.";
|
||||
} else {
|
||||
$lines = array_map(fn($a) => "[{$a['severity']}] {$a['title']}: {$a['message']}", $activeAlerts);
|
||||
$reply = count($activeAlerts) . " active alert" . (count($activeAlerts)>1?'s':'') . ", {$userAddr}: " . implode('; ', $lines) . '.';
|
||||
}
|
||||
$source = 'intent:alerts_show';
|
||||
break;
|
||||
|
||||
case 'alerts_count':
|
||||
$alertCount = JarvisDB::single("SELECT COUNT(*) cnt FROM alerts WHERE resolved=0");
|
||||
$cnt = (int)($alertCount['cnt'] ?? 0);
|
||||
$reply = $cnt > 0
|
||||
? "There are currently {$cnt} unresolved alert" . ($cnt>1?'s':'') . ", {$userAddr}. Say 'show alerts' for details."
|
||||
: "No active alerts at this time, {$userAddr}. All systems nominal.";
|
||||
$source = 'intent:alerts_count';
|
||||
break;
|
||||
|
||||
case 'alerts_clear':
|
||||
$cleared = JarvisDB::single("SELECT COUNT(*) cnt FROM alerts WHERE resolved=0");
|
||||
JarvisDB::execute("UPDATE alerts SET resolved=1 WHERE resolved=0");
|
||||
$cnt = (int)($cleared['cnt'] ?? 0);
|
||||
$reply = "Resolved {$cnt} alert" . ($cnt!==1?'s':'') . ", {$userAddr}. Alert panel cleared.";
|
||||
$source = 'intent:alerts_clear';
|
||||
break;
|
||||
|
||||
case 'agents_offline':
|
||||
$offline = JarvisDB::query(
|
||||
"SELECT hostname, ip_address, agent_type FROM registered_agents WHERE status='offline' ORDER BY last_seen DESC LIMIT 10"
|
||||
);
|
||||
if (!$offline) {
|
||||
$reply = "All registered agents are currently online, {$userAddr}.";
|
||||
} else {
|
||||
$names = array_map(fn($a) => $a['hostname'] . ' (' . $a['ip_address'] . ')', $offline);
|
||||
$reply = count($offline) . " agent" . (count($offline)>1?'s are':' is') . " offline, {$userAddr}: " . implode(', ', $names) . '.';
|
||||
}
|
||||
$source = 'intent:agents_offline';
|
||||
break;
|
||||
|
||||
case 'agents_all':
|
||||
$allAgents = JarvisDB::query(
|
||||
"SELECT hostname, ip_address, status, agent_type FROM registered_agents ORDER BY FIELD(status,'online','offline','unknown'), hostname ASC"
|
||||
);
|
||||
if (!$allAgents) {
|
||||
$reply = "No registered agents found, {$userAddr}.";
|
||||
} else {
|
||||
$onlineList = array_filter($allAgents, fn($a) => $a['status'] === 'online');
|
||||
$offlineList = array_filter($allAgents, fn($a) => $a['status'] !== 'online');
|
||||
$reply = count($allAgents) . " registered agents — " . count($onlineList) . " online, " . count($offlineList) . " offline, {$userAddr}.";
|
||||
if ($onlineList) $reply .= ' Online: ' . implode(', ', array_map(fn($a) => $a['hostname'], $onlineList)) . '.';
|
||||
if ($offlineList) $reply .= ' Offline: ' . implode(', ', array_map(fn($a) => $a['hostname'], $offlineList)) . '.';
|
||||
}
|
||||
$source = 'intent:agents_all';
|
||||
break;
|
||||
|
||||
case 'agents_count':
|
||||
$agentStats = JarvisDB::single(
|
||||
"SELECT COUNT(*) total, SUM(status='online') online FROM registered_agents"
|
||||
);
|
||||
$t = (int)($agentStats['total'] ?? 0);
|
||||
$o = (int)($agentStats['online'] ?? 0);
|
||||
$reply = "{$t} agents registered — {$o} online, " . ($t-$o) . " offline, {$userAddr}.";
|
||||
$source = 'intent:agents_count';
|
||||
break;
|
||||
|
||||
case 'deploy_status':
|
||||
$deployLog = '/home/jarvis.orbishosting.com/logs/deploy.log';
|
||||
if (file_exists($deployLog)) {
|
||||
$lines = array_filter(array_map('trim', array_slice(file($deployLog), -20)));
|
||||
$recent = array_slice(array_values($lines), -5);
|
||||
$last = end($recent);
|
||||
$reply = "Last deploy entry, {$userAddr}: " . htmlspecialchars_decode(strip_tags($last)) . '. Say "deploy log" to see the full recent history.';
|
||||
} else {
|
||||
$reply = "Deploy log not found, {$userAddr}. Check /home/jarvis.orbishosting.com/logs/deploy.log on the server.";
|
||||
}
|
||||
$source = 'intent:deploy_status';
|
||||
break;
|
||||
|
||||
case 'deploy_force':
|
||||
$reply = "Manual deploy is triggered by pushing to the GitHub main branch, {$userAddr}. The webhook at jarvis.orbishosting.com/webhook.php handles it automatically within 60 seconds. To hot-fix without a push, SCP the file directly to the server.";
|
||||
$source = 'intent:deploy_force';
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user