"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[6719,1488],{40715:(ae,B,t)=>{t.d(B,{o:()=>f});var o=t(96540),e=t(80348),A=t(97007);function f(S){const y=(0,e.useDispatch)(),N=(0,o.useRef)(S);N.current=S,(0,o.useEffect)(()=>()=>{y((0,A.N)({cleanupAction:N.current}))},[y])}},34708:(ae,B,t)=>{t.r(B),t.d(B,{default:()=>_n,findRoutesMatchingFilters:()=>zt});var o=t(32196),e=t(96540),A=t(41053),f=t(40845),S=t(63021),y=t(40675),N=t(40980),x=t(39558),M=t(42418),d=t(67061),L=t(66602),h=t(83277),v=t(80348),U=t(40715),R=t(82843),J=t(55740),ee=t(49962),le=t(68788);const de=ee.H.injectEndpoints({endpoints:n=>({contactPointsState:n.query({queryFn:async({amSourceName:a})=>{try{return{data:await(0,le.pB)(a)}}catch(r){return{error:r}}}})})}),se=n=>{const a={receivers:{},errorCount:0},{currentData:r}=de.useContactPointsStateQuery({amSourceName:n??""},{skip:!n,pollingInterval:J.cB});return r??a};var he=t(33450),ye=t(57895),ce=t(42941),z=t(55852),Re=t(96374),m=t(50720),F=t(29158),g=t(38138),V=t(64756),G=t(64853),P=t(19073),Q=t(51488),w=t(23770),re=t(56361),Qe=t(75591),rt=t(23088);const Me=({buttonIcon:n,buttonLabel:a,buttonSize:r="lg",buttonVariant:l="primary",onButtonClick:s,text:u,href:c,showButton:i=!0})=>{const p=(0,f.of)(ot),I={className:p.button,icon:n,size:r,variant:l};return e.createElement(rt.Z,null,e.createElement(e.Fragment,null,e.createElement("p",{className:p.text},u),i&&(c?e.createElement(z.z9,{href:c,type:"button",...I},a):e.createElement(z.$n,{onClick:s,type:"button",...I},a))))},ot=n=>({container:(0,o.css)`
      background-color: ${n.colors.background.secondary};
      color: ${n.colors.text.secondary};
      padding: ${n.spacing(4)};
      text-align: center;
    `,text:(0,o.css)`
      margin-bottom: ${n.spacing(2)};
    `,button:(0,o.css)`
      margin: ${n.spacing(2,0,1)};
    `});var lt=t(48205),Je=t(26058),Ye=t(79938),Be=t(16293),st=t(76648),Xe=t(84029);const it=({exportFormat:n,onClose:a})=>{const{currentData:r="",isFetching:l}=Ye.hK.useExportMuteTimingsQuery({format:n}),s=`mute-timings-${new Date().getTime()}`;return l?e.createElement(x._,{text:"Loading...."}):e.createElement(Be.J,{format:n,textDefinition:r,downloadFileName:s,onClose:a})},ct=({exportFormat:n,onClose:a,muteTimingName:r})=>{const{currentData:l="",isFetching:s}=Ye.hK.useExportMuteTimingQuery({format:n,muteTiming:r}),u=`mute-timing-${r}-${new Date().getTime()}`;return s?e.createElement(x._,{text:"Loading...."}):e.createElement(Be.J,{format:n,textDefinition:l,downloadFileName:u,onClose:a})},pe=({onClose:n,muteTimingName:a})=>{const[r,l]=(0,e.useState)("yaml");return e.createElement(st.m,{activeTab:r,onTabChange:l,onClose:n,formatProviders:Object.values(Xe.sl)},a?e.createElement(ct,{exportFormat:r,onClose:n,muteTimingName:a}):e.createElement(it,{exportFormat:r,onClose:n}))};var ie=t(4724);const Ce=Symbol("all mute timings"),xe=()=>{const[n,a]=(0,e.useState)(null),[r,l]=(0,ce.A)(!1),s=(0,e.useCallback)(()=>{a(null),l(!1)},[l]),u=i=>{a(i),l(!0)};return[(0,e.useMemo)(()=>!n||!r?null:n===Ce?e.createElement(pe,{onClose:s}):e.createElement(pe,{muteTimingName:n,onClose:s}),[r,s,n]),u]},Jt=({alertManagerSourceName:n,muteTimingNames:a,hideActions:r})=>{const l=(0,f.of)(Xt),s=(0,V.wA)(),{currentData:u}=(0,Q.f)(n,{refetchOnFocus:!0,refetchOnReconnect:!0}),c=u?.alertmanager_config,[i,p]=(0,e.useState)(""),I=(0,e.useMemo)(()=>{const k=c?.mute_time_intervals??[],X=c?.muteTimeProvenances??{};return k.filter(({name:W})=>a?a.includes(W):!0).map(W=>({id:W.name,data:{...W,provenance:X[W.name]}}))},[c?.mute_time_intervals,c?.muteTimeProvenances,a]),[C,T]=(0,P.L7)(P.QI.CreateMuteTiming),[O,E]=xe(),[D,$]=(0,P.L7)(P.QI.ExportMuteTimings),b=Yt(n,r,p,E);return e.createElement("div",{className:l.container},e.createElement(d.B,{direction:"row",alignItems:"center"},e.createElement("span",null,"Enter specific time intervals when not to send notifications or freeze notifications for recurring periods of time."),e.createElement(Je.h,null),!r&&I.length>0&&e.createElement(G._,{actions:[P.QI.CreateMuteTiming]},e.createElement(z.z9,{className:l.muteTimingsButtons,icon:"plus",variant:"primary",href:(0,re.nL)("alerting/routes/mute-timing/new",n)},"Add mute timing")),D&&e.createElement(z.$n,{icon:"download-alt",className:l.muteTimingsButtons,variant:"secondary","aria-label":"export all",disabled:!$,onClick:()=>E(Ce)},"Export all")),I.length>0?e.createElement(Qe.E,{items:I,cols:b,pagination:{itemsPerPage:25}}):r?e.createElement(Me,{text:"No mute timings configured",buttonLabel:"",showButton:!1}):e.createElement(Me,{text:"You haven't created any mute timings yet",buttonLabel:"Add mute timing",buttonIcon:"plus",buttonSize:"lg",href:(0,re.nL)("alerting/routes/mute-timing/new",n),showButton:T}),!r&&e.createElement(Re.u,{isOpen:!!i,title:"Delete mute timing",body:`Are you sure you would like to delete "${i}"`,confirmText:"Delete",onConfirm:()=>{s((0,w.$8)(n,i)),p("")},onDismiss:()=>p("")}),O)};function Yt(n,a=!1,r,l){const[[s,u],[c,i]]=(0,P.Hl)([P.QI.UpdateMuteTiming,P.QI.DeleteMuteTiming]),p=!a&&(u||i),[I,C]=(0,P.L7)(P.QI.ExportMuteTimings);return(0,e.useMemo)(()=>{const T=[{id:"name",label:"Name",renderCell:function({data:E}){return e.createElement(e.Fragment,null,E.name," ",E.provenance&&e.createElement(lt.rS,null))},size:"250px"},{id:"timeRange",label:"Time range",renderCell:({data:O})=>(0,ie.av)(O)}];return p&&T.push({id:"actions",label:"Actions",renderCell:function({data:E}){return E.provenance?e.createElement("div",null,e.createElement(m.N,{href:(0,re.nL)("/alerting/routes/mute-timing/edit",n,{muteName:E.name})},e.createElement(F.K,{name:"file-alt",tooltip:"View mute timing"}))):e.createElement("div",null,e.createElement(G._,{actions:[P.QI.UpdateMuteTiming]},e.createElement(m.N,{href:(0,re.nL)("/alerting/routes/mute-timing/edit",n,{muteName:E.name})},e.createElement(F.K,{name:"edit",tooltip:"Edit mute timing"}))),e.createElement(G._,{actions:[P.QI.DeleteMuteTiming]},e.createElement(F.K,{name:"trash-alt",tooltip:"Delete mute timing",onClick:()=>r(E.name)})))},size:"80px"}),I&&T.push({id:"actions",label:"",renderCell:function({data:E}){return e.createElement("div",null,e.createElement(g.W.Item,{icon:"download-alt",label:"Export",ariaLabel:"export",disabled:!C,"data-testid":"export",onClick:()=>l(E.name)}))},size:"100px"}),T},[n,r,p,I,C,l])}const Xt=n=>({container:(0,o.css)`
    display: flex;
    flex-flow: column nowrap;
  `,muteTimingsButtons:(0,o.css)`
    margin-bottom: ${n.spacing(2)};
    align-self: flex-end;
  `});var oe=t(2543),Y=t(88575),Zt=t(60029),Te=t(56034),Ge=t(14578),ut=t(10354),Pe=t(88323),mt=t(94753),kt=t(39964),be=t(98164),$t=t(32642);const qt=({receivers:n,onChangeReceiver:a,onChangeMatchers:r,matchingCount:l})=>{const[s,u]=(0,kt.l)(),c=(0,e.useRef)(null),{queryString:i,contactPoint:p}=tn(s),I=(0,f.of)(nn),C=(0,e.useCallback)(()=>(0,oe.debounce)(r,500),[r]);(0,e.useEffect)(()=>{a(p)},[p,a]),(0,e.useEffect)(()=>{const b=(0,be.J$)(i??"").map(be.NL);C()(b)},[C,i]);const T=(0,e.useCallback)(()=>{c.current&&(c.current.value=""),u({contactPoint:void 0,queryString:void 0})},[u]),O=n.map(en),E=O.find(b=>b.value===p)??null,D=i||p,$=i&&i.length>3?(0,be.J$)(i).length===0:!1;return e.createElement(d.B,{direction:"row",alignItems:"flex-end",gap:1},e.createElement(Y.D,{className:I.noBottom,label:e.createElement(Zt.J,null,e.createElement(d.B,{gap:.5},e.createElement("span",null,"Search by matchers"),e.createElement(Te.m,{content:e.createElement("div",null,"Filter silences by matchers using a comma separated list of matchers, ie:",e.createElement("pre",null,"severity=critical, instance=~cluster-us-.+"))},e.createElement(Ge.I,{name:"info-circle",size:"sm"})))),invalid:$,error:$?"Query must use valid matcher syntax":null},e.createElement(ut.p,{ref:c,"data-testid":"search-query-input",placeholder:"Search",width:46,prefix:e.createElement(Ge.I,{name:"search"}),onChange:b=>{u({queryString:b.currentTarget.value})},defaultValue:i})),e.createElement(Y.D,{label:"Search by contact point",style:{marginBottom:0}},e.createElement(Pe.l6,{id:"receiver","aria-label":"Search by contact point",value:E,options:O,onChange:b=>{u({contactPoint:b?.value})},width:28,isClearable:!0})),D&&e.createElement(d.B,{alignItems:"center"},e.createElement(z.$n,{variant:"secondary",icon:"times",onClick:T},"Clear filters"),e.createElement(mt.E,{variant:"bodySmall",color:"secondary"},l===0&&"No policies matching filters.",l===1&&`${l} policy matches the filters.`,l>1&&`${l} policies match the filters.`)))};function Wt(n,a){const r=new Map;function l(s,u){const c=[...u,s];if(a(s)){const i=r.get(s)??[];r.set(s,[...i,...c])}s.routes?.forEach(i=>l(i,c))}return l(n,[]),r}function _t(n,a){const r=(0,$t.J$)(n);return a.every(l=>r.some(s=>(0,oe.isEqual)(l,s)))}const en=n=>({label:n.name,value:n.name}),tn=n=>({queryString:n.get("queryString")??void 0,contactPoint:n.get("contactPoint")??void 0}),nn=()=>({noBottom:(0,o.css)({marginBottom:0})});var ge=t(37390),an=t(62930),$e=t(60021),rn=t(45067),on=t(26423),ln=t(12210),dt=t(99494),sn=t(37534);const cn=()=>{const{installed:n}=(0,ln._)(dt.W.OnCall),{data:a}=on.WG.useGrafanaOnCallIntegrationsQuery(void 0,{skip:!n});return l=>{const s=a??[];if(n&&(0,sn.p8)(l,s))return dt.W.OnCall}},Lt=n=>{const a=cn(),r=l=>({label:l.name,value:l.name,grafanaAppReceiverType:a(l)});return n.map(r)};var un=t(55127),We=t.n(un),Le=t(39938);const mn=({active:n=0,suppressed:a=0,unprocessed:r=0})=>{const l=[],s=n+a+r;return n&&l.push(e.createElement(Le.E,{color:"red",key:"firing",text:`${n} firing`})),a&&l.push(e.createElement(Le.E,{color:"blue",key:"suppressed",text:`${a} suppressed`})),r&&l.push(e.createElement(Le.E,{color:"orange",key:"unprocessed",text:`${r} unprocessed`})),l.length>1&&l.unshift(e.createElement(e.Fragment,{key:"total"},s," ",We()("instance",s))),!!l.length?e.createElement(d.B,{gap:.5},l):null};var Ft=t(51253),Ie=t(16504),dn=t(82762),H=t(79657),De=t(33915),wt=t(99903),Ze=t(27835);const pn=({actionButtons:n,alertManagerSourceName:a,onSubmit:r,receivers:l,route:s})=>{const u=(0,f.of)(wt.t),[c,i]=(0,e.useState)(!1),[p,I]=(0,e.useState)((0,H.gY)(s.group_by)),C=(0,H.YE)(s);return e.createElement(Ft.l,{defaultValues:{...C,overrideTimings:!0,overrideGrouping:!0},onSubmit:r},({register:T,control:O,errors:E,setValue:D,getValues:$})=>e.createElement(e.Fragment,null,e.createElement(Y.D,{label:"Default contact point",invalid:!!E.receiver,error:E.receiver?.message},e.createElement(e.Fragment,null,e.createElement("div",{className:u.container,"data-testid":"am-receiver-select"},e.createElement(Ie.e,{render:({field:{onChange:b,ref:k,...X}})=>e.createElement(Pe.l6,{"aria-label":"Default contact point",...X,className:u.input,onChange:W=>b((0,H.eb)(W)),options:l}),control:O,name:"receiver",rules:{required:{value:!0,message:"Required."}}}),e.createElement("span",null,"or"),e.createElement(m.N,{className:u.linkText,href:(0,re.nL)("/alerting/notifications/receivers/new",a)},"Create a contact point")))),e.createElement(Y.D,{label:"Group by",description:"Group alerts when you receive a notification based on labels.","data-testid":"am-group-select"},e.createElement(Ie.e,{render:({field:{onChange:b,ref:k,...X}})=>e.createElement(Pe.KF,{"aria-label":"Group by",...X,allowCustomValue:!0,className:u.input,onCreateOption:W=>{I(K=>[...K,(0,H.Mk)(W)]),D("groupBy",[...X.value,W])},onChange:W=>b((0,H.ie)(W)),options:[...H.Yl,...p]}),control:O,name:"groupBy"})),e.createElement(dn.S,{collapsible:!0,className:u.collapse,isOpen:c,label:"Timing options",onToggle:i},e.createElement("div",{className:u.timingFormContainer},e.createElement(Y.D,{label:"Group wait",description:"The waiting time until the initial notification is sent for a new group created by an incoming alert. Default 30 seconds.",invalid:!!E.groupWaitValue,error:E.groupWaitValue?.message,"data-testid":"am-group-wait"},e.createElement(De.V,{...T("groupWaitValue",{validate:H.hH}),placeholder:Ze.H.group_wait,className:u.promDurationInput,"aria-label":"Group wait"})),e.createElement(Y.D,{label:"Group interval",description:"The waiting time to send a batch of new alerts for that group after the first notification was sent. Default 5 minutes.",invalid:!!E.groupIntervalValue,error:E.groupIntervalValue?.message,"data-testid":"am-group-interval"},e.createElement(De.V,{...T("groupIntervalValue",{validate:H.hH}),placeholder:Ze.H.group_interval,className:u.promDurationInput,"aria-label":"Group interval"})),e.createElement(Y.D,{label:"Repeat interval",description:"The waiting time to resend an alert after they have successfully been sent. Default 4 hours. Should be a multiple of Group interval.",invalid:!!E.repeatIntervalValue,error:E.repeatIntervalValue?.message,"data-testid":"am-repeat-interval"},e.createElement(De.V,{...T("repeatIntervalValue",{validate:b=>{const k=$("groupIntervalValue");return(0,H.DY)(b,k)}}),placeholder:Ze.H.repeat_interval,className:u.promDurationInput,"aria-label":"Repeat interval"})))),e.createElement("div",{className:u.container},n)))};var gn=t(95984),pt=t(15292),En=t(72093),Nt=t(70383);function fn(){const{selectedAlertmanager:n}=(0,Nt.VI)(),{currentData:a}=(0,Q.f)(n),r=a?.alertmanager_config;return(0,e.useMemo)(()=>r?.mute_time_intervals?.map(s=>({value:s.name,label:s.name,description:s.time_intervals.map(u=>(0,be.LF)(u)).join(", AND ")}))??[],[r])}var fe=t(97174);const Ut=({actionButtons:n,receivers:a,route:r,onSubmit:l,defaults:s})=>{const u=(0,f.of)(hn),c=(0,f.of)(wt.t),[i,p]=(0,e.useState)((0,H.gY)(r?.group_by)),I=fn(),C=[{name:"",operator:$e.ho.equal,value:""}],T=a.sort(vn),O={...(0,H.YE)(r),...s},E={...O,object_matchers:r?O.object_matchers:C};return e.createElement(Ft.l,{defaultValues:E,onSubmit:l,maxWidth:"none"},({control:D,register:$,errors:b,setValue:k,watch:X,getValues:W})=>e.createElement(e.Fragment,null,e.createElement("input",{type:"hidden",...$("id")}),e.createElement(gn.E,{name:"object_matchers",control:D},({fields:K,append:ne,remove:_})=>e.createElement(e.Fragment,null,e.createElement(d.B,{direction:"column",alignItems:"flex-start"},e.createElement("div",null,"Matching labels"),K.length===0&&e.createElement(Le.E,{color:"orange",className:u.noMatchersWarning,icon:"exclamation-triangle",text:"If no matchers are specified, this notification policy will handle all alert instances."}),K.length>0&&e.createElement("div",{className:u.matchersContainer},K.map((j,q)=>e.createElement(d.B,{direction:"row",key:j.id,alignItems:"center"},e.createElement(Y.D,{label:"Label",invalid:!!b.object_matchers?.[q]?.name,error:b.object_matchers?.[q]?.name?.message},e.createElement(ut.p,{...$(`object_matchers.${q}.name`,{required:"Field is required"}),defaultValue:j.name,placeholder:"label",autoFocus:!0})),e.createElement(Y.D,{label:"Operator"},e.createElement(Ie.e,{render:({field:{onChange:Ee,ref:Z,...Ae}})=>e.createElement(Pe.l6,{...Ae,className:u.matchersOperator,onChange:we=>Ee(we?.value),options:be.xH,"aria-label":"Operator"}),defaultValue:j.operator,control:D,name:`object_matchers.${q}.operator`,rules:{required:{value:!0,message:"Required."}}})),e.createElement(Y.D,{label:"Value",invalid:!!b.object_matchers?.[q]?.value,error:b.object_matchers?.[q]?.value?.message},e.createElement(ut.p,{...$(`object_matchers.${q}.value`),defaultValue:j.value,placeholder:"value"})),e.createElement(F.K,{tooltip:"Remove matcher",name:"trash-alt",onClick:()=>_(q)},"Remove")))),e.createElement(z.$n,{className:u.addMatcherBtn,icon:"plus",onClick:()=>ne(H.Rg),variant:"secondary",type:"button"},"Add matcher")))),e.createElement(Y.D,{label:"Contact point"},e.createElement(Ie.e,{render:({field:{onChange:K,ref:ne,..._}})=>e.createElement(Pe.l6,{"aria-label":"Contact point",..._,className:c.input,onChange:j=>K((0,H.eb)(j)),options:T,isClearable:!0}),control:D,name:"receiver"})),e.createElement(Y.D,{label:"Continue matching subsequent sibling nodes"},e.createElement(pt.d,{id:"continue-toggle",...$("continue")})),e.createElement(Y.D,{label:"Override grouping"},e.createElement(pt.d,{id:"override-grouping-toggle",...$("overrideGrouping")})),X().overrideGrouping&&e.createElement(Y.D,{label:"Group by",description:"Group alerts when you receive a notification based on labels. If empty it will be inherited from the parent policy."},e.createElement(Ie.e,{rules:{validate:K=>!K||K.length===0?"At least one group by option is required.":!0},render:({field:{onChange:K,ref:ne,..._},fieldState:{error:j}})=>e.createElement(e.Fragment,null,e.createElement(Pe.KF,{"aria-label":"Group by",..._,invalid:!!j,allowCustomValue:!0,className:c.input,onCreateOption:q=>{p(Ee=>[...Ee,(0,H.Mk)(q)]),k("groupBy",[..._.value,q])},onChange:q=>K((0,H.ie)(q)),options:[...H.Yl,...i]}),j&&e.createElement(En.P,null,j.message)),control:D,name:"groupBy"})),e.createElement(Y.D,{label:"Override general timings"},e.createElement(pt.d,{id:"override-timings-toggle",...$("overrideTimings")})),X().overrideTimings&&e.createElement(e.Fragment,null,e.createElement(Y.D,{label:fe.G.groupWait.label,description:fe.G.groupWait.description,invalid:!!b.groupWaitValue,error:b.groupWaitValue?.message},e.createElement(De.V,{...$("groupWaitValue",{validate:H.hH}),"aria-label":fe.G.groupWait.ariaLabel,className:c.promDurationInput})),e.createElement(Y.D,{label:fe.G.groupInterval.label,description:fe.G.groupInterval.description,invalid:!!b.groupIntervalValue,error:b.groupIntervalValue?.message},e.createElement(De.V,{...$("groupIntervalValue",{validate:H.hH}),"aria-label":fe.G.groupInterval.ariaLabel,className:c.promDurationInput})),e.createElement(Y.D,{label:fe.G.repeatInterval.label,description:fe.G.repeatInterval.description,invalid:!!b.repeatIntervalValue,error:b.repeatIntervalValue?.message},e.createElement(De.V,{...$("repeatIntervalValue",{validate:(K="")=>{const ne=W("groupIntervalValue");return(0,H.DY)(K,ne)}}),"aria-label":fe.G.repeatInterval.ariaLabel,className:c.promDurationInput}))),e.createElement(Y.D,{label:"Mute timings","data-testid":"am-mute-timing-select",description:"Add mute timing to policy",invalid:!!b.muteTimeIntervals},e.createElement(Ie.e,{render:({field:{onChange:K,ref:ne,..._}})=>e.createElement(Pe.KF,{"aria-label":"Mute timings",..._,className:c.input,onChange:j=>K((0,H.ie)(j)),options:I}),control:D,name:"muteTimeIntervals"})),n))};function vn(n){return n.grafanaAppReceiverType===dt.W.OnCall?-1:0}const hn=n=>{const a=n.spacing(3.5);return{addMatcherBtn:(0,o.css)`
      margin-bottom: ${a};
    `,matchersContainer:(0,o.css)`
      background-color: ${n.colors.background.secondary};
      padding: ${n.spacing(1.5)} ${n.spacing(2)};
      padding-bottom: 0;
      width: fit-content;
    `,matchersOperator:(0,o.css)`
      min-width: 120px;
    `,noMatchersWarning:(0,o.css)`
      padding: ${n.spacing(1)} ${n.spacing(2)};
      margin-bottom: ${n.spacing(1)};
    `}};var Vt=t(26928);const yn=(n=[],a,r)=>{const[l,s]=(0,e.useState)(!1),[u,c]=(0,e.useState)(),i=Lt(n),p=(0,e.useCallback)(()=>{c(void 0),s(!1)},[]),I=(0,e.useCallback)(T=>{c(T),s(!0)},[]);return[(0,e.useMemo)(()=>r?e.createElement(gt,{isOpen:l}):e.createElement(ge.a,{isOpen:l,onDismiss:p,closeOnBackdropClick:!0,closeOnEscape:!0,title:"Add notification policy"},e.createElement(Ut,{receivers:i,defaults:{groupBy:u?.group_by},onSubmit:T=>u&&a(T,u),actionButtons:e.createElement(ge.a.ButtonRow,null,e.createElement(z.$n,{type:"button",variant:"secondary",onClick:p,fill:"outline"},"Cancel"),e.createElement(z.$n,{type:"submit"},"Save policy"))})),[i,a,p,r,u,l]),I,p]},Mn=(n,a,r,l)=>{const[s,u]=(0,e.useState)(!1),[c,i]=(0,e.useState)(!1),[p,I]=(0,e.useState)(),C=Lt(a),T=(0,e.useCallback)(()=>{I(void 0),u(!1)},[]),O=(0,e.useCallback)((D,$)=>{i($??!1),I(D),u(!0)},[]);return[(0,e.useMemo)(()=>l?e.createElement(gt,{isOpen:s}):e.createElement(ge.a,{isOpen:s,onDismiss:T,closeOnBackdropClick:!0,closeOnEscape:!0,title:"Edit notification policy"},c&&p&&e.createElement(pn,{alertManagerSourceName:n,onSubmit:r,receivers:C,route:p,actionButtons:e.createElement(ge.a.ButtonRow,null,e.createElement(z.$n,{type:"button",variant:"secondary",onClick:T,fill:"outline"},"Cancel"),e.createElement(z.$n,{type:"submit"},"Update default policy"))}),!c&&e.createElement(Ut,{receivers:C,route:p,onSubmit:r,actionButtons:e.createElement(ge.a.ButtonRow,null,e.createElement(z.$n,{type:"button",variant:"secondary",onClick:T,fill:"outline"},"Cancel"),e.createElement(z.$n,{type:"submit"},"Update policy"))})),[C,n,T,r,c,l,p,s]),O,T]},Pn=(n,a)=>{const[r,l]=(0,e.useState)(!1),[s,u]=(0,e.useState)(),c=(0,e.useCallback)(()=>{u(void 0),l(!1)},[u]),i=(0,e.useCallback)(C=>{u(C),l(!0)},[]),p=(0,e.useCallback)(()=>{s&&n(s)},[n,s]);return[(0,e.useMemo)(()=>a?e.createElement(gt,{isOpen:r}):e.createElement(ge.a,{isOpen:r,onDismiss:c,closeOnBackdropClick:!0,closeOnEscape:!0,title:"Delete notification policy"},e.createElement("p",null,"Deleting this notification policy will permanently remove it."),e.createElement("p",null,"Are you sure you want to delete this policy?"),e.createElement(ge.a.ButtonRow,null,e.createElement(z.$n,{type:"button",variant:"destructive",onClick:p},"Yes, delete policy"),e.createElement(z.$n,{type:"button",variant:"secondary",onClick:c},"Cancel"))),[c,p,a,r]),i,c]},bn=()=>{const[n,a]=(0,e.useState)(!1),[r,l]=(0,e.useState)([]),[s,u]=(0,e.useState)([]),[c,i]=(0,e.useState)("default"),p=(0,e.useCallback)(()=>{a(!1),l([]),u([])},[]),I=(0,e.useCallback)((O,E,D)=>{l(O),E&&u(E),D&&i(D),a(!0)},[]),C=(0,e.useMemo)(()=>{const O=r.flatMap(E=>E.alerts);return(0,oe.groupBy)(O,E=>E.status.state)},[r]);return[(0,e.useMemo)(()=>e.createElement(ge.a,{isOpen:n,onDismiss:p,closeOnBackdropClick:!0,closeOnEscape:!0,title:e.createElement(d.B,{direction:"row",alignItems:"center",gap:1,wrap:"wrap"},e.createElement(d.B,{direction:"row",alignItems:"center",gap:.5},e.createElement(Ge.I,{name:"x"})," Matchers"),e.createElement(Vt.s,{matchers:s,formatter:c}))},e.createElement(d.B,{direction:"column"},e.createElement(mn,{active:C[$e.Or.Active]?.length,suppressed:C[$e.Or.Suppressed]?.length,unprocessed:C[$e.Or.Unprocessed]?.length}),e.createElement("div",null,r.map((O,E)=>e.createElement(rn._,{key:E,alertManagerSourceName:"",group:O})))),e.createElement(ge.a.ButtonRow,null,e.createElement(z.$n,{type:"button",variant:"secondary",onClick:p},"Cancel"))),[r,p,C,s,c,n]),I,p]},gt=({isOpen:n})=>e.createElement(ge.a,{isOpen:n,onDismiss:()=>{},closeOnBackdropClick:!1,closeOnEscape:!1,title:e.createElement(d.B,{direction:"row",alignItems:"center",gap:.5},"Updating... ",e.createElement(an.y,{inline:!0}))},"Please wait while we update your notification policies.");var ke=t(54625),An=t(32264),Cn=t(83122),Tn=t(69613),Et=t(46913),In=t(19645),Kt=t(79581),ft=t(35108),vt=t(8406),ve=t(55196),ue=t(94855);const Dn=({exportFormat:n,onClose:a})=>{const{currentData:r="",isFetching:l}=Ye.hK.useExportPoliciesQuery({format:n}),s=`policies-${new Date().getTime()}`;return l?e.createElement(x._,{text:"Loading...."}):e.createElement(Be.J,{format:n,textDefinition:r,downloadFileName:s,onClose:a})},On=({onClose:n})=>{const[a,r]=(0,e.useState)("yaml");return e.createElement(st.m,{activeTab:a,onTabChange:r,onClose:n,formatProviders:Object.values(Xe.sl)},e.createElement(Dn,{exportFormat:a,onClose:n}))},jt=n=>{const{receivers:a=[],contactPointsState:r,readOnly:l=!1,provisioned:s=!1,alertGroups:u=[],alertManagerSourceName:c,currentRoute:i,routeTree:p,inheritedProperties:I,routesMatchingFilters:C={filtersApplied:!1,matchedRoutesWithPath:new Map},matchingInstancesPreview:T={enabled:!1},onEditPolicy:O,onAddPolicy:E,onDeletePolicy:D,onShowAlertInstances:$,isAutoGenerated:b=!1}=n,k=(0,f.of)(Fe),X=i===p,W=i.receiver,K=i.continue??!1,ne=(0,$t.J$)(i),_=!!(ne&&ne.length),{filtersApplied:j,matchedRoutesWithPath:q}=C,Ee=Array.from(q.keys()),Z=j&&Ee.some(te=>te.id===i.id),Ae=Array.from(q.values()).flat(),we=Ae.some(te=>te.id===i.id),Oe=[],qe=!_&&!X&&!K,Pt=W??I?.receiver??"",bt=r?Kn(Pt,r):[],_e=i.routes??[],et=j?_e.filter(te=>Ae.some(He=>He.id===te.id)):_e,[Ne,tt]=(0,ce.A)(!1),Ue=T?.groupsMap?.get(i.id),At=Ue?(0,oe.sumBy)(Ue,te=>te.alerts.length):void 0,[Ct,Tt]=(0,P.L7)(P.QI.ViewAutogeneratedPolicyTree),Ve=Sn(i),[Ke,It]=(0,ce.A)(!1),Dt=Ve&&Ke||!Ve,Ot=i.group_by,St=i.mute_time_intervals??[],Rt={group_wait:i.group_wait,group_interval:i.group_interval,repeat_interval:i.repeat_interval};bt.forEach(te=>{Oe.push(te)});const nt=20,[at,Bt]=(0,e.useState)(nt),je=ht(i),ze=Bn(b,X,s,O,i,tt,D);if(b&&(!Tt||!Ct)||j&&!we)return null;const xt=X||je,ea=et.filter(te=>Ae.some(He=>He.id===te.id)),Ht=j?ea:et,Qt=Ht.slice(0,at),Gt=Ht.length-Qt.length,ta=Gt>0;return e.createElement(e.Fragment,null,e.createElement(d.B,{direction:"column",gap:1.5},e.createElement("div",{className:k.policyWrapper(Z),"data-testid":X?"am-root-route-container":"am-route-container"},K&&e.createElement($n,null),qe&&e.createElement(Wn,null),e.createElement("div",{className:k.policyItemWrapper},e.createElement(d.B,{direction:"column",gap:1},e.createElement("div",null,e.createElement(d.B,{direction:"row",alignItems:"center",gap:1},Ve&&e.createElement(F.K,{name:Ke?"angle-down":"angle-right",onClick:It,"aria-label":Ke?"Collapse":"Expand"}),xt?je?e.createElement(Fn,null):e.createElement(Ln,null):_?e.createElement(Vt.s,{matchers:ne??[],formatter:(0,be.VE)(c)}):e.createElement("span",{className:k.metadata},"No matchers"),e.createElement(Je.h,null),Oe.length>0&&e.createElement(Gn,{errors:Oe}),s&&e.createElement(lt.rS,null),e.createElement(d.B,{direction:"row",gap:.5},!b&&!l&&e.createElement(G._,{actions:[P.QI.CreateNotificationPolicy]},e.createElement(Et.A,{shouldWrap:s,wrap:yt},e.createElement(z.$n,{variant:"secondary",icon:"plus",size:"sm",onClick:()=>E(i),disabled:s,type:"button"},"New nested policy"))),ze.length>0&&e.createElement(Cn.m,{overlay:e.createElement(g.W,null,ze)},e.createElement(z.$n,{icon:"ellipsis-h",variant:"secondary",size:"sm",type:"button","aria-label":"more-actions","data-testid":"more-actions"}))))),e.createElement(Rn,{matchingInstancesPreview:T,numberOfAlertInstances:At,contactPoint:W??void 0,groupBy:Ot,muteTimings:St,timingOptions:Rt,inheritedProperties:I,alertManagerSourceName:c,receivers:a,matchingAlertGroups:Ue,matchers:ne,isDefaultPolicy:X,onShowAlertInstances:$})))),e.createElement("div",{className:k.childPolicies},Dt&&e.createElement(e.Fragment,null,Qt.map(te=>{const He=(0,Kt.W$)(i,te,I),na=ht(te)||b,aa=l||s||b;return e.createElement(jt,{key:te.id,routeTree:p,currentRoute:te,receivers:a,contactPointsState:r,readOnly:aa,inheritedProperties:He,onAddPolicy:E,onEditPolicy:O,onDeletePolicy:D,onShowAlertInstances:$,alertManagerSourceName:c,alertGroups:u,routesMatchingFilters:C,matchingInstancesPreview:T,isAutoGenerated:na,provisioned:s})}),ta&&e.createElement(z.$n,{size:"sm",icon:"angle-down",variant:"secondary",className:k.moreButtons,onClick:()=>Bt(at+nt)},Gt," additional ",We()("policy",Gt)))),Ne&&e.createElement(On,{onClose:tt})))};function Sn(n){const a=n.routes?.length??0,[r,l]=(0,P.L7)(P.QI.ViewAutogeneratedPolicyTree);return a>0&&r&&l&&ht(n)}function Rn({numberOfAlertInstances:n,isDefaultPolicy:a,timingOptions:r,groupBy:l,muteTimings:s=[],matchingInstancesPreview:u,inheritedProperties:c,matchingAlertGroups:i,onShowAlertInstances:p,matchers:I,contactPoint:C,alertManagerSourceName:T,receivers:O}){const E=(0,f.of)(Fe),D=c&&c.group_by,$=c&&Object.keys(c).length>0,b=(0,oe.isArray)(l)&&l[0]==="...",k=!b&&(0,oe.isArray)(l)&&l.length>0,X=a&&(0,oe.isArray)(l)&&l.length===0,W=!!s.length;return e.createElement("div",{className:E.metadataRow},e.createElement(d.B,{direction:"row",alignItems:"center",gap:1},u.enabled&&e.createElement(ve.P,{icon:"layers-alt",onClick:()=>{i&&p(i,I,(0,be.VE)(T))},"data-testid":"matching-instances"},e.createElement(ue.O,null,n??"-"),e.createElement("span",null,We()("instance",n))),C&&e.createElement(ve.P,{icon:"at","data-testid":"contact-point"},e.createElement("span",null,"Delivered to"),e.createElement(Vn,{alertManagerSourceName:T,receivers:O,contactPoint:C})),!D&&e.createElement(e.Fragment,null,k&&e.createElement(ve.P,{icon:"layer-group","data-testid":"grouping"},e.createElement("span",null,"Grouped by"),e.createElement(ue.O,null,l.join(", "))),X&&e.createElement(ve.P,{icon:"layer-group"},e.createElement("span",null,"Single group")),b&&e.createElement(ve.P,{icon:"layer-group"},e.createElement("span",null,"Not grouping"))),W&&e.createElement(ve.P,{icon:"calendar-slash","data-testid":"mute-timings"},e.createElement("span",null,"Muted when"),e.createElement(Nn,{timings:s,alertManagerSourceName:T})),r&&e.createElement(Un,{timingOptions:a?(0,oe.defaults)(r,Ze.H):r}),$&&e.createElement(e.Fragment,null,e.createElement(ve.P,{icon:"corner-down-right-alt","data-testid":"inherited-properties"},e.createElement("span",null,"Inherited"),e.createElement(wn,{properties:c})))))}const Bn=(n,a,r,l,s,u,c)=>{const[[i,p],[I,C],[T,O]]=(0,P.Hl)([P.QI.UpdateNotificationPolicyTree,P.QI.DeleteNotificationPolicy,P.QI.ExportNotificationPolicies]),E=[],D=O&&T&&a&&!n,$=i&&p,b=I&&C&&!a&&!n;return $&&E.push(e.createElement(e.Fragment,{key:"edit-policy"},e.createElement(Et.A,{shouldWrap:r,wrap:yt},e.createElement(g.W.Item,{icon:"edit",disabled:r||n,label:"Edit",onClick:()=>l(s,a)})))),D&&E.push(e.createElement(g.W.Item,{key:"export-policy",icon:"download-alt",label:"Export",onClick:u})),b&&E.push(e.createElement(e.Fragment,{key:"delete-policy"},e.createElement(g.W.Divider,null),e.createElement(Et.A,{shouldWrap:r,wrap:yt},e.createElement(g.W.Item,{destructive:!0,icon:"trash-alt",disabled:r||n,label:"Delete",onClick:()=>c(s)})))),E},xn="__grafana_autogenerated__";function ht(n){return!(An.$.featureToggles.alertingSimplifiedRouting??!1)||!n.object_matchers?!1:n.object_matchers.some(r=>r[0]===xn&&r[1]===$e.ho.equal&&r[2]==="true")??!1}const yt=n=>e.createElement(Te.m,{content:"Provisioned items cannot be edited in the UI",placement:"top"},e.createElement("span",null,n)),Gn=({errors:n})=>e.createElement(ft.j,{arrow:!0,placement:"top",content:e.createElement(d.B,{direction:"column",gap:.5},n.map(a=>e.createElement(e.Fragment,{key:(0,oe.uniqueId)()},a)))},e.createElement("span",null,e.createElement(Le.E,{icon:"exclamation-circle",color:"red",text:We()("error",n.length,!0)}))),$n=()=>{const n=(0,f.of)(Fe);return e.createElement(Te.m,{placement:"top",content:"This route will continue matching other policies"},e.createElement("div",{className:n.gutterIcon,"data-testid":"continue-matching"},e.createElement(Ge.I,{name:"arrow-down"})))},Wn=()=>{const n=(0,f.of)(Fe);return e.createElement(Te.m,{placement:"top",content:"This policy matches all labels"},e.createElement("div",{className:n.gutterIcon,"data-testid":"matches-all"},e.createElement(Ge.I,{name:"exclamation-triangle"})))};function Ln(){const n=(0,f.of)(Fe);return e.createElement(e.Fragment,null,e.createElement("strong",null,"Default policy"),e.createElement("span",{className:n.metadata},"All alert instances will be handled by the default policy if no other matching policies are found."))}function Fn(){return e.createElement("strong",null," Auto-generated policies")}const wn=({properties:n})=>e.createElement(ft.j,{arrow:!0,placement:"top",content:e.createElement(d.B,{direction:"row",gap:.5},Object.entries(n).map(([a,r])=>r?e.createElement(vt.J,{key:a,label:jn(a),value:e.createElement(ue.O,null,zn(a,r))}):null))},e.createElement("div",null,e.createElement(ue.O,null,We()("property",Object.keys(n).length,!0)))),Nn=({timings:n,alertManagerSourceName:a})=>e.createElement("div",null,e.createElement(ue.O,null,n.map(r=>e.createElement(ke.Link,{key:r,to:(0,re.i7)(r,a)},r)))),Un=({timingOptions:n})=>{const a=n.group_wait,r=n.group_interval;return!a&&!r?null:e.createElement(ve.P,{icon:"hourglass","data-testid":"timing-options"},e.createElement("span",null,"Wait"),a&&e.createElement(Te.m,{placement:"top",content:"How long to initially wait to send a notification for a group of alert instances."},e.createElement("span",null,e.createElement(ue.O,null,a)," ",e.createElement("span",null,"to group instances"),a&&r&&",")),r&&e.createElement(Te.m,{placement:"top",content:"How long to wait before sending a notification about new alerts that are added to a group of alerts for which an initial notification has already been sent."},e.createElement("span",null,e.createElement(ue.O,null,r)," ",e.createElement("span",null,"before sending updates"))))},Vn=({alertManagerSourceName:n,contactPoint:a,receivers:r})=>{const l=r.find(c=>c.name===a);if(!l)return e.createElement(ke.Link,{to:(0,re.bg)(a,n)},e.createElement(ue.O,null,a));if(!l.grafana_managed_receiver_configs)return e.createElement(ke.Link,{to:(0,re.bg)(a,n)},e.createElement(ue.O,null,a));const u=(0,oe.groupBy)(l.grafana_managed_receiver_configs,c=>c.type);return e.createElement(ft.j,{arrow:!0,placement:"top",header:e.createElement(ve.P,{icon:"at"},e.createElement("div",null,"Contact Point"),e.createElement(ue.O,null,a)),key:(0,oe.uniqueId)(),content:e.createElement(d.B,{direction:"row",gap:.5},Object.entries(u).map(([c,i])=>e.createElement(vt.J,{key:(0,oe.uniqueId)(),label:i.length>1?i.length:void 0,icon:In.M[c],value:(0,oe.upperFirst)(c)})))},e.createElement(ke.Link,{to:(0,re.bg)(a,n)},e.createElement(ue.O,null,a)))};function Kn(n,a){return Object.entries(a[n]?.notifiers??[]).reduce((s=[],[u,c])=>{const i=c.filter(p=>p.lastNotifyAttemptError).map(p=>e.createElement(vt.J,{icon:"at",key:(0,oe.uniqueId)(),label:`Contact Point \u203A ${p.name}`,value:p.lastNotifyAttemptError}));return s.concat(i)},[])}const jn=n=>{switch(n){case"receiver":return"Contact Point";case"group_by":return"Group by";case"group_interval":return"Group interval";case"group_wait":return"Group wait";case"repeat_interval":return"Repeat interval";default:return n}},zn=(n,a)=>{const r=n==="group_by"&&Array.isArray(a)&&a[0]==="...",l=n==="group_by"&&Array.isArray(a)&&a.length===0;return r?e.createElement(mt.E,{variant:"bodySmall",color:"secondary"},"Not grouping"):l?e.createElement(mt.E,{variant:"bodySmall",color:"secondary"},"Single group"):Array.isArray(a)?a.join(", "):a},Fe=n=>({matcher:a=>{const{color:r,borderColor:l}=(0,Tn.MC)(a);return{wrapper:(0,o.css)({color:"#fff",background:r,padding:`${n.spacing(.33)} ${n.spacing(.66)}`,fontSize:n.typography.bodySmall.fontSize,border:`solid 1px ${l}`,borderRadius:n.shape.radius.default})}},childPolicies:(0,o.css)({marginLeft:n.spacing(4),position:"relative","&:before":{content:'""',position:"absolute",height:"calc(100% - 10px)",borderLeft:`solid 1px ${n.colors.border.weak}`,marginTop:0,marginLeft:"-20px"}}),policyItemWrapper:(0,o.css)({padding:n.spacing(1.5)}),metadataRow:(0,o.css)({borderBottomLeftRadius:n.shape.borderRadius(2),borderBottomRightRadius:n.shape.borderRadius(2)}),policyWrapper:(a=!1)=>(0,o.css)({flex:1,position:"relative",background:n.colors.background.secondary,borderRadius:n.shape.radius.default,border:`solid 1px ${n.colors.border.weak}`,...a&&{borderColor:n.colors.primary.border,background:n.colors.primary.transparent}}),metadata:(0,o.css)({color:n.colors.text.secondary,fontSize:n.typography.bodySmall.fontSize,fontWeight:n.typography.bodySmall.fontWeight}),break:(0,o.css)({width:"100%",height:0,marginBottom:n.spacing(2)}),gutterIcon:(0,o.css)({position:"absolute",top:0,transform:"translateY(50%)",left:`-${n.spacing(4)}`,color:n.colors.text.secondary,background:n.colors.background.primary,width:"25px",height:"25px",textAlign:"center",border:`solid 1px ${n.colors.border.weak}`,borderRadius:n.shape.radius.default,padding:0}),moreButtons:(0,o.css)({marginTop:n.spacing(.5),marginBottom:n.spacing(1.5)})});var Hn=t(19143),Qn=t(88467),Mt=t(67332),Jn=(n=>(n.NotificationPolicies="notification_policies",n.MuteTimings="mute_timings",n))(Jn||{});const Yn=()=>{const n=(0,v.useDispatch)(),a=(0,f.of)(Zn),{useGetAlertmanagerAlertGroupsQuery:r}=R.m,[l,s]=(0,h.s)(),{tab:u}=kn(l),[c,i]=(0,e.useState)(u),[p,I]=(0,e.useState)(!1),[C,T]=(0,e.useState)(),[O,E]=(0,e.useState)([]),{selectedAlertmanager:D,hasConfigurationAPI:$,isGrafanaAlertmanager:b}=(0,Nt.VI)(),{getRouteGroupsMap:k}=(0,Hn.L)(),X=se(D??""),{currentData:W,isLoading:K,error:ne}=(0,Q.f)(D,{refetchOnFocus:!0,refetchOnReconnect:!0}),_=W?.alertmanager_config,{currentData:j,refetch:q}=r({amSourceName:D??""},{skip:!D}),Ee=_?.receivers??[],Z=(0,e.useMemo)(()=>{if(_?.route)return(0,H.QM)(_.route)},[_?.route]),[{value:Ae,error:we},Oe]=(0,A.A)(k,[k]);(0,e.useEffect)(()=>{Z&&j&&Oe(Z,j,{unquoteMatchers:!b})},[Z,j,Oe,b]);const qe=(0,e.useMemo)(()=>Z?zt(Z,{contactPointFilter:C,labelMatchersFilter:O}):{filtersApplied:!1,matchedRoutesWithPath:new Map},[C,O,Z]),Pt=!!_?.route?.provenance;function bt(me){if(!Z)return;const Se=(0,Mt.AB)(D??"",me,Z);Ne(Se)}function _e(me){if(!Z)return;const Se=(0,Mt.AS)(me,Z);Ne(Se)}function et(me,Se){if(!Z)return;const xt=(0,Mt.pq)(D??"",me,Se,Z);Ne(xt)}function Ne(me){W&&(I(!0),n((0,w.RW)({newConfig:{...W,alertmanager_config:{...W.alertmanager_config,route:me}},oldConfig:W,alertManagerSourceName:D,successMessage:"Updated notification policies"})).unwrap().then(()=>{D&&q(),Ve(),At(),Dt()}).finally(()=>{I(!1)}))}const[tt,Ue,At]=yn(Ee,et,p),[Ct,Tt,Ve]=Mn(D??"",Ee,bt,p),[Ke,It,Dt]=Pn(_e,p),[Ot,St]=bn();if((0,U.o)(me=>me.unifiedAlerting.saveAMConfig=Qn.jA),!D)return null;const Rt=W?.alertmanager_config.mute_time_intervals?.length??0,nt=W&&!ne&&!K,at=!W&&K,Bt=ne&&!K,je=c==="mute_timings",ze=c==="notification_policies";return e.createElement(e.Fragment,null,e.createElement(S.U,null,e.createElement(y.o,{label:"Notification Policies",active:ze,onChangeTab:()=>{i("notification_policies"),s({tab:"notification_policies"})}}),e.createElement(y.o,{label:"Mute Timings",active:je,counter:Rt,onChangeTab:()=>{i("mute_timings"),s({tab:"mute_timings"})}})),e.createElement(N.J,{className:a.tabContent},at&&e.createElement(x._,{text:"Loading Alertmanager config..."}),Bt&&e.createElement(M.F,{severity:"error",title:"Error loading Alertmanager config"},ne.message||"Unknown error."),nt&&e.createElement(e.Fragment,null,ze&&e.createElement(e.Fragment,null,e.createElement(ye.M,{currentAlertmanager:D}),e.createElement(d.B,{direction:"column",gap:1},Z&&e.createElement(qt,{receivers:Ee,onChangeMatchers:E,onChangeReceiver:T,matchingCount:qe.matchedRoutesWithPath.size}),Z&&e.createElement(jt,{receivers:Ee,routeTree:Z,currentRoute:Z,alertGroups:j??[],contactPointsState:X.receivers,readOnly:!$,provisioned:Pt,alertManagerSourceName:D,onAddPolicy:Ue,onEditPolicy:Tt,onDeletePolicy:It,onShowAlertInstances:St,routesMatchingFilters:qe,matchingInstancesPreview:{groupsMap:Ae,enabled:!we},isAutoGenerated:!1})),tt,Ct,Ke,Ot),je&&e.createElement(Jt,{alertManagerSourceName:D,hideActions:!$}))))},zt=(n,a)=>{const{contactPointFilter:r,labelMatchersFilter:l=[]}=a,s=r||l.length>0,u=!!r&&l.length>0;if(!s)return{filtersApplied:!1,matchedRoutesWithPath:new Map};let c=[];const i=(0,Kt._I)(n),p=r?Wt(i,E=>E.receiver===r):new Map,I=Array.from(p.keys());I&&c.push(I);const C=l.length?Wt(i,E=>_t(E,l)):new Map,T=Array.from(C.keys());return C.size>0&&c.push(T),{filtersApplied:!0,matchedRoutesWithPath:u?Xn(C,p):new Map([...C,...p])}};function Xn(...n){const a=new Map;for(const r of n[0].keys())n.every(l=>l.has(r))&&a.set(r,n[0].get(r));return a}const Zn=n=>({tabContent:(0,o.css)`
    margin-top: ${n.spacing(2)};
  `});function kn(n){let a="notification_policies";return n.tab==="notification_policies"&&(a="notification_policies"),n.tab==="mute_timings"&&(a="mute_timings"),{tab:a}}const qn=()=>e.createElement(he.y,{navId:"am-routes",accessType:"notification"},e.createElement(Yn,null)),_n=(0,L.Xc)(qn,{style:"page"})},23088:(ae,B,t)=>{t.d(B,{Z:()=>f});var o=t(32196),e=t(96540),A=t(40845);const f=({children:y})=>{const N=(0,A.of)(S);return e.createElement("div",{className:N.container},y)},S=y=>({container:(0,o.css)`
      background-color: ${y.colors.background.secondary};
      color: ${y.colors.text.secondary};
      padding: ${y.spacing(4)};
      text-align: center;
    `})},45067:(ae,B,t)=>{t.d(B,{_:()=>m});var o=t(32196),e=t(96540),A=t(40845),f=t(67061),S=t(60021),y=t(69087),N=t(64047),x=t(55196),M=t(94855),d=t(70416),L=t(10562),h=t(97754),v=t(55852),U=t(16233),R=t(80348),J=t(19073),ee=t(57220),le=t(56361),de=t(71223),se=t(64853);const he=({alert:g,alertManagerSourceName:V})=>{const G=(0,A.of)(ye),Q=(0,ee.z2)(V)?U.TP.hasPermission(R.AccessControlAction.AlertingRuleRead):!0;return e.createElement(e.Fragment,null,e.createElement("div",{className:G.actionsRow},g.status.state===S.Or.Suppressed&&e.createElement(se._,{actions:[J.QI.CreateSilence,J.QI.UpdateSilence]},e.createElement(v.z9,{href:`${(0,le.nL)("/alerting/silences",V)}&silenceIds=${g.status.silencedBy.join(",")}`,className:G.button,icon:"bell",size:"sm"},"Manage silences")),g.status.state===S.Or.Active&&e.createElement(se._,{actions:[J.QI.CreateSilence]},e.createElement(v.z9,{href:(0,le.BK)(V,g.labels),className:G.button,icon:"bell-slash",size:"sm"},"Silence")),Q&&g.generatorURL&&e.createElement(v.z9,{className:G.button,href:g.generatorURL,icon:"chart-line",size:"sm"},"See source")),Object.entries(g.annotations).map(([w,re])=>e.createElement(de.s,{key:w,annotationKey:w,value:re})),e.createElement("div",{className:G.receivers},"Receivers:"," ",g.receivers.map(({name:w})=>w).filter(w=>!!w).join(", ")))},ye=g=>({button:(0,o.css)`
    & + & {
      margin-left: ${g.spacing(1)};
    }
  `,actionsRow:(0,o.css)`
    padding: ${g.spacing(2,0)} !important;
    border-bottom: 1px solid ${g.colors.border.medium};
  `,receivers:(0,o.css)`
    padding: ${g.spacing(1,0)};
  `}),ce=({alerts:g,alertManagerSourceName:V})=>{const G=(0,A.of)(z),P=(0,e.useMemo)(()=>[{id:"state",label:"State",renderCell:({data:w})=>e.createElement(e.Fragment,null,e.createElement(h.y,{state:w.status.state}),e.createElement("span",{className:G.duration},"for"," ",(0,d.dU)({start:new Date(w.startsAt),end:new Date(w.endsAt)}))),size:"220px"},{id:"labels",label:"Labels",renderCell:({data:{labels:w}})=>e.createElement(y.m,{labels:w,size:"sm"}),size:1}],[G]),Q=(0,e.useMemo)(()=>g.map(w=>({id:w.fingerprint,data:w})),[g]);return e.createElement("div",{className:G.tableWrapper,"data-testid":"alert-group-table"},e.createElement(L.B,{cols:P,items:Q,isExpandable:!0,renderExpandedContent:({data:w})=>e.createElement(he,{alert:w,alertManagerSourceName:V})}))},z=g=>({tableWrapper:(0,o.css)`
    margin-top: ${g.spacing(3)};
    ${g.breakpoints.up("md")} {
      margin-left: ${g.spacing(4.5)};
    }
  `,duration:(0,o.css)`
    margin-left: ${g.spacing(1)};
    font-size: ${g.typography.bodySmall.fontSize};
  `});var Re=t(27962);const m=({alertManagerSourceName:g,group:V})=>{const[G,P]=(0,e.useState)(!0),Q=(0,A.of)(F),w=V.receiver.name!=="NONE";return e.createElement("div",{className:Q.wrapper},e.createElement("div",{className:Q.header},e.createElement("div",{className:Q.group,"data-testid":"alert-group"},e.createElement(N.e,{size:"sm",isCollapsed:G,onToggle:()=>P(!G),"data-testid":"alert-group-collapse-toggle"}),Object.keys(V.labels).length?e.createElement(f.B,{direction:"row",alignItems:"center"},e.createElement(y.m,{labels:V.labels,size:"sm"}),w&&e.createElement(x.P,{icon:"at"},"Delivered to ",e.createElement(M.O,null,V.receiver.name))):e.createElement("span",null,"No grouping")),e.createElement(Re.f,{group:V})),!G&&e.createElement(ce,{alertManagerSourceName:g,alerts:V.alerts}))},F=g=>({wrapper:(0,o.css)({"& + &":{marginTop:g.spacing(2)}}),header:(0,o.css)({display:"flex",flexDirection:"row",flexWrap:"wrap",alignItems:"center",justifyContent:"space-between",padding:`${g.spacing(1)} ${g.spacing(1)} ${g.spacing(1)} 0`,backgroundColor:g.colors.background.secondary,width:"100%"}),group:(0,o.css)({display:"flex",flexDirection:"row",alignItems:"center"}),summary:(0,o.css)({}),[S.Or.Active]:(0,o.css)({color:g.colors.error.main}),[S.Or.Suppressed]:(0,o.css)({color:g.colors.primary.main}),[S.Or.Unprocessed]:(0,o.css)({color:g.colors.secondary.main})})},4724:(ae,B,t)=>{t.d(B,{Hy:()=>y,av:()=>x,oB:()=>N});var o=t(95093),e=t.n(o),A=t(96540),f=t(98164);const S=/^((([01][0-9])|(2[0-3])):[0-5][0-9])$|(^24:00$)/,y=M=>M?S.test(M):!0,N=(M,d)=>{if(!M&&!d)return!0;if(!M&&d||M&&!d)return!1;const L="HH:mm",h=e()().startOf("day").add(M,L),v=e()().startOf("day").add(d,L);return!!(M&&d&&h.isBefore(v)||M&&d&&v.isAfter(h))};function x(M){return M.time_intervals.map((L,h)=>{const{times:v,weekdays:U,days_of_month:R,months:J,years:ee,location:le}=L,de=(0,f.Dm)(v,le),se=(0,f.uH)(U),he=(0,f.UL)(R),ye=(0,f.$P)(J),ce=(0,f.mP)(ee);return A.createElement(A.Fragment,{key:JSON.stringify(L)+h},`${de} ${se}`,A.createElement("br",null),[he,ye,ce].join(" | "),A.createElement("br",null))})}},26928:(ae,B,t)=>{t.d(B,{s:()=>d});var o=t(32196),e=t(2543),A=t.n(e),f=t(96540),S=t(40845),y=t(67061),N=t(69613),x=t(32642),M=t(35108);const d=({matchers:v,formatter:U="default"})=>{const R=(0,S.of)(h),J=5,ee=(0,e.take)(v,J),le=(0,e.takeRight)(v,v.length-J),de=le.length>0;return f.createElement("span",{"data-testid":"label-matchers"},f.createElement(y.B,{direction:"row",gap:1,alignItems:"center",wrap:"wrap"},ee.map(se=>f.createElement(L,{key:(0,e.uniqueId)(),matcher:se,formatter:U})),de&&f.createElement(M.j,{arrow:!0,placement:"top",content:f.createElement(f.Fragment,null,le.map(se=>f.createElement(L,{key:(0,e.uniqueId)(),matcher:se})))},f.createElement("span",null,f.createElement("div",{className:R.metadata},`and ${le.length} more`)))))},L=({matcher:v,formatter:U="default"})=>{const R=(0,S.of)(h);return f.createElement("div",{className:R.matcher(v[0]).wrapper},f.createElement(y.B,{direction:"row",gap:0,alignItems:"baseline"},x.t8[U](v)))},h=v=>({matcher:U=>{const{color:R,borderColor:J}=(0,N.MC)(U);return{wrapper:(0,o.css)`
        color: #fff;
        background: ${R};
        padding: ${v.spacing(.33)} ${v.spacing(.66)};
        font-size: ${v.typography.bodySmall.fontSize};

        border: solid 1px ${J};
        border-radius: ${v.shape.borderRadius(2)};
      `}},metadata:(0,o.css)`
    color: ${v.colors.text.secondary};

    font-size: ${v.typography.bodySmall.fontSize};
    font-weight: ${v.typography.bodySmall.fontWeight};
  `})},33915:(ae,B,t)=>{t.d(B,{V:()=>L});var o=t(96540),e=t(10354),A=t(14578),f=t(35108),S=t(32196),y=t(40845),N=t(41068);function x(){const h=(0,y.of)(d);return o.createElement("div",null,"Prometheus duration format consist of a number followed by a time unit.",o.createElement("br",null),"Different units can be combined for more granularity.",o.createElement("hr",null),o.createElement("div",{className:h.list},o.createElement("div",{className:h.header},o.createElement("div",null,"Symbol"),o.createElement("div",null,"Time unit"),o.createElement("div",null,"Example")),o.createElement(M,{unit:N.y.seconds,name:"seconds",example:"20s"}),o.createElement(M,{unit:N.y.minutes,name:"minutes",example:"10m"}),o.createElement(M,{unit:N.y.hours,name:"hours",example:"4h"}),o.createElement(M,{unit:N.y.days,name:"days",example:"3d"}),o.createElement(M,{unit:N.y.weeks,name:"weeks",example:"2w"}),o.createElement("div",{className:h.examples},o.createElement("div",null,"Multiple units combined"),o.createElement("code",null,"1m30s, 2h30m20s, 1w2d"))))}function M({unit:h,name:v,example:U}){const R=(0,y.of)(d);return o.createElement(o.Fragment,null,o.createElement("div",{className:R.unit},h),o.createElement("div",null,v),o.createElement("code",null,U))}const d=h=>({unit:(0,S.css)`
    font-weight: ${h.typography.fontWeightBold};
  `,list:(0,S.css)`
    display: grid;
    grid-template-columns: max-content 1fr 2fr;
    gap: ${h.spacing(1,3)};
  `,header:(0,S.css)`
    display: contents;
    font-weight: ${h.typography.fontWeightBold};
  `,examples:(0,S.css)`
    display: contents;
    & > div {
      grid-column: 1 / span 2;
    }
  `}),L=o.forwardRef((h,v)=>o.createElement(e.p,{suffix:o.createElement(f.j,{content:o.createElement(x,null),disabled:!1},o.createElement(A.I,{name:"info-circle",size:"lg"})),...h,ref:v}));L.displayName="PromDurationInput"},99903:(ae,B,t)=>{t.d(B,{t:()=>e});var o=t(32196);const e=A=>({container:(0,o.css)`
      align-items: center;
      display: flex;
      flex-flow: row nowrap;

      & > * + * {
        margin-left: ${A.spacing(1)};
      }
    `,input:(0,o.css)`
      flex: 1;
    `,promDurationInput:(0,o.css)`
      max-width: ${A.spacing(32)};
    `,timingFormContainer:(0,o.css)`
      padding: ${A.spacing(1)};
    `,linkText:(0,o.css)`
      text-decoration: underline;
    `,collapse:(0,o.css)`
      border: none;
      background: none;
      color: ${A.colors.text.primary};
    `})},97174:(ae,B,t)=>{t.d(B,{G:()=>o});const o={groupWait:{label:"Group wait",description:"The waiting time until the initial notification is sent for a new group created by an incoming alert. If empty it will be inherited from the parent policy.",ariaLabel:"Group wait value"},groupInterval:{label:"Group interval",description:"The waiting time to send a batch of new alerts for that group after the first notification was sent. If empty it will be inherited from the parent policy.",ariaLabel:"Group interval value"},repeatInterval:{label:"Repeat interval",description:"The waiting time to resend an alert after they have successfully been sent.",ariaLabel:"Repeat interval value"}}},27835:(ae,B,t)=>{t.d(B,{H:()=>o});const o={group_wait:"30s",group_interval:"5m",repeat_interval:"4h"}},97754:(ae,B,t)=>{t.d(B,{y:()=>S});var o=t(96540),e=t(60021),A=t(65415);const f={[e.Or.Active]:"bad",[e.Or.Unprocessed]:"neutral",[e.Or.Suppressed]:"info"},S=({state:y})=>o.createElement(A.O,{state:f[y]},y)},51488:(ae,B,t)=>{t.d(B,{f:()=>e});var o=t(82843);function e(A,f){const S=o.m.endpoints.getAlertmanagerConfiguration.useQuery(A??"",{...f,skip:!A});return{...S,error:S.error}}},19143:(ae,B,t)=>{t.d(B,{L:()=>M});var o=t(14590),e=t(96540),A=t(25027),f=t(67278);const S=()=>new f.c(new URL(t.p+t.u(5398),t.b));let y;function N(){let d;if(y===void 0)try{d=S(),y=o.LV(d)}catch(h){h instanceof Error&&(0,A.vV)(h)}return{disposeWorker:()=>{d&&y&&(y[o.A2](),d.terminate(),y=void 0,d=void 0)}}}function x(d){if(!y)throw new Error("Route Matcher has not been initialized")}function M(){(0,e.useEffect)(()=>{const{disposeWorker:h}=N();return h},[]);const d=(0,e.useCallback)(async(h,v,U)=>{x(y);const R=performance.now(),J=await y.getRouteGroupsMap(h,v,U),ee=performance.now()-R;return(0,A.fH)(`Route Groups Matched in  ${ee} ms`,{matchingTime:ee.toString(),alertGroupsCount:v.length.toString(),topLevelRoutesCount:h.routes?.length.toString()??"0"}),J},[]),L=(0,e.useCallback)(async(h,v,U)=>{x(y);const R=performance.now(),J=await y.matchInstancesToRoute(h,v,U),ee=performance.now()-R;return(0,A.fH)(`Instances Matched in  ${ee} ms`,{matchingTime:ee.toString(),instancesToMatchCount:v.length.toString(),topLevelRoutesCount:h.routes?.length.toString()??"0"}),J},[]);return{getRouteGroupsMap:d,matchInstancesToRoute:L}}},79657:(ae,B,t)=>{t.d(B,{DY:()=>Re,Mk:()=>de,QM:()=>J,Rg:()=>h,SJ:()=>le,YE:()=>ee,Yl:()=>U,eb:()=>he,gY:()=>se,hH:()=>ce,ie:()=>ye});var o=t(2543),e=t.n(o),A=t(60021),f=t(98164),S=t(57220),y=t(32642),N=t(67332),x=t(25968);const M=(m,F)=>Object.entries(m??{}).reduce((g,[V,G])=>[...g,{name:V,value:G,operator:F?A.ho.regex:A.ho.equal}],[]),d=m=>m.value,L=m=>(m??[]).map(d),h={name:"",value:"",operator:A.ho.equal},v=["grafana_folder","alertname"],U=[{label:"grafana_folder",value:"grafana_folder",isFixed:!0},{label:"alertname",value:"alertname",isFixed:!0},{label:"Disable (...)",value:"..."}],R={id:"",overrideGrouping:!1,groupBy:v,object_matchers:[],routes:[],continue:!1,receiver:"",overrideTimings:!1,groupWaitValue:"",groupIntervalValue:"",repeatIntervalValue:"",muteTimeIntervals:[]};function J(m){return{id:(0,o.uniqueId)("route-"),...m,routes:(m.routes??[]).map(J)}}const ee=m=>{if(!m)return R;const F="id"in m?m.id:(0,o.uniqueId)("route-");if(Object.keys(m).length===0)return{...R,id:F};const g=[];m.routes?.forEach(P=>{const Q=ee(P);g.push(Q)});const V=m.object_matchers?.map(P=>({name:P[0],operator:P[1],value:P[2]}))??[],G=m.matchers?.map(P=>(0,f.MU)((0,y.qR)(P))).map(({name:P,operator:Q,value:w})=>({name:P,operator:Q,value:(0,y.Ig)(w)}))??[];return{id:F,object_matchers:[...G,...V,...M(m.match,!1),...M(m.match_re,!0)],continue:m.continue??!1,receiver:m.receiver??"",overrideGrouping:Array.isArray(m.group_by)&&m.group_by.length>0,groupBy:m.group_by??void 0,overrideTimings:[m.group_wait,m.group_interval,m.repeat_interval].some(Boolean),groupWaitValue:m.group_wait??"",groupIntervalValue:m.group_interval??"",repeatIntervalValue:m.repeat_interval??"",routes:g,muteTimeIntervals:m.mute_time_intervals??[]}},le=(m,F,g)=>{const V=(0,N.eM)(F.id??"",g),{overrideGrouping:G,groupBy:P,overrideTimings:Q,groupWaitValue:w,groupIntervalValue:re,repeatIntervalValue:Qe,receiver:rt}=F,Me=void 0,ot=G?P:Me,Je=Q&&w?w:Me,Be=Q&&re?re:Me,Xe=Q&&Qe?Qe:Me,it=F.object_matchers?.filter(ie=>ie.name&&ie.operator&&ie.value!==null&&ie.value!==void 0).map(({name:ie,operator:Ce,value:xe})=>[ie,Ce,xe]),ct=F.routes?.map(ie=>le(m,ie,g)),pe={...V??{},continue:F.continue,group_by:ot,object_matchers:it,match:void 0,match_re:void 0,group_wait:Je,group_interval:Be,repeat_interval:Xe,routes:ct,mute_time_intervals:F.muteTimeIntervals,receiver:rt};return m!==S.hY?(pe.matchers=F.object_matchers?.map(({name:ie,operator:Ce,value:xe})=>`${ie}${Ce}${(0,y.ot)(xe)}`),pe.object_matchers=void 0):(pe.object_matchers=(0,y.J$)(pe),pe.matchers=void 0),F.receiver&&(pe.receiver=F.receiver),pe},de=m=>({label:m,value:m}),se=m=>(m??[]).map(de),he=m=>m===null?null:m?d(m)??"":"",ye=m=>m?L(m):[];function ce(m){return!m||m.length===0?!0:(0,x.TN)(m)||"Invalid duration format. Must be {number}{time_unit}"}const z=m=>m.map(F=>{const[g,V,G]=F;return`${g}${V}${G}`}),Re=(m,F="")=>{if(m.length===0)return!0;const g=ce(m),V=ce(F);if(g!==!0)return g;if(V!==!0)return V;const G=(0,x.ge)(m),P=(0,x.ge)(F);return P!==0&&G<P?"Repeat interval should be higher or equal to Group interval":!0}},67332:(ae,B,t)=>{t.d(B,{AB:()=>f,AS:()=>S,eM:()=>N,pq:()=>y});var o=t(2543),e=t.n(o),A=t(79657);const f=(x,M,d)=>{if(!N(M.id??"",d))throw new Error(`No such route with ID '${M.id}'`);function h(v){let U=v;if(v.id===M.id){const R=(0,A.SJ)(x,M,d);U=(0,o.omit)({...v,...R},"id")}return(0,o.omit)({...U,routes:v.routes?.map(h)},"id")}return h(d)},S=(x,M)=>{if(x.id===M.id)throw new Error("You cant remove the root policy");function d(L){return(0,o.omit)({...L,routes:L.routes?.reduce((h=[],v)=>(v.id===x.id||h.push(d(v)),h),[])},"id")}return d(M)},y=(x,M,d,L)=>{const h=(0,A.SJ)(x,M,L);function v(R){return R.id===d.id?{...R,routes:R.routes?.concat(h)}:{...R,routes:R.routes?.map(v)}}function U(R){return(0,o.omit)({...R,routes:R.routes?.map(U)},"id")}return U(v(L))};function N(x,M){return M.id===x?M:M.routes?.find(d=>N(x,d))}}}]);

//# sourceMappingURL=AlertAmRoutes.10a0d9a23a082caf12c8.js.map