"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[8648],{83171:(U,b,a)=>{a.r(b),a.d(b,{default:()=>Tt});var n=a(52423),e=a(68404),m=a(72648),p=a(45253),h=a(61744),O=a(53546),E=a(81168),D=a(40014),S=a(94984),W=a(45524),$=a(731),w=a(88331),L=a(40106),g=a(31403),R=a(51981),V=a(97953),Q=a(94270),G=a(24799),Y=a(63619),Z=a(53217),ie=a(29460),we=a(2352),q=a(82897),ce=a(39031),F=a(20194),ye=a(45849),Fe=a(20383);const Ce=(t,r)=>Object.entries(t??{}).reduce((o,[s,i])=>[...o,{name:s,value:i,operator:r?ce._M.regex:ce._M.equal}],[]),Ae=t=>t.value,Ke=t=>(t??[]).map(Ae),Ie={name:"",value:"",operator:ce._M.equal},je=["grafana_folder","alertname"],be=[{label:"grafana_folder",value:"grafana_folder"},{label:"alertname",value:"alertname"},{label:"Disable (...)",value:"..."}],re={id:"",overrideGrouping:!1,groupBy:je,object_matchers:[],routes:[],continue:!1,receiver:"",overrideTimings:!1,groupWaitValue:"",groupIntervalValue:"",repeatIntervalValue:"",muteTimeIntervals:[]},Me=t=>{if(!t)return[re,{}];const r=String(Math.random()),o={[r]:t};if(Object.keys(t).length===0)return[{...re,id:r},o];const s=[];t.routes?.forEach(l=>{const[c,y]=Me(l);s.push(c),Object.assign(o,y)});const i=t.matchers?t.matchers?.map(l=>(0,F.cm)((0,F.tC)(l)))??[]:t.object_matchers?.map(l=>({name:l[0],operator:l[1],value:l[2]}))??[];return[{id:r,object_matchers:[...i,...Ce(t.match,!1),...Ce(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??[],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:s,muteTimeIntervals:t.mute_time_intervals??[]},o]},Te=(t,r,o)=>{const s=o[r.id],{overrideGrouping:i,groupBy:l,overrideTimings:c,groupWaitValue:y,groupIntervalValue:f,repeatIntervalValue:u}=r,C=i&&l?l:[],d=c&&y?y:void 0,T=c&&f?f:void 0,x=c&&u?u:void 0,M={...s??{},continue:r.continue,group_by:C,object_matchers:r.object_matchers.length?r.object_matchers.map(v=>[v.name,v.operator,v.value]):void 0,match:void 0,match_re:void 0,group_wait:d,group_interval:T,repeat_interval:x,routes:r.routes.map(v=>Te(t,v,o)),mute_time_intervals:r.muteTimeIntervals};return t!==ye.GC?(M.matchers=r.object_matchers.map(({name:v,operator:N,value:J})=>`${v}${N}${J}`),M.object_matchers=void 0):M.matchers=void 0,r.receiver&&(M.receiver=r.receiver),(0,q.omitBy)(M,q.isUndefined)},me=t=>({label:t,value:t}),Pe=t=>(t??[]).map(me),Re=t=>t?Ae(t)??"":"",ue=t=>t?Ke(t):[];function X(t){return t.length===0?!0:(0,Fe.wd)(t)||"Invalid duration format. Must be {number}{time_unit}"}var k=a(10505),ee=a(46967),le=a(39904),xe=a(42042),te=a(4528);function ze(){const t=(0,m.wW)(Oe);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(ae,{unit:te.t.seconds,name:"seconds",example:"20s"}),e.createElement(ae,{unit:te.t.minutes,name:"minutes",example:"10m"}),e.createElement(ae,{unit:te.t.hours,name:"hours",example:"4h"}),e.createElement(ae,{unit:te.t.days,name:"days",example:"3d"}),e.createElement(ae,{unit:te.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 ae({unit:t,name:r,example:o}){const s=(0,m.wW)(Oe);return e.createElement(e.Fragment,null,e.createElement("div",{className:s.unit},t),e.createElement("div",null,r),e.createElement("code",null,o))}const Oe=t=>({unit:n.css`
    font-weight: ${t.typography.fontWeightBold};
  `,list:n.css`
    display: grid;
    grid-template-columns: max-content 1fr 2fr;
    gap: ${t.spacing(1,3)};
  `,header:n.css`
    display: contents;
    font-weight: ${t.typography.fontWeightBold};
  `,examples:n.css`
    display: contents;
    & > div {
      grid-column: 1 / span 2;
    }
  `}),H=e.forwardRef((t,r)=>e.createElement(ee.I,{suffix:e.createElement(xe.z,{content:e.createElement(ze,null),disabled:!1},e.createElement(le.J,{name:"info-circle",size:"lg"})),...t,ref:r}));H.displayName="PromDurationInput";const De=t=>({container:n.css`
      align-items: center;
      display: flex;
      flex-flow: row nowrap;

      & > * + * {
        margin-left: ${t.spacing(1)};
      }
    `,input:n.css`
      flex: 1;
    `,promDurationInput:n.css`
      max-width: ${t.spacing(32)};
    `,timingFormContainer:n.css`
      padding: ${t.spacing(1)};
    `,linkText:n.css`
      text-decoration: underline;
    `,collapse:n.css`
      border: none;
      background: none;
      color: ${t.colors.text.primary};
    `}),de={group_wait:"30s",group_interval:"5m",repeat_interval:"4h"},Je=({alertManagerSourceName:t,onCancel:r,onSave:o,receivers:s,routes:i})=>{const l=(0,m.wW)(De),[c,y]=(0,e.useState)(!1),[f,u]=(0,e.useState)(Pe(i.groupBy));return e.createElement(Q.l,{defaultValues:{...i,overrideTimings:!0,overrideGrouping:!0},onSubmit:o},({register:C,control:A,errors:d,setValue:B})=>e.createElement(e.Fragment,null,e.createElement(G.g,{label:"Default contact point",invalid:!!d.receiver,error:d.receiver?.message},e.createElement(e.Fragment,null,e.createElement("div",{className:l.container,"data-testid":"am-receiver-select"},e.createElement(Y.g,{render:({field:{onChange:T,ref:P,...x}})=>e.createElement(Z.Ph,{"aria-label":"Default contact point",...x,className:l.input,onChange:M=>T(Re(M)),options:s}),control:A,name:"receiver",rules:{required:{value:!0,message:"Required."}}}),e.createElement("span",null,"or"),e.createElement(ie.r,{className:l.linkText,href:(0,k.eQ)("/alerting/notifications/receivers/new",t)},"Create a contact point")))),e.createElement(G.g,{label:"Group by",description:"Group alerts when you receive a notification based on labels.","data-testid":"am-group-select"},e.createElement(Y.g,{render:({field:{onChange:T,ref:P,...x}})=>e.createElement(Z.NU,{"aria-label":"Group by",...x,allowCustomValue:!0,className:l.input,onCreateOption:M=>{u(v=>[...v,me(M)]),B("groupBy",[...x.value,M])},onChange:M=>T(ue(M)),options:[...be,...f]}),control:A,name:"groupBy"})),e.createElement(we.U,{collapsible:!0,className:l.collapse,isOpen:c,label:"Timing options",onToggle:y},e.createElement("div",{className:l.timingFormContainer},e.createElement(G.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:!!d.groupWaitValue,error:d.groupWaitValue?.message,"data-testid":"am-group-wait"},e.createElement(H,{...C("groupWaitValue",{validate:X}),placeholder:de.group_wait,className:l.promDurationInput,"aria-label":"Group wait"})),e.createElement(G.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:!!d.groupIntervalValue,error:d.groupIntervalValue?.message,"data-testid":"am-group-interval"},e.createElement(H,{...C("groupIntervalValue",{validate:X}),placeholder:de.group_interval,className:l.promDurationInput,"aria-label":"Group interval"})),e.createElement(G.g,{label:"Repeat interval",description:"The waiting time to resend an alert after they have successfully been sent. Default 4 hours.",invalid:!!d.repeatIntervalValue,error:d.repeatIntervalValue?.message,"data-testid":"am-repeat-interval"},e.createElement(H,{...C("repeatIntervalValue",{validate:X}),placeholder:de.repeat_interval,className:l.promDurationInput,"aria-label":"Repeat interval"})))),e.createElement("div",{className:l.container},e.createElement(g.zx,{type:"submit"},"Save"),e.createElement(g.zx,{onClick:r,type:"reset",variant:"secondary",fill:"outline"},"Cancel"))))},We=t=>({container:n.css`
      display: grid;
      font-style: ${t.typography.fontSize};
      grid-template-columns: ${t.spacing(15.5)} auto;

      ${t.breakpoints.down("md")} {
        grid-template-columns: 100%;
      }
    `,titleCell:n.css`
      color: ${t.colors.text.primary};
    `,valueCell:n.css`
      color: ${t.colors.text.secondary};
      margin-bottom: ${t.spacing(1)};
    `}),Qe=({routes:t})=>{const r=(0,m.wW)(We),o=t.receiver||"-",s=t.groupBy.join(", ")||"-",i=t.groupWaitValue||"-",l=t.groupIntervalValue||"-",c=t.repeatIntervalValue||"-";return e.createElement("div",{className:r.container},e.createElement("div",{className:r.titleCell},"Contact point"),e.createElement("div",{className:r.valueCell,"data-testid":"am-routes-root-receiver"},o),e.createElement("div",{className:r.titleCell},"Group by"),e.createElement("div",{className:r.valueCell,"data-testid":"am-routes-root-group-by"},s),e.createElement("div",{className:r.titleCell},"Timings"),e.createElement("div",{className:r.valueCell,"data-testid":"am-routes-root-timings"},"Group wait: ",i," | Group interval: ",l," | Repeat interval: ",c))},He=({isEditMode:t,onSave:r,onEnterEditMode:o,onExitEditMode:s,receivers:i,routes:l,alertManagerSourceName:c,readOnly:y=!1})=>{const f=(0,m.wW)(Ye),u=(0,V.Ko)(c);return e.createElement("div",{className:f.container,"data-testid":"am-root-route-container"},e.createElement("div",{className:f.titleContainer},e.createElement("h5",{className:f.title},"Root policy - ",e.createElement("i",null,"default for all alerts")),!t&&!y&&e.createElement(R.q,{actions:[u.update]},e.createElement(g.zx,{icon:"pen",onClick:o,size:"sm",type:"button",variant:"secondary"},"Edit"))),e.createElement("p",null,"All alerts will go to the default contact point, unless you set additional matchers in the specific routing area."),t?e.createElement(Je,{alertManagerSourceName:c,onCancel:s,onSave:r,receivers:i,routes:l}):e.createElement(Qe,{routes:l}))},Ye=t=>({container:n.css`
      background-color: ${t.colors.background.secondary};
      color: ${t.colors.text.secondary};
      padding: ${t.spacing(2)};
    `,titleContainer:n.css`
      color: ${t.colors.text.primary};
      display: flex;
      flex-flow: row nowrap;
    `,title:n.css`
      flex: 100%;
    `});var Ze=a(70197),Be=a(64353),_=a(82002),Xe=a(31808);const oe=({children:t})=>{const r=(0,m.wW)(ke);return e.createElement("div",{className:r.container},t)},ke=t=>({container:n.css`
      background-color: ${t.colors.background.secondary};
      color: ${t.colors.text.secondary};
      padding: ${t.spacing(4)};
      text-align: center;
    `}),ge=({buttonIcon:t,buttonLabel:r,buttonSize:o="lg",buttonVariant:s="primary",onButtonClick:i,text:l,href:c,showButton:y=!0})=>{const f=(0,m.wW)(_e),u={className:f.button,icon:t,size:o,variant:s};return e.createElement(oe,null,e.createElement(e.Fragment,null,e.createElement("p",{className:f.text},l),y&&(c?e.createElement(g.Qj,{href:c,type:"button",...u},r):e.createElement(g.zx,{onClick:i,type:"button",...u},r))))},_e=t=>({container:n.css`
      background-color: ${t.colors.background.secondary};
      color: ${t.colors.text.secondary};
      padding: ${t.spacing(4)};
      text-align: center;
    `,text:n.css`
      margin-bottom: ${t.spacing(2)};
    `,button:n.css`
      margin: ${t.spacing(2,0,1)};
    `});var pe=a(52081),ne=a(8180),Se=a(98102);const qe=(t,r)=>t.map((o,s)=>({id:r?.(o)??s,data:o}));var Ne=a(53731),et=a(44479),tt=a(99631),at=a(70132),nt=a(19985),ve=a(8944),se=a(46818),Ge=a(29614),$e=a(23403),Ee=a(69945);function rt(){const t=(0,$e.k)("notification"),[r]=(0,Ge.k)(t),o=(0,Ee._)(s=>s.amConfigs);return(0,e.useMemo)(()=>{const{result:s}=r&&o[r]||se.oq;return(s?.alertmanager_config??{})?.mute_time_intervals?.map(c=>({value:c.name,label:c.name,description:c.time_intervals.map(y=>(0,F.uK)(y)).join(", AND ")}))??[]},[r,o])}var lt=a(2390);const ot=({onCancel:t,onSave:r,receivers:o,routes:s})=>{const i=(0,m.wW)(st),l=(0,m.wW)(De),[c,y]=(0,e.useState)(Pe(s.groupBy)),f=rt(),u=o.sort((C,A)=>C.grafanaAppReceiverType===lt.W.OnCall?-1:0);return e.createElement(Q.l,{defaultValues:s,onSubmit:r},({control:C,register:A,errors:d,setValue:B,watch:T})=>e.createElement(e.Fragment,null,e.createElement("input",{type:"hidden",...A("id")}),e.createElement(at.F,{name:"object_matchers",control:C},({fields:P,append:x,remove:M})=>e.createElement(e.Fragment,null,e.createElement(pe.wc,{justify:"flex-start",spacing:"md"},e.createElement("div",null,"Matching labels"),P.length===0&&e.createElement(nt.C,{color:"orange",className:i.noMatchersWarning,icon:"exclamation-triangle",text:"If no matchers are specified, this notification policy will handle all alert instances."}),P.length>0&&e.createElement("div",{className:i.matchersContainer},P.map((v,N)=>e.createElement(pe.Lh,{key:v.id,align:"flex-start",height:"auto"},e.createElement(G.g,{label:"Label",invalid:!!d.object_matchers?.[N]?.name,error:d.object_matchers?.[N]?.name?.message},e.createElement(ee.I,{...A(`object_matchers.${N}.name`,{required:"Field is required"}),defaultValue:v.name,placeholder:"label"})),e.createElement(G.g,{label:"Operator"},e.createElement(Y.g,{render:({field:{onChange:J,ref:K,...j}})=>e.createElement(Z.Ph,{...j,className:i.matchersOperator,onChange:I=>J(I?.value),options:F.tA,"aria-label":"Operator"}),defaultValue:v.operator,control:C,name:`object_matchers.${N}.operator`,rules:{required:{value:!0,message:"Required."}}})),e.createElement(G.g,{label:"Value",invalid:!!d.object_matchers?.[N]?.value,error:d.object_matchers?.[N]?.value?.message},e.createElement(ee.I,{...A(`object_matchers.${N}.value`,{required:"Field is required"}),defaultValue:v.value,placeholder:"value"})),e.createElement(ne.h,{className:i.removeButton,tooltip:"Remove matcher",name:"trash-alt",onClick:()=>M(N)},"Remove")))),e.createElement(g.zx,{className:i.addMatcherBtn,icon:"plus",onClick:()=>x(Ie),variant:"secondary",type:"button"},"Add matcher")))),e.createElement(G.g,{label:"Contact point"},e.createElement(Y.g,{render:({field:{onChange:P,ref:x,...M}})=>e.createElement(Z.Ph,{"aria-label":"Contact point",...M,className:l.input,onChange:v=>P(Re(v)),options:u}),control:C,name:"receiver"})),e.createElement(G.g,{label:"Continue matching subsequent sibling nodes"},e.createElement(ve.r,{id:"continue-toggle",...A("continue")})),e.createElement(G.g,{label:"Override grouping"},e.createElement(ve.r,{id:"override-grouping-toggle",...A("overrideGrouping")})),T().overrideGrouping&&e.createElement(G.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(Y.g,{render:({field:{onChange:P,ref:x,...M}})=>e.createElement(Z.NU,{"aria-label":"Group by",...M,allowCustomValue:!0,className:l.input,onCreateOption:v=>{y(N=>[...N,me(v)]),B("groupBy",[...M.value,v])},onChange:v=>P(ue(v)),options:[...be,...c]}),control:C,name:"groupBy"})),e.createElement(G.g,{label:"Override general timings"},e.createElement(ve.r,{id:"override-timings-toggle",...A("overrideTimings")})),T().overrideTimings&&e.createElement(e.Fragment,null,e.createElement(G.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:!!d.groupWaitValue,error:d.groupWaitValue?.message},e.createElement(H,{...A("groupWaitValue",{validate:X}),"aria-label":"Group wait value",className:l.promDurationInput})),e.createElement(G.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:!!d.groupIntervalValue,error:d.groupIntervalValue?.message},e.createElement(H,{...A("groupIntervalValue",{validate:X}),"aria-label":"Group interval value",className:l.promDurationInput})),e.createElement(G.g,{label:"Repeat interval",description:"The waiting time to resend an alert after they have successfully been sent.",invalid:!!d.repeatIntervalValue,error:d.repeatIntervalValue?.message},e.createElement(H,{...A("repeatIntervalValue",{validate:X}),"aria-label":"Repeat interval value",className:l.promDurationInput}))),e.createElement(G.g,{label:"Mute timings","data-testid":"am-mute-timing-select",description:"Add mute timing to policy",invalid:!!d.muteTimeIntervals},e.createElement(Y.g,{render:({field:{onChange:P,ref:x,...M}})=>e.createElement(Z.NU,{"aria-label":"Mute timings",...M,className:l.input,onChange:v=>P(ue(v)),options:f}),control:C,name:"muteTimeIntervals"})),e.createElement("div",{className:i.buttonGroup},e.createElement(g.zx,{type:"submit"},"Save policy"),e.createElement(g.zx,{onClick:t,fill:"outline",type:"button",variant:"secondary"},"Cancel"))))},st=t=>{const r=t.spacing(3.5);return{addMatcherBtn:n.css`
      margin-bottom: ${r};
    `,matchersContainer:n.css`
      background-color: ${t.colors.background.secondary};
      margin: ${t.spacing(1,0)};
      padding: ${t.spacing(1,4.6,1,1.5)};
      width: fit-content;
    `,matchersOperator:n.css`
      min-width: 140px;
    `,nestedPolicies:n.css`
      margin-top: ${r};
    `,removeButton:n.css`
      margin-left: ${t.spacing(1)};
      margin-top: ${t.spacing(2.5)};
    `,buttonGroup:n.css`
      margin: ${t.spacing(6)} 0 ${r};

      & > * + * {
        margin-left: ${t.spacing(1.5)};
      }
    `,noMatchersWarning:n.css`
      padding: ${t.spacing(1)} ${t.spacing(2)};
    `}};var fe=a(72004);const Le=({alertManagerSourceName:t,muteTimingNames:r,hideActions:o})=>{const s=(0,m.wW)(mt),i=(0,E.useDispatch)(),l=(0,V.Ko)(t),c=(0,Ee._)(d=>d.amConfigs),[y,f]=(0,e.useState)(""),{result:u}=t&&c[t]||se.oq,C=(0,e.useMemo)(()=>{const d=u?.alertmanager_config?.mute_time_intervals??[],B=u?.alertmanager_config?.muteTimeProvenances??{};return d.filter(({name:T})=>r?r.includes(T):!0).map(T=>({id:T.name,data:{...T,provenance:B[T.name]}}))},[u?.alertmanager_config?.mute_time_intervals,u?.alertmanager_config?.muteTimeProvenances,r]),A=it(t,o,f);return e.createElement("div",{className:s.container},!o&&e.createElement("h5",null,"Mute timings"),!o&&e.createElement("p",null,"Mute timings are a named interval of time that may be referenced in the notification policy tree to mute particular notification policies for specific times of the day."),!o&&C.length>0&&e.createElement(R.q,{actions:[l.create]},e.createElement(g.Qj,{className:s.addMuteButton,icon:"plus",variant:"primary",href:(0,k.eQ)("alerting/routes/mute-timing/new",t)},"Add mute timing")),C.length>0?e.createElement(Ne.t,{items:C,cols:A}):o?e.createElement("p",null,"No mute timings configured"):e.createElement(ge,{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:_.Vt.hasPermission(l.create)}),!o&&e.createElement(Se.s,{isOpen:!!y,title:"Delete mute timing",body:`Are you sure you would like to delete "${y}"`,confirmText:"Delete",onConfirm:()=>i((0,fe.r0)(t,y)),onDismiss:()=>f("")}))};function it(t,r=!1,o){const s=(0,V.Ko)(t),i=_.Vt.hasPermission(s.update),l=_.Vt.hasPermission(s.delete),c=!r&&(i||l);return(0,e.useMemo)(()=>{const y=[{id:"name",label:"Name",renderCell:function({data:u}){return e.createElement(e.Fragment,null,u.name," ",u.provenance&&e.createElement(L.C0,null))},size:"250px"},{id:"timeRange",label:"Time range",renderCell:({data:f})=>ct(f.time_intervals)}];return c&&y.push({id:"actions",label:"Actions",renderCell:function({data:u}){return u.provenance?e.createElement("div",null,e.createElement(ie.r,{href:(0,k.eQ)("/alerting/routes/mute-timing/edit",t,{muteName:u.name})},e.createElement(ne.h,{name:"file-alt",title:"View mute timing"}))):e.createElement("div",null,e.createElement(R.q,{actions:[s.update]},e.createElement(ie.r,{href:(0,k.eQ)("/alerting/routes/mute-timing/edit",t,{muteName:u.name})},e.createElement(ne.h,{name:"edit",title:"Edit mute timing"}))),e.createElement(R.q,{actions:[s.delete]},e.createElement(ne.h,{name:"trash-alt",title:"Delete mute timing",onClick:()=>o(u.name)})))},size:"100px"}),y},[t,o,c,s])}function ct(t){return t.map((r,o)=>{const{times:s,weekdays:i,days_of_month:l,months:c,years:y}=r,f=(0,F.u6)(s),u=(0,F.v7)(i),C=(0,F.J8)(l),A=(0,F.m8)(c),d=(0,F.qw)(y);return e.createElement(e.Fragment,{key:JSON.stringify(r)+o},`${f} ${u}`,e.createElement("br",null),[C,A,d].join(" | "),e.createElement("br",null))})}const mt=t=>({container:n.css`
    display: flex;
    flex-flow: column nowrap;
  `,addMuteButton:n.css`
    margin-bottom: ${t.spacing(2)};
    align-self: flex-end;
  `}),ut=({onChange:t,receivers:r,routes:o,readOnly:s=!1,alertManagerSourceName:i})=>{const l=(0,m.wW)(dt),c=(0,m.wW)(We),y=(0,V.Ko)(i),f=o.groupWaitValue??"-",u=o.groupIntervalValue??"-",C=o.repeatIntervalValue??"-",[A,d]=(0,e.useState)(o.routes),[B,T]=(0,e.useState)(!1);return e.createElement("div",{className:c.container},e.createElement("div",{className:c.titleCell},"Group wait"),e.createElement("div",{className:c.valueCell},f),e.createElement("div",{className:c.titleCell},"Group interval"),e.createElement("div",{className:c.valueCell},u),e.createElement("div",{className:c.titleCell},"Repeat interval"),e.createElement("div",{className:c.valueCell},C),e.createElement("div",{className:c.titleCell},"Nested policies"),e.createElement("div",{className:c.valueCell},A.length?e.createElement(Ue,{isAddMode:B,onCancelAdd:()=>{T(!1),d(P=>{const x=[...P];return x.pop(),x})},onChange:P=>{t({...o,routes:P}),B&&T(!1)},receivers:r,routes:A,alertManagerSourceName:i}):e.createElement("p",null,"No nested policies configured."),!B&&!s&&e.createElement(R.q,{actions:[y.create]},e.createElement(g.zx,{className:l.addNestedRoutingBtn,icon:"plus",onClick:()=>{d(P=>[...P,re]),T(!0)},variant:"secondary",type:"button"},"Add nested policy"))),e.createElement("div",{className:c.titleCell},"Mute timings"),e.createElement("div",{className:c.valueCell},e.createElement(Le,{alertManagerSourceName:i,muteTimingNames:o.muteTimeIntervals,hideActions:!0})))},dt=t=>({addNestedRoutingBtn:n.css`
      margin-top: ${t.spacing(2)};
    `}),gt=(t,r,o)=>{const s=(0,F.Zh)(r??"");let i=t;return s.length&&(i=t.filter(l=>{const c=l.object_matchers.map(F._J);return(0,q.differenceWith)(s,c,q.isEqual).length===0})),o&&o.length>0&&(i=i.filter(l=>l.receiver.toLowerCase().includes(o.toLowerCase()))),i},Ve=(t,r)=>{const o=[...t],s=o.findIndex(i=>i.id===r.id);return s>=0&&(o[s]={...o[s],...r}),o},pt=(t,r)=>t.filter(o=>o.id!==r),vt=(t,r)=>t.find(o=>o.label===r)?.grafanaAppReceiverType,Ue=({isAddMode:t,onCancelAdd:r,onChange:o,receivers:s,routes:i,filters:l,readOnly:c=!1,alertManagerSourceName:y})=>{const[f,u]=(0,e.useState)(!1),[C,A]=(0,e.useState)(void 0),[d,B]=(0,e.useState)(),T=(0,V.Ko)(y),P=_.Vt.hasPermission(T.update),x=_.Vt.hasPermission(T.delete),M=!c&&(P||x),v=(0,e.useCallback)(I=>B(I.id),[]),N=(0,e.useCallback)(()=>B(void 0),[]),J=[{id:"matchingCriteria",label:"Matching labels",renderCell:I=>I.data.object_matchers.length?e.createElement(tt.g,{matchers:I.data.object_matchers.map(F._J)}):e.createElement("span",null,"Matches all alert instances"),size:10},{id:"groupBy",label:"Group by",renderCell:I=>I.data.overrideGrouping&&I.data.groupBy.join(", ")||"-",size:5},{id:"receiverChannel",label:"Contact point",renderCell:I=>{const z=vt(s,I.data.receiver);return I.data.receiver?e.createElement(e.Fragment,null,I.data.receiver," ",z&&e.createElement(et.i,{grafanaAppType:z})):"-"},size:5},{id:"muteTimings",label:"Mute timings",renderCell:I=>I.data.muteTimeIntervals.join(", ")||"-",size:5},...M?[{id:"actions",label:"Actions",renderCell:I=>{if(I.renderExpandedContent)return null;const z=()=>{v(I),u(!0)};return e.createElement(e.Fragment,null,e.createElement(pe.Lh,null,e.createElement(g.zx,{"aria-label":"Edit route",icon:"pen",onClick:z,size:"sm",type:"button",variant:"secondary"},"Edit"),e.createElement(ne.h,{"aria-label":"Delete route",name:"trash-alt",onClick:()=>{A(I.data.id)},type:"button"})))},size:"100px"}]:[]],K=(0,e.useMemo)(()=>gt(i,l?.queryString,l?.contactPoint),[i,l]),j=(0,e.useMemo)(()=>qe(t?i:K),[t,i,K]);return(0,e.useEffect)(()=>{t&&j.length&&B(j[j.length-1].id),!t&&j.length&&B(void 0)},[t,j]),i.length>0&&K.length===0?e.createElement(oe,null,e.createElement("p",null,"No policies found")):e.createElement(e.Fragment,null,e.createElement(Ne.t,{cols:J,isExpandable:!0,items:j,testIdGenerator:()=>"am-routes-row",onCollapse:N,onExpand:v,isExpanded:I=>d===I.id,renderExpandedContent:I=>t||f?e.createElement(ot,{onCancel:()=>{t&&r(),u(!1)},onSave:z=>{const he=Ve(i,z);u(!1),o(he)},receivers:s,routes:I.data}):e.createElement(ut,{onChange:z=>{const he=Ve(i,z);o(he)},receivers:s,routes:I.data,readOnly:c,alertManagerSourceName:y})}),e.createElement(Se.s,{isOpen:!!C,title:"Delete notification policy",body:"Deleting this notification policy will permanently remove it. Are you sure you want to delete this policy?",confirmText:"Yes, delete",icon:"exclamation-triangle",onConfirm:()=>{if(C){const I=pt(i,C);o(I),A(void 0)}},onDismiss:()=>A(void 0)}))};var Et=a(26418),ft=a(54408),ht=a(41904);const yt=({className:t,onFilterChange:r,defaultQueryString:o})=>{const s=(0,m.wW)(Ct),i=(0,e.useMemo)(()=>(0,q.debounce)(c=>{(0,ft.PN)(ht.z7.filterPoliciesByMatchers),r(c.target.value)},600),[r]);(0,e.useEffect)(()=>i.cancel(),[i]);const l=e.createElement(le.J,{name:"search"});return e.createElement("div",{className:t},e.createElement(Be._,null,e.createElement(Et.Stack,{gap:.5},e.createElement("span",null,"Search by matcher"),e.createElement(xe.z,{content:e.createElement("div",{className:s.hoverContent},"Filter notification policies by ",e.createElement("span",{className:s.bold},"matchers"),e.createElement("div",{className:s.textBlock},"Notification policies are characterized by labels matchers rathen than labels. ",e.createElement("br",null),"Filtering by matchers means we compare if matchers are equal contrary to checking if a label matches a matcher."),e.createElement("div",{className:s.textBlock},"According to that, e.g. ",e.createElement("code",null,"severity=critical")," equals only ",e.createElement("code",null,"severity=critical"),e.createElement("br",null),"and ",e.createElement("span",{className:s.bold},"is not equal")," ",e.createElement("code",null,"severity=~critical"),e.createElement("br",null),"This is an important distinction from how filtering of alert rules works"),e.createElement("hr",null),"Filter policies using matchers querying, e.g.:",e.createElement("pre",null,'{severity="critical", instance=~"cluster-us-.+"}'))},e.createElement(le.J,{className:s.icon,name:"info-circle",size:"sm"})))),e.createElement(ee.I,{placeholder:"Search",defaultValue:o,onChange:i,"data-testid":"search-query-input",prefix:l,className:s.inputWidth}))},Ct=t=>({icon:n.css`
    margin-right: ${t.spacing(.5)};
  `,inputWidth:n.css`
    width: 340px;
    flex-grow: 0;
  `,bold:n.css`
    font-weight: ${t.typography.fontWeightBold};
  `,textBlock:n.css`
    padding: ${t.spacing(1,0)};
  `,hoverContent:n.css`
    max-width: 600px;
  `}),At=({alertManagerSourceName:t,onChange:r,onRootRouteEdit:o,receivers:s,routes:i,readOnly:l=!1})=>{const[c,y]=(0,e.useState)([...i.routes]),[f,u]=(0,e.useState)(!1),C=(0,V.Ko)(t),A=_.Vt.hasPermission(C.create),[d,B]=(0,Xe.j)(),{queryString:T,contactPoint:P}=(0,k.$f)(d),[x,M]=(0,e.useState)({queryString:T,contactPoint:P});(0,Ze.Z)(()=>{B({queryString:x.queryString,contactPoint:x.contactPoint})},400,[x]);const v=(0,m.wW)(It),N=()=>{M({queryString:void 0,contactPoint:void 0}),B({queryString:void 0,contactPoint:void 0})},J=()=>{N(),u(!0),y(()=>[...i.routes,{...re,matchers:[Ie]}])},K=()=>{u(!1),y([...i.routes])},j=I=>{r({...i,routes:I}),f&&u(!1)};return e.createElement("div",{className:v.container},e.createElement("h5",null,"Specific routing"),e.createElement("p",null,"Send specific alerts to chosen contact points, based on matching criteria"),i.receiver?c.length>0?e.createElement(e.Fragment,null,e.createElement("div",null,!f&&e.createElement("div",{className:v.searchContainer},e.createElement(yt,{onFilterChange:I=>M(z=>({...z,queryString:I})),defaultQueryString:x.queryString??"",className:v.filterInput}),e.createElement("div",{className:v.filterInput},e.createElement(Be._,null,"Search by contact point"),e.createElement(ee.I,{onChange:({currentTarget:I})=>M(z=>({...z,contactPoint:I.value})),value:x.contactPoint??"",placeholder:"Search by contact point","data-testid":"search-query-input",prefix:e.createElement(le.J,{name:"search"})})),(T||P)&&e.createElement(g.zx,{variant:"secondary",icon:"times",onClick:N,className:v.clearFilterBtn},"Clear filters")),!f&&!l&&e.createElement(R.q,{actions:[C.create]},e.createElement("div",{className:v.addMatcherBtnRow},e.createElement(g.zx,{className:v.addMatcherBtn,icon:"plus",onClick:J,type:"button"},"Add policy")))),e.createElement(Ue,{isAddMode:f,readOnly:l,onCancelAdd:K,onChange:j,receivers:s,routes:c,filters:{queryString:T,contactPoint:P},alertManagerSourceName:t})):l?e.createElement(oe,null,e.createElement("p",null,"There are no specific policies configured.")):e.createElement(ge,{buttonIcon:"plus",buttonLabel:"New specific policy",onButtonClick:J,text:"You haven't created any specific policies yet.",showButton:A}):l?e.createElement(oe,null,e.createElement("p",null,"There is no default contact point configured for the root route.")):e.createElement(ge,{buttonIcon:"rocket",buttonLabel:"Set a default contact point",onButtonClick:o,text:"You haven't set a default contact point for the root route yet.",showButton:A}))},It=t=>({container:n.css`
      display: flex;
      flex-flow: column wrap;
    `,searchContainer:n.css`
      display: flex;
      flex-flow: row nowrap;
      padding-bottom: ${t.spacing(2)};
      border-bottom: 1px solid ${t.colors.border.strong};
    `,clearFilterBtn:n.css`
      align-self: flex-end;
      margin-left: ${t.spacing(1)};
    `,filterInput:n.css`
      width: 340px;
      & + & {
        margin-left: ${t.spacing(1)};
      }
    `,addMatcherBtnRow:n.css`
      display: flex;
      flex-flow: column nowrap;
      padding: ${t.spacing(2)} 0;
    `,addMatcherBtn:n.css`
      align-self: flex-end;
    `});var bt=a(52259);const Mt=()=>{const t=(0,E.useDispatch)(),r=(0,m.wW)(Pt),[o,s]=(0,e.useState)(!1),i=(0,$e.k)("notification"),[l,c]=(0,Ge.k)(i),y=(0,Ee._)(K=>K.amConfigs),f=(0,e.useCallback)(()=>{l&&t((0,fe.Yh)(l))},[l,t]);(0,e.useEffect)(()=>{f()},[f]);const{result:u,loading:C,error:A}=l&&y[l]||se.oq,d=u?.alertmanager_config,[B,T]=(0,e.useMemo)(()=>Me(d?.route),[d?.route]),P=(0,bt.Kt)(d?.receivers??[]),x=(0,e.useMemo)(()=>Boolean(d?.route?.provenance),[d?.route]),M=()=>{s(!0)},v=()=>{s(!1)};(0,D.x)(K=>K.unifiedAlerting.saveAMConfig=se.oq);const N=K=>{if(!u)return;const j=Te(l,{...B,...K},T);o&&v(),t((0,fe.mM)({newConfig:{...u,alertmanager_config:{...u.alertmanager_config,route:j}},oldConfig:u,alertManagerSourceName:l,successMessage:"Saved",refetch:!0}))};if(!l)return e.createElement(W.J,{pageId:"am-routes"},e.createElement(w.I,{availableAlertManagers:i}));const J=l?(0,ye.RY)(l)||x:!0;return e.createElement(W.J,{pageId:"am-routes"},e.createElement(S.P,{current:l,onChange:c,dataSources:i}),A&&!C&&e.createElement(p.b,{severity:"error",title:"Error loading Alertmanager config"},A.message||"Unknown error."),e.createElement($.u,{currentAlertmanager:l}),x&&e.createElement(L.Xq,{resource:L.Uv.RootNotificationPolicy}),C&&e.createElement(h.u,{text:"Loading Alertmanager config..."}),u&&!C&&!A&&e.createElement(e.Fragment,null,e.createElement(He,{readOnly:J,alertManagerSourceName:l,isEditMode:o,onSave:N,onEnterEditMode:M,onExitEditMode:v,receivers:P,routes:B}),e.createElement("div",{className:r.break}),e.createElement(At,{alertManagerSourceName:l,onChange:N,readOnly:J,onRootRouteEdit:M,receivers:P,routes:B}),e.createElement("div",{className:r.break}),e.createElement(Le,{alertManagerSourceName:l})))},Tt=(0,O.Pf)(Mt,{style:"page"}),Pt=t=>({break:n.css`
    width: 100%;
    height: 0;
    margin-bottom: ${t.spacing(2)};
  `})},30173:(U,b,a)=>{a.d(b,{h:()=>e});var n=a(29427);const e=n.C.injectEndpoints({endpoints:m=>({getAlertmanagerChoiceStatus:m.query({query:()=>({url:"/api/v1/ngalert"}),providesTags:["AlertmanagerChoice"]}),getExternalAlertmanagerConfig:m.query({query:()=>({url:"/api/v1/ngalert/admin_config"}),providesTags:["AlertmanagerChoice"]}),getExternalAlertmanagers:m.query({query:()=>({url:"/api/v1/ngalert/alertmanagers"}),transformResponse:p=>p.data}),saveExternalAlertmanagersConfig:m.mutation({query:p=>({url:"/api/v1/ngalert/admin_config",method:"POST",data:p}),invalidatesTags:["AlertmanagerChoice"]})})})},45524:(U,b,a)=>{a.d(b,{J:()=>m});var n=a(68404),e=a(79396);const m=({children:p,pageId:h,pageNav:O,isLoading:E})=>n.createElement(e.T,{pageNav:O,navId:h},n.createElement(e.T.Contents,{isLoading:E},p))},51981:(U,b,a)=>{a.d(b,{q:()=>m});var n=a(68404),e=a(82002);const m=({actions:p,children:h,fallback:O=!0})=>p.some(E=>e.Vt.hasAccess(E,O))?n.createElement(n.Fragment,null,h):null},731:(U,b,a)=>{a.d(b,{u:()=>D});var n=a(52423),e=a(68404),m=a(72648),p=a(45253),h=a(39031),O=a(30173),E=a(45849);function D({currentAlertmanager:W}){const $=(0,m.wW)(S),{useGetAlertmanagerChoiceStatusQuery:w}=O.h,{currentData:L}=w(),g=W===E.GC;if(!(L?.alertmanagersChoice&&[h.TE.External,h.TE.All].includes(L?.alertmanagersChoice))||!g)return null;const V=L.numExternalAlertmanagers>0;return L.alertmanagersChoice===h.TE.External?e.createElement(p.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.",e.createElement("div",{className:$.adminHint},"To change your Alertmanager setup, go to the Alerting Admin page. If you do not have access, contact your Administrator.")):L.alertmanagersChoice===h.TE.All&&V?e.createElement(p.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.",e.createElement("div",{className:$.adminHint},"To change your Alertmanager setup, go to the Alerting Admin page. If you do not have access, contact your Administrator.")):null}const S=W=>({adminHint:n.css`
    font-size: ${W.typography.bodySmall.fontSize};
    font-weight: ${W.typography.bodySmall.fontWeight};
  `})},88331:(U,b,a)=>{a.d(b,{I:()=>E});var n=a(68404),e=a(45253),m=a(29614),p=a(94984);const h=()=>n.createElement(e.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."),O=()=>n.createElement(e.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."),E=({availableAlertManagers:D})=>{const[S,W]=(0,m.k)(D),$=D.length>0;return n.createElement("div",null,$?n.createElement(n.Fragment,null,n.createElement(p.P,{onChange:W,dataSources:D}),n.createElement(O,null)):n.createElement(h,null))}},40106:(U,b,a)=>{a.d(b,{C0:()=>O,Uv:()=>p,Xq:()=>h});var n=a(68404),e=a(45253),m=a(19985),p=(E=>(E.ContactPoint="contact point",E.Template="template",E.MuteTiming="mute timing",E.AlertRule="alert rule",E.RootNotificationPolicy="root notification policy",E))(p||{});const h=({resource:E})=>n.createElement(e.b,{title:`This ${E} cannot be edited through the UI`,severity:"info"},"This ",E," has been provisioned, that means it was created by config. Please contact your server admin to update this ",E,"."),O=()=>n.createElement(m.C,{text:"Provisioned",color:"purple"})},44479:(U,b,a)=>{a.d(b,{i:()=>E});var n=a(52423),e=a(68404),m=a(72648),p=a(52081),h=a(2390);const O={[h.W.OnCall]:"public/img/alerting/oncall_logo.svg",[h.W.Incident]:"",[h.W.MachineLearning]:""},E=({grafanaAppType:S})=>{const W=(0,m.wW)(D);return e.createElement("div",{className:W.wrapper},e.createElement(p.Lh,{align:"center",spacing:"xs"},e.createElement("img",{src:O[S],alt:"",height:"12px"}),e.createElement("span",null,S)))},D=S=>({wrapper:n.css`
    text-align: left;
    height: 22px;
    display: inline-flex;
    padding: 1px 4px;
    border-radius: 3px;
    border: 1px solid rgba(245, 95, 62, 1);
    color: rgba(245, 95, 62, 1);
    font-weight: ${S.typography.fontWeightRegular};
  `})},52259:(U,b,a)=>{a.d(b,{Kt:()=>w,HU:()=>L});var n=a(3363),e=a(54899),m=a(29427);const p=m.C.injectEndpoints({endpoints:g=>({getOnCallIntegrations:g.query({queryFn:async()=>({data:await h()}),providesTags:["AlertmanagerChoice"]})})});async function h(){try{return(await(0,n.n)((0,e.i)().fetch({url:"/api/plugin-proxy/grafana-oncall-app/api/internal/v1/alert_receive_channels/",showErrorAlert:!1,showSuccessAlert:!1}))).data.map(R=>R.integration_url)}catch{return[]}}const{useGetOnCallIntegrationsQuery:O}=p;var E=a(58509),D=a(2390);const S=(g,R)=>R.includes(g),W=(g,R)=>{if(!g.grafana_managed_receiver_configs)return!1;const V=g.grafana_managed_receiver_configs.length===1,Q=S(g.grafana_managed_receiver_configs[0]?.settings?.url??"",R);return V&&Q},$=()=>{const{installed:g}=(0,E.n)(D.W.OnCall),{data:R}=O(void 0,{skip:!g});return Q=>{if(g&&W(Q,R??[]))return D.W.OnCall}},w=g=>{const R=$(),V=Q=>({label:Q.name,value:Q.name,grafanaAppReceiverType:R(Q)});return g.map(V)},L=g=>{const R=$();return g.map(V=>({...V,grafanaAppReceiverType:R(V)}))}},99631:(U,b,a)=>{a.d(b,{g:()=>O});var n=a(52423),e=a(68404),m=a(72648),p=a(34807),h=a(20194);const O=({matchers:D})=>{const S=(0,m.wW)(E);return e.createElement("div",null,e.createElement(p.P,{className:S.tags,tags:D.map(W=>`${W.name}${(0,h.zy)(W)}${W.value}`)}))},E=()=>({tags:n.css`
    justify-content: flex-start;
  `})},29614:(U,b,a)=>{a.d(b,{k:()=>E});var n=a(68404),e=a(96044),m=a(58379),p=a(37190),h=a(45849);function O(D){return(0,n.useCallback)(S=>D.map($=>$.name).includes(S),[D])}function E(D){const[S,W]=(0,e.K)(),$=O(D),w=(0,n.useCallback)(R=>{$(R)&&(R===h.GC?(m.Z.delete(p.de),W({[p.c4]:null})):(m.Z.set(p.de,R),W({[p.c4]:R})))},[W,$]),L=S[p.c4];if(L&&typeof L=="string")return $(L)?[L,w]:[void 0,w];const g=m.Z.get(p.de);return g&&typeof g=="string"&&$(g)?(w(g),[g,w]):$(h.GC)?[h.GC,w]:[void 0,w]}},23403:(U,b,a)=>{a.d(b,{k:()=>m});var n=a(68404),e=a(45849);function m(p){return(0,n.useMemo)(()=>(0,e.LE)(p),[p])}},58509:(U,b,a)=>{a.d(b,{n:()=>m});var n=a(22350),e=a(13011);function m(p){const{loading:h,error:O,value:E}=(0,n.Z)(()=>(0,e.a)(p,{showErrorAlert:!1})),D=E&&!O&&!h,S=E?.enabled;return h&&!E?{loading:!0}:!D||!S?{loading:!1,installed:!1}:{loading:h,installed:!0,settings:E}}},31808:(U,b,a)=>{a.d(b,{j:()=>p});var n=a(68404),e=a(70356),m=a(37932);function p(){const{search:h}=(0,e.TH)(),O=(0,n.useMemo)(()=>new URLSearchParams(h),[h]),E=(0,n.useCallback)((D,S)=>{m.E1.partial(D,S)},[]);return[O,E]}},2390:(U,b,a)=>{a.d(b,{W:()=>n});var n=(e=>(e.Incident="grafana-incident-app",e.OnCall="grafana-oncall-app",e.MachineLearning="grafana-ml-app",e))(n||{})}}]);

//# sourceMappingURL=AlertAmRoutes.5d56d60dc34b65555111.js.map