public override async Task ConfigureAsync()
        {
            const string FLATTEN_ERRORS_SCRIPT = @"
if (!ctx.containsKey('data') || !(ctx.data.containsKey('@error') || ctx.data.containsKey('@simple_error')))
    return null;

def types = [];
def messages = [];
def codes = [];
def err = ctx.data.containsKey('@error') ? ctx.data['@error'] : ctx.data['@simple_error'];
def curr = err;
while (curr != null) {
    if (curr.containsKey('type'))
        types.add(curr.type);
    if (curr.containsKey('message'))
        messages.add(curr.message);
    if (curr.containsKey('code'))
        codes.add(curr.code);
    curr = curr.inner;
}

if (ctx.error == null)
    ctx.error = new HashMap();

ctx.error.type = types;
ctx.error.message = messages;
ctx.error.code = codes;";

            var response = await Configuration.Client.PutPipelineAsync(Pipeline, d => d.Processors(p => p
                                                                                                   .Script(s => new ScriptProcessor {
                Inline = FLATTEN_ERRORS_SCRIPT.Replace("\r\n", String.Empty).Replace("    ", " ")
            })));

            var logger = Configuration.LoggerFactory.CreateLogger <EventIndexType>();

            if (logger.IsEnabled(LogLevel.Trace))
            {
                logger.LogTrace(response.GetRequest());
            }

            if (response.IsValid)
            {
                return;
            }

            logger.LogError(response.OriginalException, "Error creating the pipeline {Pipeline}: {Message}", Pipeline, response.GetErrorMessage());
            throw new ApplicationException($"Error creating the pipeline {Pipeline}: {response.GetErrorMessage()}", response.OriginalException);
        }
Exemple #2
0
        public override async Task ConfigureAsync()
        {
            const string pipeline = "events-pipeline";
            var          response = await Configuration.Client.Ingest.PutPipelineAsync(pipeline, d => d.Processors(p => p
                                                                                                                   .Script(s => new ScriptProcessor {
                Source = FLATTEN_ERRORS_SCRIPT.Replace("\r", String.Empty).Replace("\n", String.Empty).Replace("  ", " ")
            })));

            var logger = Configuration.LoggerFactory.CreateLogger <EventIndex>();

            logger.LogRequest(response);

            if (!response.IsValid)
            {
                logger.LogError(response.OriginalException, "Error creating the pipeline {Pipeline}: {Message}", pipeline, response.GetErrorMessage());
                throw new ApplicationException($"Error creating the pipeline {pipeline}: {response.GetErrorMessage()}", response.OriginalException);
            }

            await base.ConfigureAsync();
        }