Splunk CLI Useful Commands Cheatsheet
Splunk CLI Useful Commands Cheatsheet
On the master license server, list the licenses splunk list licenses
On a search head, add a distributed search peer splunk add search-server peer:port \
-remoteUsername user -remotePassword pass
Move search jobs from dispatch directory based splunk cmd splunkd clean-dispatch
on the last modification time of the job; dest_directory mod_time
Example:
mod_time is a relative time in SPL format splunk cmd splunkd clean-dispatch /tmp/jobs/ -7d@d
Show the automatic sourcetype that Splunk will splunk test sourcetype file_to_test
assign to this input
Remove an installed app from this server splunk remove app appfolder
Create a new (empty) app, where the template splunk create app appname \
can be barebones or sample_app –template template_name
Forward inputs to the indexer (idx) that is splunk add forward-server idx:rport
listening on port rport (run on forwarder)
On any non-clustered instance, set the instance splunk set deploy-poll dserver:port
to use the deployment server (dserver)
Multisite
Make this instance a cluster master of a splunk edit cluster-config \
multisite cluster -mode master -multisite true \
-site site1 \
-available_sites site1,site2 \
-site_replication_factor origin:1,total:2
\
-site_search_factor origin:1,total:2 \
-secret mycluster
Make this indexer a cluster peer in a multisite splunk edit cluster-config \
cluster -master_uri https://master:port \
-mode slave -site site1 \
-replication_port port -secret mycluster
Stop this peer gracefully. With enforced counts, splunk offline [--enforce-counts]
takes peer offline permanently, otherwise peer
must restart within 60 seconds.
Assign a label to all the search heads and peers splunk edit cluster-config \
that are part of this cluster (run on master) -cluster_label label_name
Undo the last cluster bundle and return to splunk rollback cluster-bundle
previous state (run on master)
Remove offline peers entirely from the cluster splunk remove cluster-peers \
(run on master) -peers guid1,guid2
Set the detention status of a peer. Options are splunk edit cluster-config \
on: disables indexing & incoming replication
-manual_detention option
on_ports_enabled: disables incoming
replication
off
For indexer discovery, set the site fail-over (site1 splunk edit cluster-config \
-forwarder_site_failover site1:site2
to site2 in the example)
Manually assign a captain and set a member list splunk bootstrap shcluster-captain \
–servers_list https://SH2:port, \
(run on the new captain) https://SH3:port,https://SH4:port
./splunk start
To make cut-and-paste work better with this document, the Linux line-continuation character “\” has been added at the
end of each line; do not include this character when manually typing the command on a single line!
REST ENDPOINTS
You can use REST endpoints instead of many CLI commands. The purpose of this section is to capture some of the
REST endpoints for which no CLI equivalent exists. Documentation for all endpoints can be found in the Splunk REST
API Reference Manual. [http://docs.splunk.com/Documentation/Splunk/latest/RESTREF]
Endpoints can be accessed via the REST API directly using tools such as curl, or by putting the endpoint into a
browser, like this
https://<host>:<mPort>/services/endpoint
where host is the Splunk host and mPort is the splunkd port (aka management port). Note that you must use https to
access the splunkd port. You will typically need to authenticate with an admin account and password to proceed.
In addition to accessing the REST API directly, you may choose to download a SDK and use a higher-level library in
your code. See http://dev.splunk.com for more details about the REST API and the SDKs, including tutorials and user
guides.
Finally, the REST endpoints can be accessed in Splunk searches using the rest command, as follows
| rest /services/endpoint
For example:
| rest /services/cluster/master/peers
Function Endpoint
Indexer Cluster
Initiate primary rebalancing manually for an cluster/master/control/control/rebalance_primaries
indexer cluster
View the number of primaries on a peer and cluster/master/peers
other settings
Adjust cluster peer detention mode cluster/slave/control/control/set_detention_override
Give information about a specific bucket cluster/master/buckets/bucketid
(bucketid) including whether primary or not,
site, etc.
Re-add the cluster peer (indexer) to the cluster cluster/slave/control/control/re-add-peer
master
Top level endpoint for master to slave cluster/master
communication
Top level endpoint for slave to master cluster/slave
communications
Search Head Cluster
Access configuration replication health statistics replication/configuration/health
for SHC
Info regarding KO replication, including lookups replication/configuration
Lists searchhead cluster artifacts and replicas shcluster/captain/artifacts
(must run on captain)
SHC captain info and control shcluster/captain
SHC member info and control shcluster/member
Copyright © 2017 Splunk, Inc. All rights reserved
Function Endpoint
General
See the current in-memory configuration (like properties
btool)
btool Supplement
btoool displays merged on-disk configuration values. It is a helpful tool for finding basic configuration problems. (Some
of the btool commands are also listed in the tables above.)
• To list the configurations of a single type, use the following form of btool. Substitute the name of the configuration
file (without the .conf extension) for conf_name in the command:
splunk btool conf_name list [ --debug ]
• To see a single stanza, you can include the stanza, for example:
splunk btool inputs list monitor:///var/log
However, the command line must specify the stanza exactly in order to match.
You can also specify the user and app to see the configurations from a user point of view.
If you specify the user, you must also specify the app
splunk btool conf_name list [ -- user=user_name --app=app_name ]
As an alternative to btool, you can see the current in-memory configuration values with
https://host:mPort/services/properties/
where host is the name of the indexer and mport is the management port.
pcregextest
This is a command line tool to test a regular expression. You must give the tool the regular expression to test, and a
test string to test against. For example: