/** * Restarts the service. The service will be unavailable until it has * successfully restarted. * * @return The restart response message. */ public ResponseMessage restart() { return post("server/control/restart"); }
/** * {@inheritDoc} */ @Override public void update(Map<String, Object> args) { // Merge cached setters and live args together before updating. HashMap<String, Object> mergedArgs = new HashMap<String, Object>(); mergedArgs.putAll(toUpdate); mergedArgs.putAll(args); service.post(path + "/settings", mergedArgs); toUpdate.clear(); invalidate(); }
/** * {@inheritDoc} */ @Override public void update() { service.post(path + "/settings", toUpdate); invalidate(); } }
/** * Performs rolling hot buckets for this index. */ public void rollHotBuckets() { ResponseMessage response = service.post(path + "/roll-hot-buckets"); assert(response.getStatus() == 200); }
/** * Disables the entity that is named by this endpoint. This method is * available on almost every endpoint. */ public void disable() { service.post(actionPath("disable")); invalidate(); }
/** * Enables the entity that is named by this endpoint. This method is * available on almost every endpoint. */ public void enable() { service.post(actionPath("enable")); invalidate(); }
/** * Acknowledges the suppression of alerts from this saved search * and resumes alerting. */ public void acknowledge() { service.post(actionPath("acknowledge")); invalidate(); }
/** * Updates the entity with the values you previously set using the setter * methods, and any additional specified arguments. The specified arguments * take precedent over the values that were set using the setter methods. * * @param args The arguments to update. */ public void update(Map<String, Object> args) { if (!toUpdate.isEmpty() || !args.isEmpty()) { // Merge cached setters and live args together before updating. Map<String, Object> mergedArgs = new LinkedHashMap<String, Object>(); mergedArgs.putAll(toUpdate); mergedArgs.putAll(args); if (mergedArgs.containsKey("name") && !isNameChangeAllowed()) { throw new IllegalStateException("Cannot set 'name' on an existing entity."); } service.post(actionPath("edit"), mergedArgs); toUpdate.clear(); invalidate(); } }
/** * Creates a oneshot synchronous search using search arguments. * * @param query The search query. * @param args The search arguments:<ul> * <li>"output_mode": Specifies the output format of the results (XML, JSON, * or CSV).</li> * <li>"earliest_time": Specifies the earliest time in the time range to * search. The time string can be a UTC time (with fractional seconds), a * relative time specifier (to now), or a formatted time string.</li> * <li>"latest_time": Specifies the latest time in the time range to search. * The time string can be a UTC time (with fractional seconds), a relative * time specifier (to now), or a formatted time string.</li> * <li>"rf": Specifies one or more fields to add to the search.</li></ul> * @return The search results. */ public InputStream oneshotSearch(String query, Map args) { args = Args.create(args); args.put("search", query); args.put("exec_mode", "oneshot"); // By default, don't highlight search terms in the search output. if (!args.containsKey("segmentation")) { args.put("segmentation", "none"); } ResponseMessage response = post(JobCollection.REST_PATH, args); return response.getContent(); }
/** * Creates a search. * <p> * <b>Note:</b> You can't create a "oneshot" search using this method. * Instead, use the {@link Service#oneshotSearch} method. * * @param query The search query. * @param args Additional arguments for this job (see {@link JobArgs}). * @return The unique search identifier (SID). */ public Job create(String query, Map args) { if (args != null && args.containsKey("exec_mode")) { if (args.get("exec_mode").equals("oneshot")) throw new RuntimeException(oneShotNotAllowed); } args = Args.create(args).add("search", query); ResponseMessage response = service.post(path, args); assert(response.getStatus() == 201); String sid = Xml.parse(response.getContent()) .getElementsByTagName("sid") .item(0) .getTextContent(); Job job = new Job(service, REST_PATH + "/" + sid); job.refresh(); return job; }
/** * Creates an entity in this collection. * * @param name The name of the entity. * @param args Arguments for creating the entity. * @return The entity. */ public T create(String name, Map args) { args = Args.create(args).add("name", name); service.post(path, args); invalidate(); return get(name); }
/** * Creates a new stanza in the current configuration file with attributes. * * @param name The name of the stanza to create. * @param args Optional. A set of attributes as key-value pairs to put in * the new stanza. * @return The name of the new stanza. */ public EntityCollection<Entity> create(String name, Map args) { args = Args.create(args).add("__conf", name); service.post(path, args); invalidate(); return get(name); }
/** * Performs the requested action on this job. Valid values are: "pause", * "unpause", "finalize", "cancel", "touch", "setttl", "setpriority", * "enablepreview", and "disablepreview". * * @param action The action to perform. * @param args Optional arguments for this action ("ttl" and "priority"). * @return The search job. */ public Job control(String action, Map args) { args = Args.create(args).add("action", action); service.post(actionPath("control"), args); invalidate(); return this; }
/** * Authenticates the {@code Service} instance with a specified username and * password. Note that these values override any previously-set values for * username and password. * * @param username The Splunk account username. * @param password The password for the username. * @return The current {@code Service} instance. */ public Service login(String username, String password) { this.username = username; this.password = password; Args args = new Args(); args.put("username", username); args.put("password", password); args.put("cookie", "1"); ResponseMessage response = post("/services/auth/login", args); String sessionKey = Xml.parse(response.getContent()) .getElementsByTagName("sessionKey") .item(0) .getTextContent(); this.token = "Splunk " + sessionKey; this.version = this.getInfo().getVersion(); if (versionCompare("4.3") >= 0) this.passwordEndPoint = "storage/passwords"; return this; }
/** * Runs the saved search using dispatch arguments. * * @param args Dispatch arguments: <ul> * <li>"dispatch.now": A time string that is used to dispatch the search as * though the specified time were the current time.</li> * <li>"dispatch.*": Overwrites the value of the search field specified in * "*".</li> * <li>"trigger_actions": A Boolean that indicates whether to trigger alert * actions.</li> * <li>"force_dispatch": A Boolean that indicates whether to start a new * search if another instance of this search is already running.</li></ul> * @return The search job. */ public Job dispatch(Map args) throws InterruptedException { ResponseMessage response = service.post(actionPath("dispatch"), args); invalidate(); String sid = Job.getSid(response); Job job = service.getJob(sid); // if job not yet scheduled, create an empty job object if (job == null) { job = new Job(service, JobCollection.REST_PATH + "/" + sid); } return job; }
args = Args.create(args).add("name", name); String path = this.path + "/" + kind.getRelativePath(); service.post(path, args);