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

//# sourceMappingURL=AlertGroups.620ef2c6f29a024f9fff.js.map