"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[7680],{39137:(K,x,t)=>{t.r(x),t.d(x,{default:()=>ge});var e=t(27702),I=t(81324),o=t(42844),v=t(66310),h=t(63439),P=t(18771),F=t(97529),C=t(10027),M=t(1469),R=t(47702),p=t(22513),Z=t(99633),U=t(64022),c=t(28580),g=t(66670),b=t(52646),W=t(23839),G=t(22209),B=t(11649),z=t(3613);const J=({defaultValues:a,readOnly:l,loading:r,alertManagerSourceName:s,showConfirmDeleteAMConfig:d,onSubmit:n,onReset:E,onConfirmReset:y,onDismiss:m})=>e.createElement(W.l,{defaultValues:a,onSubmit:n,key:a.configJSON},({errors:u,setValue:i,register:O})=>(O("configJSON",{required:{value:!0,message:"Required"},validate:A=>{try{return JSON.parse(A),!0}catch(N){return N instanceof Error?N.message:"JSON is invalid"}}}),e.createElement(e.Fragment,null,e.createElement(G.g,{disabled:r,label:"Configuration",invalid:!!u.configJSON,error:u.configJSON?.message,"data-testid":l?"readonly-config":"config"},e.createElement(B.p,{language:"json",width:"100%",height:500,showLineNumbers:!0,value:a.configJSON,showMiniMap:!1,onSave:A=>{i("configJSON",A)},onBlur:A=>{i("configJSON",A)},readOnly:l})),!l&&e.createElement(U.Lh,null,e.createElement(g.zx,{type:"submit",variant:"primary",disabled:r},"Save configuration"),E&&e.createElement(g.zx,{type:"button",disabled:r,variant:"destructive",onClick:E},"Reset configuration")),!!d&&y&&m&&e.createElement(z.s,{isOpen:!0,title:"Reset Alertmanager configuration",body:`Are you sure you want to reset configuration ${s===p.GC?"for the Grafana Alertmanager":`for "${s}"`}? Contact points and notification policies will be reset to their defaults.`,confirmText:"Yes, reset configuration",onConfirm:y,onDismiss:m}))));function Q({onChange:a,selectedAmConfig:l,defaultValues:r,onSubmit:s,readOnly:d,loading:n}){const{useGetValidAlertManagersConfigQuery:E,useResetAlertManagerConfigToOldVersionMutation:y}=b.alertmanagerApi,m=(0,v.wW)(j),{currentData:u,isLoading:i}=E(),[O]=y(),A=(0,e.useMemo)(()=>{if(!u?.length)return[];const f=u.map($=>{const T=new Date($.last_applied);return{label:$.last_applied?`Config from ${T.toLocaleString()} (${(0,Z.CQ)(T).locale("en").fromNow(!0)} ago)`:"Previous config",value:$}});return a(f[0]),f},[u,a]),N=async()=>{const f=l?.value?.id;f!==void 0&&O({id:f})};return e.createElement(e.Fragment,null,!i&&u&&u.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:m.container},e.createElement(U.Lh,{align:"flex-start",spacing:"md"},e.createElement(c.Ph,{options:A,value:l,onChange:f=>{a(f)}}),e.createElement(g.zx,{variant:"primary",disabled:n,onClick:N},"Reset to selected configuration"))),e.createElement(J,{defaultValues:r,onSubmit:f=>s(f),readOnly:d,loading:n,alertManagerSourceName:p.GC})):null)}const j=a=>({container:(0,o.css)`
    margin-top: ${a.spacing(2)};
    margin-bottom: ${a.spacing(2)};
  `});function X(){const a=(0,P.useDispatch)(),[l,r]=(0,e.useState)(!1),{loading:s}=(0,C._)(S=>S.deleteAMConfig),{loading:d}=(0,C._)(S=>S.saveAMConfig),{selectedAlertmanager:n}=(0,M.Z)(),E=n?(0,p.RY)(n):!1,y=(0,v.wW)(w),[m,u]=(0,e.useState)(),{currentData:i,error:O,isLoading:A}=(0,F.W)(n),N=()=>{n&&a((0,R.Nc)(n)),r(!1)},f=(0,e.useMemo)(()=>({configJSON:i?JSON.stringify(i,null,2):""}),[i]),$=(0,e.useMemo)(()=>({configJSON:m?JSON.stringify(m.value,null,2):""}),[m]),T=s||A||d,H=S=>{n&&i&&a((0,R.mM)({newConfig:JSON.parse(S.configJSON),oldConfig:i,alertManagerSourceName:n,successMessage:"Alertmanager configuration updated.",refetch:!0}))};return e.createElement("div",{className:y.container},O&&!T&&e.createElement(e.Fragment,null,e.createElement(h.b,{severity:"error",title:"Your Alertmanager configuration is incorrect. These are the details of the error:"},O.message||"Unknown error."),n===p.GC&&e.createElement(Q,{onChange:u,selectedAmConfig:m,defaultValues:$,readOnly:!0,loading:T,onSubmit:H})),s&&n!==p.GC&&e.createElement(h.b,{severity:"info",title:"Resetting Alertmanager configuration"},"It might take a while..."),n&&i&&e.createElement(J,{defaultValues:f,onSubmit:S=>H(S),readOnly:E,loading:T,alertManagerSourceName:n,showConfirmDeleteAMConfig:l,onReset:()=>r(!0),onConfirmReset:N,onDismiss:()=>r(!1)}))}const w=a=>({container:(0,o.css)`
    margin-bottom: ${a.spacing(4)};
  `});var k=t(40705),q=t(58473),L=t(62862),_=t(94752),ee=t(89949),te=t(60801),D=t(50230),ae=t(80011),ne=t(73453),V=t(25357),re=t(39036);function le({alertmanagers:a,inactive:l}){const r=(0,v.wW)(Y);return e.createElement(e.Fragment,null,e.createElement("h5",null,"Alertmanagers Receiving Grafana-managed alerts"),e.createElement("div",{className:r.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."),a.length===0&&e.createElement(te._,{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(g.Qj,{href:"/datasources"},"Go to data sources"),className:r.externalDsCTA}),a.length>0&&e.createElement("div",{className:r.externalDs},a.map(s=>e.createElement(oe,{key:s.dataSource.uid,alertmanager:s,inactive:l}))))}function oe({alertmanager:a,inactive:l}){const r=(0,v.wW)(Y),{dataSource:s,status:d,statusInconclusive:n,url:E}=a;return e.createElement(D.Z,null,e.createElement(D.Z.Heading,{className:r.externalHeading},s.name," ",n&&e.createElement(ae.u,{content:"Multiple Alertmanagers have the same URL configured. The state might be inconclusive."},e.createElement(ne.J,{name:"exclamation-triangle",size:"md",className:r.externalWarningIcon}))),e.createElement(D.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(D.Z.Tags,null,l?e.createElement(V.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(V.C,{text:(0,ee.capitalize)(d),color:d==="dropped"?"red":d==="active"?"green":"orange"})),e.createElement(D.Z.Meta,null,E),e.createElement(D.Z.Actions,null,e.createElement(g.Qj,{href:(0,re.__)(s),size:"sm",variant:"secondary"},"Go to datasource")))}const Y=a=>({muted:(0,o.css)`
    font-size: ${a.typography.bodySmall.fontSize};
    line-height: ${a.typography.bodySmall.lineHeight};
    color: ${a.colors.text.secondary};
  `,externalHeading:(0,o.css)`
    justify-content: flex-start;
  `,externalWarningIcon:(0,o.css)`
    margin: ${a.spacing(0,1)};
    fill: ${a.colors.warning.main};
  `,externalDs:(0,o.css)`
    display: grid;
    gap: ${a.spacing(1)};
    padding: ${a.spacing(2,0)};
  `,externalDsCTA:(0,o.css)`
    margin: ${a.spacing(2,0)};
  `}),se=[{value:L.TE.Internal,label:"Only Internal"},{value:L.TE.External,label:"Only External"},{value:L.TE.All,label:"Both internal and external"}],ie=()=>{const a=(0,v.wW)(ce),l=(0,P.useDispatch)(),r=(0,_.S)(),{useSaveExternalAlertmanagersConfigMutation:s,useGetExternalAlertmanagerConfigQuery:d,useGetExternalAlertmanagersQuery:n}=b.alertmanagerApi,[E]=s(),{currentData:y}=d();n(void 0,{pollingInterval:5e3});const m=y?.alertmanagersChoice;(0,e.useEffect)(()=>{l((0,q.bZ)())},[l]);const u=i=>{E({alertmanagersChoice:i})};return e.createElement("div",null,e.createElement("h4",null,"External Alertmanagers"),e.createElement(h.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:a.amChoice},e.createElement(G.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(k.S,{options:se,value:m,onChange:i=>u(i)}))),e.createElement(le,{alertmanagers:r,inactive:m===L.TE.Internal}))},ce=a=>({url:(0,o.css)`
    margin-right: ${a.spacing(1)};
  `,actions:(0,o.css)`
    margin-top: ${a.spacing(2)};
    display: flex;
    justify-content: flex-end;
  `,table:(0,o.css)`
    margin-bottom: ${a.spacing(2)};
  `,amChoice:(0,o.css)`
    margin-bottom: ${a.spacing(4)};
  `});function ge(){return e.createElement(I.O,{pageId:"alerting-admin",accessType:"notification"},e.createElement(me,null))}function me(){const{selectedAlertmanager:a}=(0,M.Z)(),l=a===p.GC;return e.createElement(e.Fragment,null,e.createElement(X,{"test-id":"admin-alertmanagerconfig"}),l&&e.createElement(ie,{"test-id":"admin-externalalertmanagers"}))}},97529:(K,x,t)=>{t.d(x,{W:()=>I});var e=t(52646);function I(o,v){const h=e.alertmanagerApi.endpoints.getAlertmanagerConfiguration.useQuery(o??"",{...v,skip:!o});return{...h,error:h.error}}},94752:(K,x,t)=>{t.d(x,{S:()=>P});var e=t(89949),I=t.n(e),o=t(18771),v=t(52646),h=t(22513);function P(){const{useGetExternalAlertmanagersQuery:C}=v.alertmanagerApi,{currentData:M}=C(),R=(0,h.aM)().filter(c=>c.jsonData.handleGrafanaManagedAlerts),p=(0,o.useSelector)(c=>(0,e.keyBy)(c.dataSources.dataSources.filter(g=>g.type==="alertmanager"),g=>g.uid)),Z=(0,e.countBy)(M?.droppedAlertManagers,c=>c.url),U=(0,e.countBy)(M?.activeAlertManagers,c=>c.url);return R.map(c=>{const g=p[c.uid];if(!g)return{dataSource:c,status:"pending"};const W=`${F(g)}/api/v2/alerts`,G=Z[W]??0,B=U[W]??0,z=G>0,J=B>0,Q=G+B>1,j=z?"dropped":J?"active":"pending";return{dataSource:c,url:g.url,status:j,statusInconclusive:Q}})}function F(C){return new RegExp("^[^:]*://").test(C.url)?C.url:`http://${C.url}`}}}]);

//# sourceMappingURL=AlertingAdmin.2eebc81f8530b883b778.js.map