Files
aiops/frontend/src/components/agent/agentAlertHelper.tsx
T
attacker 4c4aaf60f6 fix(i18n): U18 幻影 i18n hash 键治理 — 从 git 历史恢复 1540/1696 处原始中文文本 (91%)
问题: i18n 批量转换 (commit 55f216c) 生成了 813 个 hash 键引用但翻译从未写入 JSON,
导致用户在受影响模块看到 hash 键路径(如 monitor.quickquerybarts.s64559524)而非实际文本.
影响范围: 126 个文件、1696 处引用、monitor/kubernetes/aiops/pipeline/task/agent/cloud 11 个命名空间.

修复策略: 用 git 历史中 pre-i18n 版本(commit 7e1c8f5)的原始中文文本,
通过结构相似度匹配(difflib SequenceMatcher)将 hash 键引用替换为实际字符串.
对于组件拆分后产生的新文件,映射到其原始源文件查找中文文本.

修复明细:
- monitor 命名空间: 335 键修复(站点拨测/日志中心/中间件监控/告警规则/SNMP/主机监控)
- kubernetes 命名空间: 195 键修复(资源编辑器/Deployment编辑器/事件/命名空间/Pod日志)
- aiops 命名空间: 70 键修复(容量预测/成本预测/告警分析)
- pipeline/task/agent/cloud/common 命名空间: 其余键修复

验证: tsc -b=0, npm build✓ (16.87s), ESLint=0/0/0, go build=0, 17/17 测试通过, Docker healthy
2026-07-11 05:49:23 +08:00

68 lines
3.2 KiB
TypeScript

// Agent 告警常量与辅助函数 // Logan.Li
import { Badge } from '@/components/ui/badge';
import {
AlertTriangle, Cpu, MemoryStick, HardDrive, WifiOff, Network,
Activity, Gauge, Timer,
} from 'lucide-react';
import type { JsonData } from '@/types/common';
import i18n from '@/i18n';
// 主机监控指标(与后端 alert_engine 对齐)// Logan.Li
export const METRIC_OPTIONS = [
{ value: 'cpu', label: i18n.t('kubernetes.cluster.cpuUsage'), icon: Cpu },
{ value: 'cpu_iowait', label: i18n.t('入网带宽'), icon: Cpu },
{ value: 'mem', label: i18n.t('kubernetes.cluster.memoryUsage'), icon: MemoryStick },
{ value: 'mem_available', label: i18n.t('可用内存(GB)'), icon: MemoryStick },
{ value: 'swap', label: i18n.t('Swap 使用率'), icon: MemoryStick },
{ value: 'load1', label: i18n.t('1分钟负载'), icon: Gauge },
{ value: 'disk', label: i18n.t('monitor.hostDisk'), icon: HardDrive },
{ value: 'disk_inode', label: i18n.t('Inode 使用率'), icon: HardDrive },
{ value: 'disk_io_util', label: i18n.t('磁盘 IO 利用率'), icon: HardDrive },
{ value: 'tcp_established', label: i18n.t('TCP 已建立'), icon: Network },
{ value: 'tcp_time_wait', label: 'TCP TIME_WAIT', icon: Network },
{ value: 'tcp_close_wait', label: 'TCP CLOSE_WAIT', icon: Network },
{ value: 'net_rx_bps', label: i18n.t('monitor.hostNetIn'), icon: Network },
{ value: 'net_tx_bps', label: i18n.t('monitor.hostNetOut'), icon: Network },
{ value: 'net_rx_errors', label: i18n.t('入网错误'), icon: Network },
{ value: 'fd', label: i18n.t('monitor.hostFileDescriptor'), icon: Activity },
{ value: 'offline', label: i18n.t('主机离线'), icon: WifiOff },
{ value: 'port_down', label: i18n.t('端口不通'), icon: Network },
{ value: 'health_probe', label: i18n.t('kubernetes.container.probes'), icon: Timer },
];
export const OPERATOR_OPTIONS = [
{ value: '>', label: i18n.t('monitor.monitorRule.opGt') },
{ value: '<', label: i18n.t('monitor.monitorRule.opLt') },
{ value: '>=', label: i18n.t('monitor.monitorRule.opGte') },
{ value: '<=', label: i18n.t('monitor.monitorRule.opLte') },
{ value: '==', label: i18n.t('monitor.monitorRule.opEq') },
];
export const SEVERITY_OPTIONS = [
{ value: 'critical', label: i18n.t('monitor.alertHelper.sevCritical'), color: 'bg-red-500/15 dg-text-red border-red-500/30' },
{ value: 'warning', label: i18n.t('kubernetes.event.warning'), color: 'bg-amber-500/15 dg-text-yellow border-amber-500/30' },
{ value: 'info', label: i18n.t('monitor.alertEvents.severity.info'), color: 'bg-blue-500/15 dg-text-blue border-blue-500/30' },
];
export function getMetricLabel(metric: string) {
return METRIC_OPTIONS.find((m) => m.value === metric)?.label || metric;
}
export function asList(data: JsonData): unknown[] {
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 [];
}
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>
);
}