Alerting: Fix check for contact point email in IRM essentials page (#98977)
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
import { useEffect } from 'react';
|
||||
|
||||
import { alertRuleApi } from 'app/features/alerting/unified/api/alertRuleApi';
|
||||
import { alertmanagerApi } from 'app/features/alerting/unified/api/alertmanagerApi';
|
||||
import { ReceiverTypes } from 'app/features/alerting/unified/components/receivers/grafanaAppReceivers/onCall/onCall';
|
||||
import { useDataSourceFeatures } from 'app/features/alerting/unified/hooks/useCombinedRule';
|
||||
import { GRAFANA_RULES_SOURCE_NAME } from 'app/features/alerting/unified/utils/datasource';
|
||||
@@ -34,20 +33,3 @@ export function isOnCallContactPointReady(contactPoints: Receiver[]) {
|
||||
contactPoint.grafana_managed_receiver_configs?.some((receiver) => receiver.type === ReceiverTypes.OnCall)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Will be removed when notification policies is moved to k8s API. Do not use!
|
||||
*/
|
||||
export function useGetDefaultContactPoint() {
|
||||
const alertmanagerConfiguration = alertmanagerApi.endpoints.getAlertmanagerConfiguration.useQuery(
|
||||
GRAFANA_RULES_SOURCE_NAME,
|
||||
{
|
||||
refetchOnFocus: true,
|
||||
refetchOnReconnect: true,
|
||||
refetchOnMountOrArgChange: true,
|
||||
}
|
||||
);
|
||||
|
||||
const defaultContactpoint = alertmanagerConfiguration.data?.alertmanager_config?.route?.receiver ?? '';
|
||||
return { defaultContactpoint, isLoading: alertmanagerConfiguration.isLoading };
|
||||
}
|
||||
|
||||
@@ -2,14 +2,21 @@ import { Receiver } from 'app/plugins/datasource/alertmanager/types';
|
||||
const DEFAULT_EMAIL = '<example@email.com>';
|
||||
|
||||
export function isContactPointReady(defaultContactPoint: string, contactPoints: Receiver[]) {
|
||||
// We consider the contact point ready if the default contact has the address filled
|
||||
|
||||
const defaultEmailUpdated = contactPoints.some(
|
||||
(contactPoint: Receiver) =>
|
||||
contactPoint.name === defaultContactPoint &&
|
||||
contactPoint.grafana_managed_receiver_configs?.some(
|
||||
(receiver) => receiver.name === defaultContactPoint && receiver.settings?.address !== DEFAULT_EMAIL
|
||||
)
|
||||
// We consider the contact point ready if the default contact is no longer referencing the default email address
|
||||
const matchingDefaultContactPoint = contactPoints.find(
|
||||
(contactPoint: Receiver) => contactPoint.name === defaultContactPoint
|
||||
);
|
||||
return defaultEmailUpdated;
|
||||
|
||||
if (!matchingDefaultContactPoint) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return matchingDefaultContactPoint.grafana_managed_receiver_configs?.some((receiver) => {
|
||||
const isEmailReceiver = receiver.type === 'email';
|
||||
if (isEmailReceiver) {
|
||||
return receiver.settings?.addresses !== DEFAULT_EMAIL;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -2,9 +2,11 @@ import { useMemo } from 'react';
|
||||
|
||||
import { locationService } from '@grafana/runtime';
|
||||
import { useGrafanaContactPoints } from 'app/features/alerting/unified/components/contact-points/useContactPoints';
|
||||
import { useNotificationPolicyRoute } from 'app/features/alerting/unified/components/notification-policies/useNotificationPolicyRoute';
|
||||
import { GRAFANA_RULES_SOURCE_NAME } from 'app/features/alerting/unified/utils/datasource';
|
||||
import { RelativeUrl, createRelativeUrl } from 'app/features/alerting/unified/utils/url';
|
||||
|
||||
import { isOnCallContactPointReady, useGetDefaultContactPoint, useIsCreateAlertRuleDone } from './alerting/hooks';
|
||||
import { isOnCallContactPointReady, useIsCreateAlertRuleDone } from './alerting/hooks';
|
||||
import { isContactPointReady } from './alerting/utils';
|
||||
import { ConfigurationStepsEnum, DataSourceConfigurationData, IrmCardConfiguration } from './components/ConfigureIRM';
|
||||
import { useGetIncidentPluginConfig } from './incidents/hooks';
|
||||
@@ -50,8 +52,10 @@ export interface EssentialsConfigurationData {
|
||||
function useGetConfigurationForApps() {
|
||||
// configuration checks for alerting
|
||||
const { contactPoints, isLoading: isLoadingContactPoints } = useGrafanaContactPoints();
|
||||
// TODO: Switch to k8s API/refactored notification policies hook when available
|
||||
const { defaultContactpoint, isLoading: isLoadingDefaultContactPoint } = useGetDefaultContactPoint();
|
||||
const { data: rootRoute, isLoading: isLoadingDefaultContactPoint } = useNotificationPolicyRoute({
|
||||
alertmanager: GRAFANA_RULES_SOURCE_NAME,
|
||||
});
|
||||
const defaultContactpoint = rootRoute?.[0].receiver || '';
|
||||
const { isDone: isCreateAlertRuleDone, isLoading: isLoadingAlertCreatedDone } = useIsCreateAlertRuleDone();
|
||||
// configuration checks for incidents
|
||||
const {
|
||||
@@ -124,8 +128,8 @@ export function useGetEssentialsConfiguration(): EssentialsConfigurationData {
|
||||
description: 'Configure Grafana Alerting',
|
||||
steps: [
|
||||
{
|
||||
title: 'Update default email contact point',
|
||||
description: 'Add a valid email to the default email contact point.',
|
||||
title: 'Update default contact point',
|
||||
description: 'Update the default contact point to a method other than the example email address.',
|
||||
button: {
|
||||
type: 'openLink',
|
||||
urlLink: {
|
||||
|
||||
Reference in New Issue
Block a user