Spaces:
Runtime error
Runtime error
| import axios, { AxiosInstance } from 'axios' | |
| const API_BASE = 'http://localhost:8001/api/v1' | |
| const api: AxiosInstance = axios.create({ | |
| baseURL: API_BASE, | |
| headers: { | |
| 'Content-Type': 'application/json', | |
| }, | |
| }) | |
| export interface Alert { | |
| id: string | |
| source: string | |
| title: string | |
| description?: string | |
| severity: 'CRITICAL' | 'HIGH' | 'MEDIUM' | 'LOW' | 'INFO' | |
| status: 'NEW' | 'ACKNOWLEDGED' | 'RESOLVED' | 'SUPPRESSED' | |
| affected_service?: string[] | |
| tags?: string[] | |
| created_at: string | |
| updated_at: string | |
| } | |
| export interface Incident { | |
| id: string | |
| title: string | |
| status: 'OPEN' | 'IN_PROGRESS' | 'RESOLVED' | 'CLOSED' | |
| severity: 'CRITICAL' | 'HIGH' | 'MEDIUM' | 'LOW' | |
| created_at: string | |
| updated_at: string | |
| } | |
| export interface SystemStats { | |
| total_incidents: number | |
| open_incidents: number | |
| total_alerts: number | |
| avg_mttr_minutes: number | null | |
| } | |
| export const alertsApi = { | |
| // Get all alerts | |
| getAlerts: (page = 1, perPage = 20) => | |
| api.get<{ items: Alert[]; total: number }>('/alerts', { | |
| params: { page, per_page: perPage } | |
| }), | |
| // Create alert | |
| createAlert: (data: Partial<Alert>) => | |
| api.post<Alert>('/alerts', data), | |
| // Get single alert | |
| getAlert: (id: string) => | |
| api.get<Alert>(`/alerts/${id}`), | |
| // Update alert | |
| updateAlert: (id: string, data: Partial<Alert>) => | |
| api.put<Alert>(`/alerts/${id}`, data), | |
| // Delete alert | |
| deleteAlert: (id: string) => | |
| api.delete(`/alerts/${id}`), | |
| } | |
| export const incidentsApi = { | |
| // Get all incidents | |
| getIncidents: (page = 1, perPage = 20) => | |
| api.get<{ items: Incident[]; total: number }>('/incidents', { | |
| params: { page, per_page: perPage } | |
| }), | |
| // Create incident | |
| createIncident: (data: Partial<Incident>) => | |
| api.post<Incident>('/incidents', data), | |
| // Get single incident | |
| getIncident: (id: string) => | |
| api.get<Incident>(`/incidents/${id}`), | |
| // Acknowledge incident | |
| acknowledgeIncident: (id: string) => | |
| api.post(`/incidents/${id}/acknowledge`, {}), | |
| // Resolve incident | |
| resolveIncident: (id: string) => | |
| api.post(`/incidents/${id}/resolve`, {}), | |
| } | |
| export const healthApi = { | |
| // Health check | |
| getHealth: () => | |
| api.get('/health'), | |
| // System stats | |
| getStats: () => | |
| api.get<SystemStats>('/stats'), | |
| } | |