Splunk Search

Set Sort Order in Splunk Panel

chlebs
New Member

I have made a dashboard with a few panels on it, each of which contains a _time field and an environment field that the panels are sorted by. The primary sorting field is environment, then _time comes second. Below I will place an example search from one of the panels. I am wondering if I can preset the order of the sorting. There are 4 possible values for the environment variable: Test, Stage, Train, and Production. That is the order they should be in, but the sort command sorts alphabetically and places them in the order: Train, Test, Stage, Production. Thank you in advance to anyone who helps me with this.

Example Code:

index=java sourcetype=j2ee source="/opt/jbosslogs/profileData.log" web{ profile=$app_tok$ | eval environment=case(like(host, "%t"), "Test", like(host, "%s"), "Stage", like(host, "%n"), "Train", like(host, "%p"), "Production") | table _time, environment, host, proxy_name, path, pattern | sort -environment, _time
0 Karma
1 Solution

Grumpalot
Communicator

Here is sort based on example 5 of Sort from http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Sort

index=java sourcetype=j2ee source="/opt/jbosslogs/profileData.log" web{ profile=$app_tok$ | eval environment=case(like(host, "%t"), "Test", like(host, "%s"), "Stage", like(host, "%n"), "Train", like(host, "%p"), "Production") | table _time, environment, host, proxy_name, path, pattern | eval sort_environment=case(environment=="Train",1, environment=="Test",2, environment=="Stage",3, environment=="Production",4) | sort -sort_environment, _time | fields - sort_environment

View solution in original post

0 Karma

Grumpalot
Communicator

Here is sort based on example 5 of Sort from http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Sort

index=java sourcetype=j2ee source="/opt/jbosslogs/profileData.log" web{ profile=$app_tok$ | eval environment=case(like(host, "%t"), "Test", like(host, "%s"), "Stage", like(host, "%n"), "Train", like(host, "%p"), "Production") | table _time, environment, host, proxy_name, path, pattern | eval sort_environment=case(environment=="Train",1, environment=="Test",2, environment=="Stage",3, environment=="Production",4) | sort -sort_environment, _time | fields - sort_environment
0 Karma

Grumpalot
Communicator

With the reverse of Test, Stage, Train, and Production

Production = 4
Train = 3
Stage = 2
Test = 1

Sorry missed the order was more of a -- this should work for you just have to change the parameters.

0 Karma

chlebs
New Member

Clever answer! This seems like common sense now that I see it. I must've been too caught up in the problem to find the solution. Thank you so much!

0 Karma
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...