From 30b8a2d0ff01ff2011e1de3d97db34adad4b0816 Mon Sep 17 00:00:00 2001 From: Shahzad Date: Tue, 10 Jan 2023 17:52:11 +0100 Subject: [PATCH 1/3] [Synthetics] Test run detail page header (#148470) Fixes https://github.com/elastic/kibana/issues/145377 Fixes https://github.com/elastic/kibana/issues/148472 --- .../common/components/monitor_status.tsx | 2 +- .../hooks/use_journey_steps.tsx | 35 ++++---- .../monitor_details_status.tsx | 11 ++- .../overview_errors/overview_errors.tsx | 8 +- .../overview_errors/overview_errors_count.tsx | 56 ++++++++++++ .../overview_errors_sparklines.tsx | 49 +++++++++++ .../components/test_run_date.tsx | 28 ++++++ .../test_run_details/route_config.tsx | 49 +++++++++++ .../test_run_details/test_run_details.tsx | 85 ++++++++++++++----- .../public/apps/synthetics/routes.tsx | 2 + .../state/browser_journey/actions.ts | 8 ++ .../synthetics/state/browser_journey/api.ts | 2 +- .../state/browser_journey/effects.ts | 13 ++- .../synthetics/state/browser_journey/index.ts | 15 ++++ .../state/browser_journey/models.ts | 3 + .../state/browser_journey/selectors.ts | 5 ++ .../synthetics/state/monitor_details/api.ts | 3 +- .../synthetics/state/monitor_list/effects.ts | 4 +- .../apps/synthetics/state/root_effect.ts | 3 +- .../apps/synthetics/state/utils/actions.ts | 2 +- .../synthetics/state/utils/fetch_effect.ts | 6 +- .../apps/synthetics/state/utils/http_error.ts | 10 ++- .../__mocks__/synthetics_store.mock.ts | 2 + 23 files changed, 344 insertions(+), 57 deletions(-) create mode 100644 x-pack/plugins/synthetics/public/apps/synthetics/components/monitors_page/overview/overview/overview_errors/overview_errors_count.tsx create mode 100644 x-pack/plugins/synthetics/public/apps/synthetics/components/monitors_page/overview/overview/overview_errors/overview_errors_sparklines.tsx create mode 100644 x-pack/plugins/synthetics/public/apps/synthetics/components/test_run_details/components/test_run_date.tsx create mode 100644 x-pack/plugins/synthetics/public/apps/synthetics/components/test_run_details/route_config.tsx diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/components/common/components/monitor_status.tsx b/x-pack/plugins/synthetics/public/apps/synthetics/components/common/components/monitor_status.tsx index 41cc80bb73bb25..44fce2e767a947 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/components/common/components/monitor_status.tsx +++ b/x-pack/plugins/synthetics/public/apps/synthetics/components/common/components/monitor_status.tsx @@ -41,7 +41,7 @@ export const MonitorStatus = ({ ); }; -const STATUS_LABEL = i18n.translate('xpack.synthetics.monitorStatus.statusLabel', { +export const STATUS_LABEL = i18n.translate('xpack.synthetics.monitorStatus.statusLabel', { defaultMessage: 'Status', }); diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_details/hooks/use_journey_steps.tsx b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_details/hooks/use_journey_steps.tsx index 6fb0bf83801a35..8e023f58ff482b 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_details/hooks/use_journey_steps.tsx +++ b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_details/hooks/use_journey_steps.tsx @@ -5,44 +5,47 @@ * 2.0. */ -import { useFetcher } from '@kbn/observability-plugin/public'; import { useParams } from 'react-router-dom'; +import { useDispatch, useSelector } from 'react-redux'; +import { useEffect } from 'react'; import { isStepEnd } from '../../common/monitor_test_result/browser_steps_list'; import { JourneyStep, SyntheticsJourneyApiResponse } from '../../../../../../common/runtime_types'; -import { fetchJourneySteps } from '../../../state'; +import { + fetchJourneyAction, + selectBrowserJourney, + selectBrowserJourneyLoading, +} from '../../../state'; export const useJourneySteps = (checkGroup?: string, lastRefresh?: number) => { const { stepIndex } = useParams<{ stepIndex: string }>(); const { checkGroupId: urlCheckGroup } = useParams<{ checkGroupId: string }>(); - const checkGroupId = checkGroup ?? urlCheckGroup; - const { data, loading } = useFetcher(() => { - if (!checkGroupId) { - return Promise.resolve(null); - } + const journeyData = useSelector(selectBrowserJourney(checkGroupId)); + const loading = useSelector(selectBrowserJourneyLoading(checkGroupId)); + + const dispatch = useDispatch(); - return fetchJourneySteps({ checkGroup: checkGroupId }); - }, [checkGroupId, lastRefresh]); + useEffect(() => { + dispatch(fetchJourneyAction.get({ checkGroup: checkGroupId })); + }, [checkGroupId, dispatch, lastRefresh]); const isFailed = - data?.steps.some( + journeyData?.steps.some( (step) => step.synthetics?.step?.status === 'failed' || step.synthetics?.step?.status === 'skipped' ) ?? false; - const failedStep = data?.steps.find((step) => step.synthetics?.step?.status === 'failed'); - - const stepEnds: JourneyStep[] = (data?.steps ?? []).filter(isStepEnd); - + const stepEnds: JourneyStep[] = (journeyData?.steps ?? []).filter(isStepEnd); + const failedStep = journeyData?.steps.find((step) => step.synthetics?.step?.status === 'failed'); const stepLabels = stepEnds.map((stepEnd) => stepEnd?.synthetics?.step?.name ?? ''); const currentStep = stepIndex - ? data?.steps.find((step) => step.synthetics?.step?.index === Number(stepIndex)) + ? journeyData?.steps.find((step) => step.synthetics?.step?.index === Number(stepIndex)) : undefined; return { - data: data as SyntheticsJourneyApiResponse, + data: journeyData as SyntheticsJourneyApiResponse, loading: loading ?? false, isFailed, stepEnds, diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_details/monitor_details_status.tsx b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_details/monitor_details_status.tsx index 8b60edce8b93ff..e0860a9186088e 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_details/monitor_details_status.tsx +++ b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_details/monitor_details_status.tsx @@ -6,7 +6,8 @@ */ import React from 'react'; -import { MonitorStatus } from '../common/components/monitor_status'; +import { EuiDescriptionList, EuiLoadingContent } from '@elastic/eui'; +import { MonitorStatus, STATUS_LABEL } from '../common/components/monitor_status'; import { useSelectedMonitor } from './hooks/use_selected_monitor'; import { useMonitorLatestPing } from './hooks/use_monitor_latest_ping'; @@ -16,7 +17,13 @@ export const MonitorDetailsStatus = () => { const { monitor } = useSelectedMonitor(); if (!monitor) { - return null; + return ( + }]} + /> + ); } return ( diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitors_page/overview/overview/overview_errors/overview_errors.tsx b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitors_page/overview/overview/overview_errors/overview_errors.tsx index a4ae1fc95bcb8e..98569e38f5bfb8 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitors_page/overview/overview/overview_errors/overview_errors.tsx +++ b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitors_page/overview/overview/overview_errors/overview_errors.tsx @@ -9,9 +9,9 @@ import { EuiFlexGroup, EuiFlexItem, EuiPanel, EuiSpacer, EuiTitle } from '@elast import React from 'react'; import { useSelector } from 'react-redux'; import { i18n } from '@kbn/i18n'; +import { OverviewErrorsSparklines } from './overview_errors_sparklines'; +import { OverviewErrorsCount } from './overview_errors_count'; import { ErrorsLink } from '../../../../common/links/view_errors'; -import { MonitorErrorSparklines } from '../../../../monitor_details/monitor_summary/monitor_error_sparklines'; -import { MonitorErrorsCount } from '../../../../monitor_details/monitor_summary/monitor_errors_count'; import { selectOverviewStatus } from '../../../../../state'; export function OverviewErrors() { @@ -25,10 +25,10 @@ export function OverviewErrors() { - + - + diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitors_page/overview/overview/overview_errors/overview_errors_count.tsx b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitors_page/overview/overview/overview_errors/overview_errors_count.tsx new file mode 100644 index 00000000000000..ca61583fa9e0ad --- /dev/null +++ b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitors_page/overview/overview/overview_errors/overview_errors_count.tsx @@ -0,0 +1,56 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import { useKibana } from '@kbn/kibana-react-plugin/public'; +import React, { useMemo } from 'react'; +import { ReportTypes } from '@kbn/observability-plugin/public'; +import { EuiLoadingContent } from '@elastic/eui'; +import { ClientPluginsStart } from '../../../../../../../plugin'; + +interface MonitorErrorsCountProps { + from: string; + to: string; + locationLabel?: string; + monitorId: string[]; +} + +export const OverviewErrorsCount = ({ + monitorId, + from, + to, + locationLabel, +}: MonitorErrorsCountProps) => { + const { observability } = useKibana().services; + + const { ExploratoryViewEmbeddable } = observability; + + const time = useMemo(() => ({ from, to }), [from, to]); + + if (!monitorId) { + return ; + } + + return ( + + ); +}; diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitors_page/overview/overview/overview_errors/overview_errors_sparklines.tsx b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitors_page/overview/overview/overview_errors/overview_errors_sparklines.tsx new file mode 100644 index 00000000000000..21867416f869cd --- /dev/null +++ b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitors_page/overview/overview/overview_errors/overview_errors_sparklines.tsx @@ -0,0 +1,49 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import { useKibana } from '@kbn/kibana-react-plugin/public'; +import React, { useMemo } from 'react'; +import { useEuiTheme } from '@elastic/eui'; +import { ClientPluginsStart } from '../../../../../../../plugin'; + +interface Props { + from: string; + to: string; + monitorId: string[]; +} +export const OverviewErrorsSparklines = ({ from, to, monitorId }: Props) => { + const { observability } = useKibana().services; + + const { ExploratoryViewEmbeddable } = observability; + + const { euiTheme } = useEuiTheme(); + + const time = useMemo(() => ({ from, to }), [from, to]); + + return ( + + ); +}; diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/components/test_run_details/components/test_run_date.tsx b/x-pack/plugins/synthetics/public/apps/synthetics/components/test_run_details/components/test_run_date.tsx new file mode 100644 index 00000000000000..1a2d0177510fb1 --- /dev/null +++ b/x-pack/plugins/synthetics/public/apps/synthetics/components/test_run_details/components/test_run_date.tsx @@ -0,0 +1,28 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import React, { ReactElement } from 'react'; +import { EuiDescriptionList, EuiLoadingContent } from '@elastic/eui'; +import { i18n } from '@kbn/i18n'; +import { useJourneySteps } from '../../monitor_details/hooks/use_journey_steps'; +import { useFormatTestRunAt } from '../../../utils/monitor_test_result/test_time_formats'; + +export const TestRunDate: React.FC = () => { + const { data } = useJourneySteps(); + + let startedAt: string | ReactElement = useFormatTestRunAt(data?.details?.timestamp); + + if (!startedAt) { + startedAt = ; + } + + return ; +}; + +const ERROR_DURATION = i18n.translate('xpack.synthetics.testDetails.date', { + defaultMessage: 'Date', +}); diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/components/test_run_details/route_config.tsx b/x-pack/plugins/synthetics/public/apps/synthetics/components/test_run_details/route_config.tsx new file mode 100644 index 00000000000000..58970da0cdc7bb --- /dev/null +++ b/x-pack/plugins/synthetics/public/apps/synthetics/components/test_run_details/route_config.tsx @@ -0,0 +1,49 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import { i18n } from '@kbn/i18n'; +import { FormattedMessage } from '@kbn/i18n-react'; +import React from 'react'; +import { useHistory } from 'react-router-dom'; +import { OutPortal } from 'react-reverse-portal'; +import { RouteProps } from '../../routes'; +import { MonitorDetailsStatus } from '../monitor_details/monitor_details_status'; +import { MonitorDetailsLocation } from '../monitor_details/monitor_details_location'; +import { TestRunDate } from './components/test_run_date'; +import { TEST_RUN_DETAILS_ROUTE } from '../../../../../common/constants'; +import { TestRunDetails } from './test_run_details'; +import { MonitorDetailsLinkPortalNode } from '../monitor_add_edit/portals'; + +export const getTestRunDetailsRoute = ( + history: ReturnType, + syntheticsPath: string, + baseTitle: string +): RouteProps => { + return { + title: i18n.translate('xpack.synthetics.testRunDetailsRoute.title', { + defaultMessage: 'Test run details | {baseTitle}', + values: { baseTitle }, + }), + path: TEST_RUN_DETAILS_ROUTE, + component: TestRunDetails, + dataTestSubj: 'syntheticsMonitorTestRunDetailsPage', + pageHeader: { + breadcrumbs: [ + { + text: , + }, + ], + pageTitle: ( + + ), + rightSideItems: [, , ], + }, + }; +}; diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/components/test_run_details/test_run_details.tsx b/x-pack/plugins/synthetics/public/apps/synthetics/components/test_run_details/test_run_details.tsx index ebf6bb6913e4d1..dd94d68e34c611 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/components/test_run_details/test_run_details.tsx +++ b/x-pack/plugins/synthetics/public/apps/synthetics/components/test_run_details/test_run_details.tsx @@ -6,14 +6,20 @@ */ import React from 'react'; -import { EuiFlexGroup, EuiFlexItem, EuiSpacer } from '@elastic/eui'; +import { EuiFlexGroup, EuiFlexItem, EuiPanel, EuiSpacer, EuiTitle } from '@elastic/eui'; import moment from 'moment'; +import { FormattedMessage } from '@kbn/i18n-react'; +import { useParams } from 'react-router-dom'; +import { useSelectedLocation } from '../monitor_details/hooks/use_selected_location'; +import { MonitorDetailsLinkPortal } from '../monitor_add_edit/monitor_details_portal'; +import { StepNumberNav } from './components/step_number_nav'; +import { StepScreenshotDetails } from './step_screenshot_details'; +import { StepTabs } from './step_tabs'; import { MonitorDetailsPanel } from '../monitor_details/monitor_summary/monitor_details_panel'; import { useJourneySteps } from '../monitor_details/hooks/use_journey_steps'; import { StepDurationPanel } from '../monitor_details/monitor_summary/step_duration_panel'; import { TestRunSteps } from './test_run_steps'; import { useTestRunDetailsBreadcrumbs } from './hooks/use_test_run_details_breadcrumbs'; -import { StepDetails } from './components/step_details'; export const TestRunDetails = () => { // Step index from starts at 1 in synthetics @@ -29,25 +35,62 @@ export const TestRunDetails = () => { const totalSteps = stepsLoading ? 1 : stepEnds.length; + const { monitorId } = useParams<{ monitorId: string }>(); + const selectedLocation = useSelectedLocation(); + return ( - - - - - - - - - - - - + <> + + + + + + +

+ +

+
+
+ + { + setStepIndex(stepIndex + 1); + }} + handlePreviousStep={() => { + setStepIndex(stepIndex - 1); + }} + /> + +
+ + + + +
+ + +
+ + + + + +
+ {/* needed to render the monitor details link in breadcrumb*/} + + ); }; diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/routes.tsx b/x-pack/plugins/synthetics/public/apps/synthetics/routes.tsx index 9d938e4ce6b379..ef032262cbe72c 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/routes.tsx +++ b/x-pack/plugins/synthetics/public/apps/synthetics/routes.tsx @@ -16,6 +16,7 @@ import { APP_WRAPPER_CLASS } from '@kbn/core/public'; import { useKibana } from '@kbn/kibana-react-plugin/public'; import { useInspectorContext } from '@kbn/observability-plugin/public'; import type { LazyObservabilityPageTemplateProps } from '@kbn/observability-plugin/public'; +import { getTestRunDetailsRoute } from './components/test_run_details/route_config'; import { getSettingsRouteConfig } from './components/settings/route_config'; import { TestRunDetails } from './components/test_run_details/test_run_details'; import { StepTitle } from './components/step_details_page/step_title'; @@ -84,6 +85,7 @@ const getRoutes = ( return [ ...getSettingsRouteConfig(history, syntheticsPath, baseTitle), getErrorDetailsRouteConfig(history, syntheticsPath, baseTitle), + getTestRunDetailsRoute(history, syntheticsPath, baseTitle), { title: i18n.translate('xpack.synthetics.gettingStartedRoute.title', { defaultMessage: 'Synthetics Getting Started | {baseTitle}', diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/state/browser_journey/actions.ts b/x-pack/plugins/synthetics/public/apps/synthetics/state/browser_journey/actions.ts index 3a151ced4246ca..7ebb208e5f8204 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/state/browser_journey/actions.ts +++ b/x-pack/plugins/synthetics/public/apps/synthetics/state/browser_journey/actions.ts @@ -6,6 +6,9 @@ */ import { createAction } from '@reduxjs/toolkit'; +import { FetchJourneyStepsParams } from '..'; +import { SyntheticsJourneyApiResponse } from '../../../../../common/runtime_types'; +import { createAsyncAction } from '../utils/actions'; import { PutBlocksPayload } from './models'; // This action denotes a set of blocks is required @@ -31,3 +34,8 @@ export const updateHitCountsAction = createAction('[BROWSER JOURNEY] U export const pruneCacheAction = createAction( '[BROWSER JOURNEY] PRUNE SCREENSHOT BLOCK CACHE' ); + +export const fetchJourneyAction = createAsyncAction< + FetchJourneyStepsParams, + SyntheticsJourneyApiResponse +>('fetchJourneyStepsAction'); diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/state/browser_journey/api.ts b/x-pack/plugins/synthetics/public/apps/synthetics/state/browser_journey/api.ts index a6fd6185af06b4..e0a8068e1d4600 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/state/browser_journey/api.ts +++ b/x-pack/plugins/synthetics/public/apps/synthetics/state/browser_journey/api.ts @@ -30,7 +30,7 @@ export async function fetchScreenshotBlockSet(params: string[]): Promise { return apiService.get( diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/state/browser_journey/effects.ts b/x-pack/plugins/synthetics/public/apps/synthetics/state/browser_journey/effects.ts index ad85440ee97083..f28e3bbfc947db 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/state/browser_journey/effects.ts +++ b/x-pack/plugins/synthetics/public/apps/synthetics/state/browser_journey/effects.ts @@ -6,9 +6,9 @@ */ import { Action } from 'redux-actions'; -import { all, call, fork, put, select, takeEvery, throttle } from 'redux-saga/effects'; +import { all, call, fork, put, select, takeEvery, takeLeading, throttle } from 'redux-saga/effects'; import { ScreenshotBlockDoc, ScreenshotBlockCache } from '../../../../../common/runtime_types'; -import { fetchScreenshotBlockSet } from './api'; +import { fetchBrowserJourney, fetchScreenshotBlockSet } from './api'; import { fetchBlocksAction, @@ -17,11 +17,13 @@ import { putBlocksAction, putCacheSize, updateHitCountsAction, + fetchJourneyAction, } from './actions'; import { isPendingBlock } from './models'; import { selectBrowserJourneyState } from './selectors'; +import { fetchEffectFactory } from '../utils/fetch_effect'; export function* browserJourneyEffects() { yield all([fork(fetchScreenshotBlocks), fork(generateBlockStatsOnPut), fork(pruneBlockCache)]); @@ -85,3 +87,10 @@ function* pruneBlockCache() { } }); } + +export function* fetchJourneyStepsEffect() { + yield takeLeading( + fetchJourneyAction.get, + fetchEffectFactory(fetchBrowserJourney, fetchJourneyAction.success, fetchJourneyAction.fail) + ); +} diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/state/browser_journey/index.ts b/x-pack/plugins/synthetics/public/apps/synthetics/state/browser_journey/index.ts index 75b82f989358bc..4bd0ba94f3271f 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/state/browser_journey/index.ts +++ b/x-pack/plugins/synthetics/public/apps/synthetics/state/browser_journey/index.ts @@ -11,6 +11,7 @@ import { isScreenshotBlockDoc } from '../../../../../common/runtime_types'; import type { BrowserJourneyState } from './models'; import { + fetchJourneyAction, pruneCacheAction, putBlocksAction, putCacheSize, @@ -23,6 +24,8 @@ const initialState: BrowserJourneyState = { blocks: {}, cacheSize: 0, hitCount: [], + journeys: {}, + journeysLoading: {}, }; export const browserJourneyReducer = createReducer(initialState, (builder) => { @@ -86,6 +89,18 @@ export const browserJourneyReducer = createReducer(initialState, (builder) => { ...state.blocks, ...action.payload.blocks.reduce((acc, cur) => ({ ...acc, [cur.id]: cur }), {}), }; + }) + .addCase(fetchJourneyAction.get, (state, action) => { + state.journeysLoading[action.payload.checkGroup] = true; + }) + .addCase(fetchJourneyAction.success, (state, action) => { + state.journeysLoading[action.payload.checkGroup] = false; + state.journeys[action.payload.checkGroup] = action.payload; + }) + .addCase(fetchJourneyAction.fail, (state, action) => { + if (action.payload.getPayload) { + state.journeysLoading[action.payload.getPayload.checkGroup] = false; + } }); }); diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/state/browser_journey/models.ts b/x-pack/plugins/synthetics/public/apps/synthetics/state/browser_journey/models.ts index 12d6074300c89a..863015de95f103 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/state/browser_journey/models.ts +++ b/x-pack/plugins/synthetics/public/apps/synthetics/state/browser_journey/models.ts @@ -9,6 +9,7 @@ import { PendingBlock, ScreenshotBlockCache, ScreenshotBlockDoc, + SyntheticsJourneyApiResponse, } from '../../../../../common/runtime_types'; export function isPendingBlock(data: unknown): data is PendingBlock { @@ -24,6 +25,8 @@ export interface BrowserJourneyState { blocks: ScreenshotBlockCache; cacheSize: number; hitCount: CacheHitCount[]; + journeys: Record; + journeysLoading: Record; } export interface PutBlocksPayload { diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/state/browser_journey/selectors.ts b/x-pack/plugins/synthetics/public/apps/synthetics/state/browser_journey/selectors.ts index eae2632d9ae5a4..89efdd64fc0ce5 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/state/browser_journey/selectors.ts +++ b/x-pack/plugins/synthetics/public/apps/synthetics/state/browser_journey/selectors.ts @@ -8,3 +8,8 @@ import { SyntheticsAppState } from '../root_reducer'; export const selectBrowserJourneyState = (state: SyntheticsAppState) => state.browserJourney; +export const selectBrowserJourney = (checkGroup?: string) => (state: SyntheticsAppState) => + checkGroup ? state.browserJourney.journeys[checkGroup] : undefined; + +export const selectBrowserJourneyLoading = (checkGroup?: string) => (state: SyntheticsAppState) => + checkGroup ? state.browserJourney.journeysLoading[checkGroup] : false; diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/state/monitor_details/api.ts b/x-pack/plugins/synthetics/public/apps/synthetics/state/monitor_details/api.ts index eb48b6cdc9ae01..42c0b21c56bcad 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/state/monitor_details/api.ts +++ b/x-pack/plugins/synthetics/public/apps/synthetics/state/monitor_details/api.ts @@ -6,6 +6,7 @@ */ import { SavedObject } from '@kbn/core/types'; +import moment from 'moment'; import { apiService } from '../../../../utils/api_service'; import { EncryptedSyntheticsSavedMonitor, @@ -47,7 +48,7 @@ export const fetchMonitorRecentPings = async ({ SYNTHETICS_API_URLS.PINGS, { monitorId, - from: from ?? new Date(0).toISOString(), + from: from ?? moment().subtract(30, 'days').toISOString(), to: to ?? new Date().toISOString(), locations, sort, diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/state/monitor_list/effects.ts b/x-pack/plugins/synthetics/public/apps/synthetics/state/monitor_list/effects.ts index e7185a74f266c2..017365b8b8b833 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/state/monitor_list/effects.ts +++ b/x-pack/plugins/synthetics/public/apps/synthetics/state/monitor_list/effects.ts @@ -58,7 +58,7 @@ export function* enableMonitorAlertEffect() { yield put( enableMonitorAlertAction.fail({ configId: action.payload.configId, - error: serializeHttpFetchError(error), + error: serializeHttpFetchError(error, action.payload), }) ); } @@ -90,7 +90,7 @@ export function* upsertMonitorEffect() { yield put( fetchUpsertFailureAction({ configId: action.payload.configId, - error: serializeHttpFetchError(error), + error: serializeHttpFetchError(error, action.payload), }) ); } finally { diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/state/root_effect.ts b/x-pack/plugins/synthetics/public/apps/synthetics/state/root_effect.ts index f447f56c4aa63b..d244b41924b70c 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/state/root_effect.ts +++ b/x-pack/plugins/synthetics/public/apps/synthetics/state/root_effect.ts @@ -26,7 +26,7 @@ import { } from './monitor_list'; import { fetchMonitorOverviewEffect, fetchOverviewStatusEffect } from './overview'; import { fetchServiceLocationsEffect } from './service_locations'; -import { browserJourneyEffects } from './browser_journey'; +import { browserJourneyEffects, fetchJourneyStepsEffect } from './browser_journey'; import { fetchPingStatusesEffect } from './ping_status'; export const rootEffect = function* root(): Generator { @@ -52,5 +52,6 @@ export const rootEffect = function* root(): Generator { fork(enableMonitorAlertEffect), fork(updateDefaultAlertingEffect), fork(executeEsQueryEffect), + fork(fetchJourneyStepsEffect), ]); }; diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/state/utils/actions.ts b/x-pack/plugins/synthetics/public/apps/synthetics/state/utils/actions.ts index 6a83b34572cf1b..2a8d13a0f60257 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/state/utils/actions.ts +++ b/x-pack/plugins/synthetics/public/apps/synthetics/state/utils/actions.ts @@ -11,7 +11,7 @@ import type { IHttpSerializedFetchError } from './http_error'; export function createAsyncAction< Payload, SuccessPayload, - FailurePayload = IHttpSerializedFetchError + FailurePayload = IHttpSerializedFetchError >(actionStr: string) { return { get: createAction(actionStr, (payload: Payload) => prepareForTimestamp(payload)), diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/state/utils/fetch_effect.ts b/x-pack/plugins/synthetics/public/apps/synthetics/state/utils/fetch_effect.ts index 94114a88a794f9..ae7bcecbee8832 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/state/utils/fetch_effect.ts +++ b/x-pack/plugins/synthetics/public/apps/synthetics/state/utils/fetch_effect.ts @@ -57,7 +57,7 @@ export const sendErrorToast = (payload: ToastParams, error: E export function fetchEffectFactory( fetch: (request: T) => Promise, success: (response: R) => PayloadAction, - fail: (error: IHttpSerializedFetchError) => PayloadAction, + fail: (error: IHttpSerializedFetchError) => PayloadAction, onSuccess?: ((response: R) => void) | string, onFailure?: ((error: Error) => void) | string ) { @@ -68,7 +68,7 @@ export function fetchEffectFactory( // eslint-disable-next-line no-console console.error(response); - yield put(fail(serializeHttpFetchError(response as IHttpFetchError))); + yield put(fail(serializeHttpFetchError(response as IHttpFetchError, action.payload))); if (typeof onFailure === 'function') { onFailure?.(response); } else if (typeof onFailure === 'string') { @@ -107,7 +107,7 @@ export function fetchEffectFactory( }); } - yield put(fail(serializeHttpFetchError(error))); + yield put(fail(serializeHttpFetchError(error, action.payload))); if (typeof onFailure === 'function') { onFailure?.(error); } else if (typeof onFailure === 'string') { diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/state/utils/http_error.ts b/x-pack/plugins/synthetics/public/apps/synthetics/state/utils/http_error.ts index 5c296eedb79f9a..79907e5e2e69df 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/state/utils/http_error.ts +++ b/x-pack/plugins/synthetics/public/apps/synthetics/state/utils/http_error.ts @@ -7,7 +7,7 @@ import type { IHttpFetchError } from '@kbn/core-http-browser'; -export interface IHttpSerializedFetchError { +export interface IHttpSerializedFetchError

{ name: string; body: { error?: string; @@ -15,9 +15,13 @@ export interface IHttpSerializedFetchError { statusCode?: number; }; requestUrl: string; + getPayload?: P; } -export const serializeHttpFetchError = (error: IHttpFetchError): IHttpSerializedFetchError => { +export const serializeHttpFetchError =

( + error: IHttpFetchError, + getPayload?: P +): IHttpSerializedFetchError

=> { if (error.name && !error.body) { return { name: error.name, @@ -27,6 +31,7 @@ export const serializeHttpFetchError = (error: IHttpFetchError): IHttpSerialized statusCode: undefined, }, requestUrl: error?.request?.url, + getPayload, }; } @@ -39,5 +44,6 @@ export const serializeHttpFetchError = (error: IHttpFetchError): IHttpSerialized statusCode: body!.statusCode, }, requestUrl: error.request.url, + getPayload, }; }; diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/utils/testing/__mocks__/synthetics_store.mock.ts b/x-pack/plugins/synthetics/public/apps/synthetics/utils/testing/__mocks__/synthetics_store.mock.ts index 8e0aa77e55f00c..8b572bdfd6ce54 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/utils/testing/__mocks__/synthetics_store.mock.ts +++ b/x-pack/plugins/synthetics/public/apps/synthetics/utils/testing/__mocks__/synthetics_store.mock.ts @@ -159,6 +159,8 @@ function getBrowserJourneyMockSlice() { { hash: '4bae236101175ae7746cb922f4c511083af4fbcd', hitTime: 1658682270849 }, { hash: 'ec95c047e2e05a27598451fdaa7f24db973eb933', hitTime: 1658682270849 }, ], + journeys: {}, + journeysLoading: {}, }; } From d35296ea3b5390e6ee5d3d6163abc27161c2c778 Mon Sep 17 00:00:00 2001 From: Lisa Cawley Date: Tue, 10 Jan 2023 09:27:58 -0800 Subject: [PATCH 2/3] [DOCS] Create open API specification for update rule (#147407) --- .../rules/rule-apis-passthru.asciidoc | 408 +++++++-- docs/api/alerting/delete_rule.asciidoc | 8 +- docs/api/alerting/get_rules.asciidoc | 88 +- docs/api/alerting/update_rule.asciidoc | 29 +- .../alerting/docs/openapi/bundled.json | 779 +++++++++++++----- .../alerting/docs/openapi/bundled.yaml | 586 +++++++++---- .../examples/get_rule_response.yaml | 56 ++ .../examples/update_rule_request.yaml | 21 + .../examples/update_rule_response.yaml | 47 ++ .../components/parameters/rule_id.yaml | 7 + .../openapi/components/schemas/actions.yaml | 22 + .../components/schemas/notify_when.yaml | 8 + .../schemas/rule_response_properties.yaml | 135 +++ .../openapi/components/schemas/schedule.yaml | 6 + .../docs/openapi/components/schemas/tags.yaml | 5 + .../openapi/components/schemas/throttle.yaml | 5 + .../schemas/update_rule_request.yaml | 28 + .../alerting/docs/openapi/entrypoint.yaml | 4 +- ...@{spaceid}@api@alerting@rule@{ruleid}.yaml | 94 +++ .../s@{spaceid}@api@alerting@rules@_find.yaml | 149 +--- 20 files changed, 1894 insertions(+), 591 deletions(-) create mode 100644 x-pack/plugins/alerting/docs/openapi/components/examples/get_rule_response.yaml create mode 100644 x-pack/plugins/alerting/docs/openapi/components/examples/update_rule_request.yaml create mode 100644 x-pack/plugins/alerting/docs/openapi/components/examples/update_rule_response.yaml create mode 100644 x-pack/plugins/alerting/docs/openapi/components/parameters/rule_id.yaml create mode 100644 x-pack/plugins/alerting/docs/openapi/components/schemas/actions.yaml create mode 100644 x-pack/plugins/alerting/docs/openapi/components/schemas/notify_when.yaml create mode 100644 x-pack/plugins/alerting/docs/openapi/components/schemas/rule_response_properties.yaml create mode 100644 x-pack/plugins/alerting/docs/openapi/components/schemas/schedule.yaml create mode 100644 x-pack/plugins/alerting/docs/openapi/components/schemas/tags.yaml create mode 100644 x-pack/plugins/alerting/docs/openapi/components/schemas/throttle.yaml create mode 100644 x-pack/plugins/alerting/docs/openapi/components/schemas/update_rule_request.yaml create mode 100644 x-pack/plugins/alerting/docs/openapi/paths/s@{spaceid}@api@alerting@rule@{ruleid}.yaml diff --git a/docs/api-generated/rules/rule-apis-passthru.asciidoc b/docs/api-generated/rules/rule-apis-passthru.asciidoc index 2b193c2c20201c..45a6ab4c4f43a0 100644 --- a/docs/api-generated/rules/rule-apis-passthru.asciidoc +++ b/docs/api-generated/rules/rule-apis-passthru.asciidoc @@ -18,10 +18,52 @@ Any modifications made to this file will be overwritten.

Alerting

Alerting

+
+
+ Up +
delete /s/{spaceId}/api/alerting/rule/{ruleId}
+
Deletes a rule. (deleteRule)
+
You must have all privileges for the appropriate Kibana features, depending on the consumer and rule_type_id of the rule you're deleting. For example, the Management > Stack Rules feature, Analytics > Discover or Machine Learning features, Observability, or Security features. WARNING: After you delete a rule, you cannot recover it.
+ +

Path parameters

+
+
ruleId (required)
+ +
Path Parameter — An identifier for the rule. default: null
spaceId (required)
+ +
Path Parameter — An identifier for the space. If /s/ and the identifier are omitted from the path, the default space is used. default: null
+
+ + + +

Request headers

+
+
kbn-xsrf (required)
+ +
Header Parameter — default: null
+ +
+ + + + + + + + +

Responses

+

204

+ Indicates a successful call. + +
+
Up @@ -76,17 +118,17 @@ Any modifications made to this file will be overwritten.

Example data

Content-Type: application/json
{
-  "per_page" : 2,
-  "total" : 7,
+  "per_page" : 6,
+  "total" : 1,
   "data" : [ {
     "throttle" : "10m",
     "created_at" : "2022-12-05T23:36:58.284Z",
     "last_run" : {
       "alerts_count" : {
-        "new" : 0,
         "ignored" : 6,
-        "recovered" : 1,
-        "active" : 5
+        "new" : 1,
+        "recovered" : 5,
+        "active" : 0
       },
       "outcome_msg" : "outcome_msg",
       "warning" : "warning",
@@ -136,10 +178,10 @@ Any modifications made to this file will be overwritten.
     "created_at" : "2022-12-05T23:36:58.284Z",
     "last_run" : {
       "alerts_count" : {
-        "new" : 0,
         "ignored" : 6,
-        "recovered" : 1,
-        "active" : 5
+        "new" : 1,
+        "recovered" : 5,
+        "active" : 0
       },
       "outcome_msg" : "outcome_msg",
       "warning" : "warning",
@@ -185,7 +227,7 @@ Any modifications made to this file will be overwritten.
     } ],
     "consumer" : "alerts"
   } ],
-  "page" : 5
+  "page" : 0
 }

Produces

@@ -201,121 +243,357 @@ Any modifications made to this file will be overwritten. findRules_200_response

+
+
+ Up +
get /s/{spaceId}/api/alerting/rule/{ruleId}
+
Retrieve a rule by its identifier. (getRule)
+
You must have read privileges for the appropriate Kibana features, depending on the consumer and rule_type_id of the rules you're seeking. For example, the Management > Stack Rules feature, Analytics > Discover and Machine Learning features, Observability features, or Security features. To get rules associated with the Stack Monitoring feature, use the monitoring_user built-in role.
+ +

Path parameters

+
+
ruleId (required)
+ +
Path Parameter — An identifier for the rule. default: null
spaceId (required)
+ +
Path Parameter — An identifier for the space. If /s/ and the identifier are omitted from the path, the default space is used. default: null
+
+ + + + + + +

Return type

+ + + + +

Example data

+
Content-Type: application/json
+
{
+  "throttle" : "10m",
+  "created_at" : "2022-12-05T23:36:58.284Z",
+  "last_run" : {
+    "alerts_count" : {
+      "ignored" : 6,
+      "new" : 1,
+      "recovered" : 5,
+      "active" : 0
+    },
+    "outcome_msg" : "outcome_msg",
+    "warning" : "warning",
+    "outcome" : "succeeded"
+  },
+  "params" : {
+    "key" : ""
+  },
+  "created_by" : "elastic",
+  "enabled" : true,
+  "muted_alert_ids" : [ "muted_alert_ids", "muted_alert_ids" ],
+  "rule_type_id" : "monitoring_alert_cluster_health",
+  "tags" : [ "tags", "tags" ],
+  "api_key_owner" : "elastic",
+  "schedule" : {
+    "interval" : "1m"
+  },
+  "notify_when" : "onActiveAlert",
+  "next_run" : "2022-12-06T00:14:43.818Z",
+  "updated_at" : "2022-12-05T23:36:58.284Z",
+  "execution_status" : {
+    "last_execution_date" : "2022-12-06T00:13:43.89Z",
+    "last_duration" : 55,
+    "status" : "ok"
+  },
+  "name" : "cluster_health_rule",
+  "updated_by" : "elastic",
+  "scheduled_task_id" : "b530fed0-74f5-11ed-9801-35303b735aef",
+  "id" : "b530fed0-74f5-11ed-9801-35303b735aef",
+  "mute_all" : false,
+  "actions" : [ {
+    "id" : "9dca3e00-74f5-11ed-9801-35303b735aef",
+    "params" : {
+      "key" : ""
+    },
+    "group" : "default"
+  }, {
+    "id" : "9dca3e00-74f5-11ed-9801-35303b735aef",
+    "params" : {
+      "key" : ""
+    },
+    "group" : "default"
+  } ],
+  "consumer" : "alerts"
+}
+ +

Produces

+ This API call produces the following media types according to the Accept request header; + the media type will be conveyed by the Content-Type response header. +
    +
  • application/json
  • +
+ +

Responses

+

200

+ Indicates a successful call. + rule_response_properties +
+
+
+
+ Up +
put /s/{spaceId}/api/alerting/rule/{ruleId}
+
Updates the attributes for a rule. (updateRule)
+
You must have all privileges for the appropriate Kibana features, depending on the consumer and rule_type_id of the rule you're updating. For example, you must have privileges for the Management > Stack rules feature, Analytics > Discover and Machine Learning features, Observability features, or Security features. If the rule has actions, you must also have read privileges for the Management > Actions and Connectors feature. NOTE: This API supports only token-based authentication. When you update a rule, it identifies which roles you have at that point in time. Thereafter, when the rule performs queries, it uses those security privileges. If you have different privileges than the user that created or most recently updated the rule, you might change its behavior. Though some properties are optional, when you update the rule the existing property values are overwritten with default values. Therefore, it is recommended to explicitly set all property values.
+ +

Path parameters

+
+
ruleId (required)
+ +
Path Parameter — An identifier for the rule. default: null
spaceId (required)
+ +
Path Parameter — An identifier for the space. If /s/ and the identifier are omitted from the path, the default space is used. default: null
+
+ +

Consumes

+ This API call consumes the following media types via the Content-Type request header: +
    +
  • application/json
  • +
+ +

Request body

+
+
update_rule_request update_rule_request (required)
+ +
Body Parameter
+ +
+ +

Request headers

+
+
kbn-xsrf (required)
+ +
Header Parameter — default: null
+ +
+ + + +

Return type

+ + + + +

Example data

+
Content-Type: application/json
+
{
+  "throttle" : "10m",
+  "created_at" : "2022-12-05T23:36:58.284Z",
+  "last_run" : {
+    "alerts_count" : {
+      "ignored" : 6,
+      "new" : 1,
+      "recovered" : 5,
+      "active" : 0
+    },
+    "outcome_msg" : "outcome_msg",
+    "warning" : "warning",
+    "outcome" : "succeeded"
+  },
+  "params" : {
+    "key" : ""
+  },
+  "created_by" : "elastic",
+  "enabled" : true,
+  "muted_alert_ids" : [ "muted_alert_ids", "muted_alert_ids" ],
+  "rule_type_id" : "monitoring_alert_cluster_health",
+  "tags" : [ "tags", "tags" ],
+  "api_key_owner" : "elastic",
+  "schedule" : {
+    "interval" : "1m"
+  },
+  "notify_when" : "onActiveAlert",
+  "next_run" : "2022-12-06T00:14:43.818Z",
+  "updated_at" : "2022-12-05T23:36:58.284Z",
+  "execution_status" : {
+    "last_execution_date" : "2022-12-06T00:13:43.89Z",
+    "last_duration" : 55,
+    "status" : "ok"
+  },
+  "name" : "cluster_health_rule",
+  "updated_by" : "elastic",
+  "scheduled_task_id" : "b530fed0-74f5-11ed-9801-35303b735aef",
+  "id" : "b530fed0-74f5-11ed-9801-35303b735aef",
+  "mute_all" : false,
+  "actions" : [ {
+    "id" : "9dca3e00-74f5-11ed-9801-35303b735aef",
+    "params" : {
+      "key" : ""
+    },
+    "group" : "default"
+  }, {
+    "id" : "9dca3e00-74f5-11ed-9801-35303b735aef",
+    "params" : {
+      "key" : ""
+    },
+    "group" : "default"
+  } ],
+  "consumer" : "alerts"
+}
+ +

Produces

+ This API call produces the following media types according to the Accept request header; + the media type will be conveyed by the Content-Type response header. +
    +
  • application/json
  • +
+ +

Responses

+

200

+ Indicates a successful call. + rule_response_properties +
+

Models

[ Jump to Methods ]

Table of Contents

    +
  1. actions_inner -
  2. findRules_200_response -
  3. -
  4. findRules_200_response_data_inner -
  5. -
  6. findRules_200_response_data_inner_actions_inner -
  7. -
  8. findRules_200_response_data_inner_execution_status -
  9. -
  10. findRules_200_response_data_inner_last_run -
  11. -
  12. findRules_200_response_data_inner_last_run_alerts_count -
  13. -
  14. findRules_200_response_data_inner_schedule -
  15. findRules_has_reference_parameter -
  16. findRules_search_fields_parameter -
  17. +
  18. notify_when -
  19. +
  20. rule_response_properties - Rule response properties
  21. +
  22. rule_response_properties_execution_status -
  23. +
  24. rule_response_properties_last_run -
  25. +
  26. rule_response_properties_last_run_alerts_count -
  27. +
  28. schedule -
  29. +
  30. update_rule_request - Update rule request
+
+

actions_inner - Up

+
+
+
group (optional)
String The group name for the actions. If you don't need to group actions, set to default.
+
id (optional)
String The identifier for the connector saved object.
+
params (optional)
map[String, oas_any_type_not_mapped] The parameters for the action, which are sent to the connector. The params are handled as Mustache templates and passed a default set of context.
+
+

findRules_200_response - Up

-
data (optional)
+
data (optional)
page (optional)
per_page (optional)
total (optional)
-

findRules_200_response_data_inner - Up

+

findRules_has_reference_parameter - Up

-
actions (optional)
-
api_key_owner (optional)
-
consumer (optional)
String The application or feature that owns the rule. For example, alerts, apm, discover, infrastructure, logs, metrics, ml, monitoring, securitySolution, siem, stackAlerts, or uptime.
-
created_at (optional)
Date The date and time that the rule as created. format: date-time
-
created_by (optional)
String The identifier for the user that created the rule.
-
enabled (optional)
Boolean Indicates whether the rule is currently enabled.
-
execution_status (optional)
-
id (optional)
String The identifier for the rule.
-
last_run (optional)
-
muted_alert_ids (optional)
-
mute_all (optional)
-
name (optional)
String The name of the rule.
-
next_run (optional)
Date format: date-time
-
notify_when (optional)
String Indicates how often alerts generate actions.
-
Enum:
-
onActionGroupChange
onActiveAlert
onThrottleInterval
-
params (optional)
map[String, oas_any_type_not_mapped] The parameters for the rule.
-
rule_type_id (optional)
String The identifier for the type of rule. For example, .es-query, .index-threshold, logs.alert.document.count, monitoring_alert_cluster_health, siem.thresholdRule, or xpack.ml.anomaly_detection_alert.
-
schedule (optional)
-
scheduled_task_id (optional)
-
tags (optional)
array[String] The tags for the rule.
-
throttle (optional)
String The throttle interval, which defines how often an alert generates repeated actions. It is applicable only if notify_when is set to onThrottleInterval. It is specified in seconds, minutes, hours, or days.
-
updated_at (optional)
String The date and time that the rule was updated most recently.
-
updated_by (optional)
String The identifier for the user that updated this rule most recently.
+
id (optional)
+
type (optional)
-

findRules_200_response_data_inner_actions_inner - Up

+

findRules_search_fields_parameter - Up

-
group (optional)
String The group name for the actions.
-
id (optional)
String The identifier for the connector saved object.
-
params (optional)
map[String, oas_any_type_not_mapped] The parameters for the action, which are sent to the connector.
+
+
+
+

notify_when - Up

+
Indicates how often alerts generate actions. Valid values include: onActionGroupChange: Actions run when the alert status changes; onActiveAlert: Actions run when the alert becomes active and at each check interval while the rule conditions are met; onThrottleInterval: Actions run when the alert becomes active and at the interval specified in the throttle property while the rule conditions are met.
+
+
+
+
+

rule_response_properties - Rule response properties Up

+
+
+
actions
+
api_key_owner
+
consumer
String The application or feature that owns the rule. For example, alerts, apm, discover, infrastructure, logs, metrics, ml, monitoring, securitySolution, siem, stackAlerts, or uptime.
+
created_at
Date The date and time that the rule was created. format: date-time
+
created_by
String The identifier for the user that created the rule.
+
enabled
Boolean Indicates whether the rule is currently enabled.
+
execution_status
+
id
String The identifier for the rule.
+
last_run (optional)
+
muted_alert_ids
+
mute_all
+
name
String The name of the rule.
+
next_run (optional)
Date format: date-time
+
notify_when
+
params
map[String, oas_any_type_not_mapped] The parameters for the rule.
+
rule_type_id
String The identifier for the type of rule. For example, .es-query, .index-threshold, logs.alert.document.count, monitoring_alert_cluster_health, siem.thresholdRule, or xpack.ml.anomaly_detection_alert.
+
schedule
+
scheduled_task_id (optional)
+
tags
array[String] The tags for the rule.
+
throttle
String The throttle interval, which defines how often an alert generates repeated actions. It is applicable only if notify_when is set to onThrottleInterval. It is specified in seconds, minutes, hours, or days.
+
updated_at
String The date and time that the rule was updated most recently.
+
updated_by
String The identifier for the user that updated this rule most recently.
-

findRules_200_response_data_inner_execution_status - Up

+

rule_response_properties_execution_status - Up

-
status (optional)
+
last_duration (optional)
last_execution_date (optional)
Date format: date-time
-
last_duration (optional)
+
status (optional)
-

findRules_200_response_data_inner_last_run - Up

+

rule_response_properties_last_run - Up

-
alerts_count (optional)
+
alerts_count (optional)
+
outcome (optional)
outcome_msg (optional)
warning (optional)
-
outcome (optional)
-

findRules_200_response_data_inner_last_run_alerts_count - Up

+

rule_response_properties_last_run_alerts_count - Up

-
new (optional)
+
active (optional)
ignored (optional)
+
new (optional)
recovered (optional)
-
active (optional)
-

findRules_200_response_data_inner_schedule - Up

+

schedule - Up

The check interval, which specifies how frequently the rule conditions are checked. The interval is specified in seconds, minutes, hours, or days.
interval (optional)
-

findRules_has_reference_parameter - Up

-
+

update_rule_request - Update rule request Up

+
The update rule API request body varies depending on the type of rule and actions.
-
id (optional)
-
type (optional)
+
actions (optional)
+
name
String The name of the rule.
+
notify_when
+
params
map[String, oas_any_type_not_mapped] The parameters for the rule.
+
schedule
+
tags (optional)
array[String] The tags for the rule.
+
throttle (optional)
String The throttle interval, which defines how often an alert generates repeated actions. It is applicable only if notify_when is set to onThrottleInterval. It is specified in seconds, minutes, hours, or days.
-
++++ diff --git a/docs/api/alerting/delete_rule.asciidoc b/docs/api/alerting/delete_rule.asciidoc index 12b07c5bb0f120..143507fa206009 100644 --- a/docs/api/alerting/delete_rule.asciidoc +++ b/docs/api/alerting/delete_rule.asciidoc @@ -8,6 +8,12 @@ Permanently removes a rule. WARNING: After you delete a rule, you cannot recover it. +[NOTE] +==== +For the most up-to-date API details, refer to the +{kib-repo}/tree/{branch}/x-pack/plugins/alerting/docs/openapi[open API specification]. For a preview, check out <>. +==== + [[delete-rule-api-request]] === {api-request-title} @@ -36,7 +42,7 @@ default space is used. [[delete-rule-api-response-codes]] === {api-response-codes-title} -`200`:: +`204`:: Indicates a successful call. === {api-examples-title} diff --git a/docs/api/alerting/get_rules.asciidoc b/docs/api/alerting/get_rules.asciidoc index 41aa01df01a475..fd291617e08d38 100644 --- a/docs/api/alerting/get_rules.asciidoc +++ b/docs/api/alerting/get_rules.asciidoc @@ -6,6 +6,12 @@ Retrieve a rule by ID. +[NOTE] +==== +For the most up-to-date API details, refer to the +{kib-repo}/tree/{branch}/x-pack/plugins/alerting/docs/openapi[open API specification]. For a preview, check out <>. +==== + [[get-rule-api-request]] === {api-request-title} @@ -55,33 +61,63 @@ The API returns the following: [source,sh] -------------------------------------------------- { - "id": "0a037d60-6b62-11eb-9e0d-85d233e3ee35", - "notify_when": "onActionGroupChange", - "params": { - "aggType": "avg", + "id":"31697a40-7b36-11ed-aa79-f742c05329b2", + "consumer":"alerts", + "tags":["cpu"], + "name":"my alert", + "enabled":true, + "throttle":null, + "schedule":{ + "interval":"1m" + }, + "params":{ + "aggType":"avg", + "termSize":6, + "thresholdComparator":">", + "timeWindowSize":5, + "timeWindowUnit":"m", + "groupBy":"top", + "threshold":[1000], + "index":["test-index"], + "timeField":"@timestamp", + "aggField":"sheet.version", + "termField":"name.keyword" + }, + "rule_type_id":".index-threshold", + "created_by":"elastic", + "updated_by":"elastic", + "created_at":"2022-12-13T22:33:41.163Z", + "updated_at":"2022-12-13T22:33:41.163Z", + "api_key_owner":"elastic", + "notify_when":"onActionGroupChange", + "muted_alert_ids":[], + "mute_all":false, + "scheduled_task_id":"31697a40-7b36-11ed-aa79-f742c05329b2", + "execution_status":{ + "status":"ok", + "last_execution_date":"2022-12-13T22:33:44.388Z", + "last_duration":83 }, - "consumer": "alerts", - "rule_type_id": "test.rule.type", - "schedule": { - "interval": "1m" + "actions":[{ + "group":"threshold met", + "id":"1007a0c0-7a6e-11ed-89d5-abec321c0def", + "params":{ + "level":"info", + "message":"alert {{alertName}} is active for group {{context.group}}:\n\n- Value: {{context.value}}\n- Conditions Met: {{context.conditions}} over {{params.timeWindowSize}}{{params.timeWindowUnit}}\n- Timestamp: {{context.date}}" + }, + "connector_type_id":".server-log" + }], + "last_run":{ + "alerts_count":{ + "new":0, + "ignored":0, + "recovered":0, + "active":0 + }, + "outcome_msg":null, + "warning":null, + "outcome":"succeeded" }, - "actions": [], - "tags": [], - "name": "test rule", - "enabled": true, - "throttle": null, - "api_key_owner": "elastic", - "created_by": "elastic", - "updated_by": "elastic", - "mute_all": false, - "muted_alert_ids": [], - "updated_at": "2021-02-10T05:37:19.086Z", - "created_at": "2021-02-10T05:37:19.086Z", - "scheduled_task_id": "0b092d90-6b62-11eb-9e0d-85d233e3ee35", - "execution_status": { - "last_execution_date": "2021-02-10T17:55:14.262Z", - "status": "ok", - "last_duration": 359 - } + "next_run":"2022-12-13T22:34:44.314Z" } -------------------------------------------------- diff --git a/docs/api/alerting/update_rule.asciidoc b/docs/api/alerting/update_rule.asciidoc index fe5e91212d7d19..0db4c2cf38195b 100644 --- a/docs/api/alerting/update_rule.asciidoc +++ b/docs/api/alerting/update_rule.asciidoc @@ -6,6 +6,12 @@ Update the attributes for an existing rule. +[NOTE] +==== +For the most up-to-date API details, refer to the +{kib-repo}/tree/{branch}/x-pack/plugins/alerting/docs/openapi[open API specification]. For a preview, check out <>. +==== + [[update-rule-api-request]] === {api-request-title} @@ -132,7 +138,6 @@ PUT api/alerting/rule/ac4e6b90-6be7-11eb-ba0d-9b1c1f912d74 "timeWindowUnit":"m", "thresholdComparator":">", "threshold":[1000], - "aggType":"avg", "aggField":"sheet.version", "termField":"name.keyword", "termSize":6 @@ -180,16 +185,28 @@ The API returns the following: "updated_by": "elastic", "rule_type_id": ".index-threshold", "scheduled_task_id": "4c5eda00-e74f-11ec-b72f-5b18752ff9ea", - "created_at": "2022-06-08T17:20:31.632Z", - "updated_at": "2022-06-09T23:36:36.090Z", + "created_at": "2022-12-12T22:43:20.578Z", + "updated_at": "2022-12-12T22:44:21.783Z", "notify_when": "onActionGroupChange", "mute_all": false, "muted_alert_ids": [], "execution_status": { "status": "ok", - "last_execution_date": "2022-06-09T23:36:17.332Z", - "last_duration": 577 + "last_execution_date": "2022-12-12T22:43:21.723Z", + "last_duration": 125 + }, + "actions":[], + "last_run":{ + "alerts_count": { + "new": 0, + "ignored": 0, + "recovered": 0, + "active": 0 + }, + "outcome_msg" :null, + "warning": null, + "outcome": "succeeded" }, - "actions":[] + "next_run": "2022-12-12T22:44:21.653Z" } -------------------------------------------------- diff --git a/x-pack/plugins/alerting/docs/openapi/bundled.json b/x-pack/plugins/alerting/docs/openapi/bundled.json index f5aa50c5d45e0f..51665e76f2f97d 100644 --- a/x-pack/plugins/alerting/docs/openapi/bundled.json +++ b/x-pack/plugins/alerting/docs/openapi/bundled.json @@ -25,6 +25,131 @@ } ], "paths": { + "/s/{spaceId}/api/alerting/rule/{ruleId}": { + "get": { + "summary": "Retrieve a rule by its identifier.", + "operationId": "getRule", + "description": "You must have `read` privileges for the appropriate Kibana features, depending on the `consumer` and `rule_type_id` of the rules you're seeking. For example, the **Management > Stack Rules** feature, **Analytics > Discover** and **Machine Learning** features, **Observability** features, or **Security** features. To get rules associated with the **Stack Monitoring** feature, use the `monitoring_user` built-in role.\n", + "tags": [ + "alerting" + ], + "parameters": [ + { + "$ref": "#/components/parameters/rule_id" + }, + { + "$ref": "#/components/parameters/space_id" + } + ], + "responses": { + "200": { + "description": "Indicates a successful call.", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/rule_response_properties" + }, + "examples": { + "updateRuleResponse": { + "$ref": "#/components/examples/get_rule_response" + } + } + } + } + } + } + }, + "delete": { + "summary": "Deletes a rule.", + "operationId": "deleteRule", + "description": "You must have `all` privileges for the appropriate Kibana features, depending on the `consumer` and `rule_type_id` of the rule you're deleting. For example, the **Management** > **Stack Rules** feature, **Analytics** > **Discover** or **Machine Learning** features, **Observability**, or **Security** features. WARNING: After you delete a rule, you cannot recover it.\n", + "tags": [ + "alerting" + ], + "parameters": [ + { + "$ref": "#/components/parameters/kbn_xsrf" + }, + { + "$ref": "#/components/parameters/rule_id" + }, + { + "$ref": "#/components/parameters/space_id" + } + ], + "responses": { + "204": { + "description": "Indicates a successful call." + } + }, + "servers": [ + { + "url": "https://localhost:5601" + } + ] + }, + "put": { + "summary": "Updates the attributes for a rule.", + "operationId": "updateRule", + "description": "You must have `all` privileges for the appropriate Kibana features, depending on the `consumer` and `rule_type_id` of the rule you're updating. For example, you must have privileges for the **Management > Stack rules** feature, **Analytics > Discover** and **Machine Learning** features, **Observability** features, or **Security** features. If the rule has actions, you must also have `read` privileges for the **Management > Actions and Connectors** feature. NOTE: This API supports only token-based authentication. When you update a rule, it identifies which roles you have at that point in time. Thereafter, when the rule performs queries, it uses those security privileges. If you have different privileges than the user that created or most recently updated the rule, you might change its behavior. Though some properties are optional, when you update the rule the existing property values are overwritten with default values. Therefore, it is recommended to explicitly set all property values.\n", + "tags": [ + "alerting" + ], + "parameters": [ + { + "$ref": "#/components/parameters/kbn_xsrf" + }, + { + "$ref": "#/components/parameters/rule_id" + }, + { + "$ref": "#/components/parameters/space_id" + } + ], + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/update_rule_request" + }, + "examples": { + "updateCaseRequest": { + "$ref": "#/components/examples/update_rule_request" + } + } + } + } + }, + "responses": { + "200": { + "description": "Indicates a successful call.", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/rule_response_properties" + }, + "examples": { + "updateRuleResponse": { + "$ref": "#/components/examples/update_rule_response" + } + } + } + } + } + }, + "servers": [ + { + "url": "https://localhost:5601" + } + ] + }, + "servers": [ + { + "url": "https://localhost:5601" + } + ] + }, "/s/{spaceId}/api/alerting/rules/_find": { "get": { "summary": "Retrieves information about rules.", @@ -162,201 +287,7 @@ "data": { "type": "array", "items": { - "type": "object", - "properties": { - "actions": { - "type": "array", - "items": { - "type": "object", - "properties": { - "group": { - "type": "string", - "description": "The group name for the actions.", - "example": "default" - }, - "id": { - "type": "string", - "description": "The identifier for the connector saved object.", - "example": "9dca3e00-74f5-11ed-9801-35303b735aef" - }, - "params": { - "type": "object", - "description": "The parameters for the action, which are sent to the connector.", - "additionalProperties": true - } - } - } - }, - "api_key_owner": { - "type": "string", - "nullable": true, - "example": "elastic" - }, - "consumer": { - "type": "string", - "description": "The application or feature that owns the rule. For example, `alerts`, `apm`, `discover`, `infrastructure`, `logs`, `metrics`, `ml`, `monitoring`, `securitySolution`, `siem`, `stackAlerts`, or `uptime`.", - "example": "alerts" - }, - "created_at": { - "type": "string", - "description": "The date and time that the rule as created.", - "format": "date-time", - "example": "2022-12-05T23:36:58.284Z" - }, - "created_by": { - "type": "string", - "description": "The identifier for the user that created the rule.", - "nullable": true, - "example": "elastic" - }, - "enabled": { - "type": "boolean", - "description": "Indicates whether the rule is currently enabled.", - "example": true - }, - "execution_status": { - "type": "object", - "properties": { - "status": { - "type": "string", - "example": "ok" - }, - "last_execution_date": { - "type": "string", - "format": "date-time", - "example": "2022-12-06T00:13:43.890Z" - }, - "last_duration": { - "type": "integer", - "example": 55 - } - } - }, - "id": { - "type": "string", - "description": "The identifier for the rule.", - "example": "b530fed0-74f5-11ed-9801-35303b735aef" - }, - "last_run": { - "type": "object", - "properties": { - "alerts_count": { - "type": "object", - "properties": { - "new": { - "type": "integer", - "nullable": true - }, - "ignored": { - "type": "integer", - "nullable": true - }, - "recovered": { - "type": "integer", - "nullable": true - }, - "active": { - "type": "integer", - "nullable": true - } - } - }, - "outcome_msg": { - "type": "string", - "nullable": true, - "example": null - }, - "warning": { - "type": "string", - "nullable": true, - "example": null - }, - "outcome": { - "type": "string", - "example": "succeeded" - } - } - }, - "muted_alert_ids": { - "type": "array", - "items": { - "type": "string" - } - }, - "mute_all": { - "type": "boolean", - "example": false - }, - "name": { - "type": "string", - "description": "The name of the rule.", - "example": "cluster_health_rule" - }, - "next_run": { - "type": "string", - "format": "date-time", - "nullable": true, - "example": "2022-12-06T00:14:43.818Z" - }, - "notify_when": { - "type": "string", - "description": "Indicates how often alerts generate actions.", - "enum": [ - "onActionGroupChange", - "onActiveAlert", - "onThrottleInterval" - ], - "example": "onActiveAlert" - }, - "params": { - "type": "object", - "description": "The parameters for the rule.", - "additionalProperties": true - }, - "rule_type_id": { - "type": "string", - "description": "The identifier for the type of rule. For example, `.es-query`, `.index-threshold`, `logs.alert.document.count`, `monitoring_alert_cluster_health`, `siem.thresholdRule`, or `xpack.ml.anomaly_detection_alert`.", - "example": "monitoring_alert_cluster_health" - }, - "schedule": { - "type": "object", - "description": "The check interval, which specifies how frequently the rule conditions are checked. The interval is specified in seconds, minutes, hours, or days.", - "properties": { - "interval": { - "type": "string", - "example": "1m" - } - } - }, - "scheduled_task_id": { - "type": "string", - "example": "b530fed0-74f5-11ed-9801-35303b735aef" - }, - "tags": { - "type": "array", - "description": "The tags for the rule.", - "items": { - "type": "string" - } - }, - "throttle": { - "type": "string", - "description": "The throttle interval, which defines how often an alert generates repeated actions. It is applicable only if `notify_when` is set to `onThrottleInterval`. It is specified in seconds, minutes, hours, or days.", - "nullable": true, - "example": "10m" - }, - "updated_at": { - "type": "string", - "description": "The date and time that the rule was updated most recently.", - "example": "2022-12-05T23:36:58.284Z" - }, - "updated_by": { - "type": "string", - "description": "The identifier for the user that updated this rule most recently.", - "nullable": true, - "example": "elastic" - } - } + "$ref": "#/components/schemas/rule_response_properties" } }, "page": { @@ -405,6 +336,16 @@ } }, "parameters": { + "rule_id": { + "in": "path", + "name": "ruleId", + "description": "An identifier for the rule.", + "required": true, + "schema": { + "type": "string", + "example": "ac4e6b90-6be7-11eb-ba0d-9b1c1f912d74" + } + }, "space_id": { "in": "path", "name": "spaceId", @@ -414,9 +355,457 @@ "type": "string", "example": "default" } + }, + "kbn_xsrf": { + "schema": { + "type": "string" + }, + "in": "header", + "name": "kbn-xsrf", + "required": true + } + }, + "schemas": { + "actions": { + "type": "array", + "default": [], + "required": [ + "group", + "id", + "params" + ], + "nullable": true, + "items": { + "type": "object", + "properties": { + "group": { + "type": "string", + "description": "The group name for the actions. If you don't need to group actions, set to `default`.", + "example": "default" + }, + "id": { + "type": "string", + "description": "The identifier for the connector saved object.", + "example": "9dca3e00-74f5-11ed-9801-35303b735aef" + }, + "params": { + "type": "object", + "description": "The parameters for the action, which are sent to the connector. The `params` are handled as Mustache templates and passed a default set of context.", + "additionalProperties": true + } + } + } + }, + "notify_when": { + "type": "string", + "description": "Indicates how often alerts generate actions. Valid values include: `onActionGroupChange`: Actions run when the alert status changes; `onActiveAlert`: Actions run when the alert becomes active and at each check interval while the rule conditions are met; `onThrottleInterval`: Actions run when the alert becomes active and at the interval specified in the throttle property while the rule conditions are met.\n", + "enum": [ + "onActionGroupChange", + "onActiveAlert", + "onThrottleInterval" + ], + "example": "onActiveAlert" + }, + "schedule": { + "type": "object", + "description": "The check interval, which specifies how frequently the rule conditions are checked. The interval is specified in seconds, minutes, hours, or days.", + "properties": { + "interval": { + "type": "string", + "example": "1m" + } + } + }, + "tags": { + "type": "array", + "description": "The tags for the rule.", + "items": { + "type": "string" + }, + "default": [] + }, + "throttle": { + "type": "string", + "description": "The throttle interval, which defines how often an alert generates repeated actions. It is applicable only if `notify_when` is set to `onThrottleInterval`. It is specified in seconds, minutes, hours, or days.", + "nullable": true, + "default": null, + "example": "10m" + }, + "rule_response_properties": { + "title": "Rule response properties", + "type": "object", + "required": [ + "actions", + "api_key_owner", + "consumer", + "created_at", + "created_by", + "enabled", + "execution_status", + "id", + "mute_all", + "muted_alert_ids", + "name", + "notify_when", + "params", + "rule_type_id", + "schedule", + "tags", + "throttle", + "updated_at", + "updated_by" + ], + "properties": { + "actions": { + "$ref": "#/components/schemas/actions" + }, + "api_key_owner": { + "type": "string", + "nullable": true, + "example": "elastic" + }, + "consumer": { + "type": "string", + "description": "The application or feature that owns the rule. For example, `alerts`, `apm`, `discover`, `infrastructure`, `logs`, `metrics`, `ml`, `monitoring`, `securitySolution`, `siem`, `stackAlerts`, or `uptime`.", + "example": "alerts" + }, + "created_at": { + "type": "string", + "description": "The date and time that the rule was created.", + "format": "date-time", + "example": "2022-12-05T23:36:58.284Z" + }, + "created_by": { + "type": "string", + "description": "The identifier for the user that created the rule.", + "nullable": true, + "example": "elastic" + }, + "enabled": { + "type": "boolean", + "description": "Indicates whether the rule is currently enabled.", + "example": true + }, + "execution_status": { + "type": "object", + "properties": { + "last_duration": { + "type": "integer", + "example": 55 + }, + "last_execution_date": { + "type": "string", + "format": "date-time", + "example": "2022-12-06T00:13:43.890Z" + }, + "status": { + "type": "string", + "example": "ok" + } + } + }, + "id": { + "type": "string", + "description": "The identifier for the rule.", + "example": "b530fed0-74f5-11ed-9801-35303b735aef" + }, + "last_run": { + "type": "object", + "properties": { + "alerts_count": { + "type": "object", + "properties": { + "active": { + "type": "integer" + }, + "ignored": { + "type": "integer" + }, + "new": { + "type": "integer" + }, + "recovered": { + "type": "integer" + } + } + }, + "outcome": { + "type": "string", + "example": "succeeded" + }, + "outcome_msg": { + "type": "string", + "nullable": true, + "example": null + }, + "warning": { + "type": "string", + "nullable": true, + "example": null + } + } + }, + "muted_alert_ids": { + "type": "array", + "nullable": true, + "items": { + "type": "string" + } + }, + "mute_all": { + "type": "boolean", + "example": false + }, + "name": { + "type": "string", + "description": "The name of the rule.", + "example": "cluster_health_rule" + }, + "next_run": { + "type": "string", + "format": "date-time", + "nullable": true, + "example": "2022-12-06T00:14:43.818Z" + }, + "notify_when": { + "$ref": "#/components/schemas/notify_when" + }, + "params": { + "type": "object", + "description": "The parameters for the rule.", + "additionalProperties": true + }, + "rule_type_id": { + "type": "string", + "description": "The identifier for the type of rule. For example, `.es-query`, `.index-threshold`, `logs.alert.document.count`, `monitoring_alert_cluster_health`, `siem.thresholdRule`, or `xpack.ml.anomaly_detection_alert`.\n", + "example": "monitoring_alert_cluster_health" + }, + "schedule": { + "$ref": "#/components/schemas/schedule" + }, + "scheduled_task_id": { + "type": "string", + "example": "b530fed0-74f5-11ed-9801-35303b735aef" + }, + "tags": { + "$ref": "#/components/schemas/tags" + }, + "throttle": { + "$ref": "#/components/schemas/throttle" + }, + "updated_at": { + "type": "string", + "description": "The date and time that the rule was updated most recently.", + "example": "2022-12-05T23:36:58.284Z" + }, + "updated_by": { + "type": "string", + "description": "The identifier for the user that updated this rule most recently.", + "nullable": true, + "example": "elastic" + } + } + }, + "update_rule_request": { + "title": "Update rule request", + "description": "The update rule API request body varies depending on the type of rule and actions.", + "type": "object", + "required": [ + "name", + "notify_when", + "params", + "schedule" + ], + "properties": { + "actions": { + "$ref": "#/components/schemas/actions" + }, + "name": { + "type": "string", + "description": "The name of the rule.", + "example": "cluster_health_rule" + }, + "notify_when": { + "$ref": "#/components/schemas/notify_when" + }, + "params": { + "type": "object", + "description": "The parameters for the rule.", + "additionalProperties": true + }, + "schedule": { + "$ref": "#/components/schemas/schedule" + }, + "tags": { + "$ref": "#/components/schemas/tags" + }, + "throttle": { + "$ref": "#/components/schemas/throttle" + } + } } }, "examples": { + "get_rule_response": { + "summary": "The get rule API returns a JSON object that contains details about the rule.", + "value": { + "id": "31697a40-7b36-11ed-aa79-f742c05329b2", + "consumer": "alerts", + "tags": [ + "cpu" + ], + "name": "my alert", + "enabled": true, + "throttle": null, + "schedule": { + "interval": "1m" + }, + "params": { + "aggType": "avg", + "termSize": 6, + "thresholdComparator": ">", + "timeWindowSize": 5, + "timeWindowUnit": "m", + "groupBy": "top", + "threshold": [ + 1000 + ], + "index": [ + "test-index" + ], + "timeField": "@timestamp", + "aggField": "sheet.version", + "termField": "name.keyword" + }, + "rule_type_id": ".index-threshold", + "created_by": "elastic", + "updated_by": "elastic", + "created_at": "2022-12-13T22:33:41.163Z", + "updated_at": "2022-12-13T22:33:41.163Z", + "api_key_owner": "elastic", + "notify_when": "onActionGroupChange", + "muted_alert_ids": [], + "mute_all": false, + "scheduled_task_id": "31697a40-7b36-11ed-aa79-f742c05329b2", + "execution_status": { + "status": "ok", + "last_execution_date": "2022-12-13T22:33:44.388Z", + "last_duration": 83 + }, + "actions": [ + { + "group": "threshold met", + "id": "1007a0c0-7a6e-11ed-89d5-abec321c0def", + "params": { + "level": "info", + "message": "alert {{alertName}} is active for group {{context.group}}:\n\n- Value: {{context.value}}\n- Conditions Met: {{context.conditions}} over {{params.timeWindowSize}}{{params.timeWindowUnit}}\n- Timestamp: {{context.date}", + "connector_type_id": ".server-log" + } + } + ], + "last_run": { + "alerts_count": { + "new": 0, + "ignored": 0, + "recovered": 0, + "active": 0 + }, + "outcome_msg": null, + "warning": null, + "outcome": "succeeded" + }, + "next_run": "2022-12-13T22:34:44.314Z" + } + }, + "update_rule_request": { + "summary": "Update an index threshold rule.", + "value": { + "notify_when": "onActionGroupChange", + "params": { + "index": [ + ".test-index" + ], + "timeField": "@timestamp", + "groupBy": "top", + "aggType": "avg", + "timeWindowSize": 5, + "timeWindowUnit": "m", + "thresholdComparator": ">", + "threshold": [ + 1000 + ], + "aggField": "sheet.version", + "termField": "name.keyword", + "termSize": 6 + }, + "schedule": { + "interval": "1m" + }, + "actions": [], + "tags": [], + "name": "new name", + "throttle": null + } + }, + "update_rule_response": { + "summary": "The update rule API returns a JSON object that contains details about the rule.", + "value": { + "id": "ac4e6b90-6be7-11eb-ba0d-9b1c1f912d74", + "consumer": "alerts", + "tags": [], + "name": "new name", + "enabled": true, + "throttle": null, + "schedule": { + "interval": "1m" + }, + "params": { + "index": [ + ".updated-index" + ], + "timeField": "@timestamp", + "groupBy": "top", + "aggType": "avg", + "timeWindowSize": 5, + "timeWindowUnit": "m", + "thresholdComparator": ">", + "threshold": [ + 1000 + ], + "aggField": "sheet.version", + "termField": "name.keyword", + "termSize": 6 + }, + "api_key_owner": "elastic", + "created_by": "elastic", + "updated_by": "elastic", + "rule_type_id": ".index-threshold", + "scheduled_task_id": "4c5eda00-e74f-11ec-b72f-5b18752ff9ea", + "created_at": "2022-12-12T22:43:20.578Z", + "updated_at": "2022-12-12T22:44:21.783Z", + "notify_when": "onActionGroupChange", + "mute_all": false, + "muted_alert_ids": [], + "execution_status": { + "status": "ok", + "last_execution_date": "2022-12-12T22:43:21.723Z", + "last_duration": 125 + }, + "actions": [], + "last_run": { + "alerts_count": { + "new": 0, + "ignored": 0, + "recovered": 0, + "active": 0 + }, + "outcome_msg": null, + "warning": null, + "outcome": "succeeded" + }, + "next_run": "2022-12-12T22:44:21.653Z" + } + }, "find_rules_response": { "summary": "Retrieve information about a rule.", "value": { diff --git a/x-pack/plugins/alerting/docs/openapi/bundled.yaml b/x-pack/plugins/alerting/docs/openapi/bundled.yaml index d8ae1f576af8da..c2c572cfe66190 100644 --- a/x-pack/plugins/alerting/docs/openapi/bundled.yaml +++ b/x-pack/plugins/alerting/docs/openapi/bundled.yaml @@ -15,6 +15,77 @@ servers: - url: http://localhost:5601 description: local paths: + /s/{spaceId}/api/alerting/rule/{ruleId}: + get: + summary: Retrieve a rule by its identifier. + operationId: getRule + description: | + You must have `read` privileges for the appropriate Kibana features, depending on the `consumer` and `rule_type_id` of the rules you're seeking. For example, the **Management > Stack Rules** feature, **Analytics > Discover** and **Machine Learning** features, **Observability** features, or **Security** features. To get rules associated with the **Stack Monitoring** feature, use the `monitoring_user` built-in role. + tags: + - alerting + parameters: + - $ref: '#/components/parameters/rule_id' + - $ref: '#/components/parameters/space_id' + responses: + '200': + description: Indicates a successful call. + content: + application/json: + schema: + $ref: '#/components/schemas/rule_response_properties' + examples: + updateRuleResponse: + $ref: '#/components/examples/get_rule_response' + delete: + summary: Deletes a rule. + operationId: deleteRule + description: | + You must have `all` privileges for the appropriate Kibana features, depending on the `consumer` and `rule_type_id` of the rule you're deleting. For example, the **Management** > **Stack Rules** feature, **Analytics** > **Discover** or **Machine Learning** features, **Observability**, or **Security** features. WARNING: After you delete a rule, you cannot recover it. + tags: + - alerting + parameters: + - $ref: '#/components/parameters/kbn_xsrf' + - $ref: '#/components/parameters/rule_id' + - $ref: '#/components/parameters/space_id' + responses: + '204': + description: Indicates a successful call. + servers: + - url: https://localhost:5601 + put: + summary: Updates the attributes for a rule. + operationId: updateRule + description: | + You must have `all` privileges for the appropriate Kibana features, depending on the `consumer` and `rule_type_id` of the rule you're updating. For example, you must have privileges for the **Management > Stack rules** feature, **Analytics > Discover** and **Machine Learning** features, **Observability** features, or **Security** features. If the rule has actions, you must also have `read` privileges for the **Management > Actions and Connectors** feature. NOTE: This API supports only token-based authentication. When you update a rule, it identifies which roles you have at that point in time. Thereafter, when the rule performs queries, it uses those security privileges. If you have different privileges than the user that created or most recently updated the rule, you might change its behavior. Though some properties are optional, when you update the rule the existing property values are overwritten with default values. Therefore, it is recommended to explicitly set all property values. + tags: + - alerting + parameters: + - $ref: '#/components/parameters/kbn_xsrf' + - $ref: '#/components/parameters/rule_id' + - $ref: '#/components/parameters/space_id' + requestBody: + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/update_rule_request' + examples: + updateCaseRequest: + $ref: '#/components/examples/update_rule_request' + responses: + '200': + description: Indicates a successful call. + content: + application/json: + schema: + $ref: '#/components/schemas/rule_response_properties' + examples: + updateRuleResponse: + $ref: '#/components/examples/update_rule_response' + servers: + - url: https://localhost:5601 + servers: + - url: https://localhost:5601 /s/{spaceId}/api/alerting/rules/_find: get: summary: Retrieves information about rules. @@ -110,154 +181,7 @@ paths: data: type: array items: - type: object - properties: - actions: - type: array - items: - type: object - properties: - group: - type: string - description: The group name for the actions. - example: default - id: - type: string - description: The identifier for the connector saved object. - example: 9dca3e00-74f5-11ed-9801-35303b735aef - params: - type: object - description: The parameters for the action, which are sent to the connector. - additionalProperties: true - api_key_owner: - type: string - nullable: true - example: elastic - consumer: - type: string - description: The application or feature that owns the rule. For example, `alerts`, `apm`, `discover`, `infrastructure`, `logs`, `metrics`, `ml`, `monitoring`, `securitySolution`, `siem`, `stackAlerts`, or `uptime`. - example: alerts - created_at: - type: string - description: The date and time that the rule as created. - format: date-time - example: '2022-12-05T23:36:58.284Z' - created_by: - type: string - description: The identifier for the user that created the rule. - nullable: true - example: elastic - enabled: - type: boolean - description: Indicates whether the rule is currently enabled. - example: true - execution_status: - type: object - properties: - status: - type: string - example: ok - last_execution_date: - type: string - format: date-time - example: '2022-12-06T00:13:43.890Z' - last_duration: - type: integer - example: 55 - id: - type: string - description: The identifier for the rule. - example: b530fed0-74f5-11ed-9801-35303b735aef - last_run: - type: object - properties: - alerts_count: - type: object - properties: - new: - type: integer - nullable: true - ignored: - type: integer - nullable: true - recovered: - type: integer - nullable: true - active: - type: integer - nullable: true - outcome_msg: - type: string - nullable: true - example: null - warning: - type: string - nullable: true - example: null - outcome: - type: string - example: succeeded - muted_alert_ids: - type: array - items: - type: string - mute_all: - type: boolean - example: false - name: - type: string - description: The name of the rule. - example: cluster_health_rule - next_run: - type: string - format: date-time - nullable: true - example: '2022-12-06T00:14:43.818Z' - notify_when: - type: string - description: Indicates how often alerts generate actions. - enum: - - onActionGroupChange - - onActiveAlert - - onThrottleInterval - example: onActiveAlert - params: - type: object - description: The parameters for the rule. - additionalProperties: true - rule_type_id: - type: string - description: The identifier for the type of rule. For example, `.es-query`, `.index-threshold`, `logs.alert.document.count`, `monitoring_alert_cluster_health`, `siem.thresholdRule`, or `xpack.ml.anomaly_detection_alert`. - example: monitoring_alert_cluster_health - schedule: - type: object - description: The check interval, which specifies how frequently the rule conditions are checked. The interval is specified in seconds, minutes, hours, or days. - properties: - interval: - type: string - example: 1m - scheduled_task_id: - type: string - example: b530fed0-74f5-11ed-9801-35303b735aef - tags: - type: array - description: The tags for the rule. - items: - type: string - throttle: - type: string - description: The throttle interval, which defines how often an alert generates repeated actions. It is applicable only if `notify_when` is set to `onThrottleInterval`. It is specified in seconds, minutes, hours, or days. - nullable: true - example: 10m - updated_at: - type: string - description: The date and time that the rule was updated most recently. - example: '2022-12-05T23:36:58.284Z' - updated_by: - type: string - description: The identifier for the user that updated this rule most recently. - nullable: true - example: elastic + $ref: '#/components/schemas/rule_response_properties' page: type: integer per_page: @@ -281,6 +205,14 @@ components: in: header name: ApiKey parameters: + rule_id: + in: path + name: ruleId + description: An identifier for the rule. + required: true + schema: + type: string + example: ac4e6b90-6be7-11eb-ba0d-9b1c1f912d74 space_id: in: path name: spaceId @@ -289,7 +221,365 @@ components: schema: type: string example: default + kbn_xsrf: + schema: + type: string + in: header + name: kbn-xsrf + required: true + schemas: + actions: + type: array + default: [] + required: + - group + - id + - params + nullable: true + items: + type: object + properties: + group: + type: string + description: The group name for the actions. If you don't need to group actions, set to `default`. + example: default + id: + type: string + description: The identifier for the connector saved object. + example: 9dca3e00-74f5-11ed-9801-35303b735aef + params: + type: object + description: The parameters for the action, which are sent to the connector. The `params` are handled as Mustache templates and passed a default set of context. + additionalProperties: true + notify_when: + type: string + description: | + Indicates how often alerts generate actions. Valid values include: `onActionGroupChange`: Actions run when the alert status changes; `onActiveAlert`: Actions run when the alert becomes active and at each check interval while the rule conditions are met; `onThrottleInterval`: Actions run when the alert becomes active and at the interval specified in the throttle property while the rule conditions are met. + enum: + - onActionGroupChange + - onActiveAlert + - onThrottleInterval + example: onActiveAlert + schedule: + type: object + description: The check interval, which specifies how frequently the rule conditions are checked. The interval is specified in seconds, minutes, hours, or days. + properties: + interval: + type: string + example: 1m + tags: + type: array + description: The tags for the rule. + items: + type: string + default: [] + throttle: + type: string + description: The throttle interval, which defines how often an alert generates repeated actions. It is applicable only if `notify_when` is set to `onThrottleInterval`. It is specified in seconds, minutes, hours, or days. + nullable: true + default: null + example: 10m + rule_response_properties: + title: Rule response properties + type: object + required: + - actions + - api_key_owner + - consumer + - created_at + - created_by + - enabled + - execution_status + - id + - mute_all + - muted_alert_ids + - name + - notify_when + - params + - rule_type_id + - schedule + - tags + - throttle + - updated_at + - updated_by + properties: + actions: + $ref: '#/components/schemas/actions' + api_key_owner: + type: string + nullable: true + example: elastic + consumer: + type: string + description: The application or feature that owns the rule. For example, `alerts`, `apm`, `discover`, `infrastructure`, `logs`, `metrics`, `ml`, `monitoring`, `securitySolution`, `siem`, `stackAlerts`, or `uptime`. + example: alerts + created_at: + type: string + description: The date and time that the rule was created. + format: date-time + example: '2022-12-05T23:36:58.284Z' + created_by: + type: string + description: The identifier for the user that created the rule. + nullable: true + example: elastic + enabled: + type: boolean + description: Indicates whether the rule is currently enabled. + example: true + execution_status: + type: object + properties: + last_duration: + type: integer + example: 55 + last_execution_date: + type: string + format: date-time + example: '2022-12-06T00:13:43.890Z' + status: + type: string + example: ok + id: + type: string + description: The identifier for the rule. + example: b530fed0-74f5-11ed-9801-35303b735aef + last_run: + type: object + properties: + alerts_count: + type: object + properties: + active: + type: integer + ignored: + type: integer + new: + type: integer + recovered: + type: integer + outcome: + type: string + example: succeeded + outcome_msg: + type: string + nullable: true + example: null + warning: + type: string + nullable: true + example: null + muted_alert_ids: + type: array + nullable: true + items: + type: string + mute_all: + type: boolean + example: false + name: + type: string + description: The name of the rule. + example: cluster_health_rule + next_run: + type: string + format: date-time + nullable: true + example: '2022-12-06T00:14:43.818Z' + notify_when: + $ref: '#/components/schemas/notify_when' + params: + type: object + description: The parameters for the rule. + additionalProperties: true + rule_type_id: + type: string + description: | + The identifier for the type of rule. For example, `.es-query`, `.index-threshold`, `logs.alert.document.count`, `monitoring_alert_cluster_health`, `siem.thresholdRule`, or `xpack.ml.anomaly_detection_alert`. + example: monitoring_alert_cluster_health + schedule: + $ref: '#/components/schemas/schedule' + scheduled_task_id: + type: string + example: b530fed0-74f5-11ed-9801-35303b735aef + tags: + $ref: '#/components/schemas/tags' + throttle: + $ref: '#/components/schemas/throttle' + updated_at: + type: string + description: The date and time that the rule was updated most recently. + example: '2022-12-05T23:36:58.284Z' + updated_by: + type: string + description: The identifier for the user that updated this rule most recently. + nullable: true + example: elastic + update_rule_request: + title: Update rule request + description: The update rule API request body varies depending on the type of rule and actions. + type: object + required: + - name + - notify_when + - params + - schedule + properties: + actions: + $ref: '#/components/schemas/actions' + name: + type: string + description: The name of the rule. + example: cluster_health_rule + notify_when: + $ref: '#/components/schemas/notify_when' + params: + type: object + description: The parameters for the rule. + additionalProperties: true + schedule: + $ref: '#/components/schemas/schedule' + tags: + $ref: '#/components/schemas/tags' + throttle: + $ref: '#/components/schemas/throttle' examples: + get_rule_response: + summary: The get rule API returns a JSON object that contains details about the rule. + value: + id: 31697a40-7b36-11ed-aa79-f742c05329b2 + consumer: alerts + tags: + - cpu + name: my alert + enabled: true + throttle: null + schedule: + interval: 1m + params: + aggType: avg + termSize: 6 + thresholdComparator: '>' + timeWindowSize: 5 + timeWindowUnit: m + groupBy: top + threshold: + - 1000 + index: + - test-index + timeField: '@timestamp' + aggField: sheet.version + termField: name.keyword + rule_type_id: .index-threshold + created_by: elastic + updated_by: elastic + created_at: '2022-12-13T22:33:41.163Z' + updated_at: '2022-12-13T22:33:41.163Z' + api_key_owner: elastic + notify_when: onActionGroupChange + muted_alert_ids: [] + mute_all: false + scheduled_task_id: 31697a40-7b36-11ed-aa79-f742c05329b2 + execution_status: + status: ok + last_execution_date: '2022-12-13T22:33:44.388Z' + last_duration: 83 + actions: + - group: threshold met + id: 1007a0c0-7a6e-11ed-89d5-abec321c0def + params: + level: info + message: |- + alert {{alertName}} is active for group {{context.group}}: + + - Value: {{context.value}} + - Conditions Met: {{context.conditions}} over {{params.timeWindowSize}}{{params.timeWindowUnit}} + - Timestamp: {{context.date} + connector_type_id: .server-log + last_run: + alerts_count: + new: 0 + ignored: 0 + recovered: 0 + active: 0 + outcome_msg: null + warning: null + outcome: succeeded + next_run: '2022-12-13T22:34:44.314Z' + update_rule_request: + summary: Update an index threshold rule. + value: + notify_when: onActionGroupChange + params: + index: + - .test-index + timeField: '@timestamp' + groupBy: top + aggType: avg + timeWindowSize: 5 + timeWindowUnit: m + thresholdComparator: '>' + threshold: + - 1000 + aggField: sheet.version + termField: name.keyword + termSize: 6 + schedule: + interval: 1m + actions: [] + tags: [] + name: new name + throttle: null + update_rule_response: + summary: The update rule API returns a JSON object that contains details about the rule. + value: + id: ac4e6b90-6be7-11eb-ba0d-9b1c1f912d74 + consumer: alerts + tags: [] + name: new name + enabled: true + throttle: null + schedule: + interval: 1m + params: + index: + - .updated-index + timeField: '@timestamp' + groupBy: top + aggType: avg + timeWindowSize: 5 + timeWindowUnit: m + thresholdComparator: '>' + threshold: + - 1000 + aggField: sheet.version + termField: name.keyword + termSize: 6 + api_key_owner: elastic + created_by: elastic + updated_by: elastic + rule_type_id: .index-threshold + scheduled_task_id: 4c5eda00-e74f-11ec-b72f-5b18752ff9ea + created_at: '2022-12-12T22:43:20.578Z' + updated_at: '2022-12-12T22:44:21.783Z' + notify_when: onActionGroupChange + mute_all: false + muted_alert_ids: [] + execution_status: + status: ok + last_execution_date: '2022-12-12T22:43:21.723Z' + last_duration: 125 + actions: [] + last_run: + alerts_count: + new: 0 + ignored: 0 + recovered: 0 + active: 0 + outcome_msg: null + warning: null + outcome: succeeded + next_run: '2022-12-12T22:44:21.653Z' find_rules_response: summary: Retrieve information about a rule. value: diff --git a/x-pack/plugins/alerting/docs/openapi/components/examples/get_rule_response.yaml b/x-pack/plugins/alerting/docs/openapi/components/examples/get_rule_response.yaml new file mode 100644 index 00000000000000..eb63c8aeb82a3b --- /dev/null +++ b/x-pack/plugins/alerting/docs/openapi/components/examples/get_rule_response.yaml @@ -0,0 +1,56 @@ +summary: The get rule API returns a JSON object that contains details about the rule. +value: + id: 31697a40-7b36-11ed-aa79-f742c05329b2 + consumer: alerts + tags: + - cpu + name: my alert + enabled: true + throttle: null + schedule: + interval: 1m + params: + aggType: avg + termSize: 6 + thresholdComparator: ">" + timeWindowSize: 5 + timeWindowUnit: m + groupBy: top + threshold: + - 1000 + index: + - test-index + timeField: "@timestamp" + aggField: sheet.version + termField: name.keyword + rule_type_id: .index-threshold + created_by: elastic + updated_by: elastic + created_at: '2022-12-13T22:33:41.163Z' + updated_at: '2022-12-13T22:33:41.163Z' + api_key_owner: elastic + notify_when: onActionGroupChange + muted_alert_ids: [] + mute_all: false + scheduled_task_id: 31697a40-7b36-11ed-aa79-f742c05329b2 + execution_status: + status: ok + last_execution_date: '2022-12-13T22:33:44.388Z' + last_duration: 83 + actions: + - group: threshold met + id: 1007a0c0-7a6e-11ed-89d5-abec321c0def + params: + level: info + message: "alert {{alertName}} is active for group {{context.group}}:\n\n- Value: {{context.value}}\n- Conditions Met: {{context.conditions}} over {{params.timeWindowSize}}{{params.timeWindowUnit}}\n- Timestamp: {{context.date}" + connector_type_id: .server-log + last_run: + alerts_count: + new: 0 + ignored: 0 + recovered: 0 + active: 0 + outcome_msg: null + warning: null + outcome: succeeded + next_run: '2022-12-13T22:34:44.314Z' \ No newline at end of file diff --git a/x-pack/plugins/alerting/docs/openapi/components/examples/update_rule_request.yaml b/x-pack/plugins/alerting/docs/openapi/components/examples/update_rule_request.yaml new file mode 100644 index 00000000000000..de593e31724ed4 --- /dev/null +++ b/x-pack/plugins/alerting/docs/openapi/components/examples/update_rule_request.yaml @@ -0,0 +1,21 @@ +summary: Update an index threshold rule. +value: + notify_when: onActionGroupChange + params: + index: [".test-index"] + timeField: "@timestamp" + groupBy: top + aggType: avg + timeWindowSize: 5 + timeWindowUnit: m + thresholdComparator: ">" + threshold: [1000] + aggField : sheet.version + termField: name.keyword + termSize: 6 + schedule: + interval: 1m + actions: [] + tags: [] + name: new name + throttle: null \ No newline at end of file diff --git a/x-pack/plugins/alerting/docs/openapi/components/examples/update_rule_response.yaml b/x-pack/plugins/alerting/docs/openapi/components/examples/update_rule_response.yaml new file mode 100644 index 00000000000000..7bbdba73774ac0 --- /dev/null +++ b/x-pack/plugins/alerting/docs/openapi/components/examples/update_rule_response.yaml @@ -0,0 +1,47 @@ +summary: The update rule API returns a JSON object that contains details about the rule. +value: + id: ac4e6b90-6be7-11eb-ba0d-9b1c1f912d74 + consumer: alerts + tags: [] + name: new name + enabled: true + throttle: null + schedule: + interval: 1m + params: + index: [".updated-index"] + timeField: "@timestamp" + groupBy: top + aggType: "avg" + timeWindowSize: 5 + timeWindowUnit: m + thresholdComparator: ">" + threshold: [1000] + aggField: sheet.version + termField: name.keyword + termSize: 6 + api_key_owner: elastic + created_by: elastic + updated_by: elastic + rule_type_id: .index-threshold + scheduled_task_id: 4c5eda00-e74f-11ec-b72f-5b18752ff9ea + created_at: '2022-12-12T22:43:20.578Z' + updated_at: '2022-12-12T22:44:21.783Z' + notify_when: onActionGroupChange + mute_all: false + muted_alert_ids: [] + execution_status: + status: ok + last_execution_date: '2022-12-12T22:43:21.723Z' + last_duration: 125 + actions: [] + last_run: + alerts_count: + new: 0 + ignored: 0 + recovered: 0 + active: 0 + outcome_msg: null + warning: null + outcome: succeeded + next_run: '2022-12-12T22:44:21.653Z' \ No newline at end of file diff --git a/x-pack/plugins/alerting/docs/openapi/components/parameters/rule_id.yaml b/x-pack/plugins/alerting/docs/openapi/components/parameters/rule_id.yaml new file mode 100644 index 00000000000000..4b5d14e2073530 --- /dev/null +++ b/x-pack/plugins/alerting/docs/openapi/components/parameters/rule_id.yaml @@ -0,0 +1,7 @@ +in: path +name: ruleId +description: An identifier for the rule. +required: true +schema: + type: string + example: ac4e6b90-6be7-11eb-ba0d-9b1c1f912d74 \ No newline at end of file diff --git a/x-pack/plugins/alerting/docs/openapi/components/schemas/actions.yaml b/x-pack/plugins/alerting/docs/openapi/components/schemas/actions.yaml new file mode 100644 index 00000000000000..ae381d6b370f30 --- /dev/null +++ b/x-pack/plugins/alerting/docs/openapi/components/schemas/actions.yaml @@ -0,0 +1,22 @@ +type: array +default: [] +required: + - group + - id + - params +nullable: true +items: + type: object + properties: + group: + type: string + description: The group name for the actions. If you don't need to group actions, set to `default`. + example: default + id: + type: string + description: The identifier for the connector saved object. + example: 9dca3e00-74f5-11ed-9801-35303b735aef + params: + type: object + description: The parameters for the action, which are sent to the connector. The `params` are handled as Mustache templates and passed a default set of context. + additionalProperties: true diff --git a/x-pack/plugins/alerting/docs/openapi/components/schemas/notify_when.yaml b/x-pack/plugins/alerting/docs/openapi/components/schemas/notify_when.yaml new file mode 100644 index 00000000000000..875fc057c25ca8 --- /dev/null +++ b/x-pack/plugins/alerting/docs/openapi/components/schemas/notify_when.yaml @@ -0,0 +1,8 @@ +type: string +description: > + Indicates how often alerts generate actions. Valid values include: `onActionGroupChange`: Actions run when the alert status changes; `onActiveAlert`: Actions run when the alert becomes active and at each check interval while the rule conditions are met; `onThrottleInterval`: Actions run when the alert becomes active and at the interval specified in the throttle property while the rule conditions are met. +enum: + - onActionGroupChange + - onActiveAlert + - onThrottleInterval +example: onActiveAlert \ No newline at end of file diff --git a/x-pack/plugins/alerting/docs/openapi/components/schemas/rule_response_properties.yaml b/x-pack/plugins/alerting/docs/openapi/components/schemas/rule_response_properties.yaml new file mode 100644 index 00000000000000..39f35d97d846b3 --- /dev/null +++ b/x-pack/plugins/alerting/docs/openapi/components/schemas/rule_response_properties.yaml @@ -0,0 +1,135 @@ +title: Rule response properties +type: object +required: + - actions + - api_key_owner + - consumer + - created_at + - created_by + - enabled + - execution_status + - id + - mute_all + - muted_alert_ids + - name + - notify_when + - params + - rule_type_id + - schedule + - tags + - throttle + - updated_at + - updated_by +properties: + actions: + $ref: 'actions.yaml' + api_key_owner: + type: string + nullable: true + example: elastic + consumer: + type: string + description: The application or feature that owns the rule. For example, `alerts`, `apm`, `discover`, `infrastructure`, `logs`, `metrics`, `ml`, `monitoring`, `securitySolution`, `siem`, `stackAlerts`, or `uptime`. + example: alerts + created_at: + type: string + description: The date and time that the rule was created. + format: date-time + example: '2022-12-05T23:36:58.284Z' + created_by: + type: string + description: The identifier for the user that created the rule. + nullable: true + example: elastic + enabled: + type: boolean + description: Indicates whether the rule is currently enabled. + example: true + execution_status: + type: object + properties: + last_duration: + type: integer + example: 55 + last_execution_date: + type: string + format: date-time + example: '2022-12-06T00:13:43.890Z' + status: + type: string + example: ok + id: + type: string + description: The identifier for the rule. + example: b530fed0-74f5-11ed-9801-35303b735aef + last_run: + type: object + properties: + alerts_count: + type: object + properties: + active: + type: integer + ignored: + type: integer + new: + type: integer + recovered: + type: integer + outcome: + type: string + example: succeeded + outcome_msg: + type: string + nullable: true + example: null + warning: + type: string + nullable: true + example: null + muted_alert_ids: + type: array + nullable: true + items: + type: string + mute_all: + type: boolean + example: false + name: + type: string + description: The name of the rule. + example: cluster_health_rule + next_run: + type: string + format: date-time + nullable: true + example: '2022-12-06T00:14:43.818Z' + notify_when: + $ref: 'notify_when.yaml' + params: + type: object + description: The parameters for the rule. + additionalProperties: true + rule_type_id: + type: string + description: > + The identifier for the type of rule. For example, `.es-query`, `.index-threshold`, `logs.alert.document.count`, `monitoring_alert_cluster_health`, `siem.thresholdRule`, or `xpack.ml.anomaly_detection_alert`. + example: monitoring_alert_cluster_health + schedule: + $ref: 'schedule.yaml' + scheduled_task_id: + type: string + example: b530fed0-74f5-11ed-9801-35303b735aef + tags: + $ref: 'tags.yaml' + throttle: + $ref: 'throttle.yaml' + updated_at: + type: string + description: The date and time that the rule was updated most recently. + example: '2022-12-05T23:36:58.284Z' + updated_by: + type: string + description: The identifier for the user that updated this rule most recently. + nullable: true + example: elastic \ No newline at end of file diff --git a/x-pack/plugins/alerting/docs/openapi/components/schemas/schedule.yaml b/x-pack/plugins/alerting/docs/openapi/components/schemas/schedule.yaml new file mode 100644 index 00000000000000..57ddf84ceb413f --- /dev/null +++ b/x-pack/plugins/alerting/docs/openapi/components/schemas/schedule.yaml @@ -0,0 +1,6 @@ +type: object +description: The check interval, which specifies how frequently the rule conditions are checked. The interval is specified in seconds, minutes, hours, or days. +properties: + interval: + type: string + example: 1m \ No newline at end of file diff --git a/x-pack/plugins/alerting/docs/openapi/components/schemas/tags.yaml b/x-pack/plugins/alerting/docs/openapi/components/schemas/tags.yaml new file mode 100644 index 00000000000000..98015ced85844d --- /dev/null +++ b/x-pack/plugins/alerting/docs/openapi/components/schemas/tags.yaml @@ -0,0 +1,5 @@ +type: array +description: The tags for the rule. +items: + type: string +default: [] \ No newline at end of file diff --git a/x-pack/plugins/alerting/docs/openapi/components/schemas/throttle.yaml b/x-pack/plugins/alerting/docs/openapi/components/schemas/throttle.yaml new file mode 100644 index 00000000000000..a344013176f44c --- /dev/null +++ b/x-pack/plugins/alerting/docs/openapi/components/schemas/throttle.yaml @@ -0,0 +1,5 @@ +type: string +description: The throttle interval, which defines how often an alert generates repeated actions. It is applicable only if `notify_when` is set to `onThrottleInterval`. It is specified in seconds, minutes, hours, or days. +nullable: true +default: null +example: 10m \ No newline at end of file diff --git a/x-pack/plugins/alerting/docs/openapi/components/schemas/update_rule_request.yaml b/x-pack/plugins/alerting/docs/openapi/components/schemas/update_rule_request.yaml new file mode 100644 index 00000000000000..fb4bd9586ea1f1 --- /dev/null +++ b/x-pack/plugins/alerting/docs/openapi/components/schemas/update_rule_request.yaml @@ -0,0 +1,28 @@ +title: Update rule request +description: >- + The update rule API request body varies depending on the type of rule and actions. +type: object +required: + - name + - notify_when + - params + - schedule +properties: + actions: + $ref: 'actions.yaml' + name: + type: string + description: The name of the rule. + example: cluster_health_rule + notify_when: + $ref: 'notify_when.yaml' + params: + type: object + description: The parameters for the rule. + additionalProperties: true + schedule: + $ref: 'schedule.yaml' + tags: + $ref: 'tags.yaml' + throttle: + $ref: 'throttle.yaml' diff --git a/x-pack/plugins/alerting/docs/openapi/entrypoint.yaml b/x-pack/plugins/alerting/docs/openapi/entrypoint.yaml index 05a3d79ec62a9c..ea46f385b8c5e8 100644 --- a/x-pack/plugins/alerting/docs/openapi/entrypoint.yaml +++ b/x-pack/plugins/alerting/docs/openapi/entrypoint.yaml @@ -15,8 +15,8 @@ servers: - url: 'http://localhost:5601' description: local paths: -# '/s/{spaceId}/api/alerting/rule/{ruleId}': -# $ref: 'paths/s@{spaceid}@api@alerting@rule@{ruleid}.yaml' + '/s/{spaceId}/api/alerting/rule/{ruleId}': + $ref: 'paths/s@{spaceid}@api@alerting@rule@{ruleid}.yaml' # '/s/{spaceId}/api/alerting/rule/{ruleId}/_disable': # $ref: 'paths/s@{spaceid}@api@alerting@rule@{ruleid}@_disable.yaml' # '/s/{spaceId}/api/alerting/rule/{ruleId}/_enable': diff --git a/x-pack/plugins/alerting/docs/openapi/paths/s@{spaceid}@api@alerting@rule@{ruleid}.yaml b/x-pack/plugins/alerting/docs/openapi/paths/s@{spaceid}@api@alerting@rule@{ruleid}.yaml new file mode 100644 index 00000000000000..cb6a4a34525d96 --- /dev/null +++ b/x-pack/plugins/alerting/docs/openapi/paths/s@{spaceid}@api@alerting@rule@{ruleid}.yaml @@ -0,0 +1,94 @@ +get: + summary: Retrieve a rule by its identifier. + operationId: getRule + description: > + You must have `read` privileges for the appropriate Kibana features, + depending on the `consumer` and `rule_type_id` of the rules you're seeking. + For example, the **Management > Stack Rules** feature, + **Analytics > Discover** and **Machine Learning** features, **Observability** + features, or **Security** features. To get rules associated with the + **Stack Monitoring** feature, use the `monitoring_user` built-in role. + tags: + - alerting + parameters: + - $ref: '../components/parameters/rule_id.yaml' + - $ref: '../components/parameters/space_id.yaml' + responses: + '200': + description: Indicates a successful call. + content: + application/json: + schema: + $ref: '../components/schemas/rule_response_properties.yaml' + examples: + updateRuleResponse: + $ref: '../components/examples/get_rule_response.yaml' + +delete: + summary: Deletes a rule. + operationId: deleteRule + description: > + You must have `all` privileges for the appropriate Kibana features, depending + on the `consumer` and `rule_type_id` of the rule you're deleting. For example, + the **Management** > **Stack Rules** feature, **Analytics** > **Discover** or + **Machine Learning** features, **Observability**, or **Security** features. + WARNING: After you delete a rule, you cannot recover it. + tags: + - alerting + parameters: + - $ref: ../components/headers/kbn_xsrf.yaml + - $ref: '../components/parameters/rule_id.yaml' + - $ref: '../components/parameters/space_id.yaml' + responses: + '204': + description: Indicates a successful call. + servers: + - url: https://localhost:5601 + +put: + summary: Updates the attributes for a rule. + operationId: updateRule + description: > + You must have `all` privileges for the appropriate Kibana features, + depending on the `consumer` and `rule_type_id` of the rule you're updating. + For example, you must have privileges for the **Management > Stack rules** + feature, **Analytics > Discover** and **Machine Learning** features, + **Observability** features, or **Security** features. If the rule has + actions, you must also have `read` privileges for the + **Management > Actions and Connectors** feature. NOTE: This API supports + only token-based authentication. When you update a rule, it identifies which + roles you have at that point in time. Thereafter, when the rule performs + queries, it uses those security privileges. If you have different privileges + than the user that created or most recently updated the rule, you might + change its behavior. Though some properties are optional, when you update + the rule the existing property values are overwritten with default values. + Therefore, it is recommended to explicitly set all property values. + tags: + - alerting + parameters: + - $ref: ../components/headers/kbn_xsrf.yaml + - $ref: '../components/parameters/rule_id.yaml' + - $ref: '../components/parameters/space_id.yaml' + requestBody: + required: true + content: + application/json: + schema: + $ref: '../components/schemas/update_rule_request.yaml' + examples: + updateCaseRequest: + $ref: '../components/examples/update_rule_request.yaml' + responses: + '200': + description: Indicates a successful call. + content: + application/json: + schema: + $ref: '../components/schemas/rule_response_properties.yaml' + examples: + updateRuleResponse: + $ref: '../components/examples/update_rule_response.yaml' + servers: + - url: https://localhost:5601 +servers: + - url: https://localhost:5601 \ No newline at end of file diff --git a/x-pack/plugins/alerting/docs/openapi/paths/s@{spaceid}@api@alerting@rules@_find.yaml b/x-pack/plugins/alerting/docs/openapi/paths/s@{spaceid}@api@alerting@rules@_find.yaml index a6d0969efe6140..42c4b817f79683 100644 --- a/x-pack/plugins/alerting/docs/openapi/paths/s@{spaceid}@api@alerting@rules@_find.yaml +++ b/x-pack/plugins/alerting/docs/openapi/paths/s@{spaceid}@api@alerting@rules@_find.yaml @@ -103,154 +103,7 @@ get: data: type: array items: - type: object - properties: - actions: - type: array - items: - type: object - properties: - group: - type: string - description: The group name for the actions. - example: default - id: - type: string - description: The identifier for the connector saved object. - example: 9dca3e00-74f5-11ed-9801-35303b735aef - params: - type: object - description: The parameters for the action, which are sent to the connector. - additionalProperties: true - api_key_owner: - type: string - nullable: true - example: elastic - consumer: - type: string - description: The application or feature that owns the rule. For example, `alerts`, `apm`, `discover`, `infrastructure`, `logs`, `metrics`, `ml`, `monitoring`, `securitySolution`, `siem`, `stackAlerts`, or `uptime`. - example: alerts - created_at: - type: string - description: The date and time that the rule as created. - format: date-time - example: '2022-12-05T23:36:58.284Z' - created_by: - type: string - description: The identifier for the user that created the rule. - nullable: true - example: elastic - enabled: - type: boolean - description: Indicates whether the rule is currently enabled. - example: true - execution_status: - type: object - properties: - status: - type: string - example: ok - last_execution_date: - type: string - format: date-time - example: '2022-12-06T00:13:43.890Z' - last_duration: - type: integer - example: 55 - id: - type: string - description: The identifier for the rule. - example: b530fed0-74f5-11ed-9801-35303b735aef - last_run: - type: object - properties: - alerts_count: - type: object - properties: - new: - type: integer - nullable: true - ignored: - type: integer - nullable: true - recovered: - type: integer - nullable: true - active: - type: integer - nullable: true - outcome_msg: - type: string - nullable: true - example: null - warning: - type: string - nullable: true - example: null - outcome: - type: string - example: succeeded - muted_alert_ids: - type: array - items: - type: string - mute_all: - type: boolean - example: false - name: - type: string - description: The name of the rule. - example: cluster_health_rule - next_run: - type: string - format: date-time - nullable: true - example: '2022-12-06T00:14:43.818Z' - notify_when: - type: string - description: Indicates how often alerts generate actions. - enum: - - onActionGroupChange - - onActiveAlert - - onThrottleInterval - example: onActiveAlert - params: - type: object - description: The parameters for the rule. - additionalProperties: true - rule_type_id: - type: string - description: The identifier for the type of rule. For example, `.es-query`, `.index-threshold`, `logs.alert.document.count`, `monitoring_alert_cluster_health`, `siem.thresholdRule`, or `xpack.ml.anomaly_detection_alert`. - example: monitoring_alert_cluster_health - schedule: - type: object - description: The check interval, which specifies how frequently the rule conditions are checked. The interval is specified in seconds, minutes, hours, or days. - properties: - interval: - type: string - example: 1m - scheduled_task_id: - type: string - example: b530fed0-74f5-11ed-9801-35303b735aef - tags: - type: array - description: The tags for the rule. - items: - type: string - throttle: - type: string - description: The throttle interval, which defines how often an alert generates repeated actions. It is applicable only if `notify_when` is set to `onThrottleInterval`. It is specified in seconds, minutes, hours, or days. - nullable: true - example: 10m - updated_at: - type: string - description: The date and time that the rule was updated most recently. - example: '2022-12-05T23:36:58.284Z' - updated_by: - type: string - description: The identifier for the user that updated this rule most recently. - nullable: true - example: elastic + $ref: '../components/schemas/rule_response_properties.yaml' page: type: integer per_page: From 72bd23b740759e87a33c6579638313510e5317a3 Mon Sep 17 00:00:00 2001 From: spalger Date: Tue, 10 Jan 2023 10:39:48 -0700 Subject: [PATCH 3/3] [sort-package-json] always ensure 2-space indent is used --- packages/kbn-sort-package-json/index.js | 54 +++++++++++++------------ 1 file changed, 29 insertions(+), 25 deletions(-) diff --git a/packages/kbn-sort-package-json/index.js b/packages/kbn-sort-package-json/index.js index 326d6bc8317b38..f6ca06d969f6e1 100644 --- a/packages/kbn-sort-package-json/index.js +++ b/packages/kbn-sort-package-json/index.js @@ -13,29 +13,33 @@ import sorter from 'sort-package-json'; * @returns */ export function sortPackageJson(json) { - return sorter(typeof json === 'string' ? json : JSON.stringify(json, null, 2), { - // top level keys in the order they were written when this was implemented - sortOrder: [ - 'name', - 'description', - 'keywords', - 'private', - 'version', - 'branch', - 'main', - 'browser', - 'types', - 'tsdocMetadata', - 'build', - 'homepage', - 'bugs', - 'license', - 'kibana', - 'author', - 'scripts', - 'repository', - 'engines', - 'resolutions', - ], - }); + return sorter( + // always parse and stringify the json to make sure it's using 2 space indentation + JSON.stringify(typeof json === 'string' ? JSON.parse(json) : json, null, 2), + { + // top level keys in the order they were written when this was implemented + sortOrder: [ + 'name', + 'description', + 'keywords', + 'private', + 'version', + 'branch', + 'main', + 'browser', + 'types', + 'tsdocMetadata', + 'build', + 'homepage', + 'bugs', + 'license', + 'kibana', + 'author', + 'scripts', + 'repository', + 'engines', + 'resolutions', + ], + } + ); }