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;
}
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());
}
}
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;
}
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());
}
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();
}
Aggregations