import { useState, useEffect } from 'react'; import { Card, CardContent, CardHeader, CardTitle, CardDescription } from '@/components/ui/card'; import { Button } from '@/components/ui/button'; import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs'; import { Plus, Settings, Bell, AlertTriangle, Clock, CheckCircle } 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 type { JsonData } from '@/types/common'; 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: JsonData) => { 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 }, ]; return (
{/* Page Header */}

监控告警

告警规则管理与告警事件处理

{/* Stats Cards */}

告警规则

{rules.length}

触发中

{alerts.filter((e) => e.status === 'firing').length}

今日告警

{alerts.length}

已恢复

{alerts.filter((e) => e.status === 'resolved').length}

{/* Alert Trend Chart */} 告警趋势 过去24小时告警统计
{/* Tabs */} 告警事件 告警规则 {/* Dialogs */}
); }