/** * Creates a new empty instance of {@code Args}. * * @return The {@code Args} instance. */ public static Args create() { return new Args(); }
/** * Creates a new {@code Args} instance and initializes it with a single * key-value pair. * * @param key The key name. * @param value The value, as a {@code String:String} or * {@code String:String[]}. * @return The {@code Args} instance. */ public static Args create(String key, Object value) { return new Args(key, value); }
/** * Creates a saved search from a name and search query. * * @param name The name for the search. * @param search The search query. * @return The new saved search. */ public SavedSearch create(String name, String search) { Args args = new Args("search", search); return create(name, args); }
/** * Creates a credential with a username and password. * * @param name The username. * @param password The password. * * @return The new credential. */ public Password create(String name, String password) { Args args = new Args("password", password); return create(name, args); }
/** * Creates a new message. * * @param name The name (primary key) of the new message. * @param value The message text. * @return The new message. */ public Message create(String name, String value) { Args args = new Args("value", value); return create(name, args); } }
/** * Enable distributed search on this Splunk instance. * * Requires restarting Splunk before it takes effect. */ @Override public void enable() { Args args = new Args(); args.put("disabled", "0"); update(args); }
/** * 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)); }
/** * Disable distributed search on this Splunk instance. * * Requires restarting Splunk before it takes effect. */ @Override public void disable() { Args args = new Args(); args.put("disabled", "1"); update(args); }
private Args namespace(AtomEntry entry) { Args namespace = new Args(); // no content? return an empty namespace. if (entry.content == null) return namespace; HashMap<String, String> entityMetadata = (HashMap<String, String>)entry.content.get("eai:acl"); // If there is no ACL info, we just create an empty map if (entityMetadata == null) { entityMetadata = new HashMap<String, String>(); } if (entityMetadata.containsKey("owner")) namespace.put("owner", entityMetadata.get("owner")); if (entityMetadata.containsKey("app")) namespace.put("app", entityMetadata.get("app")); if (entityMetadata.containsKey("sharing")) namespace.put("sharing", entityMetadata.get("sharing")); return namespace; }
/** * 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); }
/** * Creates a credential with a username, password, and realm. * * @param name The username. * @param password The password. * @param realm The credential realm. * @return The new credential. */ public Password create(String name, String password, String realm) { Args args = new Args(); args.put("password", password); args.put("realm", realm); return create(name, args); }
/** * Extracts the namespace components from the specified argument list * (modifying the original list in place) and returns the namespace * components in its own namespace Args. * * @param args An argument list. Will be modified in place. * @return The namespace arguments from the original argument list. */ private static Args extractNamespaceFrom(Args args) { Args namespace = new Args(); for (String componentName : NAMESPACE_COMPONENT_NAMES) { if (args.containsKey(componentName)) { namespace.put(componentName, args.get(componentName).toString()); args.remove(componentName); } } return namespace; }
/** * 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; }
/** * Query Splunk for SPL queries corresponding to this pivot. * * @return a Pivot object encapsulating the returned queries. */ public Pivot pivot() { Service service = this.dataModelObject.getDataModel().getService(); Args args = new Args(); args.put("pivot_json", toJson()); if (this.accelerationNamespace != null) { args.put("namespace", this.accelerationNamespace); } ResponseMessage response = service.get( "datamodel/pivot/" + this.dataModelObject.getDataModel().getName(), args ); if (response.getStatus() != 200) { throw HttpException.create(response); } else { return Pivot.parseStream(service, response.getContent()); } } }