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

//# sourceMappingURL=AlertGroups.61716ade3d714651828e.js.map