|
|
|
@ -16,7 +16,6 @@ import { |
|
|
|
|
useStyles2, |
|
|
|
|
} from '@grafana/ui'; |
|
|
|
|
import { config } from 'app/core/config'; |
|
|
|
|
import { contextSrv } from 'app/core/services/context_srv'; |
|
|
|
|
import alertDef from 'app/features/alerting/state/alertDef'; |
|
|
|
|
import { alertRuleApi } from 'app/features/alerting/unified/api/alertRuleApi'; |
|
|
|
|
import { INSTANCES_DISPLAY_LIMIT } from 'app/features/alerting/unified/components/rules/RuleDetails'; |
|
|
|
@ -38,9 +37,10 @@ import { flattenCombinedRules, getFirstActiveAt } from 'app/features/alerting/un |
|
|
|
|
import { getDashboardSrv } from 'app/features/dashboard/services/DashboardSrv'; |
|
|
|
|
import { DashboardModel } from 'app/features/dashboard/state'; |
|
|
|
|
import { Matcher } from 'app/plugins/datasource/alertmanager/types'; |
|
|
|
|
import { AccessControlAction, ThunkDispatch, useDispatch } from 'app/types'; |
|
|
|
|
import { ThunkDispatch, useDispatch } from 'app/types'; |
|
|
|
|
import { PromAlertingRuleState } from 'app/types/unified-alerting-dto'; |
|
|
|
|
|
|
|
|
|
import { AlertingAction, useAlertingAbility } from '../../../features/alerting/unified/hooks/useAbilities'; |
|
|
|
|
import { getAlertingRule } from '../../../features/alerting/unified/utils/rules'; |
|
|
|
|
import { AlertingRule, CombinedRuleWithLocation } from '../../../types/unified-alerting'; |
|
|
|
|
|
|
|
|
@ -93,9 +93,10 @@ const fetchPromAndRuler = ({ |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
export function UnifiedAlertList(props: PanelProps<UnifiedAlertListOptions>) { |
|
|
|
|
function UnifiedAlertList(props: PanelProps<UnifiedAlertListOptions>) { |
|
|
|
|
const dispatch = useDispatch(); |
|
|
|
|
const [limitInstances, toggleLimit] = useToggle(true); |
|
|
|
|
const [, gmaViewAllowed] = useAlertingAbility(AlertingAction.ViewAlertRule); |
|
|
|
|
|
|
|
|
|
const { usePrometheusRulesByNamespaceQuery } = alertRuleApi; |
|
|
|
|
|
|
|
|
@ -137,7 +138,7 @@ export function UnifiedAlertList(props: PanelProps<UnifiedAlertListOptions>) { |
|
|
|
|
|
|
|
|
|
// If the datasource is not defined we should NOT skip the query
|
|
|
|
|
// Undefined dataSourceName means that there is no datasource filter applied and we should fetch all the rules
|
|
|
|
|
const shouldFetchGrafanaRules = !dataSourceName || dataSourceName === GRAFANA_RULES_SOURCE_NAME; |
|
|
|
|
const shouldFetchGrafanaRules = (!dataSourceName || dataSourceName === GRAFANA_RULES_SOURCE_NAME) && gmaViewAllowed; |
|
|
|
|
|
|
|
|
|
//For grafana managed rules, get the result using RTK Query to avoid the need of using the redux store
|
|
|
|
|
//See https://github.com/grafana/grafana/pull/70482
|
|
|
|
@ -217,15 +218,6 @@ export function UnifiedAlertList(props: PanelProps<UnifiedAlertListOptions>) { |
|
|
|
|
|
|
|
|
|
const havePreviousResults = Object.values(promRulesRequests).some((state) => state.result); |
|
|
|
|
|
|
|
|
|
if ( |
|
|
|
|
!contextSrv.hasPermission(AccessControlAction.AlertingRuleRead) && |
|
|
|
|
!contextSrv.hasPermission(AccessControlAction.AlertingRuleExternalRead) |
|
|
|
|
) { |
|
|
|
|
return ( |
|
|
|
|
<Alert title="Permission required">Sorry, you do not have the required permissions to read alert rules</Alert> |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
|
<CustomScrollbar autoHeightMin="100%" autoHeightMax="100%"> |
|
|
|
|
<div className={styles.container}> |
|
|
|
@ -456,3 +448,16 @@ export const getStyles = (theme: GrafanaTheme2) => ({ |
|
|
|
|
display: none; |
|
|
|
|
`,
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
export function UnifiedAlertListPanel(props: PanelProps<UnifiedAlertListOptions>) { |
|
|
|
|
const [, gmaReadAllowed] = useAlertingAbility(AlertingAction.ViewAlertRule); |
|
|
|
|
const [, externalReadAllowed] = useAlertingAbility(AlertingAction.ViewExternalAlertRule); |
|
|
|
|
|
|
|
|
|
if (!gmaReadAllowed && !externalReadAllowed) { |
|
|
|
|
return ( |
|
|
|
|
<Alert title="Permission required">Sorry, you do not have the required permissions to read alert rules</Alert> |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return <UnifiedAlertList {...props} />; |
|
|
|
|
} |
|
|
|
|