Splunk Search

How to combine my two event count searches into one search and then do an eval function to divide the event counts?

john122089
New Member

Need to search for different event counts in the same sourcetype. I can do it in 2 different searches, but I need it in one.

index="ally_nga_sm" sourcetype="custom_auth_scheme_log" "invalid credentials" | stats count as IC
index="ally_nga_sm" sourcetype="custom_auth_scheme_log" "SuccessfulLogin" | stats count as SL

Then I need to do an eval function to divide the two counts IC/SL

0 Karma
1 Solution

somesoni2
Revered Legend

I would do like this

Fixed typos

index="ally_nga_sm" sourcetype="custom_auth_scheme_log" "invalid credentials" OR "SuccessfulLogin" | eval IC=if(searchmatch("invalid credentials"),1,0) | eval SL=if(searchmatch("SuccessfulLogin"),1,0) | stats sum(IC) as IC sum(SL) as SL

View solution in original post

0 Karma

hortonew
Builder

Perhaps something like:

 index="ally_nga_sm" sourcetype="custom_auth_scheme_log" ("invalid credentials" OR "SuccessfulLogin")
 | eval status=if(like(_raw, "%SuccessfulLogin%"), Successful, Invalid)
 | stats count by status
0 Karma

somesoni2
Revered Legend

I would do like this

Fixed typos

index="ally_nga_sm" sourcetype="custom_auth_scheme_log" "invalid credentials" OR "SuccessfulLogin" | eval IC=if(searchmatch("invalid credentials"),1,0) | eval SL=if(searchmatch("SuccessfulLogin"),1,0) | stats sum(IC) as IC sum(SL) as SL
0 Karma

john122089
New Member

Error in 'eval' command: The 'search_match' function is unsupported or undefined.

I am getting the above error

0 Karma

john122089
New Member

This great! Now can it also show the IC/SL?

0 Karma

john122089
New Member

I tried adding count(eval(sum(IC)/(sum(IC)+sum(SL)))) to the end. Getting an error. Is there a better way?

0 Karma

aaraneta_splunk
Splunk Employee
Splunk Employee

Hi @john122089 - If somesoni2 ended up answering your question, please don't forget to resolve this post by clicking on "Accept" below the answer 🙂 If not, please provide him with some more feedback. Thanks!

0 Karma

somesoni2
Revered Legend

Guessing you want to add a ratio of both. Add following to end of search

..current search.. | eval "IC/SL"=IC/(IC+SL)

IF you see the result of current search, column names being shown is IC and SL, so you're use those field names now for any further calculation.

0 Karma

somesoni2
Revered Legend

My bad, updated the function name now.

0 Karma
Get Updates on the Splunk Community!

ICYMI - Check out the latest releases of Splunk Edge Processor

Splunk is pleased to announce the latest enhancements to Splunk Edge Processor.  HEC Receiver authorization ...

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...

Introducing the 2024 Splunk MVPs!

We are excited to announce the 2024 cohort of the Splunk MVP program. Splunk MVPs are passionate members of ...