Splunk Search

Search 1hr using IPs from 24hr

mztopp
Explorer

How would I take a 24 hour search such as: index=* | iplocation src_ip | stats count by src_ip, Country, dest_ip, dest_port | sort 10 -count     that can effectively use the IPs from a 24 hour search, to search for the traffic in the last hour (using the same 10 IPs from the 24hr not the most popular from the last hour)? I have tried to bucket _time span=1hr, but that just searches through for the most active ips in the last hour and changes what I need. Any suggestions are appreciated!

Labels (3)
0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Something like this - use eventstats to find the most popular src_ip Country dest_ip etc (whatever criteria you want); sort descending by count and criteria just in case more than one combination has the same count; establish a combined key for the combination,; use streamstats based on this key to determine a rank; filter based on established rank; filter based on time criteria; calculate counts for surviving events

index=* 
| iplocation src_ip 
| eventstats count by src_ip, Country, dest_ip, dest_port 
| sort -count src_ip Country dest_ip dest_port
| eval key=src_ip.":".Country.":".dest_ip.":".dest_port
| streamstats dc(key) as rank
| where rank <= 10
| fields - rank key count
| where _time > relative_time(now(),"-1h@m")
| stats count by src_ip, Country, dest_ip, dest_port
0 Karma

manjunathmeti
Champion

hi @mztopp,

If field src_ip is part of the index then you can try this:

index=index earliest=-1h [search index=index earliest=-24h | top limit=10 src_ip | fields src_ip | format] | iplocation src_ip | stats count by src_ip, Country, dest_ip, dest_port

 

If this reply helps you, an upvote/like would be appreciated.

0 Karma

mztopp
Explorer

Just to be clear, my hope is to use this data for a report, so ideally I would be able to accomplish this all in one single search.

0 Karma

mztopp
Explorer

I ended up using a separate lookup to store the IPs. Not really ideal, but I wasn't getting the results I was looking for. Thanks for the help!

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Announcing Modern Navigation: A New Era of Splunk User Experience

We are excited to introduce the Modern Navigation feature in the Splunk Platform, available to both cloud and ...

Modernize your Splunk Apps – Introducing Python 3.13 in Splunk

We are excited to announce that the upcoming releases of Splunk Enterprise 10.2.x and Splunk Cloud Platform ...

Step into “Hunt the Insider: An Splunk ES Premier Mystery” to catch a cybercriminal ...

After a whole week of being on call, you fell asleep on your keyboard, and you hit a sequence of buttons that ...