Splunk Search

How to count the flag values assigned in a column from an eval?

packet_hunter
Contributor

Scenario:
I have a search that evaluates email events (given a specific subject) to count the number of recipients per individual email and then sum the total number of recipients from all emails (given the same subject). The search also looks for recipients on a watch_list.csv with a flag to create a yes or no value next to the watched emailaddress.

Now I need a column (total_on_watch_list) with the total number of "yes" recipients.

Search:

index=mail sourcetype=xemail [search index=mail sourcetype=xemail subject = "Blah" |stats count by UID| fields UID] 
|stats list(subject) as subj list(sender) as sender list(recipient) as recp list(vendor_action) as status by UID            
|lookup watch_list.csv emailaddress as recp OUTPUT flag emailaddress 
|eval on_watch_list=if(flag=1,"yes","no") 
| fields - flag         
|eval recp_count=mvcount(recp)          
|eventstats sum(recp_count) as total_recipients

Please provide an example.

Much appreciated

Tags (2)
0 Karma
1 Solution

somesoni2
SplunkTrust
SplunkTrust

Try something like this

your current search  | eventstats count(eval(on_watch_list="yes"))) as total_on_watch_list 

View solution in original post

0 Karma

somesoni2
SplunkTrust
SplunkTrust

Try something like this

your current search  | eventstats count(eval(on_watch_list="yes"))) as total_on_watch_list 
0 Karma

packet_hunter
Contributor

| eventstats count(eval(on_watch_list = "yes")) as total_on_watch_list

works great!!! Thank you!

0 Karma
Get Updates on the Splunk Community!

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...

What's new in Splunk Cloud Platform 9.1.2312?

Hi Splunky people! We are excited to share the newest updates in Splunk Cloud Platform 9.1.2312! Analysts can ...