Search in sources :

Example 6 with SplunkEvent

use of org.apache.camel.component.splunk.event.SplunkEvent in project camel by apache.

the class SplunkEventTest method testEventDataFromMap.

@Test
public void testEventDataFromMap() {
    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"));
}
Also used : SplunkEvent(org.apache.camel.component.splunk.event.SplunkEvent) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 7 with SplunkEvent

use of org.apache.camel.component.splunk.event.SplunkEvent in project camel by apache.

the class SplunkDataReader method nonBlockingSearch.

private List<SplunkEvent> nonBlockingSearch(SplunkResultProcessor callback) throws Exception {
    LOG.debug("non block search start");
    JobArgs queryArgs = new JobArgs();
    queryArgs.setExecutionMode(ExecutionMode.NORMAL);
    Calendar startTime = Calendar.getInstance();
    populateArgs(queryArgs, startTime, false);
    List<SplunkEvent> data = runQuery(queryArgs, false, callback);
    lastSuccessfulReadTime = startTime;
    return data;
}
Also used : SplunkEvent(org.apache.camel.component.splunk.event.SplunkEvent) JobArgs(com.splunk.JobArgs) Calendar(java.util.Calendar)

Example 8 with SplunkEvent

use of org.apache.camel.component.splunk.event.SplunkEvent in project camel by apache.

the class SplunkDataReader method extractData.

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);
                }
            }
            offset += getCount();
            IOHelper.close(stream);
        }
    }
    if (resultsReader != null) {
        resultsReader.close();
    }
    job.cancel();
    return result;
}
Also used : SplunkEvent(org.apache.camel.component.splunk.event.SplunkEvent) ResultsReader(com.splunk.ResultsReader) JobResultsArgs(com.splunk.JobResultsArgs) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) SplunkEndpoint(org.apache.camel.component.splunk.SplunkEndpoint) ResultsReaderJson(com.splunk.ResultsReaderJson)

Example 9 with SplunkEvent

use of org.apache.camel.component.splunk.event.SplunkEvent in project camel by apache.

the class RealtimeSearchTest method testRealtimeSearch.

@Test
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"));
}
Also used : SplunkEvent(org.apache.camel.component.splunk.event.SplunkEvent) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Test(org.junit.Test)

Example 10 with SplunkEvent

use of org.apache.camel.component.splunk.event.SplunkEvent in project camel by apache.

the class SplunkTest method init.

@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);
}
Also used : SplunkEvent(org.apache.camel.component.splunk.event.SplunkEvent) Before(org.junit.Before)

Aggregations

SplunkEvent (org.apache.camel.component.splunk.event.SplunkEvent)21 Test (org.junit.Test)13 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)11 JobArgs (com.splunk.JobArgs)4 Job (com.splunk.Job)3 JobResultsArgs (com.splunk.JobResultsArgs)3 InputStream (java.io.InputStream)3 Calendar (java.util.Calendar)3 Producer (org.apache.camel.Producer)3 JobCollection (com.splunk.JobCollection)2 Exchange (org.apache.camel.Exchange)2 Message (org.apache.camel.Message)2 Matchers.anyString (org.mockito.Matchers.anyString)2 ResultsReader (com.splunk.ResultsReader)1 ResultsReaderJson (com.splunk.ResultsReaderJson)1 SavedSearch (com.splunk.SavedSearch)1 SavedSearchCollection (com.splunk.SavedSearchCollection)1 SavedSearchDispatchArgs (com.splunk.SavedSearchDispatchArgs)1 Service (com.splunk.Service)1 ServiceArgs (com.splunk.ServiceArgs)1