"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[2415],{97138:(B,C,t)=>{t.r(C),t.d(C,{default:()=>ee});var s=t(42844),e=t(27702),v=t(66310),E=t(52419),G=t(63439),h=t(89033),S=t(18771),W=t(62862),d=t(52646),N=t(81324),x=t(9853),$=t(66670),F=t(39036),I=t(79978),R=t(40705);const L=({onStateFilterChange:r,stateFilter:c})=>{const g=(0,v.wW)(K),i=Object.entries(W.Z9).sort(([n],[l])=>n<l?-1:1).map(([n,l])=>({label:n,value:l}));return e.createElement("div",{className:g.wrapper},e.createElement(I._,null,"State"),e.createElement(R.S,{options:i,value:c,onChange:r}))},K=r=>({wrapper:(0,s.css)`
    margin-left: ${r.spacing(1)};
  `});var U=t(89949),z=t(28580),Z=t(73453);const Q=({className:r,groups:c,groupBy:g,onGroupingChange:i})=>{const n=(0,U.uniq)(c.flatMap(l=>l.alerts).flatMap(({labels:l})=>Object.keys(l))).filter(l=>!(l.startsWith("__")&&l.endsWith("__"))).map(l=>({label:l,value:l}));return e.createElement("div",{"data-testid":"group-by-container",className:r},e.createElement(I._,null,"Custom group by"),e.createElement(z.NU,{"aria-label":"group by label keys",value:g,placeholder:"Group by",prefix:e.createElement(Z.J,{name:"tag-alt"}),onChange:l=>{i(l.map(({value:o})=>o))},options:n}))};var H=t(71444);const J=({groups:r})=>{const[c,g]=(0,e.useState)(Math.floor(Math.random()*100)),[i,n]=(0,h.K)(),{groupBy:l=[],queryString:o,alertState:p}=(0,F.lC)(i),y=`matcher-${c}`,A=(0,v.wW)(V),T=()=>{n({groupBy:null,queryString:null,alertState:null}),setTimeout(()=>g(c+1),100)},Y=!!(l.length>0||o||p);return e.createElement("div",{className:A.wrapper},e.createElement("div",{className:A.filterSection},e.createElement(H.F,{className:A.filterInput,key:y,defaultQueryString:o,onFilterChange:b=>n({queryString:b||null})}),e.createElement(Q,{className:A.filterInput,groups:r,groupBy:l,onGroupingChange:b=>n({groupBy:b.length?b.join(","):null})}),e.createElement(L,{stateFilter:p,onStateFilterChange:b=>n({alertState:b||null})}),Y&&e.createElement($.zx,{className:A.clearButton,variant:"secondary",icon:"times",onClick:T},"Clear filters")))},V=r=>({wrapper:(0,s.css)`
    border-bottom: 1px solid ${r.colors.border.medium};
    margin-bottom: ${r.spacing(3)};
  `,filterSection:(0,s.css)`
    display: flex;
    flex-direction: row;
    margin-bottom: ${r.spacing(3)};
  `,filterInput:(0,s.css)`
    width: 340px;
    & + & {
      margin-left: ${r.spacing(1)};
    }
  `,clearButton:(0,s.css)`
    margin-left: ${r.spacing(1)};
    margin-top: 19px;
  `});var a=t(76658);const f=r=>{const[c]=(0,h.K)(),g=(0,F.lC)(c),i=(0,a.Zh)(g.queryString||"");return(0,e.useMemo)(()=>r.reduce((n,l)=>{const o=l.alerts.filter(({labels:p,status:y})=>{const A=(0,a.eD)(p,i),T=g.alertState?y.state===g.alertState:!0;return A&&T});return o.length>0&&(Object.keys(l.labels).length===0?n.unshift({...l,alerts:o}):n.push({...l,alerts:o})),n},[]),[r,g,i])},m=(r,c)=>(0,e.useMemo)(()=>c.length===0?r.filter(n=>Object.keys(n.labels).length===0).length>1?r.reduce((n,l)=>{if(Object.keys(l.labels).length===0){const o=n.find(({labels:p})=>Object.keys(p));o?o.alerts=(0,U.uniqBy)([...o.alerts,...l.alerts],"labels"):n.push({alerts:l.alerts,labels:{},receiver:{name:"NONE"}})}else n.push(l);return n},[]):r:r.flatMap(({alerts:i})=>i).reduce((i,n)=>{if(c.every(o=>Object.keys(n.labels).includes(o))){const o=i.find(p=>c.every(y=>p.labels[y]===n.labels[y]));if(o)o.alerts.push(n);else{const p=c.reduce((y,A)=>(y={...y,[A]:n.labels[A]},y),{});i.push({alerts:[n],labels:p,receiver:{name:"NONE"}})}}else{const o=i.find(p=>Object.keys(p.labels).length===0);o?o.alerts.push(n):i.push({alerts:[n],labels:{},receiver:{name:"NONE"}})}return i},[]),[r,c]);var D=t(10027),P=t(1469),u=t(47702),M=t(33555),X=t(22513),w=t(84369);const k=()=>{const{useGetAlertmanagerChoiceStatusQuery:r}=d.alertmanagerApi,{selectedAlertmanager:c}=(0,P.Z)(),g=(0,S.useDispatch)(),[i]=(0,h.K)(),{groupBy:n=[]}=(0,F.lC)(i),l=(0,v.wW)(_),{currentData:o}=r(),p=(0,D._)(O=>O.amAlertGroups),{loading:y,error:A,result:T=[]}=p[c||""]??w.oq,Y=m(T,n),b=f(Y),te=c===X.GC&&o?.alertmanagersChoice===W.TE.External;return(0,e.useEffect)(()=>{function O(){c&&g((0,u.mS)(c))}O();const j=setInterval(O,M.iF);return()=>{clearInterval(j)}},[g,c]),e.createElement(e.Fragment,null,e.createElement(J,{groups:T}),y&&e.createElement(E.u,{text:"Loading notifications"}),A&&!y&&e.createElement(G.b,{title:"Error loading notifications",severity:"error"},A.message||"Unknown error"),te&&e.createElement(G.b,{title:"Grafana alerts are not delivered to Grafana Alertmanager"},"Grafana is configured to send alerts to external alertmanagers only. No alerts are expected to be available here for the selected Alertmanager."),T&&b.map((O,j)=>e.createElement(e.Fragment,{key:`${JSON.stringify(O.labels)}-group-${j}`},(j===1&&Object.keys(b[0].labels).length===0||j===0&&Object.keys(O.labels).length>0)&&e.createElement("p",{className:l.groupingBanner},"Grouped by: ",Object.keys(O.labels).join(", ")),e.createElement(x.y,{alertManagerSourceName:c||"",group:O}))),T&&!b.length&&e.createElement("p",null,"No results."))},q=()=>e.createElement(N.O,{pageId:"groups",accessType:"instance"},e.createElement(k,null)),_=r=>({groupingBanner:(0,s.css)`
    margin: ${r.spacing(2,0)};
  `}),ee=q},89439:(B,C,t)=>{t.d(C,{q:()=>v});var s=t(27702),e=t(91368);const v=({actions:E,children:G,fallback:h=!0})=>E.some(S=>e.contextSrv.hasAccess(S,h))?s.createElement(s.Fragment,null,G):null},43491:(B,C,t)=>{t.d(C,{F:()=>G});var s=t(42844),e=t(27702),v=t(66310),E=t(45986);const G=({renderExpandedContent:S,...W})=>{const d=(0,v.wW)(h);return e.createElement(E.t,{renderExpandedContent:S?(N,x,$)=>e.createElement(e.Fragment,null,x!==$.length-1&&e.createElement("div",{className:(0,s.cx)(d.contentGuideline,d.guideline)}),S(N,x,$)):void 0,renderPrefixHeader:()=>e.createElement("div",{className:d.relative},e.createElement("div",{className:(0,s.cx)(d.headerGuideline,d.guideline)})),renderPrefixCell:(N,x,$)=>e.createElement("div",{className:d.relative},e.createElement("div",{className:(0,s.cx)(d.topGuideline,d.guideline)}),x!==$.length-1&&e.createElement("div",{className:(0,s.cx)(d.bottomGuideline,d.guideline)})),...W})},h=S=>({relative:(0,s.css)`
    position: relative;
    height: 100%;
  `,guideline:(0,s.css)`
    left: -19px;
    border-left: 1px solid ${S.colors.border.weak};
    position: absolute;

    ${S.breakpoints.down("md")} {
      display: none;
    }
  `,topGuideline:(0,s.css)`
    width: 18px;
    border-bottom: 1px solid ${S.colors.border.medium};
    top: 0;
    bottom: 50%;
  `,bottomGuideline:(0,s.css)`
    top: 50%;
    bottom: 0;
  `,contentGuideline:(0,s.css)`
    top: 0;
    bottom: 0;
    left: -49px !important;
  `,headerGuideline:(0,s.css)`
    top: -17px;
    bottom: 0;
  `})},9853:(B,C,t)=>{t.d(C,{y:()=>J});var s=t(42844),e=t(27702),v=t(66310),E=t(62862),G=t(8254),h=t(10759),S=t(32082),W=t(43491),d=t(22201),N=t(66670),x=t(91368),$=t(18771),F=t(2082),I=t(22513),R=t(39036),L=t(73104),K=t(89439);const U=({alert:a,alertManagerSourceName:f})=>{const m=(0,v.wW)(z),D=(0,F.QX)(f),u=(0,I.HY)(f)?x.contextSrv.hasPermission($.AccessControlAction.AlertingRuleRead):!0;return e.createElement(e.Fragment,null,e.createElement("div",{className:m.actionsRow},e.createElement(K.q,{actions:[D.update,D.create],fallback:x.contextSrv.isEditor},a.status.state===E.Z9.Suppressed&&e.createElement(N.Qj,{href:`${(0,R.eQ)("/alerting/silences",f)}&silenceIds=${a.status.silencedBy.join(",")}`,className:m.button,icon:"bell",size:"sm"},"Manage silences"),a.status.state===E.Z9.Active&&e.createElement(N.Qj,{href:(0,R.VN)(f,a.labels),className:m.button,icon:"bell-slash",size:"sm"},"Silence")),u&&a.generatorURL&&e.createElement(N.Qj,{className:m.button,href:a.generatorURL,icon:"chart-line",size:"sm"},"See source")),Object.entries(a.annotations).map(([M,X])=>e.createElement(L.a,{key:M,annotationKey:M,value:X})),e.createElement("div",{className:m.receivers},"Receivers:"," ",a.receivers.map(({name:M})=>M).filter(M=>!!M).join(", ")))},z=a=>({button:(0,s.css)`
    & + & {
      margin-left: ${a.spacing(1)};
    }
  `,actionsRow:(0,s.css)`
    padding: ${a.spacing(2,0)} !important;
    border-bottom: 1px solid ${a.colors.border.medium};
  `,receivers:(0,s.css)`
    padding: ${a.spacing(1,0)};
  `}),Z=({alerts:a,alertManagerSourceName:f})=>{const m=(0,v.wW)(Q),D=(0,e.useMemo)(()=>[{id:"state",label:"State",renderCell:({data:u})=>e.createElement(e.Fragment,null,e.createElement(d.G,{state:u.status.state}),e.createElement("span",{className:m.duration},"for"," ",(0,S.vT)({start:new Date(u.startsAt),end:new Date(u.endsAt)}))),size:"220px"},{id:"labels",label:"Labels",renderCell:({data:{labels:u}})=>e.createElement(G.s,{labels:u,size:"sm"}),size:1}],[m]),P=(0,e.useMemo)(()=>a.map(u=>({id:u.fingerprint,data:u})),[a]);return e.createElement("div",{className:m.tableWrapper,"data-testid":"alert-group-table"},e.createElement(W.F,{cols:D,items:P,isExpandable:!0,renderExpandedContent:({data:u})=>e.createElement(U,{alert:u,alertManagerSourceName:f})}))},Q=a=>({tableWrapper:(0,s.css)`
    margin-top: ${a.spacing(3)};
    ${a.breakpoints.up("md")} {
      margin-left: ${a.spacing(4.5)};
    }
  `,duration:(0,s.css)`
    margin-left: ${a.spacing(1)};
    font-size: ${a.typography.bodySmall.fontSize};
  `});var H=t(33273);const J=({alertManagerSourceName:a,group:f})=>{const[m,D]=(0,e.useState)(!0),P=(0,v.wW)(V);return e.createElement("div",{className:P.wrapper},e.createElement("div",{className:P.header},e.createElement("div",{className:P.group,"data-testid":"alert-group"},e.createElement(h.U,{size:"sm",isCollapsed:m,onToggle:()=>D(!m),"data-testid":"alert-group-collapse-toggle"}),Object.keys(f.labels).length?e.createElement(G.s,{labels:f.labels,size:"sm"}):e.createElement("span",null,"No grouping")),e.createElement(H.Z,{group:f})),!m&&e.createElement(Z,{alertManagerSourceName:a,alerts:f.alerts}))},V=a=>({wrapper:(0,s.css)`
    & + & {
      margin-top: ${a.spacing(2)};
    }
  `,header:(0,s.css)`
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    padding: ${a.spacing(1,1,1,0)};
    background-color: ${a.colors.background.secondary};
    width: 100%;
  `,group:(0,s.css)`
    display: flex;
    flex-direction: row;
    align-items: center;
  `,summary:(0,s.css)``,spanElement:(0,s.css)`
    margin-left: ${a.spacing(.5)};
  `,[E.Z9.Active]:(0,s.css)`
    color: ${a.colors.error.main};
  `,[E.Z9.Suppressed]:(0,s.css)`
    color: ${a.colors.primary.main};
  `,[E.Z9.Unprocessed]:(0,s.css)`
    color: ${a.colors.secondary.main};
  `})},22201:(B,C,t)=>{t.d(C,{G:()=>G});var s=t(27702),e=t(62862),v=t(6949);const E={[e.Z9.Active]:"bad",[e.Z9.Unprocessed]:"neutral",[e.Z9.Suppressed]:"info"},G=({state:h})=>s.createElement(v.i,{state:E[h]},h)}}]);

//# sourceMappingURL=AlertGroups.db5f0995ecf7bb8b3b38.js.map