"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[8648],{9661:(Q,P,t)=>{t.d(P,{x:()=>d});var a=t(39953),r=t(57721),e=t(43686);function d(c){const p=(0,r.useDispatch)(),y=(0,a.useRef)(c);y.current=c,(0,a.useEffect)(()=>()=>{p((0,e.e)({cleanupAction:y.current}))},[p])}},57621:(Q,P,t)=>{t.d(P,{Z:()=>e});var a=t(39953);function r({children:d,shouldWrap:c,wrap:p},y){return c?a.cloneElement(p(d)):d}const e=(0,a.forwardRef)(r)},11337:(Q,P,t)=>{t.r(P),t.d(P,{default:()=>Wn,findRoutesMatchingFilters:()=>Bt});var a=t(41407),r=t(86832),e=t(39953),d=t(65489),c=t(27366),p=t(82803),y=t(22784),D=t(77804),m=t(90201),M=t(84766),A=t(33155),E=t(41393),h=t(67650),G=t(57721),S=t(9661),U=t(37546),Y=t(69533),_=t(762),ae=t(86860),N=t(4919),fe=t(32840),ie=t(18950),re=t(68497),Ue=t(28804),T=t(81456),s=t(18314),I=t(72401),V=t(79493),$=t(76716),W=t(47224);const X=({children:n})=>{const o=(0,p.wW)(Ee);return e.createElement("div",{className:o.container},n)},Ee=n=>({container:(0,a.css)`
      background-color: ${n.colors.background.secondary};
      color: ${n.colors.text.secondary};
      padding: ${n.spacing(4)};
      text-align: center;
    `}),be=({buttonIcon:n,buttonLabel:o,buttonSize:l="lg",buttonVariant:u="primary",onButtonClick:g,text:v,href:i,showButton:O=!0})=>{const f=(0,p.wW)(we),x={className:f.button,icon:n,size:l,variant:u};return e.createElement(X,null,e.createElement(e.Fragment,null,e.createElement("p",{className:f.text},v),O&&(i?e.createElement(N.Qj,{href:i,type:"button",...x},o):e.createElement(N.zx,{onClick:g,type:"button",...x},o))))},we=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 De=t(61324),Ke=t(67111),Me=t(61868);const qe=({alertManagerSourceName:n,muteTimingNames:o,hideActions:l})=>{const u=(0,p.wW)(et),g=(0,Ue.I0)(),{currentData:v}=(0,I.W)(n,{refetchOnFocus:!0,refetchOnReconnect:!0}),i=v?.alertmanager_config,[O,f]=(0,e.useState)(""),x=(0,e.useMemo)(()=>{const j=i?.mute_time_intervals??[],Z=i?.muteTimeProvenances??{};return j.filter(({name:C})=>o?o.includes(C):!0).map(C=>({id:C.name,data:{...C,provenance:Z[C.name]}}))},[i?.mute_time_intervals,i?.muteTimeProvenances,o]),b=At(n,l,f),[R,k]=(0,s.RA)(s.oI.CreateMuteTiming);return e.createElement("div",{className:u.container},e.createElement(c.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(Ke.L,null),!l&&x.length>0&&e.createElement(T.q,{actions:[s.oI.CreateMuteTiming]},e.createElement(N.Qj,{className:u.addMuteButton,icon:"plus",variant:"primary",href:(0,$.eQ)("alerting/routes/mute-timing/new",n)},"Add mute timing"))),x.length>0?e.createElement(W.t,{items:x,cols:b,pagination:{itemsPerPage:25}}):l?e.createElement(be,{text:"No mute timings configured",buttonLabel:"",showButton:!1}):e.createElement(be,{text:"You haven't created any mute timings yet",buttonLabel:"Add mute timing",buttonIcon:"plus",buttonSize:"lg",href:(0,$.eQ)("alerting/routes/mute-timing/new",n),showButton:k}),!l&&e.createElement(fe.s,{isOpen:!!O,title:"Delete mute timing",body:`Are you sure you would like to delete "${O}"`,confirmText:"Delete",onConfirm:()=>{g((0,V.r0)(n,O)),f("")},onDismiss:()=>f("")}))};function At(n,o=!1,l){const[[u,g],[v,i]]=(0,s.o2)([s.oI.UpdateMuteTiming,s.oI.DeleteMuteTiming]),O=!o&&(g||i);return(0,e.useMemo)(()=>{const f=[{id:"name",label:"Name",renderCell:function({data:b}){return e.createElement(e.Fragment,null,b.name," ",b.provenance&&e.createElement(De.C0,null))},size:"250px"},{id:"timeRange",label:"Time range",renderCell:({data:x})=>(0,Me.Nx)(x)}];return O&&f.push({id:"actions",label:"Actions",renderCell:function({data:b}){return b.provenance?e.createElement("div",null,e.createElement(ie.r,{href:(0,$.eQ)("/alerting/routes/mute-timing/edit",n,{muteName:b.name})},e.createElement(re.h,{name:"file-alt",tooltip:"View mute timing"}))):e.createElement("div",null,e.createElement(T.q,{actions:[s.oI.UpdateMuteTiming]},e.createElement(ie.r,{href:(0,$.eQ)("/alerting/routes/mute-timing/edit",n,{muteName:b.name})},e.createElement(re.h,{name:"edit",tooltip:"Edit mute timing"}))),e.createElement(T.q,{actions:[s.oI.DeleteMuteTiming]},e.createElement(re.h,{name:"trash-alt",tooltip:"Delete mute timing",onClick:()=>l(b.name)})))},size:"100px"}),f},[n,l,O])}const et=n=>({container:(0,a.css)`
    display: flex;
    flex-flow: column nowrap;
  `,addMuteButton:(0,a.css)`
    margin-bottom: ${n.spacing(2)};
    align-self: flex-end;
  `});var z=t(96227),tt=t(36495),he=t(69865),ve=t(12190),Pe=t(38637),ce=t(9558),ue=t(88617),q=t(14949);const Re=({receivers:n,onChangeReceiver:o,onChangeMatchers:l})=>{const[u,g]=(0,ue.j)(),v=(0,e.useRef)(null),{queryString:i,contactPoint:O}=$t(u),f=(0,p.wW)(Lt),x=(0,e.useCallback)(()=>(0,r.debounce)(l,500),[l]);(0,e.useEffect)(()=>{o(O)},[O,o]),(0,e.useEffect)(()=>{const C=(0,q.Zh)(i??"").map(q.xz);x()(C)},[x,i]);const b=(0,e.useCallback)(()=>{v.current&&(v.current.value=""),g({contactPoint:void 0,queryString:void 0})},[g]),R=n.map(Nt),k=R.find(C=>C.value===O)??null,j=i||O,Z=i&&i.length>3?(0,q.Zh)(i).length===0:!1;return e.createElement(c.K,{direction:"row",alignItems:"flex-start",gap:.5},e.createElement(z.g,{className:f.noBottom,label:e.createElement(tt._,null,e.createElement(c.K,{gap:.5},e.createElement("span",null,"Search by matchers"),e.createElement(he.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(ve.J,{name:"info-circle",size:"sm"})))),invalid:Z,error:Z?"Query must use valid matcher syntax":null},e.createElement(Pe.I,{ref:v,"data-testid":"search-query-input",placeholder:"Search",width:46,prefix:e.createElement(ve.J,{name:"search"}),onChange:C=>{g({queryString:C.currentTarget.value})},defaultValue:i})),e.createElement(z.g,{label:"Search by contact point",style:{marginBottom:0}},e.createElement(ce.Ph,{id:"receiver","aria-label":"Search by contact point",value:k,options:R,onChange:C=>{g({contactPoint:C?.value})},width:28,isClearable:!0})),j&&e.createElement(N.zx,{variant:"secondary",icon:"times",onClick:b,style:{marginTop:19}},"Clear filters"))};function Oe(n,o){const l=[];function u(g){o(g)&&l.push(g),g.routes?.forEach(u)}return u(n),l}const Nt=n=>({label:n.name,value:n.name}),$t=n=>({queryString:n.get("queryString")??void 0,contactPoint:n.get("contactPoint")??void 0}),Lt=()=>({noBottom:(0,a.css)`
    margin-bottom: 0;
  `});var se=t(73075),Ut=t(28409),Fe=t(47858),wt=t(25969),Kt=t(80039),Ft=t(17241),nt=t(11272),Vt=t(76197);const Ct=()=>{const{installed:n}=(0,Ft.n)(nt.W.OnCall),{data:o}=Kt.onCallApi.useGrafanaOnCallIntegrationsQuery(void 0,{skip:!n});return u=>{const g=o??[];if(n&&(0,Vt.Fs)(u,g))return nt.W.OnCall}},Mt=n=>{const o=Ct(),l=u=>({label:u.name,value:u.name,grafanaAppReceiverType:o(u)});return n.map(l)},Gn=n=>{const o=Ct();return n.map(l=>({...l,grafanaAppReceiverType:o(l)}))};var zt=t(71757),Ve=t.n(zt),Se=t(12608);const jt=({active:n=0,suppressed:o=0,unprocessed:l=0})=>{const u=[],g=n+o+l;return n&&u.push(e.createElement(Se.C,{color:"red",key:"firing",text:`${n} firing`})),o&&u.push(e.createElement(Se.C,{color:"blue",key:"suppressed",text:`${o} suppressed`})),l&&u.push(e.createElement(Se.C,{color:"orange",key:"unprocessed",text:`${l} unprocessed`})),u.length>1&&u.unshift(e.createElement(e.Fragment,{key:"total"},g," ",Ve()("instance",g))),!!u.length?e.createElement(c.K,{gap:.5},u):null};var Pt=t(85830),Te=t(9006),Zt=t(62818),K=t(93139),ze=t(44351),xe=t(54637);function Qt(){const n=(0,p.wW)(Ot);return e.createElement("div",null,"Prometheus duration format consist of a number followed by a time unit.",e.createElement("br",null),"Different units can be combined for more granularity.",e.createElement("hr",null),e.createElement("div",{className:n.list},e.createElement("div",{className:n.header},e.createElement("div",null,"Symbol"),e.createElement("div",null,"Time unit"),e.createElement("div",null,"Example")),e.createElement(We,{unit:xe.t.seconds,name:"seconds",example:"20s"}),e.createElement(We,{unit:xe.t.minutes,name:"minutes",example:"10m"}),e.createElement(We,{unit:xe.t.hours,name:"hours",example:"4h"}),e.createElement(We,{unit:xe.t.days,name:"days",example:"3d"}),e.createElement(We,{unit:xe.t.weeks,name:"weeks",example:"2w"}),e.createElement("div",{className:n.examples},e.createElement("div",null,"Multiple units combined"),e.createElement("code",null,"1m30s, 2h30m20s, 1w2d"))))}function We({unit:n,name:o,example:l}){const u=(0,p.wW)(Ot);return e.createElement(e.Fragment,null,e.createElement("div",{className:u.unit},n),e.createElement("div",null,o),e.createElement("code",null,l))}const Ot=n=>({unit:(0,a.css)`
    font-weight: ${n.typography.fontWeightBold};
  `,list:(0,a.css)`
    display: grid;
    grid-template-columns: max-content 1fr 2fr;
    gap: ${n.spacing(1,3)};
  `,header:(0,a.css)`
    display: contents;
    font-weight: ${n.typography.fontWeightBold};
  `,examples:(0,a.css)`
    display: contents;
    & > div {
      grid-column: 1 / span 2;
    }
  `}),ye=e.forwardRef((n,o)=>e.createElement(Pe.I,{suffix:e.createElement(ze.z,{content:e.createElement(Qt,null),disabled:!1},e.createElement(ve.J,{name:"info-circle",size:"lg"})),...n,ref:o}));ye.displayName="PromDurationInput";const Tt=n=>({container:(0,a.css)`
      align-items: center;
      display: flex;
      flex-flow: row nowrap;

      & > * + * {
        margin-left: ${n.spacing(1)};
      }
    `,input:(0,a.css)`
      flex: 1;
    `,promDurationInput:(0,a.css)`
      max-width: ${n.spacing(32)};
    `,timingFormContainer:(0,a.css)`
      padding: ${n.spacing(1)};
    `,linkText:(0,a.css)`
      text-decoration: underline;
    `,collapse:(0,a.css)`
      border: none;
      background: none;
      color: ${n.colors.text.primary};
    `}),je={group_wait:"30s",group_interval:"5m",repeat_interval:"4h"},Ht=({actionButtons:n,alertManagerSourceName:o,onSubmit:l,receivers:u,route:g})=>{const v=(0,p.wW)(Tt),[i,O]=(0,e.useState)(!1),[f,x]=(0,e.useState)((0,K.eh)(g.group_by)),b=(0,K.ZS)(g);return e.createElement(Pt.l,{defaultValues:{...b,overrideTimings:!0,overrideGrouping:!0},onSubmit:l},({register:R,control:k,errors:j,setValue:Z,getValues:C})=>e.createElement(e.Fragment,null,e.createElement(z.g,{label:"Default contact point",invalid:!!j.receiver,error:j.receiver?.message},e.createElement(e.Fragment,null,e.createElement("div",{className:v.container,"data-testid":"am-receiver-select"},e.createElement(Te.g,{render:({field:{onChange:B,ref:de,...H}})=>e.createElement(ce.Ph,{"aria-label":"Default contact point",...H,className:v.input,onChange:te=>B((0,K.mJ)(te)),options:u}),control:k,name:"receiver",rules:{required:{value:!0,message:"Required."}}}),e.createElement("span",null,"or"),e.createElement(ie.r,{className:v.linkText,href:(0,$.eQ)("/alerting/notifications/receivers/new",o)},"Create a contact point")))),e.createElement(z.g,{label:"Group by",description:"Group alerts when you receive a notification based on labels.","data-testid":"am-group-select"},e.createElement(Te.g,{render:({field:{onChange:B,ref:de,...H}})=>e.createElement(ce.NU,{"aria-label":"Group by",...H,allowCustomValue:!0,className:v.input,onCreateOption:te=>{x(w=>[...w,(0,K.T0)(te)]),Z("groupBy",[...H.value,te])},onChange:te=>B((0,K.bi)(te)),options:[...K.dO,...f]}),control:k,name:"groupBy"})),e.createElement(Zt.U,{collapsible:!0,className:v.collapse,isOpen:i,label:"Timing options",onToggle:O},e.createElement("div",{className:v.timingFormContainer},e.createElement(z.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:!!j.groupWaitValue,error:j.groupWaitValue?.message,"data-testid":"am-group-wait"},e.createElement(ye,{...R("groupWaitValue",{validate:K.Oy}),placeholder:je.group_wait,className:v.promDurationInput,"aria-label":"Group wait"})),e.createElement(z.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:!!j.groupIntervalValue,error:j.groupIntervalValue?.message,"data-testid":"am-group-interval"},e.createElement(ye,{...R("groupIntervalValue",{validate:K.Oy}),placeholder:je.group_interval,className:v.promDurationInput,"aria-label":"Group interval"})),e.createElement(z.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:!!j.repeatIntervalValue,error:j.repeatIntervalValue?.message,"data-testid":"am-repeat-interval"},e.createElement(ye,{...R("repeatIntervalValue",{validate:B=>{const de=C("groupIntervalValue");return(0,K.eP)(B,de)}}),placeholder:je.repeat_interval,className:v.promDurationInput,"aria-label":"Repeat interval"})))),e.createElement("div",{className:v.container},n)))};var Jt=t(58464),at=t(26286),Yt=t(43324),It=t(328);function Xt(){const{selectedAlertmanager:n}=(0,It.ZA)(),{currentData:o}=(0,I.W)(n),l=o?.alertmanager_config;return(0,e.useMemo)(()=>l?.mute_time_intervals?.map(g=>({value:g.name,label:g.name,description:g.time_intervals.map(v=>(0,q.uK)(v)).join(", AND ")}))??[],[l])}const bt=({actionButtons:n,receivers:o,route:l,onSubmit:u,defaults:g})=>{const v=(0,p.wW)(_t),i=(0,p.wW)(Tt),[O,f]=(0,e.useState)((0,K.eh)(l?.group_by)),x=Xt(),b=[{name:"",operator:Fe._M.equal,value:""}],R=o.sort(kt),k={...(0,K.ZS)(l),...g},j={...k,object_matchers:l?k.object_matchers:b};return e.createElement(Pt.l,{defaultValues:j,onSubmit:u,maxWidth:"none"},({control:Z,register:C,errors:B,setValue:de,watch:H,getValues:te})=>e.createElement(e.Fragment,null,e.createElement("input",{type:"hidden",...C("id")}),e.createElement(Jt.F,{name:"object_matchers",control:Z},({fields:w,append:ne,remove:ee})=>e.createElement(e.Fragment,null,e.createElement(c.K,{direction:"column",alignItems:"flex-start"},e.createElement("div",null,"Matching labels"),w.length===0&&e.createElement(Se.C,{color:"orange",className:v.noMatchersWarning,icon:"exclamation-triangle",text:"If no matchers are specified, this notification policy will handle all alert instances."}),w.length>0&&e.createElement("div",{className:v.matchersContainer},w.map((J,F)=>e.createElement(c.K,{direction:"row",key:J.id,alignItems:"center"},e.createElement(z.g,{label:"Label",invalid:!!B.object_matchers?.[F]?.name,error:B.object_matchers?.[F]?.name?.message},e.createElement(Pe.I,{...C(`object_matchers.${F}.name`,{required:"Field is required"}),defaultValue:J.name,placeholder:"label",autoFocus:!0})),e.createElement(z.g,{label:"Operator"},e.createElement(Te.g,{render:({field:{onChange:L,ref:Ge,...Ae}})=>e.createElement(ce.Ph,{...Ae,className:v.matchersOperator,onChange:ge=>L(ge?.value),options:q.tA,"aria-label":"Operator"}),defaultValue:J.operator,control:Z,name:`object_matchers.${F}.operator`,rules:{required:{value:!0,message:"Required."}}})),e.createElement(z.g,{label:"Value",invalid:!!B.object_matchers?.[F]?.value,error:B.object_matchers?.[F]?.value?.message},e.createElement(Pe.I,{...C(`object_matchers.${F}.value`,{required:"Field is required"}),defaultValue:J.value,placeholder:"value"})),e.createElement(re.h,{tooltip:"Remove matcher",name:"trash-alt",onClick:()=>ee(F)},"Remove")))),e.createElement(N.zx,{className:v.addMatcherBtn,icon:"plus",onClick:()=>ne(K.fx),variant:"secondary",type:"button"},"Add matcher")))),e.createElement(z.g,{label:"Contact point"},e.createElement(Te.g,{render:({field:{onChange:w,ref:ne,...ee}})=>e.createElement(ce.Ph,{"aria-label":"Contact point",...ee,className:i.input,onChange:J=>w((0,K.mJ)(J)),options:R,isClearable:!0}),control:Z,name:"receiver"})),e.createElement(z.g,{label:"Continue matching subsequent sibling nodes"},e.createElement(at.r,{id:"continue-toggle",...C("continue")})),e.createElement(z.g,{label:"Override grouping"},e.createElement(at.r,{id:"override-grouping-toggle",...C("overrideGrouping")})),H().overrideGrouping&&e.createElement(z.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(Te.g,{rules:{validate:w=>!w||w.length===0?"At least one group by option is required.":!0},render:({field:{onChange:w,ref:ne,...ee},fieldState:{error:J}})=>e.createElement(e.Fragment,null,e.createElement(ce.NU,{"aria-label":"Group by",...ee,invalid:!!J,allowCustomValue:!0,className:i.input,onCreateOption:F=>{f(L=>[...L,(0,K.T0)(F)]),de("groupBy",[...ee.value,F])},onChange:F=>w((0,K.bi)(F)),options:[...K.dO,...O]}),J&&e.createElement(Yt.S,null,J.message)),control:Z,name:"groupBy"})),e.createElement(z.g,{label:"Override general timings"},e.createElement(at.r,{id:"override-timings-toggle",...C("overrideTimings")})),H().overrideTimings&&e.createElement(e.Fragment,null,e.createElement(z.g,{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.",invalid:!!B.groupWaitValue,error:B.groupWaitValue?.message},e.createElement(ye,{...C("groupWaitValue",{validate:K.Oy}),"aria-label":"Group wait value",className:i.promDurationInput})),e.createElement(z.g,{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.",invalid:!!B.groupIntervalValue,error:B.groupIntervalValue?.message},e.createElement(ye,{...C("groupIntervalValue",{validate:K.Oy}),"aria-label":"Group interval value",className:i.promDurationInput})),e.createElement(z.g,{label:"Repeat interval",description:"The waiting time to resend an alert after they have successfully been sent.",invalid:!!B.repeatIntervalValue,error:B.repeatIntervalValue?.message},e.createElement(ye,{...C("repeatIntervalValue",{validate:w=>{const ne=te("groupIntervalValue");return(0,K.eP)(w,ne)}}),"aria-label":"Repeat interval value",className:i.promDurationInput}))),e.createElement(z.g,{label:"Mute timings","data-testid":"am-mute-timing-select",description:"Add mute timing to policy",invalid:!!B.muteTimeIntervals},e.createElement(Te.g,{render:({field:{onChange:w,ref:ne,...ee}})=>e.createElement(ce.NU,{"aria-label":"Mute timings",...ee,className:i.input,onChange:J=>w((0,K.bi)(J)),options:x}),control:Z,name:"muteTimeIntervals"})),n))};function kt(n){return n.grafanaAppReceiverType===nt.W.OnCall?-1:0}const _t=n=>{const o=n.spacing(3.5);return{addMatcherBtn:(0,a.css)`
      margin-bottom: ${o};
    `,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 Dt=t(96440);const qt=(n=[],o,l)=>{const[u,g]=(0,e.useState)(!1),[v,i]=(0,e.useState)(),O=Mt(n),f=(0,e.useCallback)(()=>{i(void 0),g(!1)},[]),x=(0,e.useCallback)(R=>{i(R),g(!0)},[]);return[(0,e.useMemo)(()=>l?e.createElement(rt,{isOpen:u}):e.createElement(se.u,{isOpen:u,onDismiss:f,closeOnBackdropClick:!0,closeOnEscape:!0,title:"Add notification policy"},e.createElement(bt,{receivers:O,defaults:{groupBy:v?.group_by},onSubmit:R=>v&&o(R,v),actionButtons:e.createElement(se.u.ButtonRow,null,e.createElement(N.zx,{type:"button",variant:"secondary",onClick:f,fill:"outline"},"Cancel"),e.createElement(N.zx,{type:"submit"},"Save policy"))})),[O,o,f,l,v,u]),x,f]},en=(n,o,l,u)=>{const[g,v]=(0,e.useState)(!1),[i,O]=(0,e.useState)(!1),[f,x]=(0,e.useState)(),b=Mt(o),R=(0,e.useCallback)(()=>{x(void 0),v(!1)},[]),k=(0,e.useCallback)((Z,C)=>{O(C??!1),x(Z),v(!0)},[]);return[(0,e.useMemo)(()=>u?e.createElement(rt,{isOpen:g}):e.createElement(se.u,{isOpen:g,onDismiss:R,closeOnBackdropClick:!0,closeOnEscape:!0,title:"Edit notification policy"},i&&f&&e.createElement(Ht,{alertManagerSourceName:n,onSubmit:l,receivers:b,route:f,actionButtons:e.createElement(se.u.ButtonRow,null,e.createElement(N.zx,{type:"button",variant:"secondary",onClick:R,fill:"outline"},"Cancel"),e.createElement(N.zx,{type:"submit"},"Update default policy"))}),!i&&e.createElement(bt,{receivers:b,route:f,onSubmit:l,actionButtons:e.createElement(se.u.ButtonRow,null,e.createElement(N.zx,{type:"button",variant:"secondary",onClick:R,fill:"outline"},"Cancel"),e.createElement(N.zx,{type:"submit"},"Update policy"))})),[b,n,R,l,i,u,f,g]),k,R]},tn=(n,o)=>{const[l,u]=(0,e.useState)(!1),[g,v]=(0,e.useState)(),i=(0,e.useCallback)(()=>{v(void 0),u(!1)},[v]),O=(0,e.useCallback)(b=>{v(b),u(!0)},[]),f=(0,e.useCallback)(()=>{g&&n(g)},[n,g]);return[(0,e.useMemo)(()=>o?e.createElement(rt,{isOpen:l}):e.createElement(se.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(se.u.ButtonRow,null,e.createElement(N.zx,{type:"button",variant:"destructive",onClick:f},"Yes, delete policy"),e.createElement(N.zx,{type:"button",variant:"secondary",onClick:i},"Cancel"))),[i,f,o,l]),O,i]},nn=()=>{const[n,o]=(0,e.useState)(!1),[l,u]=(0,e.useState)([]),[g,v]=(0,e.useState)([]),i=(0,e.useCallback)(()=>{o(!1),u([]),v([])},[]),O=(0,e.useCallback)((b,R)=>{u(b),R&&v(R),o(!0)},[]),f=(0,e.useMemo)(()=>{const b=l.flatMap(R=>R.alerts);return(0,r.groupBy)(b,R=>R.status.state)},[l]);return[(0,e.useMemo)(()=>e.createElement(se.u,{isOpen:n,onDismiss:i,closeOnBackdropClick:!0,closeOnEscape:!0,title:e.createElement(c.K,{direction:"row",alignItems:"center",gap:1,flexGrow:1},e.createElement(c.K,{direction:"row",alignItems:"center",gap:.5},e.createElement(ve.J,{name:"x"})," Matchers"),e.createElement(Dt.g,{matchers:g}))},e.createElement(c.K,{direction:"column"},e.createElement(jt,{active:f[Fe.Z9.Active]?.length,suppressed:f[Fe.Z9.Suppressed]?.length,unprocessed:f[Fe.Z9.Unprocessed]?.length}),e.createElement("div",null,l.map((b,R)=>e.createElement(wt.y,{key:R,alertManagerSourceName:"",group:b})))),e.createElement(se.u.ButtonRow,null,e.createElement(N.zx,{type:"button",variant:"secondary",onClick:i},"Cancel"))),[l,i,f,g,n]),O,i]},rt=({isOpen:n})=>e.createElement(se.u,{isOpen:n,onDismiss:()=>{},closeOnBackdropClick:!1,closeOnEscape:!1,title:e.createElement(c.K,{direction:"row",alignItems:"center",gap:.5},"Updating... ",e.createElement(Ut.$,{inline:!0}))},"Please wait while we update your notification policies.");var Ze=t(17716),an=t(948),Be=t(13767),rn=t(58047),Rt=t(98632),on=t(72899),ot=t(57621),ln=t(25793),St=t(75404),xt=t(62393),lt=t(15429),me=t(18677),oe=t(64258),sn=t(26516),cn=t(91753),un=t(42527),mn=t(15898);const dn=({exportFormat:n,onClose:o})=>{const{currentData:l="",isFetching:u}=sn.alertRuleApi.useExportPoliciesQuery({format:n}),g=`policies-${new Date().getTime()}`;return u?e.createElement(M.u,{text:"Loading...."}):e.createElement(cn.u,{format:n,textDefinition:l,downloadFileName:g,onClose:o})},gn=({onClose:n})=>{const[o,l]=(0,e.useState)("yaml");return e.createElement(un.i,{activeTab:o,onTabChange:l,onClose:n,formatProviders:Object.values(mn.uN)},e.createElement(dn,{exportFormat:o,onClose:n}))},Wt=({receivers:n=[],contactPointsState:o,readOnly:l=!1,provisioned:u=!1,alertGroups:g=[],alertManagerSourceName:v,currentRoute:i,routeTree:O,inheritedProperties:f,routesMatchingFilters:x=[],matchingInstancesPreview:b={enabled:!1},onEditPolicy:R,onAddPolicy:k,onDeletePolicy:j,onShowAlertInstances:Z})=>{const C=(0,p.wW)(Qe),B=i===O,[[de,H],[te,w],[ne,ee]]=(0,s.o2)([s.oI.UpdateNotificationPolicyTree,s.oI.DeleteNotificationPolicy,s.oI.ExportNotificationPolicies]),J=i.receiver,F=i.continue??!1,L=i.group_by,Ge=i.mute_time_intervals??[],Ae={group_wait:i.group_wait,group_interval:i.group_interval,repeat_interval:i.repeat_interval},ge=(0,St.QO)(i),He=!!(ge&&ge.length),ct=!!Ge.length,ut=x.some(le=>le.id===i.id),Ne=[],mt=!He&&!B&&!F,$e=J??f?.receiver??"";(o?Mn($e,o):[]).forEach(le=>{Ne.push(le)});const Je=f&&Object.keys(f).length>0,dt=i.routes??[],gt=Je&&f.group_by,Ye=(0,r.isArray)(L)&&L[0]==="...",pt=!Ye&&(0,r.isArray)(L)&&L.length>0,Et=B&&(0,r.isArray)(L)&&L.length===0,Ie=b?.groupsMap?.get(i.id),Xe=Ie?(0,r.sumBy)(Ie,le=>le.alerts.length):void 0,[vt,ke]=(0,an.Z)(!1),ft=ee&&ne&&B,ht=de&&H,yt=te&&w&&!B,Ce=[];return ht&&Ce.push(e.createElement(e.Fragment,{key:"edit-policy"},e.createElement(ot.Z,{shouldWrap:u,wrap:st},e.createElement(Be.v.Item,{icon:"edit",disabled:u,label:"Edit",onClick:()=>R(i,B)})))),ft&&Ce.push(e.createElement(Be.v.Item,{key:"export-policy",icon:"download-alt",label:"Export",onClick:ke})),yt&&Ce.push(e.createElement(e.Fragment,{key:"delete-policy"},e.createElement(Be.v.Divider,null),e.createElement(ot.Z,{shouldWrap:u,wrap:st},e.createElement(Be.v.Item,{destructive:!0,icon:"trash-alt",disabled:u,label:"Delete",onClick:()=>j(i)})))),e.createElement(c.K,{direction:"column",gap:1.5},e.createElement("div",{className:C.policyWrapper(ut),"data-testid":B?"am-root-route-container":"am-route-container"},F&&e.createElement(En,null),mt&&e.createElement(vn,null),e.createElement("div",{className:C.policyItemWrapper},e.createElement(c.K,{direction:"column",gap:1},e.createElement("div",null,e.createElement(c.K,{direction:"row",alignItems:"center",gap:1},B?e.createElement(fn,null):He?e.createElement(Dt.g,{matchers:ge??[]}):e.createElement("span",{className:C.metadata},"No matchers"),e.createElement(Ke.L,null),Ne.length>0&&e.createElement(pn,{errors:Ne}),u&&e.createElement(De.C0,null),!l&&e.createElement(c.K,{direction:"row",gap:.5},e.createElement(T.q,{actions:[s.oI.CreateNotificationPolicy]},e.createElement(ot.Z,{shouldWrap:u,wrap:st},e.createElement(N.zx,{variant:"secondary",icon:"plus",size:"sm",onClick:()=>k(i),disabled:u,type:"button"},"New nested policy"))),Ce.length>0&&e.createElement(rn.L,{overlay:e.createElement(Be.v,null,Ce)},e.createElement(N.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(c.K,{direction:"row",alignItems:"center",gap:1},b.enabled&&e.createElement(me.g,{icon:"layers-alt",onClick:()=>{Ie&&Z(Ie,ge)},"data-testid":"matching-instances"},e.createElement(oe.c,null,Xe??"-"),e.createElement("span",null,Ve()("instance",Xe))),J&&e.createElement(me.g,{icon:"at","data-testid":"contact-point"},e.createElement("span",null,"Delivered to"),e.createElement(Cn,{alertManagerSourceName:v,receivers:n,contactPoint:J})),!gt&&e.createElement(e.Fragment,null,pt&&e.createElement(me.g,{icon:"layer-group","data-testid":"grouping"},e.createElement("span",null,"Grouped by"),e.createElement(oe.c,null,L.join(", "))),Et&&e.createElement(me.g,{icon:"layer-group"},e.createElement("span",null,"Single group")),Ye&&e.createElement(me.g,{icon:"layer-group"},e.createElement("span",null,"Not grouping"))),ct&&e.createElement(me.g,{icon:"calendar-slash","data-testid":"mute-timings"},e.createElement("span",null,"Muted when"),e.createElement(yn,{timings:Ge,alertManagerSourceName:v})),Ae&&e.createElement(An,{timingOptions:B?(0,r.defaults)(Ae,je):Ae}),Je&&e.createElement(e.Fragment,null,e.createElement(me.g,{icon:"corner-down-right-alt","data-testid":"inherited-properties"},e.createElement("span",null,"Inherited"),e.createElement(hn,{properties:f})))))))),e.createElement("div",{className:C.childPolicies},dt.map(le=>{const _e=(0,xt.$2)(i,le,f);return e.createElement(Wt,{key:(0,r.uniqueId)(),routeTree:O,currentRoute:le,receivers:n,contactPointsState:o,readOnly:l||u,inheritedProperties:_e,onAddPolicy:k,onEditPolicy:R,onDeletePolicy:j,onShowAlertInstances:Z,alertManagerSourceName:v,alertGroups:g,routesMatchingFilters:x,matchingInstancesPreview:b})})),vt&&e.createElement(gn,{onClose:ke}))},st=n=>e.createElement(he.u,{content:"Provisioned items cannot be edited in the UI",placement:"top"},e.createElement("span",null,n)),pn=({errors:n})=>e.createElement(ze.z,{arrow:!0,placement:"top",content:e.createElement(c.K,{direction:"column",gap:.5},n.map(o=>e.createElement(e.Fragment,{key:(0,r.uniqueId)()},o)))},e.createElement("span",null,e.createElement(Se.C,{icon:"exclamation-circle",color:"red",text:Ve()("error",n.length,!0)}))),En=()=>{const n=(0,p.wW)(Qe);return e.createElement(he.u,{placement:"top",content:"This route will continue matching other policies"},e.createElement("div",{className:n.gutterIcon,"data-testid":"continue-matching"},e.createElement(ve.J,{name:"arrow-down"})))},vn=()=>{const n=(0,p.wW)(Qe);return e.createElement(he.u,{placement:"top",content:"This policy matches all labels"},e.createElement("div",{className:n.gutterIcon,"data-testid":"matches-all"},e.createElement(ve.J,{name:"exclamation-triangle"})))},fn=()=>{const n=(0,p.wW)(Qe);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."))},hn=({properties:n})=>e.createElement(ze.z,{arrow:!0,placement:"top",content:e.createElement(c.K,{direction:"row",gap:.5},Object.entries(n).map(([o,l])=>e.createElement(lt._,{key:o,label:Pn(o),value:e.createElement(oe.c,null,On(o,l))})))},e.createElement("div",null,e.createElement(oe.c,null,Ve()("property",Object.keys(n).length,!0)))),yn=({timings:n,alertManagerSourceName:o})=>e.createElement("div",null,e.createElement(oe.c,null,n.map(l=>e.createElement(Ze.Link,{key:l,to:(0,$.ET)(l,o)},l)))),An=({timingOptions:n})=>{const o=n.group_wait,l=n.group_interval;return!o&&!l?null:e.createElement(me.g,{icon:"hourglass","data-testid":"timing-options"},e.createElement("span",null,"Wait"),o&&e.createElement(he.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(oe.c,null,o)," ",e.createElement("span",null,"to group instances"),o&&l&&",")),l&&e.createElement(he.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(oe.c,null,l)," ",e.createElement("span",null,"before sending updates"))))},Cn=({alertManagerSourceName:n,contactPoint:o,receivers:l})=>{const u=l.find(i=>i.name===o);if(!u)return e.createElement(Ze.Link,{to:(0,$.GV)(o,n)},e.createElement(oe.c,null,o));if(!u.grafana_managed_receiver_configs)return e.createElement(Ze.Link,{to:(0,$.GV)(o,n)},e.createElement(oe.c,null,o));const v=(0,r.groupBy)(u.grafana_managed_receiver_configs,i=>i.type);return e.createElement(ze.z,{arrow:!0,placement:"top",header:e.createElement(me.g,{icon:"at"},e.createElement("div",null,"Contact Point"),e.createElement(oe.c,null,o)),key:(0,r.uniqueId)(),content:e.createElement(c.K,{direction:"row",gap:.5},Object.entries(v).map(([i,O])=>e.createElement(lt._,{key:(0,r.uniqueId)(),label:O.length>1?O.length:void 0,icon:ln.y[i],value:(0,r.upperFirst)(i)})))},e.createElement(Ze.Link,{to:(0,$.GV)(o,n)},e.createElement(oe.c,null,o)))};function Mn(n,o){return Object.entries(o[n]?.notifiers??[]).reduce((g=[],[v,i])=>{const O=i.filter(f=>f.lastNotifyAttemptError).map(f=>e.createElement(lt._,{icon:"at",key:(0,r.uniqueId)(),label:`Contact Point \u203A ${f.name}`,value:f.lastNotifyAttemptError}));return g.concat(O)},[])}const Pn=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"mute_time_intervals":return"Mute timings";case"repeat_interval":return"Repeat interval";default:return n}},On=(n,o)=>{const l=n==="group_by"&&Array.isArray(o)&&o[0]==="...",u=n==="group_by"&&Array.isArray(o)&&o.length===0;return l?e.createElement(Rt.x,{variant:"bodySmall",color:"secondary"},"Not grouping"):u?e.createElement(Rt.x,{variant:"bodySmall",color:"secondary"},"Single group"):Array.isArray(o)?o.join(", "):o},Qe=n=>({matcher:o=>{const{color:l,borderColor:u}=(0,on.Bx)(o);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 ${u};
        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:(o=!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};

    ${o&&(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 Tn=t(47853),In=t(57675),it=t(75964),bn=(n=>(n.NotificationPolicies="notification_policies",n.MuteTimings="mute_timings",n))(bn||{});const Dn=()=>{const n=(0,G.useDispatch)(),o=(0,p.wW)(Rn),{useGetAlertmanagerAlertGroupsQuery:l}=U.alertmanagerApi,[u,g]=(0,h.K)(),{tab:v}=Sn(u),[i,O]=(0,e.useState)(v),[f,x]=(0,e.useState)(!1),[b,R]=(0,e.useState)(),[k,j]=(0,e.useState)([]),{getRouteGroupsMap:Z}=(0,Tn.N)(),{selectedAlertmanager:C,hasConfigurationAPI:B}=(0,It.ZA)(),de=(0,Y.V)(C??""),{currentData:H,isLoading:te,error:w}=(0,I.W)(C,{refetchOnFocus:!0,refetchOnReconnect:!0}),ne=H?.alertmanager_config,{currentData:ee,refetch:J}=l({amSourceName:C??""},{skip:!C}),F=ne?.receivers??[],L=(0,e.useMemo)(()=>{if(ne?.route)return(0,K.br)(ne.route)},[ne?.route]),[{value:Ge,error:Ae},ge]=(0,d.Z)(Z,[Z]);(0,e.useEffect)(()=>{L&&ee&&ge(L,ee)},[L,ee,ge]);const He=(0,e.useMemo)(()=>L?Bt(L,{contactPointFilter:b,labelMatchersFilter:k}):[],[b,k,L]),ct=!!ne?.route?.provenance;function ut(pe){if(!L)return;const Le=(0,it.SF)(C??"",pe,L);$e(Le)}function Ne(pe){if(!L)return;const Le=(0,it.wB)(pe,L);$e(Le)}function mt(pe,Le){if(!L)return;const Bn=(0,it._P)(C??"",pe,Le,L);$e(Bn)}function $e(pe){H&&(x(!0),n((0,V.mM)({newConfig:{...H,alertmanager_config:{...H.alertmanager_config,route:pe}},oldConfig:H,alertManagerSourceName:C,successMessage:"Updated notification policies"})).unwrap().then(()=>{C&&J(),pt(),dt(),Xe()}).finally(()=>{x(!1)}))}const[Gt,Je,dt]=qt(F,mt,f),[gt,Ye,pt]=en(C??"",F,ut,f),[Et,Ie,Xe]=tn(Ne,f),[vt,ke]=nn();if((0,S.x)(pe=>pe.unifiedAlerting.saveAMConfig=In.oq),!C)return null;const ft=H?.alertmanager_config.mute_time_intervals?.length??0,ht=H&&!w&&!te,yt=!H&&te,Ce=w&&!te,le=i==="mute_timings",_e=i==="notification_policies";return e.createElement(e.Fragment,null,e.createElement(y.J,null,e.createElement(D.O,{label:"Notification Policies",active:_e,onChangeTab:()=>{O("notification_policies"),g({tab:"notification_policies"})}}),e.createElement(D.O,{label:"Mute Timings",active:le,counter:ft,onChangeTab:()=>{O("mute_timings"),g({tab:"mute_timings"})}})),e.createElement(m.I,{className:o.tabContent},yt&&e.createElement(M.u,{text:"Loading Alertmanager config..."}),Ce&&e.createElement(A.b,{severity:"error",title:"Error loading Alertmanager config"},w.message||"Unknown error."),ht&&e.createElement(e.Fragment,null,_e&&e.createElement(e.Fragment,null,e.createElement(ae.u,{currentAlertmanager:C}),e.createElement(c.K,{direction:"column",gap:1},L&&e.createElement(Re,{receivers:F,onChangeMatchers:j,onChangeReceiver:R}),L&&e.createElement(Wt,{receivers:F,routeTree:L,currentRoute:L,alertGroups:ee??[],contactPointsState:de.receivers,readOnly:!B,provisioned:ct,alertManagerSourceName:C,onAddPolicy:Je,onEditPolicy:Ye,onDeletePolicy:Ie,onShowAlertInstances:ke,routesMatchingFilters:He,matchingInstancesPreview:{groupsMap:Ge,enabled:!Ae}})),Gt,gt,Et,vt),le&&e.createElement(qe,{alertManagerSourceName:C,hideActions:!B}))))},Bt=(n,o)=>{const{contactPointFilter:l,labelMatchersFilter:u=[]}=o;let g=[];const v=(0,xt.tK)(n),i=l?Oe(v,f=>f.receiver===l):void 0;i&&g.push(i);const O=u.length?Oe(v,f=>{const x=(0,St.QO)(f);return u.every(b=>x.some(R=>(0,r.isEqual)(b,R)))}):void 0;return O&&g.push(O),(0,r.intersectionBy)(...g,"id")},Rn=n=>({tabContent:(0,a.css)`
    margin-top: ${n.spacing(2)};
  `});function Sn(n){let o="notification_policies";return n.tab==="notification_policies"&&(o="notification_policies"),n.tab==="mute_timings"&&(o="mute_timings"),{tab:o}}const xn=()=>e.createElement(_.O,{pageId:"am-routes",accessType:"notification"},e.createElement(Dn,null)),Wn=(0,E.Pf)(xn,{style:"page"})},80039:(Q,P,t)=>{t.d(P,{NC:()=>M,ZV:()=>c,onCallApi:()=>y});var a=t(4148),r=t(76197),e=t(11272),d=t(20584);const c="grafana_alerting_v2",p=A=>`/api/plugin-proxy/${e.W.OnCall}${A}`,y=d.C.injectEndpoints({endpoints:A=>({grafanaOnCallIntegrations:A.query({query:()=>({url:p("/api/internal/v1/alert_receive_channels/"),params:{filters:!0,integration:[r.As,"legacy_grafana_alerting"]}}),transformResponse:E=>D(E)?E.results:E,providesTags:["OnCallIntegrations"]}),validateIntegrationName:A.query({query:E=>({url:p("/api/internal/v1/alert_receive_channels/validate_name/"),params:{verbal_name:E},showErrorAlert:!1})}),createIntegration:A.mutation({query:E=>({url:p("/api/internal/v1/alert_receive_channels/"),data:E,method:"POST",showErrorAlert:!0}),invalidatesTags:["OnCallIntegrations"]}),features:A.query({query:()=>({url:p("/api/internal/v1/features/")})})})});function D(A){return"results"in A&&Array.isArray(A.results)}const{useGrafanaOnCallIntegrationsQuery:m}=y;function M(A){return(0,a.kW)(A)&&"detail"in A.data}},81036:(Q,P,t)=>{t.d(P,{F:()=>c});var a=t(41407),r=t(39953),e=t(82803),d=t(47224);const c=({renderExpandedContent:y,...D})=>{const m=(0,e.wW)(p);return r.createElement(d.t,{renderExpandedContent:y?(M,A,E)=>r.createElement(r.Fragment,null,A!==E.length-1&&r.createElement("div",{className:(0,a.cx)(m.contentGuideline,m.guideline)}),y(M,A,E)):void 0,renderPrefixHeader:()=>r.createElement("div",{className:m.relative},r.createElement("div",{className:(0,a.cx)(m.headerGuideline,m.guideline)})),renderPrefixCell:(M,A,E)=>r.createElement("div",{className:m.relative},r.createElement("div",{className:(0,a.cx)(m.topGuideline,m.guideline)}),A!==E.length-1&&r.createElement("div",{className:(0,a.cx)(m.bottomGuideline,m.guideline)})),...D})},p=y=>({relative:(0,a.css)`
    position: relative;
    height: 100%;
  `,guideline:(0,a.css)`
    left: -19px;
    border-left: 1px solid ${y.colors.border.weak};
    position: absolute;

    ${y.breakpoints.down("md")} {
      display: none;
    }
  `,topGuideline:(0,a.css)`
    width: 18px;
    border-bottom: 1px solid ${y.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;
  `})},86860:(Q,P,t)=>{t.d(P,{u:()=>D});var a=t(41407),r=t(39953),e=t(82803),d=t(33155),c=t(47858),p=t(37546),y=t(95712);function D({currentAlertmanager:M}){const A=(0,e.wW)(m),{useGetAlertmanagerChoiceStatusQuery:E}=p.alertmanagerApi,{currentData:h}=E(),G=M===y.GC;if(!(h?.alertmanagersChoice&&[c.TE.External,c.TE.All].includes(h?.alertmanagersChoice))||!G)return null;const U=h.numExternalAlertmanagers>0;return h.alertmanagersChoice===c.TE.External?r.createElement(d.b,{title:"Grafana alerts are not delivered to Grafana Alertmanager"},"Grafana is configured to send alerts to external Alertmanagers only. Changing Grafana Alertmanager configuration will not affect delivery of your alerts.",r.createElement("div",{className:A.adminHint},"To change your Alertmanager setup, go to the Alerting Admin page. If you do not have access, contact your Administrator.")):h.alertmanagersChoice===c.TE.All&&U?r.createElement(d.b,{title:"You have additional Alertmanagers to configure",severity:"warning"},"Ensure you make configuration changes in the correct Alertmanagers; both internal and external. Changing one will not affect the others.",r.createElement("div",{className:A.adminHint},"To change your Alertmanager setup, go to the Alerting Admin page. If you do not have access, contact your Administrator.")):null}const m=M=>({adminHint:(0,a.css)`
    font-size: ${M.typography.bodySmall.fontSize};
    font-weight: ${M.typography.bodySmall.fontWeight};
  `})},18677:(Q,P,t)=>{t.d(P,{g:()=>y});var a=t(41407),r=t(39953),e=t(27366),d=t(82803),c=t(98632),p=t(12190);const y=({children:m,icon:M,color:A="secondary",...E})=>{const h=(0,d.wW)(D),G=typeof E.onClick=="function";return r.createElement("div",{className:(0,a.cx)({[h.interactive]:G}),...E},r.createElement(c.x,{variant:"bodySmall",color:A},r.createElement(e.K,{direction:"row",alignItems:"center",gap:.5},M&&r.createElement(p.J,{size:"sm",name:M}),m)))},D=()=>({interactive:(0,a.css)`
    cursor: pointer;
  `})},61324:(Q,P,t)=>{t.d(P,{C0:()=>p,Uv:()=>d,Xq:()=>c});var a=t(39953),r=t(33155),e=t(12608),d=(y=>(y.ContactPoint="contact point",y.Template="template",y.MuteTiming="mute timing",y.AlertRule="alert rule",y.RootNotificationPolicy="root notification policy",y))(d||{});const c=({resource:y})=>a.createElement(r.b,{title:`This ${y} cannot be edited through the UI`,severity:"info"},"This ",y," has been provisioned, that means it was created by config. Please contact your server admin to update this ",y,"."),p=()=>a.createElement(e.C,{text:"Provisioned",color:"purple"})},64258:(Q,P,t)=>{t.d(P,{c:()=>e});var a=t(39953),r=t(82803);const e=({children:d})=>{const c=(0,r.l4)();return a.createElement("strong",{style:{color:c.colors.text.primary}},d)}},25969:(Q,P,t)=>{t.d(P,{y:()=>re});var a=t(41407),r=t(39953),e=t(82803),d=t(47858),c=t(4353),p=t(98934),y=t(5195),D=t(81036),m=t(84070),M=t(4919),A=t(97125),E=t(57721),h=t(18314),G=t(95712),S=t(76716),U=t(75825),Y=t(81456);const _=({alert:T,alertManagerSourceName:s})=>{const I=(0,e.wW)(ae),$=(0,G.HY)(s)?A.contextSrv.hasPermission(E.AccessControlAction.AlertingRuleRead):!0;return r.createElement(r.Fragment,null,r.createElement("div",{className:I.actionsRow},T.status.state===d.Z9.Suppressed&&r.createElement(Y.q,{actions:[h.oI.CreateSilence,h.oI.UpdateSilence]},r.createElement(M.Qj,{href:`${(0,S.eQ)("/alerting/silences",s)}&silenceIds=${T.status.silencedBy.join(",")}`,className:I.button,icon:"bell",size:"sm"},"Manage silences")),T.status.state===d.Z9.Active&&r.createElement(Y.q,{actions:[h.oI.CreateSilence]},r.createElement(M.Qj,{href:(0,S.VN)(s,T.labels),className:I.button,icon:"bell-slash",size:"sm"},"Silence")),$&&T.generatorURL&&r.createElement(M.Qj,{className:I.button,href:T.generatorURL,icon:"chart-line",size:"sm"},"See source")),Object.entries(T.annotations).map(([W,X])=>r.createElement(U.a,{key:W,annotationKey:W,value:X})),r.createElement("div",{className:I.receivers},"Receivers:"," ",T.receivers.map(({name:W})=>W).filter(W=>!!W).join(", ")))},ae=T=>({button:(0,a.css)`
    & + & {
      margin-left: ${T.spacing(1)};
    }
  `,actionsRow:(0,a.css)`
    padding: ${T.spacing(2,0)} !important;
    border-bottom: 1px solid ${T.colors.border.medium};
  `,receivers:(0,a.css)`
    padding: ${T.spacing(1,0)};
  `}),N=({alerts:T,alertManagerSourceName:s})=>{const I=(0,e.wW)(fe),V=(0,r.useMemo)(()=>[{id:"state",label:"State",renderCell:({data:W})=>r.createElement(r.Fragment,null,r.createElement(m.G,{state:W.status.state}),r.createElement("span",{className:I.duration},"for"," ",(0,y.vT)({start:new Date(W.startsAt),end:new Date(W.endsAt)}))),size:"220px"},{id:"labels",label:"Labels",renderCell:({data:{labels:W}})=>r.createElement(c.s,{labels:W,size:"sm"}),size:1}],[I]),$=(0,r.useMemo)(()=>T.map(W=>({id:W.fingerprint,data:W})),[T]);return r.createElement("div",{className:I.tableWrapper,"data-testid":"alert-group-table"},r.createElement(D.F,{cols:V,items:$,isExpandable:!0,renderExpandedContent:({data:W})=>r.createElement(_,{alert:W,alertManagerSourceName:s})}))},fe=T=>({tableWrapper:(0,a.css)`
    margin-top: ${T.spacing(3)};
    ${T.breakpoints.up("md")} {
      margin-left: ${T.spacing(4.5)};
    }
  `,duration:(0,a.css)`
    margin-left: ${T.spacing(1)};
    font-size: ${T.typography.bodySmall.fontSize};
  `});var ie=t(66706);const re=({alertManagerSourceName:T,group:s})=>{const[I,V]=(0,r.useState)(!0),$=(0,e.wW)(Ue);return r.createElement("div",{className:$.wrapper},r.createElement("div",{className:$.header},r.createElement("div",{className:$.group,"data-testid":"alert-group"},r.createElement(p.U,{size:"sm",isCollapsed:I,onToggle:()=>V(!I),"data-testid":"alert-group-collapse-toggle"}),Object.keys(s.labels).length?r.createElement(c.s,{labels:s.labels,size:"sm"}):r.createElement("span",null,"No grouping")),r.createElement(ie.Z,{group:s})),!I&&r.createElement(N,{alertManagerSourceName:T,alerts:s.alerts}))},Ue=T=>({wrapper:(0,a.css)`
    & + & {
      margin-top: ${T.spacing(2)};
    }
  `,header:(0,a.css)`
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    padding: ${T.spacing(1,1,1,0)};
    background-color: ${T.colors.background.secondary};
    width: 100%;
  `,group:(0,a.css)`
    display: flex;
    flex-direction: row;
    align-items: center;
  `,summary:(0,a.css)``,spanElement:(0,a.css)`
    margin-left: ${T.spacing(.5)};
  `,[d.Z9.Active]:(0,a.css)`
    color: ${T.colors.error.main};
  `,[d.Z9.Suppressed]:(0,a.css)`
    color: ${T.colors.primary.main};
  `,[d.Z9.Unprocessed]:(0,a.css)`
    color: ${T.colors.secondary.main};
  `})},61868:(Q,P,t)=>{t.d(P,{Nx:()=>D,kO:()=>y,ot:()=>p});var a=t(52291),r=t.n(a),e=t(39953),d=t(14949);const c=/^((([01][0-9])|(2[0-3])):[0-5][0-9])$|(^24:00$)/,p=m=>m?c.test(m):!0,y=(m,M)=>{if(!m&&!M)return!0;if(!m&&M||m&&!M)return!1;const A="HH:mm",E=r()().startOf("day").add(m,A),h=r()().startOf("day").add(M,A);return!!(m&&M&&E.isBefore(h)||m&&M&&h.isAfter(E))};function D(m){return m.time_intervals.map((A,E)=>{const{times:h,weekdays:G,days_of_month:S,months:U,years:Y,location:_}=A,ae=(0,d.u6)(h,_),N=(0,d.v7)(G),fe=(0,d.J8)(S),ie=(0,d.m8)(U),re=(0,d.qw)(Y);return e.createElement(e.Fragment,{key:JSON.stringify(A)+E},`${ae} ${N}`,e.createElement("br",null),[fe,ie,re].join(" | "),e.createElement("br",null))})}},96440:(Q,P,t)=>{t.d(P,{g:()=>m});var a=t(41407),r=t(86832),e=t.n(r),d=t(39953),c=t(27366),p=t(82803),y=t(72899),D=t(44351);const m=({matchers:E})=>{const h=(0,p.wW)(A),G=5,S=(0,r.take)(E,G),U=(0,r.takeRight)(E,E.length-G),Y=U.length>0;return d.createElement("span",{"data-testid":"label-matchers"},d.createElement(c.K,{direction:"row",gap:1,alignItems:"center"},S.map(_=>d.createElement(M,{key:(0,r.uniqueId)(),matcher:_})),Y&&d.createElement(D.z,{arrow:!0,placement:"top",content:d.createElement(d.Fragment,null,U.map(_=>d.createElement(M,{key:(0,r.uniqueId)(),matcher:_})))},d.createElement("span",null,d.createElement("div",{className:h.metadata},`and ${U.length} more`)))))},M=({matcher:[E,h,G]})=>{const S=(0,p.wW)(A);return d.createElement("div",{className:S.matcher(E).wrapper},d.createElement(c.K,{direction:"row",gap:0,alignItems:"baseline"},E," ",h," ",G))},A=E=>({matcher:h=>{const{color:G,borderColor:S}=(0,y.Bx)(h);return{wrapper:(0,a.css)`
        color: #fff;
        background: ${G};
        padding: ${E.spacing(.33)} ${E.spacing(.66)};
        font-size: ${E.typography.bodySmall.fontSize};

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

    font-size: ${E.typography.bodySmall.fontSize};
    font-weight: ${E.typography.bodySmall.fontWeight};
  `})},76197:(Q,P,t)=>{t.d(P,{As:()=>a,Fs:()=>d,hM:()=>r});const a="grafana_alerting";var r=(c=>(c.OnCall="oncall",c))(r||{});const e=(c,p)=>p.includes(c),d=(c,p)=>{if(!c.grafana_managed_receiver_configs)return!1;const y=c.grafana_managed_receiver_configs.length===1,D=e(c.grafana_managed_receiver_configs[0]?.settings?.url??"",p.map(m=>m.integration_url));return y&&D}},84070:(Q,P,t)=>{t.d(P,{G:()=>c});var a=t(39953),r=t(47858),e=t(47624);const d={[r.Z9.Active]:"bad",[r.Z9.Unprocessed]:"neutral",[r.Z9.Suppressed]:"info"},c=({state:p})=>a.createElement(e.i,{state:d[p]},p)},72401:(Q,P,t)=>{t.d(P,{W:()=>r});var a=t(37546);function r(e,d){const c=a.alertmanagerApi.endpoints.getAlertmanagerConfiguration.useQuery(e??"",{...d,skip:!e});return{...c,error:c.error}}},88617:(Q,P,t)=>{t.d(P,{j:()=>d});var a=t(39953),r=t(53721),e=t(13601);function d(){const{search:c}=(0,r.TH)(),p=(0,a.useMemo)(()=>new URLSearchParams(c),[c]),y=(0,a.useCallback)((D,m)=>{e.E1.partial(D,m)},[]);return[p,y]}},25793:(Q,P,t)=>{t.d(P,{y:()=>a});const a={discord:"discord",email:"envelope",googlechat:"google-hangouts-alt",hipchat:"hipchat",line:"line",pagerduty:"pagerduty",slack:"slack",teams:"microsoft",telegram:"telegram-alt",webhook:"link",sns:"amazon"}},47853:(Q,P,t)=>{t.d(P,{N:()=>E});var a=t(6222),r=t(39953),e=t(5229),d=t(54538),c=t(79517),p=t(84474);const y=()=>new p.q(new URL(t.p+t.u(7530),t.b));var D=t(45050);let m;function M(){let h;if(m===void 0)try{h=y(),m=a.Ud(h)}catch(S){S instanceof Error&&(0,d.H)(S)}return{disposeWorker:()=>{h&&m&&(m[a.Yy](),h.terminate(),m=void 0,h=void 0)}}}function A(h,G){if(!h)throw new Error("Matching routes preview is disabled");if(!m)throw new Error("Route Matcher has not been initialized")}function E(){const h=(0,e.Qb)(D.v.NotificationPoliciesV2MatchingInstances);(0,r.useEffect)(()=>{if(h){const{disposeWorker:U}=M();return U}return()=>null},[h]);const G=(0,r.useCallback)(async(U,Y)=>{A(h,m);const _=performance.now(),ae=await m.getRouteGroupsMap(U,Y),N=performance.now()-_;return(0,c.PN)(`Route Groups Matched in  ${N} ms`,{matchingTime:N.toString(),alertGroupsCount:Y.length.toString(),topLevelRoutesCount:U.routes?.length.toString()??"0"}),ae},[h]),S=(0,r.useCallback)(async(U,Y)=>{A(h,m);const _=performance.now(),ae=await m.matchInstancesToRoute(U,Y),N=performance.now()-_;return(0,c.PN)(`Instances Matched in  ${N} ms`,{matchingTime:N.toString(),instancesToMatchCount:Y.length.toString(),topLevelRoutesCount:U.routes?.length.toString()??"0"}),ae},[h]);return{getRouteGroupsMap:G,matchInstancesToRoute:S}}},93139:(Q,P,t)=>{t.d(P,{Oy:()=>re,T0:()=>ae,Yg:()=>_,ZS:()=>Y,bi:()=>ie,br:()=>U,dO:()=>G,eP:()=>T,eh:()=>N,fx:()=>E,mJ:()=>fe});var a=t(86832),r=t.n(a),e=t(47858),d=t(14949),c=t(95712),p=t(75404),y=t(75964),D=t(66793);const m=(s,I)=>Object.entries(s??{}).reduce((V,[$,W])=>[...V,{name:$,value:W,operator:I?e._M.regex:e._M.equal}],[]),M=s=>s.value,A=s=>(s??[]).map(M),E={name:"",value:"",operator:e._M.equal},h=["grafana_folder","alertname"],G=[{label:"grafana_folder",value:"grafana_folder"},{label:"alertname",value:"alertname"},{label:"Disable (...)",value:"..."}],S={id:"",overrideGrouping:!1,groupBy:h,object_matchers:[],routes:[],continue:!1,receiver:"",overrideTimings:!1,groupWaitValue:"",groupIntervalValue:"",repeatIntervalValue:"",muteTimeIntervals:[]};function U(s){return{id:(0,a.uniqueId)("route-"),...s,routes:(s.routes??[]).map(U)}}const Y=s=>{if(!s)return S;const I="id"in s?s.id:(0,a.uniqueId)("route-");if(Object.keys(s).length===0)return{...S,id:I};const V=[];s.routes?.forEach(X=>{const Ee=Y(X);V.push(Ee)});const $=s.object_matchers?.map(X=>({name:X[0],operator:X[1],value:X[2]}))??[],W=s.matchers?.map(X=>(0,d.cm)((0,p.tC)(X)))??[];return{id:I,object_matchers:[...W,...$,...m(s.match,!1),...m(s.match_re,!0)],continue:s.continue??!1,receiver:s.receiver??"",overrideGrouping:Array.isArray(s.group_by)&&s.group_by.length>0,groupBy:s.group_by??void 0,overrideTimings:[s.group_wait,s.group_interval,s.repeat_interval].some(Boolean),groupWaitValue:s.group_wait??"",groupIntervalValue:s.group_interval??"",repeatIntervalValue:s.repeat_interval??"",routes:V,muteTimeIntervals:s.mute_time_intervals??[]}},_=(s,I,V)=>{const $=(0,y.Tx)(I.id??"",V),{overrideGrouping:W,groupBy:X,overrideTimings:Ee,groupWaitValue:be,groupIntervalValue:we,repeatIntervalValue:De,receiver:Ke}=I,Me=void 0,qe=W?X:Me,et=Ee&&be?be:Me,tt=Ee&&we?we:Me,ve=Ee&&De?De:Me,Pe=I.object_matchers?.filter(q=>q.name&&q.value&&q.operator).map(({name:q,operator:Re,value:Oe})=>[q,Re,Oe]),ce=I.routes?.map(q=>_(s,q,V)),ue={...$??{},continue:I.continue,group_by:qe,object_matchers:Pe,match:void 0,match_re:void 0,group_wait:et,group_interval:tt,repeat_interval:ve,routes:ce,mute_time_intervals:I.muteTimeIntervals,receiver:Ke};return s!==c.GC?(ue.matchers=I.object_matchers?.map(({name:q,operator:Re,value:Oe})=>`${q}${Re}${Oe}`),ue.object_matchers=void 0):(ue.object_matchers=(0,p.QO)(ue),ue.matchers=void 0),I.receiver&&(ue.receiver=I.receiver),ue},ae=s=>({label:s,value:s}),N=s=>(s??[]).map(ae),fe=s=>{if(s!==null)return s?M(s)??"":""},ie=s=>s?A(s):[];function re(s){return s.length===0?!0:(0,D.wd)(s)||"Invalid duration format. Must be {number}{time_unit}"}const Ue=s=>s.map(I=>{const[V,$,W]=I;return`${V}${$}${W}`}),T=(s,I)=>{if(s.length===0)return!0;const V=re(s),$=re(I);if(V!==!0)return V;if($!==!0)return $;const W=(0,D.Bg)(s),X=(0,D.Bg)(I);return X!==0&&W<X?"Repeat interval should be higher or equal to Group interval":!0}},75964:(Q,P,t)=>{t.d(P,{SF:()=>d,Tx:()=>y,_P:()=>p,wB:()=>c});var a=t(86832),r=t.n(a),e=t(93139);const d=(D,m,M)=>{if(!y(m.id??"",M))throw new Error(`No such route with ID '${m.id}'`);function E(h){let G=h;if(h.id===m.id){const S=(0,e.Yg)(D,m,M);G=(0,a.omit)({...h,...S},"id")}return(0,a.omit)({...G,routes:h.routes?.map(E)},"id")}return E(M)},c=(D,m)=>{if(D.id===m.id)throw new Error("You cant remove the root policy");function M(A){return(0,a.omit)({...A,routes:A.routes?.reduce((E=[],h)=>(h.id===D.id||E.push(M(h)),E),[])},"id")}return M(m)},p=(D,m,M,A)=>{const E=(0,e.Yg)(D,m,A);function h(S){return S.id===M.id?{...S,routes:S.routes?.concat(E)}:{...S,routes:S.routes?.map(h)}}function G(S){return(0,a.omit)({...S,routes:S.routes?.map(G)},"id")}return G(h(A))};function y(D,m){return m.id===D?m:m.routes?.find(M=>y(D,M))}}}]);

//# sourceMappingURL=AlertAmRoutes.21ceab071371b139b947.js.map