"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[7680],{30315:(K,P,a)=>{a.r(P),a.d(P,{default:()=>fe});var e=a(66111),R=a(45524),o=a(9892),c=a(72648),x=a(45253),$=a(27876),B=a(29614),D=a(23403),O=a(69945),y=a(72004),g=a(45849),p=a(46818),T=a(94984),N=a(67483),G=a(52081),Y=a(8581),U=a(31403),F=a(30173),H=a(94270),b=a(24799),X=a(97379),w=a(98102);const Q=({defaultValues:t,readOnly:l,loading:n,alertManagerSourceName:s,showConfirmDeleteAMConfig:d,onSubmit:u,onReset:r,onConfirmReset:i,onDismiss:A})=>e.createElement(H.l,{defaultValues:t,onSubmit:u,key:t.configJSON},({register:m,errors:f})=>e.createElement(e.Fragment,null,!l&&e.createElement(e.Fragment,null,e.createElement(b.g,{disabled:n,label:"Configuration",invalid:!!f.configJSON,error:f.configJSON?.message},e.createElement(X.K,{...m("configJSON",{required:{value:!0,message:"Required."},validate:v=>{try{return JSON.parse(v),!0}catch(S){return S instanceof Error?S.message:"Invalid JSON."}}}),id:"configuration",rows:25})),e.createElement(G.Lh,null,e.createElement(U.zx,{type:"submit",variant:"primary",disabled:n},"Save configuration"),r&&e.createElement(U.zx,{type:"button",disabled:n,variant:"destructive",onClick:r},"Reset configuration"))),l&&e.createElement(b.g,{label:"Configuration"},e.createElement("pre",{"data-testid":"readonly-config"},t.configJSON)),Boolean(d)&&i&&A&&e.createElement(w.s,{isOpen:!0,title:"Reset Alertmanager configuration",body:`Are you sure you want to reset configuration ${s===g.GC?"for the Grafana Alertmanager":`for "${s}"`}? Contact points and notification policies will be reset to their defaults.`,confirmText:"Yes, reset configuration",onConfirm:i,onDismiss:A})));function k({onChange:t,selectedAmConfig:l,defaultValues:n,onSubmit:s,readOnly:d,loading:u}){const{useGetValidAlertManagersConfigQuery:r,useResetAlertManagerConfigToOldVersionMutation:i}=F.h,A=(0,c.wW)(q),{currentData:m,isLoading:f}=r(),[v]=i(),S=(0,e.useMemo)(()=>{if(!m?.length)return[];const E=m.map(M=>{const L=new Date(M.last_applied);return{label:M.last_applied?`Config from ${L.toLocaleString()} (${(0,N.CQ)(L).locale("en").fromNow(!0)} ago)`:"Previous config",value:M}});return t(E[0]),E},[m,t]),h=async()=>{const E=l?.value?.id;E!==void 0&&v({id:E})};return e.createElement(e.Fragment,null,!f&&m&&m.length>0?e.createElement(e.Fragment,null,e.createElement("div",null,"Select a previous working configuration until you fix this error:"),e.createElement("div",{className:A.container},e.createElement(G.Lh,{align:"flex-start",spacing:"md"},e.createElement(Y.Ph,{options:S,value:l,onChange:E=>{t(E)}}),e.createElement(U.zx,{variant:"primary",disabled:u,onClick:h},"Reset to selected configuration"))),e.createElement(Q,{defaultValues:n,onSubmit:E=>s(E),readOnly:d,loading:u,alertManagerSourceName:g.GC})):null)}const q=t=>({container:o.css`
    margin-top: ${t.spacing(2)};
    margin-bottom: ${t.spacing(2)};
  `});function _(){const t=(0,$.useDispatch)(),l=(0,D.k)("notification"),[n,s]=(0,B.k)(l),[d,u]=(0,e.useState)(!1),{loading:r}=(0,O._)(C=>C.deleteAMConfig),{loading:i}=(0,O._)(C=>C.saveAMConfig),A=n?(0,g.RY)(n):!1,m=(0,c.wW)(ee),f=(0,O._)(C=>C.amConfigs),[v,S]=(0,e.useState)(),{result:h,loading:E,error:M}=n&&f[n]||p.oq;(0,e.useEffect)(()=>{n&&t((0,y.Yh)(n))},[n,t]);const L=()=>{n&&t((0,y.Nc)(n)),u(!1)},Ee=(0,e.useMemo)(()=>({configJSON:h?JSON.stringify(h,null,2):""}),[h]),ve=(0,e.useMemo)(()=>({configJSON:v?JSON.stringify(v.value,null,2):""}),[v]),Z=r||E||i,V=C=>{n&&h&&t((0,y.mM)({newConfig:JSON.parse(C.configJSON),oldConfig:h,alertManagerSourceName:n,successMessage:"Alertmanager configuration updated.",refetch:!0}))};return e.createElement("div",{className:m.container},e.createElement(T.P,{current:n,onChange:s,dataSources:l}),M&&!Z&&e.createElement(e.Fragment,null,e.createElement(x.b,{severity:"error",title:"Your Alertmanager configuration is incorrect. These are the details of the error:"},M.message||"Unknown error."),n===g.GC&&e.createElement(k,{onChange:S,selectedAmConfig:v,defaultValues:ve,readOnly:!0,loading:Z,onSubmit:V})),r&&n!==g.GC&&e.createElement(x.b,{severity:"info",title:"Resetting Alertmanager configuration"},"It might take a while..."),n&&h&&e.createElement(Q,{defaultValues:Ee,onSubmit:C=>V(C),readOnly:A,loading:Z,alertManagerSourceName:n,showConfirmDeleteAMConfig:d,onReset:()=>u(!0),onConfirmReset:L,onDismiss:()=>u(!1)}))}const ee=t=>({container:o.css`
    margin-bottom: ${t.spacing(4)};
  `});var te=a(2594),ae=a(96488),W=a(39031),J=a(82897);function ne(){const{useGetExternalAlertmanagersQuery:t}=F.h,{currentData:l}=t(),n=(0,g.aM)().filter(r=>r.jsonData.handleGrafanaManagedAlerts),s=(0,$.useSelector)(r=>(0,J.keyBy)(r.dataSources.dataSources.filter(i=>i.type==="alertmanager"),i=>i.uid)),d=(0,J.countBy)(l?.droppedAlertManagers,r=>r.url),u=(0,J.countBy)(l?.activeAlertManagers,r=>r.url);return n.map(r=>{const i=s[r.uid];if(!i)return{dataSource:r,status:"pending"};const m=`${re(i)}/api/v2/alerts`,f=d[m]??0,v=u[m]??0,S=f>0,h=v>0,E=f+v>1,M=S?"dropped":h?"active":"pending";return{dataSource:r,url:i.url,status:M,statusInconclusive:E}})}function re(t){return new RegExp("^[^:]*://").test(t.url)?t.url:`http://${t.url}`}var le=a(97097),I=a(72948),oe=a(61860),se=a(39904),z=a(19985),ie=a(10505);function ce({alertmanagers:t,inactive:l}){const n=(0,c.wW)(j);return e.createElement(e.Fragment,null,e.createElement("h5",null,"Alertmanagers Receiving Grafana-managed alerts"),e.createElement("div",{className:n.muted},"Alertmanager data sources support a configuration setting that allows you to choose to send Grafana-managed alerts to that Alertmanager. ",e.createElement("br",null),"Below, you can see the list of all Alertmanager data sources that have this setting enabled."),t.length===0&&e.createElement(le._,{message:e.createElement("div",null,"There are no Alertmanager data sources configured to receive Grafana-managed alerts. ",e.createElement("br",null),"You can change this by selecting Receive Grafana Alerts in a data source configuration."),callToActionElement:e.createElement(U.Qj,{href:"/datasources"},"Go to data sources"),className:n.externalDsCTA}),t.length>0&&e.createElement("div",{className:n.externalDs},t.map(s=>e.createElement(ge,{key:s.dataSource.uid,alertmanager:s,inactive:l}))))}function ge({alertmanager:t,inactive:l}){const n=(0,c.wW)(j),{dataSource:s,status:d,statusInconclusive:u,url:r}=t;return e.createElement(I.Z,null,e.createElement(I.Z.Heading,{className:n.externalHeading},s.name," ",u&&e.createElement(oe.u,{content:"Multiple Alertmanagers have the same URL configured. The state might be inconclusive."},e.createElement(se.J,{name:"exclamation-triangle",size:"md",className:n.externalWarningIcon}))),e.createElement(I.Z.Figure,null,e.createElement("img",{src:"public/app/plugins/datasource/alertmanager/img/logo.svg",alt:"",height:"40px",width:"40px",style:{objectFit:"contain"}})),e.createElement(I.Z.Tags,null,l?e.createElement(z.C,{text:"Inactive",color:"red",tooltip:"Grafana is configured to send alerts to the built-in internal Alertmanager only. External Alertmanagers do not receive any alerts."}):e.createElement(z.C,{text:(0,J.capitalize)(d),color:d==="dropped"?"red":d==="active"?"green":"orange"})),e.createElement(I.Z.Meta,null,r),e.createElement(I.Z.Actions,null,e.createElement(U.Qj,{href:(0,ie.__)(s),size:"sm",variant:"secondary"},"Go to datasource")))}const j=t=>({muted:o.css`
    font-size: ${t.typography.bodySmall.fontSize};
    line-height: ${t.typography.bodySmall.lineHeight};
    color: ${t.colors.text.secondary};
  `,externalHeading:o.css`
    justify-content: flex-start;
  `,externalWarningIcon:o.css`
    margin: ${t.spacing(0,1)};
    fill: ${t.colors.warning.main};
  `,externalDs:o.css`
    display: grid;
    gap: ${t.spacing(1)};
    padding: ${t.spacing(2,0)};
  `,externalDsCTA:o.css`
    margin: ${t.spacing(2,0)};
  `}),ue=[{value:W.TE.Internal,label:"Only Internal"},{value:W.TE.External,label:"Only External"},{value:W.TE.All,label:"Both internal and external"}],me=()=>{const t=(0,c.wW)(de),l=(0,$.useDispatch)(),n=ne(),{useSaveExternalAlertmanagersConfigMutation:s,useGetExternalAlertmanagerConfigQuery:d,useGetExternalAlertmanagersQuery:u}=F.h,[r]=s(),{currentData:i}=d();u(void 0,{pollingInterval:5e3});const A=i?.alertmanagersChoice;(0,e.useEffect)(()=>{l((0,ae.bZ)())},[l]);const m=f=>{r({alertmanagersChoice:f})};return e.createElement("div",null,e.createElement("h4",null,"External Alertmanagers"),e.createElement(x.b,{title:"External Alertmanager changes",severity:"info"},"The way you configure external Alertmanagers has changed.",e.createElement("br",null),"You can now use configured Alertmanager data sources as receivers of your Grafana-managed alerts.",e.createElement("br",null),"For more information, refer to our documentation."),e.createElement("div",{className:t.amChoice},e.createElement(b.g,{label:"Send alerts to",description:"Configures how the Grafana alert rule evaluation engine Alertmanager handles your alerts. Internal (Grafana built-in Alertmanager), External (All Alertmanagers configured below), or both."},e.createElement(te.S,{options:ue,value:A,onChange:f=>m(f)}))),e.createElement(ce,{alertmanagers:n,inactive:A===W.TE.Internal}))},de=t=>({url:o.css`
    margin-right: ${t.spacing(1)};
  `,actions:o.css`
    margin-top: ${t.spacing(2)};
    display: flex;
    justify-content: flex-end;
  `,table:o.css`
    margin-bottom: ${t.spacing(2)};
  `,amChoice:o.css`
    margin-bottom: ${t.spacing(4)};
  `});function fe(){const t=(0,D.k)("notification"),[l]=(0,B.k)(t),n=l===g.GC;return e.createElement(R.J,{pageId:"alerting-admin"},e.createElement(_,{"test-id":"admin-alertmanagerconfig"}),n&&e.createElement(me,{"test-id":"admin-externalalertmanagers"}))}},29614:(K,P,a)=>{a.d(P,{k:()=>B});var e=a(66111),R=a(96044),o=a(58379),c=a(37190),x=a(45849);function $(D){return(0,e.useCallback)(O=>D.map(g=>g.name).includes(O),[D])}function B(D){const[O,y]=(0,R.K)(),g=$(D),p=(0,e.useCallback)(G=>{g(G)&&(G===x.GC?(o.Z.delete(c.de),y({[c.c4]:null})):(o.Z.set(c.de,G),y({[c.c4]:G})))},[y,g]),T=O[c.c4];if(T&&typeof T=="string")return g(T)?[T,p]:[void 0,p];const N=o.Z.get(c.de);return N&&typeof N=="string"&&g(N)?(p(N),[N,p]):g(x.GC)?[x.GC,p]:[void 0,p]}},23403:(K,P,a)=>{a.d(P,{k:()=>o});var e=a(66111),R=a(45849);function o(c){return(0,e.useMemo)(()=>(0,R.LE)(c),[c])}}}]);

//# sourceMappingURL=AlertingAdmin.0b1f5bf856c27c2be54c.js.map