Search in sources :

Example 11 with SplunkEvent

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

Example 12 with SplunkEvent

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;
}
Also used : Exchange(org.apache.camel.Exchange) SplunkEvent(org.apache.camel.component.splunk.event.SplunkEvent) Message(org.apache.camel.Message) LinkedList(java.util.LinkedList)

Example 13 with SplunkEvent

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;
    }
}
Also used : SplunkEvent(org.apache.camel.component.splunk.event.SplunkEvent) Exchange(org.apache.camel.Exchange) SplunkResultProcessor(org.apache.camel.component.splunk.support.SplunkResultProcessor) Message(org.apache.camel.Message) AsyncCallback(org.apache.camel.AsyncCallback)

Example 14 with SplunkEvent

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;
}
Also used : SavedSearchCollection(com.splunk.SavedSearchCollection) SplunkEvent(org.apache.camel.component.splunk.event.SplunkEvent) ServiceArgs(com.splunk.ServiceArgs) SavedSearch(com.splunk.SavedSearch) Calendar(java.util.Calendar) Service(com.splunk.Service) SavedSearchDispatchArgs(com.splunk.SavedSearchDispatchArgs) Job(com.splunk.Job)

Example 15 with SplunkEvent

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;
}
Also used : SplunkEvent(org.apache.camel.component.splunk.event.SplunkEvent) JobArgs(com.splunk.JobArgs) Calendar(java.util.Calendar)

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