Splunk Search

How do I edit my search to sort performance logs from one set of servers into one category, and everything else into another category?

ShagVT
Path Finder

I'm trying to write a search that will look at performance logs for my servers, putting the data from one set of servers into one bin, and everything else into a second bin.

Here's my attempt:

index=myindex sourcetype=performance_file ExecutionTime | eval category=(host="host1" OR host="host2" OR host="host3" OR host="host4", "SpecialServers", host!="host1" AND host!="host2" AND host!="host3" AND host!="host4", "OtherServers") | timechart span=1m avg(resptime) by category

I'm surprised by the error I'm getting:

Error in 'eval' command: The expression is malformed. Expected ).

Am I on the right track at all? I'm a bit of a rookie at advanced queries like this.

Tags (2)
0 Karma
1 Solution

MattZerfas
Communicator

Try This

index=myindex sourcetype=performance_file ExecutionTime | eval category=if(host="host1" OR host="host2" OR host="host3" OR host="host4", "SpecialServers", "OtherServers") | timechart span=1m avg(resptime) by category

You were on the right track but I just modified your eval to use an if statement.

Here is the link with the syntax for if statements and many others.
http://docs.splunk.com/Documentation/Splunk/6.1/SearchReference/Commonevalfunctions

View solution in original post

javiergn
Super Champion

You forgot the "case" and the double =

eval category = case(host ...

take a look at example 11 here: http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Eval

0 Karma

MattZerfas
Communicator

No need for a case if he just wants 2 groups of items. If he wanted 3 or more then a case statement would work better than an if statement.

0 Karma

javiergn
Super Champion

True. I didn't notice there were just two groups. Just saw a long eval and "assumed" there were more.

0 Karma

MattZerfas
Communicator

Yup I did the same thing until I read through his query 🙂 All good.

0 Karma

MattZerfas
Communicator

Try This

index=myindex sourcetype=performance_file ExecutionTime | eval category=if(host="host1" OR host="host2" OR host="host3" OR host="host4", "SpecialServers", "OtherServers") | timechart span=1m avg(resptime) by category

You were on the right track but I just modified your eval to use an if statement.

Here is the link with the syntax for if statements and many others.
http://docs.splunk.com/Documentation/Splunk/6.1/SearchReference/Commonevalfunctions

Get Updates on the Splunk Community!

Automatic Discovery Part 1: What is Automatic Discovery in Splunk Observability Cloud ...

If you’ve ever deployed a new database cluster, spun up a caching layer, or added a load balancer, you know it ...

Real-Time Fraud Detection: How Splunk Dashboards Protect Financial Institutions

Financial fraud isn't slowing down. If anything, it's getting more sophisticated. Account takeovers, credit ...

Splunk + ThousandEyes: Correlate frontend, app, and network data to troubleshoot ...

 Are you tired of troubleshooting delays caused by siloed frontend, application, and network data? We've got a ...