ReceiversAndTemplatesView.tsx 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import { css } from '@emotion/css';
  2. import React, { FC } from 'react';
  3. import { GrafanaTheme2 } from '@grafana/data';
  4. import { Alert, LinkButton, useStyles2 } from '@grafana/ui';
  5. import { AlertManagerCortexConfig } from 'app/plugins/datasource/alertmanager/types';
  6. import { AccessControlAction } from 'app/types';
  7. import { GRAFANA_RULES_SOURCE_NAME, isVanillaPrometheusAlertManagerDataSource } from '../../utils/datasource';
  8. import { makeAMLink } from '../../utils/misc';
  9. import { Authorize } from '../Authorize';
  10. import { ReceiversTable } from './ReceiversTable';
  11. import { TemplatesTable } from './TemplatesTable';
  12. interface Props {
  13. config: AlertManagerCortexConfig;
  14. alertManagerName: string;
  15. }
  16. export const ReceiversAndTemplatesView: FC<Props> = ({ config, alertManagerName }) => {
  17. const isCloud = alertManagerName !== GRAFANA_RULES_SOURCE_NAME;
  18. const styles = useStyles2(getStyles);
  19. const isVanillaAM = isVanillaPrometheusAlertManagerDataSource(alertManagerName);
  20. return (
  21. <>
  22. {!isVanillaAM && <TemplatesTable config={config} alertManagerName={alertManagerName} />}
  23. <ReceiversTable config={config} alertManagerName={alertManagerName} />
  24. {isCloud && (
  25. <Authorize actions={[AccessControlAction.AlertingNotificationsExternalWrite]}>
  26. <Alert className={styles.section} severity="info" title="Global config for contact points">
  27. <p>
  28. For each external Alertmanager you can define global settings, like server addresses, usernames and
  29. password, for all the supported contact points.
  30. </p>
  31. <LinkButton href={makeAMLink('alerting/notifications/global-config', alertManagerName)} variant="secondary">
  32. {isVanillaAM ? 'View global config' : 'Edit global config'}
  33. </LinkButton>
  34. </Alert>
  35. </Authorize>
  36. )}
  37. </>
  38. );
  39. };
  40. const getStyles = (theme: GrafanaTheme2) => ({
  41. section: css`
  42. margin-top: ${theme.spacing(4)};
  43. `,
  44. });