"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[7680],{"./public/app/features/alerting/unified/Admin.tsx":(e,a,r)=>{r.r(a),r.d(a,{default:()=>R});var t,n=r("../../opt/drone/yarncache/react-npm-17.0.2-99ba37d931-b254cc17ce.zip/node_modules/react/index.js"),s=r("./public/app/features/alerting/unified/components/AlertingPageWrapper.tsx"),i=r("./.yarn/__virtual__/@emotion-css-virtual-72c314ddb1/3/opt/drone/yarncache/@emotion-css-npm-11.7.1-25ff8755a7-ac1f56656f.zip/node_modules/@emotion/css/dist/emotion-css.esm.js"),l=r("./packages/grafana-ui/src/index.ts"),o=r("./public/app/features/alerting/unified/hooks/useAlertManagerSourceName.ts"),c=r("./public/app/features/alerting/unified/components/AlertManagerPicker.tsx"),d=r("./public/app/features/alerting/unified/utils/datasource.ts"),u=r("./.yarn/__virtual__/react-redux-virtual-7ad20a440e/3/opt/drone/yarncache/react-redux-npm-7.2.6-134f5ed64d-0bf142ce0d.zip/node_modules/react-redux/es/index.js"),p=r("./public/app/features/alerting/unified/state/actions.ts"),m=r("./public/app/features/alerting/unified/hooks/useUnifiedAlertingSelector.ts"),g=r("./public/app/features/alerting/unified/utils/redux.ts"),f=r("../../opt/drone/yarncache/react-npm-17.0.2-99ba37d931-b254cc17ce.zip/node_modules/react/jsx-runtime.js");function h(){var e;const a=(0,u.useDispatch)(),[r,s]=(0,o.k)(),[i,h]=(0,n.useState)(!1),{loading:v}=(0,m._)((e=>e.deleteAMConfig)),{loading:b}=(0,m._)((e=>e.saveAMConfig)),j=!!r&&(0,d.RY)(r),y=(0,l.useStyles2)(x),A=(0,m._)((e=>e.amConfigs)),{result:C,loading:S,error:N}=r&&A[r]||g.oq;(0,n.useEffect)((()=>{r&&a((0,p.Yh)(r))}),[r,a]);const k=()=>{r&&a((0,p.Nc)(r)),h(!1)},_=(0,n.useMemo)((()=>({configJSON:C?JSON.stringify(C,null,2):""})),[C]),$=v||S||b;return(0,f.jsxs)("div",{className:y.container,children:[(0,f.jsx)(c.P,{current:r,onChange:s}),N&&!$&&(0,f.jsx)(l.Alert,{severity:"error",title:"Error loading Alertmanager configuration",children:N.message||"Unknown error."}),v&&r!==d.GC&&(t||(t=(0,f.jsx)(l.Alert,{severity:"info",title:"Resetting Alertmanager configuration",children:"It might take a while..."}))),r&&C&&(0,f.jsx)(l.Form,{defaultValues:_,onSubmit:e=>{r&&C&&a((0,p.mM)({newConfig:JSON.parse(e.configJSON),oldConfig:C,alertManagerSourceName:r,successMessage:"Alertmanager configuration updated.",refetch:!0}))},children:a=>{var t;let{register:n,errors:s}=a;return(0,f.jsxs)(f.Fragment,{children:[!j&&(0,f.jsx)(l.Field,{disabled:$,label:"Configuration",invalid:!!s.configJSON,error:null===(t=s.configJSON)||void 0===t?void 0:t.message,children:(0,f.jsx)(l.TextArea,Object.assign({},n("configJSON",{required:{value:!0,message:"Required."},validate:e=>{try{return JSON.parse(e),!0}catch(e){return e.message}}}),{id:"configuration",rows:25}))}),j&&(0,f.jsx)(l.Field,{label:"Configuration",children:(0,f.jsx)("pre",{"data-testid":"readonly-config",children:_.configJSON})}),!j&&(0,f.jsxs)(l.HorizontalGroup,{children:[e||(e=(0,f.jsx)(l.Button,{type:"submit",variant:"primary",disabled:$,children:"Save"})),(0,f.jsx)(l.Button,{type:"button",disabled:$,variant:"destructive",onClick:()=>h(!0),children:"Reset configuration"})]}),!!i&&(0,f.jsx)(l.ConfirmModal,{isOpen:!0,title:"Reset Alertmanager configuration",body:`Are you sure you want to reset configuration ${r===d.GC?"for the Grafana Alertmanager":`for "${r}"`}? Contact points and notification policies will be reset to their defaults.`,confirmText:"Yes, reset configuration",onConfirm:k,onDismiss:()=>h(!1)})]})}},_.configJSON)]})}const x=e=>({container:i.css`
    margin-bottom: ${e.spacing(4)};
  `});var v,b,j=r("./public/app/core/components/EmptyListCTA/EmptyListCTA.tsx");const y=e=>{let{alertmanagers:a,onClose:r}=e;const t=(0,l.useStyles2)(A),s=(0,u.useDispatch)(),i=(0,n.useMemo)((()=>({alertmanagers:a})),[a]),o=(0,f.jsxs)("div",{className:t.modalTitle,children:[(0,f.jsx)(l.Icon,{name:"bell",className:t.modalIcon}),v||(v=(0,f.jsx)("h3",{children:"Add Alertmanager"}))]}),c=e=>{s((0,p.sx)(e.alertmanagers.map((e=>e.url.replace(/\/$/,"").replace(/\/api\/v[1|2]\/alerts/i,""))))),r()};return(0,f.jsxs)(l.Modal,{title:o,isOpen:!0,onDismiss:r,className:t.modal,children:[(0,f.jsx)("div",{className:t.description,children:"We use a service discovery method to find existing Alertmanagers for a given URL."}),(0,f.jsx)(l.Form,{onSubmit:c,defaultValues:i,children:e=>{let{register:a,control:r,errors:n}=e;return(0,f.jsxs)("div",{children:[(0,f.jsx)(l.FieldArray,{control:r,name:"alertmanagers",children:e=>{let{fields:r,append:s,remove:i}=e;return(0,f.jsxs)("div",{className:t.fieldArray,children:[(0,f.jsx)("div",{className:t.bold,children:"Source url"}),(0,f.jsx)("div",{className:t.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 s;return(0,f.jsx)(l.Field,{invalid:!(null==n||null===(s=n.alertmanagers)||void 0===s||!s[r]),error:"Field is required",children:(0,f.jsx)(l.Input,Object.assign({className:t.input,defaultValue:e.url},a(`alertmanagers.${r}.url`,{required:!0}),{placeholder:"http://localhost:9093",addonAfter:(0,f.jsx)(l.Button,{"aria-label":"Remove alertmanager",type:"button",onClick:()=>i(r),variant:"destructive",className:t.destroyInputRow,children:b||(b=(0,f.jsx)(l.Icon,{name:"trash-alt"}))})}))},`${e.id}-${r}`)})),(0,f.jsx)(l.Button,{type:"button",variant:"secondary",onClick:()=>s({url:""}),children:"Add URL"})]})}}),(0,f.jsx)("div",{children:(0,f.jsx)(l.Button,{onSubmit:()=>c,children:"Add Alertmanagers"})})]})}})]})};const A=e=>{const a=i.css`
    color: ${e.colors.text.secondary};
  `;return{description:(0,i.cx)(i.css`
        margin-bottom: ${e.spacing(2)};
      `,a),muted:a,bold:i.css`
      font-weight: ${e.typography.fontWeightBold};
    `,modal:i.css``,modalIcon:(0,i.cx)(a,i.css`
        margin-right: ${e.spacing(1)};
      `),modalTitle:i.css`
      display: flex;
    `,input:i.css`
      margin-bottom: ${e.spacing(1)};
      margin-right: ${e.spacing(1)};
    `,inputRow:i.css`
      display: flex;
    `,destroyInputRow:i.css`
      padding: ${e.spacing(1)};
    `,fieldArray:i.css`
      margin-bottom: ${e.spacing(4)};
    `}},C=/\/api\/v[1|2]\/alerts/i;var S,N,k,_,$,w;const I=()=>{var e;const a=(0,l.useStyles2)(M),r=(0,u.useDispatch)(),[t,s]=(0,n.useState)({open:!1,payload:[{url:""}]}),[i,o]=(0,n.useState)({open:!1,index:0}),c=function(){const e=(0,u.useSelector)((e=>{var a;return null===(a=e.unifiedAlerting.externalAlertmanagers.discoveredAlertmanagers.result)||void 0===a?void 0:a.data})),a=(0,u.useSelector)((e=>{var a;return null===(a=e.unifiedAlerting.externalAlertmanagers.alertmanagerConfig.result)||void 0===a?void 0:a.alertmanagers}));if(!e||!a)return[];const r=[],t=null==e?void 0:e.droppedAlertManagers.map((e=>({url:e.url.replace(C,""),status:"dropped",actualUrl:e.url})));for(const t of a)if(0===e.activeAlertManagers.length)r.push({url:t,status:"pending",actualUrl:""});else{let a=!1;for(const n of e.activeAlertManagers)n.url===`${t}/api/v2/alerts`&&(a=!0,r.push({url:n.url.replace(C,""),status:"active",actualUrl:n.url}));a||r.push({url:t,status:"pending",actualUrl:""})}return[...r,...t]}();(0,n.useEffect)((()=>{r((0,p.zy)()),r((0,p.wE)());const e=setInterval((()=>r((0,p.zy)())),5e3);return()=>{clearInterval(e)}}),[r]);const d=(0,n.useCallback)((e=>{const a=(null!=c?c:[]).filter(((a,r)=>r!==e)).map((e=>e.url));r((0,p.sx)(a)),o({open:!1,index:0})}),[c,r]),m=(0,n.useCallback)((()=>{const e=c?[...c]:[{url:""}];s((a=>Object.assign({},a,{open:!0,payload:e})))}),[s,c]),g=(0,n.useCallback)((()=>{s((e=>{const a=c?[...c,{url:""}]:[{url:""}];return Object.assign({},e,{open:!0,payload:a})}))}),[c]),h=(0,n.useCallback)((()=>{s((e=>Object.assign({},e,{open:!1})))}),[s]),x=e=>{switch(e){case"active":return"green";case"pending":return"yellow";default:return"red"}},v=0===(null==c?void 0:c.length);return(0,f.jsxs)("div",{children:[S||(S=(0,f.jsx)("h4",{children:"External Alertmanagers"})),(0,f.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,f.jsx)("div",{className:a.actions,children:!v&&(0,f.jsx)(l.Button,{type:"button",onClick:g,children:"Add Alertmanager"})}),v?(0,f.jsx)(j.Z,{title:"You have not added any external alertmanagers",onClick:g,buttonTitle:"Add Alertmanager",buttonIcon:"bell-slash"}):(0,f.jsxs)("table",{className:"filter-table form-inline filter-table--hover",children:[(0,f.jsx)("thead",{children:(0,f.jsxs)("tr",{children:[N||(N=(0,f.jsx)("th",{children:"Url"})),k||(k=(0,f.jsx)("th",{children:"Status"})),(0,f.jsx)("th",{style:{width:"2%"},children:"Action"})]})}),(0,f.jsx)("tbody",{children:null==c?void 0:c.map(((r,t)=>(0,f.jsxs)("tr",{children:[(0,f.jsxs)("td",{children:[(0,f.jsx)("span",{className:a.url,children:r.url}),r.actualUrl?(0,f.jsx)(l.Tooltip,{content:`Discovered ${r.actualUrl} from ${r.url}`,theme:"info",children:_||(_=(0,f.jsx)(l.Icon,{name:"info-circle"}))}):null]}),(0,f.jsx)("td",{children:(0,f.jsx)(l.Icon,{name:"heart",style:{color:x(r.status)},title:r.status})}),(0,f.jsx)("td",{children:(0,f.jsxs)(l.HorizontalGroup,{children:[e||(e=(0,f.jsx)(l.Button,{variant:"secondary",type:"button",onClick:m,"aria-label":"Edit alertmanager",children:$||($=(0,f.jsx)(l.Icon,{name:"pen"}))})),(0,f.jsx)(l.Button,{variant:"destructive","aria-label":"Remove alertmanager",type:"button",onClick:()=>o({open:!0,index:t}),children:w||(w=(0,f.jsx)(l.Icon,{name:"trash-alt"}))})]})})]},t)))})]}),(0,f.jsx)(l.ConfirmModal,{isOpen:i.open,title:"Remove Alertmanager",body:"Are you sure you want to remove this Alertmanager",confirmText:"Remove",onConfirm:()=>d(i.index),onDismiss:()=>o({open:!1,index:0})}),t.open&&(0,f.jsx)(y,{onClose:h,alertmanagers:t.payload})]})},M=e=>({url:i.css`
    margin-right: ${e.spacing(1)};
  `,muted:i.css`
    color: ${e.colors.text.secondary};
  `,actions:i.css`
    margin-top: ${e.spacing(2)};
    display: flex;
    justify-content: flex-end;
  `,table:i.css``});var O;function R(){return O||(O=(0,f.jsxs)(s.J,{pageId:"alerting-admin",children:[(0,f.jsx)(h,{"test-id":"admin-alertmanagerconfig"}),(0,f.jsx)(I,{"test-id":"admin-externalalertmanagers"})]}))}},"./public/app/features/alerting/unified/components/AlertingPageWrapper.tsx":(e,a,r)=>{r.d(a,{J:()=>l});r("../../opt/drone/yarncache/react-npm-17.0.2-99ba37d931-b254cc17ce.zip/node_modules/react/index.js");var t=r("./public/app/core/components/Page/Page.tsx"),n=r("./public/app/core/selectors/navModel.ts"),s=r("./.yarn/__virtual__/react-redux-virtual-7ad20a440e/3/opt/drone/yarncache/react-redux-npm-7.2.6-134f5ed64d-0bf142ce0d.zip/node_modules/react-redux/es/index.js"),i=r("../../opt/drone/yarncache/react-npm-17.0.2-99ba37d931-b254cc17ce.zip/node_modules/react/jsx-runtime.js");const l=e=>{let{children:a,pageId:r,isLoading:l}=e;const o=(0,n.h)((0,s.useSelector)((e=>e.navIndex)),r);return(0,i.jsx)(t.Z,{navModel:o,children:(0,i.jsx)(t.Z.Contents,{isLoading:l,children:a})})}},"./public/app/features/alerting/unified/hooks/useAlertManagerSourceName.ts":(e,a,r)=>{r.d(a,{k:()=>c});var t=r("./public/app/core/hooks/useQueryParams.ts"),n=r("./public/app/core/store.ts"),s=r("../../opt/drone/yarncache/react-npm-17.0.2-99ba37d931-b254cc17ce.zip/node_modules/react/index.js"),i=r("./public/app/features/alerting/unified/utils/constants.ts"),l=r("./public/app/features/alerting/unified/utils/datasource.ts");function o(e){return e===l.GC||!!(0,l.aM)().find((a=>a.name===e))}function c(){const[e,a]=(0,t.K)(),r=(0,s.useCallback)((e=>{o(e)&&(e===l.GC?(n.Z.delete(i.de),a({[i.c4]:null})):(n.Z.set(i.de,e),a({[i.c4]:e})))}),[a]),c=e[i.c4];if(c&&"string"==typeof c)return o(c)?[c,r]:[void 0,r];const d=n.Z.get(i.de);return d&&"string"==typeof d&&o(d)?(r(d),[d,r]):[l.GC,r]}}}]);
//# sourceMappingURL=AlertingAdmin.cd4ada1146b53ad3284f.js.map