Splunk Search

help with tstats and eval

a212830
Champion

Hi,

I'm trying to count the number of events for a specific index/sourcetype combo, and then total them into a new field, using eval. I've tried this, but looks like my logic is off, as the numbers are very weird - looks like it's counting the number of splunk servers. I want to count the number of events per splunk_server and then total them into a new field named splunk_region.

|tstats count WHERE index=cisco AND sourcetype="cisco:asa" by  splunk_server _time
| eval splunk_region = case(like(splunk_server,"%bos-%"),"BOS" , 
like(splunk_server, "dfw-%"),"DFW",
like(splunk_server, "%lax-%"), "LAX", 
like(splunk_server, "%"),"OTHER") 
| timechart span=1d count by splunk_region
0 Karma
1 Solution

woodcock
Esteemed Legend

Like this:

|tstats count WHERE index=cisco AND sourcetype="cisco:asa" BY splunk_server _time span=1d
| eval splunk_region = case(
   like(splunk_server,"%bos-%"),  "BOS", 
   like(splunk_server, "dfw-%"),  "DFW",
   like(splunk_server, "%lax-%"), "LAX", 
   true(),                        "OTHER") 
| timechart span=1d sum(count) AS count BY splunk_region

View solution in original post

woodcock
Esteemed Legend

Like this:

|tstats count WHERE index=cisco AND sourcetype="cisco:asa" BY splunk_server _time span=1d
| eval splunk_region = case(
   like(splunk_server,"%bos-%"),  "BOS", 
   like(splunk_server, "dfw-%"),  "DFW",
   like(splunk_server, "%lax-%"), "LAX", 
   true(),                        "OTHER") 
| timechart span=1d sum(count) AS count BY splunk_region
Get Updates on the Splunk Community!

Technical Workshop Series: Splunk Data Management and SPL2 | Register here!

Hey, Splunk Community! Ready to take your data management skills to the next level? Join us for a 3-part ...

Splunk Observability Synthetic Monitoring - Resolved Incident on Detector Alerts

We’ve discovered a bug that affected the auto-clear of Synthetic Detectors in the Splunk Synthetic Monitoring ...

Video | Tom’s Smartness Journey Continues

Remember Splunk Community member Tom Kopchak? If you caught the first episode of our Smartness interview ...