Files
aiops/backend/static/assets/AlertRuleDialog-CkgDI_88.js
T
Logan.Li 921b44d6a4 chore: 同步 embed 静态资源(base=/ 修复深链白屏)
二进制 / K8s embed 模式 go:embed 使用 backend/static
2026-06-26 11:04:50 +08:00

15 lines
11 KiB
JavaScript

import{j as e,J as R,r as d,D as v,a as w,b as k,c as S,d as _,e as C,B as g,L}from"./index-BTQygws6.js";import{I as x}from"./input-C6mE-wO9.js";import{L as n}from"./label-8e-EC7mH.js";import{T as E}from"./textarea-DDxE7TMs.js";import{S as P}from"./switch-8l7ThrsD.js";import{a as A}from"./alert-BgGvEFrj.js";import{M as T}from"./message-square-C0PKhW_h.js";import{P as I,M as B}from"./phone-DFQ2ZxxE.js";function D(o){if(!o)return[];if(Array.isArray(o))return o;if(typeof o=="string"){try{const r=JSON.parse(o);if(Array.isArray(r))return r}catch{}return o.split(",").map(r=>r.trim()).filter(Boolean)}return[]}const F=["email","sms","dingtalk","wechat","webhook"],q={dingtalk:"钉钉",wechat:"企业微信",email:"邮件",sms:"短信",webhook:"Webhook"};function H(o,r){if(!o)return null;const a=r.find(c=>String(c.id)===String(o));return a?{type:a.type||"unknown",name:a.name||a.type||"未命名",isLegacy:!1}:F.includes(o)?{type:o,name:q[o]||o,isLegacy:!0}:null}const M=[{key:"dingtalk",label:"钉钉",placeholder:`{
"webhook": "https://oapi.dingtalk.com/robot/send?access_token=***",
"secret": "SECxxx"
}`},{key:"wechat",label:"企业微信",placeholder:`{
"webhook": "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=***"
}`},{key:"email",label:"邮件",placeholder:`{
"to": "ops@ezops.io",
"subject": "告警通知"
}`},{key:"sms",label:"短信",placeholder:`{
"phones": "13800138000",
"sign": "AIOps"
}`},{key:"webhook",label:"Webhook",placeholder:`{
"url": "https://example.com/alert"
}`}];function y(o){return M.find(r=>r.key===o)?.label||o}function j(o){switch(o){case"email":return B;case"sms":return I;case"dingtalk":case"wechat":return T;default:return R}}function U(o,r){const a=D(o.notify_channels);return a.length===0?e.jsx("span",{"code-path":"src/components/monitor/alertShared.tsx:76:33",className:"text-xs text-slate-600",children:"--"}):e.jsx("div",{"code-path":"src/components/monitor/alertShared.tsx:78:5",className:"flex flex-wrap gap-1",children:a.map(c=>{const i=H(c,r);if(!i)return null;const t=j(i.type);return e.jsxs("span",{"code-path":"src/components/monitor/alertShared.tsx:84:11",title:`${i.name} (${y(i.type)})`,className:"inline-flex items-center gap-1 text-xs px-1.5 py-0.5 rounded bg-slate-800 text-slate-300",children:[e.jsx(t,{"code-path":"src/components/monitor/alertShared.tsx:89:13",className:"h-3 w-3 text-slate-400"}),i.name]},c)})})}const b={name:"",description:"",type:"metric",source:"prometheus",expression:"",severity:"warning",duration:300,notify_channels:[]};function Z({open:o,onOpenChange:r,editingRule:a,notifyChannels:c,onSaved:i}){const[t,l]=d.useState({...b}),[h,u]=d.useState(!1);d.useEffect(()=>{o&&l(a?{name:a.name||"",description:a.description||"",type:a.type||"metric",source:a.source||"prometheus",expression:a.expression||"",severity:a.severity||"warning",duration:a.duration||300,notify_channels:D(a.notify_channels)}:{...b})},[o,a]);const f=s=>{l(m=>({...m,notify_channels:m.notify_channels.includes(s)?m.notify_channels.filter(p=>p!==s):[...m.notify_channels,s]}))},N=async()=>{if(!(!t.name.trim()||!t.expression.trim())){u(!0);try{const s={name:t.name.trim(),description:t.description.trim(),type:t.type,source:t.source,expression:t.expression.trim(),severity:t.severity,duration:Number(t.duration)||0,notify_channels:t.notify_channels};a?await A.updateRule(a.id,s):await A.createRule(s),r(!1),i()}catch(s){console.error("Failed to save rule:",s)}finally{u(!1)}}};return e.jsx(v,{"code-path":"src/components/monitor/AlertRuleDialog.tsx:103:5",open:o,onOpenChange:r,children:e.jsxs(w,{"code-path":"src/components/monitor/AlertRuleDialog.tsx:104:7",className:"bg-slate-900 border-slate-700 text-slate-100 max-w-lg",children:[e.jsxs(k,{"code-path":"src/components/monitor/AlertRuleDialog.tsx:105:9",children:[e.jsx(S,{"code-path":"src/components/monitor/AlertRuleDialog.tsx:106:11",className:"text-slate-100",children:a?"编辑告警规则":"新建告警规则"}),e.jsx(_,{"code-path":"src/components/monitor/AlertRuleDialog.tsx:109:11",className:"text-slate-500",children:a?"修改告警规则的触发条件和通知方式":"配置监控指标的告警触发条件"})]}),e.jsxs("div",{"code-path":"src/components/monitor/AlertRuleDialog.tsx:114:9",className:"space-y-4 max-h-[60vh] overflow-y-auto pr-1",children:[e.jsxs("div",{"code-path":"src/components/monitor/AlertRuleDialog.tsx:115:11",className:"space-y-1.5",children:[e.jsxs(n,{"code-path":"src/components/monitor/AlertRuleDialog.tsx:116:13",className:"text-slate-300",children:["规则名称 ",e.jsx("span",{"code-path":"src/components/monitor/AlertRuleDialog.tsx:116:52",className:"text-red-400",children:"*"})]}),e.jsx(x,{"code-path":"src/components/monitor/AlertRuleDialog.tsx:117:13",value:t.name,onChange:s=>l({...t,name:s.target.value}),placeholder:"如:CPU 使用率告警",className:"bg-slate-800/50 border-slate-700 text-slate-200 placeholder:text-slate-600"})]}),e.jsxs("div",{"code-path":"src/components/monitor/AlertRuleDialog.tsx:125:11",className:"space-y-1.5",children:[e.jsx(n,{"code-path":"src/components/monitor/AlertRuleDialog.tsx:126:13",className:"text-slate-300",children:"描述"}),e.jsx(E,{"code-path":"src/components/monitor/AlertRuleDialog.tsx:127:13",value:t.description,onChange:s=>l({...t,description:s.target.value}),placeholder:"规则说明",rows:2,className:"bg-slate-800/50 border-slate-700 text-slate-200 placeholder:text-slate-600 resize-none"})]}),e.jsxs("div",{"code-path":"src/components/monitor/AlertRuleDialog.tsx:136:11",className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{"code-path":"src/components/monitor/AlertRuleDialog.tsx:137:13",className:"space-y-1.5",children:[e.jsx(n,{"code-path":"src/components/monitor/AlertRuleDialog.tsx:138:15",className:"text-slate-300",children:"规则类型"}),e.jsxs("select",{"code-path":"src/components/monitor/AlertRuleDialog.tsx:139:15",value:t.type,onChange:s=>l({...t,type:s.target.value}),className:"w-full h-9 px-3 rounded-md bg-slate-800/50 border border-slate-700 text-slate-200 text-sm",children:[e.jsx("option",{"code-path":"src/components/monitor/AlertRuleDialog.tsx:144:17",value:"metric",children:"指标监控"}),e.jsx("option",{"code-path":"src/components/monitor/AlertRuleDialog.tsx:145:17",value:"log",children:"日志告警"}),e.jsx("option",{"code-path":"src/components/monitor/AlertRuleDialog.tsx:146:17",value:"event",children:"事件告警"})]})]}),e.jsxs("div",{"code-path":"src/components/monitor/AlertRuleDialog.tsx:149:13",className:"space-y-1.5",children:[e.jsx(n,{"code-path":"src/components/monitor/AlertRuleDialog.tsx:150:15",className:"text-slate-300",children:"数据源"}),e.jsxs("select",{"code-path":"src/components/monitor/AlertRuleDialog.tsx:151:15",value:t.source,onChange:s=>l({...t,source:s.target.value}),className:"w-full h-9 px-3 rounded-md bg-slate-800/50 border border-slate-700 text-slate-200 text-sm",children:[e.jsx("option",{"code-path":"src/components/monitor/AlertRuleDialog.tsx:156:17",value:"prometheus",children:"Prometheus"}),e.jsx("option",{"code-path":"src/components/monitor/AlertRuleDialog.tsx:157:17",value:"zabbix",children:"Zabbix"}),e.jsx("option",{"code-path":"src/components/monitor/AlertRuleDialog.tsx:158:17",value:"custom",children:"自定义"})]})]})]}),e.jsxs("div",{"code-path":"src/components/monitor/AlertRuleDialog.tsx:163:11",className:"space-y-1.5",children:[e.jsxs(n,{"code-path":"src/components/monitor/AlertRuleDialog.tsx:164:13",className:"text-slate-300",children:["触发表达式 ",e.jsx("span",{"code-path":"src/components/monitor/AlertRuleDialog.tsx:164:53",className:"text-red-400",children:"*"})]}),e.jsx(x,{"code-path":"src/components/monitor/AlertRuleDialog.tsx:165:13",value:t.expression,onChange:s=>l({...t,expression:s.target.value}),placeholder:"如:cpu_usage > 80",className:"bg-slate-800/50 border-slate-700 text-slate-200 placeholder:text-slate-600 font-mono text-sm"}),e.jsx("p",{"code-path":"src/components/monitor/AlertRuleDialog.tsx:171:13",className:"text-xs text-slate-600",children:"PromQL 或指标表达式,例如 cpu_usage > 80"})]}),e.jsxs("div",{"code-path":"src/components/monitor/AlertRuleDialog.tsx:174:11",className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{"code-path":"src/components/monitor/AlertRuleDialog.tsx:175:13",className:"space-y-1.5",children:[e.jsx(n,{"code-path":"src/components/monitor/AlertRuleDialog.tsx:176:15",className:"text-slate-300",children:"告警级别"}),e.jsxs("select",{"code-path":"src/components/monitor/AlertRuleDialog.tsx:177:15",value:t.severity,onChange:s=>l({...t,severity:s.target.value}),className:"w-full h-9 px-3 rounded-md bg-slate-800/50 border border-slate-700 text-slate-200 text-sm",children:[e.jsx("option",{"code-path":"src/components/monitor/AlertRuleDialog.tsx:182:17",value:"info",children:"提示"}),e.jsx("option",{"code-path":"src/components/monitor/AlertRuleDialog.tsx:183:17",value:"warning",children:"警告"}),e.jsx("option",{"code-path":"src/components/monitor/AlertRuleDialog.tsx:184:17",value:"critical",children:"严重"})]})]}),e.jsxs("div",{"code-path":"src/components/monitor/AlertRuleDialog.tsx:187:13",className:"space-y-1.5",children:[e.jsx(n,{"code-path":"src/components/monitor/AlertRuleDialog.tsx:188:15",className:"text-slate-300",children:"持续时间(秒)"}),e.jsx(x,{"code-path":"src/components/monitor/AlertRuleDialog.tsx:189:15",type:"number",value:t.duration,onChange:s=>l({...t,duration:Number(s.target.value)}),className:"bg-slate-800/50 border-slate-700 text-slate-200"})]})]}),e.jsxs("div",{"code-path":"src/components/monitor/AlertRuleDialog.tsx:198:11",className:"space-y-1.5",children:[e.jsx(n,{"code-path":"src/components/monitor/AlertRuleDialog.tsx:199:13",className:"text-slate-300",children:"通知渠道"}),c.length===0?e.jsx("div",{"code-path":"src/components/monitor/AlertRuleDialog.tsx:201:15",className:"text-xs text-amber-400/80 bg-amber-500/5 border border-amber-500/20 rounded-md px-3 py-2",children:"暂无已配置的通知渠道,请先在「通知渠道配置」中添加"}):e.jsx("div",{"code-path":"src/components/monitor/AlertRuleDialog.tsx:205:15",className:"flex flex-wrap gap-3 pt-1",children:c.map(s=>{const m=j(s.type),p=t.notify_channels.includes(String(s.id));return e.jsxs("label",{"code-path":"src/components/monitor/AlertRuleDialog.tsx:210:21",className:"flex items-center gap-2 cursor-pointer select-none text-sm text-slate-300",children:[e.jsx(P,{"code-path":"src/components/monitor/AlertRuleDialog.tsx:214:23",checked:p,onCheckedChange:()=>f(String(s.id)),className:"data-[state=checked]:bg-blue-600"}),e.jsx(m,{"code-path":"src/components/monitor/AlertRuleDialog.tsx:219:23",className:"h-4 w-4 text-slate-400"}),e.jsxs("span",{"code-path":"src/components/monitor/AlertRuleDialog.tsx:220:23",children:[s.name,e.jsxs("span",{"code-path":"src/components/monitor/AlertRuleDialog.tsx:222:25",className:"text-xs text-slate-500 ml-1",children:["(",y(s.type),")"]})]})]},s.id)})})]})]}),e.jsxs(C,{"code-path":"src/components/monitor/AlertRuleDialog.tsx:232:9",children:[e.jsx(g,{"code-path":"src/components/monitor/AlertRuleDialog.tsx:233:11",variant:"outline",className:"border-slate-700 text-slate-300 hover:bg-slate-800",onClick:()=>r(!1),children:"取消"}),e.jsxs(g,{"code-path":"src/components/monitor/AlertRuleDialog.tsx:240:11",className:"bg-blue-600 hover:bg-blue-700 text-white",disabled:!t.name.trim()||!t.expression.trim()||h,onClick:N,children:[h&&e.jsx(L,{"code-path":"src/components/monitor/AlertRuleDialog.tsx:245:28",className:"h-4 w-4 mr-2 animate-spin"}),a?"保存修改":"创建规则"]})]})]})})}export{Z as A,M as C,y as g,U as r};