"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[8648],{11482:(H,O,n)=>{n.r(O),n.d(O,{default:()=>kn,findRoutesMatchingFilters:()=>Dt});var c=n(9892),s=n(82897),e=n(66111),g=n(26418),E=n(72648),S=n(72142),y=n(79841),h=n(94893),D=n(61744),B=n(45253),T=n(53546),F=n(96044),j=n(27876),x=n(40014),G=n(96678),J=n(94984),q=n(45524),pe=n(731),Fe=n(88331),Ee=n(40106),V=n(31403),Ue=n(98102),ve=n(29460),me=n(8180),b=n(82002),Q=n(51981),z=n(69945),_=n(72004),ne=n(97953),R=n(20194),k=n(10505),le=n(46818),$t=n(53731);const Bt=({children:t})=>{const a=(0,E.wW)(Wt);return e.createElement("div",{className:a.container},t)},Wt=t=>({container:c.css`
      background-color: ${t.colors.background.secondary};
      color: ${t.colors.text.secondary};
      padding: ${t.spacing(4)};
      text-align: center;
    `}),Gt=({buttonIcon:t,buttonLabel:a,buttonSize:r="lg",buttonVariant:l="primary",onButtonClick:m,text:o,href:i,showButton:u=!0})=>{const d=(0,E.wW)(wt),v={className:d.button,icon:t,size:r,variant:l};return e.createElement(Bt,null,e.createElement(e.Fragment,null,e.createElement("p",{className:d.text},o),u&&(i?e.createElement(V.Qj,{href:i,type:"button",...v},a):e.createElement(V.zx,{onClick:m,type:"button",...v},a))))},wt=t=>({container:c.css`
      background-color: ${t.colors.background.secondary};
      color: ${t.colors.text.secondary};
      padding: ${t.spacing(4)};
      text-align: center;
    `,text:c.css`
      margin-bottom: ${t.spacing(2)};
    `,button:c.css`
      margin: ${t.spacing(2,0,1)};
    `});var at=n(63029);const Nt=({alertManagerSourceName:t,muteTimingNames:a,hideActions:r})=>{const l=(0,E.wW)(Ut),m=(0,j.useDispatch)(),o=(0,ne.Ko)(t),i=(0,z._)(w=>w.amConfigs),[u,d]=(0,e.useState)(""),{result:v}=t&&i[t]||le.oq,M=(0,e.useMemo)(()=>{const w=v?.alertmanager_config?.mute_time_intervals??[],$=v?.alertmanager_config?.muteTimeProvenances??{};return w.filter(({name:p})=>a?a.includes(p):!0).map(p=>({id:p.name,data:{...p,provenance:$[p.name]}}))},[v?.alertmanager_config?.mute_time_intervals,v?.alertmanager_config?.muteTimeProvenances,a]),f=Lt(t,r,d);return e.createElement("div",{className:l.container},e.createElement(g.Stack,{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(at.L,null),!r&&M.length>0&&e.createElement(Q.q,{actions:[o.create]},e.createElement(V.Qj,{className:l.addMuteButton,icon:"plus",variant:"primary",href:(0,k.eQ)("alerting/routes/mute-timing/new",t)},"Add mute timing"))),M.length>0?e.createElement($t.t,{items:M,cols:f}):r?e.createElement("p",null,"No mute timings configured"):e.createElement(Gt,{text:"You haven't created any mute timings yet",buttonLabel:"Add mute timing",buttonIcon:"plus",buttonSize:"lg",href:(0,k.eQ)("alerting/routes/mute-timing/new",t),showButton:b.Vt.hasPermission(o.create)}),!r&&e.createElement(Ue.s,{isOpen:!!u,title:"Delete mute timing",body:`Are you sure you would like to delete "${u}"`,confirmText:"Delete",onConfirm:()=>m((0,_.r0)(t,u)),onDismiss:()=>d("")}))};function Lt(t,a=!1,r){const l=(0,ne.Ko)(t),m=b.Vt.hasPermission(l.update),o=b.Vt.hasPermission(l.delete),i=!a&&(m||o);return(0,e.useMemo)(()=>{const u=[{id:"name",label:"Name",renderCell:function({data:v}){return e.createElement(e.Fragment,null,v.name," ",v.provenance&&e.createElement(Ee.C0,null))},size:"250px"},{id:"timeRange",label:"Time range",renderCell:({data:d})=>Ft(d.time_intervals)}];return i&&u.push({id:"actions",label:"Actions",renderCell:function({data:v}){return v.provenance?e.createElement("div",null,e.createElement(ve.r,{href:(0,k.eQ)("/alerting/routes/mute-timing/edit",t,{muteName:v.name})},e.createElement(me.h,{name:"file-alt",title:"View mute timing"}))):e.createElement("div",null,e.createElement(Q.q,{actions:[l.update]},e.createElement(ve.r,{href:(0,k.eQ)("/alerting/routes/mute-timing/edit",t,{muteName:v.name})},e.createElement(me.h,{name:"edit",title:"Edit mute timing"}))),e.createElement(Q.q,{actions:[l.delete]},e.createElement(me.h,{name:"trash-alt",title:"Delete mute timing",onClick:()=>r(v.name)})))},size:"100px"}),u},[t,r,i,l])}function Ft(t){return t.map((a,r)=>{const{times:l,weekdays:m,days_of_month:o,months:i,years:u}=a,d=(0,R.u6)(l),v=(0,R.v7)(m),M=(0,R.J8)(o),f=(0,R.m8)(i),w=(0,R.qw)(u);return e.createElement(e.Fragment,{key:JSON.stringify(a)+r},`${d} ${v}`,e.createElement("br",null),[M,f,w].join(" | "),e.createElement("br",null))})}const Ut=t=>({container:c.css`
    display: flex;
    flex-flow: column nowrap;
  `,addMuteButton:c.css`
    margin-bottom: ${t.spacing(2)};
    align-self: flex-end;
  `});var U=n(24799),Vt=n(64353),fe=n(61860),se=n(39904),Se=n(46967),ie=n(8581),zt=n(31808);const Kt=({receivers:t,onChangeReceiver:a,onChangeMatchers:r})=>{const[l,m]=(0,zt.j)(),o=(0,e.useRef)(null),{queryString:i,contactPoint:u}=kt(l),d=(0,E.wW)(Qt),v=(0,e.useCallback)(()=>(0,s.debounce)(r,500),[r]);(0,e.useEffect)(()=>{a(u)},[u,a]),(0,e.useEffect)(()=>{const C=(0,R.Zh)(i??"").map(R.xz);v()(C)},[v,i]);const M=(0,e.useCallback)(()=>{o.current&&(o.current.value=""),m({contactPoint:void 0,queryString:void 0})},[m]),f=t.map(jt),w=f.find(C=>C.value===u)??null,$=i||u,p=i&&i.length>3?(0,R.Zh)(i).length===0:!1;return e.createElement(g.Stack,{direction:"row",alignItems:"flex-start",gap:.5},e.createElement(U.g,{className:d.noBottom,label:e.createElement(Vt._,null,e.createElement(g.Stack,{gap:.5},e.createElement("span",null,"Search by matchers"),e.createElement(fe.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(se.J,{name:"info-circle",size:"sm"})))),invalid:p,error:p?"Query must use valid matcher syntax":null},e.createElement(Se.I,{ref:o,"data-testid":"search-query-input",placeholder:"Search",width:46,prefix:e.createElement(se.J,{name:"search"}),onChange:C=>{m({queryString:C.currentTarget.value})},defaultValue:i})),e.createElement(U.g,{label:"Search by contact point",style:{marginBottom:0}},e.createElement(ie.Ph,{id:"receiver","aria-label":"Search by contact point",value:w,options:f,onChange:C=>{m({contactPoint:C?.value})},width:28,isClearable:!0})),$&&e.createElement(V.zx,{variant:"secondary",icon:"times",onClick:M,style:{marginTop:19}},"Clear filters"))};function rt(t,a){const r=[];function l(m){a(m)&&r.push(m),m.routes?.forEach(l)}return l(t),r}function ot(t){return{...t,routes:t.routes?.map(a=>{const r=(0,s.pick)(t,["receiver","group_by","group_wait","group_interval","repeat_interval","mute_time_intervals"]);return ot({...r,...a})})}}const jt=t=>({label:t.name,value:t.name}),kt=t=>({queryString:t.get("queryString")??void 0,contactPoint:t.get("contactPoint")??void 0}),Qt=()=>({noBottom:c.css`
    margin-bottom: 0;
  `});var ae=n(35029),Zt=n(67487),K=n(39031),Ht=n(94647),lt=n(52259),Jt=n(64681),Te=n.n(Jt),he=n(19985);const Yt=({active:t=0,suppressed:a=0,unprocessed:r=0})=>{const l=[],m=t+a+r;return t&&l.push(e.createElement(he.C,{color:"red",key:"firing",text:`${t} firing`})),a&&l.push(e.createElement(he.C,{color:"blue",key:"suppressed",text:`${a} suppressed`})),r&&l.push(e.createElement(he.C,{color:"orange",key:"unprocessed",text:`${r} unprocessed`})),l.length>1&&l.unshift(e.createElement(e.Fragment,{key:"total"},m," ",Te()("instance",m))),Boolean(l.length)?e.createElement(g.Stack,{gap:.5},l):null};var st=n(94270),ue=n(63619),Xt=n(2352),it=n(45849);const qt=(t,a,r)=>{if(!Ve(a.id??"",r))throw new Error(`No such route with ID '${a.id}'`);function m(o){let i=o;if(o.id===a.id){const u=Ke(t,a,r);i=(0,s.omit)({...o,...u},"id")}return(0,s.omit)({...i,routes:o.routes?.map(m)},"id")}return m(r)},_t=(t,a)=>{if(t.id===a.id)throw new Error("You cant remove the root policy");function r(l){return(0,s.omit)({...l,routes:l.routes?.reduce((m=[],o)=>(o.id===t.id||m.push(r(o)),m),[])},"id")}return r(a)},en=(t,a,r,l)=>{const m=Ke(t,a,l);function o(u){return u.id===r.id?{...u,routes:u.routes?.concat(m)}:{...u,routes:u.routes?.map(o)}}function i(u){return(0,s.omit)({...u,routes:u.routes?.map(i)},"id")}return i(o(l))};function Ve(t,a){return a.id===t?a:a.routes?.find(r=>Ve(t,r))}var tn=n(20383);const ct=(t,a)=>Object.entries(t??{}).reduce((r,[l,m])=>[...r,{name:l,value:m,operator:a?K._M.regex:K._M.equal}],[]),mt=t=>t.value,nn=t=>(t??[]).map(mt),an={name:"",value:"",operator:K._M.equal},rn=["grafana_folder","alertname"],ut=[{label:"grafana_folder",value:"grafana_folder"},{label:"alertname",value:"alertname"},{label:"Disable (...)",value:"..."}],dt={id:"",overrideGrouping:!1,groupBy:rn,object_matchers:[],routes:[],continue:!1,receiver:"",overrideTimings:!1,groupWaitValue:"",groupIntervalValue:"",repeatIntervalValue:"",muteTimeIntervals:[]},Oe=t=>{const a=[];return t.matchers&&t.matchers.forEach(r=>{const{name:l,value:m,isEqual:o,isRegex:i}=(0,R.tC)(r);let u=K._M.equal;o&&i&&(u=K._M.regex),!o&&i&&(u=K._M.notRegex),o&&!i&&(u=K._M.equal),!o&&!i&&(u=K._M.notEqual),a.push([l,u,m])}),t.object_matchers&&a.push(...t.object_matchers),t.match_re&&Object.entries(t.match_re).forEach(([r,l])=>{a.push([r,K._M.regex,l])}),t.match&&Object.entries(t.match).forEach(([r,l])=>{a.push([r,K._M.equal,l])}),a};function gt(t){return{id:(0,s.uniqueId)("route-"),...t,routes:(t.routes??[]).map(gt)}}const ze=t=>{if(!t)return dt;const a="id"in t?t.id:(0,s.uniqueId)("route-");if(Object.keys(t).length===0)return{...dt,id:a};const r=[];t.routes?.forEach(o=>{const i=ze(o);r.push(i)});const l=t.object_matchers?.map(o=>({name:o[0],operator:o[1],value:o[2]}))??[],m=t.matchers?.map(o=>(0,R.cm)((0,R.tC)(o)))??[];return{id:a,object_matchers:[...m,...l,...ct(t.match,!1),...ct(t.match_re,!0)],continue:t.continue??!1,receiver:t.receiver??"",overrideGrouping:Array.isArray(t.group_by)&&t.group_by.length>0,groupBy:t.group_by??void 0,overrideTimings:[t.group_wait,t.group_interval,t.repeat_interval].some(Boolean),groupWaitValue:t.group_wait??"",groupIntervalValue:t.group_interval??"",repeatIntervalValue:t.repeat_interval??"",routes:r,muteTimeIntervals:t.mute_time_intervals??[]}},Ke=(t,a,r)=>{const l=Ve(a.id??"",r),{overrideGrouping:m,groupBy:o,overrideTimings:i,groupWaitValue:u,groupIntervalValue:d,repeatIntervalValue:v,receiver:M}=a,f=void 0,w=m?o:f,p=i&&u?u:f,L=i&&d?d:f,N=i&&v?v:f,W=a.object_matchers?.filter(I=>I.name&&I.value&&I.operator).map(({name:I,operator:A,value:Z})=>[I,A,Z]),Y=a.routes?.map(I=>Ke(t,I,r)),P={...l??{},continue:a.continue,group_by:w,object_matchers:W,match:void 0,match_re:void 0,group_wait:p,group_interval:L,repeat_interval:N,routes:Y,mute_time_intervals:a.muteTimeIntervals,receiver:M};return t!==it.GC?(P.matchers=a.object_matchers?.map(({name:I,operator:A,value:Z})=>`${I}${A}${Z}`),P.object_matchers=void 0):(P.object_matchers=Oe(P),P.matchers=void 0),a.receiver&&(P.receiver=a.receiver),P},je=t=>({label:t,value:t}),pt=t=>(t??[]).map(je),Et=t=>{if(t!==null)return t?mt(t)??"":""},ke=t=>t?nn(t):[];function de(t){return t.length===0?!0:(0,tn.wd)(t)||"Invalid duration format. Must be {number}{time_unit}"}var ye=n(42042),be=n(4528);function on(){const t=(0,E.wW)(vt);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:t.list},e.createElement("div",{className:t.header},e.createElement("div",null,"Symbol"),e.createElement("div",null,"Time unit"),e.createElement("div",null,"Example")),e.createElement(Me,{unit:be.t.seconds,name:"seconds",example:"20s"}),e.createElement(Me,{unit:be.t.minutes,name:"minutes",example:"10m"}),e.createElement(Me,{unit:be.t.hours,name:"hours",example:"4h"}),e.createElement(Me,{unit:be.t.days,name:"days",example:"3d"}),e.createElement(Me,{unit:be.t.weeks,name:"weeks",example:"2w"}),e.createElement("div",{className:t.examples},e.createElement("div",null,"Multiple units combined"),e.createElement("code",null,"1m30s, 2h30m20s, 1w2d"))))}function Me({unit:t,name:a,example:r}){const l=(0,E.wW)(vt);return e.createElement(e.Fragment,null,e.createElement("div",{className:l.unit},t),e.createElement("div",null,a),e.createElement("code",null,r))}const vt=t=>({unit:c.css`
    font-weight: ${t.typography.fontWeightBold};
  `,list:c.css`
    display: grid;
    grid-template-columns: max-content 1fr 2fr;
    gap: ${t.spacing(1,3)};
  `,header:c.css`
    display: contents;
    font-weight: ${t.typography.fontWeightBold};
  `,examples:c.css`
    display: contents;
    & > div {
      grid-column: 1 / span 2;
    }
  `}),ce=e.forwardRef((t,a)=>e.createElement(Se.I,{suffix:e.createElement(ye.z,{content:e.createElement(on,null),disabled:!1},e.createElement(se.J,{name:"info-circle",size:"lg"})),...t,ref:a}));ce.displayName="PromDurationInput";const ft=t=>({container:c.css`
      align-items: center;
      display: flex;
      flex-flow: row nowrap;

      & > * + * {
        margin-left: ${t.spacing(1)};
      }
    `,input:c.css`
      flex: 1;
    `,promDurationInput:c.css`
      max-width: ${t.spacing(32)};
    `,timingFormContainer:c.css`
      padding: ${t.spacing(1)};
    `,linkText:c.css`
      text-decoration: underline;
    `,collapse:c.css`
      border: none;
      background: none;
      color: ${t.colors.text.primary};
    `}),Ae={group_wait:"30s",group_interval:"5m",repeat_interval:"4h"},ln=({actionButtons:t,alertManagerSourceName:a,onSubmit:r,receivers:l,route:m})=>{const o=(0,E.wW)(ft),[i,u]=(0,e.useState)(!1),[d,v]=(0,e.useState)(pt(m.group_by)),M=ze(m);return e.createElement(st.l,{defaultValues:{...M,overrideTimings:!0,overrideGrouping:!0},onSubmit:r},({register:f,control:w,errors:$,setValue:p})=>e.createElement(e.Fragment,null,e.createElement(U.g,{label:"Default contact point",invalid:!!$.receiver,error:$.receiver?.message},e.createElement(e.Fragment,null,e.createElement("div",{className:o.container,"data-testid":"am-receiver-select"},e.createElement(ue.g,{render:({field:{onChange:C,ref:L,...te}})=>e.createElement(ie.Ph,{"aria-label":"Default contact point",...te,className:o.input,onChange:N=>C(Et(N)),options:l}),control:w,name:"receiver",rules:{required:{value:!0,message:"Required."}}}),e.createElement("span",null,"or"),e.createElement(ve.r,{className:o.linkText,href:(0,k.eQ)("/alerting/notifications/receivers/new",a)},"Create a contact point")))),e.createElement(U.g,{label:"Group by",description:"Group alerts when you receive a notification based on labels.","data-testid":"am-group-select"},e.createElement(ue.g,{render:({field:{onChange:C,ref:L,...te}})=>e.createElement(ie.NU,{"aria-label":"Group by",...te,allowCustomValue:!0,className:o.input,onCreateOption:N=>{v(W=>[...W,je(N)]),p("groupBy",[...te.value,N])},onChange:N=>C(ke(N)),options:[...ut,...d]}),control:w,name:"groupBy"})),e.createElement(Xt.U,{collapsible:!0,className:o.collapse,isOpen:i,label:"Timing options",onToggle:u},e.createElement("div",{className:o.timingFormContainer},e.createElement(U.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:!!$.groupWaitValue,error:$.groupWaitValue?.message,"data-testid":"am-group-wait"},e.createElement(ce,{...f("groupWaitValue",{validate:de}),placeholder:Ae.group_wait,className:o.promDurationInput,"aria-label":"Group wait"})),e.createElement(U.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:!!$.groupIntervalValue,error:$.groupIntervalValue?.message,"data-testid":"am-group-interval"},e.createElement(ce,{...f("groupIntervalValue",{validate:de}),placeholder:Ae.group_interval,className:o.promDurationInput,"aria-label":"Group interval"})),e.createElement(U.g,{label:"Repeat interval",description:"The waiting time to resend an alert after they have successfully been sent. Default 4 hours.",invalid:!!$.repeatIntervalValue,error:$.repeatIntervalValue?.message,"data-testid":"am-repeat-interval"},e.createElement(ce,{...f("repeatIntervalValue",{validate:de}),placeholder:Ae.repeat_interval,className:o.promDurationInput,"aria-label":"Repeat interval"})))),e.createElement("div",{className:o.container},t)))};var sn=n(70132),Qe=n(8944),cn=n(57227),ht=n(29614),yt=n(23403);function mn(){const t=(0,yt.k)("notification"),[a]=(0,ht.k)(t),r=(0,z._)(l=>l.amConfigs);return(0,e.useMemo)(()=>{const{result:l}=a&&r[a]||le.oq;return(l?.alertmanager_config??{})?.mute_time_intervals?.map(i=>({value:i.name,label:i.name,description:i.time_intervals.map(u=>(0,R.uK)(u)).join(", AND ")}))??[]},[a,r])}var un=n(2390);const bt=({actionButtons:t,receivers:a,route:r,onSubmit:l,defaults:m})=>{const o=(0,E.wW)(gn),i=(0,E.wW)(ft),[u,d]=(0,e.useState)(pt(r?.group_by)),v=mn(),M=[{name:"",operator:K._M.equal,value:""}],f=a.sort(dn),w={...ze(r),...m},$={...w,object_matchers:r?w.object_matchers:M};return e.createElement(st.l,{defaultValues:$,onSubmit:l,maxWidth:"none"},({control:p,register:C,errors:L,setValue:te,watch:N})=>e.createElement(e.Fragment,null,e.createElement("input",{type:"hidden",...C("id")}),e.createElement(sn.F,{name:"object_matchers",control:p},({fields:W,append:Y,remove:P})=>e.createElement(e.Fragment,null,e.createElement(g.Stack,{direction:"column",alignItems:"flex-start"},e.createElement("div",null,"Matching labels"),W.length===0&&e.createElement(he.C,{color:"orange",className:o.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:o.matchersContainer},W.map((I,A)=>e.createElement(g.Stack,{direction:"row",key:I.id,alignItems:"center"},e.createElement(U.g,{label:"Label",invalid:!!L.object_matchers?.[A]?.name,error:L.object_matchers?.[A]?.name?.message},e.createElement(Se.I,{...C(`object_matchers.${A}.name`,{required:"Field is required"}),defaultValue:I.name,placeholder:"label",autoFocus:!0})),e.createElement(U.g,{label:"Operator"},e.createElement(ue.g,{render:({field:{onChange:Z,ref:ge,...$e}})=>e.createElement(ie.Ph,{...$e,className:o.matchersOperator,onChange:Ce=>Z(Ce?.value),options:R.tA,"aria-label":"Operator"}),defaultValue:I.operator,control:p,name:`object_matchers.${A}.operator`,rules:{required:{value:!0,message:"Required."}}})),e.createElement(U.g,{label:"Value",invalid:!!L.object_matchers?.[A]?.value,error:L.object_matchers?.[A]?.value?.message},e.createElement(Se.I,{...C(`object_matchers.${A}.value`,{required:"Field is required"}),defaultValue:I.value,placeholder:"value"})),e.createElement(me.h,{type:"button",tooltip:"Remove matcher",name:"trash-alt",onClick:()=>P(A)},"Remove")))),e.createElement(V.zx,{className:o.addMatcherBtn,icon:"plus",onClick:()=>Y(an),variant:"secondary",type:"button"},"Add matcher")))),e.createElement(U.g,{label:"Contact point"},e.createElement(ue.g,{render:({field:{onChange:W,ref:Y,...P}})=>e.createElement(ie.Ph,{"aria-label":"Contact point",...P,className:i.input,onChange:I=>W(Et(I)),options:f,isClearable:!0}),control:p,name:"receiver"})),e.createElement(U.g,{label:"Continue matching subsequent sibling nodes"},e.createElement(Qe.r,{id:"continue-toggle",...C("continue")})),e.createElement(U.g,{label:"Override grouping"},e.createElement(Qe.r,{id:"override-grouping-toggle",...C("overrideGrouping")})),N().overrideGrouping&&e.createElement(U.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(ue.g,{rules:{validate:W=>!W||W.length===0?"At least one group by option is required.":!0},render:({field:{onChange:W,ref:Y,...P},fieldState:{error:I}})=>e.createElement(e.Fragment,null,e.createElement(ie.NU,{"aria-label":"Group by",...P,invalid:Boolean(I),allowCustomValue:!0,className:i.input,onCreateOption:A=>{d(Z=>[...Z,je(A)]),te("groupBy",[...P.value,A])},onChange:A=>W(ke(A)),options:[...ut,...u]}),I&&e.createElement(cn.S,null,I.message)),control:p,name:"groupBy"})),e.createElement(U.g,{label:"Override general timings"},e.createElement(Qe.r,{id:"override-timings-toggle",...C("overrideTimings")})),N().overrideTimings&&e.createElement(e.Fragment,null,e.createElement(U.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:!!L.groupWaitValue,error:L.groupWaitValue?.message},e.createElement(ce,{...C("groupWaitValue",{validate:de}),"aria-label":"Group wait value",className:i.promDurationInput})),e.createElement(U.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:!!L.groupIntervalValue,error:L.groupIntervalValue?.message},e.createElement(ce,{...C("groupIntervalValue",{validate:de}),"aria-label":"Group interval value",className:i.promDurationInput})),e.createElement(U.g,{label:"Repeat interval",description:"The waiting time to resend an alert after they have successfully been sent.",invalid:!!L.repeatIntervalValue,error:L.repeatIntervalValue?.message},e.createElement(ce,{...C("repeatIntervalValue",{validate:de}),"aria-label":"Repeat interval value",className:i.promDurationInput}))),e.createElement(U.g,{label:"Mute timings","data-testid":"am-mute-timing-select",description:"Add mute timing to policy",invalid:!!L.muteTimeIntervals},e.createElement(ue.g,{render:({field:{onChange:W,ref:Y,...P}})=>e.createElement(ie.NU,{"aria-label":"Mute timings",...P,className:i.input,onChange:I=>W(ke(I)),options:v}),control:p,name:"muteTimeIntervals"})),t))};function dn(t){return t.grafanaAppReceiverType===un.W.OnCall?-1:0}const gn=t=>{const a=t.spacing(3.5);return{addMatcherBtn:c.css`
      margin-bottom: ${a};
    `,matchersContainer:c.css`
      background-color: ${t.colors.background.secondary};
      padding: ${t.spacing(1.5)} ${t.spacing(2)};
      padding-bottom: 0;
      width: fit-content;
    `,matchersOperator:c.css`
      min-width: 120px;
    `,noMatchersWarning:c.css`
      padding: ${t.spacing(1)} ${t.spacing(2)};
    `}};var Mt=n(3385);const At=({matchers:t})=>{const a=(0,E.wW)(Pt),r=5,l=(0,s.take)(t,r),m=(0,s.takeRight)(t,t.length-r),o=m.length>0;return e.createElement("span",{"data-testid":"label-matchers"},e.createElement(g.Stack,{direction:"row",gap:1,alignItems:"center"},l.map(i=>e.createElement(Ct,{key:(0,s.uniqueId)(),matcher:i})),o&&e.createElement(ye.z,{arrow:!0,placement:"top",content:e.createElement(e.Fragment,null,m.map(i=>e.createElement(Ct,{key:(0,s.uniqueId)(),matcher:i})))},e.createElement("span",null,e.createElement("div",{className:a.metadata},`and ${m.length} more`)))))},Ct=({matcher:[t,a,r]})=>{const l=(0,E.wW)(Pt);return e.createElement("div",{className:l.matcher(t).wrapper},e.createElement(g.Stack,{direction:"row",gap:0,alignItems:"baseline"},t," ",a," ",r))},Pt=t=>({matcher:a=>{const{color:r,borderColor:l}=(0,Mt.Bx)(a);return{wrapper:c.css`
        color: #fff;
        background: ${r};
        padding: ${t.spacing(.33)} ${t.spacing(.66)};
        font-size: ${t.typography.bodySmall.fontSize};

        border: solid 1px ${l};
        border-radius: ${t.shape.borderRadius(2)};
      `}},metadata:c.css`
    color: ${t.colors.text.secondary};

    font-size: ${t.typography.bodySmall.fontSize};
    font-weight: ${t.typography.bodySmall.fontWeight};
  `}),pn=(t=[],a,r)=>{const[l,m]=(0,e.useState)(!1),[o,i]=(0,e.useState)(),u=(0,lt.Kt)(t),d=(0,e.useCallback)(()=>{i(void 0),m(!1)},[]),v=(0,e.useCallback)(f=>{i(f),m(!0)},[]);return[(0,e.useMemo)(()=>r?e.createElement(Ze,{isOpen:l}):e.createElement(ae.u,{isOpen:l,onDismiss:d,closeOnBackdropClick:!0,closeOnEscape:!0,title:"Add notification policy"},e.createElement(bt,{receivers:u,defaults:{groupBy:o?.group_by},onSubmit:f=>o&&a(f,o),actionButtons:e.createElement(ae.u.ButtonRow,null,e.createElement(V.zx,{type:"submit"},"Save policy"),e.createElement(V.zx,{type:"button",variant:"secondary",onClick:d},"Cancel"))})),[u,a,d,r,o,l]),v,d]},En=(t,a,r,l)=>{const[m,o]=(0,e.useState)(!1),[i,u]=(0,e.useState)(!1),[d,v]=(0,e.useState)(),M=(0,lt.Kt)(a),f=(0,e.useCallback)(()=>{v(void 0),o(!1)},[]),w=(0,e.useCallback)((p,C)=>{u(C??!1),v(p),o(!0)},[]);return[(0,e.useMemo)(()=>l?e.createElement(Ze,{isOpen:m}):e.createElement(ae.u,{isOpen:m,onDismiss:f,closeOnBackdropClick:!0,closeOnEscape:!0,title:"Edit notification policy"},i&&d&&e.createElement(ln,{alertManagerSourceName:t,onSubmit:r,receivers:M,route:d,actionButtons:e.createElement(ae.u.ButtonRow,null,e.createElement(V.zx,{type:"submit"},"Update default policy"),e.createElement(V.zx,{type:"button",variant:"secondary",onClick:f},"Cancel"))}),!i&&e.createElement(bt,{receivers:M,route:d,onSubmit:r,actionButtons:e.createElement(ae.u.ButtonRow,null,e.createElement(V.zx,{type:"submit"},"Update policy"),e.createElement(V.zx,{type:"button",variant:"secondary",onClick:f},"Cancel"))})),[M,t,f,r,i,l,d,m]),w,f]},vn=(t,a)=>{const[r,l]=(0,e.useState)(!1),[m,o]=(0,e.useState)(),i=(0,e.useCallback)(()=>{o(void 0),l(!1)},[o]),u=(0,e.useCallback)(M=>{o(M),l(!0)},[]),d=(0,e.useCallback)(()=>{m&&t(m)},[t,m]);return[(0,e.useMemo)(()=>a?e.createElement(Ze,{isOpen:r}):e.createElement(ae.u,{isOpen:r,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(ae.u.ButtonRow,null,e.createElement(V.zx,{type:"button",variant:"destructive",onClick:d},"Yes, delete policy"),e.createElement(V.zx,{type:"button",variant:"secondary",onClick:i},"Cancel"))),[i,d,a,r]),u,i]},fn=()=>{const[t,a]=(0,e.useState)(!1),[r,l]=(0,e.useState)([]),[m,o]=(0,e.useState)([]),i=(0,e.useCallback)(()=>{a(!1),l([]),o([])},[]),u=(0,e.useCallback)((M,f)=>{l(M),f&&o(f),a(!0)},[]),d=(0,e.useMemo)(()=>{const M=r.flatMap(f=>f.alerts);return(0,s.groupBy)(M,f=>f.status.state)},[r]);return[(0,e.useMemo)(()=>e.createElement(ae.u,{isOpen:t,onDismiss:i,closeOnBackdropClick:!0,closeOnEscape:!0,title:e.createElement(g.Stack,{direction:"row",alignItems:"center",gap:1,flexGrow:1},e.createElement(g.Stack,{direction:"row",alignItems:"center",gap:.5},e.createElement(se.J,{name:"x"})," Matchers"),e.createElement(At,{matchers:m}))},e.createElement(g.Stack,{direction:"column"},e.createElement(Yt,{active:d[K.Z9.Active]?.length,suppressed:d[K.Z9.Suppressed]?.length,unprocessed:d[K.Z9.Unprocessed]?.length}),e.createElement("div",null,r.map((M,f)=>e.createElement(Ht.y,{key:f,alertManagerSourceName:"",group:M})))),e.createElement(ae.u.ButtonRow,null,e.createElement(V.zx,{type:"button",variant:"secondary",onClick:i},"Cancel"))),[r,i,d,m,t]),u,i]},Ze=({isOpen:t})=>e.createElement(ae.u,{isOpen:t,onDismiss:()=>{},closeOnBackdropClick:!1,closeOnEscape:!1,title:e.createElement(g.Stack,{direction:"row",alignItems:"center",gap:.5},"Updating... ",e.createElement(Zt.$,{inline:!0}))},"Please wait while we update your notification policies.");var hn=n(37802),De=n(51947),yn=n(71698),xe=n(95130),It=n(98699),St=n(77582),bn=n(27050);const Mn={[K._M.equal]:(t,a)=>t===a,[K._M.notEqual]:(t,a)=>t!==a,[K._M.regex]:(t,a)=>Boolean(t.match(new RegExp(a))),[K._M.notRegex]:(t,a)=>!Boolean(t.match(new RegExp(a)))};function An(t,a){const[r,l]=a,[m,o,i]=t;if(r!==m)return!1;const u=Mn[o];if(!u)throw new Error(`no such operator: ${o}`);return u(l,i)}function Cn(t,a){return t.every(r=>a.some(l=>An(r,l)))}function Tt(t,a){let r=[];const l=Oe(t);if(!Cn(l,a))return[];if(t.routes)for(let m=0;m<t.routes.length;m++){let o=t.routes[m],i=Tt(o,a);if(r=r.concat(i),i.length&&!o.continue)break}return r.length===0&&r.push(t),r}function Pn(t,a,r){const l=[];return r.reduce((m,o)=>{const i=o.alerts.filter(u=>{const d=Object.entries(u.labels);return Tt(t,d).some(v=>v===a)});return i.length&&m.push({...o,alerts:i}),m},l)}function In(t,a,r){const l=(0,s.merge)({},t,r),m=(0,s.pick)(l,["receiver","group_by","group_wait","group_interval","repeat_interval","mute_time_intervals"]);return(0,s.reduce)(m,(i={},u,d)=>{const v=u!==void 0&&a[d]===void 0,M=d==="group_by"&&(0,s.isArray)(a[d])&&a[d]?.length===0;return v&&(i[d]=u),M&&(i[d]=u),i},{})}var He=n(46081),Sn=n(9085),Tn=n.n(Sn);const oe=({children:t,icon:a,...r})=>{const l=(0,E.wW)(On),m=typeof r.onClick=="function";return e.createElement("div",{className:Tn()({[l.metaText]:!0,[l.interactive]:m}),...r},e.createElement(g.Stack,{direction:"row",alignItems:"center",gap:.5},a&&e.createElement(se.J,{name:a}),t))},On=t=>({metaText:c.css`
    font-size: ${t.typography.bodySmall.fontSize};
    color: ${t.colors.text.secondary};
  `,interactive:c.css`
    cursor: pointer;

    &:hover {
      color: ${t.colors.text.primary};
    }
  `}),ee=({children:t})=>{const a=(0,E.l4)();return e.createElement("strong",{style:{color:a.colors.text.primary}},t)},Ot=({receivers:t=[],contactPointsState:a,readOnly:r=!1,alertGroups:l=[],alertManagerSourceName:m,currentRoute:o,routeTree:i,inheritedProperties:u,routesMatchingFilters:d=[],onEditPolicy:v,onAddPolicy:M,onDeletePolicy:f,onShowAlertInstances:w})=>{const $=(0,E.wW)(Re),p=o===i,C=(0,hn.Qb)(bn.v.NotificationPoliciesV2MatchingInstances),L=(0,ne.Ko)(m),te=St.Vt.hasPermission(L.update),N=St.Vt.hasPermission(L.delete),W=o.receiver,Y=o.continue??!1,P=o.group_by,I=o.mute_time_intervals??[],A={group_wait:o.group_wait,group_interval:o.group_interval,repeat_interval:o.repeat_interval},Z=Oe(o),ge=Boolean(Z&&Z.length),$e=Boolean(I.length),Ce=d.some(re=>re.id===o.id),Pe=[],Je=!ge&&!p&&!Y,Ye=W??u?.receiver??"";(a?Ln(Ye,a):[]).forEach(re=>{Pe.push(re)});const We=u&&Object.keys(u).length>0,Xe=o.routes??[],qe=We&&u.group_by,Ge=(0,s.isArray)(P)&&P[0]==="...",_e=!Ge&&(0,s.isArray)(P)&&P.length>0,et=p&&(0,s.isArray)(P)&&P.length===0,tt=te,nt=N&&!p,we=(0,e.useMemo)(()=>C?Pn(i,o,l):[],[l,o,i,C]),Ne=(0,s.sumBy)(we,re=>re.alerts.length);return e.createElement(g.Stack,{direction:"column",gap:1.5},e.createElement("div",{className:$.policyWrapper(Ce),"data-testid":p?"am-root-route-container":"am-route-container"},Y&&e.createElement(xn,null),Je&&e.createElement(Rn,null),e.createElement(g.Stack,{direction:"column",gap:0},e.createElement("div",{className:$.matchersRow},e.createElement(g.Stack,{direction:"row",alignItems:"center",gap:1},p?e.createElement($n,null):ge?e.createElement(At,{matchers:Z??[]}):e.createElement("span",{className:$.metadata},"No matchers"),e.createElement(at.L,null),Pe.length>0&&e.createElement(Dn,{errors:Pe}),!r&&e.createElement(g.Stack,{direction:"row",gap:.5},e.createElement(V.zx,{variant:"secondary",icon:"plus",size:"sm",onClick:()=>M(o),type:"button"},"New nested policy"),e.createElement(yn.L,{overlay:e.createElement(xe.v,null,e.createElement(xe.v.Item,{icon:"pen",disabled:!tt,label:"Edit",onClick:()=>v(o,p)}),nt&&e.createElement(e.Fragment,null,e.createElement(xe.v.Divider,null),e.createElement(xe.v.Item,{destructive:!0,icon:"trash-alt",label:"Delete",onClick:()=>f(o)})))},e.createElement(V.zx,{variant:"secondary",size:"sm",icon:"ellipsis-h",type:"button","aria-label":"more-actions","data-testid":"more-actions"}))))),e.createElement("div",{className:$.metadataRow},e.createElement(g.Stack,{direction:"row",alignItems:"center",gap:1},C&&e.createElement(oe,{icon:"layers-alt",onClick:()=>{w(we,Z)},"data-testid":"matching-instances"},e.createElement(ee,null,Ne),e.createElement("span",null,Te()("instance",Ne))),W&&e.createElement(oe,{icon:"at","data-testid":"contact-point"},e.createElement("span",null,"Delivered to"),e.createElement(Nn,{alertManagerSourceName:m,receivers:t,contactPoint:W})),!qe&&e.createElement(e.Fragment,null,_e&&e.createElement(oe,{icon:"layer-group","data-testid":"grouping"},e.createElement("span",null,"Grouped by"),e.createElement(ee,null,P.join(", "))),et&&e.createElement(oe,{icon:"layer-group"},e.createElement("span",null,"Single group")),Ge&&e.createElement(oe,{icon:"layer-group"},e.createElement("span",null,"Not grouping"))),$e&&e.createElement(oe,{icon:"calendar-slash","data-testid":"mute-timings"},e.createElement("span",null,"Muted when"),e.createElement(Wn,{timings:I,alertManagerSourceName:m})),A&&Object.values(A).some(Boolean)&&e.createElement(Gn,{timingOptions:A}),We&&e.createElement(e.Fragment,null,e.createElement(oe,{icon:"corner-down-right-alt","data-testid":"inherited-properties"},e.createElement("span",null,"Inherited"),e.createElement(Bn,{properties:u}))))))),e.createElement("div",{className:$.childPolicies},Xe.map(re=>{const Le=In(o,re,u);return e.createElement(Ot,{key:(0,s.uniqueId)(),routeTree:i,currentRoute:re,receivers:t,contactPointsState:a,readOnly:r,inheritedProperties:Le,onAddPolicy:M,onEditPolicy:v,onDeletePolicy:f,onShowAlertInstances:w,alertManagerSourceName:m,alertGroups:l,routesMatchingFilters:d})})))},Dn=({errors:t})=>e.createElement(ye.z,{arrow:!0,placement:"top",content:e.createElement(g.Stack,{direction:"column",gap:.5},t.map(a=>e.createElement(e.Fragment,{key:(0,s.uniqueId)()},a)))},e.createElement("span",null,e.createElement(he.C,{icon:"exclamation-circle",color:"red",text:Te()("error",t.length,!0)}))),xn=()=>{const t=(0,E.wW)(Re);return e.createElement(fe.u,{placement:"top",content:"This route will continue matching other policies"},e.createElement("div",{className:t.gutterIcon,"data-testid":"continue-matching"},e.createElement(se.J,{name:"arrow-down"})))},Rn=()=>{const t=(0,E.wW)(Re);return e.createElement(fe.u,{placement:"top",content:"This policy matches all labels"},e.createElement("div",{className:t.gutterIcon,"data-testid":"matches-all"},e.createElement(se.J,{name:"exclamation-triangle"})))},$n=()=>{const t=(0,E.wW)(Re);return e.createElement(e.Fragment,null,e.createElement("strong",null,"Default policy"),e.createElement("span",{className:t.metadata},"All alert instances will be handled by the default policy if no other matching policies are found."))},Bn=({properties:t})=>e.createElement(ye.z,{arrow:!0,placement:"top",content:e.createElement(g.Stack,{direction:"row",gap:.5},Object.entries(t).map(([a,r])=>e.createElement(He._,{key:a,label:Fn(a),value:e.createElement(ee,null,Un(a,r))})))},e.createElement("div",null,e.createElement(ee,null,Te()("property",Object.keys(t).length,!0)))),Wn=({timings:t,alertManagerSourceName:a})=>e.createElement("div",null,e.createElement(ee,null,t.map(r=>e.createElement(De.Link,{key:r,to:(0,k.ET)(r,a)},r)))),Gn=({timingOptions:t})=>{const a=t.group_wait??Ae.group_wait,r=t.group_interval??Ae.group_interval;return e.createElement(oe,{icon:"hourglass","data-testid":"timing-options"},e.createElement("span",null,"Wait"),e.createElement(fe.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(ee,null,a)," ",e.createElement("span",null,"to group instances"),",")),e.createElement(fe.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(ee,null,r)," ",e.createElement("span",null,"before sending updates"))))},wn={discord:"discord",email:"envelope",googlechat:"google-hangouts-alt",hipchat:"hipchat",line:"line",pagerduty:"pagerduty",slack:"slack",teams:"microsoft",telegram:"telegram-alt"},Nn=({alertManagerSourceName:t,contactPoint:a,receivers:r})=>{const l=r.find(i=>i.name===a);if(!l)return e.createElement(De.Link,{to:(0,k.GV)(a,t)},e.createElement(ee,null,a));if(!l.grafana_managed_receiver_configs)return e.createElement(De.Link,{to:(0,k.GV)(a,t)},e.createElement(ee,null,a));const o=(0,s.groupBy)(l.grafana_managed_receiver_configs,i=>i.type);return e.createElement(ye.z,{arrow:!0,placement:"top",header:e.createElement(oe,{icon:"at"},e.createElement("div",null,"Contact Point"),e.createElement(ee,null,a)),key:(0,s.uniqueId)(),content:e.createElement(g.Stack,{direction:"row",gap:.5},Object.entries(o).map(([i,u])=>e.createElement(He._,{key:(0,s.uniqueId)(),label:u.length>1?u.length:void 0,icon:wn[i],value:(0,s.upperFirst)(i)})))},e.createElement(De.Link,{to:(0,k.GV)(a,t)},e.createElement(ee,null,a)))};function Ln(t,a){return Object.entries(a[t]?.notifiers??[]).reduce((m=[],[o,i])=>{const u=i.filter(d=>d.lastNotifyAttemptError).map(d=>e.createElement(He._,{icon:"at",key:(0,s.uniqueId)(),label:`Contact Point \u203A ${d.name}`,value:d.lastNotifyAttemptError}));return m.concat(u)},[])}const Fn=t=>{switch(t){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"}},Un=(t,a)=>{const r=t==="group_by"&&Array.isArray(a)&&a[0]==="...",l=t==="group_by"&&Array.isArray(a)&&a.length===0;return r?e.createElement(It.Dr,{variant:"bodySmall",color:"secondary"},"Not grouping"):l?e.createElement(It.Dr,{variant:"bodySmall",color:"secondary"},"Single group"):Array.isArray(a)?a.join(", "):a},Re=t=>({matcher:a=>{const{color:r,borderColor:l}=(0,Mt.Bx)(a);return{wrapper:c.css`
        color: #fff;
        background: ${r};
        padding: ${t.spacing(.33)} ${t.spacing(.66)};
        font-size: ${t.typography.bodySmall.fontSize};

        border: solid 1px ${l};
        border-radius: ${t.shape.borderRadius(2)};
      `}},childPolicies:c.css`
    margin-left: ${t.spacing(4)};
    position: relative;

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

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

      margin-top: 0;
      margin-left: -20px;
    }
  `,metadataRow:c.css`
    background: ${t.colors.background.primary};
    padding: ${t.spacing(1.5)};

    border-bottom-left-radius: ${t.shape.borderRadius(2)};
    border-bottom-right-radius: ${t.shape.borderRadius(2)};
  `,matchersRow:c.css`
    padding: ${t.spacing(1.5)};
    border-bottom: solid 1px ${t.colors.border.weak};
  `,policyWrapper:(a=!1)=>c.css`
    flex: 1;
    position: relative;
    background: ${t.colors.background.secondary};

    border-radius: ${t.shape.borderRadius(2)};
    border: solid 1px ${t.colors.border.weak};

    ${a&&c.css`
      border-color: ${t.colors.primary.border};
    `}
  `,metadata:c.css`
    color: ${t.colors.text.secondary};

    font-size: ${t.typography.bodySmall.fontSize};
    font-weight: ${t.typography.bodySmall.fontWeight};
  `,break:c.css`
    width: 100%;
    height: 0;
    margin-bottom: ${t.spacing(2)};
  `,addPolicyWrapper:a=>c.css`
    margin-top: -${t.spacing(a?1.5:2)};
    margin-bottom: ${t.spacing(1)};
  `,gutterIcon:c.css`
    position: absolute;

    top: 0;
    transform: translateY(50%);
    left: -${t.spacing(4)};

    color: ${t.colors.text.secondary};
    background: ${t.colors.background.primary};

    width: 25px;
    height: 25px;
    text-align: center;

    border: solid 1px ${t.colors.border.weak};
    border-radius: ${t.shape.borderRadius(2)};

    padding: 0;
  `});var Vn=(t=>(t.NotificationPolicies="notification_policies",t.MuteTimings="mute_timings",t))(Vn||{});const zn=()=>{const t=(0,j.useDispatch)(),a=(0,E.wW)(Kn),[r,l]=(0,F.K)(),{tab:m}=jn(r),[o,i]=(0,e.useState)(m),[u,d]=(0,e.useState)(!1),[v,M]=(0,e.useState)(),[f,w]=(0,e.useState)([]),$=(0,yt.k)("notification"),[p,C]=(0,ht.k)($),L=(0,z._)(X=>X.amConfigs),te=(0,G.V)(p??"");(0,e.useEffect)(()=>{p&&t((0,_.Yh)(p))},[p,t]);const{result:N,loading:W,error:Y}=p&&L[p]||le.oq,P=N?.alertmanager_config,I=P?.receivers??[],A=(0,e.useMemo)(()=>{if(P?.route)return gt(P.route)},[P?.route]),Z=(0,e.useMemo)(()=>A?Dt(A,{contactPointFilter:v,labelMatchersFilter:f}):[],[v,f,A]),ge=Boolean(P?.route?.provenance),Ce=(0,z._)(X=>X.amAlertGroups)[p||""]??le.oq;function Pe(X){if(!A)return;const Ie=qt(p??"",X,A);Be(Ie)}function Je(X){if(!A)return;const Ie=_t(X,A);Be(Ie)}function Ye(X,Ie){if(!A)return;const qn=en(p??"",X,Ie,A);Be(qn)}function Be(X){N&&(d(!0),t((0,_.mM)({newConfig:{...N,alertmanager_config:{...N.alertmanager_config,route:X}},oldConfig:N,alertManagerSourceName:p,successMessage:"Updated notification policies",refetch:!0})).unwrap().then(()=>{p&&t((0,_.mS)(p)),et(),qe(),we()}).finally(()=>{d(!1)}))}const[We,Xe,qe]=pn(I,Ye,u),[Ge,_e,et]=En(p??"",I,Pe,u),[tt,nt,we]=vn(Je,u),[Ne,re]=fn();if((0,x.x)(X=>X.unifiedAlerting.saveAMConfig=le.oq),(0,e.useEffect)(()=>{p&&t((0,_.mS)(p))},[p,t]),!p)return e.createElement(q.J,{pageId:"am-routes"},e.createElement(Fe.I,{availableAlertManagers:$}));const Le=(0,it.RY)(p),Qn=Le||ge,Zn=Le,Hn=N?.alertmanager_config.mute_time_intervals?.length??0,Jn=N&&!Y&&!W,Yn=!N&&W,Xn=Y&&!W,xt=o==="mute_timings",Rt=o==="notification_policies";return e.createElement(q.J,{pageId:"am-routes"},e.createElement(J.P,{current:p,onChange:C,dataSources:$}),e.createElement(S.J,null,e.createElement(y.O,{label:"Notification Policies",active:Rt,onChangeTab:()=>{i("notification_policies"),l({tab:"notification_policies"})}}),e.createElement(y.O,{label:"Mute Timings",active:xt,counter:Hn,onChangeTab:()=>{i("mute_timings"),l({tab:"mute_timings"})}})),e.createElement(h.I,{className:a.tabContent},Yn&&e.createElement(D.u,{text:"Loading Alertmanager config..."}),Xn&&e.createElement(B.b,{severity:"error",title:"Error loading Alertmanager config"},Y.message||"Unknown error."),Jn&&e.createElement(e.Fragment,null,Rt&&e.createElement(e.Fragment,null,e.createElement(pe.u,{currentAlertmanager:p}),ge&&e.createElement(Ee.Xq,{resource:Ee.Uv.RootNotificationPolicy}),e.createElement(g.Stack,{direction:"column",gap:1},A&&e.createElement(Kt,{receivers:I,onChangeMatchers:w,onChangeReceiver:M}),A&&e.createElement(Ot,{receivers:I,routeTree:A,currentRoute:A,alertGroups:Ce.result,contactPointsState:te.receivers,readOnly:Qn,alertManagerSourceName:p,onAddPolicy:Xe,onEditPolicy:_e,onDeletePolicy:nt,onShowAlertInstances:re,routesMatchingFilters:Z})),We,Ge,tt,Ne),xt&&e.createElement(Nt,{alertManagerSourceName:p,hideActions:Zn}))))},Dt=(t,a)=>{const{contactPointFilter:r,labelMatchersFilter:l=[]}=a;let m=[];const o=ot(t),i=r?rt(o,d=>d.receiver===r):void 0;i&&m.push(i);const u=l.length?rt(o,d=>{const v=Oe(d);return l.every(M=>v.some(f=>(0,s.isEqual)(M,f)))}):void 0;return u&&m.push(u),(0,s.intersectionBy)(...m,"id")},Kn=t=>({tabContent:c.css`
    margin-top: ${t.spacing(2)};
  `});function jn(t){let a="notification_policies";return t.tab==="notification_policies"&&(a="notification_policies"),t.tab==="mute_timings"&&(a="mute_timings"),{tab:a}}const kn=(0,T.Pf)(zn,{style:"page"})},96678:(H,O,n)=>{n.d(O,{V:()=>E});var c=n(37190),s=n(29427),e=n(644);const g=s.C.injectEndpoints({endpoints:S=>({contactPointsState:S.query({queryFn:async({amSourceName:y})=>{try{return{data:await(0,e.QE)(y)}}catch(h){return{error:h}}}})})}),E=S=>{const y={receivers:{},errorCount:0},{currentData:h}=g.useContactPointsStateQuery({amSourceName:S??""},{skip:!S,pollingInterval:c.m4});return h??y}},51981:(H,O,n)=>{n.d(O,{q:()=>e});var c=n(66111),s=n(82002);const e=({actions:g,children:E,fallback:S=!0})=>g.some(y=>s.Vt.hasAccess(y,S))?c.createElement(c.Fragment,null,E):null},94762:(H,O,n)=>{n.d(O,{F:()=>E});var c=n(9892),s=n(66111),e=n(72648),g=n(53731);const E=({renderExpandedContent:y,...h})=>{const D=(0,e.wW)(S);return s.createElement(g.t,{renderExpandedContent:y?(B,T,F)=>s.createElement(s.Fragment,null,T!==F.length-1&&s.createElement("div",{className:(0,c.cx)(D.contentGuideline,D.guideline)}),y(B,T,F)):void 0,renderPrefixHeader:()=>s.createElement("div",{className:D.relative},s.createElement("div",{className:(0,c.cx)(D.headerGuideline,D.guideline)})),renderPrefixCell:(B,T,F)=>s.createElement("div",{className:D.relative},s.createElement("div",{className:(0,c.cx)(D.topGuideline,D.guideline)}),T!==F.length-1&&s.createElement("div",{className:(0,c.cx)(D.bottomGuideline,D.guideline)})),...h})},S=y=>({relative:c.css`
    position: relative;
    height: 100%;
  `,guideline:c.css`
    left: -19px;
    border-left: 1px solid ${y.colors.border.weak};
    position: absolute;

    ${y.breakpoints.down("md")} {
      display: none;
    }
  `,topGuideline:c.css`
    width: 18px;
    border-bottom: 1px solid ${y.colors.border.medium};
    top: 0;
    bottom: 50%;
  `,bottomGuideline:c.css`
    top: 50%;
    bottom: 0;
  `,contentGuideline:c.css`
    top: 0;
    bottom: 0;
    left: -49px !important;
  `,headerGuideline:c.css`
    top: -17px;
    bottom: 0;
  `})},731:(H,O,n)=>{n.d(O,{u:()=>h});var c=n(9892),s=n(66111),e=n(72648),g=n(45253),E=n(39031),S=n(30173),y=n(45849);function h({currentAlertmanager:B}){const T=(0,e.wW)(D),{useGetAlertmanagerChoiceStatusQuery:F}=S.h,{currentData:j}=F(),x=B===y.GC;if(!(j?.alertmanagersChoice&&[E.TE.External,E.TE.All].includes(j?.alertmanagersChoice))||!x)return null;const J=j.numExternalAlertmanagers>0;return j.alertmanagersChoice===E.TE.External?s.createElement(g.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.",s.createElement("div",{className:T.adminHint},"To change your Alertmanager setup, go to the Alerting Admin page. If you do not have access, contact your Administrator.")):j.alertmanagersChoice===E.TE.All&&J?s.createElement(g.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.",s.createElement("div",{className:T.adminHint},"To change your Alertmanager setup, go to the Alerting Admin page. If you do not have access, contact your Administrator.")):null}const D=B=>({adminHint:c.css`
    font-size: ${B.typography.bodySmall.fontSize};
    font-weight: ${B.typography.bodySmall.fontWeight};
  `})},46081:(H,O,n)=>{n.d(O,{_:()=>S});var c=n(9892),s=n(66111),e=n(26418),g=n(72648),E=n(39904);const S=({label:h,value:D,icon:B})=>{const T=(0,g.wW)(y);return s.createElement("div",{className:T.meta().wrapper},s.createElement(e.Stack,{direction:"row",gap:0,alignItems:"stretch"},s.createElement("div",{className:T.meta().label},s.createElement(e.Stack,{direction:"row",gap:.5,alignItems:"center"},B&&s.createElement(E.J,{name:B})," ",h??"")),s.createElement("div",{className:T.meta().value},D)))},y=h=>({meta:D=>({wrapper:c.css`
      font-size: ${h.typography.bodySmall.fontSize};
    `,label:c.css`
      display: flex;
      align-items: center;

      padding: ${h.spacing(.33)} ${h.spacing(1)};
      background: ${h.colors.secondary.transparent};

      border: solid 1px ${h.colors.border.medium};
      border-top-left-radius: ${h.shape.borderRadius(2)};
      border-bottom-left-radius: ${h.shape.borderRadius(2)};
    `,value:c.css`
      padding: ${h.spacing(.33)} ${h.spacing(1)};
      font-weight: ${h.typography.fontWeightBold};

      border: solid 1px ${h.colors.border.medium};
      border-left: none;
      border-top-right-radius: ${h.shape.borderRadius(2)};
      border-bottom-right-radius: ${h.shape.borderRadius(2)};
    `})})},88331:(H,O,n)=>{n.d(O,{I:()=>y});var c=n(66111),s=n(45253),e=n(29614),g=n(94984);const E=()=>c.createElement(s.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."),S=()=>c.createElement(s.b,{title:"Selected Alertmanager not found. Select a different Alertmanager.",severity:"warning"},"Selected Alertmanager no longer exists or you may not have permission to access it."),y=({availableAlertManagers:h})=>{const[D,B]=(0,e.k)(h),T=h.length>0;return c.createElement("div",null,T?c.createElement(c.Fragment,null,c.createElement(g.P,{onChange:B,dataSources:h}),c.createElement(S,null)):c.createElement(E,null))}},40106:(H,O,n)=>{n.d(O,{C0:()=>S,Uv:()=>g,Xq:()=>E});var c=n(66111),s=n(45253),e=n(19985),g=(y=>(y.ContactPoint="contact point",y.Template="template",y.MuteTiming="mute timing",y.AlertRule="alert rule",y.RootNotificationPolicy="root notification policy",y))(g||{});const E=({resource:y})=>c.createElement(s.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,"."),S=()=>c.createElement(e.C,{text:"Provisioned",color:"purple"})},94647:(H,O,n)=>{n.d(O,{y:()=>ve});var c=n(9892),s=n(66111),e=n(72648),g=n(39031),E=n(52694),S=n(33950),y=n(76282),h=n(94762),D=n(90072),B=n(31403),T=n(82002),F=n(27876),j=n(97953),x=n(45849),G=n(10505),J=n(78543),q=n(51981);const pe=({alert:b,alertManagerSourceName:Q})=>{const z=(0,e.wW)(Fe),_=(0,j.QX)(Q),R=(0,x.HY)(Q)?T.Vt.hasPermission(F.AccessControlAction.AlertingRuleRead):!0;return s.createElement(s.Fragment,null,s.createElement("div",{className:z.actionsRow},s.createElement(q.q,{actions:[_.update,_.create],fallback:T.Vt.isEditor},b.status.state===g.Z9.Suppressed&&s.createElement(B.Qj,{href:`${(0,G.eQ)("/alerting/silences",Q)}&silenceIds=${b.status.silencedBy.join(",")}`,className:z.button,icon:"bell",size:"sm"},"Manage silences"),b.status.state===g.Z9.Active&&s.createElement(B.Qj,{href:(0,G.VN)(Q,b.labels),className:z.button,icon:"bell-slash",size:"sm"},"Silence")),R&&b.generatorURL&&s.createElement(B.Qj,{className:z.button,href:b.generatorURL,icon:"chart-line",size:"sm"},"See source")),Object.entries(b.annotations).map(([k,le])=>s.createElement(J.a,{key:k,annotationKey:k,value:le})),s.createElement("div",{className:z.receivers},"Receivers:"," ",b.receivers.map(({name:k})=>k).filter(k=>!!k).join(", ")))},Fe=b=>({button:c.css`
    & + & {
      margin-left: ${b.spacing(1)};
    }
  `,actionsRow:c.css`
    padding: ${b.spacing(2,0)} !important;
    border-bottom: 1px solid ${b.colors.border.medium};
  `,receivers:c.css`
    padding: ${b.spacing(1,0)};
  `}),Ee=({alerts:b,alertManagerSourceName:Q})=>{const z=(0,e.wW)(V),_=(0,s.useMemo)(()=>[{id:"state",label:"State",renderCell:({data:R})=>s.createElement(s.Fragment,null,s.createElement(D.G,{state:R.status.state}),s.createElement("span",{className:z.duration},"for"," ",(0,y.vT)({start:new Date(R.startsAt),end:new Date(R.endsAt)}))),size:"220px"},{id:"labels",label:"Labels",renderCell:({data:{labels:R}})=>s.createElement(E.s,{labels:R}),size:1}],[z]),ne=(0,s.useMemo)(()=>b.map(R=>({id:R.fingerprint,data:R})),[b]);return s.createElement("div",{className:z.tableWrapper,"data-testid":"alert-group-table"},s.createElement(h.F,{cols:_,items:ne,isExpandable:!0,renderExpandedContent:({data:R})=>s.createElement(pe,{alert:R,alertManagerSourceName:Q})}))},V=b=>({tableWrapper:c.css`
    margin-top: ${b.spacing(3)};
    ${b.breakpoints.up("md")} {
      margin-left: ${b.spacing(4.5)};
    }
  `,duration:c.css`
    margin-left: ${b.spacing(1)};
    font-size: ${b.typography.bodySmall.fontSize};
  `});var Ue=n(96308);const ve=({alertManagerSourceName:b,group:Q})=>{const[z,_]=(0,s.useState)(!0),ne=(0,e.wW)(me);return s.createElement("div",{className:ne.wrapper},s.createElement("div",{className:ne.header},s.createElement("div",{className:ne.group,"data-testid":"alert-group"},s.createElement(S.U,{size:"sm",isCollapsed:z,onToggle:()=>_(!z),"data-testid":"alert-group-collapse-toggle"}),Object.keys(Q.labels).length?s.createElement(E.s,{labels:Q.labels}):s.createElement("span",null,"No grouping")),s.createElement(Ue.Z,{group:Q})),!z&&s.createElement(Ee,{alertManagerSourceName:b,alerts:Q.alerts}))},me=b=>({wrapper:c.css`
    & + & {
      margin-top: ${b.spacing(2)};
    }
  `,header:c.css`
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    padding: ${b.spacing(1,1,1,0)};
    background-color: ${b.colors.background.secondary};
    width: 100%;
  `,group:c.css`
    display: flex;
    flex-direction: row;
    align-items: center;
  `,summary:c.css``,spanElement:c.css`
    margin-left: ${b.spacing(.5)};
  `,[g.Z9.Active]:c.css`
    color: ${b.colors.error.main};
  `,[g.Z9.Suppressed]:c.css`
    color: ${b.colors.primary.main};
  `,[g.Z9.Unprocessed]:c.css`
    color: ${b.colors.secondary.main};
  `})},52259:(H,O,n)=>{n.d(O,{Kt:()=>F,HU:()=>j});var c=n(65583),s=n(54899),e=n(29427);const g=e.C.injectEndpoints({endpoints:x=>({getOnCallIntegrations:x.query({queryFn:async()=>({data:await E()})})})});async function E(){try{return(await(0,c.n)((0,s.i)().fetch({url:"/api/plugin-proxy/grafana-oncall-app/api/internal/v1/alert_receive_channels/",showErrorAlert:!1,showSuccessAlert:!1}))).data.map(G=>G.integration_url)}catch{return[]}}const{useGetOnCallIntegrationsQuery:S}=g;var y=n(58509),h=n(2390);const D=(x,G)=>G.includes(x),B=(x,G)=>{if(!x.grafana_managed_receiver_configs)return!1;const J=x.grafana_managed_receiver_configs.length===1,q=D(x.grafana_managed_receiver_configs[0]?.settings?.url??"",G);return J&&q},T=()=>{const{installed:x}=(0,y.n)(h.W.OnCall),{data:G}=S(void 0,{skip:!x});return q=>{if(x&&B(q,G??[]))return h.W.OnCall}},F=x=>{const G=T(),J=q=>({label:q.name,value:q.name,grafanaAppReceiverType:G(q)});return x.map(J)},j=x=>{const G=T();return x.map(J=>({...J,grafanaAppReceiverType:G(J)}))}},90072:(H,O,n)=>{n.d(O,{G:()=>E});var c=n(66111),s=n(39031),e=n(79453);const g={[s.Z9.Active]:"bad",[s.Z9.Unprocessed]:"neutral",[s.Z9.Suppressed]:"info"},E=({state:S})=>c.createElement(e.i,{state:g[S]},S)},29614:(H,O,n)=>{n.d(O,{k:()=>y});var c=n(66111),s=n(96044),e=n(58379),g=n(37190),E=n(45849);function S(h){return(0,c.useCallback)(D=>h.map(T=>T.name).includes(D),[h])}function y(h){const[D,B]=(0,s.K)(),T=S(h),F=(0,c.useCallback)(G=>{T(G)&&(G===E.GC?(e.Z.delete(g.de),B({[g.c4]:null})):(e.Z.set(g.de,G),B({[g.c4]:G})))},[B,T]),j=D[g.c4];if(j&&typeof j=="string")return T(j)?[j,F]:[void 0,F];const x=e.Z.get(g.de);return x&&typeof x=="string"&&T(x)?(F(x),[x,F]):T(E.GC)?[E.GC,F]:[void 0,F]}},23403:(H,O,n)=>{n.d(O,{k:()=>e});var c=n(66111),s=n(45849);function e(g){return(0,c.useMemo)(()=>(0,s.LE)(g),[g])}},31808:(H,O,n)=>{n.d(O,{j:()=>g});var c=n(66111),s=n(56895),e=n(37932);function g(){const{search:E}=(0,s.TH)(),S=(0,c.useMemo)(()=>new URLSearchParams(E),[E]),y=(0,c.useCallback)((h,D)=>{e.E1.partial(h,D)},[]);return[S,y]}}}]);

//# sourceMappingURL=AlertAmRoutes.a22d5525323501788672.js.map