Splunk Search

How to display zero if there are null values reporting for a mail id?

Navanitha
Path Finder

Hi,

I have a search similar to the one below which gives the total count of emails sent out. Here, when there are no emails sent out from a particular email id say email1@xxx.com, I need to display the count as zero under the table. Can someone help me here?

index=xyz "email1@xxx.com" OR "email2@yyy.com" OR "email3@zzz.com" OR "email4@abc.com" OR "email5@xyz.com" "ready" "MID"|stats count, last(_time) as "EmailSent" | convert ctime("EmailSent") as time | table count, time

Thanks in advance.

Tags (4)
0 Karma

somesoni2
Revered Legend

For this solution to work, you would need to have the field extracted which will contain the email address you're searching. Let's assume the field name is emailAddr. Then try this

index=xyz emailAddr="email1@xxx.com" OR emailAddr="email2@yyy.com" OR emailAddr="email3@zzz.com" OR emailAddr="email4@abc.com" OR emailAddr="email5@xyz.com" "ready" "MID"|stats count, max(_time) as "EmailSent" by emailAddr| convert ctime("EmailSent") as time | table count, time emailAddr | append [| gentimes start=-1 | eval emailAddr="email1@xxx.com,email2@yyy.com,email3@zzz.com,email4@abc.com,email5@xyz.com" | table emailAddr | makemv emailAddr delim="," | mvexpand emailAddr | eval count="0" | eval time="NA" ] | stats list(*) as * by emailAddr | eval count=mvindex(count,0) | eval time=mvindex(time,0)
0 Karma

Navanitha
Path Finder

I tried it but to my surprise the count from all the email id's is displayed as '0' which should not be the case coz there are mails sent out from all the id's with variation in the count. and the email sent time is showing "NA".

I have a field with email_id extraction.

0 Karma

alacercogitatus
SplunkTrust
SplunkTrust

Fill null might help you here. I'm assuming sender is present as a field, and contains the email address used to send the email.

<your search> | stats count last(_time) as lt by sender | fillnull value=0 count | convert ctime(lt) as time
0 Karma

jkat54
SplunkTrust
SplunkTrust

Can you please provide a sample of the data with PII / sensitive data redacted?

From what I can tell now, you'll need to use stats without the table, and maybe do some eval work to insure 0's show up.

0 Karma

Navanitha
Path Finder

index=sample "email1@xxx.com" OR "email2@yyy.com" OR "email3@aaa.com" OR "email4@bbb.com" OR "email5@ccc.com" "ready" "MID"|stats count as Count by Email_ID | append [ search index=sample "email1@xxx.com" OR "email2@yyy.com" OR "email3@aaa.com" OR "email4@bbb.com" OR "email5@ccc.com" "ready" "MID"| stats count as "Total Emails sent out", last(_time) as "EmailSent" | convert ctime("EmailSent") as "Last email sent" | table "Last email sent" , "Total Emails sent out" ]

This is my query..I know this looks weird but this is how I made things work till now 😉 Well in the above query, first stats gives the individual count of emails sent out from each email id, and the second search gives the total count of emails sent from all the individual.

0 Karma
Get Updates on the Splunk Community!

Stay Connected: Your Guide to May Tech Talks, Office Hours, and Webinars!

Take a look below to explore our upcoming Community Office Hours, Tech Talks, and Webinars this month. This ...

They're back! Join the SplunkTrust and MVP at .conf24

With our highly anticipated annual conference, .conf, comes the fez-wearers you can trust! The SplunkTrust, as ...

Enterprise Security Content Update (ESCU) | New Releases

Last month, the Splunk Threat Research Team had two releases of new security content via the Enterprise ...