Search in sources :

Example 6 with Message

use of org.graylog2.plugin.Message 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 7 with Message

use of org.graylog2.plugin.Message in project graylog2-server by Graylog2.

the class SyslogCodec method decode.

@Nullable
@Override
public Message decode(@Nonnull RawMessage rawMessage) {
    final String msg = new String(rawMessage.getPayload(), StandardCharsets.UTF_8);
    try (Timer.Context ignored = this.decodeTime.time()) {
        final ResolvableInetSocketAddress address = rawMessage.getRemoteAddress();
        final InetSocketAddress remoteAddress;
        if (address == null) {
            remoteAddress = null;
        } else {
            remoteAddress = address.getInetSocketAddress();
        }
        return parse(msg, remoteAddress == null ? null : remoteAddress.getAddress(), rawMessage.getTimestamp());
    }
}
Also used : ResolvableInetSocketAddress(org.graylog2.plugin.ResolvableInetSocketAddress) Timer(com.codahale.metrics.Timer) ResolvableInetSocketAddress(org.graylog2.plugin.ResolvableInetSocketAddress) InetSocketAddress(java.net.InetSocketAddress) Nullable(javax.annotation.Nullable)

Example 8 with Message

use of org.graylog2.plugin.Message 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)

Example 9 with Message

use of org.graylog2.plugin.Message in project graylog2-server by Graylog2.

the class BenchmarkOutput method write.

@Override
public void write(List<Message> messages) throws Exception {
    long maxOffset = Long.MIN_VALUE;
    for (final Message message : messages) {
        maxOffset = Math.max(message.getJournalOffset(), maxOffset);
    }
    journal.markJournalOffsetCommitted(maxOffset);
    messagesWritten.mark(messages.size());
}
Also used : Message(org.graylog2.plugin.Message)

Example 10 with Message

use of org.graylog2.plugin.Message in project graylog2-server by Graylog2.

the class GelfOutput method toGELFMessage.

protected GelfMessage toGELFMessage(final Message message) {
    final DateTime timestamp;
    final Object fieldTimeStamp = message.getField(Message.FIELD_TIMESTAMP);
    if (fieldTimeStamp instanceof DateTime) {
        timestamp = (DateTime) fieldTimeStamp;
    } else {
        timestamp = Tools.nowUTC();
    }
    final GelfMessageLevel messageLevel = extractLevel(message.getField(Message.FIELD_LEVEL));
    final String fullMessage = (String) message.getField(Message.FIELD_FULL_MESSAGE);
    final String facility = (String) message.getField("facility");
    final String forwarder = GelfOutput.class.getCanonicalName();
    final GelfMessageBuilder builder = new GelfMessageBuilder(message.getMessage(), message.getSource()).timestamp(timestamp.getMillis() / 1000.0d).additionalField("_forwarder", forwarder).additionalFields(message.getFields());
    if (messageLevel != null) {
        builder.level(messageLevel);
    }
    if (fullMessage != null) {
        builder.fullMessage(fullMessage);
    }
    if (facility != null) {
        builder.additionalField("_facility", facility);
    }
    return builder.build();
}
Also used : GelfMessageLevel(org.graylog2.gelfclient.GelfMessageLevel) GelfMessageBuilder(org.graylog2.gelfclient.GelfMessageBuilder) DateTime(org.joda.time.DateTime)

Aggregations

Test (org.junit.Test)227 Message (org.graylog2.plugin.Message)226 ApiOperation (io.swagger.annotations.ApiOperation)97 ApiResponses (io.swagger.annotations.ApiResponses)91 Timed (com.codahale.metrics.annotation.Timed)90 Path (javax.ws.rs.Path)72 StreamRule (org.graylog2.plugin.streams.StreamRule)70 AuditEvent (org.graylog2.audit.jersey.AuditEvent)62 Produces (javax.ws.rs.Produces)49 DateTime (org.joda.time.DateTime)46 Stream (org.graylog2.plugin.streams.Stream)45 GET (javax.ws.rs.GET)33 RawMessage (org.graylog2.plugin.journal.RawMessage)31 BadRequestException (javax.ws.rs.BadRequestException)30 POST (javax.ws.rs.POST)28 Result (org.graylog2.plugin.inputs.Extractor.Result)27 Callable (java.util.concurrent.Callable)26 PUT (javax.ws.rs.PUT)26 Consumes (javax.ws.rs.Consumes)21 AlertCondition (org.graylog2.plugin.alarms.AlertCondition)21