import { schema } from '@kbn/config-schema' ; import { UsageCounter } from 'src/plugins/usage_collection/server' ; import type { AlertingRouter } from '../../types' ; import { ILicenseState } from '../../lib/license_state' ; import { verifyApiAccess } from '../../lib/license_api_access' ; import { LEGACY_BASE_ALERT_API_PATH } from '../../../common' ; import { trackLegacyRouteUsage } from '../../lib/track_legacy_route_usage' ; const paramSchema = schema . object ( { id : schema . string ( ) , } ) ; export const getAlertStateRoute = ( router , licenseState , usageCounter ? ) => { router . get ( { path : `${ LEGACY_BASE_ALERT_API_PATH }/alert/{id}/state` , validate : { params : paramSchema , } , } , router . handleLegacyErrors ( async function ( context , req , res ) { verifyApiAccess ( licenseState ) ; if ( ! context . alerting ) { return res . badRequest ( { body : 'RouteHandlerContext is not registered for alerting' } ) ; } trackLegacyRouteUsage ( 'state' , usageCounter ) ; const rulesClient = context . alerting . getRulesClient ( ) ; const { id } = req . params ; const state = await rulesClient . getAlertState ( { id } ) ; return state ? res . ok ( { body : state } ) : res . noContent ( ) ; } ) ) ; } ;