Files
kuma-strapper/frontend/src/api/client.js
Debian 1fd29e449f
All checks were successful
Build and Push Container / build (push) Successful in 1m4s
Add local SQLite database and sync with Uptime Kuma
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>
2026-01-06 09:10:26 +00:00

94 lines
2.9 KiB
JavaScript

const API_BASE = '/api';
export async function fetchApi(endpoint, options = {}) {
const url = `${API_BASE}${endpoint}`;
const response = await fetch(url, {
headers: {
'Content-Type': 'application/json',
...options.headers,
},
...options,
});
if (!response.ok) {
const error = await response.json().catch(() => ({ error: 'Unknown error' }));
throw new Error(error.error || `HTTP ${response.status}`);
}
return response.json();
}
export const api = {
// Settings
getSettings: () => fetchApi('/settings'),
updateSettings: (settings) => fetchApi('/settings', {
method: 'PUT',
body: JSON.stringify(settings),
}),
// Scanning
startScan: (hostname, username = 'root', port = 22) => fetchApi('/scan', {
method: 'POST',
body: JSON.stringify({ hostname, username, port }),
}),
getScan: (scanId) => fetchApi(`/scan/${scanId}`),
// Commands
runCommand: (scanId, command, reason) => fetchApi(`/scan/${scanId}/command`, {
method: 'POST',
body: JSON.stringify({ command, reason }),
}),
// Approvals
getPendingApprovals: () => fetchApi('/approvals'),
approveRequest: (approvalId) => fetchApi(`/approvals/${approvalId}/approve`, {
method: 'POST',
}),
rejectRequest: (approvalId) => fetchApi(`/approvals/${approvalId}/reject`, {
method: 'POST',
}),
// Monitors
getMonitors: () => fetchApi('/monitors'),
createDefaultMonitors: (scanId) => fetchApi('/monitors/create-defaults', {
method: 'POST',
body: JSON.stringify({ scan_id: scanId }),
}),
createSuggestedMonitors: (scanId, monitorIndices) => fetchApi('/monitors/create-suggested', {
method: 'POST',
body: JSON.stringify({ scan_id: scanId, monitors: monitorIndices }),
}),
deployPushScript: (monitorId, hostname, pushMetric, options = {}) => fetchApi(`/monitors/${monitorId}/deploy-script`, {
method: 'POST',
body: JSON.stringify({
hostname,
push_metric: pushMetric,
username: options.username || 'root',
port: options.port || 22,
interval_minutes: options.intervalMinutes || 5,
}),
}),
deployAllPushScripts: (monitors) => fetchApi('/monitors/deploy-all-scripts', {
method: 'POST',
body: JSON.stringify({ monitors }),
}),
// Uptime Kuma
testKumaConnection: () => fetchApi('/kuma/test'),
getKumaAuthStatus: () => fetchApi('/kuma/auth'),
kumaLogin: (username, password, totp) => fetchApi('/kuma/login', {
method: 'POST',
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'),
};