"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[7680],{74460:(W,A,a)=>{a.r(A),a.d(A,{default:()=>ce});var e=a(68404),p=a(45524),r=a(9892),l=a(72648),x=a(45253),J=a(94270),T=a(24799),D=a(97379),I=a(52081),u=a(31403),m=a(98102),g=a(81168),M=a(29614),h=a(23403),y=a(69945),L=a(72004),G=a(45849),Y=a(46818),H=a(94984);function V(){const t=(0,g.useDispatch)(),o=(0,h.k)("notification"),[n,i]=(0,M.k)(o),[d,f]=(0,e.useState)(!1),{loading:s}=(0,y._)(v=>v.deleteAMConfig),{loading:c}=(0,y._)(v=>v.saveAMConfig),S=n?(0,G.RY)(n):!1,P=(0,l.wW)(X),C=(0,y._)(v=>v.amConfigs),{result:E,loading:K,error:B}=n&&C[n]||Y.oq;(0,e.useEffect)(()=>{n&&t((0,L.Yh)(n))},[n,t]);const Z=()=>{n&&t((0,L.Nc)(n)),f(!1)},N=(0,e.useMemo)(()=>({configJSON:E?JSON.stringify(E,null,2):""}),[E]),$=s||K||c,ge=v=>{n&&E&&t((0,L.mM)({newConfig:JSON.parse(v.configJSON),oldConfig:E,alertManagerSourceName:n,successMessage:"Alertmanager configuration updated.",refetch:!0}))};return e.createElement("div",{className:P.container},e.createElement(H.P,{current:n,onChange:i,dataSources:o}),B&&!$&&e.createElement(x.b,{severity:"error",title:"Error loading Alertmanager configuration"},B.message||"Unknown error."),s&&n!==G.GC&&e.createElement(x.b,{severity:"info",title:"Resetting Alertmanager configuration"},"It might take a while..."),n&&E&&e.createElement(J.l,{defaultValues:N,onSubmit:ge,key:N.configJSON},({register:v,errors:Q})=>e.createElement(e.Fragment,null,!S&&e.createElement(T.g,{disabled:$,label:"Configuration",invalid:!!Q.configJSON,error:Q.configJSON?.message},e.createElement(D.K,{...v("configJSON",{required:{value:!0,message:"Required."},validate:ue=>{try{return JSON.parse(ue),!0}catch(b){return b instanceof Error?b.message:"Invalid JSON."}}}),id:"configuration",rows:25})),S&&e.createElement(T.g,{label:"Configuration"},e.createElement("pre",{"data-testid":"readonly-config"},N.configJSON)),!S&&e.createElement(I.Lh,null,e.createElement(u.zx,{type:"submit",variant:"primary",disabled:$},"Save"),e.createElement(u.zx,{type:"button",disabled:$,variant:"destructive",onClick:()=>f(!0)},"Reset configuration")),!!d&&e.createElement(m.s,{isOpen:!0,title:"Reset Alertmanager configuration",body:`Are you sure you want to reset configuration ${n===G.GC?"for the Grafana Alertmanager":`for "${n}"`}? Contact points and notification policies will be reset to their defaults.`,confirmText:"Yes, reset configuration",onConfirm:Z,onDismiss:()=>f(!1)}))))}const X=t=>({container:r.css`
    margin-bottom: ${t.spacing(4)};
  `});var w=a(2594),k=a(96488),R=a(39031),j=a(30173),U=a(82897);function q(){const{useGetExternalAlertmanagersQuery:t}=j.h,{currentData:o}=t(),n=(0,G.aM)().filter(s=>s.jsonData.handleGrafanaManagedAlerts),i=(0,g.useSelector)(s=>(0,U.keyBy)(s.dataSources.dataSources.filter(c=>c.type==="alertmanager"),c=>c.uid)),d=(0,U.countBy)(o?.droppedAlertManagers,s=>s.url),f=(0,U.countBy)(o?.activeAlertManagers,s=>s.url);return n.map(s=>{const c=i[s.uid];if(!c)return{dataSource:s,status:"pending"};const P=`${_(c)}/api/v2/alerts`,C=d[P]??0,E=f[P]??0,K=C>0,B=E>0,Z=C+E>1,N=K?"dropped":B?"active":"pending";return{dataSource:s,url:c.url,status:N,statusInconclusive:Z}})}function _(t){return new RegExp("^[^:]*://").test(t.url)?t.url:`http://${t.url}`}var ee=a(97097),O=a(72948),ae=a(6554),te=a(39904),z=a(19985),ne=a(10505);function re({alertmanagers:t,inactive:o}){const n=(0,l.wW)(F);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(ee._,{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(i=>e.createElement(le,{key:i.dataSource.uid,alertmanager:i,inactive:o}))))}function le({alertmanager:t,inactive:o}){const n=(0,l.wW)(F),{dataSource:i,status:d,statusInconclusive:f,url:s}=t;return e.createElement(O.Z,null,e.createElement(O.Z.Heading,{className:n.externalHeading},i.name," ",f&&e.createElement(ae.u,{content:"Multiple Alertmanagers have the same URL configured. The state might be inconclusive."},e.createElement(te.J,{name:"exclamation-triangle",size:"md",className:n.externalWarningIcon}))),e.createElement(O.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(O.Z.Tags,null,o?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,U.capitalize)(d),color:d==="dropped"?"red":d==="active"?"green":"orange"})),e.createElement(O.Z.Meta,null,s),e.createElement(O.Z.Actions,null,e.createElement(u.Qj,{href:(0,ne.__)(i),size:"sm",variant:"secondary"},"Go to datasource")))}const F=t=>({muted:r.css`
    font-size: ${t.typography.bodySmall.fontSize};
    line-height: ${t.typography.bodySmall.lineHeight};
    color: ${t.colors.text.secondary};
  `,externalHeading:r.css`
    justify-content: flex-start;
  `,externalWarningIcon:r.css`
    margin: ${t.spacing(0,1)};
    fill: ${t.colors.warning.main};
  `,externalDs:r.css`
    display: grid;
    gap: ${t.spacing(1)};
    padding: ${t.spacing(2,0)};
  `,externalDsCTA:r.css`
    margin: ${t.spacing(2,0)};
  `}),se=[{value:R.TE.Internal,label:"Only Internal"},{value:R.TE.External,label:"Only External"},{value:R.TE.All,label:"Both internal and external"}],oe=()=>{const t=(0,l.wW)(ie),o=(0,g.useDispatch)(),n=q(),{useSaveExternalAlertmanagersConfigMutation:i,useGetExternalAlertmanagerConfigQuery:d,useGetExternalAlertmanagersQuery:f}=j.h,[s]=i(),{currentData:c}=d();f(void 0,{pollingInterval:5e3});const S=c?.alertmanagersChoice;(0,e.useEffect)(()=>{o((0,k.bZ)())},[o]);const P=C=>{s({alertmanagersChoice:C})};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(T.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(w.S,{options:se,value:S,onChange:C=>P(C)}))),e.createElement(re,{alertmanagers:n,inactive:S===R.TE.Internal}))},ie=t=>({url:r.css`
    margin-right: ${t.spacing(1)};
  `,actions:r.css`
    margin-top: ${t.spacing(2)};
    display: flex;
    justify-content: flex-end;
  `,table:r.css`
    margin-bottom: ${t.spacing(2)};
  `,amChoice:r.css`
    margin-bottom: ${t.spacing(4)};
  `});function ce(){const t=(0,h.k)("notification"),[o]=(0,M.k)(t),n=o===G.GC;return e.createElement(p.J,{pageId:"alerting-admin"},e.createElement(V,{"test-id":"admin-alertmanagerconfig"}),n&&e.createElement(oe,{"test-id":"admin-externalalertmanagers"}))}},30173:(W,A,a)=>{a.d(A,{h:()=>p});var e=a(29427);const p=e.C.injectEndpoints({endpoints:r=>({getAlertmanagerChoiceStatus:r.query({query:()=>({url:"/api/v1/ngalert"}),providesTags:["AlertmanagerChoice"]}),getExternalAlertmanagerConfig:r.query({query:()=>({url:"/api/v1/ngalert/admin_config"}),providesTags:["AlertmanagerChoice"]}),getExternalAlertmanagers:r.query({query:()=>({url:"/api/v1/ngalert/alertmanagers"}),transformResponse:l=>l.data}),saveExternalAlertmanagersConfig:r.mutation({query:l=>({url:"/api/v1/ngalert/admin_config",method:"POST",data:l}),invalidatesTags:["AlertmanagerChoice"]})})})},29614:(W,A,a)=>{a.d(A,{k:()=>T});var e=a(68404),p=a(96044),r=a(58379),l=a(37190),x=a(45849);function J(D){return(0,e.useCallback)(I=>D.map(m=>m.name).includes(I),[D])}function T(D){const[I,u]=(0,p.K)(),m=J(D),g=(0,e.useCallback)(y=>{m(y)&&(y===x.GC?(r.Z.delete(l.de),u({[l.c4]:null})):(r.Z.set(l.de,y),u({[l.c4]:y})))},[u,m]),M=I[l.c4];if(M&&typeof M=="string")return m(M)?[M,g]:[void 0,g];const h=r.Z.get(l.de);return h&&typeof h=="string"&&m(h)?(g(h),[h,g]):m(x.GC)?[x.GC,g]:[void 0,g]}},23403:(W,A,a)=>{a.d(A,{k:()=>r});var e=a(68404),p=a(45849);function r(l){return(0,e.useMemo)(()=>(0,p.LE)(l),[l])}}}]);

//# sourceMappingURL=AlertingAdmin.128439ea65d4be909dcc.js.map