@OnStopped public void onStopped() { if (splunkService != null) { isInitialized.set(false); splunkService.logout(); splunkService = null; } }
protected Service createSplunkService(final ProcessContext context) { final ServiceArgs serviceArgs = new ServiceArgs(); serviceArgs.setScheme(scheme); serviceArgs.setHost(host); serviceArgs.setPort(port); serviceArgs.setApp(app); serviceArgs.setOwner(owner); serviceArgs.setToken(token); serviceArgs.setUsername(username); serviceArgs.setPassword(password); serviceArgs.setSSLSecurityProtocol(SSLSecurityProtocol.valueOf(secProtocol)); return Service.connect(serviceArgs);
final String timeFieldStrategy = context.getProperty(TIME_FIELD_STRATEGY).getValue(); final JobExportArgs exportArgs = new JobExportArgs(); exportArgs.setSearchMode(JobExportArgs.SearchMode.NORMAL); exportArgs.setOutputMode(JobExportArgs.OutputMode.valueOf(outputMode)); exportArgs.setEarliestTime(earliestTime); } else { exportArgs.setIndexEarliest(earliestTime); exportArgs.setLatestTime(latestTime); } else { exportArgs.setIndexLatest(latestTime); export = splunkService.export(query, exportArgs); getLogger().error("Splunk request status code:" + e.getStatus() + " Retrying the request."); splunkService.logout(); splunkService = createSplunkService(context); export = splunkService.export(query, exportArgs);
/** * Called by subclasses to add the fields common to all subclasses to JSON serializations. * * @param root a JsonObject instance representing a serialization of this object. */ protected void addCommonFields(JsonObject root) { root.addProperty("fieldName", this.fieldName); root.addProperty("owner", Util.join(".", this.dataModelObject.getField(fieldName).getOwnerLineage())); root.addProperty("type", this.getType().toString()); } }
/** * Submits an event to this index through an HTTP POST request. * * @param data The event data to post. */ public void submit(String data) { Receiver receiver = service.getReceiver(); receiver.submit(getName(), data); }
/** * Uploads a file to this index as an event stream. * <p> * <b>Note:</b> This file must be directly accessible by the Splunk server. * * @param filename The path and filename. */ public void upload(String filename) { EntityCollection<Upload> uploads = service.getUploads(); Args args = new Args("index", getName()); uploads.create(filename, args); }
/** * Start a job that applies querySuffix to all the events in this data model object. * * @param querySuffix a search query, starting with a '|' that will be appended to the command to fetch * the contents of this data model object (e.g., "| head 3"). * @param args arguments to control the job. * @return a Job object. */ public Job runQuery(String querySuffix, JobArgs args) { return getDataModel().getService().search(getQuery() + querySuffix, args); }
/** * Returns the {@code InputStream} IO handle for the timeline for this job. * * @param args Optional arguments ("output_time_format" and "time_format"). * @return The timeline {@code InputStream} IO handle. */ public InputStream getTimeline(Map args) { checkReady(); ResponseMessage response = service.get(path + "/timeline", args); return response.getContent(); }
/** * Sets this job's priority in the range of 0-10. * * @param value The new priority. */ public void setPriority(int value) { checkReady(); control("setpriority", new Args("priority", value)); }
/** {@inheritDoc} */ public Collection<Object> values() { return getContent().values(); } }
@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); }
/** * {@inheritDoc} */ @Override public Input remove(String key) { Input input = retrieveInput(key); if (input != null) { input.remove(); } return input; }
/** * Removes this entity from its corresponding collection. */ public void remove() { service.delete(actionPath("remove")); }
/** * @return return the lineage, most remote ancestor first, of the data model object his filter's field is * defined on. */ public String[] getOwnerLineage() { return this.dataModelObject.getField(this.fieldName).getOwnerLineage(); }
/** * Indicates whether this entity can be modified. * * @return {@code true} if this entity can be modified, * {@code false} if not. */ public boolean isModifiable() { return getEaiAcl().getBoolean("modifiable", false); } }
/** * Submits an event to this index through an HTTP POST request. * * @param args Optional arguments for this request. Valid parameters are: * "host", "host_regex", "source", and "sourcetype". * @param data The event data to post. */ public void submit(Args args, String data) { Receiver receiver = service.getReceiver(); receiver.submit(getName(), args, data); }