"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[8648,335],{95500:(ee,x,t)=>{t.d(x,{x:()=>M});var a=t(85960),o=t(95162),e=t(1992);function M(f){const O=(0,o.useDispatch)(),h=(0,a.useRef)(f);h.current=f,(0,a.useEffect)(()=>()=>{O((0,e.e)({cleanupAction:h.current}))},[O])}},84033:(ee,x,t)=>{t.r(x),t.d(x,{default:()=>Ln,findRoutesMatchingFilters:()=>Gt});var a=t(66681),o=t(56375),e=t(85960),M=t(85954),f=t(47257),O=t(70523),h=t(94439),S=t(10305),m=t(79468),T=t(49199),u=t(13086),g=t(8958),b=t(763),L=t(95162),R=t(95500),Q=t(81828),H=t(46002),ne=t(58712),ue=t(20741);const de=ne.C.injectEndpoints({endpoints:n=>({contactPointsState:n.query({queryFn:async({amSourceName:r})=>{try{return{data:await(0,ue.QE)(r)}}catch(l){return{error:l}}}})})}),pe=n=>{const r={receivers:{},errorCount:0},{currentData:l}=de.useContactPointsStateQuery({amSourceName:n??""},{skip:!n,pollingInterval:H.m4});return l??r};var Ee=t(65892),se=t(28157),Ce=t(45220),K=t(29165),c=t(77980),w=t(59672),E=t(75064),W=t(54635),U=t(21128),A=t(53914),y=t(57297),P=t(70335),re=t(5970),te=t(77294),Me=t(79253),q=t(77085);const De=({buttonIcon:n,buttonLabel:r,buttonSize:l="lg",buttonVariant:s="primary",onButtonClick:d,text:p,href:i,showButton:I=!0})=>{const v=(0,f.wW)(je),N={className:v.button,icon:n,size:l,variant:s};return e.createElement(q.j,null,e.createElement(e.Fragment,null,e.createElement("p",{className:v.text},p),I&&(i?e.createElement(K.Qj,{href:i,type:"button",...N},r):e.createElement(K.zx,{onClick:d,type:"button",...N},r))))},je=n=>({container:(0,a.css)`
      background-color: ${n.colors.background.secondary};
      color: ${n.colors.text.secondary};
      padding: ${n.spacing(4)};
      text-align: center;
    `,text:(0,a.css)`
      margin-bottom: ${n.spacing(2)};
    `,button:(0,a.css)`
      margin: ${n.spacing(2,0,1)};
    `});var Oe=t(84237),xe=t(99586),Ae=t(14411),Ve=t(27908),ze=t(29657),Ze=t(23694);const rt=({exportFormat:n,onClose:r})=>{const{currentData:l="",isFetching:s}=Ae.alertRuleApi.useExportMuteTimingsQuery({format:n}),d=`mute-timings-${new Date().getTime()}`;return s?e.createElement(m.u,{text:"Loading...."}):e.createElement(Ve.u,{format:n,textDefinition:l,downloadFileName:d,onClose:r})},ve=({exportFormat:n,onClose:r,muteTimingName:l})=>{const{currentData:s="",isFetching:d}=Ae.alertRuleApi.useExportMuteTimingQuery({format:n,muteTiming:l}),p=`mute-timing-${l}-${new Date().getTime()}`;return d?e.createElement(m.u,{text:"Loading...."}):e.createElement(Ve.u,{format:n,textDefinition:s,downloadFileName:p,onClose:r})},le=({onClose:n,muteTimingName:r})=>{const[l,s]=(0,e.useState)("yaml");return e.createElement(ze.i,{activeTab:l,onTabChange:s,onClose:n,formatProviders:Object.values(Ze.uN)},r?e.createElement(ve,{exportFormat:l,onClose:n,muteTimingName:r}):e.createElement(rt,{exportFormat:l,onClose:n}))};var Ge=t(77542);const Se=Symbol("all mute timings"),Lt=()=>{const[n,r]=(0,e.useState)(null),[l,s]=(0,Ce.Z)(!1),d=(0,e.useCallback)(()=>{r(null),s(!1)},[s]),p=I=>{r(I),s(!0)};return[(0,e.useMemo)(()=>!n||!l?null:n===Se?e.createElement(le,{onClose:d}):e.createElement(le,{muteTimingName:n,onClose:d}),[l,d,n]),p]},wt=({alertManagerSourceName:n,muteTimingNames:r,hideActions:l})=>{const s=(0,f.wW)(Ut),d=(0,U.I0)(),{currentData:p}=(0,P.W)(n,{refetchOnFocus:!0,refetchOnReconnect:!0}),i=p?.alertmanager_config,[I,v]=(0,e.useState)(""),N=(0,e.useMemo)(()=>{const ce=i?.mute_time_intervals??[],Y=i?.muteTimeProvenances??{};return ce.filter(({name:X})=>r?r.includes(X):!0).map(X=>({id:X.name,data:{...X,provenance:Y[X.name]}}))},[i?.mute_time_intervals,i?.muteTimeProvenances,r]),[B,D]=(0,y.RA)(y.oI.CreateMuteTiming),[j,G]=Lt(),[J,C]=(0,y.RA)(y.oI.ExportMuteTimings),$=Ft(n,l,v,G);return e.createElement("div",{className:s.container},e.createElement(u.K,{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(xe.L,null),!l&&N.length>0&&e.createElement(A.q,{actions:[y.oI.CreateMuteTiming]},e.createElement(K.Qj,{className:s.muteTimingsButtons,icon:"plus",variant:"primary",href:(0,te.eQ)("alerting/routes/mute-timing/new",n)},"Add mute timing")),J&&e.createElement(K.zx,{icon:"download-alt",className:s.muteTimingsButtons,variant:"secondary","aria-label":"export all",disabled:!C,onClick:()=>G(Se)},"Export all")),N.length>0?e.createElement(Me.t,{items:N,cols:$,pagination:{itemsPerPage:25}}):l?e.createElement(De,{text:"No mute timings configured",buttonLabel:"",showButton:!1}):e.createElement(De,{text:"You haven't created any mute timings yet",buttonLabel:"Add mute timing",buttonIcon:"plus",buttonSize:"lg",href:(0,te.eQ)("alerting/routes/mute-timing/new",n),showButton:D}),!l&&e.createElement(c.s,{isOpen:!!I,title:"Delete mute timing",body:`Are you sure you would like to delete "${I}"`,confirmText:"Delete",onConfirm:()=>{d((0,re.r0)(n,I)),v("")},onDismiss:()=>v("")}),j)};function Ft(n,r=!1,l,s){const[[d,p],[i,I]]=(0,y.o2)([y.oI.UpdateMuteTiming,y.oI.DeleteMuteTiming]),v=!r&&(p||I),[N,B]=(0,y.RA)(y.oI.ExportMuteTimings);return(0,e.useMemo)(()=>{const D=[{id:"name",label:"Name",renderCell:function({data:G}){return e.createElement(e.Fragment,null,G.name," ",G.provenance&&e.createElement(Oe.C0,null))},size:"250px"},{id:"timeRange",label:"Time range",renderCell:({data:j})=>(0,Ge.Nx)(j)}];return v&&D.push({id:"actions",label:"Actions",renderCell:function({data:G}){return G.provenance?e.createElement("div",null,e.createElement(w.r,{href:(0,te.eQ)("/alerting/routes/mute-timing/edit",n,{muteName:G.name})},e.createElement(E.h,{name:"file-alt",tooltip:"View mute timing"}))):e.createElement("div",null,e.createElement(A.q,{actions:[y.oI.UpdateMuteTiming]},e.createElement(w.r,{href:(0,te.eQ)("/alerting/routes/mute-timing/edit",n,{muteName:G.name})},e.createElement(E.h,{name:"edit",tooltip:"Edit mute timing"}))),e.createElement(A.q,{actions:[y.oI.DeleteMuteTiming]},e.createElement(E.h,{name:"trash-alt",tooltip:"Delete mute timing",onClick:()=>l(G.name)})))},size:"80px"}),N&&D.push({id:"actions",label:"",renderCell:function({data:G}){return e.createElement("div",null,e.createElement(W.v.Item,{icon:"download-alt",label:"Export",ariaLabel:"export",disabled:!B,"data-testid":"export",onClick:()=>s(G.name)}))},size:"100px"}),D},[n,l,v,N,B,s])}const Ut=n=>({container:(0,a.css)`
    display: flex;
    flex-flow: column nowrap;
  `,muteTimingsButtons:(0,a.css)`
    margin-bottom: ${n.spacing(2)};
    align-self: flex-end;
  `});var k=t(20519),Kt=t(57445),Re=t(14607),$e=t(97666),ot=t(24956),Te=t(27436),jt=t(75636),Qe=t(98724);const Vt=({receivers:n,onChangeReceiver:r,onChangeMatchers:l})=>{const[s,d]=(0,jt.j)(),p=(0,e.useRef)(null),{queryString:i,contactPoint:I}=Zt(s),v=(0,f.wW)(Qt),N=(0,e.useCallback)(()=>(0,o.debounce)(l,500),[l]);(0,e.useEffect)(()=>{r(I)},[I,r]),(0,e.useEffect)(()=>{const C=(0,Qe.Zh)(i??"").map(Qe.xz);N()(C)},[N,i]);const B=(0,e.useCallback)(()=>{p.current&&(p.current.value=""),d({contactPoint:void 0,queryString:void 0})},[d]),D=n.map(zt),j=D.find(C=>C.value===I)??null,G=i||I,J=i&&i.length>3?(0,Qe.Zh)(i).length===0:!1;return e.createElement(u.K,{direction:"row",alignItems:"flex-start",gap:.5},e.createElement(k.g,{className:v.noBottom,label:e.createElement(Kt._,null,e.createElement(u.K,{gap:.5},e.createElement("span",null,"Search by matchers"),e.createElement(Re.u,{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($e.J,{name:"info-circle",size:"sm"})))),invalid:J,error:J?"Query must use valid matcher syntax":null},e.createElement(ot.I,{ref:p,"data-testid":"search-query-input",placeholder:"Search",width:46,prefix:e.createElement($e.J,{name:"search"}),onChange:C=>{d({queryString:C.currentTarget.value})},defaultValue:i})),e.createElement(k.g,{label:"Search by contact point",style:{marginBottom:0}},e.createElement(Te.Ph,{id:"receiver","aria-label":"Search by contact point",value:j,options:D,onChange:C=>{d({contactPoint:C?.value})},width:28,isClearable:!0})),G&&e.createElement(K.zx,{variant:"secondary",icon:"times",onClick:B,style:{marginTop:19}},"Clear filters"))};function Pt(n,r){const l=[];function s(d){r(d)&&l.push(d),d.routes?.forEach(s)}return s(n),l}const zt=n=>({label:n.name,value:n.name}),Zt=n=>({queryString:n.get("queryString")??void 0,contactPoint:n.get("contactPoint")??void 0}),Qt=()=>({noBottom:(0,a.css)`
    margin-bottom: 0;
  `});var ge=t(7288),Ht=t(75682),He=t(16901),Jt=t(19311),Yt=t(4609),Xt=t(84639),lt=t(58533),kt=t(66564);const qt=()=>{const{installed:n}=(0,Xt.n)(lt.W.OnCall),{data:r}=Yt.onCallApi.useGrafanaOnCallIntegrationsQuery(void 0,{skip:!n});return s=>{const d=r??[];if(n&&(0,kt.Fs)(s,d))return lt.W.OnCall}},It=n=>{const r=qt(),l=s=>({label:s.name,value:s.name,grafanaAppReceiverType:r(s)});return n.map(l)};var _t=t(53136),Je=t.n(_t),Le=t(67192);const en=({active:n=0,suppressed:r=0,unprocessed:l=0})=>{const s=[],d=n+r+l;return n&&s.push(e.createElement(Le.C,{color:"red",key:"firing",text:`${n} firing`})),r&&s.push(e.createElement(Le.C,{color:"blue",key:"suppressed",text:`${r} suppressed`})),l&&s.push(e.createElement(Le.C,{color:"orange",key:"unprocessed",text:`${l} unprocessed`})),s.length>1&&s.unshift(e.createElement(e.Fragment,{key:"total"},d," ",Je()("instance",d))),!!s.length?e.createElement(u.K,{gap:.5},s):null};var Dt=t(66596),We=t(96130),tn=t(8655),z=t(71803),Ne=t(18649),Ot=t(6681),Ye=t(49131);const nn=({actionButtons:n,alertManagerSourceName:r,onSubmit:l,receivers:s,route:d})=>{const p=(0,f.wW)(Ot.S),[i,I]=(0,e.useState)(!1),[v,N]=(0,e.useState)((0,z.eh)(d.group_by)),B=(0,z.ZS)(d);return e.createElement(Dt.l,{defaultValues:{...B,overrideTimings:!0,overrideGrouping:!0},onSubmit:l},({register:D,control:j,errors:G,setValue:J,getValues:C})=>e.createElement(e.Fragment,null,e.createElement(k.g,{label:"Default contact point",invalid:!!G.receiver,error:G.receiver?.message},e.createElement(e.Fragment,null,e.createElement("div",{className:p.container,"data-testid":"am-receiver-select"},e.createElement(We.g,{render:({field:{onChange:$,ref:ce,...Y}})=>e.createElement(Te.Ph,{"aria-label":"Default contact point",...Y,className:p.input,onChange:X=>$((0,z.mJ)(X)),options:s}),control:j,name:"receiver",rules:{required:{value:!0,message:"Required."}}}),e.createElement("span",null,"or"),e.createElement(w.r,{className:p.linkText,href:(0,te.eQ)("/alerting/notifications/receivers/new",r)},"Create a contact point")))),e.createElement(k.g,{label:"Group by",description:"Group alerts when you receive a notification based on labels.","data-testid":"am-group-select"},e.createElement(We.g,{render:({field:{onChange:$,ref:ce,...Y}})=>e.createElement(Te.NU,{"aria-label":"Group by",...Y,allowCustomValue:!0,className:p.input,onCreateOption:X=>{N(V=>[...V,(0,z.T0)(X)]),J("groupBy",[...Y.value,X])},onChange:X=>$((0,z.bi)(X)),options:[...z.dO,...v]}),control:j,name:"groupBy"})),e.createElement(tn.U,{collapsible:!0,className:p.collapse,isOpen:i,label:"Timing options",onToggle:I},e.createElement("div",{className:p.timingFormContainer},e.createElement(k.g,{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:!!G.groupWaitValue,error:G.groupWaitValue?.message,"data-testid":"am-group-wait"},e.createElement(Ne.N,{...D("groupWaitValue",{validate:z.Oy}),placeholder:Ye.M.group_wait,className:p.promDurationInput,"aria-label":"Group wait"})),e.createElement(k.g,{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:!!G.groupIntervalValue,error:G.groupIntervalValue?.message,"data-testid":"am-group-interval"},e.createElement(Ne.N,{...D("groupIntervalValue",{validate:z.Oy}),placeholder:Ye.M.group_interval,className:p.promDurationInput,"aria-label":"Group interval"})),e.createElement(k.g,{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:!!G.repeatIntervalValue,error:G.repeatIntervalValue?.message,"data-testid":"am-repeat-interval"},e.createElement(Ne.N,{...D("repeatIntervalValue",{validate:$=>{const ce=C("groupIntervalValue");return(0,z.eP)($,ce)}}),placeholder:Ye.M.repeat_interval,className:p.promDurationInput,"aria-label":"Repeat interval"})))),e.createElement("div",{className:p.container},n)))};var an=t(59885),st=t(5999),rn=t(74321),on=t(62208),fe=t(76532);const xt=({actionButtons:n,receivers:r,route:l,onSubmit:s,defaults:d})=>{const p=(0,f.wW)(sn),i=(0,f.wW)(Ot.S),[I,v]=(0,e.useState)((0,z.eh)(l?.group_by)),N=(0,on.s)(),B=[{name:"",operator:He._M.equal,value:""}],D=r.sort(ln),j={...(0,z.ZS)(l),...d},G={...j,object_matchers:l?j.object_matchers:B};return e.createElement(Dt.l,{defaultValues:G,onSubmit:s,maxWidth:"none"},({control:J,register:C,errors:$,setValue:ce,watch:Y,getValues:X})=>e.createElement(e.Fragment,null,e.createElement("input",{type:"hidden",...C("id")}),e.createElement(an.F,{name:"object_matchers",control:J},({fields:V,append:oe,remove:ae})=>e.createElement(e.Fragment,null,e.createElement(u.K,{direction:"column",alignItems:"flex-start"},e.createElement("div",null,"Matching labels"),V.length===0&&e.createElement(Le.C,{color:"orange",className:p.noMatchersWarning,icon:"exclamation-triangle",text:"If no matchers are specified, this notification policy will handle all alert instances."}),V.length>0&&e.createElement("div",{className:p.matchersContainer},V.map((_,Z)=>e.createElement(u.K,{direction:"row",key:_.id,alignItems:"center"},e.createElement(k.g,{label:"Label",invalid:!!$.object_matchers?.[Z]?.name,error:$.object_matchers?.[Z]?.name?.message},e.createElement(ot.I,{...C(`object_matchers.${Z}.name`,{required:"Field is required"}),defaultValue:_.name,placeholder:"label",autoFocus:!0})),e.createElement(k.g,{label:"Operator"},e.createElement(We.g,{render:({field:{onChange:F,ref:we,...Pe}})=>e.createElement(Te.Ph,{...Pe,className:p.matchersOperator,onChange:ye=>F(ye?.value),options:Qe.tA,"aria-label":"Operator"}),defaultValue:_.operator,control:J,name:`object_matchers.${Z}.operator`,rules:{required:{value:!0,message:"Required."}}})),e.createElement(k.g,{label:"Value",invalid:!!$.object_matchers?.[Z]?.value,error:$.object_matchers?.[Z]?.value?.message},e.createElement(ot.I,{...C(`object_matchers.${Z}.value`,{required:"Field is required"}),defaultValue:_.value,placeholder:"value"})),e.createElement(E.h,{tooltip:"Remove matcher",name:"trash-alt",onClick:()=>ae(Z)},"Remove")))),e.createElement(K.zx,{className:p.addMatcherBtn,icon:"plus",onClick:()=>oe(z.fx),variant:"secondary",type:"button"},"Add matcher")))),e.createElement(k.g,{label:"Contact point"},e.createElement(We.g,{render:({field:{onChange:V,ref:oe,...ae}})=>e.createElement(Te.Ph,{"aria-label":"Contact point",...ae,className:i.input,onChange:_=>V((0,z.mJ)(_)),options:D,isClearable:!0}),control:J,name:"receiver"})),e.createElement(k.g,{label:"Continue matching subsequent sibling nodes"},e.createElement(st.r,{id:"continue-toggle",...C("continue")})),e.createElement(k.g,{label:"Override grouping"},e.createElement(st.r,{id:"override-grouping-toggle",...C("overrideGrouping")})),Y().overrideGrouping&&e.createElement(k.g,{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(We.g,{rules:{validate:V=>!V||V.length===0?"At least one group by option is required.":!0},render:({field:{onChange:V,ref:oe,...ae},fieldState:{error:_}})=>e.createElement(e.Fragment,null,e.createElement(Te.NU,{"aria-label":"Group by",...ae,invalid:!!_,allowCustomValue:!0,className:i.input,onCreateOption:Z=>{v(F=>[...F,(0,z.T0)(Z)]),ce("groupBy",[...ae.value,Z])},onChange:Z=>V((0,z.bi)(Z)),options:[...z.dO,...I]}),_&&e.createElement(rn.S,null,_.message)),control:J,name:"groupBy"})),e.createElement(k.g,{label:"Override general timings"},e.createElement(st.r,{id:"override-timings-toggle",...C("overrideTimings")})),Y().overrideTimings&&e.createElement(e.Fragment,null,e.createElement(k.g,{label:fe.j.groupWait.label,description:fe.j.groupWait.description,invalid:!!$.groupWaitValue,error:$.groupWaitValue?.message},e.createElement(Ne.N,{...C("groupWaitValue",{validate:z.Oy}),"aria-label":fe.j.groupWait.ariaLabel,className:i.promDurationInput})),e.createElement(k.g,{label:fe.j.groupInterval.label,description:fe.j.groupInterval.description,invalid:!!$.groupIntervalValue,error:$.groupIntervalValue?.message},e.createElement(Ne.N,{...C("groupIntervalValue",{validate:z.Oy}),"aria-label":fe.j.groupInterval.ariaLabel,className:i.promDurationInput})),e.createElement(k.g,{label:fe.j.repeatInterval.label,description:fe.j.repeatInterval.description,invalid:!!$.repeatIntervalValue,error:$.repeatIntervalValue?.message},e.createElement(Ne.N,{...C("repeatIntervalValue",{validate:(V="")=>{const oe=X("groupIntervalValue");return(0,z.eP)(V,oe)}}),"aria-label":fe.j.repeatInterval.ariaLabel,className:i.promDurationInput}))),e.createElement(k.g,{label:"Mute timings","data-testid":"am-mute-timing-select",description:"Add mute timing to policy",invalid:!!$.muteTimeIntervals},e.createElement(We.g,{render:({field:{onChange:V,ref:oe,...ae}})=>e.createElement(Te.NU,{"aria-label":"Mute timings",...ae,className:i.input,onChange:_=>V((0,z.bi)(_)),options:N}),control:J,name:"muteTimeIntervals"})),n))};function ln(n){return n.grafanaAppReceiverType===lt.W.OnCall?-1:0}const sn=n=>{const r=n.spacing(3.5);return{addMatcherBtn:(0,a.css)`
      margin-bottom: ${r};
    `,matchersContainer:(0,a.css)`
      background-color: ${n.colors.background.secondary};
      padding: ${n.spacing(1.5)} ${n.spacing(2)};
      padding-bottom: 0;
      width: fit-content;
    `,matchersOperator:(0,a.css)`
      min-width: 120px;
    `,noMatchersWarning:(0,a.css)`
      padding: ${n.spacing(1)} ${n.spacing(2)};
    `}};var St=t(7914);const cn=(n=[],r,l)=>{const[s,d]=(0,e.useState)(!1),[p,i]=(0,e.useState)(),I=It(n),v=(0,e.useCallback)(()=>{i(void 0),d(!1)},[]),N=(0,e.useCallback)(D=>{i(D),d(!0)},[]);return[(0,e.useMemo)(()=>l?e.createElement(it,{isOpen:s}):e.createElement(ge.u,{isOpen:s,onDismiss:v,closeOnBackdropClick:!0,closeOnEscape:!0,title:"Add notification policy"},e.createElement(xt,{receivers:I,defaults:{groupBy:p?.group_by},onSubmit:D=>p&&r(D,p),actionButtons:e.createElement(ge.u.ButtonRow,null,e.createElement(K.zx,{type:"button",variant:"secondary",onClick:v,fill:"outline"},"Cancel"),e.createElement(K.zx,{type:"submit"},"Save policy"))})),[I,r,v,l,p,s]),N,v]},mn=(n,r,l,s)=>{const[d,p]=(0,e.useState)(!1),[i,I]=(0,e.useState)(!1),[v,N]=(0,e.useState)(),B=It(r),D=(0,e.useCallback)(()=>{N(void 0),p(!1)},[]),j=(0,e.useCallback)((J,C)=>{I(C??!1),N(J),p(!0)},[]);return[(0,e.useMemo)(()=>s?e.createElement(it,{isOpen:d}):e.createElement(ge.u,{isOpen:d,onDismiss:D,closeOnBackdropClick:!0,closeOnEscape:!0,title:"Edit notification policy"},i&&v&&e.createElement(nn,{alertManagerSourceName:n,onSubmit:l,receivers:B,route:v,actionButtons:e.createElement(ge.u.ButtonRow,null,e.createElement(K.zx,{type:"button",variant:"secondary",onClick:D,fill:"outline"},"Cancel"),e.createElement(K.zx,{type:"submit"},"Update default policy"))}),!i&&e.createElement(xt,{receivers:B,route:v,onSubmit:l,actionButtons:e.createElement(ge.u.ButtonRow,null,e.createElement(K.zx,{type:"button",variant:"secondary",onClick:D,fill:"outline"},"Cancel"),e.createElement(K.zx,{type:"submit"},"Update policy"))})),[B,n,D,l,i,s,v,d]),j,D]},un=(n,r)=>{const[l,s]=(0,e.useState)(!1),[d,p]=(0,e.useState)(),i=(0,e.useCallback)(()=>{p(void 0),s(!1)},[p]),I=(0,e.useCallback)(B=>{p(B),s(!0)},[]),v=(0,e.useCallback)(()=>{d&&n(d)},[n,d]);return[(0,e.useMemo)(()=>r?e.createElement(it,{isOpen:l}):e.createElement(ge.u,{isOpen:l,onDismiss:i,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.u.ButtonRow,null,e.createElement(K.zx,{type:"button",variant:"destructive",onClick:v},"Yes, delete policy"),e.createElement(K.zx,{type:"button",variant:"secondary",onClick:i},"Cancel"))),[i,v,r,l]),I,i]},dn=()=>{const[n,r]=(0,e.useState)(!1),[l,s]=(0,e.useState)([]),[d,p]=(0,e.useState)([]),i=(0,e.useCallback)(()=>{r(!1),s([]),p([])},[]),I=(0,e.useCallback)((B,D)=>{s(B),D&&p(D),r(!0)},[]),v=(0,e.useMemo)(()=>{const B=l.flatMap(D=>D.alerts);return(0,o.groupBy)(B,D=>D.status.state)},[l]);return[(0,e.useMemo)(()=>e.createElement(ge.u,{isOpen:n,onDismiss:i,closeOnBackdropClick:!0,closeOnEscape:!0,title:e.createElement(u.K,{direction:"row",alignItems:"center",gap:1,wrap:"wrap"},e.createElement(u.K,{direction:"row",alignItems:"center",gap:.5},e.createElement($e.J,{name:"x"})," Matchers"),e.createElement(St.g,{matchers:d}))},e.createElement(u.K,{direction:"column"},e.createElement(en,{active:v[He.Z9.Active]?.length,suppressed:v[He.Z9.Suppressed]?.length,unprocessed:v[He.Z9.Unprocessed]?.length}),e.createElement("div",null,l.map((B,D)=>e.createElement(Jt.y,{key:D,alertManagerSourceName:"",group:B})))),e.createElement(ge.u.ButtonRow,null,e.createElement(K.zx,{type:"button",variant:"secondary",onClick:i},"Cancel"))),[l,i,v,d,n]),I,i]},it=({isOpen:n})=>e.createElement(ge.u,{isOpen:n,onDismiss:()=>{},closeOnBackdropClick:!1,closeOnEscape:!1,title:e.createElement(u.K,{direction:"row",alignItems:"center",gap:.5},"Updating... ",e.createElement(Ht.$,{inline:!0}))},"Please wait while we update your notification policies.");var Xe=t(16088),gn=t(44839),Rt=t(40377),pn=t(97096),ct=t(26321),En=t(5493),Wt=t(41460),Nt=t(59439),mt=t(23595),ut=t(34340),he=t(46911),ie=t(35855);const vn=({exportFormat:n,onClose:r})=>{const{currentData:l="",isFetching:s}=Ae.alertRuleApi.useExportPoliciesQuery({format:n}),d=`policies-${new Date().getTime()}`;return s?e.createElement(m.u,{text:"Loading...."}):e.createElement(Ve.u,{format:n,textDefinition:l,downloadFileName:d,onClose:r})},fn=({onClose:n})=>{const[r,l]=(0,e.useState)("yaml");return e.createElement(ze.i,{activeTab:r,onTabChange:l,onClose:n,formatProviders:Object.values(Ze.uN)},e.createElement(vn,{exportFormat:r,onClose:n}))},Bt=({receivers:n=[],contactPointsState:r,readOnly:l=!1,provisioned:s=!1,alertGroups:d=[],alertManagerSourceName:p,currentRoute:i,routeTree:I,inheritedProperties:v,routesMatchingFilters:N=[],matchingInstancesPreview:B={enabled:!1},onEditPolicy:D,onAddPolicy:j,onDeletePolicy:G,onShowAlertInstances:J})=>{const C=(0,f.wW)(ke),$=i===I,[[ce,Y],[X,V],[oe,ae]]=(0,y.o2)([y.oI.UpdateNotificationPolicyTree,y.oI.DeleteNotificationPolicy,y.oI.ExportNotificationPolicies]),_=i.receiver,Z=i.continue??!1,F=i.group_by,we=i.mute_time_intervals??[],Pe={group_wait:i.group_wait,group_interval:i.group_interval,repeat_interval:i.repeat_interval},ye=(0,Wt.QO)(i),qe=!!(ye&&ye.length),pt=!!we.length,Et=N.some(me=>me.id===i.id),Fe=[],vt=!qe&&!$&&!Z,Ue=_??v?.receiver??"";(r?In(Ue,r):[]).forEach(me=>{Fe.push(me)});const _e=v&&Object.keys(v).length>0,ft=i.routes??[],ht=_e&&v.group_by,et=(0,o.isArray)(F)&&F[0]==="...",yt=!et&&(0,o.isArray)(F)&&F.length>0,bt=$&&(0,o.isArray)(F)&&F.length===0,Be=B?.groupsMap?.get(i.id),tt=Be?(0,o.sumBy)(Be,me=>me.alerts.length):void 0,[Mt,nt]=(0,Ce.Z)(!1),At=ae&&oe&&$,Ct=ce&&Y,Tt=X&&V&&!$,Ie=[];return Ct&&Ie.push(e.createElement(e.Fragment,{key:"edit-policy"},e.createElement(ct.Z,{shouldWrap:s,wrap:dt},e.createElement(W.v.Item,{icon:"edit",disabled:s,label:"Edit",onClick:()=>D(i,$)})))),At&&Ie.push(e.createElement(W.v.Item,{key:"export-policy",icon:"download-alt",label:"Export",onClick:nt})),Tt&&Ie.push(e.createElement(e.Fragment,{key:"delete-policy"},e.createElement(W.v.Divider,null),e.createElement(ct.Z,{shouldWrap:s,wrap:dt},e.createElement(W.v.Item,{destructive:!0,icon:"trash-alt",disabled:s,label:"Delete",onClick:()=>G(i)})))),e.createElement(u.K,{direction:"column",gap:1.5},e.createElement("div",{className:C.policyWrapper(Et),"data-testid":$?"am-root-route-container":"am-route-container"},Z&&e.createElement(yn,null),vt&&e.createElement(bn,null),e.createElement("div",{className:C.policyItemWrapper},e.createElement(u.K,{direction:"column",gap:1},e.createElement("div",null,e.createElement(u.K,{direction:"row",alignItems:"center",gap:1},$?e.createElement(Mn,null):qe?e.createElement(St.g,{matchers:ye??[]}):e.createElement("span",{className:C.metadata},"No matchers"),e.createElement(xe.L,null),Fe.length>0&&e.createElement(hn,{errors:Fe}),s&&e.createElement(Oe.C0,null),!l&&e.createElement(u.K,{direction:"row",gap:.5},e.createElement(A.q,{actions:[y.oI.CreateNotificationPolicy]},e.createElement(ct.Z,{shouldWrap:s,wrap:dt},e.createElement(K.zx,{variant:"secondary",icon:"plus",size:"sm",onClick:()=>j(i),disabled:s,type:"button"},"New nested policy"))),Ie.length>0&&e.createElement(gn.L,{overlay:e.createElement(W.v,null,Ie)},e.createElement(K.zx,{icon:"ellipsis-h",variant:"secondary",size:"sm",type:"button","aria-label":"more-actions","data-testid":"more-actions"}))))),e.createElement("div",{className:C.metadataRow},e.createElement(u.K,{direction:"row",alignItems:"center",gap:1},B.enabled&&e.createElement(he.g,{icon:"layers-alt",onClick:()=>{Be&&J(Be,ye)},"data-testid":"matching-instances"},e.createElement(ie.c,null,tt??"-"),e.createElement("span",null,Je()("instance",tt))),_&&e.createElement(he.g,{icon:"at","data-testid":"contact-point"},e.createElement("span",null,"Delivered to"),e.createElement(Pn,{alertManagerSourceName:p,receivers:n,contactPoint:_})),!ht&&e.createElement(e.Fragment,null,yt&&e.createElement(he.g,{icon:"layer-group","data-testid":"grouping"},e.createElement("span",null,"Grouped by"),e.createElement(ie.c,null,F.join(", "))),bt&&e.createElement(he.g,{icon:"layer-group"},e.createElement("span",null,"Single group")),et&&e.createElement(he.g,{icon:"layer-group"},e.createElement("span",null,"Not grouping"))),pt&&e.createElement(he.g,{icon:"calendar-slash","data-testid":"mute-timings"},e.createElement("span",null,"Muted when"),e.createElement(Cn,{timings:we,alertManagerSourceName:p})),Pe&&e.createElement(Tn,{timingOptions:$?(0,o.defaults)(Pe,Ye.M):Pe}),_e&&e.createElement(e.Fragment,null,e.createElement(he.g,{icon:"corner-down-right-alt","data-testid":"inherited-properties"},e.createElement("span",null,"Inherited"),e.createElement(An,{properties:v})))))))),e.createElement("div",{className:C.childPolicies},ft.map(me=>{const at=(0,Nt.$2)(i,me,v);return e.createElement(Bt,{key:(0,o.uniqueId)(),routeTree:I,currentRoute:me,receivers:n,contactPointsState:r,readOnly:l||s,inheritedProperties:at,onAddPolicy:j,onEditPolicy:D,onDeletePolicy:G,onShowAlertInstances:J,alertManagerSourceName:p,alertGroups:d,routesMatchingFilters:N,matchingInstancesPreview:B})})),Mt&&e.createElement(fn,{onClose:nt}))},dt=n=>e.createElement(Re.u,{content:"Provisioned items cannot be edited in the UI",placement:"top"},e.createElement("span",null,n)),hn=({errors:n})=>e.createElement(mt.z,{arrow:!0,placement:"top",content:e.createElement(u.K,{direction:"column",gap:.5},n.map(r=>e.createElement(e.Fragment,{key:(0,o.uniqueId)()},r)))},e.createElement("span",null,e.createElement(Le.C,{icon:"exclamation-circle",color:"red",text:Je()("error",n.length,!0)}))),yn=()=>{const n=(0,f.wW)(ke);return e.createElement(Re.u,{placement:"top",content:"This route will continue matching other policies"},e.createElement("div",{className:n.gutterIcon,"data-testid":"continue-matching"},e.createElement($e.J,{name:"arrow-down"})))},bn=()=>{const n=(0,f.wW)(ke);return e.createElement(Re.u,{placement:"top",content:"This policy matches all labels"},e.createElement("div",{className:n.gutterIcon,"data-testid":"matches-all"},e.createElement($e.J,{name:"exclamation-triangle"})))},Mn=()=>{const n=(0,f.wW)(ke);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."))},An=({properties:n})=>e.createElement(mt.z,{arrow:!0,placement:"top",content:e.createElement(u.K,{direction:"row",gap:.5},Object.entries(n).map(([r,l])=>e.createElement(ut._,{key:r,label:Dn(r),value:e.createElement(ie.c,null,On(r,l))})))},e.createElement("div",null,e.createElement(ie.c,null,Je()("property",Object.keys(n).length,!0)))),Cn=({timings:n,alertManagerSourceName:r})=>e.createElement("div",null,e.createElement(ie.c,null,n.map(l=>e.createElement(Xe.Link,{key:l,to:(0,te.ET)(l,r)},l)))),Tn=({timingOptions:n})=>{const r=n.group_wait,l=n.group_interval;return!r&&!l?null:e.createElement(he.g,{icon:"hourglass","data-testid":"timing-options"},e.createElement("span",null,"Wait"),r&&e.createElement(Re.u,{placement:"top",content:"How long to initially wait to send a notification for a group of alert instances."},e.createElement("span",null,e.createElement(ie.c,null,r)," ",e.createElement("span",null,"to group instances"),r&&l&&",")),l&&e.createElement(Re.u,{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(ie.c,null,l)," ",e.createElement("span",null,"before sending updates"))))},Pn=({alertManagerSourceName:n,contactPoint:r,receivers:l})=>{const s=l.find(i=>i.name===r);if(!s)return e.createElement(Xe.Link,{to:(0,te.GV)(r,n)},e.createElement(ie.c,null,r));if(!s.grafana_managed_receiver_configs)return e.createElement(Xe.Link,{to:(0,te.GV)(r,n)},e.createElement(ie.c,null,r));const p=(0,o.groupBy)(s.grafana_managed_receiver_configs,i=>i.type);return e.createElement(mt.z,{arrow:!0,placement:"top",header:e.createElement(he.g,{icon:"at"},e.createElement("div",null,"Contact Point"),e.createElement(ie.c,null,r)),key:(0,o.uniqueId)(),content:e.createElement(u.K,{direction:"row",gap:.5},Object.entries(p).map(([i,I])=>e.createElement(ut._,{key:(0,o.uniqueId)(),label:I.length>1?I.length:void 0,icon:En.y[i],value:(0,o.upperFirst)(i)})))},e.createElement(Xe.Link,{to:(0,te.GV)(r,n)},e.createElement(ie.c,null,r)))};function In(n,r){return Object.entries(r[n]?.notifiers??[]).reduce((d=[],[p,i])=>{const I=i.filter(v=>v.lastNotifyAttemptError).map(v=>e.createElement(ut._,{icon:"at",key:(0,o.uniqueId)(),label:`Contact Point \u203A ${v.name}`,value:v.lastNotifyAttemptError}));return d.concat(I)},[])}const Dn=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}},On=(n,r)=>{const l=n==="group_by"&&Array.isArray(r)&&r[0]==="...",s=n==="group_by"&&Array.isArray(r)&&r.length===0;return l?e.createElement(Rt.x,{variant:"bodySmall",color:"secondary"},"Not grouping"):s?e.createElement(Rt.x,{variant:"bodySmall",color:"secondary"},"Single group"):Array.isArray(r)?r.join(", "):r},ke=n=>({matcher:r=>{const{color:l,borderColor:s}=(0,pn.Bx)(r);return{wrapper:(0,a.css)`
        color: #fff;
        background: ${l};
        padding: ${n.spacing(.33)} ${n.spacing(.66)};
        font-size: ${n.typography.bodySmall.fontSize};

        border: solid 1px ${s};
        border-radius: ${n.shape.radius.default};
      `}},childPolicies:(0,a.css)`
    margin-left: ${n.spacing(4)};
    position: relative;

    &:before {
      content: '';
      position: absolute;
      height: calc(100% - 10px);

      border-left: solid 1px ${n.colors.border.weak};

      margin-top: 0;
      margin-left: -20px;
    }
  `,policyItemWrapper:(0,a.css)`
    padding: ${n.spacing(1.5)};
  `,metadataRow:(0,a.css)`
    background: ${n.colors.background.secondary};

    border-bottom-left-radius: ${n.shape.borderRadius(2)};
    border-bottom-right-radius: ${n.shape.borderRadius(2)};
  `,policyWrapper:(r=!1)=>(0,a.css)`
    flex: 1;
    position: relative;
    background: ${n.colors.background.secondary};

    border-radius: ${n.shape.radius.default};
    border: solid 1px ${n.colors.border.weak};

    ${r&&(0,a.css)`
      border-color: ${n.colors.primary.border};
    `}
  `,metadata:(0,a.css)`
    color: ${n.colors.text.secondary};

    font-size: ${n.typography.bodySmall.fontSize};
    font-weight: ${n.typography.bodySmall.fontWeight};
  `,break:(0,a.css)`
    width: 100%;
    height: 0;
    margin-bottom: ${n.spacing(2)};
  `,gutterIcon:(0,a.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;
    text-align: center;

    border: solid 1px ${n.colors.border.weak};
    border-radius: ${n.shape.radius.default};

    padding: 0;
  `});var xn=t(84954),Sn=t(78025),Rn=t(30422),gt=t(5476),Wn=(n=>(n.NotificationPolicies="notification_policies",n.MuteTimings="mute_timings",n))(Wn||{});const Nn=()=>{const n=(0,L.useDispatch)(),r=(0,f.wW)(Bn),{useGetAlertmanagerAlertGroupsQuery:l}=Q.alertmanagerApi,[s,d]=(0,b.K)(),{tab:p}=Gn(s),[i,I]=(0,e.useState)(p),[v,N]=(0,e.useState)(!1),[B,D]=(0,e.useState)(),[j,G]=(0,e.useState)([]),{getRouteGroupsMap:J}=(0,Sn.N)(),{selectedAlertmanager:C,hasConfigurationAPI:$}=(0,xn.ZA)(),ce=pe(C??""),{currentData:Y,isLoading:X,error:V}=(0,P.W)(C,{refetchOnFocus:!0,refetchOnReconnect:!0}),oe=Y?.alertmanager_config,{currentData:ae,refetch:_}=l({amSourceName:C??""},{skip:!C}),Z=oe?.receivers??[],F=(0,e.useMemo)(()=>{if(oe?.route)return(0,z.br)(oe.route)},[oe?.route]),[{value:we,error:Pe},ye]=(0,M.Z)(J,[J]);(0,e.useEffect)(()=>{F&&ae&&ye(F,ae)},[F,ae,ye]);const qe=(0,e.useMemo)(()=>F?Gt(F,{contactPointFilter:B,labelMatchersFilter:j}):[],[B,j,F]),pt=!!oe?.route?.provenance;function Et(be){if(!F)return;const Ke=(0,gt.SF)(C??"",be,F);Ue(Ke)}function Fe(be){if(!F)return;const Ke=(0,gt.wB)(be,F);Ue(Ke)}function vt(be,Ke){if(!F)return;const wn=(0,gt._P)(C??"",be,Ke,F);Ue(wn)}function Ue(be){Y&&(N(!0),n((0,re.mM)({newConfig:{...Y,alertmanager_config:{...Y.alertmanager_config,route:be}},oldConfig:Y,alertManagerSourceName:C,successMessage:"Updated notification policies"})).unwrap().then(()=>{C&&_(),yt(),ft(),tt()}).finally(()=>{N(!1)}))}const[$t,_e,ft]=cn(Z,vt,v),[ht,et,yt]=mn(C??"",Z,Et,v),[bt,Be,tt]=un(Fe,v),[Mt,nt]=dn();if((0,R.x)(be=>be.unifiedAlerting.saveAMConfig=Rn.oq),!C)return null;const At=Y?.alertmanager_config.mute_time_intervals?.length??0,Ct=Y&&!V&&!X,Tt=!Y&&X,Ie=V&&!X,me=i==="mute_timings",at=i==="notification_policies";return e.createElement(e.Fragment,null,e.createElement(O.J,null,e.createElement(h.O,{label:"Notification Policies",active:at,onChangeTab:()=>{I("notification_policies"),d({tab:"notification_policies"})}}),e.createElement(h.O,{label:"Mute Timings",active:me,counter:At,onChangeTab:()=>{I("mute_timings"),d({tab:"mute_timings"})}})),e.createElement(S.I,{className:r.tabContent},Tt&&e.createElement(m.u,{text:"Loading Alertmanager config..."}),Ie&&e.createElement(T.b,{severity:"error",title:"Error loading Alertmanager config"},V.message||"Unknown error."),Ct&&e.createElement(e.Fragment,null,at&&e.createElement(e.Fragment,null,e.createElement(se.u,{currentAlertmanager:C}),e.createElement(u.K,{direction:"column",gap:1},F&&e.createElement(Vt,{receivers:Z,onChangeMatchers:G,onChangeReceiver:D}),F&&e.createElement(Bt,{receivers:Z,routeTree:F,currentRoute:F,alertGroups:ae??[],contactPointsState:ce.receivers,readOnly:!$,provisioned:pt,alertManagerSourceName:C,onAddPolicy:_e,onEditPolicy:et,onDeletePolicy:Be,onShowAlertInstances:nt,routesMatchingFilters:qe,matchingInstancesPreview:{groupsMap:we,enabled:!Pe}})),$t,ht,bt,Mt),me&&e.createElement(wt,{alertManagerSourceName:C,hideActions:!$}))))},Gt=(n,r)=>{const{contactPointFilter:l,labelMatchersFilter:s=[]}=r;let d=[];const p=(0,Nt.tK)(n),i=l?Pt(p,v=>v.receiver===l):void 0;i&&d.push(i);const I=s.length?Pt(p,v=>{const N=(0,Wt.QO)(v);return s.every(B=>N.some(D=>(0,o.isEqual)(B,D)))}):void 0;return I&&d.push(I),(0,o.intersectionBy)(...d,"id")},Bn=n=>({tabContent:(0,a.css)`
    margin-top: ${n.spacing(2)};
  `});function Gn(n){let r="notification_policies";return n.tab==="notification_policies"&&(r="notification_policies"),n.tab==="mute_timings"&&(r="mute_timings"),{tab:r}}const $n=()=>e.createElement(Ee.O,{navId:"am-routes",accessType:"notification"},e.createElement(Nn,null)),Ln=(0,g.Pf)($n,{style:"page"})},65892:(ee,x,t)=>{t.d(x,{J:()=>w,O:()=>E});var a=t(85960),o=t(8134),e=t(20989),M=t(90857),f=t(79055),O=t(66681),h=t(6753),S=t(47257),m=t(74042),T=t(14607),u=t(29165),g=t(49199);const b=({localStoreKey:A,startClosed:y=!1,severity:P="error",collapseText:re,collapseTooltip:te,collapseJustify:Me="flex-end",alertTitle:q,children:De})=>{const je=(0,S.l4)(),Oe=L(je,P),[xe,Ae]=(0,h.Z)(A,y);return a.createElement(a.Fragment,null,xe&&a.createElement(m.Lh,{justify:Me},a.createElement(T.u,{content:te,placement:"bottom"},a.createElement(u.zx,{fill:"text",variant:"secondary",icon:(0,g.j)(P),className:Oe.warningButton,onClick:()=>Ae(!1)},re))),!xe&&a.createElement(g.b,{severity:P,title:q,onRemove:()=>Ae(!0)},De))},L=(A,y)=>{const P=A.colors[y];return{warningButton:(0,O.css)({color:P.text,"&:hover":{background:P.transparent}})}},R="grafana.unifiedalerting.upgrade.previewNotice",Q=()=>M.config.unifiedAlertingEnabled||!M.config.featureToggles.alertingPreviewUpgrade?null:a.createElement(b,{localStoreKey:R,alertTitle:"This is a preview of the upgraded Grafana Alerting",collapseText:"Grafana Alerting Preview",collapseTooltip:"Show preview warning",severity:"warning"},a.createElement("p",null,"No rules are being evaluated and legacy alerting is still running.",a.createElement("br",null),"Please contact your administrator to upgrade permanently."),a.createElement(f.h,{external:!0,href:"https://grafana.com/docs/grafana/latest/alerting/set-up/migrating-alerts/"},"Read about upgrading"));var H=t(84954),ne=t(84933),ue=t(27436),de=t(76679);function pe(A){return A.name===de.GC?"Grafana":A.name.slice(0,37)}const Ee=({disabled:A=!1})=>{const y=(0,S.wW)(se),{selectedAlertmanager:P,availableAlertManagers:re,setSelectedAlertmanager:te}=(0,H.ZA)(),Me=(0,a.useMemo)(()=>re.map(q=>({label:pe(q),value:q.name,imgUrl:q.imgUrl,meta:q.meta})),[re]);return a.createElement(ne._,{className:y.field,label:A?"Alertmanager":"Choose Alertmanager",disabled:A||Me.length===1,"data-testid":"alertmanager-picker"},a.createElement(ue.Ph,{"aria-label":A?"Alertmanager":"Choose Alertmanager",width:29,className:"ds-picker select-container",backspaceRemovesValue:!1,onChange:q=>{q?.value&&te(q.value)},options:Me,maxMenuHeight:500,noOptionsMessage:"No datasources found",value:P,getOptionLabel:q=>q.label}))},se=A=>({field:(0,O.css)`
    margin: 0;
  `}),Ce=()=>a.createElement(g.b,{title:"No Alertmanager found",severity:"warning"},"We could not find any external Alertmanagers and you may not have access to the built-in Grafana Alertmanager."),K=()=>a.createElement(g.b,{title:"Selected Alertmanager not found.",severity:"warning"},"The selected Alertmanager no longer exists or you may not have permission to access it. You can select a different Alertmanager from the dropdown."),c=({availableAlertManagers:A})=>{const y=A.length>0;return a.createElement("div",null,y?a.createElement(K,null):a.createElement(Ce,null))},w=({children:A,isLoading:y,...P})=>a.createElement(e.T,{...P},a.createElement(e.T.Contents,{isLoading:y},a.createElement("div",null,a.createElement(Q,null),A))),E=({children:A,accessType:y,...P})=>{const re=W();return a.createElement(H.h5,{accessType:y},a.createElement(w,{...P,actions:a.createElement(Ee,{disabled:re})},a.createElement(U,null,A)))};function W(){const A=(0,o.Z)();return["/edit","/new"].some(P=>A?.pathname?.includes(P))}const U=({children:A})=>{const{availableAlertManagers:y,selectedAlertmanager:P}=(0,H.ZA)();return P?a.createElement(a.Fragment,null,A):a.createElement(c,{availableAlertManagers:y})}},25661:(ee,x,t)=>{t.d(x,{F:()=>f});var a=t(66681),o=t(85960),e=t(47257),M=t(79253);const f=({renderExpandedContent:h,...S})=>{const m=(0,e.wW)(O);return o.createElement(M.t,{renderExpandedContent:h?(T,u,g)=>o.createElement(o.Fragment,null,u!==g.length-1&&o.createElement("div",{className:(0,a.cx)(m.contentGuideline,m.guideline)}),h(T,u,g)):void 0,renderPrefixHeader:()=>o.createElement("div",{className:m.relative},o.createElement("div",{className:(0,a.cx)(m.headerGuideline,m.guideline)})),renderPrefixCell:(T,u,g)=>o.createElement("div",{className:m.relative},o.createElement("div",{className:(0,a.cx)(m.topGuideline,m.guideline)}),u!==g.length-1&&o.createElement("div",{className:(0,a.cx)(m.bottomGuideline,m.guideline)})),...S})},O=h=>({relative:(0,a.css)`
    position: relative;
    height: 100%;
  `,guideline:(0,a.css)`
    left: -19px;
    border-left: 1px solid ${h.colors.border.weak};
    position: absolute;

    ${h.breakpoints.down("md")} {
      display: none;
    }
  `,topGuideline:(0,a.css)`
    width: 18px;
    border-bottom: 1px solid ${h.colors.border.medium};
    top: 0;
    bottom: 50%;
  `,bottomGuideline:(0,a.css)`
    top: 50%;
    bottom: 0;
  `,contentGuideline:(0,a.css)`
    top: 0;
    bottom: 0;
    left: -49px !important;
  `,headerGuideline:(0,a.css)`
    top: -17px;
    bottom: 0;
  `})},77085:(ee,x,t)=>{t.d(x,{j:()=>M});var a=t(66681),o=t(85960),e=t(47257);const M=({children:O})=>{const h=(0,e.wW)(f);return o.createElement("div",{className:h.container},O)},f=O=>({container:(0,a.css)`
      background-color: ${O.colors.background.secondary};
      color: ${O.colors.text.secondary};
      padding: ${O.spacing(4)};
      text-align: center;
    `})},19311:(ee,x,t)=>{t.d(x,{y:()=>c});var a=t(66681),o=t(85960),e=t(47257),M=t(13086),f=t(16901),O=t(2698),h=t(44211),S=t(46911),m=t(35855),T=t(18678),u=t(25661),g=t(30209),b=t(29165),L=t(41879),R=t(95162),Q=t(57297),H=t(76679),ne=t(77294),ue=t(87921),de=t(53914);const pe=({alert:E,alertManagerSourceName:W})=>{const U=(0,e.wW)(Ee),y=(0,H.HY)(W)?L.contextSrv.hasPermission(R.AccessControlAction.AlertingRuleRead):!0;return o.createElement(o.Fragment,null,o.createElement("div",{className:U.actionsRow},E.status.state===f.Z9.Suppressed&&o.createElement(de.q,{actions:[Q.oI.CreateSilence,Q.oI.UpdateSilence]},o.createElement(b.Qj,{href:`${(0,ne.eQ)("/alerting/silences",W)}&silenceIds=${E.status.silencedBy.join(",")}`,className:U.button,icon:"bell",size:"sm"},"Manage silences")),E.status.state===f.Z9.Active&&o.createElement(de.q,{actions:[Q.oI.CreateSilence]},o.createElement(b.Qj,{href:(0,ne.VN)(W,E.labels),className:U.button,icon:"bell-slash",size:"sm"},"Silence")),y&&E.generatorURL&&o.createElement(b.Qj,{className:U.button,href:E.generatorURL,icon:"chart-line",size:"sm"},"See source")),Object.entries(E.annotations).map(([P,re])=>o.createElement(ue.a,{key:P,annotationKey:P,value:re})),o.createElement("div",{className:U.receivers},"Receivers:"," ",E.receivers.map(({name:P})=>P).filter(P=>!!P).join(", ")))},Ee=E=>({button:(0,a.css)`
    & + & {
      margin-left: ${E.spacing(1)};
    }
  `,actionsRow:(0,a.css)`
    padding: ${E.spacing(2,0)} !important;
    border-bottom: 1px solid ${E.colors.border.medium};
  `,receivers:(0,a.css)`
    padding: ${E.spacing(1,0)};
  `}),se=({alerts:E,alertManagerSourceName:W})=>{const U=(0,e.wW)(Ce),A=(0,o.useMemo)(()=>[{id:"state",label:"State",renderCell:({data:P})=>o.createElement(o.Fragment,null,o.createElement(g.G,{state:P.status.state}),o.createElement("span",{className:U.duration},"for"," ",(0,T.vT)({start:new Date(P.startsAt),end:new Date(P.endsAt)}))),size:"220px"},{id:"labels",label:"Labels",renderCell:({data:{labels:P}})=>o.createElement(O.s,{labels:P,size:"sm"}),size:1}],[U]),y=(0,o.useMemo)(()=>E.map(P=>({id:P.fingerprint,data:P})),[E]);return o.createElement("div",{className:U.tableWrapper,"data-testid":"alert-group-table"},o.createElement(u.F,{cols:A,items:y,isExpandable:!0,renderExpandedContent:({data:P})=>o.createElement(pe,{alert:P,alertManagerSourceName:W})}))},Ce=E=>({tableWrapper:(0,a.css)`
    margin-top: ${E.spacing(3)};
    ${E.breakpoints.up("md")} {
      margin-left: ${E.spacing(4.5)};
    }
  `,duration:(0,a.css)`
    margin-left: ${E.spacing(1)};
    font-size: ${E.typography.bodySmall.fontSize};
  `});var K=t(44412);const c=({alertManagerSourceName:E,group:W})=>{const[U,A]=(0,o.useState)(!0),y=(0,e.wW)(w),P=W.receiver.name!=="NONE";return o.createElement("div",{className:y.wrapper},o.createElement("div",{className:y.header},o.createElement("div",{className:y.group,"data-testid":"alert-group"},o.createElement(h.U,{size:"sm",isCollapsed:U,onToggle:()=>A(!U),"data-testid":"alert-group-collapse-toggle"}),Object.keys(W.labels).length?o.createElement(M.K,{direction:"row",alignItems:"center"},o.createElement(O.s,{labels:W.labels,size:"sm"}),P&&o.createElement(S.g,{icon:"at"},"Delivered to ",o.createElement(m.c,null,W.receiver.name))):o.createElement("span",null,"No grouping")),o.createElement(K.Z,{group:W})),!U&&o.createElement(se,{alertManagerSourceName:E,alerts:W.alerts}))},w=E=>({wrapper:(0,a.css)({"& + &":{marginTop:E.spacing(2)}}),header:(0,a.css)({display:"flex",flexDirection:"row",flexWrap:"wrap",alignItems:"center",justifyContent:"space-between",padding:`${E.spacing(1)} ${E.spacing(1)} ${E.spacing(1)} 0`,backgroundColor:E.colors.background.secondary,width:"100%"}),group:(0,a.css)({display:"flex",flexDirection:"row",alignItems:"center"}),summary:(0,a.css)({}),[f.Z9.Active]:(0,a.css)({color:E.colors.error.main}),[f.Z9.Suppressed]:(0,a.css)({color:E.colors.primary.main}),[f.Z9.Unprocessed]:(0,a.css)({color:E.colors.secondary.main})})},77542:(ee,x,t)=>{t.d(x,{Nx:()=>S,kO:()=>h,ot:()=>O});var a=t(55104),o=t.n(a),e=t(85960),M=t(98724);const f=/^((([01][0-9])|(2[0-3])):[0-5][0-9])$|(^24:00$)/,O=m=>m?f.test(m):!0,h=(m,T)=>{if(!m&&!T)return!0;if(!m&&T||m&&!T)return!1;const u="HH:mm",g=o()().startOf("day").add(m,u),b=o()().startOf("day").add(T,u);return!!(m&&T&&g.isBefore(b)||m&&T&&b.isAfter(g))};function S(m){return m.time_intervals.map((u,g)=>{const{times:b,weekdays:L,days_of_month:R,months:Q,years:H,location:ne}=u,ue=(0,M.u6)(b,ne),de=(0,M.v7)(L),pe=(0,M.J8)(R),Ee=(0,M.m8)(Q),se=(0,M.qw)(H);return e.createElement(e.Fragment,{key:JSON.stringify(u)+g},`${ue} ${de}`,e.createElement("br",null),[pe,Ee,se].join(" | "),e.createElement("br",null))})}},7914:(ee,x,t)=>{t.d(x,{g:()=>m});var a=t(66681),o=t(56375),e=t.n(o),M=t(85960),f=t(47257),O=t(13086),h=t(97096),S=t(23595);const m=({matchers:g})=>{const b=(0,f.wW)(u),L=5,R=(0,o.take)(g,L),Q=(0,o.takeRight)(g,g.length-L),H=Q.length>0;return M.createElement("span",{"data-testid":"label-matchers"},M.createElement(O.K,{direction:"row",gap:1,alignItems:"center",wrap:"wrap"},R.map(ne=>M.createElement(T,{key:(0,o.uniqueId)(),matcher:ne})),H&&M.createElement(S.z,{arrow:!0,placement:"top",content:M.createElement(M.Fragment,null,Q.map(ne=>M.createElement(T,{key:(0,o.uniqueId)(),matcher:ne})))},M.createElement("span",null,M.createElement("div",{className:b.metadata},`and ${Q.length} more`)))))},T=({matcher:[g,b,L]})=>{const R=(0,f.wW)(u);return M.createElement("div",{className:R.matcher(g).wrapper},M.createElement(O.K,{direction:"row",gap:0,alignItems:"baseline"},g," ",b," ",L))},u=g=>({matcher:b=>{const{color:L,borderColor:R}=(0,h.Bx)(b);return{wrapper:(0,a.css)`
        color: #fff;
        background: ${L};
        padding: ${g.spacing(.33)} ${g.spacing(.66)};
        font-size: ${g.typography.bodySmall.fontSize};

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

    font-size: ${g.typography.bodySmall.fontSize};
    font-weight: ${g.typography.bodySmall.fontWeight};
  `})},18649:(ee,x,t)=>{t.d(x,{N:()=>u});var a=t(85960),o=t(24956),e=t(97666),M=t(23595),f=t(66681),O=t(47257),h=t(36860);function S(){const g=(0,O.wW)(T);return a.createElement("div",null,"Prometheus duration format consist of a number followed by a time unit.",a.createElement("br",null),"Different units can be combined for more granularity.",a.createElement("hr",null),a.createElement("div",{className:g.list},a.createElement("div",{className:g.header},a.createElement("div",null,"Symbol"),a.createElement("div",null,"Time unit"),a.createElement("div",null,"Example")),a.createElement(m,{unit:h.t.seconds,name:"seconds",example:"20s"}),a.createElement(m,{unit:h.t.minutes,name:"minutes",example:"10m"}),a.createElement(m,{unit:h.t.hours,name:"hours",example:"4h"}),a.createElement(m,{unit:h.t.days,name:"days",example:"3d"}),a.createElement(m,{unit:h.t.weeks,name:"weeks",example:"2w"}),a.createElement("div",{className:g.examples},a.createElement("div",null,"Multiple units combined"),a.createElement("code",null,"1m30s, 2h30m20s, 1w2d"))))}function m({unit:g,name:b,example:L}){const R=(0,O.wW)(T);return a.createElement(a.Fragment,null,a.createElement("div",{className:R.unit},g),a.createElement("div",null,b),a.createElement("code",null,L))}const T=g=>({unit:(0,f.css)`
    font-weight: ${g.typography.fontWeightBold};
  `,list:(0,f.css)`
    display: grid;
    grid-template-columns: max-content 1fr 2fr;
    gap: ${g.spacing(1,3)};
  `,header:(0,f.css)`
    display: contents;
    font-weight: ${g.typography.fontWeightBold};
  `,examples:(0,f.css)`
    display: contents;
    & > div {
      grid-column: 1 / span 2;
    }
  `}),u=a.forwardRef((g,b)=>a.createElement(o.I,{suffix:a.createElement(M.z,{content:a.createElement(S,null),disabled:!1},a.createElement(e.J,{name:"info-circle",size:"lg"})),...g,ref:b}));u.displayName="PromDurationInput"},6681:(ee,x,t)=>{t.d(x,{S:()=>o});var a=t(66681);const o=e=>({container:(0,a.css)`
      align-items: center;
      display: flex;
      flex-flow: row nowrap;

      & > * + * {
        margin-left: ${e.spacing(1)};
      }
    `,input:(0,a.css)`
      flex: 1;
    `,promDurationInput:(0,a.css)`
      max-width: ${e.spacing(32)};
    `,timingFormContainer:(0,a.css)`
      padding: ${e.spacing(1)};
    `,linkText:(0,a.css)`
      text-decoration: underline;
    `,collapse:(0,a.css)`
      border: none;
      background: none;
      color: ${e.colors.text.primary};
    `})},76532:(ee,x,t)=>{t.d(x,{j:()=>a});const a={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"}}},49131:(ee,x,t)=>{t.d(x,{M:()=>a});const a={group_wait:"30s",group_interval:"5m",repeat_interval:"4h"}},30209:(ee,x,t)=>{t.d(x,{G:()=>f});var a=t(85960),o=t(16901),e=t(65825);const M={[o.Z9.Active]:"bad",[o.Z9.Unprocessed]:"neutral",[o.Z9.Suppressed]:"info"},f=({state:O})=>a.createElement(e.i,{state:M[O]},O)},70335:(ee,x,t)=>{t.d(x,{W:()=>o});var a=t(81828);function o(e,M){const f=a.alertmanagerApi.endpoints.getAlertmanagerConfiguration.useQuery(e??"",{...M,skip:!e});return{...f,error:f.error}}},62208:(ee,x,t)=>{t.d(x,{s:()=>f});var a=t(85960),o=t(84954),e=t(98724),M=t(70335);function f(){const{selectedAlertmanager:O}=(0,o.ZA)(),{currentData:h}=(0,M.W)(O),S=h?.alertmanager_config;return(0,a.useMemo)(()=>S?.mute_time_intervals?.map(T=>({value:T.name,label:T.name,description:T.time_intervals.map(u=>(0,e.uK)(u)).join(", AND ")}))??[],[S])}},78025:(ee,x,t)=>{t.d(x,{N:()=>T});var a=t(5894),o=t(85960),e=t(45465),M=t(34456),f=t(34834);const O=()=>new f.q(new URL(t.p+t.u(3786),t.b));let h;function S(){let u;if(h===void 0)try{u=O(),h=a.Ud(u)}catch(b){b instanceof Error&&(0,e.H)(b)}return{disposeWorker:()=>{u&&h&&(h[a.Yy](),u.terminate(),h=void 0,u=void 0)}}}function m(u){if(!h)throw new Error("Route Matcher has not been initialized")}function T(){(0,o.useEffect)(()=>{const{disposeWorker:b}=S();return b},[]);const u=(0,o.useCallback)(async(b,L)=>{m(h);const R=performance.now(),Q=await h.getRouteGroupsMap(b,L),H=performance.now()-R;return(0,M.PN)(`Route Groups Matched in  ${H} ms`,{matchingTime:H.toString(),alertGroupsCount:L.length.toString(),topLevelRoutesCount:b.routes?.length.toString()??"0"}),Q},[]),g=(0,o.useCallback)(async(b,L)=>{m(h);const R=performance.now(),Q=await h.matchInstancesToRoute(b,L),H=performance.now()-R;return(0,M.PN)(`Instances Matched in  ${H} ms`,{matchingTime:H.toString(),instancesToMatchCount:L.length.toString(),topLevelRoutesCount:b.routes?.length.toString()??"0"}),Q},[]);return{getRouteGroupsMap:u,matchInstancesToRoute:g}}},71803:(ee,x,t)=>{t.d(x,{Oy:()=>se,T0:()=>ue,Yg:()=>ne,ZS:()=>H,bi:()=>Ee,br:()=>Q,dO:()=>L,eP:()=>K,eh:()=>de,fx:()=>g,mJ:()=>pe});var a=t(56375),o=t.n(a),e=t(16901),M=t(98724),f=t(76679),O=t(41460),h=t(5476),S=t(47689);const m=(c,w)=>Object.entries(c??{}).reduce((E,[W,U])=>[...E,{name:W,value:U,operator:w?e._M.regex:e._M.equal}],[]),T=c=>c.value,u=c=>(c??[]).map(T),g={name:"",value:"",operator:e._M.equal},b=["grafana_folder","alertname"],L=[{label:"grafana_folder",value:"grafana_folder"},{label:"alertname",value:"alertname"},{label:"Disable (...)",value:"..."}],R={id:"",overrideGrouping:!1,groupBy:b,object_matchers:[],routes:[],continue:!1,receiver:"",overrideTimings:!1,groupWaitValue:"",groupIntervalValue:"",repeatIntervalValue:"",muteTimeIntervals:[]};function Q(c){return{id:(0,a.uniqueId)("route-"),...c,routes:(c.routes??[]).map(Q)}}const H=c=>{if(!c)return R;const w="id"in c?c.id:(0,a.uniqueId)("route-");if(Object.keys(c).length===0)return{...R,id:w};const E=[];c.routes?.forEach(A=>{const y=H(A);E.push(y)});const W=c.object_matchers?.map(A=>({name:A[0],operator:A[1],value:A[2]}))??[],U=c.matchers?.map(A=>(0,M.cm)((0,O.tC)(A)))??[];return{id:w,object_matchers:[...U,...W,...m(c.match,!1),...m(c.match_re,!0)],continue:c.continue??!1,receiver:c.receiver??"",overrideGrouping:Array.isArray(c.group_by)&&c.group_by.length>0,groupBy:c.group_by??void 0,overrideTimings:[c.group_wait,c.group_interval,c.repeat_interval].some(Boolean),groupWaitValue:c.group_wait??"",groupIntervalValue:c.group_interval??"",repeatIntervalValue:c.repeat_interval??"",routes:E,muteTimeIntervals:c.mute_time_intervals??[]}},ne=(c,w,E)=>{const W=(0,h.Tx)(w.id??"",E),{overrideGrouping:U,groupBy:A,overrideTimings:y,groupWaitValue:P,groupIntervalValue:re,repeatIntervalValue:te,receiver:Me}=w,q=void 0,De=U?A:q,Oe=y&&P?P:q,Ae=y&&re?re:q,ze=y&&te?te:q,Ze=w.object_matchers?.filter(le=>le.name&&le.value&&le.operator).map(({name:le,operator:Ge,value:Se})=>[le,Ge,Se]),rt=w.routes?.map(le=>ne(c,le,E)),ve={...W??{},continue:w.continue,group_by:De,object_matchers:Ze,match:void 0,match_re:void 0,group_wait:Oe,group_interval:Ae,repeat_interval:ze,routes:rt,mute_time_intervals:w.muteTimeIntervals,receiver:Me};return c!==f.GC?(ve.matchers=w.object_matchers?.map(({name:le,operator:Ge,value:Se})=>`${le}${Ge}${Se}`),ve.object_matchers=void 0):(ve.object_matchers=(0,O.QO)(ve),ve.matchers=void 0),w.receiver&&(ve.receiver=w.receiver),ve},ue=c=>({label:c,value:c}),de=c=>(c??[]).map(ue),pe=c=>{if(c!==null)return c?T(c)??"":""},Ee=c=>c?u(c):[];function se(c){return!c||c.length===0?!0:(0,S.wd)(c)||"Invalid duration format. Must be {number}{time_unit}"}const Ce=c=>c.map(w=>{const[E,W,U]=w;return`${E}${W}${U}`}),K=(c,w="")=>{if(c.length===0)return!0;const E=se(c),W=se(w);if(E!==!0)return E;if(W!==!0)return W;const U=(0,S.Bg)(c),A=(0,S.Bg)(w);return A!==0&&U<A?"Repeat interval should be higher or equal to Group interval":!0}},5476:(ee,x,t)=>{t.d(x,{SF:()=>M,Tx:()=>h,_P:()=>O,wB:()=>f});var a=t(56375),o=t.n(a),e=t(71803);const M=(S,m,T)=>{if(!h(m.id??"",T))throw new Error(`No such route with ID '${m.id}'`);function g(b){let L=b;if(b.id===m.id){const R=(0,e.Yg)(S,m,T);L=(0,a.omit)({...b,...R},"id")}return(0,a.omit)({...L,routes:b.routes?.map(g)},"id")}return g(T)},f=(S,m)=>{if(S.id===m.id)throw new Error("You cant remove the root policy");function T(u){return(0,a.omit)({...u,routes:u.routes?.reduce((g=[],b)=>(b.id===S.id||g.push(T(b)),g),[])},"id")}return T(m)},O=(S,m,T,u)=>{const g=(0,e.Yg)(S,m,u);function b(R){return R.id===T.id?{...R,routes:R.routes?.concat(g)}:{...R,routes:R.routes?.map(b)}}function L(R){return(0,a.omit)({...R,routes:R.routes?.map(L)},"id")}return L(b(u))};function h(S,m){return m.id===S?m:m.routes?.find(T=>h(S,T))}}}]);

//# sourceMappingURL=AlertAmRoutes.74970a03fba86169006b.js.map