use of org.apache.camel.component.splunk.event.SplunkEvent in project camel by apache.
the class SplunkEventProcessor method process.
@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);
}
use of org.apache.camel.component.splunk.event.SplunkEvent in project camel by apache.
the class SplunkConsumer method createExchanges.
protected Queue<Exchange> createExchanges(List<SplunkEvent> splunkEvents) {
LOG.trace("Received {} messages in this poll", splunkEvents.size());
Queue<Exchange> answer = new LinkedList<Exchange>();
for (SplunkEvent splunkEvent : splunkEvents) {
Exchange exchange = getEndpoint().createExchange();
Message message = exchange.getIn();
message.setBody(splunkEvent);
answer.add(exchange);
}
return answer;
}
use of org.apache.camel.component.splunk.event.SplunkEvent in project camel by apache.
the class SplunkConsumer method poll.
@Override
protected int poll() throws Exception {
try {
if (endpoint.getConfiguration().isStreaming()) {
dataReader.read(new SplunkResultProcessor() {
@Override
public void process(SplunkEvent splunkEvent) {
final Exchange exchange = getEndpoint().createExchange();
Message message = exchange.getIn();
message.setBody(splunkEvent);
try {
LOG.trace("Processing exchange [{}]...", exchange);
getAsyncProcessor().process(exchange, new AsyncCallback() {
@Override
public void done(boolean doneSync) {
LOG.trace("Done processing exchange [{}]...", exchange);
}
});
} catch (Exception e) {
exchange.setException(e);
}
if (exchange.getException() != null) {
getExceptionHandler().handleException("Error processing exchange", exchange, exchange.getException());
}
}
});
// Return 0: no exchanges returned by poll, as exchanges have been returned asynchronously
return 0;
} else {
List<SplunkEvent> events = dataReader.read();
Queue<Exchange> exchanges = createExchanges(events);
return processBatch(CastUtils.cast(exchanges));
}
} catch (Exception e) {
endpoint.reset(e);
getExceptionHandler().handleException(e);
return 0;
}
}
use of org.apache.camel.component.splunk.event.SplunkEvent in project camel by apache.
the class SplunkDataReader method savedSearch.
private List<SplunkEvent> savedSearch(SplunkResultProcessor callback) throws Exception {
LOG.trace("saved search start");
ServiceArgs queryArgs = new ServiceArgs();
queryArgs.setApp("search");
if (ObjectHelper.isNotEmpty(endpoint.getConfiguration().getOwner())) {
queryArgs.setOwner(endpoint.getConfiguration().getOwner());
}
if (ObjectHelper.isNotEmpty(endpoint.getConfiguration().getApp())) {
queryArgs.setApp(endpoint.getConfiguration().getApp());
}
Calendar startTime = Calendar.getInstance();
SavedSearch search = null;
Job job = null;
String latestTime = getLatestTime(startTime, false);
String earliestTime = getEarliestTime(startTime, false);
Service service = endpoint.getService();
SavedSearchCollection savedSearches = service.getSavedSearches(queryArgs);
for (SavedSearch s : savedSearches.values()) {
if (s.getName().equals(getSavedSearch())) {
search = s;
break;
}
}
if (search != null) {
SavedSearchDispatchArgs args = new SavedSearchDispatchArgs();
args.setForceDispatch(true);
args.setDispatchEarliestTime(earliestTime);
args.setDispatchLatestTime(latestTime);
job = search.dispatch(args);
} else {
throw new RuntimeException("Unable to find saved search '" + getSavedSearch() + "'.");
}
while (!job.isDone()) {
Thread.sleep(2000);
}
List<SplunkEvent> data = extractData(job, false, callback);
this.lastSuccessfulReadTime = startTime;
return data;
}
use of org.apache.camel.component.splunk.event.SplunkEvent in project camel by apache.
the class SplunkDataReader method realtimeSearch.
private List<SplunkEvent> realtimeSearch(SplunkResultProcessor callback) throws Exception {
LOG.debug("realtime search start");
JobArgs queryArgs = new JobArgs();
queryArgs.setExecutionMode(ExecutionMode.NORMAL);
queryArgs.setSearchMode(SearchMode.REALTIME);
Calendar startTime = Calendar.getInstance();
populateArgs(queryArgs, startTime, true);
List<SplunkEvent> data = runQuery(queryArgs, true, callback);
lastSuccessfulReadTime = startTime;
return data;
}
Aggregations