Package org.apache.camel.component.splunk.event

Examples of org.apache.camel.component.splunk.event.SplunkEvent


    }

    private List<SplunkEvent> extractData(Job job, boolean realtime) throws Exception {
        List<SplunkEvent> result = new ArrayList<SplunkEvent>();
        HashMap<String, String> data;
        SplunkEvent splunkData;
        ResultsReader resultsReader = null;
        int total = 0;
        if (realtime) {
            total = job.getResultPreviewCount();
        } else {
            total = job.getResultCount();
        }
        if (getCount() == 0 || total < getCount()) {
            InputStream stream = null;
            JobResultsArgs outputArgs = new JobResultsArgs();
            outputArgs.setOutputMode(OutputMode.JSON);
            if (realtime) {
                if (getCount() > 0) {
                    outputArgs.setCount(getCount());
                }
                stream = job.getResultsPreview(outputArgs);
            } else {
                stream = job.getResults(outputArgs);
            }

            resultsReader = new ResultsReaderJson(stream);
            while ((data = resultsReader.getNextEvent()) != null) {
                splunkData = new SplunkEvent(data);
                result.add(splunkData);
            }
            IOHelper.close(stream);
        } else {
            int offset = 0;
            while (offset < total) {
                InputStream stream;
                JobResultsArgs outputArgs = new JobResultsArgs();
                outputArgs.setOutputMode(OutputMode.JSON);
                outputArgs.setCount(getCount());
                outputArgs.setOffset(offset);
                if (realtime) {
                    stream = job.getResultsPreview(outputArgs);
                } else {
                    stream = job.getResults(outputArgs);
                }
                resultsReader = new ResultsReaderJson(stream);
                while ((data = resultsReader.getNextEvent()) != null) {
                    splunkData = new SplunkEvent(data);
                    result.add(splunkData);
                }
                offset += getCount();
                IOHelper.close(stream);
            }
View Full Code Here


public class SplunkEventProcessor implements Processor {

    @Override
    public void process(Exchange exchange) throws Exception {
        SplunkEvent splunkEvent = new SplunkEvent();

        splunkEvent.addPair("ERRORKEY", "AVUA123");
        splunkEvent.addPair("ERRORMSG", "Service ABC Failed");
        splunkEvent.addPair("ERRORDESC", "BusinessException: Username and password don't match");
        splunkEvent.addPair(SplunkEvent.COMMON_START_TIME, "Thu Aug 15 2014 00:15:06");

        exchange.getIn().setBody(splunkEvent, SplunkEvent.class);
    }
View Full Code Here

    }

    private List<SplunkEvent> extractData(Job job, boolean realtime, SplunkResultProcessor callback) throws Exception {
        List<SplunkEvent> result = new ArrayList<SplunkEvent>();
        HashMap<String, String> data;
        SplunkEvent splunkData;
        ResultsReader resultsReader = null;
        int total = 0;
        if (realtime) {
            total = job.getResultPreviewCount();
        } else {
            total = job.getResultCount();
        }
        if (getCount() == 0 || total < getCount()) {
            InputStream stream = null;
            JobResultsArgs outputArgs = new JobResultsArgs();
            outputArgs.setOutputMode(OutputMode.JSON);
            if (realtime) {
                if (getCount() > 0) {
                    outputArgs.setCount(getCount());
                }
                stream = job.getResultsPreview(outputArgs);
            } else {
                stream = job.getResults(outputArgs);
            }

            resultsReader = new ResultsReaderJson(stream);
            while ((data = resultsReader.getNextEvent()) != null) {
                splunkData = new SplunkEvent(data);
                if (callback != null) {
                    callback.process(splunkData);
                } else {
                    result.add(splunkData);
                }
            }
            IOHelper.close(stream);
        } else {
            int offset = 0;
            while (offset < total) {
                InputStream stream;
                JobResultsArgs outputArgs = new JobResultsArgs();
                outputArgs.setOutputMode(OutputMode.JSON);
                outputArgs.setCount(getCount());
                outputArgs.setOffset(offset);
                if (realtime) {
                    stream = job.getResultsPreview(outputArgs);
                } else {
                    stream = job.getResults(outputArgs);
                }
                resultsReader = new ResultsReaderJson(stream);
                while ((data = resultsReader.getNextEvent()) != null) {
                    splunkData = new SplunkEvent(data);
                    if (callback != null) {
                        callback.process(splunkData);
                    } else {
                        result.add(splunkData);
                    }
View Full Code Here

    public void testSavedSearch() throws Exception {
        MockEndpoint searchMock = getMockEndpoint("mock:search-saved");
        searchMock.expectedMessageCount(1);

        assertMockEndpointsSatisfied(20, TimeUnit.SECONDS);
        SplunkEvent recieved = searchMock.getReceivedExchanges().get(0).getIn().getBody(SplunkEvent.class);
        assertNotNull(recieved);
        Map<String, String> data = recieved.getEventData();
        assertEquals("value1", data.get("key1"));
        assertEquals("value2", data.get("key2"));
        assertEquals("value3", data.get("key3"));
    }
View Full Code Here

        when(jobMock.isDone()).thenReturn(Boolean.TRUE);
        InputStream stream = ConsumerTest.class.getResourceAsStream("/resultsreader_test_data.json");
        when(jobMock.getResults(any(JobResultsArgs.class))).thenReturn(stream);

        assertMockEndpointsSatisfied();
        SplunkEvent recieved = searchMock.getReceivedExchanges().get(0).getIn().getBody(SplunkEvent.class);
        assertNotNull(recieved);
        Map<String, String> data = recieved.getEventData();
        assertEquals("indexertpool", data.get("name"));
        stream.close();
    }
View Full Code Here

    public void testRealtimeSearch() throws Exception {
        MockEndpoint searchMock = getMockEndpoint("mock:search-saved");
        searchMock.expectedMessageCount(1);

        assertMockEndpointsSatisfied();
        SplunkEvent recieved = searchMock.getReceivedExchanges().get(0).getIn().getBody(SplunkEvent.class);
        assertNotNull(recieved);
        Map<String, String> data = recieved.getEventData();
        assertEquals("value1", data.get("key1"));
        assertEquals("value2", data.get("key2"));
        assertEquals("value3", data.get("key3"));
    }
View Full Code Here

    // should be created in splunk before test run;
    protected static final String INDEX = "junit";

    @Before
    public void init() throws Exception {
        SplunkEvent splunkEvent = new SplunkEvent();
        splunkEvent.addPair("key1", "value1");
        splunkEvent.addPair("key2", "value2");
        splunkEvent.addPair("key3", "value3");
        template.sendBody("direct:submit", splunkEvent);
    }
View Full Code Here

public class SplunkEventTest extends Assert {

    @Test
    public void testEventDataWithQuotedValues() {
        Date now = new Date();
        SplunkEvent event = new SplunkEvent("testevent", "123", false, true);
        event.addPair("key1", "value1");
        event.addPair("key2", "value2 with whitespace");
        event.addPair(SplunkEvent.COMMON_DVC_TIME, now);
        assertEquals("Values should be quoted", "name=\"testevent\" event_id=\"123\" key1=\"value1\" key2=\"value2 with whitespace\" dvc_time=\"" + now.toString() + "\"\n",
                     event.toString());
        assertEquals(5, event.getEventData().size());
        assertTrue(event.getEventData().get("key2").equals("value2 with whitespace"));
    }
View Full Code Here

        String rawString = "2013-10-26    15:16:38:011+0200 name=\"twitter-message\" from_user=\"MyNameIsZack_98\" in_reply_to=\"null\" start_time=\"Sat Oct 26 15:16:21 CEST 2013\" "
                           + "event_id=\"394090123278974976\" text=\"RT @RGIII: Just something about music that it can vibe with your soul\" retweet_count=\"1393\"";
        Map<String, String> eventData = new LinkedHashMap<String, String>();
        eventData.put("_subsecond", ".011");
        eventData.put("_raw", rawString);
        SplunkEvent splunkEvent = new SplunkEvent(eventData);
        assertTrue(splunkEvent.toString().contains("_subsecond=\".011\" _raw=\"" + rawString + "\"\n"));
    }
View Full Code Here

        MockEndpoint searchMock = getMockEndpoint("mock:search-result");
        searchMock.expectedMessageCount(1);
        getMockEndpoint("mock:submit-result").expectedMessageCount(1);

        assertMockEndpointsSatisfied(20, TimeUnit.SECONDS);
        SplunkEvent recieved = searchMock.getReceivedExchanges().get(0).getIn().getBody(SplunkEvent.class);
        assertNotNull(recieved);
        Map<String, String> data = recieved.getEventData();
        assertEquals("value1", data.get("key1"));
        assertEquals("value2", data.get("key2"));
        assertEquals("value3", data.get("key3"));
    }
View Full Code Here

TOP

Related Classes of org.apache.camel.component.splunk.event.SplunkEvent

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.