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!

Prove Your Splunk Prowess at .conf25—No Prereqs Required!

Your Next Big Security Credential: No Prerequisites Needed We know you’ve got the skills, and now, earning the ...

Splunk Observability Cloud's AI Assistant in Action Series: Observability as Code

This is the sixth post in the Splunk Observability Cloud’s AI Assistant in Action series that digs into how to ...

Splunk Answers Content Calendar, July Edition I

Hello Community! Welcome to another month of Community Content Calendar series! For the month of July, we will ...