Splunk Search

How to use eval for basic search terms (NOT fields)?

link22
Explorer

So I want to get the stats count of two search terms in a search that looks like this:
index=myIndex "searchTermA" OR "searchTermB" (these searches being strings to find certain applications under the index and they have no fields to search for them by nor are they similar enough for field extraction to work [individually field extracting these also proves to have a lot of issues as well]).

and what I wish I could do is this:

index=myIndex "searchTermA" OR "searchTermB"  | stats (or chart/timechart) count("searchTermA") count("searchTermB")

to get the data I want.

However, I am aware this is not possible. Is there some way to use eval to give these search strings a name and use them for count?

I also cannot go into the .conf files and edit them.

Thanks!

0 Karma
1 Solution

somesoni2
Revered Legend

You can something like this

index=myIndex "searchTermA" OR "searchTermB" | stats  count(eval(searchmatch("searchTermA"))) as CountA count(eval(searchmatch("searchTermB"))) as CountB

View solution in original post

0 Karma

somesoni2
Revered Legend

You can something like this

index=myIndex "searchTermA" OR "searchTermB" | stats  count(eval(searchmatch("searchTermA"))) as CountA count(eval(searchmatch("searchTermB"))) as CountB
0 Karma

brendanmatthews
Explorer

You can run something like ... |eval count_field = case(searchmatch("searchtermA"), "A_class",searchmatch("searchtermB"),"B_class") | stats (or chart/timechart) count by count_field. It should return the counts of both types of events.

0 Karma
Get Updates on the Splunk Community!

More Ways To Control Your Costs With Archived Metrics | Register for Tech Talk

Tuesday, May 14, 2024  |  11AM PT / 2PM ET Register to Attend Join us for this Tech Talk and learn how to ...

.conf24 | Personalize your .conf experience with Learning Paths!

Personalize your .conf24 Experience Learning paths allow you to level up your skill sets and dive deeper ...

Threat Hunting Unlocked: How to Uplevel Your Threat Hunting With the PEAK Framework ...

WATCH NOWAs AI starts tackling low level alerts, it's more critical than ever to uplevel your threat hunting ...