123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307 |
- import React from 'react';
- import { PanelPlugin } from '@grafana/data';
- import { config, DataSourcePicker } from '@grafana/runtime';
- import { TagsInput } from '@grafana/ui';
- import { FolderPicker } from 'app/core/components/Select/FolderPicker';
- import {
- ALL_FOLDER,
- GENERAL_FOLDER,
- ReadonlyFolderPicker,
- } from 'app/core/components/Select/ReadonlyFolderPicker/ReadonlyFolderPicker';
- import { PermissionLevelString } from 'app/types';
- import { AlertList } from './AlertList';
- import { alertListPanelMigrationHandler } from './AlertListMigrationHandler';
- import { GroupBy } from './GroupByWithLoading';
- import { UnifiedAlertList } from './UnifiedAlertList';
- import { AlertListSuggestionsSupplier } from './suggestions';
- import { AlertListOptions, GroupMode, ShowOption, SortOrder, UnifiedAlertListOptions } from './types';
- function showIfCurrentState(options: AlertListOptions) {
- return options.showOptions === ShowOption.Current;
- }
- const alertList = new PanelPlugin<AlertListOptions>(AlertList)
- .setPanelOptions((builder) => {
- builder
- .addSelect({
- name: 'Show',
- path: 'showOptions',
- settings: {
- options: [
- { label: 'Current state', value: ShowOption.Current },
- { label: 'Recent state changes', value: ShowOption.RecentChanges },
- ],
- },
- defaultValue: ShowOption.Current,
- category: ['Options'],
- })
- .addNumberInput({
- name: 'Max items',
- path: 'maxItems',
- defaultValue: 10,
- category: ['Options'],
- })
- .addSelect({
- name: 'Sort order',
- path: 'sortOrder',
- settings: {
- options: [
- { label: 'Alphabetical (asc)', value: SortOrder.AlphaAsc },
- { label: 'Alphabetical (desc)', value: SortOrder.AlphaDesc },
- { label: 'Importance', value: SortOrder.Importance },
- { label: 'Time (asc)', value: SortOrder.TimeAsc },
- { label: 'Time (desc)', value: SortOrder.TimeDesc },
- ],
- },
- defaultValue: SortOrder.AlphaAsc,
- category: ['Options'],
- })
- .addBooleanSwitch({
- path: 'dashboardAlerts',
- name: 'Alerts from this dashboard',
- defaultValue: false,
- category: ['Options'],
- })
- .addTextInput({
- path: 'alertName',
- name: 'Alert name',
- defaultValue: '',
- category: ['Filter'],
- showIf: showIfCurrentState,
- })
- .addTextInput({
- path: 'dashboardTitle',
- name: 'Dashboard title',
- defaultValue: '',
- category: ['Filter'],
- showIf: showIfCurrentState,
- })
- .addCustomEditor({
- path: 'folderId',
- name: 'Folder',
- id: 'folderId',
- defaultValue: null,
- editor: function RenderFolderPicker({ value, onChange }) {
- return (
- <ReadonlyFolderPicker
- initialFolderId={value}
- onChange={(folder) => onChange(folder?.id)}
- extraFolders={[ALL_FOLDER, GENERAL_FOLDER]}
- />
- );
- },
- category: ['Filter'],
- showIf: showIfCurrentState,
- })
- .addCustomEditor({
- id: 'tags',
- path: 'tags',
- name: 'Tags',
- description: '',
- defaultValue: [],
- editor(props) {
- return <TagsInput tags={props.value} onChange={props.onChange} />;
- },
- category: ['Filter'],
- showIf: showIfCurrentState,
- })
- .addBooleanSwitch({
- path: 'stateFilter.ok',
- name: 'Ok',
- defaultValue: false,
- category: ['State filter'],
- showIf: showIfCurrentState,
- })
- .addBooleanSwitch({
- path: 'stateFilter.paused',
- name: 'Paused',
- defaultValue: false,
- category: ['State filter'],
- showIf: showIfCurrentState,
- })
- .addBooleanSwitch({
- path: 'stateFilter.no_data',
- name: 'No data',
- defaultValue: false,
- category: ['State filter'],
- showIf: showIfCurrentState,
- })
- .addBooleanSwitch({
- path: 'stateFilter.execution_error',
- name: 'Execution error',
- defaultValue: false,
- category: ['State filter'],
- showIf: showIfCurrentState,
- })
- .addBooleanSwitch({
- path: 'stateFilter.alerting',
- name: 'Alerting',
- defaultValue: false,
- category: ['State filter'],
- showIf: showIfCurrentState,
- })
- .addBooleanSwitch({
- path: 'stateFilter.pending',
- name: 'Pending',
- defaultValue: false,
- category: ['State filter'],
- showIf: showIfCurrentState,
- });
- })
- .setMigrationHandler(alertListPanelMigrationHandler)
- .setSuggestionsSupplier(new AlertListSuggestionsSupplier());
- const unifiedAlertList = new PanelPlugin<UnifiedAlertListOptions>(UnifiedAlertList).setPanelOptions((builder) => {
- builder
- .addRadio({
- path: 'groupMode',
- name: 'Group mode',
- description: 'How alert instances should be grouped',
- defaultValue: GroupMode.Default,
- settings: {
- options: [
- { value: GroupMode.Default, label: 'Default grouping' },
- { value: GroupMode.Custom, label: 'Custom grouping' },
- ],
- },
- category: ['Options'],
- })
- .addCustomEditor({
- path: 'groupBy',
- name: 'Group by',
- description: 'Filter alerts using label querying',
- id: 'groupBy',
- defaultValue: [],
- showIf: (options) => options.groupMode === GroupMode.Custom,
- category: ['Options'],
- editor: (props) => {
- return (
- <GroupBy
- id={props.id ?? 'groupBy'}
- defaultValue={props.value.map((value: string) => ({ label: value, value }))}
- onChange={props.onChange}
- />
- );
- },
- })
- .addNumberInput({
- name: 'Max items',
- path: 'maxItems',
- description: 'Maximum alerts to display',
- defaultValue: 20,
- category: ['Options'],
- })
- .addSelect({
- name: 'Sort order',
- path: 'sortOrder',
- description: 'Sort order of alerts and alert instances',
- settings: {
- options: [
- { label: 'Alphabetical (asc)', value: SortOrder.AlphaAsc },
- { label: 'Alphabetical (desc)', value: SortOrder.AlphaDesc },
- { label: 'Importance', value: SortOrder.Importance },
- { label: 'Time (asc)', value: SortOrder.TimeAsc },
- { label: 'Time (desc)', value: SortOrder.TimeDesc },
- ],
- },
- defaultValue: SortOrder.AlphaAsc,
- category: ['Options'],
- })
- .addBooleanSwitch({
- path: 'dashboardAlerts',
- name: 'Alerts from this dashboard',
- description: 'Show alerts from this dashboard',
- defaultValue: false,
- category: ['Options'],
- })
- .addTextInput({
- path: 'alertName',
- name: 'Alert name',
- description: 'Filter for alerts containing this text',
- defaultValue: '',
- category: ['Filter'],
- })
- .addTextInput({
- path: 'alertInstanceLabelFilter',
- name: 'Alert instance label',
- description: 'Filter alert instances using label querying, ex: {severity="critical", instance=~"cluster-us-.+"}',
- defaultValue: '',
- category: ['Filter'],
- })
- .addCustomEditor({
- path: 'folder',
- name: 'Folder',
- description: 'Filter for alerts in the selected folder',
- id: 'folder',
- defaultValue: null,
- editor: function RenderFolderPicker(props) {
- return (
- <FolderPicker
- enableReset={true}
- showRoot={false}
- allowEmpty={true}
- initialTitle={props.value?.title}
- initialFolderId={props.value?.id}
- permissionLevel={PermissionLevelString.View}
- onClear={() => props.onChange('')}
- {...props}
- />
- );
- },
- category: ['Filter'],
- })
- .addCustomEditor({
- path: 'datasource',
- name: 'Datasource',
- description: 'Filter alerts from selected datasource',
- id: 'datasource',
- defaultValue: null,
- editor: function RenderDatasourcePicker(props) {
- return (
- <DataSourcePicker
- {...props}
- type={['prometheus', 'loki', 'grafana']}
- noDefault
- current={props.value}
- onChange={(ds) => props.onChange(ds.name)}
- onClear={() => props.onChange('')}
- />
- );
- },
- category: ['Filter'],
- })
- .addBooleanSwitch({
- path: 'stateFilter.firing',
- name: 'Alerting / Firing',
- defaultValue: true,
- category: ['Alert state filter'],
- })
- .addBooleanSwitch({
- path: 'stateFilter.pending',
- name: 'Pending',
- defaultValue: true,
- category: ['Alert state filter'],
- })
- .addBooleanSwitch({
- path: 'stateFilter.noData',
- name: 'No Data',
- defaultValue: false,
- category: ['Alert state filter'],
- })
- .addBooleanSwitch({
- path: 'stateFilter.normal',
- name: 'Normal',
- defaultValue: false,
- category: ['Alert state filter'],
- })
- .addBooleanSwitch({
- path: 'stateFilter.error',
- name: 'Error',
- defaultValue: true,
- category: ['Alert state filter'],
- });
- });
- export const plugin = config.unifiedAlertingEnabled ? unifiedAlertList : alertList;
|