File size: 2,277 Bytes
d352673
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
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'),
}