use of org.graylog2.plugin.journal.RawMessage in project graylog2-server by Graylog2.
the class EnvelopeMessageHandler method channelRead0.
@Override
protected void channelRead0(ChannelHandlerContext ctx, AddressedEnvelope<ByteBuf, InetSocketAddress> envelope) throws Exception {
final ByteBuf msg = envelope.content();
final byte[] bytes = new byte[msg.readableBytes()];
msg.readBytes(bytes);
final RawMessage raw = new RawMessage(bytes, envelope.sender());
input.processRawMessage(raw);
}
use of org.graylog2.plugin.journal.RawMessage in project graylog2-server by Graylog2.
the class HttpPollTransport method doLaunch.
@Override
public void doLaunch(final MessageInput input) throws MisfireException {
serverStatus.awaitRunning(() -> lifecycleStateChange(Lifecycle.RUNNING));
// listen for lifecycle changes
serverEventBus.register(this);
final Map<String, String> headers = parseHeaders(configuration.getString(CK_HEADERS));
// figure out a reasonable remote address
final String url = configuration.getString(CK_URL);
final InetSocketAddress remoteAddress;
InetSocketAddress remoteAddress1;
try {
final URL url1 = new URL(url);
final int port = url1.getPort();
remoteAddress1 = new InetSocketAddress(url1.getHost(), port != -1 ? port : 80);
} catch (MalformedURLException e) {
remoteAddress1 = null;
}
remoteAddress = remoteAddress1;
final Runnable task = () -> {
if (paused) {
LOG.debug("Message processing paused, not polling HTTP resource {}.", url);
return;
}
if (isThrottled()) {
// this transport won't block, but we can simply skip this iteration
LOG.debug("Not polling HTTP resource {} because we are throttled.", url);
return;
}
final Request.Builder requestBuilder = new Request.Builder().get().url(url).headers(Headers.of(headers));
try (final Response r = httpClient.newCall(requestBuilder.build()).execute()) {
if (!r.isSuccessful()) {
LOG.error("Expected successful HTTP status code [2xx], got " + r.code());
return;
}
input.processRawMessage(new RawMessage(r.body().bytes(), remoteAddress));
} catch (IOException e) {
LOG.error("Could not fetch HTTP resource at " + url, e);
}
};
scheduledFuture = scheduler.scheduleAtFixedRate(task, 0, configuration.getInt(CK_INTERVAL), TimeUnit.valueOf(configuration.getString(CK_TIMEUNIT)));
}
use of org.graylog2.plugin.journal.RawMessage 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.journal.RawMessage 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.journal.RawMessage in project graylog2-server by Graylog2.
the class NetflowV9CodecAggregatorTest method convertToRawMessage.
private RawMessage convertToRawMessage(CodecAggregator.Result result, SocketAddress remoteAddress) {
final ByteBuf buffer = result.getMessage();
assertThat(buffer).isNotNull();
final byte[] payload = ByteBufUtil.getBytes(buffer);
return new RawMessage(payload, (InetSocketAddress) remoteAddress);
}
Aggregations