"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[7680],{74460:(U,g,a)=>{a.r(g),a.d(g,{default:()=>ce});var e=a(68404),u=a(45524),r=a(52423),l=a(72648),d=a(45253),I=a(94270),x=a(24799),O=a(97379),G=a(52081),f=a(31403),E=a(98102),m=a(81168),S=a(29614),C=a(23403),p=a(69945),J=a(72004),N=a(45849),b=a(46818),H=a(94984);function V(){const t=(0,m.useDispatch)(),o=(0,C.k)("notification"),[n,i]=(0,S.k)(o),[v,A]=(0,e.useState)(!1),{loading:s}=(0,p._)(y=>y.deleteAMConfig),{loading:c}=(0,p._)(y=>y.saveAMConfig),D=n?(0,N.RY)(n):!1,T=(0,l.wW)(X),M=(0,p._)(y=>y.amConfigs),{result:h,loading:K,error:$}=n&&M[n]||b.oq;(0,e.useEffect)(()=>{n&&t((0,J.Yh)(n))},[n,t]);const Z=()=>{n&&t((0,J.Nc)(n)),A(!1)},R=(0,e.useMemo)(()=>({configJSON:h?JSON.stringify(h,null,2):""}),[h]),L=s||K||c,ge=y=>{n&&h&&t((0,J.mM)({newConfig:JSON.parse(y.configJSON),oldConfig:h,alertManagerSourceName:n,successMessage:"Alertmanager configuration updated.",refetch:!0}))};return e.createElement("div",{className:T.container},e.createElement(H.P,{current:n,onChange:i,dataSources:o}),$&&!L&&e.createElement(d.b,{severity:"error",title:"Error loading Alertmanager configuration"},$.message||"Unknown error."),s&&n!==N.GC&&e.createElement(d.b,{severity:"info",title:"Resetting Alertmanager configuration"},"It might take a while..."),n&&h&&e.createElement(I.l,{defaultValues:R,onSubmit:ge,key:R.configJSON},({register:y,errors:Q})=>e.createElement(e.Fragment,null,!D&&e.createElement(x.g,{disabled:L,label:"Configuration",invalid:!!Q.configJSON,error:Q.configJSON?.message},e.createElement(O.K,{...y("configJSON",{required:{value:!0,message:"Required."},validate:ue=>{try{return JSON.parse(ue),!0}catch(Y){return Y instanceof Error?Y.message:"Invalid JSON."}}}),id:"configuration",rows:25})),D&&e.createElement(x.g,{label:"Configuration"},e.createElement("pre",{"data-testid":"readonly-config"},R.configJSON)),!D&&e.createElement(G.Lh,null,e.createElement(f.zx,{type:"submit",variant:"primary",disabled:L},"Save"),e.createElement(f.zx,{type:"button",disabled:L,variant:"destructive",onClick:()=>A(!0)},"Reset configuration")),!!v&&e.createElement(E.s,{isOpen:!0,title:"Reset Alertmanager configuration",body:`Are you sure you want to reset configuration ${n===N.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:()=>A(!1)}))))}const X=t=>({container:r.css`
    margin-bottom: ${t.spacing(4)};
  `});var w=a(2594),k=a(40897),B=a(39031),j=a(30173),W=a(82897);function q(){const{useGetExternalAlertmanagersQuery:t}=j.h,{currentData:o}=t(),n=(0,N.aM)().filter(s=>s.jsonData.handleGrafanaManagedAlerts),i=(0,m.useSelector)(s=>(0,W.keyBy)(s.dataSources.dataSources.filter(c=>c.type==="alertmanager"),c=>c.uid)),v=(0,W.countBy)(o?.droppedAlertManagers,s=>s.url),A=(0,W.countBy)(o?.activeAlertManagers,s=>s.url);return n.map(s=>{const c=i[s.uid];if(!c)return{dataSource:s,status:"pending"};const T=`${_(c)}/api/v2/alerts`,M=v[T]??0,h=A[T]??0,K=M>0,$=h>0,Z=M+h>1,R=K?"dropped":$?"active":"pending";return{dataSource:s,url:c.url,status:R,statusInconclusive:Z}})}function _(t){return new RegExp("^[^:]*://").test(t.url)?t.url:`http://${t.url}`}var ee=a(97097),P=a(72948),ae=a(61860),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(f.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:v,statusInconclusive:A,url:s}=t;return e.createElement(P.Z,null,e.createElement(P.Z.Heading,{className:n.externalHeading},i.name," ",A&&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(P.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(P.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,W.capitalize)(v),color:v==="dropped"?"red":v==="active"?"green":"orange"})),e.createElement(P.Z.Meta,null,s),e.createElement(P.Z.Actions,null,e.createElement(f.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:B.TE.Internal,label:"Only Internal"},{value:B.TE.External,label:"Only External"},{value:B.TE.All,label:"Both internal and external"}],oe=()=>{const t=(0,l.wW)(ie),o=(0,m.useDispatch)(),n=q(),{useSaveExternalAlertmanagersConfigMutation:i,useGetExternalAlertmanagerConfigQuery:v,useGetExternalAlertmanagersQuery:A}=j.h,[s]=i(),{currentData:c}=v();A(void 0,{pollingInterval:5e3});const D=c?.alertmanagersChoice;(0,e.useEffect)(()=>{o((0,k.bZ)())},[o]);const T=M=>{s({alertmanagersChoice:M})};return e.createElement("div",null,e.createElement("h4",null,"External Alertmanagers"),e.createElement(d.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(x.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:D,onChange:M=>T(M)}))),e.createElement(re,{alertmanagers:n,inactive:D===B.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,C.k)("notification"),[o]=(0,S.k)(t),n=o===N.GC;return e.createElement(u.J,{pageId:"alerting-admin"},e.createElement(V,{"test-id":"admin-alertmanagerconfig"}),n&&e.createElement(oe,{"test-id":"admin-externalalertmanagers"}))}},30173:(U,g,a)=>{a.d(g,{h:()=>u});var e=a(29427);const u=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"]})})})},45524:(U,g,a)=>{a.d(g,{J:()=>r});var e=a(68404),u=a(79396);const r=({children:l,pageId:d,pageNav:I,isLoading:x})=>e.createElement(u.T,{pageNav:I,navId:d},e.createElement(u.T.Contents,{isLoading:x},l))},29614:(U,g,a)=>{a.d(g,{k:()=>x});var e=a(68404),u=a(96044),r=a(58379),l=a(37190),d=a(45849);function I(O){return(0,e.useCallback)(G=>O.map(E=>E.name).includes(G),[O])}function x(O){const[G,f]=(0,u.K)(),E=I(O),m=(0,e.useCallback)(p=>{E(p)&&(p===d.GC?(r.Z.delete(l.de),f({[l.c4]:null})):(r.Z.set(l.de,p),f({[l.c4]:p})))},[f,E]),S=G[l.c4];if(S&&typeof S=="string")return E(S)?[S,m]:[void 0,m];const C=r.Z.get(l.de);return C&&typeof C=="string"&&E(C)?(m(C),[C,m]):E(d.GC)?[d.GC,m]:[void 0,m]}},23403:(U,g,a)=>{a.d(g,{k:()=>r});var e=a(68404),u=a(45849);function r(l){return(0,e.useMemo)(()=>(0,u.LE)(l),[l])}}}]);

//# sourceMappingURL=AlertingAdmin.6593bade6d942615bc04.js.map