Splunk Search

How to get stats on a string and name the string as a column

maddenm2
New Member

ProxyName=PLB and ("/policies" OR "/bills") stats count by ProxyName

I want the string "/policies" or "/bills" to be in a column name TYPE with the counts for each string.

Tags (4)
0 Karma

woodcock
Esteemed Legend

Like this (upper-casing of AND is VERY important):

index="YouShouldAlwaysSpecifyAnIndex" AND sourcetype="AndSourcetypeToo" AND ProxyName="PLB" AND ("/policies" OR "/bills")
| eval TYPE = if(searchmatch("/policies"), "policies", "bills")
| stats COUNT BY TYPE ProxyName

Or better yet, like this:

index="YouShouldAlwaysSpecifyAnIndex" AND sourcetype="AndSourcetypeToo" AND ProxyName="PLB" AND ("/policies" OR "/bills")
| eval TYPE = if(searchmatch("/policies"), "policies", "bills")
| chart COUNT BY TYPE ProxyName

Or even better, like this:

index="YouShouldAlwaysSpecifyAnIndex" AND sourcetype="AndSourcetypeToo" AND ProxyName="PLB" AND ("/policies" OR "/bills")
| stats count AS TOTAL count(eval(searchmatch("/policies"))) AS policies count(eval(searchmatch("/bills"))) AS bills BY ProxyName
0 Karma

oscar84x
Contributor

Could you provide event samples that contain both types? Have you considered extracting the field "type". Please provide some more data so we can see what you're working with.

0 Karma
Get Updates on the Splunk Community!

Splunk App for Anomaly Detection End of Life Announcment

Q: What is happening to the Splunk App for Anomaly Detection?A: Splunk is officially announcing the ...

Aligning Observability Costs with Business Value: Practical Strategies

 Join us for an engaging Tech Talk on Aligning Observability Costs with Business Value: Practical ...

Mastering Data Pipelines: Unlocking Value with Splunk

 In today's AI-driven world, organizations must balance the challenges of managing the explosion of data with ...