Splunk Search

Sort table in a specific order? Sample from Splunk does not work?

alex1895
Path Finder

Sample given from Splunk:

   ... | eval wd=lower(Day) | eval sort_field=case(wd=="monday",1, wd=="tuesday",2, wd=="wednesday",3, wd=="thursday",4, wd=="friday",5, wd=="weekend",6) | sort sort_field | fields - sort_field

Mine:

index=myindex sourcetype=mysourcetype vendor=myvendor   | eval sort_killchain=case(cat=="BOTNET ACTIVITY",1,cat=="COMMAND & CONTROL",2,cat=="RECONNAISSANCE",3,cat=="LATERAL MOVEMENT",4,cat=="EXFILTRATION",5) |stats count by cat |where cat=="COMMAND & CONTROL" OR cat=="RECONNAISSANCE" OR cat=="LATERAL MOVEMENT" OR cat=="BOTNET ACTIVITY" OR cat=="EXFILTRATION" | sort by sort_killchain

Any reason why mine shouldn't work?

0 Karma
1 Solution

renjith_nair
SplunkTrust
SplunkTrust

Add your sort_killchain after the stats command. The filed sort_killchain is NOT referred in stats and hence the output of stats has only cat and count.

index=myindex sourcetype=mysourcetype vendor=myvendor |stats count by cat 
| eval sort_killchain=case(cat=="BOTNET ACTIVITY",1,cat=="COMMAND & CONTROL",2,cat=="RECONNAISSANCE",3,cat=="LATERAL MOVEMENT",4,cat=="EXFILTRATION",5) 
|where cat=="COMMAND & CONTROL" OR cat=="RECONNAISSANCE" OR cat=="LATERAL MOVEMENT" OR cat=="BOTNET ACTIVITY" OR cat=="EXFILTRATION" | sort by sort_killchain
Happy Splunking!

View solution in original post

renjith_nair
SplunkTrust
SplunkTrust

Add your sort_killchain after the stats command. The filed sort_killchain is NOT referred in stats and hence the output of stats has only cat and count.

index=myindex sourcetype=mysourcetype vendor=myvendor |stats count by cat 
| eval sort_killchain=case(cat=="BOTNET ACTIVITY",1,cat=="COMMAND & CONTROL",2,cat=="RECONNAISSANCE",3,cat=="LATERAL MOVEMENT",4,cat=="EXFILTRATION",5) 
|where cat=="COMMAND & CONTROL" OR cat=="RECONNAISSANCE" OR cat=="LATERAL MOVEMENT" OR cat=="BOTNET ACTIVITY" OR cat=="EXFILTRATION" | sort by sort_killchain
Happy Splunking!
Get Updates on the Splunk Community!

What's new in Splunk Cloud Platform 9.1.2312?

Hi Splunky people! We are excited to share the newest updates in Splunk Cloud Platform 9.1.2312! Analysts can ...

What’s New in Splunk Security Essentials 3.8.0?

Splunk Security Essentials (SSE) is an app that can amplify the power of your existing Splunk Cloud Platform, ...

Let’s Get You Certified – Vegas-Style at .conf24

Are you ready to level up your Splunk game? Then, let’s get you certified live at .conf24 – our annual user ...