feat: add backup monitoring API client
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
import {
|
||||
BackupAlert,
|
||||
BackupDashboardSummary,
|
||||
BackupJob,
|
||||
BackupRun,
|
||||
} from "../types/backups";
|
||||
|
||||
const API_BASE = "/api";
|
||||
|
||||
export async function fetchBackupJobs(): Promise<BackupJob[]> {
|
||||
const res = await fetch(`${API_BASE}/backups/jobs`);
|
||||
if (!res.ok) throw new Error("Failed to fetch backup jobs");
|
||||
return res.json();
|
||||
}
|
||||
|
||||
export async function fetchBackupJob(jobId: string): Promise<{ job: BackupJob; runs: BackupRun[] }> {
|
||||
const res = await fetch(`${API_BASE}/backups/jobs/${jobId}`);
|
||||
if (!res.ok) throw new Error("Failed to fetch backup job");
|
||||
return res.json();
|
||||
}
|
||||
|
||||
export async function fetchBackupRuns(jobId?: string, status?: string): Promise<BackupRun[]> {
|
||||
const params = new URLSearchParams();
|
||||
if (jobId) params.append("job_id", jobId);
|
||||
if (status) params.append("status", status);
|
||||
const res = await fetch(`${API_BASE}/backups/runs?${params}`);
|
||||
if (!res.ok) throw new Error("Failed to fetch backup runs");
|
||||
return res.json();
|
||||
}
|
||||
|
||||
export async function fetchBackupRun(runId: string): Promise<BackupRun> {
|
||||
const res = await fetch(`${API_BASE}/backups/runs/${runId}`);
|
||||
if (!res.ok) throw new Error("Failed to fetch backup run");
|
||||
return res.json();
|
||||
}
|
||||
|
||||
export async function fetchBackupAlerts(
|
||||
jobId?: string,
|
||||
acknowledged?: boolean,
|
||||
severity?: string
|
||||
): Promise<BackupAlert[]> {
|
||||
const params = new URLSearchParams();
|
||||
if (jobId) params.append("job_id", jobId);
|
||||
if (acknowledged !== undefined) params.append("acknowledged", String(acknowledged));
|
||||
if (severity) params.append("severity", severity);
|
||||
const res = await fetch(`${API_BASE}/backups/alerts?${params}`);
|
||||
if (!res.ok) throw new Error("Failed to fetch backup alerts");
|
||||
return res.json();
|
||||
}
|
||||
|
||||
export async function acknowledgeBackupAlert(alertId: string): Promise<BackupAlert> {
|
||||
const res = await fetch(`${API_BASE}/backups/alerts/${alertId}/acknowledge`, {
|
||||
method: "POST",
|
||||
});
|
||||
if (!res.ok) throw new Error("Failed to acknowledge alert");
|
||||
return res.json();
|
||||
}
|
||||
|
||||
export async function fetchBackupDashboard(): Promise<BackupDashboardSummary> {
|
||||
const res = await fetch(`${API_BASE}/dashboard/backups`);
|
||||
if (!res.ok) throw new Error("Failed to fetch backup dashboard");
|
||||
return res.json();
|
||||
}
|
||||
Reference in New Issue
Block a user