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KACnCC,EAlBR,SAAoCJ,GAClC,OAAOnC,EAAAA,EAAAA,cACJwC,GACqCL,EAAuBnG,KAAKC,GAAOA,EAAGH,OACvC2G,SAASD,IAE9C,CAACL,IAY6BO,CAA2BP,GAErDQ,GAAS3C,EAAAA,EAAAA,cACZ5J,IACMmM,EAAwBnM,KAGzBA,IAA2B6C,EAAAA,IAC7B2J,EAAAA,EAAAA,OAAaC,EAAAA,IACbR,EAAkB,CAAE,CAACS,EAAAA,IAA8B,SAEnDF,EAAAA,EAAAA,IAAUC,EAAAA,GAAqCzM,GAC/CiM,EAAkB,CAAE,CAACS,EAAAA,IAA8B1M,QAGvD,CAACiM,EAAmBE,IAGhBQ,EAAcX,EAAYU,EAAAA,IAEhC,GAAIC,GAAsC,iBAAhBA,EACxB,OAAIR,EAAwBQ,GACnB,CAACA,EAAaJ,GAGd,MAACK,EAAWL,GAIvB,MAAMM,EAAcL,EAAAA,EAAAA,IAAUC,EAAAA,IAC9B,OAAII,GAAsC,iBAAhBA,GAA4BV,EAAwBU,IAC5EN,EAAOM,GACA,CAACA,EAAaN,IAGnBJ,EAAwBtJ,EAAAA,IACnB,CAACA,EAAAA,GAA2B0J,GAG9B,MAACK,EAAWL,K,0DC7Dd,SAASxM,EAA6B+M,GAC3C,OAAO/K,EAAAA,EAAAA,UAAQ,KAAMgL,EAAAA,EAAAA,IAAuCD,IAAa,CAACA","sources":["webpack://grafana/./public/app/features/alerting/unified/components/admin/AlertmanagerConfig.tsx","webpack://grafana/./public/app/features/alerting/unified/hooks/useExternalAmSelector.ts","webpack://grafana/./public/app/features/alerting/unified/components/admin/AddAlertManagerModal.tsx","webpack://grafana/./public/app/features/alerting/unified/components/admin/ExternalAlertmanagers.tsx","webpack://grafana/./public/app/features/alerting/unified/Admin.tsx","webpack://grafana/./public/app/features/alerting/unified/components/AlertingPageWrapper.tsx","webpack://grafana/./public/app/features/alerting/unified/hooks/useAlertManagerSourceName.ts","webpack://grafana/./public/app/features/alerting/unified/hooks/useAlertManagerSources.ts"],"sourcesContent":["import { css } from '@emotion/css';\nimport React, { useEffect, useState, useMemo } from 'react';\nimport { useDispatch } from 'react-redux';\n\nimport { GrafanaTheme2 } from '@grafana/data';\nimport { Alert, Button, ConfirmModal, TextArea, HorizontalGroup, Field, Form, useStyles2 } from '@grafana/ui';\n\nimport { useAlertManagerSourceName } from '../../hooks/useAlertManagerSourceName';\nimport { useAlertManagersByPermission } from '../../hooks/useAlertManagerSources';\nimport { useUnifiedAlertingSelector } from '../../hooks/useUnifiedAlertingSelector';\nimport {\n deleteAlertManagerConfigAction,\n fetchAlertManagerConfigAction,\n updateAlertManagerConfigAction,\n} from '../../state/actions';\nimport { GRAFANA_RULES_SOURCE_NAME, isVanillaPrometheusAlertManagerDataSource } from '../../utils/datasource';\nimport { initialAsyncRequestState } from '../../utils/redux';\nimport { AlertManagerPicker } from '../AlertManagerPicker';\n\ninterface FormValues {\n configJSON: string;\n}\n\nexport default function AlertmanagerConfig(): JSX.Element {\n const dispatch = useDispatch();\n const alertManagers = useAlertManagersByPermission('notification');\n const [alertManagerSourceName, setAlertManagerSourceName] = useAlertManagerSourceName(alertManagers);\n\n const [showConfirmDeleteAMConfig, setShowConfirmDeleteAMConfig] = useState(false);\n const { loading: isDeleting } = useUnifiedAlertingSelector((state) => state.deleteAMConfig);\n const { loading: isSaving } = useUnifiedAlertingSelector((state) => state.saveAMConfig);\n const readOnly = alertManagerSourceName ? isVanillaPrometheusAlertManagerDataSource(alertManagerSourceName) : false;\n const styles = useStyles2(getStyles);\n\n const configRequests = useUnifiedAlertingSelector((state) => state.amConfigs);\n\n const {\n result: config,\n loading: isLoadingConfig,\n error: loadingError,\n } = (alertManagerSourceName && configRequests[alertManagerSourceName]) || initialAsyncRequestState;\n\n useEffect(() => {\n if (alertManagerSourceName) {\n dispatch(fetchAlertManagerConfigAction(alertManagerSourceName));\n }\n }, [alertManagerSourceName, dispatch]);\n\n const resetConfig = () => {\n if (alertManagerSourceName) {\n dispatch(deleteAlertManagerConfigAction(alertManagerSourceName));\n }\n setShowConfirmDeleteAMConfig(false);\n };\n\n const defaultValues = useMemo(\n (): FormValues => ({\n configJSON: config ? JSON.stringify(config, null, 2) : '',\n }),\n [config]\n );\n\n const loading = isDeleting || isLoadingConfig || isSaving;\n\n const onSubmit = (values: FormValues) => {\n if (alertManagerSourceName && config) {\n dispatch(\n updateAlertManagerConfigAction({\n newConfig: JSON.parse(values.configJSON),\n oldConfig: config,\n alertManagerSourceName,\n successMessage: 'Alertmanager configuration updated.',\n refetch: true,\n })\n );\n }\n };\n\n return (\n
\n \n {loadingError && !loading && (\n \n {loadingError.message || 'Unknown error.'}\n \n )}\n {isDeleting && alertManagerSourceName !== GRAFANA_RULES_SOURCE_NAME && (\n \n It might take a while...\n \n )}\n {alertManagerSourceName && config && (\n
\n {({ register, errors }) => (\n <>\n {!readOnly && (\n \n {\n try {\n JSON.parse(v);\n return true;\n } catch (e) {\n return e.message;\n }\n },\n })}\n id=\"configuration\"\n rows={25}\n />\n \n )}\n {readOnly && (\n \n
{defaultValues.configJSON}
\n
\n )}\n {!readOnly && (\n \n \n setShowConfirmDeleteAMConfig(true)}\n >\n Reset configuration\n \n \n )}\n {!!showConfirmDeleteAMConfig && (\n setShowConfirmDeleteAMConfig(false)}\n />\n )}\n \n )}\n \n )}\n
\n );\n}\n\nconst getStyles = (theme: GrafanaTheme2) => ({\n container: css`\n margin-bottom: ${theme.spacing(4)};\n `,\n});\n","import { useSelector } from 'react-redux';\n\nimport { StoreState } from '../../../../types';\n\nconst SUFFIX_REGEX = /\\/api\\/v[1|2]\\/alerts/i;\ntype AlertmanagerConfig = { url: string; status: string; actualUrl: string };\n\nexport function useExternalAmSelector(): AlertmanagerConfig[] | [] {\n const discoveredAlertmanagers = useSelector(\n (state: StoreState) => state.unifiedAlerting.externalAlertmanagers.discoveredAlertmanagers.result?.data\n );\n const alertmanagerConfig = useSelector(\n (state: StoreState) => state.unifiedAlerting.externalAlertmanagers.alertmanagerConfig.result?.alertmanagers\n );\n\n if (!discoveredAlertmanagers || !alertmanagerConfig) {\n return [];\n }\n\n const enabledAlertmanagers: AlertmanagerConfig[] = [];\n const droppedAlertmanagers: AlertmanagerConfig[] = discoveredAlertmanagers.droppedAlertManagers.map((am) => ({\n url: am.url.replace(SUFFIX_REGEX, ''),\n status: 'dropped',\n actualUrl: am.url,\n }));\n\n for (const url of alertmanagerConfig) {\n if (discoveredAlertmanagers.activeAlertManagers.length === 0) {\n enabledAlertmanagers.push({\n url: url,\n status: 'pending',\n actualUrl: '',\n });\n } else {\n const matchingActiveAM = discoveredAlertmanagers.activeAlertManagers.find(\n (am) => am.url === `${url}/api/v2/alerts`\n );\n matchingActiveAM\n ? enabledAlertmanagers.push({\n url: matchingActiveAM.url.replace(SUFFIX_REGEX, ''),\n status: 'active',\n actualUrl: matchingActiveAM.url,\n })\n : enabledAlertmanagers.push({\n url: url,\n status: 'pending',\n actualUrl: '',\n });\n }\n }\n\n return [...enabledAlertmanagers, ...droppedAlertmanagers];\n}\n","import { css, cx } from '@emotion/css';\nimport React, { FC, useMemo } from 'react';\n\nimport { GrafanaTheme2 } from '@grafana/data';\nimport { Button, Field, FieldArray, Form, Icon, Input, Modal, useStyles2 } from '@grafana/ui';\nimport { AlertmanagerUrl } from 'app/plugins/datasource/alertmanager/types';\n\ninterface Props {\n onClose: () => void;\n alertmanagers: AlertmanagerUrl[];\n onChangeAlertmanagerConfig: (alertmanagers: string[]) => void;\n}\n\nexport const AddAlertManagerModal: FC = ({ alertmanagers, onChangeAlertmanagerConfig, onClose }) => {\n const styles = useStyles2(getStyles);\n const defaultValues: Record = useMemo(\n () => ({\n alertmanagers: alertmanagers,\n }),\n [alertmanagers]\n );\n\n const modalTitle = (\n
\n \n

Add Alertmanager

\n
\n );\n\n const onSubmit = (values: Record) => {\n onChangeAlertmanagerConfig(values.alertmanagers.map((am) => cleanAlertmanagerUrl(am.url)));\n onClose();\n };\n\n return (\n \n
\n We use a service discovery method to find existing Alertmanagers for a given URL.\n
\n
\n {({ register, control, errors }) => (\n
\n \n {({ fields, append, remove }) => (\n
\n
Source url
\n
\n Authentication can be done via URL (e.g. user:password@myalertmanager.com) and only the Alertmanager\n v2 API is supported. The suffix is added internally, there is no need to specify it.\n
\n {fields.map((field, index) => {\n return (\n \n remove(index)}\n variant=\"destructive\"\n className={styles.destroyInputRow}\n >\n \n \n }\n />\n \n );\n })}\n \n
\n )}\n
\n
\n \n
\n
\n )}\n
\n
\n );\n};\n\nfunction cleanAlertmanagerUrl(url: string): string {\n return url.replace(/\\/$/, '').replace(/\\/api\\/v[1|2]\\/alerts/i, '');\n}\n\nconst getStyles = (theme: GrafanaTheme2) => {\n const muted = css`\n color: ${theme.colors.text.secondary};\n `;\n return {\n description: cx(\n css`\n margin-bottom: ${theme.spacing(2)};\n `,\n muted\n ),\n muted: muted,\n bold: css`\n font-weight: ${theme.typography.fontWeightBold};\n `,\n modal: css``,\n modalIcon: cx(\n muted,\n css`\n margin-right: ${theme.spacing(1)};\n `\n ),\n modalTitle: css`\n display: flex;\n `,\n input: css`\n margin-bottom: ${theme.spacing(1)};\n margin-right: ${theme.spacing(1)};\n `,\n inputRow: css`\n display: flex;\n `,\n destroyInputRow: css`\n padding: ${theme.spacing(1)};\n `,\n fieldArray: css`\n margin-bottom: ${theme.spacing(4)};\n `,\n };\n};\n","import { css, cx } from '@emotion/css';\nimport React, { useCallback, useEffect, useState } from 'react';\nimport { useDispatch, useSelector } from 'react-redux';\n\nimport { GrafanaTheme2 } from '@grafana/data';\nimport {\n Button,\n ConfirmModal,\n Field,\n HorizontalGroup,\n Icon,\n RadioButtonGroup,\n Tooltip,\n useStyles2,\n useTheme2,\n} from '@grafana/ui';\nimport EmptyListCTA from 'app/core/components/EmptyListCTA/EmptyListCTA';\nimport { StoreState } from 'app/types/store';\n\nimport { useExternalAmSelector } from '../../hooks/useExternalAmSelector';\nimport {\n addExternalAlertmanagersAction,\n fetchExternalAlertmanagersAction,\n fetchExternalAlertmanagersConfigAction,\n} from '../../state/actions';\n\nimport { AddAlertManagerModal } from './AddAlertManagerModal';\n\nconst alertmanagerChoices = [\n { value: 'internal', label: 'Only Internal' },\n { value: 'external', label: 'Only External' },\n { value: 'all', label: 'Both internal and external' },\n];\n\nexport const ExternalAlertmanagers = () => {\n const styles = useStyles2(getStyles);\n const dispatch = useDispatch();\n const [modalState, setModalState] = useState({ open: false, payload: [{ url: '' }] });\n const [deleteModalState, setDeleteModalState] = useState({ open: false, index: 0 });\n\n const externalAlertManagers = useExternalAmSelector();\n const alertmanagersChoice = useSelector(\n (state: StoreState) => state.unifiedAlerting.externalAlertmanagers.alertmanagerConfig.result?.alertmanagersChoice\n );\n const theme = useTheme2();\n\n useEffect(() => {\n dispatch(fetchExternalAlertmanagersAction());\n dispatch(fetchExternalAlertmanagersConfigAction());\n const interval = setInterval(() => dispatch(fetchExternalAlertmanagersAction()), 5000);\n\n return () => {\n clearInterval(interval);\n };\n }, [dispatch]);\n\n const onDelete = useCallback(\n (index: number) => {\n // to delete we need to filter the alertmanager from the list and repost\n const newList = (externalAlertManagers ?? [])\n .filter((am, i) => i !== index)\n .map((am) => {\n return am.url;\n });\n dispatch(\n addExternalAlertmanagersAction({ alertmanagers: newList, alertmanagersChoice: alertmanagersChoice ?? 'all' })\n );\n setDeleteModalState({ open: false, index: 0 });\n },\n [externalAlertManagers, dispatch, alertmanagersChoice]\n );\n\n const onEdit = useCallback(() => {\n const ams = externalAlertManagers ? [...externalAlertManagers] : [{ url: '' }];\n setModalState((state) => ({\n ...state,\n open: true,\n payload: ams,\n }));\n }, [setModalState, externalAlertManagers]);\n\n const onOpenModal = useCallback(() => {\n setModalState((state) => {\n const ams = externalAlertManagers ? [...externalAlertManagers, { url: '' }] : [{ url: '' }];\n return {\n ...state,\n open: true,\n payload: ams,\n };\n });\n }, [externalAlertManagers]);\n\n const onCloseModal = useCallback(() => {\n setModalState((state) => ({\n ...state,\n open: false,\n }));\n }, [setModalState]);\n\n const onChangeAlertmanagerChoice = (alertmanagersChoice: string) => {\n dispatch(\n addExternalAlertmanagersAction({ alertmanagers: externalAlertManagers.map((am) => am.url), alertmanagersChoice })\n );\n };\n\n const onChangeAlertmanagers = (alertmanagers: string[]) => {\n dispatch(addExternalAlertmanagersAction({ alertmanagers, alertmanagersChoice: alertmanagersChoice ?? 'all' }));\n };\n\n const getStatusColor = (status: string) => {\n switch (status) {\n case 'active':\n return theme.colors.success.main;\n\n case 'pending':\n return theme.colors.warning.main;\n\n default:\n return theme.colors.error.main;\n }\n };\n\n const noAlertmanagers = externalAlertManagers?.length === 0;\n\n return (\n
\n

External Alertmanagers

\n
\n You can have your Grafana managed alerts be delivered to one or many external Alertmanager(s) in addition to the\n internal Alertmanager by specifying their URLs below.\n
\n
\n {!noAlertmanagers && (\n \n )}\n
\n {noAlertmanagers ? (\n \n ) : (\n <>\n \n \n \n \n \n \n \n \n \n {externalAlertManagers?.map((am, index) => {\n return (\n \n \n \n \n \n );\n })}\n \n
UrlStatusAction
\n {am.url}\n {am.actualUrl ? (\n \n \n \n ) : null}\n \n \n \n \n \n setDeleteModalState({ open: true, index })}\n >\n \n \n \n
\n
\n \n onChangeAlertmanagerChoice(value!)}\n />\n \n
\n \n )}\n onDelete(deleteModalState.index)}\n onDismiss={() => setDeleteModalState({ open: false, index: 0 })}\n />\n {modalState.open && (\n \n )}\n
\n );\n};\n\nconst getStyles = (theme: GrafanaTheme2) => ({\n url: css`\n margin-right: ${theme.spacing(1)};\n `,\n muted: css`\n color: ${theme.colors.text.secondary};\n `,\n actions: css`\n margin-top: ${theme.spacing(2)};\n display: flex;\n justify-content: flex-end;\n `,\n table: css`\n margin-bottom: ${theme.spacing(2)};\n `,\n});\n","import React from 'react';\n\nimport { AlertingPageWrapper } from './components/AlertingPageWrapper';\nimport AlertmanagerConfig from './components/admin/AlertmanagerConfig';\nimport { ExternalAlertmanagers } from './components/admin/ExternalAlertmanagers';\n\nexport default function Admin(): JSX.Element {\n return (\n \n \n \n \n );\n}\n","import React, { FC } from 'react';\nimport { useSelector } from 'react-redux';\n\nimport Page from 'app/core/components/Page/Page';\nimport { getNavModel } from 'app/core/selectors/navModel';\nimport { StoreState } from 'app/types/store';\n\ninterface Props {\n pageId: string;\n isLoading?: boolean;\n}\n\nexport const AlertingPageWrapper: FC = ({ children, pageId, isLoading }) => {\n const navModel = getNavModel(\n useSelector((state: StoreState) => state.navIndex),\n pageId\n );\n\n return (\n \n {children}\n \n );\n};\n","import { useCallback } from 'react';\n\nimport { useQueryParams } from 'app/core/hooks/useQueryParams';\nimport store from 'app/core/store';\n\nimport { ALERTMANAGER_NAME_LOCAL_STORAGE_KEY, ALERTMANAGER_NAME_QUERY_KEY } from '../utils/constants';\nimport { AlertManagerDataSource, GRAFANA_RULES_SOURCE_NAME } from '../utils/datasource';\n\nfunction useIsAlertManagerAvailable(availableAlertManagers: AlertManagerDataSource[]) {\n return useCallback(\n (alertManagerName: string) => {\n const availableAlertManagersNames = availableAlertManagers.map((am) => am.name);\n return availableAlertManagersNames.includes(alertManagerName);\n },\n [availableAlertManagers]\n );\n}\n\n/* This will return am name either from query params or from local storage or a default (grafana).\n * Due to RBAC permissions Grafana Managed Alert manager or external alert managers may not be available\n * In the worst case neihter GMA nor external alert manager is available\n */\nexport function useAlertManagerSourceName(\n availableAlertManagers: AlertManagerDataSource[]\n): [string | undefined, (alertManagerSourceName: string) => void] {\n const [queryParams, updateQueryParams] = useQueryParams();\n const isAlertManagerAvailable = useIsAlertManagerAvailable(availableAlertManagers);\n\n const update = useCallback(\n (alertManagerSourceName: string) => {\n if (!isAlertManagerAvailable(alertManagerSourceName)) {\n return;\n }\n if (alertManagerSourceName === GRAFANA_RULES_SOURCE_NAME) {\n store.delete(ALERTMANAGER_NAME_LOCAL_STORAGE_KEY);\n updateQueryParams({ [ALERTMANAGER_NAME_QUERY_KEY]: null });\n } else {\n store.set(ALERTMANAGER_NAME_LOCAL_STORAGE_KEY, alertManagerSourceName);\n updateQueryParams({ [ALERTMANAGER_NAME_QUERY_KEY]: alertManagerSourceName });\n }\n },\n [updateQueryParams, isAlertManagerAvailable]\n );\n\n const querySource = queryParams[ALERTMANAGER_NAME_QUERY_KEY];\n\n if (querySource && typeof querySource === 'string') {\n if (isAlertManagerAvailable(querySource)) {\n return [querySource, update];\n } else {\n // non existing alertmanager\n return [undefined, update];\n }\n }\n\n const storeSource = store.get(ALERTMANAGER_NAME_LOCAL_STORAGE_KEY);\n if (storeSource && typeof storeSource === 'string' && isAlertManagerAvailable(storeSource)) {\n update(storeSource);\n return [storeSource, update];\n }\n\n if (isAlertManagerAvailable(GRAFANA_RULES_SOURCE_NAME)) {\n return [GRAFANA_RULES_SOURCE_NAME, update];\n }\n\n return [undefined, update];\n}\n","import { useMemo } from 'react';\n\nimport { getAlertManagerDataSourcesByPermission } from '../utils/datasource';\n\nexport function useAlertManagersByPermission(accessType: 'instance' | 'notification') {\n return useMemo(() => getAlertManagerDataSourcesByPermission(accessType), [accessType]);\n}\n"],"names":["AlertmanagerConfig","dispatch","useDispatch","alertManagers","useAlertManagersByPermission","alertManagerSourceName","setAlertManagerSourceName","useAlertManagerSourceName","showConfirmDeleteAMConfig","setShowConfirmDeleteAMConfig","useState","loading","isDeleting","useUnifiedAlertingSelector","state","deleteAMConfig","isSaving","saveAMConfig","readOnly","isVanillaPrometheusAlertManagerDataSource","styles","useStyles2","getStyles","configRequests","amConfigs","result","config","isLoadingConfig","error","loadingError","initialAsyncRequestState","useEffect","fetchAlertManagerConfigAction","resetConfig","deleteAlertManagerConfigAction","defaultValues","useMemo","configJSON","JSON","stringify","className","container","AlertManagerPicker","current","onChange","dataSources","Alert","severity","title","message","GRAFANA_RULES_SOURCE_NAME","Form","onSubmit","values","updateAlertManagerConfigAction","newConfig","parse","oldConfig","successMessage","refetch","register","errors","Field","disabled","label","invalid","TextArea","required","value","validate","v","e","id","rows","HorizontalGroup","Button","type","variant","onClick","ConfirmModal","isOpen","body","confirmText","onConfirm","onDismiss","theme","css","spacing","SUFFIX_REGEX","AddAlertManagerModal","alertmanagers","onChangeAlertmanagerConfig","onClose","modalTitle","Icon","name","modalIcon","map","am","url","replace","Modal","modal","description","control","FieldArray","fields","append","remove","fieldArray","bold","muted","field","index","Input","input","defaultValue","placeholder","addonAfter","destroyInputRow","colors","text","secondary","cx","typography","fontWeightBold","inputRow","alertmanagerChoices","ExternalAlertmanagers","modalState","setModalState","open","payload","deleteModalState","setDeleteModalState","externalAlertManagers","discoveredAlertmanagers","useSelector","unifiedAlerting","externalAlertmanagers","data","alertmanagerConfig","enabledAlertmanagers","droppedAlertmanagers","droppedAlertManagers","status","actualUrl","activeAlertManagers","length","push","matchingActiveAM","find","useExternalAmSelector","alertmanagersChoice","useTheme2","fetchExternalAlertmanagersAction","fetchExternalAlertmanagersConfigAction","interval","setInterval","clearInterval","onDelete","useCallback","newList","filter","i","addExternalAlertmanagersAction","onEdit","ams","onOpenModal","onCloseModal","getStatusColor","success","main","warning","noAlertmanagers","actions","EmptyListCTA","buttonTitle","buttonIcon","table","style","width","Tooltip","content","color","RadioButtonGroup","options","onChangeAlertmanagerChoice","Admin","AlertingPageWrapper","pageId","children","isLoading","navModel","getNavModel","navIndex","availableAlertManagers","queryParams","updateQueryParams","useQueryParams","isAlertManagerAvailable","alertManagerName","includes","useIsAlertManagerAvailable","update","store","ALERTMANAGER_NAME_LOCAL_STORAGE_KEY","ALERTMANAGER_NAME_QUERY_KEY","querySource","undefined","storeSource","accessType","getAlertManagerDataSourcesByPermission"],"sourceRoot":""}