Search in sources :

Example 1 with GeneratorState

use of org.graylog2.inputs.random.generators.FakeHttpRawMessageGenerator.GeneratorState in project graylog2-server by Graylog2.

the class RandomHttpMessageCodec method decode.

@Nullable
@Override
public Message decode(@Nonnull RawMessage rawMessage) {
    if (!rawMessage.getCodecName().equals(getName())) {
        log.error("Cannot decode payload type {}, skipping message {}", rawMessage.getCodecName(), rawMessage.getId());
        return null;
    }
    try {
        final GeneratorState state = objectMapper.readValue(rawMessage.getPayload(), GeneratorState.class);
        final Message message = FakeHttpRawMessageGenerator.generateMessage(state);
        return message;
    } catch (IOException e) {
        log.error("Cannot decode message to class FakeHttpRawMessageGenerator.GeneratorState", e);
    }
    return null;
}
Also used : RawMessage(org.graylog2.plugin.journal.RawMessage) Message(org.graylog2.plugin.Message) IOException(java.io.IOException) GeneratorState(org.graylog2.inputs.random.generators.FakeHttpRawMessageGenerator.GeneratorState) Nullable(javax.annotation.Nullable)

Example 2 with GeneratorState

use of org.graylog2.inputs.random.generators.FakeHttpRawMessageGenerator.GeneratorState in project graylog2-server by Graylog2.

the class FakeHttpRawMessageGenerator method createMessage.

private static Message createMessage(GeneratorState state, int httpCode, Resource resource, int tookMs, DateTime ingestTime) {
    final Message msg = new Message(shortMessage(ingestTime, state.method, state.resource, httpCode, tookMs), state.source, Tools.nowUTC());
    msg.addFields(ingestTimeFields(ingestTime));
    msg.addFields(resourceFields(resource));
    msg.addField("ticks", System.nanoTime());
    msg.addField("http_method", state.method.name());
    msg.addField("http_response_code", httpCode);
    msg.addField("user_id", state.userId);
    msg.addField("took_ms", tookMs);
    return msg;
}
Also used : Message(org.graylog2.plugin.Message)

Aggregations

Message (org.graylog2.plugin.Message)2 IOException (java.io.IOException)1 Nullable (javax.annotation.Nullable)1 GeneratorState (org.graylog2.inputs.random.generators.FakeHttpRawMessageGenerator.GeneratorState)1 RawMessage (org.graylog2.plugin.journal.RawMessage)1