org.graylog2.plugin.journal.RawMessage Java Examples
The following examples show how to use
org.graylog2.plugin.journal.RawMessage.
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: NetFlowCodecTest.java From graylog-plugin-netflow with Apache License 2.0 | 6 votes |
@Test public void decodeMessagesReturnsNullIfNetFlowParserThrowsFlowException() throws Exception { final byte[] b = "Foobar".getBytes(StandardCharsets.UTF_8); final InetSocketAddress source = new InetSocketAddress(InetAddress.getLocalHost(), 12345); final RawMessage rawMessage = new RawMessage(b, source) { private boolean triggered = false; @Override public byte[] getPayload() { if (triggered) { return new byte[]{}; } triggered = true; throw new FlowException("Boom!"); } }; final Collection<Message> messages = codec.decodeMessages(rawMessage); assertThat(messages).isNull(); }
Example #2
Source File: CloudTrailCodec.java From graylog-plugin-aws with Apache License 2.0 | 6 votes |
@Nullable @Override public Message decode(@Nonnull RawMessage rawMessage) { try { final CloudTrailRecord record = objectMapper.readValue(rawMessage.getPayload(), CloudTrailRecord.class); final String source = configuration.getString(Config.CK_OVERRIDE_SOURCE, "aws-cloudtrail"); final Message message = new Message(record.getConstructedMessage(), source, DateTime.parse(record.eventTime)); message.addFields(record.additionalFieldsAsMap()); message.addField("full_message", record.getFullMessage()); message.addField(AWS.SOURCE_GROUP_IDENTIFIER, true); return message; } catch (Exception e) { throw new RuntimeException("Could not deserialize CloudTrail record.", e); } }
Example #3
Source File: BeatsCodec.java From graylog-plugin-beats with GNU General Public License v3.0 | 5 votes |
@Nullable @Override public Message decode(@Nonnull RawMessage rawMessage) { final byte[] payload = rawMessage.getPayload(); final JsonNode event; try { event = objectMapper.readTree(payload); } catch (IOException e) { LOG.error("Couldn't decode raw message {}", rawMessage); return null; } return parseEvent(event); }
Example #4
Source File: ConsolePrinter.java From graylog-plugin-beats with GNU General Public License v3.0 | 5 votes |
@Override protected void channelRead0(ChannelHandlerContext ctx, ByteBuf message) throws Exception { final int readableBytes = message.readableBytes(); final byte[] messageBytes = new byte[readableBytes]; message.readBytes(messageBytes); final RawMessage rawMessage = new RawMessage(messageBytes); final Message decodedMessage = beatsCodec.decode(rawMessage); System.out.println(decodedMessage); ctx.fireChannelRead(decodedMessage); }
Example #5
Source File: NetFlowCodecTest.java From graylog-plugin-netflow with Apache License 2.0 | 5 votes |
@Test public void decodeMessagesReturnsNullIfMessageWasInvalid() throws Exception { final byte[] b = "Foobar".getBytes(StandardCharsets.UTF_8); final InetSocketAddress source = new InetSocketAddress(InetAddress.getLocalHost(), 12345); final RawMessage rawMessage = new RawMessage(b, source); final Collection<Message> messages = codec.decodeMessages(rawMessage); assertThat(messages).isNull(); }
Example #6
Source File: NetFlowCodecTest.java From graylog-plugin-netflow with Apache License 2.0 | 5 votes |
@Test public void decodeMessagesThrowsEmptyTemplateExceptionWithIncompleteNetFlowV9() throws Exception { final byte[] b = Resources.toByteArray(Resources.getResource("netflow-data/netflow-v9-3_incomplete.dat")); final InetSocketAddress source = new InetSocketAddress(InetAddress.getLocalHost(), 12345); assertThat(codec.decodeMessages(new RawMessage(b, source))).isNull(); }
Example #7
Source File: NetflowV9CodecAggregatorTest.java From graylog-plugin-netflow with Apache License 2.0 | 5 votes |
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 #8
Source File: BeatsCodecTest.java From graylog-plugin-beats with GNU General Public License v3.0 | 4 votes |
@Test public void decodeReturnsNullIfPayloadCouldNotBeDecoded() throws Exception { assertThat(codec.decode(new RawMessage(new byte[0]))).isNull(); }
Example #9
Source File: BeatsCodecTest.java From graylog-plugin-beats with GNU General Public License v3.0 | 4 votes |
private RawMessage messageFromJson(String resourceName) throws IOException { final URL resource = Resources.getResource(resourceName); final byte[] json = Resources.toByteArray(resource); return new RawMessage(json); }
Example #10
Source File: NetFlowCodec.java From graylog-plugin-netflow with Apache License 2.0 | 4 votes |
@Nullable @Override public Message decode(@Nonnull RawMessage rawMessage) { throw new UnsupportedOperationException("MultiMessageCodec " + getClass() + " does not support decode()"); }
Example #11
Source File: NetFlowCodecTest.java From graylog-plugin-netflow with Apache License 2.0 | 4 votes |
@Test public void decodeThrowsUnsupportedOperationException() throws Exception { assertThatExceptionOfType(UnsupportedOperationException.class) .isThrownBy(() -> codec.decode(new RawMessage(new byte[0]))) .withMessage("MultiMessageCodec " + NetFlowCodec.class + " does not support decode()"); }
Example #12
Source File: KinesisTransport.java From graylog-plugin-aws with Apache License 2.0 | 4 votes |
private Consumer<byte[]> kinesisCallback(final MessageInput input) { return (data) -> input.processRawMessage(new RawMessage(data)); }