From 8b1611669038034b571afac4ce74019c7628dc9d Mon Sep 17 00:00:00 2001 From: ygx Date: Sat, 28 Mar 2026 14:24:23 +0800 Subject: [PATCH] feat --- src/api/ops/alertTemplate.ts | 206 ++++ src/router/local-menu-flat.ts | 17 + src/router/local-menu-items.ts | 18 + .../alert/template/components/RuleEditor.vue | 325 +++++++ .../components/TemplateDetailDialog.vue | 169 ++++ .../components/TemplateFormDialog.vue | 493 ++++++++++ .../ops/pages/alert/template/edit/index.vue | 708 ++++++++++++++ src/views/ops/pages/alert/template/index.vue | 893 ++++-------------- 8 files changed, 2108 insertions(+), 721 deletions(-) create mode 100644 src/api/ops/alertTemplate.ts create mode 100644 src/views/ops/pages/alert/template/components/RuleEditor.vue create mode 100644 src/views/ops/pages/alert/template/components/TemplateDetailDialog.vue create mode 100644 src/views/ops/pages/alert/template/components/TemplateFormDialog.vue create mode 100644 src/views/ops/pages/alert/template/edit/index.vue diff --git a/src/api/ops/alertTemplate.ts b/src/api/ops/alertTemplate.ts new file mode 100644 index 0000000..026b7b8 --- /dev/null +++ b/src/api/ops/alertTemplate.ts @@ -0,0 +1,206 @@ +import { request } from '@/api/request' + +// 告警模板类型定义 +export interface AlertTemplate { + id?: number + name: string + category: string + description?: string + enabled?: boolean + tags?: string + rules: AlertRule[] + channels: ChannelRef[] + suppression_rule_ids?: number[] + created_at?: string + updated_at?: string +} + +// 告警规则 +export interface AlertRule { + name: string + data_source: string + metric_name: string + rule_type: 'static' | 'dynamic' | 'promql' + compare_op: '>' | '>=' | '<' | '<=' | '==' | '!=' + threshold: string | number + duration: number + eval_interval: number + severity_code: string + labels?: Record + annotations?: Record +} + +// 通知渠道引用 +export interface ChannelRef { + channel_id: number +} + +// 通知渠道 +export interface NotificationChannel { + id: number + name: string + type: string + config?: Record + enabled?: boolean + created_at?: string + updated_at?: string +} + +// 抑制规则 +export interface SuppressionRule { + id: number + name: string + description?: string + enabled?: boolean + matchers?: Record + created_at?: string + updated_at?: string +} + +// 告警级别 +export interface AlertSeverity { + id: number + code: string + name: string + color?: string + level?: number +} + +// 指标元数据 +export interface MetricMeta { + metric_name: string + metric_unit: string + type: string + last_timestamp: string +} + +// 指标聚合响应 +export interface MetricsAggregateResponse { + data_source: string + server_identity: string + count: number + metrics: MetricMeta[] +} + +// 模板分类选项 +export const TEMPLATE_CATEGORIES = [ + { value: 'os', label: '操作系统监控模板' }, + { value: 'server_hardware', label: '服务器硬件监控模板' }, + { value: 'network_device', label: '网络设备监控模板' }, + { value: 'security_device', label: '安全设备监控模板' }, + { value: 'storage', label: '存储设备监控模板' }, + { value: 'database', label: '数据库监控模板' }, + { value: 'middleware', label: '中间件监控模板' }, + { value: 'virtualization', label: '虚拟化监控模板' }, + { value: 'power_env', label: '电力/UPS/空调/温湿度模板' }, + { value: 'safety_env', label: '消防/门禁/漏水/有害气体模板' }, +] + +// 数据源选项 +export const DATA_SOURCES = [ + { value: 'dc-host', label: '主机/操作系统指标' }, + { value: 'dc-hardware', label: '服务器硬件指标' }, + { value: 'dc-network', label: '网络设备指标' }, + { value: 'dc-database', label: '数据库指标' }, + { value: 'dc-middleware', label: '中间件指标' }, + { value: 'dc-virtualization', label: '虚拟化指标' }, + { value: 'dc-env', label: '动力/环境/安防指标' }, +] + +// 比较运算符选项 +export const COMPARE_OPERATORS = [ + { value: '>', label: '大于' }, + { value: '>=', label: '大于等于' }, + { value: '<', label: '小于' }, + { value: '<=', label: '小于等于' }, + { value: '==', label: '等于' }, + { value: '!=', label: '不等于' }, +] + +// 规则类型选项 +export const RULE_TYPES = [ + { value: 'static', label: '静态阈值' }, + { value: 'dynamic', label: '动态阈值' }, + { value: 'promql', label: 'PromQL 表达式' }, +] + +// ==================== 告警模板接口 ==================== + +/** 获取告警模板列表 */ +export const fetchTemplateList = (params?: { + page?: number + page_size?: number + name?: string + category?: string + enabled?: boolean +}) => { + return request.get('/Alert/v1/template/list', { params }) +} + +/** 获取告警模板详情 */ +export const fetchTemplateDetail = (id: number) => { + return request.get(`/Alert/v1/template/get/${id}`) +} + +/** 创建告警模板 */ +export const createTemplate = (data: AlertTemplate) => { + return request.post('/Alert/v1/template/create', data) +} + +/** 更新告警模板 */ +export const updateTemplate = (data: AlertTemplate) => { + return request.post('/Alert/v1/template/update', data) +} + +/** 删除告警模板 */ +export const deleteTemplate = (id: number) => { + return request.delete(`/Alert/v1/template/delete/${id}`) +} + +// ==================== 通知渠道接口 ==================== + +/** 获取通知渠道列表 */ +export const fetchChannelList = (params?: { enabled?: boolean; keyword?: string }) => { + return request.get('/Alert/v1/channel/list', { params }) +} + +/** 获取通知渠道详情 */ +export const fetchChannelDetail = (id: number) => { + return request.get(`/Alert/v1/channel/get/${id}`) +} + +// ==================== 抑制规则接口 ==================== + +/** 获取抑制规则列表 */ +export const fetchSuppressionList = (params?: { enabled?: boolean; keyword?: string }) => { + return request.get('/Alert/v1/suppression/list', { params }) +} + +/** 获取抑制规则详情 */ +export const fetchSuppressionDetail = (id: number) => { + return request.get(`/Alert/v1/suppression/get/${id}`) +} + +// ==================== 告警级别接口 ==================== + +/** 获取告警级别列表 */ +export const fetchSeverityList = () => { + return request.get('/Alert/v1/severity/list') +} + +/** 按 code 获取告警级别 */ +export const fetchSeverityByCode = (code: string) => { + return request.get(`/Alert/v1/severity/get-by-code/${code}`) +} + +// ==================== 指标元数据接口 ==================== + +/** 获取指标元数据 */ +export const fetchMetricsMeta = (params: { + data_source: string + server_identity?: string + keyword?: string + limit?: number +}) => { + return request.get('/DC-Control/v1/services/metrics/meta', { params }) +} \ No newline at end of file diff --git a/src/router/local-menu-flat.ts b/src/router/local-menu-flat.ts index a1928d8..7229a87 100644 --- a/src/router/local-menu-flat.ts +++ b/src/router/local-menu-flat.ts @@ -446,6 +446,23 @@ export const localMenuFlatItems: MenuItem[] = [ sort_key: 30, created_at: '2025-12-26T13:23:52.047548+08:00', }, + { + id: 4001, + identity: '019b591d-026f-785d-b473-ac804133e252', + title: '告警模版编辑', + title_en: 'Alert Template Edit', + code: 'ops:告警管理:告警模版编辑', + description: '告警管理 - 告警模版编辑', + app_id: 2, + parent_id: 39, + menu_path: '/alert/template/edit', + component: 'ops/pages/alert/template/edit/index', + menu_icon: 'appstore', + type: 1, + sort_key: 31, + hide_menu: true, + created_at: '2025-12-26T13:23:52.047548+08:00', + }, { id: 41, identity: '019b591d-027d-7eae-b9b9-23fd1b7ece75', diff --git a/src/router/local-menu-items.ts b/src/router/local-menu-items.ts index ada5899..7f58e82 100644 --- a/src/router/local-menu-items.ts +++ b/src/router/local-menu-items.ts @@ -479,6 +479,24 @@ export const localMenuItems: MenuItem[] = [ created_at: '2025-12-26T13:23:52.047548+08:00', children: [], }, + { + id: 4001, + identity: '019b591d-026f-785d-b473-ac804133e252', + title: '告警模版编辑', + title_en: 'Alert Template Edit', + code: 'ops:告警管理:告警模版编辑', + description: '告警管理 - 告警模版编辑', + app_id: 2, + parent_id: 39, + menu_path: '/alert/template/edit', + component: 'ops/pages/alert/template/edit/index', + menu_icon: 'appstore', + type: 1, + sort_key: 7, + hide_menu: true, + created_at: '2025-12-26T13:23:52.047548+08:00', + children: [], + }, { id: 41, identity: '019b591d-027d-7eae-b9b9-23fd1b7ece75', diff --git a/src/views/ops/pages/alert/template/components/RuleEditor.vue b/src/views/ops/pages/alert/template/components/RuleEditor.vue new file mode 100644 index 0000000..3b96073 --- /dev/null +++ b/src/views/ops/pages/alert/template/components/RuleEditor.vue @@ -0,0 +1,325 @@ + + + + + + + \ No newline at end of file diff --git a/src/views/ops/pages/alert/template/components/TemplateDetailDialog.vue b/src/views/ops/pages/alert/template/components/TemplateDetailDialog.vue new file mode 100644 index 0000000..6c183ab --- /dev/null +++ b/src/views/ops/pages/alert/template/components/TemplateDetailDialog.vue @@ -0,0 +1,169 @@ + + + + + + + \ No newline at end of file diff --git a/src/views/ops/pages/alert/template/components/TemplateFormDialog.vue b/src/views/ops/pages/alert/template/components/TemplateFormDialog.vue new file mode 100644 index 0000000..7794391 --- /dev/null +++ b/src/views/ops/pages/alert/template/components/TemplateFormDialog.vue @@ -0,0 +1,493 @@ + + + + + \ No newline at end of file diff --git a/src/views/ops/pages/alert/template/edit/index.vue b/src/views/ops/pages/alert/template/edit/index.vue new file mode 100644 index 0000000..18d3ef8 --- /dev/null +++ b/src/views/ops/pages/alert/template/edit/index.vue @@ -0,0 +1,708 @@ + + + + + + + \ No newline at end of file diff --git a/src/views/ops/pages/alert/template/index.vue b/src/views/ops/pages/alert/template/index.vue index 64af90d..150f782 100644 --- a/src/views/ops/pages/alert/template/index.vue +++ b/src/views/ops/pages/alert/template/index.vue @@ -17,69 +17,27 @@ > - - - -