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

//# sourceMappingURL=AlertingAdmin.646a1a6042523c5627a3.js.map