return Service.connect(serviceArgs);
@Override public Statement apply(Statement base, Description description) { try { SplunkServer splunkServer = new SplunkServer(); splunkServer.setPassword("admin"); splunkServer.setUsername("admin"); SplunkServiceFactory splunkServiceFactory = new SplunkServiceFactory(splunkServer); splunkServiceFactory.getService().open(this.port); System.setProperty("splunk.port", "" + this.port); } catch (Exception e) { logger.warn( "Not executing tests because basic connectivity test failed"); Assume.assumeNoException(e); } return super.apply(base, description); }
/** * Runs an export search (using the {@code search/jobs/export} endpoint), * and streams results back in an input stream. * * @param search The search query to run. * @return The {@code InputStream} object that contains the search results. */ public InputStream export(String search) { return export(search, null); }
Socket socket = service.open(); OutputStream ostream = socket.getOutputStream(); Writer out = new OutputStreamWriter(ostream, "UTF-8"); "X-Splunk-Input-Mode: Streaming\r\n", postUrl, service.getHost(), service.getPort() )); if (service.hasCookies()) { header.append("Cookie: "); header.append(service.stringifyCookies()); } else { header.append("Authorization: "); header.append(service.getToken());
@OnStopped public void onStopped() { if (splunkService != null) { isInitialized.set(false); splunkService.logout(); splunkService = null; } }
/** * Returns a collection of configured inputs. * * @return A collection of inputs. */ public InputCollection getInputs() { return getInputs(null); }
@Override public boolean isConnected() { if(service.getToken() == null) return false; else return true; } }
/** * Establishes a connection to a Splunk service using a map of arguments. * This member creates a new {@code Service} instance and authenticates * the session using credentials passed in from the {@code args} map. * * @param args The {@code args} map. * @return A new {@code Service} instance. */ public static Service connect(Map<String, Object> args) { Service service = new Service(args); if (args.containsKey("username")) { service.login(); } return service; }
/** * Runs an export search with arguments (using the {@code search/jobs/export} * endpoint), and streams results back in an input stream. * * @param search The search query to run. * @param args Additional search arguments (see {@code JobExportArgs}). * @return The {@code InputStream} object that contains the search results. */ // NOTE: This overload exists primarily to provide better documentation // for the "args" parameter. public InputStream export(String search, JobExportArgs args) { return export(search, (Map<String, Object>) args); }
/** * Close connection. */ @Override public void disconnect() { try { service.logout(); } catch (Exception e) { throw new RuntimeException("closing connection", e); } }
@Override public void setup(OperatorContext context) { super.setup(context); tcpInput = (TcpInput) store.getService().getInputs().get(tcpPort); try { socket = tcpInput.attach(); stream = new DataOutputStream(socket.getOutputStream()); } catch (IOException e) { throw new RuntimeException(e); } }
@Override public boolean isConnected() { if (service.getToken() == null) { return false; } else { return true; } } }
InputStream inputStream = service.export("search sourcetype=\"" + sourceType + "\" " + ThunderConstant.TRACE_ID + "=\"" + traceId + "\"", exportArgs); if (inputStream == null) { throw new MonitorException("Input stream is null");
/** * Create connection with the splunk server. */ @Override public void connect() { try { ServiceArgs loginArgs = new ServiceArgs(); loginArgs.setUsername(userName); loginArgs.setPassword(password); loginArgs.setHost(host); loginArgs.setPort(port); service = Service.connect(loginArgs); } catch (Exception e) { throw new RuntimeException("closing connection", e); } }
/** * Close connection. */ @Override public void disconnect() { try{ service.logout(); } catch(Exception e){ throw new RuntimeException("closing connection", e); } }
@Override public void setup(OperatorContext context) { super.setup(context); tcpInput = (TcpInput)store.getService().getInputs().get(tcpPort); try { socket = tcpInput.attach(); stream = new DataOutputStream(socket.getOutputStream()); } catch (IOException e) { throw new RuntimeException(e); } }
/** * This executes the search query to retrieve result from splunk. * It then converts each event's value into tuple and emit that into output port. */ @Override public void emitTuples() { String query = queryToRetrieveData(); logger.debug(String.format("select statement: %s", query)); try { exportSearch = store.getService().export(queryToRetrieveData(), exportArgs); multiResultsReader = new MultiResultsReaderXml(exportSearch); for (SearchResults searchResults : multiResultsReader) { for (Event event : searchResults) { for (String key: event.keySet()) { if (key.contains("raw")) { T tuple = getTuple(event.get(key)); outputPort.emit(tuple); } } } } multiResultsReader.close(); } catch (Exception e) { store.disconnect(); throw new RuntimeException(String.format("Error while running query: %s", query), e); } } }
/** * Create connection with the splunk server. */ @Override public void connect() { try{ ServiceArgs loginArgs = new ServiceArgs(); loginArgs.setUsername(userName); loginArgs.setPassword(password); loginArgs.setHost(host); loginArgs.setPort(port); service = Service.connect(loginArgs); } catch(Exception e){ throw new RuntimeException("closing connection", e); } }
exportSearch = store.getService().export(queryToRetrieveData(), exportArgs); multiResultsReader = new MultiResultsReaderXml(exportSearch); for (SearchResults searchResults : multiResultsReader)