import { schema } from '@kbn/config-schema' ; import { GrokdebuggerRequest } from '../../../models/grokdebugger_request' ; import { GrokdebuggerResponse } from '../../../models/grokdebugger_response' ; import { handleEsError } from '../../../shared_imports' ; import { KibanaFramework } from '../../../lib/kibana_framework' ; const requestBodySchema = schema . object ( { pattern : schema . string ( ) , rawEvent : schema . string ( ) , customPatterns : schema . object ( { } , { unknowns : 'allow' } ) , } ) ; export function registerGrokSimulateRoute ( framework ) { framework . registerRoute ( { method : 'post' , path : '/api/grokdebugger/simulate' , validate : { body : requestBodySchema , } , } , async ( requestContext , request , response ) => { try { const grokdebuggerRequest = GrokdebuggerRequest . fromDownstreamJSON ( request . body ) ; const simulateResponseFromES = await requestContext . core . elasticsearch . client . asCurrentUser . ingest . simulate ( { body : grokdebuggerRequest . upstreamJSON , } ) ; const grokdebuggerResponse = GrokdebuggerResponse . fromUpstreamJSON ( simulateResponseFromES . body ) ; return response . ok ( { body : grokdebuggerResponse , } ) ; } catch ( error ) { return handleEsError ( { error , response } ) ; } } ) ; }