/* * 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, { useState, useEffect, Fragment } from 'react'; import { EuiText, EuiLoadingLogo, EuiCallOut, EuiTextColor, EuiDescriptionList, EuiDescriptionListTitle, EuiDescriptionListDescription, EuiCodeBlock, EuiSpacer, } from '@elastic/eui'; import { withRouter, RouteComponentProps } from 'react-router-dom'; import { CoreStart } from '@kbn/core/public'; import { isEmpty } from 'lodash'; import { BASE_ALERTING_API_PATH, INTERNAL_BASE_ALERTING_API_PATH, } from '@kbn/alerting-plugin/common'; import { ALERTING_EXAMPLE_APP_ID } from '../../common/constants'; import { Rule, RuleTaskState } from '../../common/types'; type Props = RouteComponentProps & { http: CoreStart['http']; id: string; }; export const ViewAlertPage = withRouter(({ http, id }: Props) => { const [alert, setAlert] = useState(null); const [alertState, setAlertState] = useState(null); useEffect(() => { if (!alert) { http.get(`${BASE_ALERTING_API_PATH}/rule/${id}`).then(setAlert); } if (!alertState) { http .get(`${INTERNAL_BASE_ALERTING_API_PATH}/rule/${id}/state`) .then(setAlertState); } }, [alert, alertState, http, id]); return alert && alertState ? (

This is a generic view for all Rules created by the {ALERTING_EXAMPLE_APP_ID} plugin.

You are now viewing the {`${alert.name}`} Rule, whose ID is {`${alert.id}`}.

Its RuleType is {`${alert.rule_type_id}`} and its scheduled to run at an interval of {`${alert.schedule.interval}`}.

Alerts

{isEmpty(alertState.alerts) ? (

This Rule doesn't have any active alerts at the moment.

) : (

Below are the active Alerts which were activated on the rules last run.
For each alert id you can see its current state in JSON format.

{Object.entries(alertState.alerts ?? {}).map(([instance, { state }]) => ( {instance} {`${JSON.stringify(state)}`} ))}
)}
) : ( ); });