"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[8427],{12564:(R,M,t)=>{t.r(M),t.d(M,{default:()=>_});var n=t(32196),e=t(96540),m=t(40845),O=t(39558),f=t(42418),b=t(83277),T=t(80348),B=t(60021),N=t(82843),j=t(33450),g=t(45067),S=t(55852),v=t(56361),G=t(60029),K=t(94354);const x=({onStateFilterChange:l,stateFilter:c})=>{const y=Object.entries(B.Or).sort(([r],[a])=>r<a?-1:1).map(([r,a])=>({label:r,value:a}));return e.createElement("div",null,e.createElement(G.J,null,"State"),e.createElement(K.z,{options:y,value:c,onChange:l}))};var F=t(2543),U=t(88323),Q=t(14578);const L=({groups:l,groupBy:c,onGroupingChange:y})=>{const r=(0,F.uniq)(l.flatMap(a=>a.alerts).flatMap(({labels:a})=>Object.keys(a))).filter(a=>!(a.startsWith("__")&&a.endsWith("__"))).map(a=>({label:a,value:a}));return e.createElement("div",{"data-testid":"group-by-container"},e.createElement(G.J,null,"Custom group by"),e.createElement(U.KF,{"aria-label":"group by label keys",value:c,placeholder:"Group by",prefix:e.createElement(Q.I,{name:"tag-alt"}),onChange:a=>{y(a.map(({value:u})=>u))},options:r,width:34}))};var H=t(53876);const J=({groups:l})=>{const[c,y]=(0,e.useState)(Math.floor(Math.random()*100)),[r,a]=(0,b.s)(),{groupBy:u=[],queryString:i,alertState:d}=(0,v.Ht)(r),h=`matcher-${c}`,A=(0,m.of)(Y),D=()=>{a({groupBy:null,queryString:null,alertState:null}),setTimeout(()=>y(c+1),100)},k=!!(u.length>0||i||d);return e.createElement("div",{className:A.wrapper},e.createElement("div",{className:A.filterSection},e.createElement(H.X,{key:h,defaultQueryString:i,onFilterChange:C=>a({queryString:C||null})}),e.createElement(L,{groups:l,groupBy:u,onGroupingChange:C=>a({groupBy:C.length?C.join(","):null})}),e.createElement(x,{stateFilter:d,onStateFilterChange:C=>a({alertState:C||null})}),k&&e.createElement(S.$n,{className:A.clearButton,variant:"secondary",icon:"times",onClick:D},"Clear filters")))},Y=l=>({wrapper:(0,n.css)`
    border-bottom: 1px solid ${l.colors.border.medium};
    margin-bottom: ${l.spacing(3)};
  `,filterSection:(0,n.css)`
    display: flex;
    flex-direction: row;
    margin-bottom: ${l.spacing(3)};
    gap: ${l.spacing(1)};
  `,clearButton:(0,n.css)`
    margin-left: ${l.spacing(1)};
    margin-top: 19px;
  `});var W=t(98164);const V=l=>{const[c]=(0,b.s)(),y=(0,v.Ht)(c),r=(0,W.J$)(y.queryString||"");return(0,e.useMemo)(()=>l.reduce((a,u)=>{const i=u.alerts.filter(({labels:d,status:h})=>{const A=(0,W.Av)(d,r),D=y.alertState?h.state===y.alertState:!0;return A&&D});return i.length>0&&(Object.keys(u.labels).length===0?a.unshift({...u,alerts:i}):a.push({...u,alerts:i})),a},[]),[l,y,r])},X=(l,c)=>(0,e.useMemo)(()=>c.length===0?l.filter(a=>Object.keys(a.labels).length===0).length>1?l.reduce((a,u)=>{if(Object.keys(u.labels).length===0){const i=a.find(({labels:d})=>Object.keys(d));i?i.alerts=(0,F.uniqBy)([...i.alerts,...u.alerts],"labels"):a.push({alerts:u.alerts,labels:{},receiver:{name:"NONE"}})}else a.push(u);return a},[]):l:(0,F.uniqBy)(l.flatMap(({alerts:r})=>r),r=>r.fingerprint).reduce((r,a)=>{if(c.every(i=>Object.keys(a.labels).includes(i)))a.receivers.map(d=>({alerts:[a],labels:c.reduce((h,A)=>(h={...h,[A]:a.labels[A]},h),{}),receiver:d})).forEach(d=>{const h=r.find(A=>Object.keys(d.labels).every(D=>A.labels[D]===d.labels[D])&&A.receiver.name===d.receiver.name);h?h.alerts.push(a):r.push(d)});else{const i=r.find(d=>Object.keys(d.labels).length===0);i?i.alerts.push(a):r.push({alerts:[a],labels:{},receiver:{name:"NONE"}})}return r},[]),[l,c]);var Z=t(61410),s=t(70383),p=t(23770),E=t(55740),I=t(57220),P=t(88467);const o=()=>{const{useGetAlertmanagerChoiceStatusQuery:l}=N.m,{selectedAlertmanager:c}=(0,s.VI)(),y=(0,T.useDispatch)(),[r]=(0,b.s)(),{groupBy:a=[]}=(0,v.Ht)(r),u=(0,m.of)(q),{currentData:i}=l(),d=(0,Z.$)($=>$.amAlertGroups),{loading:h,error:A,result:D=[]}=d[c||""]??P.jA,k=X(D,a),C=V(k),ee=c===I.hY&&i?.alertmanagersChoice===B.nA.External;return(0,e.useEffect)(()=>{function $(){c&&y((0,p.D3)(c))}$();const z=setInterval($,E.U3);return()=>{clearInterval(z)}},[y,c]),e.createElement(e.Fragment,null,e.createElement(J,{groups:D}),h&&e.createElement(O._,{text:"Loading notifications"}),A&&!h&&e.createElement(f.F,{title:"Error loading notifications",severity:"error"},A.message||"Unknown error"),ee&&e.createElement(f.F,{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."),D&&C.map(($,z)=>e.createElement(e.Fragment,{key:`${JSON.stringify($.labels)}-group-${z}`},(z===1&&Object.keys(C[0].labels).length===0||z===0&&Object.keys($.labels).length>0)&&e.createElement("p",{className:u.groupingBanner},"Grouped by: ",Object.keys($.labels).join(", ")),e.createElement(g._,{alertManagerSourceName:c||"",group:$}))),D&&!C.length&&e.createElement("p",null,"No results."))},w=()=>e.createElement(j.y,{navId:"groups",accessType:"instance"},e.createElement(o,null)),q=l=>({groupingBanner:(0,n.css)`
    margin: ${l.spacing(2,0)};
  `}),_=w},64853:(R,M,t)=>{t.d(M,{_:()=>f});var n=t(2543),e=t.n(n),m=t(96540),O=t(19073);const f=({actions:g,children:S})=>{const v=(0,n.filter)(g,N),G=(0,n.filter)(g,j);return v.length?m.createElement(b,{actions:v},S):G.length?m.createElement(T,{actions:G},S):null},b=({actions:g,children:S})=>{const v=(0,O.iI)();return B(v,g)?m.createElement(m.Fragment,null,S):null},T=({actions:g,children:S})=>{const v=(0,O.e2)();return B(v,g)?m.createElement(m.Fragment,null,S):null};function B(g,S){return(0,n.chain)(g).pick(S).values().value().some(([v,G])=>G===!0)}function N(g){return Object.values(O.QI).includes(g)}function j(g){return Object.values(O.RY).includes(g)}},94855:(R,M,t)=>{t.d(M,{O:()=>m});var n=t(96540),e=t(40845);const m=({children:O})=>{const f=(0,e.$j)();return n.createElement("strong",{style:{color:f.colors.text.primary}},O)}},45067:(R,M,t)=>{t.d(M,{_:()=>X});var n=t(32196),e=t(96540),m=t(40845),O=t(67061),f=t(60021),b=t(69087),T=t(64047),B=t(55196),N=t(94855),j=t(70416),g=t(10562),S=t(97754),v=t(55852),G=t(16233),K=t(80348),x=t(19073),F=t(57220),U=t(56361),Q=t(71223),L=t(64853);const H=({alert:s,alertManagerSourceName:p})=>{const E=(0,m.of)(J),P=(0,F.z2)(p)?G.TP.hasPermission(K.AccessControlAction.AlertingRuleRead):!0;return e.createElement(e.Fragment,null,e.createElement("div",{className:E.actionsRow},s.status.state===f.Or.Suppressed&&e.createElement(L._,{actions:[x.QI.CreateSilence,x.QI.UpdateSilence]},e.createElement(v.z9,{href:`${(0,U.nL)("/alerting/silences",p)}&silenceIds=${s.status.silencedBy.join(",")}`,className:E.button,icon:"bell",size:"sm"},"Manage silences")),s.status.state===f.Or.Active&&e.createElement(L._,{actions:[x.QI.CreateSilence]},e.createElement(v.z9,{href:(0,U.BK)(p,s.labels),className:E.button,icon:"bell-slash",size:"sm"},"Silence")),P&&s.generatorURL&&e.createElement(v.z9,{className:E.button,href:s.generatorURL,icon:"chart-line",size:"sm"},"See source")),Object.entries(s.annotations).map(([o,w])=>e.createElement(Q.s,{key:o,annotationKey:o,value:w})),e.createElement("div",{className:E.receivers},"Receivers:"," ",s.receivers.map(({name:o})=>o).filter(o=>!!o).join(", ")))},J=s=>({button:(0,n.css)`
    & + & {
      margin-left: ${s.spacing(1)};
    }
  `,actionsRow:(0,n.css)`
    padding: ${s.spacing(2,0)} !important;
    border-bottom: 1px solid ${s.colors.border.medium};
  `,receivers:(0,n.css)`
    padding: ${s.spacing(1,0)};
  `}),Y=({alerts:s,alertManagerSourceName:p})=>{const E=(0,m.of)(W),I=(0,e.useMemo)(()=>[{id:"state",label:"State",renderCell:({data:o})=>e.createElement(e.Fragment,null,e.createElement(S.y,{state:o.status.state}),e.createElement("span",{className:E.duration},"for"," ",(0,j.dU)({start:new Date(o.startsAt),end:new Date(o.endsAt)}))),size:"220px"},{id:"labels",label:"Labels",renderCell:({data:{labels:o}})=>e.createElement(b.m,{labels:o,size:"sm"}),size:1}],[E]),P=(0,e.useMemo)(()=>s.map(o=>({id:o.fingerprint,data:o})),[s]);return e.createElement("div",{className:E.tableWrapper,"data-testid":"alert-group-table"},e.createElement(g.B,{cols:I,items:P,isExpandable:!0,renderExpandedContent:({data:o})=>e.createElement(H,{alert:o,alertManagerSourceName:p})}))},W=s=>({tableWrapper:(0,n.css)`
    margin-top: ${s.spacing(3)};
    ${s.breakpoints.up("md")} {
      margin-left: ${s.spacing(4.5)};
    }
  `,duration:(0,n.css)`
    margin-left: ${s.spacing(1)};
    font-size: ${s.typography.bodySmall.fontSize};
  `});var V=t(27962);const X=({alertManagerSourceName:s,group:p})=>{const[E,I]=(0,e.useState)(!0),P=(0,m.of)(Z),o=p.receiver.name!=="NONE";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(T.e,{size:"sm",isCollapsed:E,onToggle:()=>I(!E),"data-testid":"alert-group-collapse-toggle"}),Object.keys(p.labels).length?e.createElement(O.B,{direction:"row",alignItems:"center"},e.createElement(b.m,{labels:p.labels,size:"sm"}),o&&e.createElement(B.P,{icon:"at"},"Delivered to ",e.createElement(N.O,null,p.receiver.name))):e.createElement("span",null,"No grouping")),e.createElement(V.f,{group:p})),!E&&e.createElement(Y,{alertManagerSourceName:s,alerts:p.alerts}))},Z=s=>({wrapper:(0,n.css)({"& + &":{marginTop:s.spacing(2)}}),header:(0,n.css)({display:"flex",flexDirection:"row",flexWrap:"wrap",alignItems:"center",justifyContent:"space-between",padding:`${s.spacing(1)} ${s.spacing(1)} ${s.spacing(1)} 0`,backgroundColor:s.colors.background.secondary,width:"100%"}),group:(0,n.css)({display:"flex",flexDirection:"row",alignItems:"center"}),summary:(0,n.css)({}),[f.Or.Active]:(0,n.css)({color:s.colors.error.main}),[f.Or.Suppressed]:(0,n.css)({color:s.colors.primary.main}),[f.Or.Unprocessed]:(0,n.css)({color:s.colors.secondary.main})})},97754:(R,M,t)=>{t.d(M,{y:()=>f});var n=t(96540),e=t(60021),m=t(65415);const O={[e.Or.Active]:"bad",[e.Or.Unprocessed]:"neutral",[e.Or.Suppressed]:"info"},f=({state:b})=>n.createElement(m.O,{state:O[b]},b)}}]);

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