"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[7680,335],{19135:(ie,D,t)=>{t.r(D),t.d(D,{default:()=>ue});var e=t(85960),J=t(65892),g=t(66681),C=t(47257),M=t(49199),P=t(95162),w=t(70335),W=t(92746),j=t(84954),z=t(5970),S=t(76679),b=t(85745),Q=t(74042),X=t(27436),T=t(29165),U=t(81828),F=t(66596),Y=t(20519),k=t(62577),q=t(77980);const V=({defaultValues:a,readOnly:o,loading:s,alertManagerSourceName:m,showConfirmDeleteAMConfig:E,onSubmit:l,onReset:n,onConfirmReset:d,onDismiss:h})=>e.createElement(F.l,{defaultValues:a,onSubmit:l,key:a.configJSON},({errors:f,setValue:c,register:x})=>(x("configJSON",{required:{value:!0,message:"Required"},validate:y=>{try{return JSON.parse(y),!0}catch(N){return N instanceof Error?N.message:"JSON is invalid"}}}),e.createElement(e.Fragment,null,e.createElement(Y.g,{disabled:s,label:"Configuration",invalid:!!f.configJSON,error:f.configJSON?.message,"data-testid":o?"readonly-config":"config"},e.createElement(k.p,{language:"json",width:"100%",height:500,showLineNumbers:!0,value:a.configJSON,showMiniMap:!1,onSave:y=>{c("configJSON",y)},onBlur:y=>{c("configJSON",y)},readOnly:o})),!o&&e.createElement(Q.Lh,null,e.createElement(T.zx,{type:"submit",variant:"primary",disabled:s},"Save configuration"),n&&e.createElement(T.zx,{type:"button",disabled:s,variant:"destructive",onClick:n},"Reset configuration")),!!E&&d&&h&&e.createElement(q.s,{isOpen:!0,title:"Reset Alertmanager configuration",body:`Are you sure you want to reset configuration ${m===S.GC?"for the Grafana Alertmanager":`for "${m}"`}? Contact points and notification policies will be reset to their defaults.`,confirmText:"Yes, reset configuration",onConfirm:d,onDismiss:h}))));function _({onChange:a,selectedAmConfig:o,defaultValues:s,onSubmit:m,readOnly:E,loading:l}){const{useGetValidAlertManagersConfigQuery:n,useResetAlertManagerConfigToOldVersionMutation:d}=U.alertmanagerApi,h=(0,C.wW)(ee),{currentData:f,isLoading:c}=n(),[x]=d(),y=(0,e.useMemo)(()=>{if(!f?.length)return[];const p=f.map(O=>{const I=new Date(O.last_applied);return{label:O.last_applied?`Config from ${I.toLocaleString()} (${(0,b.CQ)(I).locale("en").fromNow(!0)} ago)`:"Previous config",value:O}});return a(p[0]),p},[f,a]),N=async()=>{const p=o?.value?.id;p!==void 0&&x({id:p})};return e.createElement(e.Fragment,null,!c&&f&&f.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:h.container},e.createElement(Q.Lh,{align:"flex-start",spacing:"md"},e.createElement(X.Ph,{options:y,value:o,onChange:p=>{a(p)}}),e.createElement(T.zx,{variant:"primary",disabled:l,onClick:N},"Reset to selected configuration"))),e.createElement(V,{defaultValues:s,onSubmit:p=>m(p),readOnly:E,loading:l,alertManagerSourceName:S.GC})):null)}const ee=a=>({container:(0,g.css)`
    margin-top: ${a.spacing(2)};
    margin-bottom: ${a.spacing(2)};
  `});function te(){const a=(0,P.useDispatch)(),[o,s]=(0,e.useState)(!1),{loading:m}=(0,W._)(G=>G.deleteAMConfig),{loading:E}=(0,W._)(G=>G.saveAMConfig),{selectedAlertmanager:l}=(0,j.ZA)(),n=l?(0,S.RY)(l):!1,d=(0,C.wW)(ae),[h,f]=(0,e.useState)(),{currentData:c,error:x,isLoading:y}=(0,w.W)(l),N=()=>{l&&a((0,z.Nc)(l)),s(!1)},p=(0,e.useMemo)(()=>({configJSON:c?JSON.stringify(c,null,2):""}),[c]),O=(0,e.useMemo)(()=>({configJSON:h?JSON.stringify(h.value,null,2):""}),[h]),I=m||y||E,ce=G=>{l&&c&&a((0,z.mM)({newConfig:JSON.parse(G.configJSON),oldConfig:c,alertManagerSourceName:l,successMessage:"Alertmanager configuration updated."}))};return e.createElement("div",{className:d.container},x&&!I&&e.createElement(e.Fragment,null,e.createElement(M.b,{severity:"error",title:"Your Alertmanager configuration is incorrect. These are the details of the error:"},x.message||"Unknown error."),l===S.GC&&e.createElement(_,{onChange:f,selectedAmConfig:h,defaultValues:O,readOnly:!0,loading:I,onSubmit:ce})),m&&l!==S.GC&&e.createElement(M.b,{severity:"info",title:"Resetting Alertmanager configuration"},"It might take a while..."),l&&c&&e.createElement(V,{defaultValues:p,onSubmit:G=>ce(G),readOnly:n,loading:I,alertManagerSourceName:l,showConfirmDeleteAMConfig:o,onReset:()=>s(!0),onConfirmReset:N,onDismiss:()=>s(!1)}))}const ae=a=>({container:(0,g.css)`
    margin-bottom: ${a.spacing(4)};
  `});var ne=t(5106),H=t(98642),$=t(16901),L=t(56375),re=t(8111);function r(){const{useGetExternalAlertmanagersQuery:a}=U.alertmanagerApi,{currentData:o}=a(),s=(0,S.aM)().filter(n=>n.jsonData.handleGrafanaManagedAlerts),m=(0,P.useSelector)((0,re.P1)(n=>n.dataSources.dataSources.filter(d=>d.type==="alertmanager"),n=>(0,L.keyBy)(n,d=>d.uid))),E=(0,L.countBy)(o?.droppedAlertManagers,n=>n.url),l=(0,L.countBy)(o?.activeAlertManagers,n=>n.url);return s.map(n=>{const d=m[n.uid];if(!d)return{dataSource:n,status:"pending"};const f=`${u(d)}/api/v2/alerts`,c=E[f]??0,x=l[f]??0,y=c>0,N=x>0,p=c+x>1,O=y?"dropped":N?"active":"pending";return{dataSource:n,url:d.url,status:O,statusInconclusive:p}})}function u(a){return new RegExp("^[^:]*://").test(a.url)?a.url:`http://${a.url}`}var i=t(11318),A=t(72435),B=t(14607),R=t(97666),v=t(67192),le=t(77294);function oe({alertmanagers:a,inactive:o}){const s=(0,C.wW)(Z);return e.createElement(e.Fragment,null,e.createElement("h5",null,"Alertmanagers Receiving Grafana-managed alerts"),e.createElement("div",{className:s.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."),a.length===0&&e.createElement(i._,{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(T.Qj,{href:"/datasources"},"Go to data sources"),className:s.externalDsCTA}),a.length>0&&e.createElement("div",{className:s.externalDs},a.map(m=>e.createElement(se,{key:m.dataSource.uid,alertmanager:m,inactive:o}))))}function se({alertmanager:a,inactive:o}){const s=(0,C.wW)(Z),{dataSource:m,status:E,statusInconclusive:l,url:n}=a;return e.createElement(A.Z,null,e.createElement(A.Z.Heading,{className:s.externalHeading},m.name," ",l&&e.createElement(B.u,{content:"Multiple Alertmanagers have the same URL configured. The state might be inconclusive."},e.createElement(R.J,{name:"exclamation-triangle",size:"md",className:s.externalWarningIcon}))),e.createElement(A.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(A.Z.Tags,null,o?e.createElement(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."}):e.createElement(v.C,{text:(0,L.capitalize)(E),color:E==="dropped"?"red":E==="active"?"green":"orange"})),e.createElement(A.Z.Meta,null,n),e.createElement(A.Z.Actions,null,e.createElement(T.Qj,{href:(0,le.__)(m),size:"sm",variant:"secondary"},"Go to datasource")))}const Z=a=>({muted:(0,g.css)`
    font-size: ${a.typography.bodySmall.fontSize};
    line-height: ${a.typography.bodySmall.lineHeight};
    color: ${a.colors.text.secondary};
  `,externalHeading:(0,g.css)`
    justify-content: flex-start;
  `,externalWarningIcon:(0,g.css)`
    margin: ${a.spacing(0,1)};
    fill: ${a.colors.warning.main};
  `,externalDs:(0,g.css)`
    display: grid;
    gap: ${a.spacing(1)};
    padding: ${a.spacing(2,0)};
  `,externalDsCTA:(0,g.css)`
    margin: ${a.spacing(2,0)};
  `}),K=[{value:$.TE.Internal,label:"Only Internal"},{value:$.TE.External,label:"Only External"},{value:$.TE.All,label:"Both internal and external"}],ge=()=>{const a=(0,C.wW)(me),o=(0,P.useDispatch)(),s=r(),{useSaveExternalAlertmanagersConfigMutation:m,useGetExternalAlertmanagerConfigQuery:E,useGetExternalAlertmanagersQuery:l}=U.alertmanagerApi,[n]=m(),{currentData:d}=E();l(void 0,{pollingInterval:5e3});const h=d?.alertmanagersChoice;(0,e.useEffect)(()=>{o((0,H.bZ)())},[o]);const f=c=>{n({alertmanagersChoice:c})};return e.createElement("div",null,e.createElement("h4",null,"External Alertmanagers"),e.createElement(M.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:a.amChoice},e.createElement(Y.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(ne.S,{options:K,value:h,onChange:c=>f(c)}))),e.createElement(oe,{alertmanagers:s,inactive:h===$.TE.Internal}))},me=a=>({url:(0,g.css)`
    margin-right: ${a.spacing(1)};
  `,actions:(0,g.css)`
    margin-top: ${a.spacing(2)};
    display: flex;
    justify-content: flex-end;
  `,table:(0,g.css)`
    margin-bottom: ${a.spacing(2)};
  `,amChoice:(0,g.css)`
    margin-bottom: ${a.spacing(4)};
  `});function ue(){return e.createElement(J.O,{navId:"alerting-admin",accessType:"notification"},e.createElement(de,null))}function de(){const{selectedAlertmanager:a}=(0,j.ZA)(),o=a===S.GC;return e.createElement(e.Fragment,null,e.createElement(te,{"test-id":"admin-alertmanagerconfig"}),o&&e.createElement(ge,{"test-id":"admin-externalalertmanagers"}))}},65892:(ie,D,t)=>{t.d(D,{J:()=>H,O:()=>$});var e=t(85960),J=t(8134),g=t(20989),C=t(90857),M=t(79055),P=t(66681),w=t(6753),W=t(47257),j=t(74042),z=t(14607),S=t(29165),b=t(49199);const Q=({localStoreKey:r,startClosed:u=!1,severity:i="error",collapseText:A,collapseTooltip:B,collapseJustify:R="flex-end",alertTitle:v,children:le})=>{const oe=(0,W.l4)(),se=X(oe,i),[Z,K]=(0,w.Z)(r,u);return e.createElement(e.Fragment,null,Z&&e.createElement(j.Lh,{justify:R},e.createElement(z.u,{content:B,placement:"bottom"},e.createElement(S.zx,{fill:"text",variant:"secondary",icon:(0,b.j)(i),className:se.warningButton,onClick:()=>K(!1)},A))),!Z&&e.createElement(b.b,{severity:i,title:v,onRemove:()=>K(!0)},le))},X=(r,u)=>{const i=r.colors[u];return{warningButton:(0,P.css)({color:i.text,"&:hover":{background:i.transparent}})}},T="grafana.unifiedalerting.upgrade.previewNotice",U=()=>C.config.unifiedAlertingEnabled||!C.config.featureToggles.alertingPreviewUpgrade?null:e.createElement(Q,{localStoreKey:T,alertTitle:"This is a preview of the upgraded Grafana Alerting",collapseText:"Grafana Alerting Preview",collapseTooltip:"Show preview warning",severity:"warning"},e.createElement("p",null,"No rules are being evaluated and legacy alerting is still running.",e.createElement("br",null),"Please contact your administrator to upgrade permanently."),e.createElement(M.h,{external:!0,href:"https://grafana.com/docs/grafana/latest/alerting/set-up/migrating-alerts/"},"Read about upgrading"));var F=t(84954),Y=t(84933),k=t(27436),q=t(76679);function V(r){return r.name===q.GC?"Grafana":r.name.slice(0,37)}const _=({disabled:r=!1})=>{const u=(0,W.wW)(ee),{selectedAlertmanager:i,availableAlertManagers:A,setSelectedAlertmanager:B}=(0,F.ZA)(),R=(0,e.useMemo)(()=>A.map(v=>({label:V(v),value:v.name,imgUrl:v.imgUrl,meta:v.meta})),[A]);return e.createElement(Y._,{className:u.field,label:r?"Alertmanager":"Choose Alertmanager",disabled:r||R.length===1,"data-testid":"alertmanager-picker"},e.createElement(k.Ph,{"aria-label":r?"Alertmanager":"Choose Alertmanager",width:29,className:"ds-picker select-container",backspaceRemovesValue:!1,onChange:v=>{v?.value&&B(v.value)},options:R,maxMenuHeight:500,noOptionsMessage:"No datasources found",value:i,getOptionLabel:v=>v.label}))},ee=r=>({field:(0,P.css)`
    margin: 0;
  `}),te=()=>e.createElement(b.b,{title:"No Alertmanager found",severity:"warning"},"We could not find any external Alertmanagers and you may not have access to the built-in Grafana Alertmanager."),ae=()=>e.createElement(b.b,{title:"Selected Alertmanager not found.",severity:"warning"},"The selected Alertmanager no longer exists or you may not have permission to access it. You can select a different Alertmanager from the dropdown."),ne=({availableAlertManagers:r})=>{const u=r.length>0;return e.createElement("div",null,u?e.createElement(ae,null):e.createElement(te,null))},H=({children:r,isLoading:u,...i})=>e.createElement(g.T,{...i},e.createElement(g.T.Contents,{isLoading:u},e.createElement("div",null,e.createElement(U,null),r))),$=({children:r,accessType:u,...i})=>{const A=L();return e.createElement(F.h5,{accessType:u},e.createElement(H,{...i,actions:e.createElement(_,{disabled:A})},e.createElement(re,null,r)))};function L(){const r=(0,J.Z)();return["/edit","/new"].some(i=>r?.pathname?.includes(i))}const re=({children:r})=>{const{availableAlertManagers:u,selectedAlertmanager:i}=(0,F.ZA)();return i?e.createElement(e.Fragment,null,r):e.createElement(ne,{availableAlertManagers:u})}},70335:(ie,D,t)=>{t.d(D,{W:()=>J});var e=t(81828);function J(g,C){const M=e.alertmanagerApi.endpoints.getAlertmanagerConfiguration.useQuery(g??"",{...C,skip:!g});return{...M,error:M.error}}}}]);

//# sourceMappingURL=AlertingAdmin.890637bd8378d32cb77f.js.map