Search in sources :

Example 1 with Service

use of com.splunk.Service in project camel by apache.

the class SplunkDataReader method runQuery.

private List<SplunkEvent> runQuery(JobArgs queryArgs, boolean realtime, SplunkResultProcessor callback) throws Exception {
    Service service = endpoint.getService();
    Job job = service.getJobs().create(getSearch(), queryArgs);
    LOG.debug("Running search : {} with queryArgs : {}", getSearch(), queryArgs);
    if (realtime) {
        while (!job.isReady()) {
            Thread.sleep(500);
        }
        // Besides job.isReady there must be some delay before real time job
        // is ready
        // TODO seems that the realtime stream is not quite isReady to be
        // read
        Thread.sleep(4000);
    } else {
        while (!job.isDone()) {
            Thread.sleep(500);
        }
    }
    return extractData(job, realtime, callback);
}
Also used : Service(com.splunk.Service) Job(com.splunk.Job)

Example 2 with Service

use of com.splunk.Service in project camel by apache.

the class SplunkConnectionFactory method createService.

public synchronized Service createService(CamelContext camelContext) {
    final ServiceArgs args = new ServiceArgs();
    if (host != null) {
        args.setHost(host);
    }
    if (port > 0) {
        args.setPort(port);
    }
    if (scheme != null) {
        args.setScheme(scheme);
    }
    if (app != null) {
        args.setApp(app);
    }
    if (owner != null) {
        args.setOwner(owner);
    }
    args.setUsername(username);
    args.setPassword(password);
    // (wls i'm looking at you)
    if (isUseSunHttpsHandler()) {
        String sunHandlerClassName = "sun.net.www.protocol.https.Handler";
        Class<URLStreamHandler> clazz = camelContext.getClassResolver().resolveClass(sunHandlerClassName, URLStreamHandler.class);
        if (clazz != null) {
            URLStreamHandler handler = camelContext.getInjector().newInstance(clazz);
            args.setHTTPSHandler(handler);
            LOG.debug("using the URLStreamHandler {} for {}", handler, args);
        } else {
            LOG.warn("could not resolve and use the URLStreamHandler class '{}'", sunHandlerClassName);
        }
    }
    ExecutorService executor = camelContext.getExecutorServiceManager().newSingleThreadExecutor(this, "DefaultSplunkConnectionFactory");
    Future<Service> future = executor.submit(new Callable<Service>() {

        public Service call() throws Exception {
            if (Service.DEFAULT_SCHEME.equals(getScheme())) {
                LOG.debug("Https in use. Setting SSL protocol to {}", getSslProtocol());
                HttpService.setSslSecurityProtocol(getSslProtocol());
            }
            return Service.connect(args);
        }
    });
    try {
        Service service = null;
        if (connectionTimeout > 0) {
            service = future.get(connectionTimeout, TimeUnit.MILLISECONDS);
        } else {
            service = future.get();
        }
        LOG.info("Successfully connected to Splunk");
        return service;
    } catch (Exception e) {
        throw new RuntimeException(String.format("could not connect to Splunk Server @ %s:%d - %s", host, port, e.getMessage()));
    } finally {
        if (executor != null) {
            camelContext.getExecutorServiceManager().shutdownNow(executor);
        }
    }
}
Also used : URLStreamHandler(java.net.URLStreamHandler) ServiceArgs(com.splunk.ServiceArgs) ExecutorService(java.util.concurrent.ExecutorService) Service(com.splunk.Service) HttpService(com.splunk.HttpService) ExecutorService(java.util.concurrent.ExecutorService)

Example 3 with Service

use of com.splunk.Service 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)

Aggregations

Service (com.splunk.Service)3 Job (com.splunk.Job)2 ServiceArgs (com.splunk.ServiceArgs)2 HttpService (com.splunk.HttpService)1 SavedSearch (com.splunk.SavedSearch)1 SavedSearchCollection (com.splunk.SavedSearchCollection)1 SavedSearchDispatchArgs (com.splunk.SavedSearchDispatchArgs)1 URLStreamHandler (java.net.URLStreamHandler)1 Calendar (java.util.Calendar)1 ExecutorService (java.util.concurrent.ExecutorService)1 SplunkEvent (org.apache.camel.component.splunk.event.SplunkEvent)1