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(`/apps/${appId}/alert-rules/${ruleId}`) } // Create a new alert rule export const createAlertRule = (appId: string, data: Partial) => { return post(`/apps/${appId}/alert-rules`, { body: data }) } // Update an alert rule export const updateAlertRule = (appId: string, ruleId: string, data: Partial) => { return patch(`/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(`/apps/${appId}/alert-notification-config`) } // Save notification channel configuration export const saveNotificationConfig = (appId: string, config: NotificationConfig) => { return post(`/apps/${appId}/alert-notification-config`, { body: config }) }