Search in sources :

Example 1 with NetFlowV9OptionTemplate

use of org.graylog.plugins.netflow.v9.NetFlowV9OptionTemplate in project graylog2-server by Graylog2.

the class NetFlowCodec method decodeV9Packets.

@VisibleForTesting
List<NetFlowV9Packet> decodeV9Packets(ByteBuf buffer) throws InvalidProtocolBufferException {
    byte[] v9JournalEntry = new byte[buffer.readableBytes()];
    buffer.readBytes(v9JournalEntry);
    final NetFlowV9Journal.RawNetflowV9 rawNetflowV9 = NetFlowV9Journal.RawNetflowV9.parseFrom(v9JournalEntry);
    // parse all templates used in the packet
    final Map<Integer, NetFlowV9Template> templateMap = Maps.newHashMap();
    rawNetflowV9.getTemplatesMap().forEach((templateId, byteString) -> {
        final NetFlowV9Template netFlowV9Template = NetFlowV9Parser.parseTemplate(Unpooled.wrappedBuffer(byteString.toByteArray()), typeRegistry);
        templateMap.put(templateId, netFlowV9Template);
    });
    final NetFlowV9OptionTemplate[] optionTemplate = { null };
    rawNetflowV9.getOptionTemplateMap().forEach((templateId, byteString) -> {
        optionTemplate[0] = NetFlowV9Parser.parseOptionTemplate(Unpooled.wrappedBuffer(byteString.toByteArray()), typeRegistry);
    });
    return rawNetflowV9.getPacketsList().stream().map(bytes -> Unpooled.wrappedBuffer(bytes.toByteArray())).map(buf -> NetFlowV9Parser.parsePacket(buf, typeRegistry, templateMap, optionTemplate[0])).collect(Collectors.toList());
}
Also used : Configuration(org.graylog2.plugin.configuration.Configuration) TextField(org.graylog2.plugin.configuration.fields.TextField) NetFlowV5Packet(org.graylog.plugins.netflow.v5.NetFlowV5Packet) NetFlowV9OptionTemplate(org.graylog.plugins.netflow.v9.NetFlowV9OptionTemplate) LoggerFactory(org.slf4j.LoggerFactory) Unpooled(io.netty.buffer.Unpooled) NettyTransport(org.graylog2.plugin.inputs.transports.NettyTransport) Assisted(com.google.inject.assistedinject.Assisted) Inject(javax.inject.Inject) ResolvableInetSocketAddress(org.graylog2.plugin.ResolvableInetSocketAddress) NetFlowFormatter(org.graylog.plugins.netflow.flows.NetFlowFormatter) ByteBuf(io.netty.buffer.ByteBuf) NetFlowV9Journal(org.graylog.plugins.netflow.v9.NetFlowV9Journal) Map(java.util.Map) RawMessage(org.graylog2.plugin.journal.RawMessage) NetFlowV9FieldTypeRegistry(org.graylog.plugins.netflow.v9.NetFlowV9FieldTypeRegistry) NetFlowV9Packet(org.graylog.plugins.netflow.v9.NetFlowV9Packet) CodecAggregator(org.graylog2.plugin.inputs.codecs.CodecAggregator) Codec(org.graylog2.plugin.inputs.annotations.Codec) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) ConfigurationRequest(org.graylog2.plugin.configuration.ConfigurationRequest) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) ConfigurationField(org.graylog2.plugin.configuration.fields.ConfigurationField) ExceptionUtils(org.graylog2.shared.utilities.ExceptionUtils) Logger(org.slf4j.Logger) MultiMessageCodec(org.graylog2.plugin.inputs.codecs.MultiMessageCodec) Collection(java.util.Collection) FactoryClass(org.graylog2.plugin.inputs.annotations.FactoryClass) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) Maps(com.google.common.collect.Maps) NetFlowV5Parser(org.graylog.plugins.netflow.v5.NetFlowV5Parser) InetSocketAddress(java.net.InetSocketAddress) Collectors(java.util.stream.Collectors) FlowException(org.graylog.plugins.netflow.flows.FlowException) NetFlowV9Template(org.graylog.plugins.netflow.v9.NetFlowV9Template) ByteBufUtil(io.netty.buffer.ByteBufUtil) List(java.util.List) ConfigClass(org.graylog2.plugin.inputs.annotations.ConfigClass) NetFlowV9Record(org.graylog.plugins.netflow.v9.NetFlowV9Record) NetFlowV9Parser(org.graylog.plugins.netflow.v9.NetFlowV9Parser) AbstractCodec(org.graylog2.plugin.inputs.codecs.AbstractCodec) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Message(org.graylog2.plugin.Message) InputStream(java.io.InputStream) NetFlowV9Template(org.graylog.plugins.netflow.v9.NetFlowV9Template) NetFlowV9OptionTemplate(org.graylog.plugins.netflow.v9.NetFlowV9OptionTemplate) NetFlowV9Journal(org.graylog.plugins.netflow.v9.NetFlowV9Journal) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Maps (com.google.common.collect.Maps)1 Assisted (com.google.inject.assistedinject.Assisted)1 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 ByteBuf (io.netty.buffer.ByteBuf)1 ByteBufUtil (io.netty.buffer.ByteBufUtil)1 Unpooled (io.netty.buffer.Unpooled)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 InetSocketAddress (java.net.InetSocketAddress)1 Collection (java.util.Collection)1 List (java.util.List)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 Nonnull (javax.annotation.Nonnull)1 Nullable (javax.annotation.Nullable)1 Inject (javax.inject.Inject)1 FlowException (org.graylog.plugins.netflow.flows.FlowException)1 NetFlowFormatter (org.graylog.plugins.netflow.flows.NetFlowFormatter)1