Package org.graylog2.plugin

Examples of org.graylog2.plugin.Message


    }

    public Message deserialize(byte[] bytes) throws IOException {
        final DeserializeBean bean = mapper.readValue(bytes, DeserializeBean.class);
        final Map<String, Object> fields = bean.getFields();
        final Message message = new Message(
                (String) fields.remove("message"),
                (String) fields.remove("source"),
                new DateTime((long) fields.remove("timestamp"), DateTimeZone.UTC)
        );
        final List<Stream> streamList = Lists.newArrayList();

        for (String id : bean.getStreams()) {
            Stream stream = getStream(id);

            if (stream != null) {
                streamList.add(stream);
            }
        }

        message.setStreams(streamList);
        message.addFields(fields);

        final MessageInput input;
        if (bean.getSourceInput() != null)
            input = getMessageInput(bean.getSourceInput());
        else
            input = null;

        if (input != null) {
            message.setSourceInput(input);
        }

        return message;
    }
View Full Code Here


                        }

                        if (targetBuffer.hasCapacity() && serverStatus.isProcessing()) {
                            try {
                                LOG.debug("Reading message from {}.", cacheName);
                                Message msg = cache.pop();
                                if (msg != null) {
                                    targetBuffer.insertFailFast(msg, msg.getSourceInput());
                                    writtenMessages.mark();
                                }
                            } catch (BufferOutOfCapacityException ex) {
                                outOfCapacity.mark();
                                LOG.debug("Target buffer out of capacity in {}. Breaking.", cacheName);
View Full Code Here

                boolean written = false;

                // Try to write the failed message to MongoDB if enabled.
                if (configuration.isDeadLettersEnabled()) {
                    try {
                        Message message = item.getMessage();

                        Map<String, Object> doc = Maps.newHashMap();
                        doc.put("letter_id", item.getId());
                        doc.put("timestamp", Tools.iso8601());
                        doc.put("message", message.toElasticSearchObject());

                        PersistedDeadLetter persistedDeadLetter = new PersistedDeadLetterImpl(doc);
                        persistedDeadLetterService.saveWithoutValidation(persistedDeadLetter);
                        written = true;
                    } catch(Exception e) {
View Full Code Here

        assertEquals("2013", msg.getField("our_result"));
    }

    @Test
    public void testBasicExtractionWithSpecialRegexChar() throws Exception {
        Message msg = new Message("The short message", "TestUnit", Tools.iso8601());

        msg.addField("somefield", "foo.bar.baz");

        SplitAndIndexExtractor x = new SplitAndIndexExtractor(metricRegistry, "foo", "foo", 0, Extractor.CursorStrategy.COPY, "somefield", "our_result", config(".", 2), "foo", noConverters(), Extractor.ConditionType.NONE, null);
        x.runExtractor(msg);

        assertNotNull(msg.getField("our_result"));
        assertEquals("foo.bar.baz", msg.getField("somefield"));
        assertEquals("bar", msg.getField("our_result"));
    }
View Full Code Here

        assertEquals("bar", msg.getField("our_result"));
    }

    @Test
    public void testBasicExtractionWithCutStrategy() throws Exception {
        Message msg = new Message("The short message", "TestUnit", Tools.iso8601());

        msg.addField("somefield", "<10> 07 Aug 2013 somesubsystem: this is my message for username9001 id:9001");

        SplitAndIndexExtractor x = new SplitAndIndexExtractor(metricRegistry, "foo", "foo", 0, Extractor.CursorStrategy.CUT, "somefield", "our_result", config(" ", 4), "foo", noConverters(), Extractor.ConditionType.NONE, null);
        x.runExtractor(msg);

        assertNotNull(msg.getField("our_result"));
        assertEquals("<10> 07 Aug  somesubsystem: this is my message for username9001 id:9001", msg.getField("somefield"));
        assertEquals("2013", msg.getField("our_result"));
    }
View Full Code Here

                                                 Sets.<MessageFilter>newHashSet(),
                                                 configuration,
                                                 processBufferWatermark, 0, 1,
                                                 outputBuffer);
        try {
            emptyFilters.handleMessage(new Message("test", "source", Tools.iso8601()));
            fail("A processor with empty filter set should throw an exception");
        } catch (RuntimeException ignored) {}
    }
View Full Code Here

                                                 Sets.newHashSet(filterOnlyFirst),
                                                 configuration,
                                                 processBufferWatermark, 0, 1,
                                                 outputBuffer);
        try {
            Message filteredoutMessage = new Message("filtered out", "source", Tools.iso8601());
            Message unfilteredMessage = new Message("filtered out", "source", Tools.iso8601());

            filterTest.handleMessage(filteredoutMessage);
            filterTest.handleMessage(unfilteredMessage);

            verify(outputBuffer, times(0)).insertCached(same(filteredoutMessage), Matchers.<MessageInput>anyObject());
            verify(outputBuffer, times(1)).insertCached(same(unfilteredMessage), Matchers.<MessageInput>anyObject());
            assertTrue(filteredoutMessage.getFilterOut());
            assertFalse(unfilteredMessage.getFilterOut());

        } catch (RuntimeException e) {
            fail("This test should not throw exceptions", e);
        }
    }
View Full Code Here

        assertEquals("2013", msg.getField("our_result"));
    }

    @Test
    public void testBasicExtractionWithCutStrategyCanOverwriteSameField() throws Exception {
        Message msg = new Message("The short message", "TestUnit", Tools.iso8601());

        SplitAndIndexExtractor x = new SplitAndIndexExtractor(metricRegistry, "foo", "foo", 0, Extractor.CursorStrategy.CUT, "message", "message", config(" ", 2), "foo", noConverters(), Extractor.ConditionType.NONE, null);
        x.runExtractor(msg);

        assertEquals("short", msg.getField("message"));
    }
View Full Code Here

        assertEquals("short", msg.getField("message"));
    }
    @Test
    public void testBasicExtractionWithCutStrategyAtEndOfString() throws Exception {
        Message msg = new Message("The short message", "TestUnit", Tools.iso8601());

        msg.addField("somefield", "<10> 07 Aug 2013 somesubsystem: this is my message for username9001 id:9001");

        SplitAndIndexExtractor x = new SplitAndIndexExtractor(metricRegistry, "foo", "foo", 0, Extractor.CursorStrategy.CUT, "somefield", "our_result", config(" ", 12), "foo", noConverters(), Extractor.ConditionType.NONE, null);
        x.runExtractor(msg);

        assertNotNull(msg.getField("our_result"));
        assertEquals("<10> 07 Aug 2013 somesubsystem: this is my message for username9001", msg.getField("somefield"));
        assertEquals("id:9001", msg.getField("our_result"));
    }
View Full Code Here

        assertEquals("id:9001", msg.getField("our_result"));
    }

    @Test
    public void testBasicExtractionDoesNotFailOnTooHighIndex() throws Exception {
        Message msg = new Message("The short message", "TestUnit", Tools.iso8601());

        msg.addField("somefield", "<10> 07 Aug 2013 somesubsystem: this is my message for username9001 id:9001");

        SplitAndIndexExtractor x = new SplitAndIndexExtractor(metricRegistry, "foo", "foo", 0, Extractor.CursorStrategy.COPY, "somefield", "our_result", config(" ", 9001), "foo", noConverters(), Extractor.ConditionType.NONE, null);
        x.runExtractor(msg);

        assertNull(msg.getField("our_result"));
        assertEquals("<10> 07 Aug 2013 somesubsystem: this is my message for username9001 id:9001", msg.getField("somefield"));
    }
View Full Code Here

TOP

Related Classes of org.graylog2.plugin.Message

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.