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
Legend

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
---
What goes around comes around. If it helps, hit it with Karma 🙂

View solution in original post

renjith_nair
Legend

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
---
What goes around comes around. If it helps, hit it with Karma 🙂
Get Updates on the Splunk Community!

Stay Connected: Your Guide to May Tech Talks, Office Hours, and Webinars!

Take a look below to explore our upcoming Community Office Hours, Tech Talks, and Webinars this month. This ...

They're back! Join the SplunkTrust and MVP at .conf24

With our highly anticipated annual conference, .conf, comes the fez-wearers you can trust! The SplunkTrust, as ...

Enterprise Security Content Update (ESCU) | New Releases

Last month, the Splunk Threat Research Team had two releases of new security content via the Enterprise ...