Files
aiops/frontend/src/components/agent/agentAlertHelper.tsx
T

55 lines
2.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Agent 告警常量与辅助函数(从 AgentAlerts.tsx 提取) // Logan.Li
import { Badge } from '@/components/ui/badge';
import { AlertTriangle, Cpu, MemoryStick, HardDrive, WifiOff, Network } from 'lucide-react';
// 监控指标选项(含图标,告警事件/规则/编辑弹窗共用) // Logan.Li
export const METRIC_OPTIONS = [
{ value: 'cpu', label: 'CPU', icon: Cpu },
{ value: 'mem', label: '内存', icon: MemoryStick },
{ value: 'disk', label: '磁盘', icon: HardDrive },
{ value: 'offline', label: '主机离线', icon: WifiOff },
{ value: 'port_down', label: '端口不通', icon: Network },
];
// 比较运算符选项 // Logan.Li
export const OPERATOR_OPTIONS = [
{ value: '>', label: '> 大于' },
{ value: '<', label: '< 小于' },
{ value: '>=', label: '≥ 大于等于' },
{ value: '<=', label: '≤ 小于等于' },
{ value: '==', label: '= 等于' },
];
// 严重程度选项(含徽章配色) // Logan.Li
export const SEVERITY_OPTIONS = [
{ value: 'critical', label: '严重', color: 'bg-red-500/15 text-red-400 border-red-500/30' },
{ value: 'warning', label: '警告', color: 'bg-amber-500/15 text-amber-400 border-amber-500/30' },
{ value: 'info', label: '提示', color: 'bg-blue-500/15 text-blue-400 border-blue-500/30' },
];
// 获取指标中文标签 // Logan.Li
export function getMetricLabel(metric: string) {
return METRIC_OPTIONS.find((m) => m.value === metric)?.label || metric;
}
// 兼容多种列表响应格式(数组 / {list} / {items} / {data}) // Logan.Li
export function asList(data: any): any[] {
if (!data) return [];
if (Array.isArray(data)) return data;
if (Array.isArray(data.list)) return data.list;
if (Array.isArray(data.items)) return data.items;
if (Array.isArray(data.data)) return data.data;
return [];
}
// 严重程度徽章(告警事件 + 规则列表共用) // Logan.Li
export function severityBadge(sev: string) {
const opt = SEVERITY_OPTIONS.find((s) => s.value === sev) || SEVERITY_OPTIONS[1];
return (
<Badge className={opt.color}>
<AlertTriangle className="h-3 w-3 mr-1" />
{opt.label}
</Badge>
);
}