import { useState, useEffect } from 'react'; import { Card, CardContent, CardHeader, CardTitle, CardDescription } from '@/components/ui/card'; import { Button } from '@/components/ui/button'; import { Plus, Settings, Bell } from 'lucide-react'; import { ResponsiveContainer, AreaChart, Area, XAxis, YAxis, CartesianGrid, Tooltip, } from 'recharts'; import { alertApi } from '@/api'; import { AlertEventsTab } from './AlertEventsTab'; import { AlertRulesTab } from './AlertRulesTab'; import { AlertRuleDialog } from './AlertRuleDialog'; import { AlertChannelDialog } from './AlertChannelDialog'; import { PageShell } from '@/components/layout/PageShell'; import { StatStrip } from '@/components/ui/stat-strip'; import type { JsonData } from '@/types/common'; import type { AlertEventRecord, AlertRuleRecord, AlertChannel } from '@/types'; import i18n from '@/i18n'; export function AlertManager() { const [activeTab, setActiveTab] = useState('events'); const [alerts, setAlerts] = useState([]); const [rules, setRules] = useState([]); const [loading, setLoading] = useState(true); const [ruleDialogOpen, setRuleDialogOpen] = useState(false); const [editingRule, setEditingRule] = useState(null); const [channelDialogOpen, setChannelDialogOpen] = useState(false); const [notifyChannels, setNotifyChannels] = useState([]); const loadData = async () => { try { setLoading(true); const [alertsData, rulesData, channelsData] = await Promise.all([ alertApi.getAlerts(), alertApi.getRules(), alertApi.getNotifyChannels(), ]); setAlerts((alertsData as JsonData)?.list || []); setRules((rulesData as JsonData)?.list || (Array.isArray(rulesData) ? rulesData : [])); setNotifyChannels((channelsData as JsonData)?.list || []); } catch (error) { console.error('Failed to load alert data:', error); } finally { setLoading(false); } }; useEffect(() => { loadData(); }, []); const openCreateRule = () => { setEditingRule(null); setRuleDialogOpen(true); }; const openEditRule = (rule: AlertRuleRecord) => { setEditingRule(rule); setRuleDialogOpen(true); }; // 告警趋势数据 const alertTrendData = [ { time: '00:00', critical: 2, warning: 5, info: 8 }, { time: '04:00', critical: 1, warning: 3, info: 6 }, { time: '08:00', critical: 3, warning: 7, info: 12 }, { time: '12:00', critical: 5, warning: 10, info: 15 }, { time: '16:00', critical: 4, warning: 8, info: 10 }, { time: '20:00', critical: 3, warning: 6, info: 9 }, { time: '24:00', critical: 2, warning: 4, info: 7 }, ]; const pageTabs = [ { id: 'events', label: i18n.t('monitor.alertMgr2.alertEvents') }, { id: 'rules', label: i18n.t('monitor.alertRules') }, ]; return ( } tabs={pageTabs} activeTab={activeTab} onTabChange={setActiveTab} metrics={( e.status === 'firing').length, color: 'red' }, { label: i18n.t('monitor.alertMgr2.todayAlerts'), value: alerts.length, color: 'amber' }, { label: i18n.t('kubernetes.msg.uncordonSuccess'), value: alerts.filter((e) => e.status === 'resolved').length, color: 'emerald' }, ]} /> )} actions={( <> )} > {i18n.t('monitor.alertmanagertsx.s358b05d0')} {i18n.t('monitor.alertmanagertsx.s615fa6cb')}
{activeTab === 'events' && ( )} {activeTab === 'rules' && ( )}
); }