2022-04-22 08:33:13 -05:00
|
|
|
import { uniq } from 'lodash';
|
|
|
|
import React from 'react';
|
|
|
|
import { Redirect } from 'react-router-dom';
|
|
|
|
|
2022-04-13 10:19:54 -05:00
|
|
|
import { OrgRole } from '@grafana/data';
|
2022-09-05 04:07:13 -05:00
|
|
|
import { NavLandingPage } from 'app/core/components/AppChrome/NavLandingPage';
|
2021-10-25 07:40:45 -05:00
|
|
|
import { SafeDynamicImport } from 'app/core/components/DynamicImports/SafeDynamicImport';
|
|
|
|
import { config } from 'app/core/config';
|
|
|
|
import { RouteDescriptor } from 'app/core/navigation/types';
|
2022-03-21 18:54:37 -05:00
|
|
|
import { AccessControlAction } from 'app/types';
|
2022-04-22 08:33:13 -05:00
|
|
|
|
2022-04-06 11:24:33 -05:00
|
|
|
import { evaluateAccess } from './unified/utils/access-control';
|
2021-10-25 07:40:45 -05:00
|
|
|
|
2022-02-02 03:57:43 -06:00
|
|
|
const commonRoutes: RouteDescriptor[] = [
|
2021-10-25 07:40:45 -05:00
|
|
|
{
|
|
|
|
path: '/alerting',
|
2022-09-05 04:07:13 -05:00
|
|
|
component: () =>
|
|
|
|
config.featureToggles.topnav ? <NavLandingPage navId="alerting" /> : <Redirect to="/alerting/list" />,
|
2021-10-25 07:40:45 -05:00
|
|
|
},
|
2022-02-02 03:57:43 -06:00
|
|
|
];
|
|
|
|
|
|
|
|
const legacyRoutes: RouteDescriptor[] = [
|
|
|
|
...commonRoutes,
|
2021-10-25 07:40:45 -05:00
|
|
|
{
|
|
|
|
path: '/alerting/list',
|
|
|
|
component: SafeDynamicImport(
|
2022-02-02 03:57:43 -06:00
|
|
|
() => import(/* webpackChunkName: "AlertRuleListIndex" */ 'app/features/alerting/AlertRuleList')
|
2021-10-25 07:40:45 -05:00
|
|
|
),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
path: '/alerting/ng/list',
|
|
|
|
component: SafeDynamicImport(
|
|
|
|
() => import(/* webpackChunkName: "AlertRuleList" */ 'app/features/alerting/AlertRuleList')
|
|
|
|
),
|
|
|
|
},
|
2022-02-02 03:57:43 -06:00
|
|
|
{
|
|
|
|
path: '/alerting/notifications',
|
|
|
|
roles: config.unifiedAlertingEnabled ? () => ['Editor', 'Admin'] : undefined,
|
|
|
|
component: SafeDynamicImport(
|
|
|
|
() => import(/* webpackChunkName: "NotificationsListPage" */ 'app/features/alerting/NotificationsListPage')
|
|
|
|
),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
path: '/alerting/notifications/templates/new',
|
|
|
|
roles: () => ['Editor', 'Admin'],
|
|
|
|
component: SafeDynamicImport(
|
|
|
|
() => import(/* webpackChunkName: "NotificationsListPage" */ 'app/features/alerting/NotificationsListPage')
|
|
|
|
),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
path: '/alerting/notifications/templates/:id/edit',
|
|
|
|
roles: () => ['Editor', 'Admin'],
|
|
|
|
component: SafeDynamicImport(
|
|
|
|
() => import(/* webpackChunkName: "NotificationsListPage" */ 'app/features/alerting/NotificationsListPage')
|
|
|
|
),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
path: '/alerting/notifications/receivers/new',
|
|
|
|
roles: () => ['Editor', 'Admin'],
|
|
|
|
component: SafeDynamicImport(
|
|
|
|
() => import(/* webpackChunkName: "NotificationsListPage" */ 'app/features/alerting/NotificationsListPage')
|
|
|
|
),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
path: '/alerting/notifications/receivers/:id/edit',
|
|
|
|
roles: () => ['Editor', 'Admin'],
|
|
|
|
component: SafeDynamicImport(
|
|
|
|
() => import(/* webpackChunkName: "NotificationsListPage" */ 'app/features/alerting/NotificationsListPage')
|
|
|
|
),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
path: '/alerting/notifications/global-config',
|
|
|
|
roles: () => ['Admin', 'Editor'],
|
|
|
|
component: SafeDynamicImport(
|
|
|
|
() => import(/* webpackChunkName: "NotificationsListPage" */ 'app/features/alerting/NotificationsListPage')
|
|
|
|
),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
path: '/alerting/notification/new',
|
|
|
|
component: SafeDynamicImport(
|
|
|
|
() => import(/* webpackChunkName: "NewNotificationChannel" */ 'app/features/alerting/NewNotificationChannelPage')
|
|
|
|
),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
path: '/alerting/notification/:id/edit',
|
|
|
|
component: SafeDynamicImport(
|
|
|
|
() => import(/* webpackChunkName: "EditNotificationChannel"*/ 'app/features/alerting/EditNotificationChannelPage')
|
|
|
|
),
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
const unifiedRoutes: RouteDescriptor[] = [
|
|
|
|
...commonRoutes,
|
|
|
|
{
|
|
|
|
path: '/alerting/list',
|
2022-04-08 06:34:02 -05:00
|
|
|
roles: evaluateAccess(
|
|
|
|
[AccessControlAction.AlertingRuleRead, AccessControlAction.AlertingRuleExternalRead],
|
|
|
|
[OrgRole.Viewer, OrgRole.Editor, OrgRole.Admin]
|
|
|
|
),
|
2022-02-02 03:57:43 -06:00
|
|
|
component: SafeDynamicImport(
|
|
|
|
() => import(/* webpackChunkName: "AlertRuleListIndex" */ 'app/features/alerting/unified/RuleList')
|
|
|
|
),
|
|
|
|
},
|
2021-10-25 07:40:45 -05:00
|
|
|
{
|
|
|
|
path: '/alerting/routes',
|
2022-04-13 10:19:54 -05:00
|
|
|
roles: evaluateAccess(
|
|
|
|
[AccessControlAction.AlertingNotificationsRead, AccessControlAction.AlertingNotificationsExternalRead],
|
|
|
|
[OrgRole.Editor, OrgRole.Admin]
|
|
|
|
),
|
2021-10-25 07:40:45 -05:00
|
|
|
component: SafeDynamicImport(
|
|
|
|
() => import(/* webpackChunkName: "AlertAmRoutes" */ 'app/features/alerting/unified/AmRoutes')
|
|
|
|
),
|
|
|
|
},
|
2022-01-05 12:16:43 -06:00
|
|
|
{
|
|
|
|
path: '/alerting/routes/mute-timing/new',
|
2022-04-06 11:24:33 -05:00
|
|
|
roles: evaluateAccess(
|
2022-05-20 09:55:07 -05:00
|
|
|
[AccessControlAction.AlertingNotificationsWrite, AccessControlAction.AlertingNotificationsExternalWrite],
|
2022-04-06 11:24:33 -05:00
|
|
|
['Editor', 'Admin']
|
|
|
|
),
|
2022-01-05 12:16:43 -06:00
|
|
|
component: SafeDynamicImport(
|
|
|
|
() => import(/* webpackChunkName: "MuteTimings" */ 'app/features/alerting/unified/MuteTimings')
|
|
|
|
),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
path: '/alerting/routes/mute-timing/edit',
|
2022-04-06 11:24:33 -05:00
|
|
|
roles: evaluateAccess(
|
2022-05-20 09:55:07 -05:00
|
|
|
[AccessControlAction.AlertingNotificationsWrite, AccessControlAction.AlertingNotificationsExternalWrite],
|
2022-04-06 11:24:33 -05:00
|
|
|
['Editor', 'Admin']
|
|
|
|
),
|
2022-01-05 12:16:43 -06:00
|
|
|
component: SafeDynamicImport(
|
|
|
|
() => import(/* webpackChunkName: "MuteTimings" */ 'app/features/alerting/unified/MuteTimings')
|
|
|
|
),
|
|
|
|
},
|
2021-10-25 07:40:45 -05:00
|
|
|
{
|
|
|
|
path: '/alerting/silences',
|
2022-05-05 06:34:58 -05:00
|
|
|
roles: evaluateAccess(
|
|
|
|
[AccessControlAction.AlertingInstanceRead, AccessControlAction.AlertingInstancesExternalRead],
|
2022-05-19 08:22:26 -05:00
|
|
|
['Viewer', 'Editor', 'Admin']
|
2022-05-05 06:34:58 -05:00
|
|
|
),
|
2021-10-25 07:40:45 -05:00
|
|
|
component: SafeDynamicImport(
|
|
|
|
() => import(/* webpackChunkName: "AlertSilences" */ 'app/features/alerting/unified/Silences')
|
|
|
|
),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
path: '/alerting/silence/new',
|
2022-04-06 11:24:33 -05:00
|
|
|
roles: evaluateAccess(
|
|
|
|
[AccessControlAction.AlertingInstanceCreate, AccessControlAction.AlertingInstancesExternalWrite],
|
|
|
|
['Editor', 'Admin']
|
|
|
|
),
|
2021-10-25 07:40:45 -05:00
|
|
|
component: SafeDynamicImport(
|
|
|
|
() => import(/* webpackChunkName: "AlertSilences" */ 'app/features/alerting/unified/Silences')
|
|
|
|
),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
path: '/alerting/silence/:id/edit',
|
2022-04-06 11:24:33 -05:00
|
|
|
roles: evaluateAccess(
|
|
|
|
[AccessControlAction.AlertingInstanceUpdate, AccessControlAction.AlertingInstancesExternalWrite],
|
|
|
|
['Editor', 'Admin']
|
|
|
|
),
|
2021-10-25 07:40:45 -05:00
|
|
|
component: SafeDynamicImport(
|
|
|
|
() => import(/* webpackChunkName: "AlertSilences" */ 'app/features/alerting/unified/Silences')
|
|
|
|
),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
path: '/alerting/notifications',
|
2022-04-06 11:24:33 -05:00
|
|
|
roles: evaluateAccess(
|
|
|
|
[AccessControlAction.AlertingNotificationsRead, AccessControlAction.AlertingNotificationsExternalRead],
|
|
|
|
['Editor', 'Admin']
|
|
|
|
),
|
2021-10-25 07:40:45 -05:00
|
|
|
component: SafeDynamicImport(
|
2022-02-02 03:57:43 -06:00
|
|
|
() => import(/* webpackChunkName: "NotificationsListPage" */ 'app/features/alerting/unified/Receivers')
|
2021-10-25 07:40:45 -05:00
|
|
|
),
|
|
|
|
},
|
|
|
|
{
|
2022-09-06 09:25:07 -05:00
|
|
|
path: '/alerting/notifications/:type/new',
|
2022-04-06 11:24:33 -05:00
|
|
|
roles: evaluateAccess(
|
2022-05-20 09:55:07 -05:00
|
|
|
[AccessControlAction.AlertingNotificationsWrite, AccessControlAction.AlertingNotificationsExternalWrite],
|
2022-04-06 11:24:33 -05:00
|
|
|
['Editor', 'Admin']
|
|
|
|
),
|
2021-10-25 07:40:45 -05:00
|
|
|
component: SafeDynamicImport(
|
2022-02-02 03:57:43 -06:00
|
|
|
() => import(/* webpackChunkName: "NotificationsListPage" */ 'app/features/alerting/unified/Receivers')
|
2021-10-25 07:40:45 -05:00
|
|
|
),
|
|
|
|
},
|
|
|
|
{
|
2022-09-06 09:25:07 -05:00
|
|
|
path: '/alerting/notifications/:type/:id/edit',
|
2022-04-06 11:24:33 -05:00
|
|
|
roles: evaluateAccess(
|
2022-05-20 09:55:07 -05:00
|
|
|
[AccessControlAction.AlertingNotificationsWrite, AccessControlAction.AlertingNotificationsExternalWrite],
|
2022-04-06 11:24:33 -05:00
|
|
|
['Editor', 'Admin']
|
|
|
|
),
|
2021-10-25 07:40:45 -05:00
|
|
|
component: SafeDynamicImport(
|
2022-02-02 03:57:43 -06:00
|
|
|
() => import(/* webpackChunkName: "NotificationsListPage" */ 'app/features/alerting/unified/Receivers')
|
2021-10-25 07:40:45 -05:00
|
|
|
),
|
|
|
|
},
|
|
|
|
{
|
2022-09-06 09:25:07 -05:00
|
|
|
path: '/alerting/notifications/:type',
|
2022-04-06 11:24:33 -05:00
|
|
|
roles: evaluateAccess(
|
2022-05-20 09:55:07 -05:00
|
|
|
[AccessControlAction.AlertingNotificationsWrite, AccessControlAction.AlertingNotificationsExternalWrite],
|
2022-04-06 11:24:33 -05:00
|
|
|
['Editor', 'Admin']
|
|
|
|
),
|
2021-10-25 07:40:45 -05:00
|
|
|
component: SafeDynamicImport(
|
2022-02-02 03:57:43 -06:00
|
|
|
() => import(/* webpackChunkName: "NotificationsListPage" */ 'app/features/alerting/unified/Receivers')
|
2021-10-25 07:40:45 -05:00
|
|
|
),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
path: '/alerting/groups/',
|
2022-04-08 06:34:02 -05:00
|
|
|
roles: evaluateAccess(
|
|
|
|
[AccessControlAction.AlertingInstanceRead, AccessControlAction.AlertingInstancesExternalRead],
|
|
|
|
[OrgRole.Viewer, OrgRole.Editor, OrgRole.Admin]
|
|
|
|
),
|
2021-10-25 07:40:45 -05:00
|
|
|
component: SafeDynamicImport(
|
|
|
|
() => import(/* webpackChunkName: "AlertGroups" */ 'app/features/alerting/unified/AlertGroups')
|
|
|
|
),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
path: '/alerting/new',
|
|
|
|
pageClass: 'page-alerting',
|
2022-04-08 06:34:02 -05:00
|
|
|
roles: evaluateAccess(
|
|
|
|
[AccessControlAction.AlertingRuleCreate, AccessControlAction.AlertingRuleExternalWrite],
|
2022-05-23 08:58:20 -05:00
|
|
|
[OrgRole.Viewer, OrgRole.Editor, OrgRole.Admin] // Needs to include viewer because there may be Viewers with Edit permissions in folders
|
2022-04-08 06:34:02 -05:00
|
|
|
),
|
2021-10-25 07:40:45 -05:00
|
|
|
component: SafeDynamicImport(
|
|
|
|
() => import(/* webpackChunkName: "AlertingRuleForm"*/ 'app/features/alerting/unified/RuleEditor')
|
|
|
|
),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
path: '/alerting/:id/edit',
|
|
|
|
pageClass: 'page-alerting',
|
2022-04-08 06:34:02 -05:00
|
|
|
roles: evaluateAccess(
|
|
|
|
[AccessControlAction.AlertingRuleUpdate, AccessControlAction.AlertingRuleExternalWrite],
|
2022-05-23 08:58:20 -05:00
|
|
|
[OrgRole.Viewer, OrgRole.Editor, OrgRole.Admin] // Needs to include viewer because there may be Viewers with Edit permissions in folders
|
2022-04-08 06:34:02 -05:00
|
|
|
),
|
2021-10-25 07:40:45 -05:00
|
|
|
component: SafeDynamicImport(
|
|
|
|
() => import(/* webpackChunkName: "AlertingRuleForm"*/ 'app/features/alerting/unified/RuleEditor')
|
|
|
|
),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
path: '/alerting/:sourceName/:id/view',
|
|
|
|
pageClass: 'page-alerting',
|
2022-04-08 06:34:02 -05:00
|
|
|
roles: evaluateAccess(
|
|
|
|
[AccessControlAction.AlertingRuleRead, AccessControlAction.AlertingRuleExternalRead],
|
|
|
|
[OrgRole.Viewer, OrgRole.Editor, OrgRole.Admin]
|
|
|
|
),
|
2021-10-25 07:40:45 -05:00
|
|
|
component: SafeDynamicImport(
|
|
|
|
() => import(/* webpackChunkName: "AlertingRule"*/ 'app/features/alerting/unified/RuleViewer')
|
|
|
|
),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
path: '/alerting/:sourceName/:name/find',
|
|
|
|
pageClass: 'page-alerting',
|
2022-04-13 10:19:54 -05:00
|
|
|
roles: evaluateAccess(
|
|
|
|
[AccessControlAction.AlertingRuleRead, AccessControlAction.AlertingRuleExternalRead],
|
|
|
|
[OrgRole.Viewer, OrgRole.Editor, OrgRole.Admin]
|
|
|
|
),
|
2021-10-25 07:40:45 -05:00
|
|
|
component: SafeDynamicImport(
|
|
|
|
() => import(/* webpackChunkName: "AlertingRedirectToRule"*/ 'app/features/alerting/unified/RedirectToRuleViewer')
|
|
|
|
),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
path: '/alerting/admin',
|
|
|
|
roles: () => ['Admin'],
|
|
|
|
component: SafeDynamicImport(
|
|
|
|
() => import(/* webpackChunkName: "AlertingAdmin" */ 'app/features/alerting/unified/Admin')
|
|
|
|
),
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
export function getAlertingRoutes(cfg = config): RouteDescriptor[] {
|
2022-02-02 03:57:43 -06:00
|
|
|
if (cfg.unifiedAlertingEnabled) {
|
|
|
|
return unifiedRoutes;
|
|
|
|
} else if (cfg.alertingEnabled) {
|
|
|
|
return legacyRoutes;
|
2021-10-25 07:40:45 -05:00
|
|
|
}
|
|
|
|
|
2022-02-02 03:57:43 -06:00
|
|
|
const uniquePaths = uniq([...legacyRoutes, ...unifiedRoutes].map((route) => route.path));
|
|
|
|
return uniquePaths.map((path) => ({
|
|
|
|
path,
|
2021-10-25 07:40:45 -05:00
|
|
|
component: SafeDynamicImport(
|
2022-05-16 08:26:14 -05:00
|
|
|
() => import(/* webpackChunkName: "AlertingFeatureTogglePage"*/ 'app/features/alerting/FeatureTogglePage')
|
2021-10-25 07:40:45 -05:00
|
|
|
),
|
|
|
|
}));
|
|
|
|
}
|