/** * Returns a collection of license group configurations. * * @param args Collection arguments that specify the number of entities to * return and how to sort them. See {@link CollectionArgs}. * @return A collection of license group configurations. */ public EntityCollection<LicenseGroup> getLicenseGroups(Args args) { return new EntityCollection<LicenseGroup>( this, "licenser/groups", LicenseGroup.class, args); }
/** * Creates an entity in this collection. * * @param name The name of the entity. * @return The entity. */ public T create(String name) { return create(name, (Map)null); }
/** * Get a credential with realm and name. * * @param realm The credential realm. * @param name The username. * @return The credential, or null if not found. */ public Password get(String realm, String name) { return super.get(String.format("%s:%s:", realm, name)); }
/** * Removes an entity from this collection. * * @param key The name of the entity to remove. * @return The collection. * @throws SplunkException The exception "AMBIGUOUS" if the collection * contains more than one entity with the specified key. Disambiguation is * done through a similar method, * {@code remove(Object key, HashMap<String,String>namespace}, which uses * the namespace to perform the disambiguation. */ public T remove(String key) { validate(); if (!containsKey(key)) return null; LinkedList<T> entities = items.get(key); if (entities != null && entities.size() > 1) { throw new SplunkException(SplunkException.AMBIGUOUS, "Key has multiple values, specify a namespace"); } if (entities == null) return null; T entity = entities.get(0); entity.remove(); // by invalidating any access to items will get refreshed invalidate(); return entity; }
/** * 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); }
/** * Remove a credential with realm and name. * * @param realm The credential realm. * @param name The username. * @return The removed credential, or null if not found. */ public Password remove(String realm, String name) { return super.remove(String.format("%s:%s:", realm, name)); }
@Override public boolean containsKey(Object key) { if (key instanceof String && !((String) key).contains(":")) { return getByUsername((String) key) != null; } return super.containsKey(key); }
/** * Removes an entity from this collection, with a namespace restriction. * * @param key The name of the entity to remove. * @param namespace The namespace restriction within the collection. * @return This collection. */ public T remove(String key, Args namespace) { Util.ensureNamespaceIsExact(namespace); validate(); if (!containsKey(key)) return null; LinkedList<T> entities = items.get(key); String pathMatcher = service.fullpath("", namespace); if (entities == null || entities.size() == 0) return null; for (T entity: entities) { if (entity.path.startsWith(pathMatcher)) { entity.remove(); // By invalidating, any access to items will get refreshed invalidate(); return entity; } } return null; } }
/** * {@inheritDoc} */ public Index remove(String key) { if (this.service.versionCompare("5.0") < 0) { throw new UnsupportedOperationException( "Indexes cannot be deleted via the REST API in versions " + "prior to 5.0"); } else { return (Index)super.remove(key); } } }
/** * Returns a collection of slaves reporting to this license master. * * @param args Collection arguments that specify the number of entities to * return and how to sort them. See {@link CollectionArgs}. * @return A collection of licenser slaves. */ public EntityCollection<LicenseSlave> getLicenseSlaves(Args args) { return new EntityCollection<LicenseSlave>( this, "licenser/slaves", LicenseSlave.class, args); }
/** * Creates an entity in this collection. * * @param name The name of the entity. * @param args Arguments for creating the entity. * @return The entity. */ @Override public DataModel create(String name, Map args) { Args revisedArgs = Args.create(args); // concise=0 forces the server to return all details of the newly // created data model. if (!args.containsKey("concise")) { revisedArgs = revisedArgs.add("concise", "0"); } return super.create(name, revisedArgs); } }
@Override public Password remove(String key) { // Make it compatible with the old way (low-efficient) if (!key.contains(":")) { Password password = getByUsername((String) key); validate(); if (password == null) return null; password.remove(); // by invalidating any access to items will get refreshed invalidate(); return password; } return super.remove(key); }
@Override public Password get(Object key) { // Make it compatible with the old way (low-efficient) if (key instanceof String && !((String) key).contains(":")) { return getByUsername((String) key); } return super.get(key); }
/** * Returns a collection of service logging categories and their status. * * @param args Collection arguments that specify the number of entities to * return and how to sort them. See {@link CollectionArgs}. * @return A collection of logging categories. */ public EntityCollection<Logger> getLoggers(Args args) { return new EntityCollection<Logger>( this, "server/logger", Logger.class, args); }
/** * 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); }
/** * Returns a collection of in-progress oneshot uploads. * * @param namespace This collection's namespace; there are no other * optional arguments for this endpoint. * @return A collection of in-progress oneshot uploads */ public EntityCollection<Upload> getUploads(Args namespace) { return new EntityCollection<Upload>( this, "data/inputs/oneshot", Upload.class, 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. * * @param args Optional arguments for this request. Valid parameters are: * "host", "sourcetype", "rename-source". More found at: * http://docs.splunk.com/Documentation/Splunk/latest/RESTAPI/RESTinput#data.2Finputs.2Foneshot * */ public void upload(String filename, Args args) { EntityCollection<Upload> uploads = service.getUploads(); if(args.containsKey("index")){ throw new IllegalArgumentException("The 'index' parameter cannot be passed to an index's oneshot upload."); } args.add("index", getName()); uploads.create(filename, args); } }
/** * Returns a group of fired alerts for a given saved search. * * @return The fired alerts in the group. */ public EntityCollection<FiredAlert> getAlerts() { return new EntityCollection<FiredAlert>( service, this.path, FiredAlert.class); } }
/** * Returns the collection of applications. * * @return The application collection. */ public EntityCollection<Application> getApplications() { return new EntityCollection<Application>( this, "/services/apps/local", Application.class); }
/** * Returns a collection of Splunk user roles. * * @param args Collection arguments that specify the number of entities to * return and how to sort them. See {@link CollectionArgs}. * @return A collection of user roles. */ public EntityCollection<Role> getRoles(Args args) { return new EntityCollection<Role>( this, "authorization/roles", Role.class, args); }