"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[7680],{18673:(e,a,r)=>{r.r(a),r.d(a,{default:()=>he});var n,t=r(68404),s=r(40256),l=r(27549),i=r(9617),o=r(8771),c=r(61692),d=r(84719),u=r(63639),g=r(25049),m=r(40920),h=r(95378),x=r(47570),f=r(82498),p=r(1698),v=r(33899),j=r(83809),b=r(19462),y=r(8455),A=r(50489),C=r(45916);function N(){var e;const a=(0,x.I0)(),r=(0,p.k)("notification"),[s,l]=(0,f.k)(r),[N,$]=(0,t.useState)(!1),{loading:S}=(0,v._)((e=>e.deleteAMConfig)),{loading:k}=(0,v._)((e=>e.saveAMConfig)),I=!!s&&(0,b.RY)(s),T=(0,i.wW)(w),E=(0,v._)((e=>e.amConfigs)),{result:O,loading:R,error:J}=s&&E[s]||y.oq;(0,t.useEffect)((()=>{s&&a((0,j.Yh)(s))}),[s,a]);const G=()=>{s&&a((0,j.Nc)(s)),$(!1)},M=(0,t.useMemo)((()=>({configJSON:O?JSON.stringify(O,null,2):""})),[O]),U=S||R||k;return(0,C.jsxs)("div",{className:T.container,children:[(0,C.jsx)(A.P,{current:s,onChange:l,dataSources:r}),J&&!U&&(0,C.jsx)(o.b,{severity:"error",title:"Error loading Alertmanager configuration",children:J.message||"Unknown error."}),S&&s!==b.GC&&(n||(n=(0,C.jsx)(o.b,{severity:"info",title:"Resetting Alertmanager configuration",children:"It might take a while..."}))),s&&O&&(0,C.jsx)(c.l,{defaultValues:M,onSubmit:e=>{s&&O&&a((0,j.mM)({newConfig:JSON.parse(e.configJSON),oldConfig:O,alertManagerSourceName:s,successMessage:"Alertmanager configuration updated.",refetch:!0}))},children:a=>{var r;let{register:n,errors:t}=a;return(0,C.jsxs)(C.Fragment,{children:[!I&&(0,C.jsx)(d.g,{disabled:U,label:"Configuration",invalid:!!t.configJSON,error:null===(r=t.configJSON)||void 0===r?void 0:r.message,children:(0,C.jsx)(u.K,Object.assign({},n("configJSON",{required:{value:!0,message:"Required."},validate:e=>{try{return JSON.parse(e),!0}catch(e){return e instanceof Error?e.message:"Invalid JSON."}}}),{id:"configuration",rows:25}))}),I&&(0,C.jsx)(d.g,{label:"Configuration",children:(0,C.jsx)("pre",{"data-testid":"readonly-config",children:M.configJSON})}),!I&&(0,C.jsxs)(g.Lh,{children:[e||(e=(0,C.jsx)(m.zx,{type:"submit",variant:"primary",disabled:U,children:"Save"})),(0,C.jsx)(m.zx,{type:"button",disabled:U,variant:"destructive",onClick:()=>$(!0),children:"Reset configuration"})]}),!!N&&(0,C.jsx)(h.s,{isOpen:!0,title:"Reset Alertmanager configuration",body:`Are you sure you want to reset configuration ${s===b.GC?"for the Grafana Alertmanager":`for "${s}"`}? Contact points and notification policies will be reset to their defaults.`,confirmText:"Yes, reset configuration",onConfirm:G,onDismiss:()=>$(!1)})]})}},M.configJSON)]})}const w=e=>({container:l.css`
    margin-bottom: ${e.spacing(4)};
  `});var $=r(96380),S=r(9442),k=r(24085),I=r(28436),T=r(94933),E=r(10331),O=r(82897);const R=/\/api\/v[1|2]\/alerts/i;function J(){const e=(0,b.aM)().filter((e=>e.jsonData.handleGrafanaManagedAlerts)),a=(0,x.v9)((e=>(0,O.keyBy)(e.dataSources.dataSources.filter((e=>"alertmanager"===e.type)),(e=>e.uid)))),r=(0,v._)((e=>{var a;return null===(a=e.externalAlertmanagers.discoveredAlertmanagers.result)||void 0===a?void 0:a.data})),n=(0,O.countBy)(null==r?void 0:r.droppedAlertManagers,(e=>e.url)),t=(0,O.countBy)(null==r?void 0:r.activeAlertManagers,(e=>e.url));return e.map((e=>{var r,s;const l=a[e.uid];if(!l)return{dataSource:e,status:"pending"};const i=function(e){if(!new RegExp("^[^:]*://").test(e.url))return`http://${e.url}`;return e.url}(l),o=`${i}/api/v2/alerts`,c=null!==(r=n[o])&&void 0!==r?r:0,d=null!==(s=t[o])&&void 0!==s?s:0,u=c+d>1,g=c>0?"dropped":d>0?"active":"pending";return{dataSource:e,url:l.url,status:g,statusInconclusive:u}}))}var G,M,U=r(59385),z=r(78056),L=r(1652);const Z=e=>{let{alertmanagers:a,onChangeAlertmanagerConfig:r,onClose:n}=e;const s=(0,i.wW)(D),l=(0,t.useMemo)((()=>({alertmanagers:a})),[a]),o=(0,C.jsxs)("div",{className:s.modalTitle,children:[(0,C.jsx)(k.J,{name:"bell",className:s.modalIcon}),G||(G=(0,C.jsx)("h3",{children:"Add Alertmanager"}))]}),u=e=>{r(e.alertmanagers.map((e=>e.url.replace(/\/$/,"").replace(/\/api\/v[1|2]\/alerts/i,"")))),n()};return(0,C.jsxs)(U.u,{title:o,isOpen:!0,onDismiss:n,className:s.modal,children:[(0,C.jsx)("div",{className:s.description,children:"We use a service discovery method to find existing Alertmanagers for a given URL."}),(0,C.jsx)(c.l,{onSubmit:u,defaultValues:l,children:e=>{let{register:a,control:r,errors:n}=e;return(0,C.jsxs)("div",{children:[(0,C.jsx)(z.F,{control:r,name:"alertmanagers",children:e=>{let{fields:r,append:t,remove:l}=e;return(0,C.jsxs)("div",{className:s.fieldArray,children:[(0,C.jsx)("div",{className:s.bold,children:"Source url"}),(0,C.jsx)("div",{className:s.muted,children:"Authentication can be done via URL (e.g. user:password@myalertmanager.com) and only the Alertmanager v2 API is supported. The suffix is added internally, there is no need to specify it."}),r.map(((e,r)=>{var t;return(0,C.jsx)(d.g,{invalid:!(null==n||null===(t=n.alertmanagers)||void 0===t||!t[r]),error:"Field is required",children:(0,C.jsx)(L.I,Object.assign({className:s.input,defaultValue:e.url},a(`alertmanagers.${r}.url`,{required:!0}),{placeholder:"http://localhost:9093",addonAfter:(0,C.jsx)(m.zx,{"aria-label":"Remove alertmanager",type:"button",onClick:()=>l(r),variant:"destructive",className:s.destroyInputRow,children:M||(M=(0,C.jsx)(k.J,{name:"trash-alt"}))})}))},`${e.id}-${r}`)})),(0,C.jsx)(m.zx,{type:"button",variant:"secondary",onClick:()=>t({url:""}),children:"Add URL"})]})}}),(0,C.jsx)("div",{children:(0,C.jsx)(m.zx,{type:"submit",onSubmit:()=>u,children:"Add Alertmanagers"})})]})}})]})};const D=e=>{const a=l.css`
    color: ${e.colors.text.secondary};
  `;return{description:(0,l.cx)(l.css`
        margin-bottom: ${e.spacing(2)};
      `,a),muted:a,bold:l.css`
      font-weight: ${e.typography.fontWeightBold};
    `,modal:l.css``,modalIcon:(0,l.cx)(a,l.css`
        margin-right: ${e.spacing(1)};
      `),modalTitle:l.css`
      display: flex;
    `,input:l.css`
      margin-bottom: ${e.spacing(1)};
      margin-right: ${e.spacing(1)};
    `,inputRow:l.css`
      display: flex;
    `,destroyInputRow:l.css`
      padding: ${e.spacing(1)};
    `,fieldArray:l.css`
      margin-bottom: ${e.spacing(4)};
    `}};var W,F,Y,_,B,q=r(74727),H=r(11340),V=r(87885),K=r(39357);function P(e){let{alertmanagers:a,inactive:r}=e;const n=(0,i.wW)(X);return(0,C.jsxs)(C.Fragment,{children:[W||(W=(0,C.jsx)("h5",{children:"Alertmanagers data sources"})),(0,C.jsxs)("div",{className:n.muted,children:["Alertmanager data sources support a configuration setting that allows you to choose to send Grafana-managed alerts to that Alertmanager. ",F||(F=(0,C.jsx)("br",{})),"Below, you can see the list of all Alertmanager data sources that have this setting enabled."]}),0===a.length&&(0,C.jsx)(q._,{message:Y||(Y=(0,C.jsxs)("div",{children:["There are no Alertmanager data sources configured to receive Grafana-managed alerts. ",(0,C.jsx)("br",{}),"You can change this by selecting Receive Grafana Alerts in a data source configuration."]})),callToActionElement:_||(_=(0,C.jsx)(m.Qj,{href:"/datasources",children:"Go to data sources"})),className:n.externalDsCTA}),a.length>0&&(0,C.jsx)("div",{className:n.externalDs,children:a.map((e=>(0,C.jsx)(Q,{alertmanager:e,inactive:r},e.dataSource.uid)))})]})}function Q(e){let{alertmanager:a,inactive:r}=e;const n=(0,i.wW)(X),{dataSource:t,status:s,statusInconclusive:l,url:o}=a;return(0,C.jsxs)(H.Z,{children:[(0,C.jsxs)(H.Z.Heading,{className:n.externalHeading,children:[t.name," ",l&&(0,C.jsx)(S.u,{content:"Multiple Alertmangers have the same URL configured. The state might be inconclusive.",children:(0,C.jsx)(k.J,{name:"exclamation-triangle",size:"md",className:n.externalWarningIcon})})]}),(0,C.jsx)(H.Z.Figure,{children:(0,C.jsx)("img",{src:"public/app/plugins/datasource/alertmanager/img/logo.svg",alt:"",height:"40px",width:"40px",style:{objectFit:"contain"}})}),(0,C.jsx)(H.Z.Tags,{children:r?B||(B=(0,C.jsx)(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."})):(0,C.jsx)(V.C,{text:(0,O.capitalize)(s),color:"dropped"===s?"red":"active"===s?"green":"orange"})}),(0,C.jsx)(H.Z.Meta,{children:o}),(0,C.jsx)(H.Z.Actions,{children:(0,C.jsx)(m.Qj,{href:(0,K.__)(t),size:"sm",variant:"secondary",children:"Go to datasource"})})]})}const X=e=>({muted:l.css`
    color: ${e.colors.text.secondary};
  `,externalHeading:l.css`
    justify-content: flex-start;
  `,externalWarningIcon:l.css`
    margin: ${e.spacing(0,1)};
    fill: ${e.colors.warning.main};
  `,externalDs:l.css`
    display: grid;
    gap: ${e.spacing(1)};
    padding: ${e.spacing(2,0)};
  `,externalDsCTA:l.css`
    margin: ${e.spacing(2,0)};
  `});var ee,ae,re,ne,te,se,le,ie,oe;const ce=[{value:E.TE.Internal,label:"Only Internal"},{value:E.TE.External,label:"Only External"},{value:E.TE.All,label:"Both internal and external"}],de=()=>{var e;const a=(0,i.wW)(ue),r=(0,x.I0)(),[n,s]=(0,t.useState)({open:!1,payload:[{url:""}]}),[c,u]=(0,t.useState)({open:!1,index:0}),f=function(){const e=(0,x.v9)((e=>{var a;return null===(a=e.unifiedAlerting.externalAlertmanagers.discoveredAlertmanagers.result)||void 0===a?void 0:a.data})),a=(0,x.v9)((e=>{var a;return null===(a=e.unifiedAlerting.externalAlertmanagers.alertmanagerConfig.result)||void 0===a?void 0:a.alertmanagers}));if(!e||!a)return[];const r=[],n=e.droppedAlertManagers.map((e=>({url:e.url.replace(R,""),status:"dropped",actualUrl:e.url})));for(const n of a)if(0===e.activeAlertManagers.length)r.push({url:n,status:"pending",actualUrl:""});else{const a=e.activeAlertManagers.find((e=>e.url===`${n}/api/v2/alerts`));a?r.push({url:a.url.replace(R,""),status:"active",actualUrl:a.url}):r.push({url:n,status:"pending",actualUrl:""})}return[...r,...n]}(),p=J(),v=(0,x.v9)((e=>{var a;return null===(a=e.unifiedAlerting.externalAlertmanagers.alertmanagerConfig.result)||void 0===a?void 0:a.alertmanagersChoice})),b=(0,i.l4)();(0,t.useEffect)((()=>{r((0,j.zy)()),r((0,j.wE)()),r((0,T.bZ)());const e=setInterval((()=>r((0,j.zy)())),5e3);return()=>{clearInterval(e)}}),[r]);const y=(0,t.useCallback)((e=>{const a=(null!=f?f:[]).filter(((a,r)=>r!==e)).map((e=>e.url));r((0,j.sx)({alertmanagers:a,alertmanagersChoice:null!=v?v:E.TE.All})),u({open:!1,index:0})}),[f,r,v]),A=(0,t.useCallback)((()=>{const e=f?[...f]:[{url:""}];s((a=>Object.assign({},a,{open:!0,payload:e})))}),[s,f]),N=(0,t.useCallback)((()=>{s((e=>{const a=f?[...f,{url:""}]:[{url:""}];return Object.assign({},e,{open:!0,payload:a})}))}),[f]),w=(0,t.useCallback)((()=>{s((e=>Object.assign({},e,{open:!1})))}),[s]),O=e=>{switch(e){case"active":return b.colors.success.main;case"pending":return b.colors.warning.main;default:return b.colors.error.main}},G=0===(null==f?void 0:f.length),M=0===(null==p?void 0:p.length),U=!(G&&M);return(0,C.jsxs)("div",{children:[ee||(ee=(0,C.jsx)("h4",{children:"External Alertmanagers"})),ae||(ae=(0,C.jsxs)(o.b,{title:"External Alertmanager changes",severity:"info",children:["The way you configure external Alertmanagers has changed.",(0,C.jsx)("br",{}),"You can now use configured Alertmanager data sources as receivers of your Grafana-managed alerts.",(0,C.jsx)("br",{}),"For more information, refer to our documentation."]})),(0,C.jsx)(P,{alertmanagers:p,inactive:v===E.TE.Internal}),U&&(0,C.jsx)("div",{className:a.amChoice,children:(0,C.jsx)(d.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 above), or both.",children:(0,C.jsx)($.S,{options:ce,value:v,onChange:e=>(e=>{r((0,j.sx)({alertmanagers:f.map((e=>e.url)),alertmanagersChoice:e}))})(e)})})}),re||(re=(0,C.jsx)("h5",{children:"Alertmanagers by URL"})),ne||(ne=(0,C.jsxs)(o.b,{severity:"warning",title:"Deprecation Notice",children:["The URL-based configuration of Alertmanagers is deprecated and will be removed in Grafana 9.2.0.",(0,C.jsx)("br",{}),"Use Alertmanager data sources to configure your external Alertmanagers."]})),(0,C.jsx)("div",{className:a.muted,children:"You can have your Grafana managed alerts be delivered to one or many external Alertmanager(s) in addition to the internal Alertmanager by specifying their URLs below."}),(0,C.jsx)("div",{className:a.actions,children:!G&&(0,C.jsx)(m.zx,{type:"button",onClick:N,children:"Add Alertmanager"})}),G?(0,C.jsx)(I.Z,{title:"You have not added any external alertmanagers",onClick:N,buttonTitle:"Add Alertmanager",buttonIcon:"bell-slash"}):(0,C.jsx)(C.Fragment,{children:(0,C.jsxs)("table",{className:(0,l.cx)("filter-table form-inline filter-table--hover",a.table),children:[(0,C.jsx)("thead",{children:(0,C.jsxs)("tr",{children:[te||(te=(0,C.jsx)("th",{children:"Url"})),se||(se=(0,C.jsx)("th",{children:"Status"})),(0,C.jsx)("th",{style:{width:"2%"},children:"Action"})]})}),(0,C.jsx)("tbody",{children:null==f?void 0:f.map(((r,n)=>(0,C.jsxs)("tr",{children:[(0,C.jsxs)("td",{children:[(0,C.jsx)("span",{className:a.url,children:r.url}),r.actualUrl?(0,C.jsx)(S.u,{content:`Discovered ${r.actualUrl} from ${r.url}`,theme:"info",children:le||(le=(0,C.jsx)(k.J,{name:"info-circle"}))}):null]}),(0,C.jsx)("td",{children:(0,C.jsx)(k.J,{name:"heart",style:{color:O(r.status)},title:r.status})}),(0,C.jsx)("td",{children:(0,C.jsxs)(g.Lh,{children:[e||(e=(0,C.jsx)(m.zx,{variant:"secondary",type:"button",onClick:A,"aria-label":"Edit alertmanager",children:ie||(ie=(0,C.jsx)(k.J,{name:"pen"}))})),(0,C.jsx)(m.zx,{variant:"destructive","aria-label":"Remove alertmanager",type:"button",onClick:()=>u({open:!0,index:n}),children:oe||(oe=(0,C.jsx)(k.J,{name:"trash-alt"}))})]})})]},n)))})]})}),(0,C.jsx)(h.s,{isOpen:c.open,title:"Remove Alertmanager",body:"Are you sure you want to remove this Alertmanager",confirmText:"Remove",onConfirm:()=>y(c.index),onDismiss:()=>u({open:!1,index:0})}),n.open&&(0,C.jsx)(Z,{onClose:w,alertmanagers:n.payload,onChangeAlertmanagerConfig:e=>{r((0,j.sx)({alertmanagers:e,alertmanagersChoice:null!=v?v:E.TE.All}))}})]})},ue=e=>({url:l.css`
    margin-right: ${e.spacing(1)};
  `,muted:l.css`
    color: ${e.colors.text.secondary};
  `,actions:l.css`
    margin-top: ${e.spacing(2)};
    display: flex;
    justify-content: flex-end;
  `,table:l.css`
    margin-bottom: ${e.spacing(2)};
  `,amChoice:l.css`
    margin-bottom: ${e.spacing(4)};
  `});var ge,me;function he(){const e=(0,p.k)("notification"),[a]=(0,f.k)(e),r=a===b.GC;return(0,C.jsxs)(s.J,{pageId:"alerting-admin",children:[ge||(ge=(0,C.jsx)(N,{"test-id":"admin-alertmanagerconfig"})),r&&(me||(me=(0,C.jsx)(de,{"test-id":"admin-externalalertmanagers"})))]})}},40256:(e,a,r)=>{r.d(a,{J:()=>s});r(68404);var n=r(90894),t=r(45916);const s=e=>{let{children:a,pageId:r,pageNav:s,isLoading:l}=e;return(0,t.jsx)(n.T,{pageNav:s,navId:r,children:(0,t.jsx)(n.T.Contents,{isLoading:l,children:a})})}},82498:(e,a,r)=>{r.d(a,{k:()=>o});var n=r(68404),t=r(26011),s=r(17421),l=r(85464),i=r(19462);function o(e){const[a,r]=(0,t.K)(),o=function(e){return(0,n.useCallback)((a=>e.map((e=>e.name)).includes(a)),[e])}(e),c=(0,n.useCallback)((e=>{o(e)&&(e===i.GC?(s.Z.delete(l.de),r({[l.c4]:null})):(s.Z.set(l.de,e),r({[l.c4]:e})))}),[r,o]),d=a[l.c4];if(d&&"string"==typeof d)return o(d)?[d,c]:[void 0,c];const u=s.Z.get(l.de);return u&&"string"==typeof u&&o(u)?(c(u),[u,c]):o(i.GC)?[i.GC,c]:[void 0,c]}},1698:(e,a,r)=>{r.d(a,{k:()=>s});var n=r(68404),t=r(19462);function s(e){return(0,n.useMemo)((()=>(0,t.LE)(e)),[e])}}}]);
//# sourceMappingURL=AlertingAdmin.e8ac89228a289dd5f765.js.map