| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- import { del, get, patch, post } from './base'
- // Alert Rule Types
- export type MetricType = 'error_rate' | 'avg_response_time' | 'response_time_p95' | 'response_time_p99'
- export type OperatorType = '>' | '<' | '>=' | '<=' | '='
- export type AlertRule = {
- id: string
- app_id: string
- name: string
- description: string
- is_enabled: boolean
- metric_type: MetricType
- operator: OperatorType
- threshold_value: number
- check_interval_minutes: number
- consecutive_triggers: number
- notification_channels: {
- email?: string[]
- dingtalk?: string[]
- wecom?: string[]
- }
- created_by: string
- created_at: string
- updated_at: string
- }
- export type AlertLog = {
- id: string
- rule_id: string
- triggered_at: string
- metric_value: number
- threshold_value: number
- notification_status: 'pending' | 'sent' | 'failed' | 'partial'
- notification_details: string
- }
- export type NotificationConfig = {
- email: {
- enabled?: boolean
- smtp_server?: string
- smtp_port?: number
- smtp_user?: string
- smtp_password?: string
- smtp_from_email?: string
- smtp_from_name?: string
- recipients?: string[]
- }
- dingtalk: {
- enabled?: boolean
- webhooks?: string[]
- }
- wecom: {
- enabled?: boolean
- webhooks?: string[]
- }
- }
- // Get all alert rules for an app
- export const fetchAlertRules = (appId: string) => {
- return get<{ data: AlertRule[] }>(`/apps/${appId}/alert-rules`)
- }
- // Get a specific alert rule
- export const fetchAlertRule = (appId: string, ruleId: string) => {
- return get<AlertRule>(`/apps/${appId}/alert-rules/${ruleId}`)
- }
- // Create a new alert rule
- export const createAlertRule = (appId: string, data: Partial<AlertRule>) => {
- return post<AlertRule>(`/apps/${appId}/alert-rules`, { body: data })
- }
- // Update an alert rule
- export const updateAlertRule = (appId: string, ruleId: string, data: Partial<AlertRule>) => {
- return patch<AlertRule>(`/apps/${appId}/alert-rules/${ruleId}`, { body: data })
- }
- // Delete an alert rule
- export const deleteAlertRule = (appId: string, ruleId: string) => {
- return del<{ result: string }>(`/apps/${appId}/alert-rules/${ruleId}`)
- }
- // Get alert logs for a rule
- export const fetchAlertLogs = (appId: string, ruleId: string, limit = 100) => {
- return get<{ data: AlertLog[] }>(`/apps/${appId}/alert-rules/${ruleId}/logs`, { params: { limit } })
- }
- // Get notification channel configuration
- export const fetchNotificationConfig = (appId: string) => {
- return get<NotificationConfig>(`/apps/${appId}/alert-notification-config`)
- }
- // Save notification channel configuration
- export const saveNotificationConfig = (appId: string, config: NotificationConfig) => {
- return post<NotificationConfig>(`/apps/${appId}/alert-notification-config`, { body: config })
- }
|