Files
LokiStack/frontend/src/api/alerts/index.ts
T
logan 2d73661dd1 feat: complete Loki query, insights, settings and deployment workflows
Add the Loki query UI, access policies, ingress insights, alert and registry settings, and their backend APIs. Include the related Kubernetes deployment and collector updates required by the integrated application.

Validated with go test ./..., npm run build, and npm run lint.
2026-10-25 21:28:32 +08:00

67 lines
2.3 KiB
TypeScript

// 告警域 API — 飞书通知配置 + 告警规则
import { http } from '../http'
export interface NotifyConfig {
enabled: boolean
hasWebhook: boolean
hasSecret: boolean
}
export interface AlertRule {
id: number
name: string
sourceId: number
channelIds: number[]
query: string
windowMin: number
threshold: number
enabled: boolean
cooldownMin: number
lastFiredAt?: string
createdAt?: string
}
export interface AlertDelivery {
id: number
ruleId: number
ruleName: string
count: number
status: 'sent' | 'failed' | 'cooldown'
reason: string
createdAt: string
}
export const alertsApi = {
getNotifyConfig: () => http.get<NotifyConfig>('/alerts/notify-config'),
saveNotifyConfig: (data: { enabled: boolean; webhook?: string; signingSecret?: string }) =>
http.put<{ message: string }>('/alerts/notify-config', data),
testNotifyConfig: () => http.post<{ status: string }>('/alerts/notify-config/test'),
listRules: () => http.get<AlertRule[]>('/alerts/rules'),
createRule: (data: Omit<AlertRule, 'id' | 'lastFiredAt' | 'createdAt'>) =>
http.post<AlertRule>('/alerts/rules', data),
updateRule: (id: number, data: Partial<AlertRule>) =>
http.put<AlertRule>(`/alerts/rules/${id}`, data),
deleteRule: (id: number) => http.delete<{ message: string }>(`/alerts/rules/${id}`),
checkNow: () => http.post<{ message: string }>('/alerts/check'),
deliveries: () => http.get<AlertDelivery[]>('/alerts/deliveries'),
// 通知通道(多 webhook 对应不同告警群)
listChannels: () => http.get<NotifyChannel[]>('/alerts/channels'),
saveChannel: (data: { id?: number; name: string; webhook?: string; signingSecret?: string; enabled: boolean }) =>
http.post<NotifyChannel>('/alerts/channels', data),
updateChannel: (id: number, data: { name: string; webhook?: string; signingSecret?: string; enabled: boolean }) =>
http.put<NotifyChannel>(`/alerts/channels/${id}`, data),
deleteChannel: (id: number) => http.delete<{ message: string }>(`/alerts/channels/${id}`),
testChannel: (data: { id?: number; name?: string; webhook?: string; signingSecret?: string }) =>
http.post<{ status: string }>('/alerts/channels/test', data),
}
export interface NotifyChannel {
id: number
name: string
hasWebhook: boolean
hasSecret: boolean
enabled: boolean
createdAt?: string
}