"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[6130,1488],{24513:(V,N,n)=>{n.r(N),n.d(N,{default:()=>he});var e=n(96540),O=n(37959),i=n(32196),E=n(40845),y=n(42418),R=n(31678),Y=n(51488),G=n(61410),T=n(70383),J=n(23770),h=n(57220),H=n(47232),j=n(66864),Q=n(88323),x=n(55852),I=n(82843),U=n(49785),L=n(88575),Z=n(32372),W=n(67061),K=n(96374);const F=({defaultValues:t,readOnly:a,loading:r,alertManagerSourceName:o,showConfirmDeleteAMConfig:s,onSubmit:l,onReset:A,onConfirmReset:u,onDismiss:f})=>{const{handleSubmit:d,formState:{errors:g},setValue:m,register:D}=(0,U.mN)({defaultValues:t});return D("configJSON",{required:{value:!0,message:"Required"},validate:v=>{try{return JSON.parse(v),!0}catch(c){return c instanceof Error?c.message:"JSON is invalid"}}}),e.createElement("form",{onSubmit:d(l),key:t.configJSON},e.createElement(L.D,{disabled:r,label:"Configuration",invalid:!!g.configJSON,error:g.configJSON?.message,"data-testid":a?"readonly-config":"config"},e.createElement(Z.B,{language:"json",width:"100%",height:500,showLineNumbers:!0,value:t.configJSON,showMiniMap:!1,onSave:v=>{m("configJSON",v)},onBlur:v=>{m("configJSON",v)},readOnly:a})),!a&&e.createElement(W.B,{gap:1},e.createElement(x.$n,{type:"submit",variant:"primary",disabled:r},"Save configuration"),A&&e.createElement(x.$n,{type:"button",disabled:r,variant:"destructive",onClick:A},"Reset configuration")),!!s&&u&&f&&e.createElement(K.u,{isOpen:!0,title:"Reset Alertmanager configuration",body:`Are you sure you want to reset configuration ${o===h.hY?"for the Grafana Alertmanager":`for "${o}"`}? Contact points and notification policies will be reset to their defaults.`,confirmText:"Yes, reset configuration",onConfirm:u,onDismiss:f}))};function X({onChange:t,selectedAmConfig:a,defaultValues:r,onSubmit:o,readOnly:s,loading:l}){const{useGetValidAlertManagersConfigQuery:A,useResetAlertManagerConfigToOldVersionMutation:u}=I.m,f=(0,E.of)(w),{currentData:d,isLoading:g}=A(),[m]=u(),D=(0,e.useMemo)(()=>{if(!d?.length)return[];const c=d.map(M=>{const C=new Date(M.last_applied);return{label:M.last_applied?`Config from ${C.toLocaleString()} (${(0,H.KQ)(C).locale("en").fromNow(!0)} ago)`:"Previous config",value:M}});return t(c[0]),c},[d,t]),v=async()=>{const c=a?.value?.id;c!==void 0&&m({id:c})};return e.createElement(e.Fragment,null,!g&&d&&d.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:f.container},e.createElement(j.Gy,{align:"flex-start",spacing:"md"},e.createElement(Q.l6,{options:D,value:a,onChange:c=>{t(c)}}),e.createElement(x.$n,{variant:"primary",disabled:l,onClick:v},"Reset to selected configuration"))),e.createElement(F,{defaultValues:r,onSubmit:c=>o(c),readOnly:s,loading:l,alertManagerSourceName:h.hY})):null)}const w=t=>({container:(0,i.css)`
    margin-top: ${t.spacing(2)};
    margin-bottom: ${t.spacing(2)};
  `});function k(){const t=(0,R.useDispatch)(),[a,r]=(0,e.useState)(!1),{loading:o}=(0,G.$)(p=>p.deleteAMConfig),{loading:s}=(0,G.$)(p=>p.saveAMConfig),{selectedAlertmanager:l}=(0,T.VI)(),A=l?(0,h.AL)(l):!1,u=(0,E.of)(q),[f,d]=(0,e.useState)(),{currentData:g,error:m,isLoading:D}=(0,Y.f)(l),v=()=>{l&&t((0,J.nO)(l)),r(!1)},c=(0,e.useMemo)(()=>({configJSON:g?JSON.stringify(g,null,2):""}),[g]),M=(0,e.useMemo)(()=>({configJSON:f?JSON.stringify(f.value,null,2):""}),[f]),C=o||D||s,z=p=>{l&&g&&t((0,J.RW)({newConfig:JSON.parse(p.configJSON),oldConfig:g,alertManagerSourceName:l,successMessage:"Alertmanager configuration updated."}))};return e.createElement("div",{className:u.container},m&&!C&&e.createElement(e.Fragment,null,e.createElement(y.F,{severity:"error",title:"Your Alertmanager configuration is incorrect. These are the details of the error:"},m.message||"Unknown error."),l===h.hY&&e.createElement(X,{onChange:d,selectedAmConfig:f,defaultValues:M,readOnly:!0,loading:C,onSubmit:z})),o&&l!==h.hY&&e.createElement(y.F,{severity:"info",title:"Resetting Alertmanager configuration"},"It might take a while..."),l&&g&&e.createElement(F,{defaultValues:c,onSubmit:p=>z(p),readOnly:A,loading:C,alertManagerSourceName:l,showConfirmDeleteAMConfig:a,onReset:()=>r(!0),onConfirmReset:v,onDismiss:()=>r(!1)}))}const q=t=>({container:(0,i.css)`
    margin-bottom: ${t.spacing(4)};
  `});var _=n(94354),ee=n(34258),$=n(60021),te=n(49962);const ne=te.H.injectEndpoints({endpoints:t=>({getAllDataSourceSettings:t.query({query:()=>({url:"api/datasources"}),providesTags:a=>a?a.map(({uid:r})=>({type:"DataSourceSettings",id:r})):["DataSourceSettings"]})})});function ae(){const{alertmanagerDataSources:t}=ne.endpoints.getAllDataSourceSettings.useQuery(void 0,{refetchOnReconnect:!0,selectFromResult:r=>{const o=r.currentData?.filter(h.bD)??[];return{...r,alertmanagerDataSources:o}}}),{currentData:a}=I.m.endpoints.getExternalAlertmanagers.useQuery(void 0,{refetchOnReconnect:!0});return t?t.map(r=>{const o=a?re(a,r):"unknown";return{dataSourceSettings:r,status:o}}):[]}function re(t,a){if(!a.jsonData.handleGrafanaManagedAlerts)return"uninterested";const o=t?.activeAlertManagers.some(u=>b(a.url,u.url))??[],s=t?.droppedAlertManagers.some(u=>b(a.url,u.url))??[];return!o&&!s?"pending":o&&s?"inconclusive":o?"active":s?"dropped":"unknown"}const oe="/alertmanager/api/v2/alerts",le="/api/v2/alerts";function b(t,a){const r=se(t),o=a===`${r}${le}`,s=a===`${r}${oe}`;return o||s}function se(t){return new RegExp("^[^:]*://").test(t)?t:`http://${t}`}var ie=n(2543),ce=n(76442),S=n(10860),ge=n(56034),me=n(14578),B=n(39938),ue=n(56361);function de({alertmanagers:t,inactive:a}){const r=(0,E.of)(P);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."),t.length===0&&e.createElement(ce.c,{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(x.z9,{href:"/datasources"},"Go to data sources"),className:r.externalDsCTA}),t.length>0&&e.createElement("div",{className:r.externalDs},t.map(o=>e.createElement(fe,{key:o.dataSourceSettings.uid,alertmanager:o,inactive:a}))))}function fe({alertmanager:t,inactive:a}){const r=(0,E.of)(P),{dataSourceSettings:o,status:s}=t;return e.createElement(S.Z,null,e.createElement(S.Z.Heading,{className:r.externalHeading},o.name," ",s==="inconclusive"&&e.createElement(ge.m,{content:"Multiple Alertmanagers have the same URL configured. The state might be inconclusive."},e.createElement(me.I,{name:"exclamation-triangle",size:"md",className:r.externalWarningIcon}))),e.createElement(S.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(S.Z.Tags,null,a?e.createElement(B.E,{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(B.E,{text:(0,ie.capitalize)(s),color:s==="dropped"?"red":s==="active"?"green":"orange"})),e.createElement(S.Z.Meta,null,o.url),e.createElement(S.Z.Actions,null,e.createElement(x.z9,{href:(0,ue.GD)(o.uid),size:"sm",variant:"secondary"},"Go to datasource")))}const P=t=>({muted:(0,i.css)`
    font-size: ${t.typography.bodySmall.fontSize};
    line-height: ${t.typography.bodySmall.lineHeight};
    color: ${t.colors.text.secondary};
  `,externalHeading:(0,i.css)`
    justify-content: flex-start;
  `,externalWarningIcon:(0,i.css)`
    margin: ${t.spacing(0,1)};
    fill: ${t.colors.warning.main};
  `,externalDs:(0,i.css)`
    display: grid;
    gap: ${t.spacing(1)};
    padding: ${t.spacing(2,0)};
  `,externalDsCTA:(0,i.css)`
    margin: ${t.spacing(2,0)};
  `}),Ae=[{value:$.nA.Internal,label:"Only Internal"},{value:$.nA.External,label:"Only External"},{value:$.nA.All,label:"Both internal and external"}],ve=()=>{const t=(0,E.of)(Ee),a=(0,R.useDispatch)(),o=ae().filter(m=>m.dataSourceSettings.jsonData.handleGrafanaManagedAlerts===!0),{useSaveExternalAlertmanagersConfigMutation:s,useGetExternalAlertmanagerConfigQuery:l,useGetExternalAlertmanagersQuery:A}=I.m,[u]=s(),{currentData:f}=l();A(void 0,{pollingInterval:5e3});const d=f?.alertmanagersChoice;(0,e.useEffect)(()=>{a((0,ee.bn)())},[a]);const g=m=>{u({alertmanagersChoice:m})};return e.createElement("div",null,e.createElement("h4",null,"External Alertmanagers"),e.createElement(y.F,{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(L.D,{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(_.z,{options:Ae,value:d,onChange:m=>g(m)}))),e.createElement(de,{alertmanagers:o,inactive:d===$.nA.Internal}))},Ee=t=>({url:(0,i.css)`
    margin-right: ${t.spacing(1)};
  `,actions:(0,i.css)`
    margin-top: ${t.spacing(2)};
    display: flex;
    justify-content: flex-end;
  `,table:(0,i.css)`
    margin-bottom: ${t.spacing(2)};
  `,amChoice:(0,i.css)`
    margin-bottom: ${t.spacing(4)};
  `});function he(){return e.createElement(O.y,{navId:"alerting-admin",accessType:"notification"},e.createElement(pe,null))}function pe(){const{selectedAlertmanager:t}=(0,T.VI)(),a=t===h.hY;return e.createElement(e.Fragment,null,e.createElement(k,{"test-id":"admin-alertmanagerconfig"}),a&&e.createElement(ve,{"test-id":"admin-externalalertmanagers"}))}},51488:(V,N,n)=>{n.d(N,{f:()=>O});var e=n(82843);function O(i,E){const y=e.m.endpoints.getAlertmanagerConfiguration.useQuery(i??"",{...E,skip:!i});return{...y,error:y.error}}}}]);

//# sourceMappingURL=AlertingAdmin.5b6d6bb75a0f47e3f018.js.map