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"));
}
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;
}
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;
}
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"));
}
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);
}
Aggregations