- {' '}
- Alertmanager:
+
Alertmanager:

{alertManagerSource.name}
diff --git a/public/app/features/alerting/unified/components/rule-editor/notificaton-preview/useAlertmanagerNotificationRoutingPreview.ts b/public/app/features/alerting/unified/components/rule-editor/notificaton-preview/useAlertmanagerNotificationRoutingPreview.ts
index a8df723da12..b6dcfb3e746 100644
--- a/public/app/features/alerting/unified/components/rule-editor/notificaton-preview/useAlertmanagerNotificationRoutingPreview.ts
+++ b/public/app/features/alerting/unified/components/rule-editor/notificaton-preview/useAlertmanagerNotificationRoutingPreview.ts
@@ -1,9 +1,11 @@
import { useMemo } from 'react';
import { useAsync } from 'react-use';
+import { useContactPointsWithStatus } from 'app/features/alerting/unified/components/contact-points/useContactPoints';
+import { useNotificationPolicyRoute } from 'app/features/alerting/unified/components/notification-policies/useNotificationPolicyRoute';
+
import { Receiver } from '../../../../../../plugins/datasource/alertmanager/types';
import { Labels } from '../../../../../../types/unified-alerting-dto';
-import { useAlertmanagerConfig } from '../../../hooks/useAlertmanagerConfig';
import { useRouteGroupsMatcher } from '../../../useRouteGroupsMatcher';
import { addUniqueIdentifierToRoute } from '../../../utils/amroutes';
import { GRAFANA_RULES_SOURCE_NAME } from '../../../utils/datasource';
@@ -11,41 +13,50 @@ import { AlertInstanceMatch, computeInheritedTree, normalizeRoute } from '../../
import { getRoutesByIdMap, RouteWithPath } from './route';
-export const useAlertmanagerNotificationRoutingPreview = (
- alertManagerSourceName: string,
- potentialInstances: Labels[]
-) => {
- const { currentData, isLoading: configLoading, error: configError } = useAlertmanagerConfig(alertManagerSourceName);
- const config = currentData?.alertmanager_config;
+export const useAlertmanagerNotificationRoutingPreview = (alertmanager: string, potentialInstances: Labels[]) => {
+ const {
+ data: currentData,
+ isLoading: isPoliciesLoading,
+ error: policiesError,
+ } = useNotificationPolicyRoute({ alertmanager });
+
+ const {
+ contactPoints,
+ isLoading: contactPointsLoading,
+ error: contactPointsError,
+ } = useContactPointsWithStatus({
+ alertmanager,
+ fetchPolicies: false,
+ fetchStatuses: false,
+ });
const { matchInstancesToRoute } = useRouteGroupsMatcher();
- // to create the list of matching contact points we need to first get the rootRoute
- const { rootRoute, receivers } = useMemo(() => {
- if (!config) {
- return {
- receivers: [],
- rootRoute: undefined,
- };
+ const [defaultPolicy] = currentData ?? [];
+ const rootRoute = useMemo(() => {
+ if (!defaultPolicy) {
+ return;
}
-
- return {
- rootRoute: config.route ? normalizeRoute(addUniqueIdentifierToRoute(config.route)) : undefined,
- receivers: config.receivers ?? [],
- };
- }, [config]);
+ return normalizeRoute(addUniqueIdentifierToRoute(defaultPolicy));
+ }, [defaultPolicy]);
// create maps for routes to be get by id, this map also contains the path to the route
// ⚠️ don't forget to compute the inherited tree before using this map
- const routesByIdMap: Map