org.graylog2.plugin.inputs.codecs.CodecAggregator Java Examples

The following examples show how to use org.graylog2.plugin.inputs.codecs.CodecAggregator. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NetflowMessageAggregationHandler.java    From graylog-plugin-netflow with Apache License 2.0 6 votes vote down vote up
@Override
protected void channelRead0(ChannelHandlerContext ctx, DatagramPacket msg) throws Exception {
    final SocketAddress remoteAddress = msg.sender();
    final CodecAggregator.Result result;
    try (Timer.Context ignored = aggregationTimer.time()) {
        result = aggregator.addChunk(msg.content(), remoteAddress);
    }
    final ByteBuf completeMessage = result.getMessage();
    if (completeMessage != null) {
        LOG.debug("Message aggregation completion, forwarding {}", completeMessage);
        ctx.fireChannelRead(completeMessage);
    } else if (result.isValid()) {
        LOG.debug("More chunks necessary to complete this message");
    } else {
        invalidChunksMeter.mark();
        LOG.debug("Message chunk was not valid and discarded.");
    }
}
 
Example #2
Source File: NetflowV9CodecAggregatorTest.java    From graylog-plugin-netflow with Apache License 2.0 6 votes vote down vote up
private Collection<NetFlowV9Packet> parseNetflowPcapStream(String resourceName) throws IOException {
    final List<NetFlowV9Packet> allPackets = Lists.newArrayList();
    try (InputStream inputStream = Resources.getResource(resourceName).openStream()) {
        final Pcap pcap = Pcap.openStream(inputStream);
        pcap.loop(packet -> {
                    if (packet.hasProtocol(Protocol.UDP)) {
                        final UDPPacket udp = (UDPPacket) packet.getPacket(Protocol.UDP);
                        final InetSocketAddress source = new InetSocketAddress(udp.getSourceIP(), udp.getSourcePort());
                        final CodecAggregator.Result result = codecAggregator.addChunk(Unpooled.copiedBuffer(udp.getPayload().getArray()), source);
                        if (result.isValid() && result.getMessage() != null) {
                            final ByteBuf buffer = result.getMessage();
                            // must read the marker byte off the buffer first.
                            buffer.readByte();
                            allPackets.addAll(codec.decodeV9Packets(buffer));
                        }
                    }
                    return true;
                }
        );
    }
    return allPackets;
}
 
Example #3
Source File: NetflowV9CodecAggregatorTest.java    From graylog-plugin-netflow with Apache License 2.0 6 votes vote down vote up
private Collection<Message> decodePcapStream(String resourceName) throws IOException {

        final List<Message> allMessages = Lists.newArrayList();
        try (InputStream inputStream = Resources.getResource(resourceName).openStream()) {
            final Pcap pcap = Pcap.openStream(inputStream);
            pcap.loop(packet -> {
                        if (packet.hasProtocol(Protocol.UDP)) {
                            final UDPPacket udp = (UDPPacket) packet.getPacket(Protocol.UDP);
                            final InetSocketAddress source = new InetSocketAddress(udp.getSourceIP(), udp.getSourcePort());
                            final CodecAggregator.Result result = codecAggregator.addChunk(Unpooled.copiedBuffer(udp.getPayload().getArray()), source);
                            if (result.isValid() && result.getMessage() != null) {
                                final Collection<Message> c = codec.decodeMessages(convertToRawMessage(result, source));
                                if (c != null) {
                                    allMessages.addAll(c);
                                }
                            }
                        }
                        return true;
                    }
            );
        }
        return allMessages;
    }
 
Example #4
Source File: NetflowV9CodecAggregatorTest.java    From graylog-plugin-netflow with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example #5
Source File: NetFlowCodec.java    From graylog-plugin-netflow with Apache License 2.0 4 votes vote down vote up
@Nullable
@Override
public CodecAggregator getAggregator() {
    return netflowV9CodecAggregator;
}
 
Example #6
Source File: NetflowV9CodecAggregatorTest.java    From graylog-plugin-netflow with Apache License 2.0 4 votes vote down vote up
private CodecAggregator.Result aggregateRawPacket(String resourceName) throws IOException {
    final byte[] bytes = Resources.toByteArray(Resources.getResource(resourceName));
    final ByteBuf channelBuffer = Unpooled.wrappedBuffer(bytes);
    return codecAggregator.addChunk(channelBuffer, source);
}
 
Example #7
Source File: NetflowV9CodecAggregatorTest.java    From graylog-plugin-netflow with Apache License 2.0 4 votes vote down vote up
private Collection<Message> decodeResult(CodecAggregator.Result result) {
    if (result.getMessage() == null) {
        return Collections.emptyList();
    }
    return codec.decodeMessages(convertToRawMessage(result, source));
}
 
Example #8
Source File: CloudWatchLogDataCodec.java    From graylog-plugin-aws with Apache License 2.0 4 votes vote down vote up
@Nullable
@Override
public CodecAggregator getAggregator() {
    return null;
}
 
Example #9
Source File: KinesisTransport.java    From graylog-plugin-aws with Apache License 2.0 4 votes vote down vote up
@Override
public void setMessageAggregator(CodecAggregator aggregator) {
    // Not supported.
}
 
Example #10
Source File: CloudTrailTransport.java    From graylog-plugin-aws with Apache License 2.0 4 votes vote down vote up
@Override
public void setMessageAggregator(CodecAggregator aggregator) {
    // Not supported.
}
 
Example #11
Source File: HttpMonitorTransport.java    From graylog2-plugin-input-httpmonitor with MIT License 2 votes vote down vote up
@Override
public void setMessageAggregator(CodecAggregator codecAggregator) {

}