/* eslint-disable @typescript-eslint/no-explicit-any */ // LogAlertsPanel — 日志告警规则列表 // Logan.Li import { useState, useEffect, useCallback } from 'react'; import { Button } from '@/components/ui/button'; import { Badge } from '@/components/ui/badge'; import { Card, CardContent } from '@/components/ui/card'; import { Plus, Pencil, Trash2, RefreshCw, Loader2 } from 'lucide-react'; import { useToast } from '@/hooks/use-toast'; import { useConfirm } from '@/components/ui/confirm-dialog'; import { alertApi } from '@/api'; import { AlertRuleDialog } from '@/components/monitor/AlertRuleDialog'; import i18n from '@/i18n'; export function LogAlertsPanel() { const { toast } = useToast(); const confirm = useConfirm(); const [rules, setRules] = useState([]); const [channels, setChannels] = useState([]); const [loading, setLoading] = useState(true); const [dialogOpen, setDialogOpen] = useState(false); const [editing, setEditing] = useState(null); const load = useCallback(async () => { setLoading(true); try { const [rulesRes, chRes] = await Promise.all([ alertApi.getRules(), alertApi.getNotifyChannels(), ]); const all = (rulesRes as any)?.list || (Array.isArray(rulesRes) ? rulesRes : []); setRules(all.filter((r: any) => r.type === 'log' || r.source === 'loki' || r.source === 'elasticsearch')); setChannels((chRes as any)?.list || []); } finally { setLoading(false); } }, []); useEffect(() => { load(); }, [load]); const handleDelete = async (rule: any) => { const ok = await confirm({ title: i18n.t('monitor.deleteRule'), description: `删除「${rule.name}」?`, variant: 'destructive', confirmText: i18n.t('kubernetes.storage.delete2') }); if (!ok) return; try { await alertApi.deleteRule(rule.id); toast({ title: i18n.t('monitor.silenceRules.deleted') }); load(); } catch (e: any) { toast({ title: i18n.t('kubernetes.msg.deleteFailed2'), description: e?.message || String(e), variant: 'destructive' }); } }; const severityColor: Record = { critical: 'bg-red-500/15 dg-text-red', warning: 'bg-amber-500/15 dg-text-yellow', info: 'bg-blue-500/15 dg-text-blue', }; return (

{i18n.t('monitor.logalertspanelt.s5bc514d8')}

{loading ? (
) : rules.length === 0 ? ( 暂无日志告警。在 Loki/ES 查询页点击右下角「叮当」可从当前查询快速创建。 ) : (
{rules.map(rule => (
{rule.name} {rule.source || 'log'} {rule.severity} {!rule.enabled && rule.enabled !== undefined && ( {i18n.t('aiops.llmDisabled')} )}

{rule.expression}

))}
)}
); }