Searches go in the search bar in Splunk Web, for Splunk Enterprise and Splunk Cloud. Index names and field names depend on your setup and the add-ons you use, so the security searches use common field names such as user, src and dest; swap in yours if they differ. CLI commands run from the Splunk bin folder ($SPLUNK_HOME/bin, which is /opt/splunk/bin or /opt/splunkforwarder/bin on a forwarder) as the user that runs Splunk. On Windows, drop the ./ and run them from %SPLUNK_HOME%\bin. Splunk Cloud has no CLI access. Names and addresses are examples.
Official links: Splunk website, SPL Search Reference, Splunk Quick Reference Guide.
Search basics #
-
Search an index for a wordSplunk search (SPL)
index=main error -
Search one sourcetypeSplunk search (SPL)
index=main sourcetype=syslog -
Search one hostSplunk search (SPL)
index=main host=WEB-01 -
Search every index you can seeSplunk search (SPL)
index=* 10.0.0.25Warning: Searching every index is slow on a big deployment. Name the index when you know it.
-
Match either wordSplunk search (SPL)
index=main (error OR fail*) -
Leave out events with a wordSplunk search (SPL)
index=main error NOT debug -
Match a field valueSplunk search (SPL)
index=main status=404 -
Match an exact phraseSplunk search (SPL)
index=main "connection refused" -
Find events where a field isn't a value, or is missingSplunk search (SPL)
index=main NOT status=200Warning: status!=200 only matches events that have a status field. NOT status=200 also returns events with no status at all.
-
Show only the newest 20 eventsSplunk search (SPL)
index=main | head 20 -
Show the oldest events firstSplunk search (SPL)
index=main | reverse -
Count events in each indexSplunk search (SPL)
| tstats count where index=* by index -
List the sourcetypes in an indexSplunk search (SPL)
| metadata type=sourcetypes index=main | table sourcetype totalCount -
Make a test event to try a search onSplunk search (SPL)
| makeresults | eval user="jsmith", src="10.0.0.25"
Time ranges #
-
Last 24 hoursSplunk search (SPL)
index=main earliest=-24h latest=now -
Last hour, snapped to the start of the hourSplunk search (SPL)
index=main earliest=-1h@h latest=@h -
YesterdaySplunk search (SPL)
index=main earliest=-1d@d latest=@d -
Last 7 full daysSplunk search (SPL)
index=main earliest=-7d@d latest=@d -
This week so far (from Monday)Splunk search (SPL)
index=main earliest=@w1 -
Between two exact timesSplunk search (SPL)
index=main earliest="11/23/2026:09:00:00" latest="11/23/2026:17:00:00"Warning: The format is month/day/year:hour:minute:second.
-
Show the time in a readable formatSplunk search (SPL)
index=main | eval time=strftime(_time, "%Y-%m-%d %H:%M:%S") | table time host _raw -
Group events into 5-minute bucketsSplunk search (SPL)
index=main | bin _time span=5m | stats count by _time
Picking fields #
-
Show only some fields in a tableSplunk search (SPL)
index=main | table _time host source _raw -
Keep only the fields you need (faster)Splunk search (SPL)
index=main | fields host, status, uri -
Drop a fieldSplunk search (SPL)
index=main | fields - _raw -
Rename a fieldSplunk search (SPL)
index=main | rename src_ip AS src -
Remove duplicatesSplunk search (SPL)
index=main | dedup host -
Sort, biggest firstSplunk search (SPL)
index=main | stats count by host | sort - count -
Filter on a calculationSplunk search (SPL)
index=main | where bytes > 1000000 -
Filter with wildcards in whereSplunk search (SPL)
index=main | where like(uri, "%admin%") -
Filter again after other commandsSplunk search (SPL)
index=main | stats count by user | search count>10 -
Fill empty fields with 0Splunk search (SPL)
index=main | fillnull value=0 -
See which fields exist and how full they areSplunk search (SPL)
index=main | fieldsummary | table field count distinct_count
Counting and stats #
-
Count events by a fieldSplunk search (SPL)
index=main | stats count by host -
Count by two fieldsSplunk search (SPL)
index=main | stats count by host, status -
Count unique valuesSplunk search (SPL)
index=main | stats dc(user) AS users by host -
Average, max and 95th percentileSplunk search (SPL)
index=main | stats avg(response_time) AS avg max(response_time) AS max p95(response_time) AS p95 by uri -
Sum a fieldSplunk search (SPL)
index=main | stats sum(bytes) AS bytes by src -
List the values seen for each groupSplunk search (SPL)
index=main | stats values(src) AS sources count by user -
First and last time something was seenSplunk search (SPL)
index=main | stats earliest(_time) AS first latest(_time) AS last by user | convert ctime(first) ctime(last) -
Top 10 values of a fieldSplunk search (SPL)
index=main | top limit=10 user -
Least common values of a fieldSplunk search (SPL)
index=main | rare limit=10 process_name -
Add a total to every row without groupingSplunk search (SPL)
index=main | eventstats count AS total by host -
Running count per userSplunk search (SPL)
index=main | streamstats count AS seen by user -
Add a totals row at the bottomSplunk search (SPL)
index=main | stats count by host | addcoltotals labelfield=host label=Total -
Add a sparkline to each rowSplunk search (SPL)
index=main | stats sparkline count by host
Charts #
-
Events over timeSplunk search (SPL)
index=main | timechart span=1h count -
Events over time, one line per hostSplunk search (SPL)
index=main | timechart span=1h count by host limit=10 -
Average over timeSplunk search (SPL)
index=main | timechart span=15m avg(response_time) -
A table with one row per host and a column per statusSplunk search (SPL)
index=main | chart count over host by status -
Compare today with last weekSplunk search (SPL)
index=main earliest=-7d@d | timechart span=1h count | timewrap 1d -
Forecast a trendSplunk search (SPL)
index=main | timechart span=1d count | predict count
eval and functions #
-
Make a new field from a sumSplunk search (SPL)
index=main | eval MB=round(bytes/1024/1024, 2) -
Set a value with ifSplunk search (SPL)
index=main | eval result=if(status>=400, "error", "ok") -
Set a value with several conditionsSplunk search (SPL)
index=main | eval severity=case(status>=500, "high", status>=400, "medium", true(), "low") -
Use the first field that has a valueSplunk search (SPL)
index=main | eval user=coalesce(user, Account_Name, username) -
Lower-case a fieldSplunk search (SPL)
index=main | eval user=lower(user) -
Length of a fieldSplunk search (SPL)
index=main | eval len=len(query) -
Part of a stringSplunk search (SPL)
index=main | eval prefix=substr(host, 1, 3) -
Split a string and take one partSplunk search (SPL)
index=main | eval domain=mvindex(split(user, "@"), 1) -
Turn a multivalue field into one row per valueSplunk search (SPL)
index=main | mvexpand recipient -
Replace text with a regexSplunk search (SPL)
index=main | eval uri=replace(uri, "\d+", "N") -
Check if an address is in a networkSplunk search (SPL)
index=main | where cidrmatch("10.0.0.0/8", src) -
Seconds as a readable durationSplunk search (SPL)
index=main | eval took=tostring(duration, "duration") -
Numbers with commasSplunk search (SPL)
index=main | stats count | eval count=tostring(count, "commas") -
Decode a URLSplunk search (SPL)
index=main | eval uri=urldecode(uri) -
Where an address is in the worldSplunk search (SPL)
index=main | iplocation src | stats count by Country
Pulling fields out of text #
-
Extract a field with a regexSplunk search (SPL)
index=main | rex "user=(?<user>\S+)" -
Extract from one field instead of _rawSplunk search (SPL)
index=main | rex field=uri "^/(?<section>[^/]+)" -
Extract every match, not just the firstSplunk search (SPL)
index=main | rex max_match=0 "(?<ip>\d{1,3}(?:\.\d{1,3}){3})" -
Mask card numbers in resultsSplunk search (SPL)
index=main | rex mode=sed "s/\d{4}-\d{4}-\d{4}-(\d{4})/XXXX-XXXX-XXXX-\1/g" -
Read fields from JSONSplunk search (SPL)
index=main | spath | table user.name, event.action -
Read one JSON pathSplunk search (SPL)
index=main | spath path=user.name output=user -
Read key=value pairs with other separatorsSplunk search (SPL)
index=main | extract pairdelim="," kvdelim=":"
Lookups #
-
Show what's in a lookupSplunk search (SPL)
| inputlookup bad_ips.csv -
Add fields from a lookupSplunk search (SPL)
index=main | lookup bad_ips.csv ip AS src OUTPUT owner, location -
Save results as a lookupSplunk search (SPL)
index=main | stats count by src | outputlookup bad_ips.csv -
Add to a lookup instead of replacing itSplunk search (SPL)
index=main | stats count by src | outputlookup append=true bad_ips.csv -
Search for anything in a lookup (a watchlist)Splunk search (SPL)
index=main [| inputlookup bad_ips.csv | fields src]Warning: The column name in the lookup must match the field name in the events. Rename it inside the brackets if it doesn't.
-
Find lookup rows that never showed upSplunk search (SPL)
| inputlookup bad_ips.csv | search NOT [search index=main earliest=-7d | stats count by src | fields src]
Combining searches #
-
Use one search's results to filter another (subsearch)Splunk search (SPL)
index=main [search index=main action=blocked | dedup src | fields src]Warning: Subsearches stop at 10,000 results and 60 seconds by default.
-
Add another search's results underneathSplunk search (SPL)
index=main sourcetype=a | append [search index=main sourcetype=b] -
Join two searches on a fieldSplunk search (SPL)
index=main sourcetype=a | join type=left user [search index=main sourcetype=b | fields user, department]Warning: join is slow and has subsearch limits. stats with by often does the same job faster.
-
Join two sourcetypes with stats insteadSplunk search (SPL)
index=main (sourcetype=a OR sourcetype=b) | stats values(department) AS department count by user -
Group related events into oneSplunk search (SPL)
index=main | transaction user maxspan=30m maxpause=5m
Fast searches #
-
Count by index and sourcetype instantlySplunk search (SPL)
| tstats count where index=* by index, sourcetype -
Events per hour from indexed dataSplunk search (SPL)
| tstats count where index=main by _time span=1h -
Count failed logins from a data modelSplunk search (SPL)
| tstats count from datamodel=Authentication where Authentication.action=failure by Authentication.src -
List hosts and when they last sent dataSplunk search (SPL)
| metadata type=hosts index=main | convert ctime(lastTime) | table host lastTime totalCount -
Find hosts that stopped sending dataSplunk search (SPL)
| metadata type=hosts index=main | where lastTime < relative_time(now(), "-24h") | convert ctime(lastTime) | table host lastTime -
List the indexes and their sizeSplunk search (SPL)
| rest /services/data/indexes | table title currentDBSizeMB totalEventCount -
List the saved searches and their schedulesSplunk search (SPL)
| rest /servicesNS/-/-/saved/searches | table title eai:acl.app cron_schedule
Security: logins #
-
Failed Windows logins by user and sourceSplunk search (SPL)
index=wineventlog EventCode=4625 | stats count by user, src | sort - count -
Possible brute force (many failures)Splunk search (SPL)
index=wineventlog EventCode=4625 | stats count by user, src | where count > 10 -
Failures followed by a successSplunk search (SPL)
index=wineventlog (EventCode=4625 OR EventCode=4624) | stats count(eval(EventCode=4625)) AS failures count(eval(EventCode=4624)) AS successes by user, src | where failures > 10 AND successes > 0 -
Password spraying (one source, many users)Splunk search (SPL)
index=wineventlog EventCode=4625 | stats dc(user) AS users by src | where users > 10 -
Accounts locked outSplunk search (SPL)
index=wineventlog EventCode=4740 | table _time user host -
RDP loginsSplunk search (SPL)
index=wineventlog EventCode=4624 Logon_Type=10 | stats count by user, src -
Logins outside working hoursSplunk search (SPL)
index=wineventlog EventCode=4624 | eval hour=tonumber(strftime(_time, "%H")) | where hour < 7 OR hour > 19 | stats count by user -
Failed SSH logins on LinuxSplunk search (SPL)
index=linux sourcetype=linux_secure "Failed password" | rex "for (invalid user )?(?<user>\S+) from (?<src>\S+)" | stats count by user, src | sort - count -
Successful SSH logins on LinuxSplunk search (SPL)
index=linux sourcetype=linux_secure "Accepted" | rex "Accepted \S+ for (?<user>\S+) from (?<src>\S+)" | stats count by user, src -
sudo use on LinuxSplunk search (SPL)
index=linux sourcetype=linux_secure sudo COMMAND | rex "sudo:\s+(?<user>\S+) :.*COMMAND=(?<command>.*)" | table _time host user command
Security: Windows changes #
-
New user accountsSplunk search (SPL)
index=wineventlog EventCode=4720 | table _time user src_user host -
Users added to a security groupSplunk search (SPL)
index=wineventlog (EventCode=4728 OR EventCode=4732 OR EventCode=4756) | table _time src_user user Group_Name host -
Accounts deletedSplunk search (SPL)
index=wineventlog EventCode=4726 | table _time user src_user host -
Security log clearedSplunk search (SPL)
index=wineventlog EventCode=1102 | table _time host user -
New services installedSplunk search (SPL)
index=wineventlog EventCode=7045 | table _time host Service_Name Service_File_Name -
Scheduled tasks createdSplunk search (SPL)
index=wineventlog EventCode=4698 | table _time host user Task_Name -
Processes started, with command linesSplunk search (SPL)
index=wineventlog EventCode=4688 | table _time host user New_Process_Name Process_Command_Line -
Rare processes across your hostsSplunk search (SPL)
index=wineventlog EventCode=4688 | rare limit=20 New_Process_Name -
Encoded PowerShell commandsSplunk search (SPL)
index=wineventlog EventCode=4688 New_Process_Name=*powershell.exe (Process_Command_Line="*-enc*" OR Process_Command_Line="*-EncodedCommand*") | table _time host user Process_Command_Line
Security: network and web #
-
Most-blocked sources on the firewallSplunk search (SPL)
index=firewall action=blocked | stats count by src | sort - count | head 20 -
Possible port scan (one source, many ports)Splunk search (SPL)
index=firewall | stats dc(dest_port) AS ports by src, dest | where ports > 50 -
Top talkers by bytesSplunk search (SPL)
index=firewall | stats sum(bytes) AS bytes by src | sort - bytes | head 10 | eval MB=round(bytes/1024/1024, 2) -
Traffic to an addressSplunk search (SPL)
index=firewall dest=10.0.0.25 | stats count by src, dest_port, action -
Connections from outside your countrySplunk search (SPL)
index=firewall action=allowed | iplocation src | where Country!="Ireland" | stats count by Country, src -
Web clients getting the most 404sSplunk search (SPL)
index=web sourcetype=access_combined status=404 | stats count by clientip | sort - count -
Web server errors over timeSplunk search (SPL)
index=web sourcetype=access_combined status>=500 | timechart span=1h count by status -
Unusual user agentsSplunk search (SPL)
index=web sourcetype=access_combined | rare limit=20 useragent -
Requests that look like SQL injectionSplunk search (SPL)
index=web sourcetype=access_combined | eval uri=urldecode(uri) | where match(uri, "(?i)union\s+select|or\s+1=1|sleep\(") -
Long DNS queries (possible tunnelling)Splunk search (SPL)
index=dns | eval len=len(query) | where len > 50 | stats count by src, query
Splunk's own logs #
-
Splunk errors by componentSplunk search (SPL)
index=_internal sourcetype=splunkd log_level=ERROR | stats count by component | sort - count -
Daily licence use by index (GB)Splunk search (SPL)
index=_internal source=*license_usage.log type=Usage | eval GB=b/1024/1024/1024 | timechart span=1d sum(GB) by idx -
Forwarders and when they last connectedSplunk search (SPL)
index=_internal sourcetype=splunkd group=tcpin_connections | stats latest(_time) AS last_seen by hostname | convert ctime(last_seen) -
Who ran which searchesSplunk search (SPL)
index=_audit action=search info=granted search=* | table _time user search -
Logins to SplunkSplunk search (SPL)
index=_audit action="login attempt" | stats count by user, info -
Slowest scheduled searchesSplunk search (SPL)
index=_internal sourcetype=scheduler status=success | stats avg(run_time) AS avg_seconds by savedsearch_name | sort - avg_seconds -
Skipped scheduled searchesSplunk search (SPL)
index=_internal sourcetype=scheduler status=skipped | stats count by savedsearch_name, reason
CLI: start, stop and status #
-
Start SplunkSplunk CLI
./splunk start -
Stop SplunkSplunk CLI
./splunk stop -
Restart SplunkSplunk CLI
./splunk restart -
Check whether Splunk is runningSplunk CLI
./splunk status -
Show the versionSplunk CLI
./splunk version -
Start Splunk when the server bootsSplunk CLI
sudo ./splunk enable boot-start -user splunk -
Stop starting at bootSplunk CLI
sudo ./splunk disable boot-start -
Show the management portSplunk CLI
./splunk show splunkd-port -
Show the web portSplunk CLI
./splunk show web-port
CLI: getting data in #
-
Let the indexer receive data from forwardersSplunk CLI
./splunk enable listen 9997 -
Send a forwarder's data to an indexerSplunk CLI
./splunk add forward-server idx1.example.com:9997 -
List where a forwarder sends dataSplunk CLI
./splunk list forward-server -
Stop sending to an indexerSplunk CLI
./splunk remove forward-server idx1.example.com:9997 -
Watch a log file or folderSplunk CLI
./splunk add monitor /var/log/secure -index main -sourcetype syslog -
List the files being watchedSplunk CLI
./splunk list monitor -
Index a file onceSplunk CLI
./splunk add oneshot /var/log/secure -index main -sourcetype syslog -
Point a forwarder at a deployment serverSplunk CLI
./splunk set deploy-poll ds1.example.com:8089 -
Push deployment server changes to clientsSplunk CLI
./splunk reload deploy-server -
List the deployment clientsSplunk CLI
./splunk list deploy-clients -
Create an indexSplunk CLI
./splunk add index main -
Delete all the data in an indexSplunk CLI
./splunk stop ./splunk clean eventdata -index main ./splunk startWarning: This permanently deletes every event in the index. There's no undo.
CLI: config and troubleshooting #
-
Show the merged inputs config and which file each line is fromSplunk CLI
./splunk btool inputs list --debug -
Show the merged outputs configSplunk CLI
./splunk btool outputs list --debug -
Show how a sourcetype is parsedSplunk CLI
./splunk btool props list syslog --debug -
Check config files for typosSplunk CLI
./splunk btool check -
Run a search from the command lineSplunk CLI
./splunk search "index=_internal | head 10" -
List the installed appsSplunk CLI
./splunk display app -
Install an app from a fileSplunk CLI
./splunk install app /tmp/my_app.tgz -
Collect a diag file for Splunk supportSplunk CLI
./splunk diag