"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[1783],{8572:(Q,M,t)=>{t.r(M),t.d(M,{default:()=>yt});var e=t(68404),m=t(70356),c=t(45253),g=t(53546),v=t(81168),R=t(79572),b=t(94984),T=t(45524),U=t(731),I=t(88331),r=t(52423),N=t(82897),P=t(59052),z=t(70197),L=t(37556),J=t(69311),s=t(46519),A=t(35645),u=t(72648),O=t(13393),S=t(24799),x=t(46967),B=t(97379),$=t(31403),q=t(40014),F=t(39031),X=t(31808),k=t(69945),G=t(72004),Y=t(20194),w=t(66367),j=t(10505),ne=t(46818),ye=t(19985),Me=t(61627),Ce=t(79662),oe=t(52694),ce=t(53731),De=t(45608);const Se=()=>{const[a,n]=(0,e.useState)([]),o=(0,P.Gc)(),i=(0,v.useDispatch)(),{watch:E}=o,h=E("matchers"),l=(0,u.wW)(xe),p=Pe();(0,e.useEffect)(()=>{i((0,G.ei)())},[i]);const d=(0,Me.Zo)();return(0,z.Z)(()=>{const C=d.flatMap(f=>f.groups.flatMap(D=>D.rules.map(y=>y.promRule).filter(y=>(0,Ce.x_)(y)).flatMap(y=>(0,w.TZ)(y.alerts??[],h))));n(C)},500,[d,h]),e.createElement("div",null,e.createElement("h4",{className:l.title},"Affected alert instances",a.length>0?e.createElement(ye.C,{className:l.badge,color:"blue",text:a.length}):null),e.createElement("div",{className:l.table},h.every(C=>!C.value&&!C.name)?e.createElement("span",null,"Add a valid matcher to see affected alerts"):e.createElement(ce.t,{items:a,isExpandable:!1,cols:p,pagination:{itemsPerPage:5}})))};function Pe(){return[{id:"state",label:"State",renderCell:function({data:{matchedInstance:n}}){return e.createElement(De.l,{state:n.state})},size:"160px"},{id:"labels",label:"Labels",renderCell:function({data:{matchedInstance:n}}){return e.createElement(oe.s,{labels:n.labels})},size:"auto"},{id:"created",label:"Created",renderCell:function({data:{matchedInstance:n}}){return e.createElement(e.Fragment,null,n.activeAt.startsWith("0001")?"-":(0,s.CQ)(n.activeAt).format("YYYY-MM-DD HH:mm:ss"))},size:"180px"}]}const xe=a=>({table:r.css`
    max-width: ${a.breakpoints.values.lg}px;
  `,moreMatches:r.css`
    margin-top: ${a.spacing(1)};
  `,title:r.css`
    display: flex;
    align-items: center;
  `,badge:r.css`
    margin-left: ${a.spacing(1)};
  `});var Re=t(63619),Oe=t(53217),Te=t(8180);const Ie=({className:a})=>{const n=(0,u.wW)(Be),o=(0,P.Gc)(),{control:i,register:E,formState:{errors:h}}=o,{fields:l=[],append:p,remove:d}=(0,P.Dq)({name:"matchers"});return e.createElement("div",{className:(0,r.cx)(a,n.wrapper)},e.createElement(S.g,{label:"Matching labels",required:!0},e.createElement("div",null,e.createElement("div",{className:n.matchers},l.map((C,f)=>e.createElement("div",{className:n.row,key:`${C.id}`,"data-testid":"matcher"},e.createElement(S.g,{label:"Label",invalid:!!h?.matchers?.[f]?.name,error:h?.matchers?.[f]?.name?.message},e.createElement(x.I,{...E(`matchers.${f}.name`,{required:{value:!0,message:"Required."}}),defaultValue:C.name,placeholder:"label"})),e.createElement(S.g,{label:"Operator"},e.createElement(Re.g,{control:i,render:({field:{onChange:D,ref:y,...W}})=>e.createElement(Oe.Ph,{...W,onChange:ee=>D(ee.value),className:n.matcherOptions,options:Y.tA,"aria-label":"operator"}),defaultValue:C.operator||Y.tA[0].value,name:`matchers.${f}.operator`,rules:{required:{value:!0,message:"Required."}}})),e.createElement(S.g,{label:"Value",invalid:!!h?.matchers?.[f]?.value,error:h?.matchers?.[f]?.value?.message},e.createElement(x.I,{...E(`matchers.${f}.value`,{required:{value:!0,message:"Required."}}),defaultValue:C.value,placeholder:"value"})),l.length>1&&e.createElement(Te.h,{className:n.removeButton,tooltip:"Remove matcher",name:"trash-alt",onClick:()=>d(f)},"Remove")))),e.createElement($.zx,{type:"button",icon:"plus",variant:"secondary",onClick:()=>{const C={name:"",value:"",operator:F._M.equal};p(C)}},"Add matcher"))))},Be=a=>({wrapper:r.css`
      margin-top: ${a.spacing(2)};
    `,row:r.css`
      display: flex;
      align-items: flex-start;
      flex-direction: row;
      background-color: ${a.colors.background.secondary};
      padding: ${a.spacing(1)} ${a.spacing(1)} 0 ${a.spacing(1)};
      & > * + * {
        margin-left: ${a.spacing(2)};
      }
    `,removeButton:r.css`
      margin-left: ${a.spacing(1)};
      margin-top: ${a.spacing(2.5)};
    `,matcherOptions:r.css`
      min-width: 140px;
    `,matchers:r.css`
      max-width: ${a.breakpoints.values.sm}px;
      margin: ${a.spacing(1)} 0;
      padding-top: ${a.spacing(.5)};
    `}),We=Ie;var be=t(95794);const Le=()=>{const{control:a,getValues:n}=(0,P.Gc)(),{field:{onChange:o,value:i},fieldState:{invalid:E}}=(0,P.bc)({name:"startsAt",control:a,rules:{validate:W=>n().endsAt>W}}),{field:{onChange:h,value:l},fieldState:{invalid:p}}=(0,P.bc)({name:"endsAt",control:a,rules:{validate:W=>n().startsAt<W}}),{field:{onChange:d,value:C}}=(0,P.bc)({name:"timeZone",control:a}),f=E||p,D=(0,s.CQ)(i),y=(0,s.CQ)(l);return e.createElement(S.g,{className:Ne.timeRange,label:"Silence start and end",error:f?"To is before or the same as from":"",invalid:f},e.createElement(be.K,{value:{from:D,to:y,raw:{from:D,to:y}},timeZone:C,onChange:W=>{o((0,s.CQ)(W.from)),h((0,s.CQ)(W.to))},onChangeTimeZone:W=>d(W),hideTimeZone:!1,hideQuickRanges:!0,placeholder:"Select time range"}))},Ne={timeRange:r.css`
    width: 400px;
  `},$e=a=>{const n={},o=a.get("comment"),i=a.getAll("matcher"),E=(0,w.RT)(i);return E.length&&(n.matchers=E.map(Y.cm)),o&&(n.comment=o),n},Ke=(a,n)=>{const o=new Date;if(n){const E=Date.parse(n.endsAt)<Date.now()?{start:o,end:(0,L.Ks)(o,{hours:2})}:{start:new Date(n.startsAt),end:new Date(n.endsAt)};return{id:n.id,startsAt:E.start.toISOString(),endsAt:E.end.toISOString(),comment:n.comment,createdBy:n.createdBy,duration:(0,L.vT)(E),isRegex:!1,matchers:n.matchers?.map(Y.cm)||[],matcherName:"",matcherValue:"",timeZone:J.Ys}}else{const i=(0,L.Ks)(o,{hours:2});return{id:"",startsAt:o.toISOString(),endsAt:i.toISOString(),comment:`created ${(0,s.CQ)().format("YYYY-MM-DD HH:mm")}`,createdBy:A.v.bootData.user.name,duration:"2h",isRegex:!1,matchers:[{name:"",value:"",operator:F._M.equal}],matcherName:"",matcherValue:"",timeZone:J.Ys,...$e(a)}}},Ue=({silence:a,alertManagerSourceName:n})=>{const[o]=(0,X.j)(),i=(0,e.useMemo)(()=>Ke(o,a),[a,o]),E=(0,P.cI)({defaultValues:i}),h=(0,v.useDispatch)(),l=(0,u.wW)(Qe),{loading:p}=(0,k._)(Z=>Z.updateSilence);(0,q.x)(Z=>Z.unifiedAlerting.updateSilence=ne.oq);const{register:d,handleSubmit:C,formState:f,watch:D,setValue:y,clearErrors:W}=E,ee=Z=>{const{id:Ae,startsAt:ae,endsAt:Ct,comment:Dt,createdBy:St,matchers:Pt}=Z,xt=Pt.map(Y._J),pe=(0,N.pickBy)({id:Ae,startsAt:ae,endsAt:Ct,comment:Dt,createdBy:St,matchers:xt},Rt=>!!Rt);h((0,G.QY)({alertManagerSourceName:n,payload:pe,exitOnSave:!0,successMessage:`Silence ${pe.id?"updated":"created"}`}))},V=D("duration"),K=D("startsAt"),H=D("endsAt"),[ve,he]=(0,e.useState)(V);(0,z.Z)(()=>{if((0,L.qb)(K)&&(0,L.qb)(H))if(V!==ve)y("endsAt",(0,s.CQ)((0,L.Ks)(new Date(K),(0,L.RA)(V))).toISOString()),he(V);else{const Z=new Date(K).valueOf();if(new Date(H).valueOf()>Z){const ae=(0,L.vT)({start:new Date(K),end:new Date(H)});y("duration",ae),he(ae)}}},700,[W,V,H,ve,y,K]);const Mt=Boolean(A.v.bootData.user.isSignedIn&&A.v.bootData.user.name);return e.createElement(P.RV,{...E},e.createElement("form",{onSubmit:C(ee)},e.createElement(O.C,{label:`${a?"Recreate silence":"Create silence"}`},e.createElement("div",{className:(0,r.cx)(l.flexRow,l.silencePeriod)},e.createElement(Le,null),e.createElement(S.g,{label:"Duration",invalid:!!f.errors.duration,error:f.errors.duration&&(f.errors.duration.type==="required"?"Required field":f.errors.duration.message)},e.createElement(x.I,{className:l.createdBy,...d("duration",{validate:Z=>Object.keys((0,L.RA)(Z)).length===0?"Invalid duration. Valid example: 1d 4h (Available units: y, M, w, d, h, m, s)":void 0}),id:"duration"}))),e.createElement(We,null),e.createElement(S.g,{className:(0,r.cx)(l.field,l.textArea),label:"Comment",required:!0,error:f.errors.comment?.message,invalid:!!f.errors.comment},e.createElement(B.K,{...d("comment",{required:{value:!0,message:"Required."}}),rows:5,placeholder:"Details about the silence"})),!Mt&&e.createElement(S.g,{className:(0,r.cx)(l.field,l.createdBy),label:"Created By",required:!0,error:f.errors.createdBy?.message,invalid:!!f.errors.createdBy},e.createElement(x.I,{...d("createdBy",{required:{value:!0,message:"Required."}}),placeholder:"Who's creating the silence"})),e.createElement(Se,null)),e.createElement("div",{className:l.flexRow},p&&e.createElement($.zx,{disabled:!0,icon:"fa fa-spinner",variant:"primary"},"Saving..."),!p&&e.createElement($.zx,{type:"submit"},"Submit"),e.createElement($.Qj,{href:(0,j.eQ)("alerting/silences",n),variant:"secondary",fill:"outline"},"Cancel"))))},Qe=a=>({field:r.css`
    margin: ${a.spacing(1,0)};
  `,textArea:r.css`
    max-width: ${a.breakpoints.values.sm}px;
  `,createdBy:r.css`
    width: 200px;
  `,flexRow:r.css`
    display: flex;
    flex-direction: row;
    justify-content: flex-start;

    & > * {
      margin-right: ${a.spacing(1)};
    }
  `,silencePeriod:r.css`
    max-width: ${a.breakpoints.values.sm}px;
  `}),ie=Ue;var te=t(21053),me=t(26418),de=t(29460),se=t(39904),re=t(96044),_=t(82002),le=t(97953),ze=t(51981);const ue=({className:a,...n})=>{const o=(0,u.wW)(Fe);return e.createElement($.zx,{variant:"secondary",size:"xs",className:(0,r.cx)(o.wrapper,a),...n})},Fe=a=>({wrapper:r.css`
    height: 24px;
    font-size: ${a.typography.bodySmall.fontSize};
  `});var Ge=t(65750),Ye=t(99631),Ve=t(97097),Ze=t(69142);const je=({alertManagerSourceName:a})=>{const n=(0,le.QX)(a);return _.Vt.hasAccess(n.create,_.Vt.isEditor)?e.createElement(Ze.Z,{title:"You haven't created any silences yet",buttonIcon:"bell-slash",buttonLink:(0,j.eQ)("alerting/silence/new",a),buttonTitle:"Create silence"}):e.createElement(Ve._,{callToActionElement:e.createElement("div",null),message:"No silences found."})};var He=t(85655),Je=t(33950),we=t(90072);const Xe=({alert:a,className:n})=>{const[o,i]=(0,e.useState)(!0),E=(0,L.vT)({start:new Date(a.startsAt),end:new Date(a.endsAt)}),h=Object.entries(a.labels).reduce((l,[p,d])=>((p==="alertname"||p==="__alert_rule_title__")&&(l=d),l),"");return e.createElement(e.Fragment,null,e.createElement("tr",{className:n},e.createElement("td",null,e.createElement(Je.U,{isCollapsed:o,onToggle:l=>i(l)})),e.createElement("td",null,e.createElement(we.G,{state:a.status.state})),e.createElement("td",null,"for ",E," seconds"),e.createElement("td",null,h)),!o&&e.createElement("tr",{className:n},e.createElement("td",null),e.createElement("td",{colSpan:5},e.createElement(oe.s,{labels:a.labels}))))},ke=({silencedAlerts:a})=>{const n=(0,u.wW)(He.D),o=(0,u.wW)(qe);return a.length?e.createElement("table",{className:(0,r.cx)(n.table,o.tableMargin)},e.createElement("colgroup",null,e.createElement("col",{className:n.colExpand}),e.createElement("col",{className:o.colState}),e.createElement("col",null),e.createElement("col",{className:o.colName})),e.createElement("thead",null,e.createElement("tr",null,e.createElement("th",null),e.createElement("th",null,"State"),e.createElement("th",null),e.createElement("th",null,"Alert name"))),e.createElement("tbody",null,a.map((i,E)=>e.createElement(Xe,{key:i.fingerprint,alert:i,className:E%2===0?n.evenRow:""})))):null},qe=a=>({tableMargin:r.css`
    margin-bottom: ${a.spacing(1)};
  `,colState:r.css`
    width: 110px;
  `,colName:r.css`
    width: 65%;
  `}),_e=ke,et=({silence:a})=>{const{startsAt:n,endsAt:o,comment:i,createdBy:E,silencedAlerts:h}=a,l=(0,u.wW)(tt),p="YYYY-MM-DD HH:mm",d=te.parse(n),C=te.parse(o),f=(0,L.vT)({start:new Date(n),end:new Date(o)});return e.createElement("div",{className:l.container},e.createElement("div",{className:l.title},"Comment"),e.createElement("div",null,i),e.createElement("div",{className:l.title},"Schedule"),e.createElement("div",null,`${d?.format(p)} - ${C?.format(p)}`),e.createElement("div",{className:l.title},"Duration"),e.createElement("div",null," ",f),e.createElement("div",{className:l.title},"Created by"),e.createElement("div",null," ",E),e.createElement("div",{className:l.title},"Affected alerts"),e.createElement(_e,{silencedAlerts:h}))},tt=a=>({container:r.css`
    display: grid;
    grid-template-columns: 1fr 9fr;
    grid-row-gap: 1rem;
  `,title:r.css`
    color: ${a.colors.text.primary};
  `,row:r.css`
    margin: ${a.spacing(1,0)};
  `});var at=t(79453);const nt={[F.As.Active]:"good",[F.As.Expired]:"neutral",[F.As.Pending]:"neutral"},st=({state:a})=>e.createElement(at.i,{state:nt[a]},a);var rt=t(64353),lt=t(61860),ot=t(2594);const ct=Object.entries(F.As).map(([a,n])=>({label:a,value:n})),ge=()=>(0,N.uniqueId)("query-string-"),it=()=>{const[a,n]=(0,e.useState)(ge()),[o,i]=(0,re.K)(),{queryString:E,silenceState:h}=(0,j.pF)(o),l=(0,u.wW)(mt),p=(0,N.debounce)(D=>{const y=D.target;i({queryString:y.value||null})},400),d=D=>{i({silenceState:D})},C=()=>{i({queryString:null,silenceState:null}),setTimeout(()=>n(ge()))},f=E&&E.length>3?(0,Y.Zh)(E).length===0:!1;return e.createElement("div",{className:l.flexRow},e.createElement(S.g,{className:l.rowChild,label:e.createElement(rt._,null,e.createElement(me.Stack,{gap:.5},e.createElement("span",null,"Search by matchers"),e.createElement(lt.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:f,error:f?"Query must use valid matcher syntax":null},e.createElement(x.I,{key:a,className:l.searchInput,prefix:e.createElement(se.J,{name:"search"}),onChange:p,defaultValue:E??"",placeholder:"Search","data-testid":"search-query-input"})),e.createElement(S.g,{className:l.rowChild,label:"State"},e.createElement(ot.S,{options:ct,value:h,onChange:d})),(E||h)&&e.createElement("div",{className:l.rowChild},e.createElement($.zx,{variant:"secondary",icon:"times",onClick:C},"Clear filters")))},mt=a=>({searchInput:r.css`
    width: 360px;
  `,flexRow:r.css`
    display: flex;
    flex-direction: row;
    align-items: flex-end;
    padding-bottom: ${a.spacing(2)};
    border-bottom: 1px solid ${a.colors.border.strong};
  `,rowChild:r.css`
    margin-right: ${a.spacing(1)};
    margin-bottom: 0;
    max-height: 52px;
  `,fieldLabel:r.css`
    font-size: 12px;
    font-weight: 500;
  `}),dt=({silences:a,alertManagerAlerts:n,alertManagerSourceName:o})=>{const i=(0,u.wW)(Ee),[E]=(0,re.K)(),h=ut(a),l=(0,le.QX)(o),{silenceState:p}=(0,j.pF)(E),d=!!h.length&&(p===void 0||p===F.As.Expired),C=gt(o),f=(0,e.useMemo)(()=>{const D=y=>n.filter(W=>W.status.silencedBy.includes(y));return h.map(y=>{const W=D(y.id);return{id:y.id,data:{...y,silencedAlerts:W}}})},[h,n]);return e.createElement("div",{"data-testid":"silences-table"},!!a.length&&e.createElement(e.Fragment,null,e.createElement(it,null),e.createElement(ze.q,{actions:[l.create],fallback:_.Vt.isEditor},e.createElement("div",{className:i.topButtonContainer},e.createElement(de.r,{href:(0,j.eQ)("/alerting/silence/new",o)},e.createElement($.zx,{className:i.addNewSilence,icon:"plus"},"Add Silence")))),f.length?e.createElement(e.Fragment,null,e.createElement(ce.t,{items:f,cols:C,isExpandable:!0,renderExpandedContent:({data:D})=>e.createElement(et,{silence:D})}),d&&e.createElement("div",{className:i.callout},e.createElement(se.J,{className:i.calloutIcon,name:"info-circle"}),e.createElement("span",null,"Expired silences are automatically deleted after 5 days."))):"No matching silences found"),!a.length&&e.createElement(je,{alertManagerSourceName:o}))},ut=a=>{const[n]=(0,re.K)();return(0,e.useMemo)(()=>{const{queryString:o,silenceState:i}=(0,j.pF)(n),E=n?.silenceIds;return a.filter(h=>!(typeof E=="string"&&!E.split(",").includes(h.id)||o&&!(0,Y.Zh)(o).every(d=>h.matchers?.some(({name:C,value:f,isEqual:D,isRegex:y})=>d.name===C&&d.value===f&&d.isEqual===D&&d.isRegex===y))||i&&!(h.status.state===i)))},[n,a])},Ee=a=>({topButtonContainer:r.css`
    display: flex;
    flex-direction: row;
    justify-content: flex-end;
  `,addNewSilence:r.css`
    margin: ${a.spacing(2,0)};
  `,callout:r.css`
    background-color: ${a.colors.background.secondary};
    border-top: 3px solid ${a.colors.info.border};
    border-radius: 2px;
    height: 62px;
    display: flex;
    flex-direction: row;
    align-items: center;
    margin-top: ${a.spacing(2)};

    & > * {
      margin-left: ${a.spacing(1)};
    }
  `,calloutIcon:r.css`
    color: ${a.colors.info.text};
  `,editButton:r.css`
    margin-left: ${a.spacing(.5)};
  `});function gt(a){const n=(0,v.useDispatch)(),o=(0,u.wW)(Ee),i=(0,le.QX)(a);return(0,e.useMemo)(()=>{const E=p=>{n((0,G.yO)(a,p))},h=_.Vt.hasAccess(i.update,_.Vt.isEditor),l=[{id:"state",label:"State",renderCell:function({data:{status:d}}){return e.createElement(st,{state:d.state})},size:4},{id:"matchers",label:"Matching labels",renderCell:function({data:{matchers:d}}){return e.createElement(Ye.g,{matchers:d||[]})},size:10},{id:"alerts",label:"Alerts",renderCell:function({data:{silencedAlerts:d}}){return e.createElement("span",{"data-testid":"alerts"},d.length)},size:4},{id:"schedule",label:"Schedule",renderCell:function({data:{startsAt:d,endsAt:C}}){const f=te.parse(d),D=te.parse(C),y="YYYY-MM-DD HH:mm";return e.createElement(e.Fragment,null," ",f?.format(y)," ","-",D?.format(y))},size:7}];return h&&l.push({id:"actions",label:"Actions",renderCell:function({data:d}){return e.createElement(me.Stack,{gap:.5},d.status.state==="expired"?e.createElement(de.r,{href:(0,j.eQ)(`/alerting/silence/${d.id}/edit`,a)},e.createElement(ue,{icon:"sync"},"Recreate")):e.createElement(ue,{icon:"bell",onClick:()=>E(d.id)},"Unsilence"),d.status.state!=="expired"&&e.createElement(Ge.A,{className:o.editButton,to:(0,j.eQ)(`/alerting/silence/${d.id}/edit`,a),icon:"pen",tooltip:"edit"}))},size:5}),l},[a,n,o,i])}const Et=dt;var ft=t(29614),vt=t(23403);const fe={icon:"bell-slash",breadcrumbs:[{title:"Silences",url:"alerting/silences"}]};function ht(){const{isExact:a,path:n}=(0,m.$B)(),[o,i]=(0,e.useState)();return(0,e.useEffect)(()=>{n==="/alerting/silence/new"?i({...fe,id:"silence-new",text:"Add silence"}):n==="/alerting/silence/:id/edit"&&i({...fe,id:"silence-edit",text:"Edit silence"})},[n,a]),o}var At=t(37190);const pt=()=>{const a=(0,vt.k)("instance"),[n,o]=(0,ft.k)(a),i=(0,v.useDispatch)(),E=(0,k._)(K=>K.silences),h=(0,k._)(K=>K.amAlerts),l=n?h[n]||ne.oq:void 0,p=(0,m.TH)(),d=ht(),C=p.pathname.endsWith("/alerting/silences"),{currentData:f}=R.T.useDiscoverAmFeaturesQuery({amSourceName:n??""},{skip:!n});(0,e.useEffect)(()=>{function K(){n&&(i((0,G.je)(n)),i((0,G.dB)(n)))}K();const H=setInterval(()=>K,At.cm);return()=>{clearInterval(H)}},[n,i]);const{result:D,loading:y,error:W}=n&&E[n]||ne.oq,ee=(0,e.useCallback)(K=>D&&D.find(H=>H.id===K),[D]),V=W?.message?.includes("the Alertmanager is not configured")&&f?.lazyConfigInit;return n?e.createElement(T.J,{pageId:"silences",isLoading:y,pageNav:d},e.createElement(b.P,{disabled:!C,current:n,onChange:o,dataSources:a}),e.createElement(U.u,{currentAlertmanager:n}),V&&e.createElement(c.b,{title:"The selected Alertmanager has no configuration",severity:"warning"},"Create a new contact point to create a configuration using the default values or contact your administrator to set up the Alertmanager."),W&&!y&&!V&&e.createElement(c.b,{severity:"error",title:"Error loading silences"},W.message||"Unknown error."),l?.error&&!l?.loading&&!V&&e.createElement(c.b,{severity:"error",title:"Error loading Alertmanager alerts"},l.error?.message||"Unknown error."),D&&!W&&e.createElement(m.rs,null,e.createElement(m.AW,{exact:!0,path:"/alerting/silences"},e.createElement(Et,{silences:D,alertManagerAlerts:l?.result??[],alertManagerSourceName:n})),e.createElement(m.AW,{exact:!0,path:"/alerting/silence/new"},e.createElement(ie,{alertManagerSourceName:n})),e.createElement(m.AW,{exact:!0,path:"/alerting/silence/:id/edit"},({match:K})=>K?.params.id&&e.createElement(ie,{silence:ee(K.params.id),alertManagerSourceName:n})))):C?e.createElement(T.J,{pageId:"silences",pageNav:d},e.createElement(I.I,{availableAlertManagers:a})):e.createElement(m.l_,{to:"/alerting/silences"})},yt=(0,g.Pf)(pt,{style:"page"})},30173:(Q,M,t)=>{t.d(M,{h:()=>m});var e=t(29427);const m=e.C.injectEndpoints({endpoints:c=>({getAlertmanagerChoiceStatus:c.query({query:()=>({url:"/api/v1/ngalert"}),providesTags:["AlertmanagerChoice"]}),getExternalAlertmanagerConfig:c.query({query:()=>({url:"/api/v1/ngalert/admin_config"}),providesTags:["AlertmanagerChoice"]}),getExternalAlertmanagers:c.query({query:()=>({url:"/api/v1/ngalert/alertmanagers"}),transformResponse:g=>g.data}),saveExternalAlertmanagersConfig:c.mutation({query:g=>({url:"/api/v1/ngalert/admin_config",method:"POST",data:g}),invalidatesTags:["AlertmanagerChoice"]})})})},45524:(Q,M,t)=>{t.d(M,{J:()=>c});var e=t(68404),m=t(79396);const c=({children:g,pageId:v,pageNav:R,isLoading:b})=>e.createElement(m.T,{pageNav:R,navId:v},e.createElement(m.T.Contents,{isLoading:b},g))},51981:(Q,M,t)=>{t.d(M,{q:()=>c});var e=t(68404),m=t(82002);const c=({actions:g,children:v,fallback:R=!0})=>g.some(b=>m.Vt.hasAccess(b,R))?e.createElement(e.Fragment,null,v):null},731:(Q,M,t)=>{t.d(M,{u:()=>T});var e=t(52423),m=t(68404),c=t(72648),g=t(45253),v=t(39031),R=t(30173),b=t(45849);function T({currentAlertmanager:I}){const r=(0,c.wW)(U),{useGetAlertmanagerChoiceStatusQuery:N}=R.h,{currentData:P}=N(),z=I===b.GC;if(!(P?.alertmanagersChoice&&[v.TE.External,v.TE.All].includes(P?.alertmanagersChoice))||!z)return null;const J=P.numExternalAlertmanagers>0;return P.alertmanagersChoice===v.TE.External?m.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.",m.createElement("div",{className:r.adminHint},"To change your Alertmanager setup, go to the Alerting Admin page. If you do not have access, contact your Administrator.")):P.alertmanagersChoice===v.TE.All&&J?m.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.",m.createElement("div",{className:r.adminHint},"To change your Alertmanager setup, go to the Alerting Admin page. If you do not have access, contact your Administrator.")):null}const U=I=>({adminHint:e.css`
    font-size: ${I.typography.bodySmall.fontSize};
    font-weight: ${I.typography.bodySmall.fontWeight};
  `})},88331:(Q,M,t)=>{t.d(M,{I:()=>b});var e=t(68404),m=t(45253),c=t(29614),g=t(94984);const v=()=>e.createElement(m.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."),R=()=>e.createElement(m.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."),b=({availableAlertManagers:T})=>{const[U,I]=(0,c.k)(T),r=T.length>0;return e.createElement("div",null,r?e.createElement(e.Fragment,null,e.createElement(g.P,{onChange:I,dataSources:T}),e.createElement(R,null)):e.createElement(v,null))}},65750:(Q,M,t)=>{t.d(M,{A:()=>g});var e=t(68404),m=t(61860),c=t(31403);const g=({tooltip:v,icon:R,to:b,target:T,onClick:U,className:I,tooltipPlacement:r="top",...N})=>{const P=typeof v=="string"?v:void 0;return e.createElement(m.u,{content:v,placement:r},b?e.createElement(c.Qj,{variant:"secondary",fill:"text",icon:R,href:b,size:"sm",target:T,...N,"aria-label":P}):e.createElement(c.zx,{className:I,variant:"secondary",fill:"text",size:"sm",icon:R,type:"button",onClick:U,...N,"aria-label":P}))}},90072:(Q,M,t)=>{t.d(M,{G:()=>v});var e=t(68404),m=t(39031),c=t(79453);const g={[m.Z9.Active]:"bad",[m.Z9.Unprocessed]:"neutral",[m.Z9.Suppressed]:"info"},v=({state:R})=>e.createElement(c.i,{state:g[R]},R)},99631:(Q,M,t)=>{t.d(M,{g:()=>R});var e=t(52423),m=t(68404),c=t(72648),g=t(34807),v=t(20194);const R=({matchers:T})=>{const U=(0,c.wW)(b);return m.createElement("div",null,m.createElement(g.P,{className:U.tags,tags:T.map(I=>`${I.name}${(0,v.zy)(I)}${I.value}`)}))},b=()=>({tags:e.css`
    justify-content: flex-start;
  `})},29614:(Q,M,t)=>{t.d(M,{k:()=>b});var e=t(68404),m=t(96044),c=t(58379),g=t(37190),v=t(45849);function R(T){return(0,e.useCallback)(U=>T.map(r=>r.name).includes(U),[T])}function b(T){const[U,I]=(0,m.K)(),r=R(T),N=(0,e.useCallback)(L=>{r(L)&&(L===v.GC?(c.Z.delete(g.de),I({[g.c4]:null})):(c.Z.set(g.de,L),I({[g.c4]:L})))},[I,r]),P=U[g.c4];if(P&&typeof P=="string")return r(P)?[P,N]:[void 0,N];const z=c.Z.get(g.de);return z&&typeof z=="string"&&r(z)?(N(z),[z,N]):r(v.GC)?[v.GC,N]:[void 0,N]}},23403:(Q,M,t)=>{t.d(M,{k:()=>c});var e=t(68404),m=t(45849);function c(g){return(0,e.useMemo)(()=>(0,m.LE)(g),[g])}},61627:(Q,M,t)=>{t.d(M,{Kd:()=>T,Zo:()=>b});var e=t(82897),m=t.n(e),c=t(68404),g=t(45849),v=t(79662),R=t(69945);function b(s){const A=(0,R._)(x=>x.promRules),u=(0,R._)(x=>x.rulerRules),O=(0,c.useRef)({}),S=(0,c.useMemo)(()=>{if(s){const x=(0,g.o_)(s);if(!x)throw new Error(`Unknown rules source: ${s}`);return[x]}return(0,g.h_)()},[s]);return(0,c.useMemo)(()=>S.map(x=>{const B=(0,g.jq)(x)?x.name:x,$=A[B]?.result,q=u[B]?.result,F=O.current[B];if(F&&F.promRules===$&&F.rulerRules===q)return F.result;const X={};Object.entries(q||{}).forEach(([G,Y])=>{const w={rulesSource:x,name:G,groups:[]};X[G]=w,I(w,Y)}),$?.forEach(({name:G,groups:Y})=>{const w=X[G]=X[G]||{rulesSource:x,name:G,groups:[]};r(w,Y)});const k=Object.values(X);return O.current[B]={promRules:$,rulerRules:q,result:k},k}).flat(),[A,u,S])}function T(s){return s.map(A=>{const u={...A,groups:[]};return u.groups.push({name:"default",rules:U(A.groups.flatMap(O=>O.rules))}),u})}function U(s){return s.sort((A,u)=>A.name.localeCompare(u.name))}function I(s,A=[]){s.groups=A.map(u=>{const O={name:u.name,interval:u.interval,source_tenants:u.source_tenants,rules:[]};return O.rules=u.rules.map(S=>P(S,s,O)),O})}function r(s,A){const u=new Map;s.groups.forEach(O=>u.set(O.name,O)),A.forEach(O=>{let S=u.get(O.name);S||(S={name:O.name,rules:[]},s.groups.push(S),u.set(O.name,S));const x=new Map;S.rules.forEach(B=>{const $=x.get(B.name);$?$.push(B):x.set(B.name,[B])}),(O.rules??[]).forEach(B=>{const $=z(B,x,s.rulesSource);$?$.promRule=B:S.rules.push(N(B,s,S))})})}function N(s,A,u){return{name:s.name,query:s.query,labels:s.labels||{},annotations:(0,v.x_)(s)?s.annotations||{}:{},promRule:s,namespace:A,group:u}}function P(s,A,u){return(0,v.cG)(s)?{name:s.alert,query:s.expr,labels:s.labels||{},annotations:s.annotations||{},rulerRule:s,namespace:A,group:u}:(0,v.yF)(s)?{name:s.record,query:s.expr,labels:s.labels||{},annotations:{},rulerRule:s,namespace:A,group:u}:{name:s.grafana_alert.title,query:"",labels:s.labels||{},annotations:s.annotations||{},rulerRule:s,namespace:A,group:u}}function z(s,A,u){const O=A.get(s.name);if(!O)return;if((0,g.HY)(u))return O[0];const S=O.find(B=>!B.promRule&&L(B,s,!0));if(S)return S;const x=O.find(B=>!B.promRule&&L(B,s,!1));if(x)return x}function L(s,A,u=!0){return s.name===A.name?(0,e.isEqual)([u?J(s.query):"",s.labels,s.annotations],[u?J(A.query):"",A.labels||{},(0,v.x_)(A)?A.annotations||{}:{}]):!1}function J(s){return s.length>1&&s[0]==="("&&s[s.length-1]===")"&&(s=s.slice(1,-1)),s=s.replace(/\s|\n/g,""),s.split("").sort().join("")}},31808:(Q,M,t)=>{t.d(M,{j:()=>g});var e=t(68404),m=t(70356),c=t(37932);function g(){const{search:v}=(0,m.TH)(),R=(0,e.useMemo)(()=>new URLSearchParams(v),[v]),b=(0,e.useCallback)((T,U)=>{c.E1.partial(T,U)},[]);return[R,b]}},85655:(Q,M,t)=>{t.d(M,{D:()=>m});var e=t(52423);const m=c=>({table:e.css`
    width: 100%;
    border-radius: ${c.shape.borderRadius()};
    border: solid 1px ${c.colors.border.weak};
    background-color: ${c.colors.background.secondary};

    th {
      padding: ${c.spacing(1)};
    }

    td {
      padding: 0 ${c.spacing(1)};
    }

    tr {
      height: 38px;
    }
  `,evenRow:e.css`
    background-color: ${c.colors.background.primary};
  `,colExpand:e.css`
    width: 36px;
  `,actionsCell:e.css`
    text-align: right;
    width: 1%;
    white-space: nowrap;

    & > * + * {
      margin-left: ${c.spacing(.5)};
    }
  `})}}]);

//# sourceMappingURL=AlertSilences.13a4e826b65749d703bd.js.map