"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[2415],{49653:(j,O,e)=>{e.r(O),e.d(O,{default:()=>T});var a=e(66681),t=e(85960),i=e(47257),y=e(79468),f=e(49199),h=e(763),C=e(95162),x=e(16901),p=e(81828),G=e(65892),m=e(19311),d=e(29165),A=e(77294),D=e(57445),F=e(5106);const L=({onStateFilterChange:c,stateFilter:g})=>{const P=(0,i.wW)(U),v=Object.entries(x.Z9).sort(([r],[s])=>r<s?-1:1).map(([r,s])=>({label:r,value:s}));return t.createElement("div",{className:P.wrapper},t.createElement(D._,null,"State"),t.createElement(F.S,{options:v,value:g,onChange:c}))},U=c=>({wrapper:(0,a.css)`
    margin-left: ${c.spacing(1)};
  `});var R=e(56375),J=e(27436),z=e(97666);const Y=({className:c,groups:g,groupBy:P,onGroupingChange:v})=>{const r=(0,R.uniq)(g.flatMap(s=>s.alerts).flatMap(({labels:s})=>Object.keys(s))).filter(s=>!(s.startsWith("__")&&s.endsWith("__"))).map(s=>({label:s,value:s}));return t.createElement("div",{"data-testid":"group-by-container",className:c},t.createElement(D._,null,"Custom group by"),t.createElement(J.NU,{"aria-label":"group by label keys",value:P,placeholder:"Group by",prefix:t.createElement(z.J,{name:"tag-alt"}),onChange:s=>{v(s.map(({value:E})=>E))},options:r}))};var V=e(69737);const X=({groups:c})=>{const[g,P]=(0,t.useState)(Math.floor(Math.random()*100)),[v,r]=(0,h.K)(),{groupBy:s=[],queryString:E,alertState:b}=(0,A.lC)(v),N=`matcher-${g}`,W=(0,i.wW)(w),$=()=>{r({groupBy:null,queryString:null,alertState:null}),setTimeout(()=>P(g+1),100)},ee=!!(s.length>0||E||b);return t.createElement("div",{className:W.wrapper},t.createElement("div",{className:W.filterSection},t.createElement(V.F,{className:W.filterInput,key:N,defaultQueryString:E,onFilterChange:I=>r({queryString:I||null})}),t.createElement(Y,{className:W.filterInput,groups:c,groupBy:s,onGroupingChange:I=>r({groupBy:I.length?I.join(","):null})}),t.createElement(L,{stateFilter:b,onStateFilterChange:I=>r({alertState:I||null})}),ee&&t.createElement(d.zx,{className:W.clearButton,variant:"secondary",icon:"times",onClick:$},"Clear filters")))},w=c=>({wrapper:(0,a.css)`
    border-bottom: 1px solid ${c.colors.border.medium};
    margin-bottom: ${c.spacing(3)};
  `,filterSection:(0,a.css)`
    display: flex;
    flex-direction: row;
    margin-bottom: ${c.spacing(3)};
  `,filterInput:(0,a.css)`
    width: 340px;
    & + & {
      margin-left: ${c.spacing(1)};
    }
  `,clearButton:(0,a.css)`
    margin-left: ${c.spacing(1)};
    margin-top: 19px;
  `});var Z=e(98724);const k=c=>{const[g]=(0,h.K)(),P=(0,A.lC)(g),v=(0,Z.Zh)(P.queryString||"");return(0,t.useMemo)(()=>c.reduce((r,s)=>{const E=s.alerts.filter(({labels:b,status:N})=>{const W=(0,Z.eD)(b,v),$=P.alertState?N.state===P.alertState:!0;return W&&$});return E.length>0&&(Object.keys(s.labels).length===0?r.unshift({...s,alerts:E}):r.push({...s,alerts:E})),r},[]),[c,P,v])},Q=(c,g)=>(0,t.useMemo)(()=>g.length===0?c.filter(r=>Object.keys(r.labels).length===0).length>1?c.reduce((r,s)=>{if(Object.keys(s.labels).length===0){const E=r.find(({labels:b})=>Object.keys(b));E?E.alerts=(0,R.uniqBy)([...E.alerts,...s.alerts],"labels"):r.push({alerts:s.alerts,labels:{},receiver:{name:"NONE"}})}else r.push(s);return r},[]):c:c.flatMap(({alerts:v})=>v).reduce((v,r)=>{if(g.every(E=>Object.keys(r.labels).includes(E))){const E=v.find(b=>g.every(N=>b.labels[N]===r.labels[N]));if(E)E.alerts.push(r);else{const b=g.reduce((N,W)=>(N={...N,[W]:r.labels[W]},N),{});v.push({alerts:[r],labels:b,receiver:{name:"NONE"}})}}else{const E=v.find(b=>Object.keys(b.labels).length===0);E?E.alerts.push(r):v.push({alerts:[r],labels:{},receiver:{name:"NONE"}})}return v},[]),[c,g]);var l=e(92746),M=e(84954),S=e(5970),o=e(46002),u=e(76679),n=e(30422);const B=()=>{const{useGetAlertmanagerChoiceStatusQuery:c}=p.alertmanagerApi,{selectedAlertmanager:g}=(0,M.ZA)(),P=(0,C.useDispatch)(),[v]=(0,h.K)(),{groupBy:r=[]}=(0,A.lC)(v),s=(0,i.wW)(H),{currentData:E}=c(),b=(0,l._)(K=>K.amAlertGroups),{loading:N,error:W,result:$=[]}=b[g||""]??n.oq,ee=Q($,r),I=k(ee),te=g===u.GC&&E?.alertmanagersChoice===x.TE.External;return(0,t.useEffect)(()=>{function K(){g&&P((0,S.mS)(g))}K();const _=setInterval(K,o.iF);return()=>{clearInterval(_)}},[P,g]),t.createElement(t.Fragment,null,t.createElement(X,{groups:$}),N&&t.createElement(y.u,{text:"Loading notifications"}),W&&!N&&t.createElement(f.b,{title:"Error loading notifications",severity:"error"},W.message||"Unknown error"),te&&t.createElement(f.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."),$&&I.map((K,_)=>t.createElement(t.Fragment,{key:`${JSON.stringify(K.labels)}-group-${_}`},(_===1&&Object.keys(I[0].labels).length===0||_===0&&Object.keys(K.labels).length>0)&&t.createElement("p",{className:s.groupingBanner},"Grouped by: ",Object.keys(K.labels).join(", ")),t.createElement(m.y,{alertManagerSourceName:g||"",group:K}))),$&&!I.length&&t.createElement("p",null,"No results."))},q=()=>t.createElement(G.O,{navId:"groups",accessType:"instance"},t.createElement(B,null)),H=c=>({groupingBanner:(0,a.css)`
    margin: ${c.spacing(2,0)};
  `}),T=q},65892:(j,O,e)=>{e.d(O,{J:()=>Q,O:()=>l});var a=e(85960),t=e(8134),i=e(20989),y=e(90857),f=e(79055),h=e(66681),C=e(6753),x=e(47257),p=e(74042),G=e(14607),m=e(29165),d=e(49199);const A=({localStoreKey:o,startClosed:u=!1,severity:n="error",collapseText:B,collapseTooltip:q,collapseJustify:H="flex-end",alertTitle:T,children:c})=>{const g=(0,x.l4)(),P=D(g,n),[v,r]=(0,C.Z)(o,u);return a.createElement(a.Fragment,null,v&&a.createElement(p.Lh,{justify:H},a.createElement(G.u,{content:q,placement:"bottom"},a.createElement(m.zx,{fill:"text",variant:"secondary",icon:(0,d.j)(n),className:P.warningButton,onClick:()=>r(!1)},B))),!v&&a.createElement(d.b,{severity:n,title:T,onRemove:()=>r(!0)},c))},D=(o,u)=>{const n=o.colors[u];return{warningButton:(0,h.css)({color:n.text,"&:hover":{background:n.transparent}})}},F="grafana.unifiedalerting.upgrade.previewNotice",L=()=>y.config.unifiedAlertingEnabled||!y.config.featureToggles.alertingPreviewUpgrade?null:a.createElement(A,{localStoreKey:F,alertTitle:"This is a preview of the upgraded Grafana Alerting",collapseText:"Grafana Alerting Preview",collapseTooltip:"Show preview warning",severity:"warning"},a.createElement("p",null,"No rules are being evaluated and legacy alerting is still running.",a.createElement("br",null),"Please contact your administrator to upgrade permanently."),a.createElement(f.h,{external:!0,href:"https://grafana.com/docs/grafana/latest/alerting/set-up/migrating-alerts/"},"Read about upgrading"));var U=e(84954),R=e(84933),J=e(27436),z=e(76679);function Y(o){return o.name===z.GC?"Grafana":o.name.slice(0,37)}const V=({disabled:o=!1})=>{const u=(0,x.wW)(X),{selectedAlertmanager:n,availableAlertManagers:B,setSelectedAlertmanager:q}=(0,U.ZA)(),H=(0,a.useMemo)(()=>B.map(T=>({label:Y(T),value:T.name,imgUrl:T.imgUrl,meta:T.meta})),[B]);return a.createElement(R._,{className:u.field,label:o?"Alertmanager":"Choose Alertmanager",disabled:o||H.length===1,"data-testid":"alertmanager-picker"},a.createElement(J.Ph,{"aria-label":o?"Alertmanager":"Choose Alertmanager",width:29,className:"ds-picker select-container",backspaceRemovesValue:!1,onChange:T=>{T?.value&&q(T.value)},options:H,maxMenuHeight:500,noOptionsMessage:"No datasources found",value:n,getOptionLabel:T=>T.label}))},X=o=>({field:(0,h.css)`
    margin: 0;
  `}),w=()=>a.createElement(d.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."),Z=()=>a.createElement(d.b,{title:"Selected Alertmanager not found.",severity:"warning"},"The selected Alertmanager no longer exists or you may not have permission to access it. You can select a different Alertmanager from the dropdown."),k=({availableAlertManagers:o})=>{const u=o.length>0;return a.createElement("div",null,u?a.createElement(Z,null):a.createElement(w,null))},Q=({children:o,isLoading:u,...n})=>a.createElement(i.T,{...n},a.createElement(i.T.Contents,{isLoading:u},a.createElement("div",null,a.createElement(L,null),o))),l=({children:o,accessType:u,...n})=>{const B=M();return a.createElement(U.h5,{accessType:u},a.createElement(Q,{...n,actions:a.createElement(V,{disabled:B})},a.createElement(S,null,o)))};function M(){const o=(0,t.Z)();return["/edit","/new"].some(n=>o?.pathname?.includes(n))}const S=({children:o})=>{const{availableAlertManagers:u,selectedAlertmanager:n}=(0,U.ZA)();return n?a.createElement(a.Fragment,null,o):a.createElement(k,{availableAlertManagers:u})}},53914:(j,O,e)=>{e.d(O,{q:()=>f});var a=e(56375),t=e.n(a),i=e(85960),y=e(57297);const f=({actions:m,children:d})=>{const A=(0,a.filter)(m,p),D=(0,a.filter)(m,G);return A.length?i.createElement(h,{actions:A},d):D.length?i.createElement(C,{actions:D},d):null},h=({actions:m,children:d})=>{const A=(0,y.Mz)();return x(A,m)?i.createElement(i.Fragment,null,d):null},C=({actions:m,children:d})=>{const A=(0,y.K_)();return x(A,m)?i.createElement(i.Fragment,null,d):null};function x(m,d){return(0,a.chain)(m).pick(d).values().value().some(([A,D])=>D===!0)}function p(m){return Object.values(y.oI).includes(m)}function G(m){return Object.values(y.jU).includes(m)}},25661:(j,O,e)=>{e.d(O,{F:()=>f});var a=e(66681),t=e(85960),i=e(47257),y=e(79253);const f=({renderExpandedContent:C,...x})=>{const p=(0,i.wW)(h);return t.createElement(y.t,{renderExpandedContent:C?(G,m,d)=>t.createElement(t.Fragment,null,m!==d.length-1&&t.createElement("div",{className:(0,a.cx)(p.contentGuideline,p.guideline)}),C(G,m,d)):void 0,renderPrefixHeader:()=>t.createElement("div",{className:p.relative},t.createElement("div",{className:(0,a.cx)(p.headerGuideline,p.guideline)})),renderPrefixCell:(G,m,d)=>t.createElement("div",{className:p.relative},t.createElement("div",{className:(0,a.cx)(p.topGuideline,p.guideline)}),m!==d.length-1&&t.createElement("div",{className:(0,a.cx)(p.bottomGuideline,p.guideline)})),...x})},h=C=>({relative:(0,a.css)`
    position: relative;
    height: 100%;
  `,guideline:(0,a.css)`
    left: -19px;
    border-left: 1px solid ${C.colors.border.weak};
    position: absolute;

    ${C.breakpoints.down("md")} {
      display: none;
    }
  `,topGuideline:(0,a.css)`
    width: 18px;
    border-bottom: 1px solid ${C.colors.border.medium};
    top: 0;
    bottom: 50%;
  `,bottomGuideline:(0,a.css)`
    top: 50%;
    bottom: 0;
  `,contentGuideline:(0,a.css)`
    top: 0;
    bottom: 0;
    left: -49px !important;
  `,headerGuideline:(0,a.css)`
    top: -17px;
    bottom: 0;
  `})},46911:(j,O,e)=>{e.d(O,{g:()=>C});var a=e(66681),t=e(85960),i=e(47257),y=e(40377),f=e(13086),h=e(97666);const C=({children:p,icon:G,color:m="secondary",direction:d="row",...A})=>{const D=(0,i.wW)(x),F=typeof A.onClick=="function",L=d==="row",U=L?"center":"flex-start",R=L?.5:0;return t.createElement("div",{className:(0,a.cx)({[D.interactive]:F}),...A},t.createElement(y.x,{variant:"bodySmall",color:m},t.createElement(f.K,{direction:d,alignItems:U,gap:R,wrap:"wrap"},G&&t.createElement(h.J,{size:"sm",name:G}),p)))},x=()=>({interactive:(0,a.css)`
    cursor: pointer;
  `})},35855:(j,O,e)=>{e.d(O,{c:()=>i});var a=e(85960),t=e(47257);const i=({children:y})=>{const f=(0,t.l4)();return a.createElement("strong",{style:{color:f.colors.text.primary}},y)}},19311:(j,O,e)=>{e.d(O,{y:()=>k});var a=e(66681),t=e(85960),i=e(47257),y=e(13086),f=e(16901),h=e(2698),C=e(44211),x=e(46911),p=e(35855),G=e(18678),m=e(25661),d=e(30209),A=e(29165),D=e(41879),F=e(95162),L=e(57297),U=e(76679),R=e(77294),J=e(87921),z=e(53914);const Y=({alert:l,alertManagerSourceName:M})=>{const S=(0,i.wW)(V),u=(0,U.HY)(M)?D.contextSrv.hasPermission(F.AccessControlAction.AlertingRuleRead):!0;return t.createElement(t.Fragment,null,t.createElement("div",{className:S.actionsRow},l.status.state===f.Z9.Suppressed&&t.createElement(z.q,{actions:[L.oI.CreateSilence,L.oI.UpdateSilence]},t.createElement(A.Qj,{href:`${(0,R.eQ)("/alerting/silences",M)}&silenceIds=${l.status.silencedBy.join(",")}`,className:S.button,icon:"bell",size:"sm"},"Manage silences")),l.status.state===f.Z9.Active&&t.createElement(z.q,{actions:[L.oI.CreateSilence]},t.createElement(A.Qj,{href:(0,R.VN)(M,l.labels),className:S.button,icon:"bell-slash",size:"sm"},"Silence")),u&&l.generatorURL&&t.createElement(A.Qj,{className:S.button,href:l.generatorURL,icon:"chart-line",size:"sm"},"See source")),Object.entries(l.annotations).map(([n,B])=>t.createElement(J.a,{key:n,annotationKey:n,value:B})),t.createElement("div",{className:S.receivers},"Receivers:"," ",l.receivers.map(({name:n})=>n).filter(n=>!!n).join(", ")))},V=l=>({button:(0,a.css)`
    & + & {
      margin-left: ${l.spacing(1)};
    }
  `,actionsRow:(0,a.css)`
    padding: ${l.spacing(2,0)} !important;
    border-bottom: 1px solid ${l.colors.border.medium};
  `,receivers:(0,a.css)`
    padding: ${l.spacing(1,0)};
  `}),X=({alerts:l,alertManagerSourceName:M})=>{const S=(0,i.wW)(w),o=(0,t.useMemo)(()=>[{id:"state",label:"State",renderCell:({data:n})=>t.createElement(t.Fragment,null,t.createElement(d.G,{state:n.status.state}),t.createElement("span",{className:S.duration},"for"," ",(0,G.vT)({start:new Date(n.startsAt),end:new Date(n.endsAt)}))),size:"220px"},{id:"labels",label:"Labels",renderCell:({data:{labels:n}})=>t.createElement(h.s,{labels:n,size:"sm"}),size:1}],[S]),u=(0,t.useMemo)(()=>l.map(n=>({id:n.fingerprint,data:n})),[l]);return t.createElement("div",{className:S.tableWrapper,"data-testid":"alert-group-table"},t.createElement(m.F,{cols:o,items:u,isExpandable:!0,renderExpandedContent:({data:n})=>t.createElement(Y,{alert:n,alertManagerSourceName:M})}))},w=l=>({tableWrapper:(0,a.css)`
    margin-top: ${l.spacing(3)};
    ${l.breakpoints.up("md")} {
      margin-left: ${l.spacing(4.5)};
    }
  `,duration:(0,a.css)`
    margin-left: ${l.spacing(1)};
    font-size: ${l.typography.bodySmall.fontSize};
  `});var Z=e(44412);const k=({alertManagerSourceName:l,group:M})=>{const[S,o]=(0,t.useState)(!0),u=(0,i.wW)(Q),n=M.receiver.name!=="NONE";return t.createElement("div",{className:u.wrapper},t.createElement("div",{className:u.header},t.createElement("div",{className:u.group,"data-testid":"alert-group"},t.createElement(C.U,{size:"sm",isCollapsed:S,onToggle:()=>o(!S),"data-testid":"alert-group-collapse-toggle"}),Object.keys(M.labels).length?t.createElement(y.K,{direction:"row",alignItems:"center"},t.createElement(h.s,{labels:M.labels,size:"sm"}),n&&t.createElement(x.g,{icon:"at"},"Delivered to ",t.createElement(p.c,null,M.receiver.name))):t.createElement("span",null,"No grouping")),t.createElement(Z.Z,{group:M})),!S&&t.createElement(X,{alertManagerSourceName:l,alerts:M.alerts}))},Q=l=>({wrapper:(0,a.css)({"& + &":{marginTop:l.spacing(2)}}),header:(0,a.css)({display:"flex",flexDirection:"row",flexWrap:"wrap",alignItems:"center",justifyContent:"space-between",padding:`${l.spacing(1)} ${l.spacing(1)} ${l.spacing(1)} 0`,backgroundColor:l.colors.background.secondary,width:"100%"}),group:(0,a.css)({display:"flex",flexDirection:"row",alignItems:"center"}),summary:(0,a.css)({}),[f.Z9.Active]:(0,a.css)({color:l.colors.error.main}),[f.Z9.Suppressed]:(0,a.css)({color:l.colors.primary.main}),[f.Z9.Unprocessed]:(0,a.css)({color:l.colors.secondary.main})})},30209:(j,O,e)=>{e.d(O,{G:()=>f});var a=e(85960),t=e(16901),i=e(65825);const y={[t.Z9.Active]:"bad",[t.Z9.Unprocessed]:"neutral",[t.Z9.Suppressed]:"info"},f=({state:h})=>a.createElement(i.i,{state:y[h]},h)}}]);

//# sourceMappingURL=AlertGroups.67e27b78a9a387f25201.js.map