mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Alerting: Prevent alerting routes from working if alerting is not enabled (#40521)
* show alerting not enabled when not enabled * correct navmodel index * use correct config values
This commit is contained in:
parent
68266d54be
commit
57750639cd
31
public/app/features/alerting/FeatureTogglePage.tsx
Normal file
31
public/app/features/alerting/FeatureTogglePage.tsx
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import Page from 'app/core/components/Page/Page';
|
||||||
|
import { useNavModel } from 'app/core/hooks/useNavModel';
|
||||||
|
|
||||||
|
export default function FeatureTogglePage() {
|
||||||
|
const navModel = useNavModel('alert-list');
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Page navModel={navModel}>
|
||||||
|
<Page.Contents>
|
||||||
|
<h1>Alerting is not enabled</h1>
|
||||||
|
To enable alerting, enable it in the Grafana config:
|
||||||
|
<div>
|
||||||
|
<pre>
|
||||||
|
{`[unified_alerting]
|
||||||
|
enable = true
|
||||||
|
`}
|
||||||
|
</pre>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
For legacy alerting
|
||||||
|
<pre>
|
||||||
|
{`[alerting]
|
||||||
|
enable = true
|
||||||
|
`}
|
||||||
|
</pre>
|
||||||
|
</div>
|
||||||
|
</Page.Contents>
|
||||||
|
</Page>
|
||||||
|
);
|
||||||
|
}
|
160
public/app/features/alerting/routes.tsx
Normal file
160
public/app/features/alerting/routes.tsx
Normal file
@ -0,0 +1,160 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { Redirect } from 'react-router-dom';
|
||||||
|
import { SafeDynamicImport } from 'app/core/components/DynamicImports/SafeDynamicImport';
|
||||||
|
import { config } from 'app/core/config';
|
||||||
|
import { RouteDescriptor } from 'app/core/navigation/types';
|
||||||
|
|
||||||
|
const alertingRoutes = [
|
||||||
|
{
|
||||||
|
path: '/alerting',
|
||||||
|
// eslint-disable-next-line react/display-name
|
||||||
|
component: () => <Redirect to="/alerting/list" />,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/alerting/list',
|
||||||
|
component: SafeDynamicImport(
|
||||||
|
() => import(/* webpackChunkName: "AlertRuleListIndex" */ 'app/features/alerting/AlertRuleListIndex')
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/alerting/ng/list',
|
||||||
|
component: SafeDynamicImport(
|
||||||
|
() => import(/* webpackChunkName: "AlertRuleList" */ 'app/features/alerting/AlertRuleList')
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/alerting/routes',
|
||||||
|
roles: () => ['Admin', 'Editor'],
|
||||||
|
component: SafeDynamicImport(
|
||||||
|
() => import(/* webpackChunkName: "AlertAmRoutes" */ 'app/features/alerting/unified/AmRoutes')
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/alerting/silences',
|
||||||
|
component: SafeDynamicImport(
|
||||||
|
() => import(/* webpackChunkName: "AlertSilences" */ 'app/features/alerting/unified/Silences')
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/alerting/silence/new',
|
||||||
|
roles: () => ['Editor', 'Admin'],
|
||||||
|
component: SafeDynamicImport(
|
||||||
|
() => import(/* webpackChunkName: "AlertSilences" */ 'app/features/alerting/unified/Silences')
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/alerting/silence/:id/edit',
|
||||||
|
roles: () => ['Editor', 'Admin'],
|
||||||
|
component: SafeDynamicImport(
|
||||||
|
() => import(/* webpackChunkName: "AlertSilences" */ 'app/features/alerting/unified/Silences')
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/alerting/notifications',
|
||||||
|
roles: config.unifiedAlertingEnabled ? () => ['Editor', 'Admin'] : undefined,
|
||||||
|
component: SafeDynamicImport(
|
||||||
|
() => import(/* webpackChunkName: "NotificationsListPage" */ 'app/features/alerting/NotificationsIndex')
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/alerting/notifications/templates/new',
|
||||||
|
roles: () => ['Editor', 'Admin'],
|
||||||
|
component: SafeDynamicImport(
|
||||||
|
() => import(/* webpackChunkName: "NotificationsListPage" */ 'app/features/alerting/NotificationsIndex')
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/alerting/notifications/templates/:id/edit',
|
||||||
|
roles: () => ['Editor', 'Admin'],
|
||||||
|
component: SafeDynamicImport(
|
||||||
|
() => import(/* webpackChunkName: "NotificationsListPage" */ 'app/features/alerting/NotificationsIndex')
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/alerting/notifications/receivers/new',
|
||||||
|
roles: () => ['Editor', 'Admin'],
|
||||||
|
component: SafeDynamicImport(
|
||||||
|
() => import(/* webpackChunkName: "NotificationsListPage" */ 'app/features/alerting/NotificationsIndex')
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/alerting/notifications/receivers/:id/edit',
|
||||||
|
roles: () => ['Editor', 'Admin'],
|
||||||
|
component: SafeDynamicImport(
|
||||||
|
() => import(/* webpackChunkName: "NotificationsListPage" */ 'app/features/alerting/NotificationsIndex')
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/alerting/notifications/global-config',
|
||||||
|
roles: () => ['Admin', 'Editor'],
|
||||||
|
component: SafeDynamicImport(
|
||||||
|
() => import(/* webpackChunkName: "NotificationsListPage" */ 'app/features/alerting/NotificationsIndex')
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
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')
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/alerting/groups/',
|
||||||
|
component: SafeDynamicImport(
|
||||||
|
() => import(/* webpackChunkName: "AlertGroups" */ 'app/features/alerting/unified/AlertGroups')
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/alerting/new',
|
||||||
|
pageClass: 'page-alerting',
|
||||||
|
component: SafeDynamicImport(
|
||||||
|
() => import(/* webpackChunkName: "AlertingRuleForm"*/ 'app/features/alerting/unified/RuleEditor')
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/alerting/:id/edit',
|
||||||
|
pageClass: 'page-alerting',
|
||||||
|
component: SafeDynamicImport(
|
||||||
|
() => import(/* webpackChunkName: "AlertingRuleForm"*/ 'app/features/alerting/unified/RuleEditor')
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/alerting/:sourceName/:id/view',
|
||||||
|
pageClass: 'page-alerting',
|
||||||
|
component: SafeDynamicImport(
|
||||||
|
() => import(/* webpackChunkName: "AlertingRule"*/ 'app/features/alerting/unified/RuleViewer')
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/alerting/:sourceName/:name/find',
|
||||||
|
pageClass: 'page-alerting',
|
||||||
|
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[] {
|
||||||
|
if (cfg.alertingEnabled || cfg.unifiedAlertingEnabled) {
|
||||||
|
return alertingRoutes;
|
||||||
|
}
|
||||||
|
|
||||||
|
return alertingRoutes.map((route) => ({
|
||||||
|
...route,
|
||||||
|
component: SafeDynamicImport(
|
||||||
|
() => import(/* webpackChunkName: "Alerting feature toggle page"*/ 'app/features/alerting/FeatureTogglePage')
|
||||||
|
),
|
||||||
|
}));
|
||||||
|
}
|
@ -11,6 +11,7 @@ import ErrorPage from 'app/core/components/ErrorPage/ErrorPage';
|
|||||||
import { getPluginsAdminRoutes } from 'app/features/plugins/routes';
|
import { getPluginsAdminRoutes } from 'app/features/plugins/routes';
|
||||||
import { contextSrv } from 'app/core/services/context_srv';
|
import { contextSrv } from 'app/core/services/context_srv';
|
||||||
import { getLiveRoutes } from 'app/features/live/pages/routes';
|
import { getLiveRoutes } from 'app/features/live/pages/routes';
|
||||||
|
import { getAlertingRoutes } from 'app/features/alerting/routes';
|
||||||
|
|
||||||
export const extraRoutes: RouteDescriptor[] = [];
|
export const extraRoutes: RouteDescriptor[] = [];
|
||||||
|
|
||||||
@ -330,148 +331,6 @@ export function getAppRoutes(): RouteDescriptor[] {
|
|||||||
// controller: 'AppPageCtrl',
|
// controller: 'AppPageCtrl',
|
||||||
// controllerAs: 'ctrl',
|
// controllerAs: 'ctrl',
|
||||||
// },
|
// },
|
||||||
{
|
|
||||||
path: '/alerting',
|
|
||||||
// eslint-disable-next-line react/display-name
|
|
||||||
component: () => <Redirect to="/alerting/list" />,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
path: '/alerting/list',
|
|
||||||
component: SafeDynamicImport(
|
|
||||||
() => import(/* webpackChunkName: "AlertRuleListIndex" */ 'app/features/alerting/AlertRuleListIndex')
|
|
||||||
),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
path: '/alerting/ng/list',
|
|
||||||
component: SafeDynamicImport(
|
|
||||||
() => import(/* webpackChunkName: "AlertRuleList" */ 'app/features/alerting/AlertRuleList')
|
|
||||||
),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
path: '/alerting/routes',
|
|
||||||
roles: () => ['Admin', 'Editor'],
|
|
||||||
component: SafeDynamicImport(
|
|
||||||
() => import(/* webpackChunkName: "AlertAmRoutes" */ 'app/features/alerting/unified/AmRoutes')
|
|
||||||
),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
path: '/alerting/silences',
|
|
||||||
component: SafeDynamicImport(
|
|
||||||
() => import(/* webpackChunkName: "AlertSilences" */ 'app/features/alerting/unified/Silences')
|
|
||||||
),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
path: '/alerting/silence/new',
|
|
||||||
roles: () => ['Editor', 'Admin'],
|
|
||||||
component: SafeDynamicImport(
|
|
||||||
() => import(/* webpackChunkName: "AlertSilences" */ 'app/features/alerting/unified/Silences')
|
|
||||||
),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
path: '/alerting/silence/:id/edit',
|
|
||||||
roles: () => ['Editor', 'Admin'],
|
|
||||||
component: SafeDynamicImport(
|
|
||||||
() => import(/* webpackChunkName: "AlertSilences" */ 'app/features/alerting/unified/Silences')
|
|
||||||
),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
path: '/alerting/notifications',
|
|
||||||
roles: config.unifiedAlertingEnabled ? () => ['Editor', 'Admin'] : undefined,
|
|
||||||
component: SafeDynamicImport(
|
|
||||||
() => import(/* webpackChunkName: "NotificationsListPage" */ 'app/features/alerting/NotificationsIndex')
|
|
||||||
),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
path: '/alerting/notifications/templates/new',
|
|
||||||
roles: () => ['Editor', 'Admin'],
|
|
||||||
component: SafeDynamicImport(
|
|
||||||
() => import(/* webpackChunkName: "NotificationsListPage" */ 'app/features/alerting/NotificationsIndex')
|
|
||||||
),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
path: '/alerting/notifications/templates/:id/edit',
|
|
||||||
roles: () => ['Editor', 'Admin'],
|
|
||||||
component: SafeDynamicImport(
|
|
||||||
() => import(/* webpackChunkName: "NotificationsListPage" */ 'app/features/alerting/NotificationsIndex')
|
|
||||||
),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
path: '/alerting/notifications/receivers/new',
|
|
||||||
roles: () => ['Editor', 'Admin'],
|
|
||||||
component: SafeDynamicImport(
|
|
||||||
() => import(/* webpackChunkName: "NotificationsListPage" */ 'app/features/alerting/NotificationsIndex')
|
|
||||||
),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
path: '/alerting/notifications/receivers/:id/edit',
|
|
||||||
roles: () => ['Editor', 'Admin'],
|
|
||||||
component: SafeDynamicImport(
|
|
||||||
() => import(/* webpackChunkName: "NotificationsListPage" */ 'app/features/alerting/NotificationsIndex')
|
|
||||||
),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
path: '/alerting/notifications/global-config',
|
|
||||||
roles: () => ['Admin', 'Editor'],
|
|
||||||
component: SafeDynamicImport(
|
|
||||||
() => import(/* webpackChunkName: "NotificationsListPage" */ 'app/features/alerting/NotificationsIndex')
|
|
||||||
),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
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')
|
|
||||||
),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
path: '/alerting/groups/',
|
|
||||||
component: SafeDynamicImport(
|
|
||||||
() => import(/* webpackChunkName: "AlertGroups" */ 'app/features/alerting/unified/AlertGroups')
|
|
||||||
),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
path: '/alerting/new',
|
|
||||||
pageClass: 'page-alerting',
|
|
||||||
component: SafeDynamicImport(
|
|
||||||
() => import(/* webpackChunkName: "AlertingRuleForm"*/ 'app/features/alerting/unified/RuleEditor')
|
|
||||||
),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
path: '/alerting/:id/edit',
|
|
||||||
pageClass: 'page-alerting',
|
|
||||||
component: SafeDynamicImport(
|
|
||||||
() => import(/* webpackChunkName: "AlertingRuleForm"*/ 'app/features/alerting/unified/RuleEditor')
|
|
||||||
),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
path: '/alerting/:sourceName/:id/view',
|
|
||||||
pageClass: 'page-alerting',
|
|
||||||
component: SafeDynamicImport(
|
|
||||||
() => import(/* webpackChunkName: "AlertingRule"*/ 'app/features/alerting/unified/RuleViewer')
|
|
||||||
),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
path: '/alerting/:sourceName/:name/find',
|
|
||||||
pageClass: 'page-alerting',
|
|
||||||
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')
|
|
||||||
),
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
path: '/playlists',
|
path: '/playlists',
|
||||||
component: SafeDynamicImport(
|
component: SafeDynamicImport(
|
||||||
@ -522,6 +381,7 @@ export function getAppRoutes(): RouteDescriptor[] {
|
|||||||
},
|
},
|
||||||
...getPluginsAdminRoutes(),
|
...getPluginsAdminRoutes(),
|
||||||
...getLiveRoutes(),
|
...getLiveRoutes(),
|
||||||
|
...getAlertingRoutes(),
|
||||||
...extraRoutes,
|
...extraRoutes,
|
||||||
{
|
{
|
||||||
path: '/*',
|
path: '/*',
|
||||||
|
Loading…
Reference in New Issue
Block a user