Search in sources :

Example 11 with RawMessage

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);
}
Also used : ByteBuf(io.netty.buffer.ByteBuf) RawMessage(org.graylog2.plugin.journal.RawMessage)

Example 12 with RawMessage

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)));
}
Also used : Response(okhttp3.Response) MalformedURLException(java.net.MalformedURLException) InetSocketAddress(java.net.InetSocketAddress) IOException(java.io.IOException) RawMessage(org.graylog2.plugin.journal.RawMessage) URL(java.net.URL)

Example 13 with RawMessage

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;
}
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 14 with RawMessage

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());
    }
}
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 15 with RawMessage

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);
}
Also used : ByteBuf(io.netty.buffer.ByteBuf) RawMessage(org.graylog2.plugin.journal.RawMessage)

Aggregations

RawMessage (org.graylog2.plugin.journal.RawMessage)59 Test (org.junit.Test)35 Message (org.graylog2.plugin.Message)23 InetSocketAddress (java.net.InetSocketAddress)13 IOException (java.io.IOException)7 Nullable (javax.annotation.Nullable)7 MappedMessage (org.graylog.plugins.cef.parser.MappedMessage)6 ResolvableInetSocketAddress (org.graylog2.plugin.ResolvableInetSocketAddress)6 DateTime (org.joda.time.DateTime)5 Configuration (org.graylog2.plugin.configuration.Configuration)4 ByteBuf (io.netty.buffer.ByteBuf)3 URL (java.net.URL)3 ZonedDateTime (java.time.ZonedDateTime)3 Timer (com.codahale.metrics.Timer)2 List (java.util.List)2 Map (java.util.Map)2 Properties (java.util.Properties)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 NotFoundException (javax.ws.rs.NotFoundException)2 DocumentNotFoundException (org.graylog2.indexer.messages.DocumentNotFoundException)2