Add local SQLite database and sync with Uptime Kuma
All checks were successful
Build and Push Container / build (push) Successful in 1m4s
All checks were successful
Build and Push Container / build (push) Successful in 1m4s
Features: - SQLite database to track monitors and hosts locally - Uses Uptime Kuma tags to mark monitors as managed by Kuma Strapper - Sync on startup, before each scan, and on-demand via API - Shows existing monitors when re-scanning a host New files: - backend/services/database.py - SQLite database service - backend/services/sync.py - Sync service for Uptime Kuma reconciliation API endpoints: - POST /api/sync - Full sync with Uptime Kuma - POST /api/sync/host/<hostname> - Sync specific host - GET /api/hosts - List tracked hosts - GET /api/hosts/<hostname>/monitors - Get monitors for host - GET /api/monitors/tracked - Get all tracked monitors 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -17,6 +17,7 @@ export default function App() {
|
||||
const [scanProgress, setScanProgress] = useState({});
|
||||
const [scanResults, setScanResults] = useState({});
|
||||
const [analysisResults, setAnalysisResults] = useState({});
|
||||
const [existingMonitors, setExistingMonitors] = useState({});
|
||||
const [kumaAuth, setKumaAuth] = useState({ authenticated: false, url: '' });
|
||||
const [showKumaLogin, setShowKumaLogin] = useState(false);
|
||||
|
||||
@@ -94,6 +95,13 @@ export default function App() {
|
||||
setPendingApprovals(prev => prev.filter(r => r.id !== request.id));
|
||||
});
|
||||
|
||||
socket.on('host_sync_complete', (data) => {
|
||||
setExistingMonitors(prev => ({
|
||||
...prev,
|
||||
[data.hostname]: data.existing_monitors || [],
|
||||
}));
|
||||
});
|
||||
|
||||
return () => {
|
||||
socket.off('connect');
|
||||
socket.off('disconnect');
|
||||
@@ -105,6 +113,7 @@ export default function App() {
|
||||
socket.off('analysis_error');
|
||||
socket.off('approval_request');
|
||||
socket.off('approval_resolved');
|
||||
socket.off('host_sync_complete');
|
||||
};
|
||||
}, []);
|
||||
|
||||
@@ -183,6 +192,7 @@ export default function App() {
|
||||
scanProgress={scanProgress}
|
||||
scanResults={scanResults}
|
||||
analysisResults={analysisResults}
|
||||
existingMonitors={existingMonitors}
|
||||
devMode={settings.dev_mode}
|
||||
/>
|
||||
</main>
|
||||
|
||||
@@ -81,4 +81,13 @@ export const api = {
|
||||
body: JSON.stringify({ username, password, totp }),
|
||||
}),
|
||||
kumaLogout: () => fetchApi('/kuma/logout', { method: 'POST' }),
|
||||
|
||||
// Sync
|
||||
triggerSync: () => fetchApi('/sync', { method: 'POST' }),
|
||||
syncHost: (hostname) => fetchApi(`/sync/host/${encodeURIComponent(hostname)}`, { method: 'POST' }),
|
||||
|
||||
// Hosts and tracked monitors
|
||||
getHosts: () => fetchApi('/hosts'),
|
||||
getHostMonitors: (hostname) => fetchApi(`/hosts/${encodeURIComponent(hostname)}/monitors`),
|
||||
getTrackedMonitors: () => fetchApi('/monitors/tracked'),
|
||||
};
|
||||
|
||||
@@ -3,7 +3,7 @@ import { api } from '../api/client';
|
||||
import HostCard from './HostCard';
|
||||
import DiscoveryResults from './DiscoveryResults';
|
||||
|
||||
export default function Dashboard({ scanProgress, scanResults, analysisResults, devMode }) {
|
||||
export default function Dashboard({ scanProgress, scanResults, analysisResults, existingMonitors, devMode }) {
|
||||
const [hostname, setHostname] = useState('');
|
||||
const [username, setUsername] = useState('root');
|
||||
const [port, setPort] = useState('22');
|
||||
@@ -133,6 +133,7 @@ export default function Dashboard({ scanProgress, scanResults, analysisResults,
|
||||
scanId={currentScanId}
|
||||
scan={currentScan}
|
||||
analysis={currentAnalysis}
|
||||
existingMonitors={existingMonitors?.[hostname] || []}
|
||||
devMode={devMode}
|
||||
onCommandApproved={async (command) => {
|
||||
await api.runCommand(currentScanId, command, 'User approved from UI');
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { useState } from 'react';
|
||||
import { api } from '../api/client';
|
||||
|
||||
export default function DiscoveryResults({ scanId, scan, analysis, devMode, onCommandApproved, onQuestionAnswered }) {
|
||||
export default function DiscoveryResults({ scanId, scan, analysis, existingMonitors, devMode, onCommandApproved, onQuestionAnswered }) {
|
||||
const [selectedMonitors, setSelectedMonitors] = useState([]);
|
||||
const [creatingDefaults, setCreatingDefaults] = useState(false);
|
||||
const [creatingSuggested, setCreatingSuggested] = useState(false);
|
||||
@@ -194,6 +194,66 @@ export default function DiscoveryResults({ scanId, scan, analysis, devMode, onCo
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Existing Monitors */}
|
||||
{existingMonitors && existingMonitors.length > 0 && (
|
||||
<div className="mb-6">
|
||||
<h4 className="font-medium mb-3 flex items-center gap-2">
|
||||
<svg className="w-4 h-4 text-green-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z" />
|
||||
</svg>
|
||||
Existing Monitors ({existingMonitors.length})
|
||||
<span className="text-xs text-slate-400 font-normal">
|
||||
Already tracked for this host
|
||||
</span>
|
||||
</h4>
|
||||
<div className="space-y-2">
|
||||
{existingMonitors.map((monitor, index) => (
|
||||
<div
|
||||
key={index}
|
||||
className={`p-3 rounded ${
|
||||
monitor.status === 'deleted_in_kuma'
|
||||
? 'bg-red-900/20 border border-red-800'
|
||||
: 'bg-slate-700/30 border border-slate-600'
|
||||
}`}
|
||||
>
|
||||
<div className="flex items-center gap-3">
|
||||
<span className={`w-2 h-2 rounded-full ${
|
||||
monitor.status === 'active' ? 'bg-green-400' :
|
||||
monitor.status === 'paused' ? 'bg-yellow-400' :
|
||||
monitor.status === 'deleted_in_kuma' ? 'bg-red-400' :
|
||||
'bg-slate-400'
|
||||
}`}></span>
|
||||
<span className={`px-2 py-0.5 text-xs font-medium rounded ${
|
||||
monitor.type === 'http' ? 'bg-blue-900 text-blue-200' :
|
||||
monitor.type === 'tcp' ? 'bg-green-900 text-green-200' :
|
||||
monitor.type === 'docker' ? 'bg-cyan-900 text-cyan-200' :
|
||||
monitor.type === 'push' ? 'bg-purple-900 text-purple-200' :
|
||||
monitor.type === 'ping' ? 'bg-emerald-900 text-emerald-200' :
|
||||
'bg-slate-600 text-slate-200'
|
||||
}`}>
|
||||
{monitor.type.toUpperCase()}
|
||||
{monitor.push_metric && (
|
||||
<span className="ml-1 opacity-75">({monitor.push_metric})</span>
|
||||
)}
|
||||
</span>
|
||||
<span className="text-slate-300">{monitor.name}</span>
|
||||
{monitor.status === 'deleted_in_kuma' && (
|
||||
<span className="ml-auto text-xs text-red-400">
|
||||
Deleted in Uptime Kuma
|
||||
</span>
|
||||
)}
|
||||
{monitor.status === 'paused' && (
|
||||
<span className="ml-auto text-xs text-yellow-400">
|
||||
Paused
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Suggested Monitors */}
|
||||
{analysis.monitors && analysis.monitors.length > 0 && (
|
||||
<div>
|
||||
|
||||
Reference in New Issue
Block a user