Splunk Search

How to combine Values Within Stats Command

whunterj
Explorer

I have written a search that breaks down the four values in the majorCustomer field and counts the number of servers in each of the four majorCustomers. What I want to do is combine the commercial and information systems customer into one called corporate and have the count be a sum of their individual server counts. Any suggestions?

This is the search:

index=citrix
| fields majorCustomer Host
| rename majorCustomer as "Line of Business"
| stats count(Host) as Servers by "Line of Business"
| eventstats sum(Servers) as Total
| eval Percentage = (Servers/Total)*100
| eval Percentage = round(Percentage, 2)
| eval Percentage = Percentage + "%"
| table "Line of Business" Servers Percentage
| sort -Servers!

alt text

0 Karma

niketn
Legend

@whunterj try the following eval after your fields pipe | eval majorCustomer=case(majorCustomer IN ("commercial","information systems"),"Corporate",true(),majorCustomer)

index=citrix majorCustomer=* Host=*
| fields majorCustomer Host
| eval majorCustomer=case(majorCustomer IN ("commercial","information systems"),"Corporate",true(),majorCustomer)
| rename majorCustomer as "Line of Business"
| stats count(Host) as Servers by "Line of Business"
| eventstats sum(Servers) as Total
| eval Percentage = (Servers/Total)*100
| eval Percentage = round(Percentage, 2)
| eval Percentage = Percentage + "%"
| table "Line of Business" Servers Percentage
| sort -Servers

PS: IN clause will work only if you are on Splunk 6.6 or higher, or else you would need to use majorCustomer=="commercial" OR majorCustomer=="information systems"

____________________________________________
| makeresults | eval message= "Happy Splunking!!!"
0 Karma

whunterj
Explorer

This is exactly what I was trying to do. Thank you!

woodcock
Esteemed Legend

If that's it, then click Accept to close the question.

Get Updates on the Splunk Community!

Join Us for Splunk University and Get Your Bootcamp Game On!

If you know, you know! Splunk University is the vibe this summer so register today for bootcamps galore ...

.conf24 | Learning Tracks for Security, Observability, Platform, and Developers!

.conf24 is taking place at The Venetian in Las Vegas from June 11 - 14. Continue reading to learn about the ...

Announcing Scheduled Export GA for Dashboard Studio

We're excited to announce the general availability of Scheduled Export for Dashboard Studio. Starting in ...