public class Service extends HttpService
Service
class represents a Splunk service instance at a given
address (host:port), accessed using the http
or https
protocol scheme.
A Service
instance also captures an optional namespace context
consisting of an optional owner name (or "-" wildcard) and optional app name
(or "-" wildcard).
To access Service
members, the Service
instance must be
authenticated by presenting credentials using the login
method, or
by constructing the Service
instance using the connect
method, which both creates and authenticates the instance.
Modifier and Type | Field and Description |
---|---|
protected String |
app
The current app context.
|
static String |
DEFAULT_HOST
The default host name, which is used when a host name is not provided.
|
static int |
DEFAULT_PORT
The default port number, which is used when a port number is not
provided.
|
static String |
DEFAULT_SCHEME
The default scheme, which is used when a scheme is not provided.
|
String |
instanceType
The type of this Splunk instance, once logged in.
|
protected String |
owner
The current owner context.
|
protected String |
password
The password, which is used to authenticate the Splunk instance.
|
protected String |
passwordEndPoint
The default password endpoint, can change over Splunk versions.
|
protected String |
simpleReceiverEndPoint
The default simple receiver endpoint.
|
protected String |
token
The current session token.
|
protected String |
username
The Splunk account username, which is used to authenticate the Splunk
instance.
|
String |
version
The version of this Splunk instance, once logged in.
|
connectTimeout, cookieStore, customHeaders, host, httpsHandler, port, readTimeout, scheme, sslSecurityProtocol, validateCertificates
Constructor and Description |
---|
Service(Map<String,Object> args)
Creates a new
Service instance using a map of arguments. |
Service(ServiceArgs args)
Creates a new
Service instance using a collection of arguments. |
Service(String host)
Creates a new
Service instance using a host. |
Service(String host,
int port)
Creates a new
Service instance using a host and port. |
Service(String host,
int port,
String scheme)
Creates a new
Service instance using a host, port, and
scheme for accessing the service (http or https ). |
Service(String host,
int port,
String scheme,
URLStreamHandler httpsHandler)
Constructs a new
Service instance using the given host,
port, and scheme, and instructing it to use the specified HTTPS handler. |
Modifier and Type | Method and Description |
---|---|
static Service |
connect(Map<String,Object> args)
Establishes a connection to a Splunk service using a map of arguments.
|
boolean |
enableV2SearchApi() |
InputStream |
export(String search)
Runs an export search (using the
search/jobs/export endpoint),
and streams results back in an input stream. |
InputStream |
export(String search,
JobExportArgs args)
Runs an export search with arguments (using the
search/jobs/export
endpoint), and streams results back in an input stream. |
InputStream |
export(String search,
Map args)
Runs an export search with arguments (using the
search/jobs/export
endpoint), and streams results back in an input stream. |
String |
fullpath(String path,
Args namespace)
Ensures that a given path is fully qualified, prepending a path
prefix if necessary.
|
String |
getApp()
Returns the app context for this
Service instance. |
EntityCollection<Application> |
getApplications()
Returns the collection of applications.
|
String[] |
getCapabilities()
Returns an array of system capabilities.
|
ConfCollection |
getConfs()
Returns the collection of configurations.
|
ConfCollection |
getConfs(Args args)
Returns the collection of configurations.
|
DataModelCollection |
getDataModels()
Returns the collection of data models.
|
DeploymentClient |
getDeploymentClient()
Returns the configuration and status of a deployment client.
|
EntityCollection<DeploymentServerClass> |
getDeploymentServerClasses()
Returns a collection of class configurations for a deployment server.
|
EntityCollection<DeploymentServerClass> |
getDeploymentServerClasses(Args args)
Returns a collection of class configurations for a deployment server.
|
EntityCollection<DeploymentServer> |
getDeploymentServers()
Returns the configuration of all deployment servers.
|
EntityCollection<DeploymentServer> |
getDeploymentServers(Args args)
Returns the collection of deployment servers.
|
EntityCollection<DeploymentTenant> |
getDeploymentTenants()
Returns a collection of multi-tenant configurations.
|
EntityCollection<DeploymentTenant> |
getDeploymentTenants(Args args)
Returns a collection of multi-tenant configurations.
|
DistributedConfiguration |
getDistributedConfiguration()
Returns information about distributed search options.
|
EntityCollection<DistributedPeer> |
getDistributedPeers()
Returns a collection of distributed search peers.
|
EntityCollection<DistributedPeer> |
getDistributedPeers(Args args)
Returns a collection of distributed search peers.
|
EventTypeCollection |
getEventTypes()
Returns a collection of saved event types.
|
EventTypeCollection |
getEventTypes(Args args)
Returns a collection of saved event types.
|
FiredAlertGroupCollection |
getFiredAlertGroups()
Returns a collection of alerts that have been fired by the service.
|
FiredAlertGroupCollection |
getFiredAlertsGroups(Args args)
Returns a collection of alerts that have been fired by the service.
|
IndexCollection |
getIndexes()
Returns a collection of Splunk indexes.
|
IndexCollection |
getIndexes(Args args)
Returns a collection of Splunk indexes.
|
IndexCollection |
getIndexes(IndexCollectionArgs args)
Returns a collection of Splunk indexes.
|
ServiceInfo |
getInfo()
Returns information about the Splunk service.
|
InputCollection |
getInputs()
Returns a collection of configured inputs.
|
InputCollection |
getInputs(Args args)
Returns a collection of configured inputs.
|
Job |
getJob(String sid)
Returns a Job by the provided sid.
|
JobCollection |
getJobs()
Returns a collection of current search jobs.
|
JobCollection |
getJobs(Args args)
Returns a collection of current search jobs.
|
JobCollection |
getJobs(CollectionArgs args)
Returns a collection of current search jobs.
|
EntityCollection<LicenseGroup> |
getLicenseGroups()
Returns a collection of license group configurations.
|
EntityCollection<LicenseGroup> |
getLicenseGroups(Args args)
Returns a collection of license group configurations.
|
EntityCollection<LicenseMessage> |
getLicenseMessages()
Returns a collection of messages from the licenser.
|
EntityCollection<LicenseMessage> |
getLicenseMessages(Args args)
Returns a collection of messages from the licenser.
|
LicensePoolCollection |
getLicensePools()
Returns a collection of licenser pool configurations.
|
LicensePoolCollection |
getLicensePools(Args args)
Returns a collection of licenser pool configurations.
|
EntityCollection<License> |
getLicenses()
Returns a collection of licenses for this service.
|
EntityCollection<License> |
getLicenses(Args args)
Returns a collection of licenses for this service.
|
EntityCollection<LicenseSlave> |
getLicenseSlaves()
Returns a collection of slaves reporting to this license master.
|
EntityCollection<LicenseSlave> |
getLicenseSlaves(Args args)
Returns a collection of slaves reporting to this license master.
|
EntityCollection<LicenseStack> |
getLicenseStacks()
Returns a collection of license stack configurations.
|
EntityCollection<LicenseStack> |
getLicenseStacks(Args args)
Returns a collection of license stack configurations.
|
EntityCollection<Logger> |
getLoggers()
Returns a collection of service logging categories and their status.
|
EntityCollection<Logger> |
getLoggers(Args args)
Returns a collection of service logging categories and their status.
|
MessageCollection |
getMessages()
Returns a collection of system messages.
|
MessageCollection |
getMessages(Args args)
Returns a collection of system messages.
|
ResourceCollection<ModularInputKind> |
getModularInputKinds()
Returns a collection of modular inputs.
|
ResourceCollection<ModularInputKind> |
getModularInputKinds(Args args)
Returns a collection of modular inputs.
|
OutputDefault |
getOutputDefault()
Returns global TCP output properties.
|
EntityCollection<OutputGroup> |
getOutputGroups()
Returns a collection of output group configurations.
|
EntityCollection<OutputGroup> |
getOutputGroups(Args args)
Returns a collection of output group configurations.
|
EntityCollection<OutputServer> |
getOutputServers()
Returns a collection of data-forwarding configurations.
|
EntityCollection<OutputServer> |
getOutputServers(Args args)
Returns a collection of data-forwarding configurations.
|
EntityCollection<OutputSyslog> |
getOutputSyslogs()
Returns a collection of configurations for forwarding data in standard
syslog format.
|
EntityCollection<OutputSyslog> |
getOutputSyslogs(Args args)
Returns a collection of configurations for forwarding data in standard
syslog format.
|
String |
getOwner()
Returns the current owner context for this
Service instance. |
String |
getPassword()
Returns the current password that was used to authenticate the session.
|
PasswordCollection |
getPasswords()
Returns a collection of passwords.
|
PasswordCollection |
getPasswords(Args args)
Returns a collection of passwords.
|
Receiver |
getReceiver()
Returns the receiver object for the Splunk service.
|
EntityCollection<Role> |
getRoles()
Returns a collection of Splunk user roles.
|
EntityCollection<Role> |
getRoles(Args args)
Returns a collection of Splunk user roles.
|
SavedSearch |
getSavedSearch(String title)
Returns a Saved Search by the provided title key.
|
SavedSearchCollection |
getSavedSearches()
Returns a collection of saved searches.
|
SavedSearchCollection |
getSavedSearches(Args args)
Returns a collection of saved searches.
|
SavedSearchCollection |
getSavedSearches(SavedSearchCollectionArgs args)
Returns a collection of saved searches.
|
Settings |
getSettings()
Returns service configuration information for an instance of Splunk.
|
String |
getToken()
Returns the current session token.
|
EntityCollection<Upload> |
getUploads()
Returns a collection of in-progress oneshot uploads.
|
EntityCollection<Upload> |
getUploads(Args namespace)
Returns a collection of in-progress oneshot uploads.
|
String |
getUsername()
Returns the Splunk account username that was used to authenticate the
current session.
|
UserCollection |
getUsers()
Returns a collection of Splunk users.
|
UserCollection |
getUsers(Args args)
Returns a collection of Splunk users.
|
Service |
login()
Authenticates the
Service instance with the username and password
that were specified when the instance was created. |
Service |
login(String username,
String password)
Authenticates the
Service instance with a specified username and
password. |
Service |
logout()
Forgets the current session token.
|
InputStream |
oneshotSearch(String query)
Creates a oneshot synchronous search.
|
InputStream |
oneshotSearch(String query,
Args args)
Creates a oneshot synchronous search using search arguments.
|
InputStream |
oneshotSearch(String query,
Map args)
Creates a oneshot synchronous search using search arguments.
|
Socket |
open(int port)
Opens a raw socket to this service.
|
ResponseMessage |
parse(String query)
Parses a search query and returns a semantic map for the search in JSON
format.
|
ResponseMessage |
parse(String query,
Map args)
Parses a search query with additional arguments and returns a semantic
map for the search in JSON format.
|
ResponseMessage |
restart()
Restarts the service.
|
Job |
search(String query)
Creates an asynchronous search using the given query.
|
Job |
search(String query,
Map<String,Object> args)
Creates an asynchronous search job using the given query and
search arguments.
|
ResponseMessage |
send(String path,
RequestMessage request)
Issues an HTTP request against the service using a request path and
message.
|
void |
setBearerToken(String value)
Provides a session token having Bearer added before token.
|
void |
setSplunkToken(String value)
Provides a session token having Splunk added before token.
|
void |
setToken(String value)
Provides a session token for use by this
Service instance. |
int |
versionCompare(String otherVersion)
Returns a value indicating how the version of this Splunk instance
compares to a given version:
-1 if this version < the given version
0 if this version = the given version
1 if this version > the given version
|
addCookie, createSSLFactory, delete, delete, get, get, getConnectTimeout, getCustomHeaders, getHost, getPort, getPrefix, getReadTimeout, getScheme, getSslSecurityProtocol, getSSLSocketFactory, getUrl, hasSplunkAuthCookies, post, post, removeAllCookies, setConnectTimeout, setCustomHeaders, setReadTimeout, setSslSecurityProtocol, setSSLSocketFactory, setValidateCertificates, stringifyCookies
protected String app
protected String token
protected String owner
protected String username
protected String password
protected String simpleReceiverEndPoint
protected String passwordEndPoint
public String version
public String instanceType
public static String DEFAULT_HOST
public static int DEFAULT_PORT
public static String DEFAULT_SCHEME
public Service(String host)
Service
instance using a host.host
- The host name.public Service(String host, int port)
Service
instance using a host and port.host
- The host name.port
- The port number.public Service(String host, int port, String scheme)
Service
instance using a host, port, and
scheme for accessing the service (http
or https
).host
- The host name.port
- The port number.scheme
- The scheme (http
or https
).public Service(String host, int port, String scheme, URLStreamHandler httpsHandler)
Service
instance using the given host,
port, and scheme, and instructing it to use the specified HTTPS handler.host
- The host name of the service.port
- The port number of the service.scheme
- Scheme for accessing the service (http
or
https
).httpsHandler
- The URLStreamHandler instancepublic Service(ServiceArgs args)
Service
instance using a collection of arguments.args
- The ServiceArgs
to initialize the service.public static Service connect(Map<String,Object> args)
Service
instance and authenticates
the session using credentials passed in from the args
map.args
- The args
map.Service
instance.public InputStream export(String search)
search/jobs/export
endpoint),
and streams results back in an input stream.search
- The search query to run.InputStream
object that contains the search results.public InputStream export(String search, Map args)
search/jobs/export
endpoint), and streams results back in an input stream.search
- The search query to run.args
- Additional search arguments.
For a list of possible parameters, see
Saved search parameters on
dev.splunk.com.InputStream
object that contains the search results.public InputStream export(String search, JobExportArgs args)
search/jobs/export
endpoint), and streams results back in an input stream.search
- The search query to run.args
- Additional search arguments (see JobExportArgs
).InputStream
object that contains the search results.public String fullpath(String path, Args namespace)
path
- The path to verify.namespace
- The namespace dictionary (app, owner, sharing).public String getApp()
Service
instance.
A null
value indicates no app context, and a value of
"-"
indicates an app wildcard.public EntityCollection<Application> getApplications()
public ConfCollection getConfs()
public ConfCollection getConfs(Args args)
args
- Collection arguments that specify the number of entities to
return and how to sort them. See CollectionArgs
.public String[] getCapabilities()
public DataModelCollection getDataModels()
public DeploymentClient getDeploymentClient()
public EntityCollection<DeploymentServer> getDeploymentServers()
public EntityCollection<DeploymentServer> getDeploymentServers(Args args)
args
- Collection arguments that specify the number of entities to
return and how to sort them. See CollectionArgs
.public EntityCollection<DeploymentServerClass> getDeploymentServerClasses()
public EntityCollection<DeploymentServerClass> getDeploymentServerClasses(Args args)
args
- Collection arguments that specify the number of entities to
return and how to sort them. See CollectionArgs
.public EntityCollection<DeploymentTenant> getDeploymentTenants()
public EntityCollection<DeploymentTenant> getDeploymentTenants(Args args)
args
- Collection arguments that specify the number of entities to
return and how to sort them. See CollectionArgs
.public DistributedConfiguration getDistributedConfiguration()
public EntityCollection<DistributedPeer> getDistributedPeers()
public EntityCollection<DistributedPeer> getDistributedPeers(Args args)
args
- Collection arguments that specify the number of entities to
return and how to sort them. See CollectionArgs
.public EventTypeCollection getEventTypes()
public EventTypeCollection getEventTypes(Args args)
args
- Collection arguments that specify the number of entities to
return and how to sort them. See CollectionArgs
.public FiredAlertGroupCollection getFiredAlertGroups()
public FiredAlertGroupCollection getFiredAlertsGroups(Args args)
args
- Collection arguments that specify the number of entities to
return and how to sort them. See CollectionArgs
.public IndexCollection getIndexes()
public IndexCollection getIndexes(IndexCollectionArgs args)
args
- Collection arguments that specify the number of entities to
return and how to sort them. See IndexCollectionArgs
.public IndexCollection getIndexes(Args args)
args
- Collection arguments that specify the number of entities to
return and how to sort them. See IndexCollectionArgs
.public ServiceInfo getInfo()
public InputCollection getInputs()
public InputCollection getInputs(Args args)
args
- Collection arguments that specify the number of entities to
return and how to sort them. See CollectionArgs
.public JobCollection getJobs()
public JobCollection getJobs(CollectionArgs args)
args
- Collection arguments that specify the number of entities to
return and how to sort them. See CollectionArgs
.public JobCollection getJobs(Args args)
args
- Collection arguments that specify the number of entities to
return and how to sort them. See CollectionArgs
.public Job getJob(String sid)
sid
- The sid for a job.public EntityCollection<LicenseGroup> getLicenseGroups()
public EntityCollection<LicenseGroup> getLicenseGroups(Args args)
args
- Collection arguments that specify the number of entities to
return and how to sort them. See CollectionArgs
.public EntityCollection<LicenseMessage> getLicenseMessages()
public EntityCollection<LicenseMessage> getLicenseMessages(Args args)
args
- Collection arguments that specify the number of entities to
return and how to sort them. See CollectionArgs
.public String getOwner()
Service
instance.
A value of "-"
indicates a wildcard, and a null
value
indicates no owner context.public LicensePoolCollection getLicensePools()
public LicensePoolCollection getLicensePools(Args args)
args
- Collection arguments that specify the number of entities to
return and how to sort them. See CollectionArgs
.public EntityCollection<LicenseSlave> getLicenseSlaves()
public EntityCollection<LicenseSlave> getLicenseSlaves(Args args)
args
- Collection arguments that specify the number of entities to
return and how to sort them. See CollectionArgs
.public EntityCollection<LicenseStack> getLicenseStacks()
public EntityCollection<LicenseStack> getLicenseStacks(Args args)
args
- Collection arguments that specify the number of entities to
return and how to sort them. See CollectionArgs
.public EntityCollection<License> getLicenses()
public EntityCollection<License> getLicenses(Args args)
args
- Collection arguments that specify the number of entities to
return and how to sort them. See CollectionArgs
.public EntityCollection<Logger> getLoggers()
public EntityCollection<Logger> getLoggers(Args args)
args
- Collection arguments that specify the number of entities to
return and how to sort them. See CollectionArgs
.public MessageCollection getMessages()
public MessageCollection getMessages(Args args)
args
- Collection arguments that specify the number of entities to
return and how to sort them. See CollectionArgs
.public ResourceCollection<ModularInputKind> getModularInputKinds()
public ResourceCollection<ModularInputKind> getModularInputKinds(Args args)
args
- Collection arguments that specify the number of entities to
return and how to sort them. See CollectionArgs
.public OutputDefault getOutputDefault()
public EntityCollection<OutputGroup> getOutputGroups()
public EntityCollection<OutputGroup> getOutputGroups(Args args)
args
- Collection arguments that specify the number of entities to
return and how to sort them. See CollectionArgs
.public EntityCollection<OutputServer> getOutputServers()
public EntityCollection<OutputServer> getOutputServers(Args args)
args
- Collection arguments that specify the number of entities to
return and how to sort them. See CollectionArgs
.public EntityCollection<OutputSyslog> getOutputSyslogs()
public EntityCollection<OutputSyslog> getOutputSyslogs(Args args)
args
- Collection arguments that specify the number of entities to
return and how to sort them. See CollectionArgs
.public String getPassword()
public PasswordCollection getPasswords()
public PasswordCollection getPasswords(Args args)
args
- Collection arguments that specify the number of entities to
return and how to sort them. See CollectionArgs
.public Receiver getReceiver()
public EntityCollection<Role> getRoles()
public EntityCollection<Role> getRoles(Args args)
args
- Collection arguments that specify the number of entities to
return and how to sort them. See CollectionArgs
.public SavedSearchCollection getSavedSearches()
public SavedSearchCollection getSavedSearches(SavedSearchCollectionArgs args)
args
- Collection arguments that specify the number of entities to
return and how to sort them. See SavedSearchCollectionArgs
.public SavedSearchCollection getSavedSearches(Args args)
args
- Collection arguments that specify the number of entities to
return and how to sort them. See CollectionArgs
.public SavedSearch getSavedSearch(String title)
title
- The title for a job.public Settings getSettings()
public String getToken()
Service
instances.public EntityCollection<Upload> getUploads()
public EntityCollection<Upload> getUploads(Args namespace)
namespace
- This collection's namespace; there are no other
optional arguments for this endpoint.public String getUsername()
public UserCollection getUsers()
public UserCollection getUsers(Args args)
args
- Collection arguments that specify the number of entities to
return and how to sort them. See CollectionArgs
.public Service login()
Service
instance with the username and password
that were specified when the instance was created.
Three cases:
1. If we have a cookie, but are missing username and/or password, login is noop
2. If we don't have a cookie, and are missing username and/or password we can't login
3. Otherwise login as usualService
instance.public Service login(String username, String password)
Service
instance with a specified username and
password. Note that these values override any previously-set values for
username and password.username
- The Splunk account username.password
- The password for the username.Service
instance.public Service logout()
Service
instance.public InputStream oneshotSearch(String query)
query
- The search query.public InputStream oneshotSearch(String query, Map args)
query
- The search query.args
- The search arguments:public InputStream oneshotSearch(String query, Args args)
query
- The search query.args
- The search arguments:public Socket open(int port) throws IOException
port
- The port to open. This port must already have been
created as an allowable TCP input to the service.IOException
- The IOException instancepublic ResponseMessage parse(String query)
query
- The search query.public ResponseMessage parse(String query, Map args)
query
- The search query.args
- Additional parse arguments.public ResponseMessage restart()
public Job search(String query)
query
- The search query.public Job search(String query, Map<String,Object> args)
query
- The search query.args
- The search arguments.public ResponseMessage send(String path, RequestMessage request)
HttpService.send
method
and applies the Splunk authorization header, which is required for
authenticated interactions with the Splunk service.send
in class HttpService
path
- The request path.request
- The request message.public void setToken(String value)
Service
instance.
Session tokens can be shared across multiple Service
instances.value
- The session token, which is a basic authorization header in
the format "Basic sessiontoken", where sessiontoken is the
Base64-encoded "username:password" string.public void setSplunkToken(String value)
value
- The token valuepublic void setBearerToken(String value)
value
- The token valuepublic boolean enableV2SearchApi()
public int versionCompare(String otherVersion)
-1 if this version < the given version
0 if this version = the given version
1 if this version > the given version
otherVersion
- The other version to compare to.Copyright © 2022 Splunk, Inc.. All rights reserved.