Splunk Search

How to create a search that shows a daily message count and the average for each direction?

weetabixsplunk
Explorer

I'm trying to create a search that shows a daily message count (both inbound and outobound) and the average for each direction. Although it doesn't give me any errors, when the table gets created, the results show as zero (I know this is inaccurate as I pulled a message trace from o365 to confirm).

 

index=vs_email sampledesign@victoriasecret.com
| eval direction=case(RecipientAddress="sampledesign@victoriasecret.com", "inbound", RecipientAddress!="sampledesign@victoriasecret.com", "outbound")
| dedup MessageId
| bin _time span=1d
| eventstats count(direction="inbound") as inbound_count
| eventstats count(direction="outbound") as outbound_count
| dedup _time
| eventstats avg(inbound_count) as average_inbound_count
| eventstats avg(outbound_count) as average_outbound_count
| table inbound_count outbound_count average_inbound_count average_outbound_count

 

All of the results are showing as zero. Any help would be much appreciated.

Thanks!

Labels (2)
0 Karma
1 Solution

richgalloway
SplunkTrust
SplunkTrust

The stats, eventstats, and streamstats expect field names rather than expressions.   To use an expression, embed the eval function.

index=vs_email sampledesign@victoriasecret.com
| eval direction=case(RecipientAddress="sampledesign@victoriasecret.com", "inbound", RecipientAddress!="sampledesign@victoriasecret.com", "outbound")
| dedup MessageId
| bin _time span=1d
| eventstats count(eval(direction="inbound")) as inbound_count
| eventstats count(eval(direction="outbound")) as outbound_count
| dedup _time
| eventstats avg(inbound_count) as average_inbound_count
| eventstats avg(outbound_count) as average_outbound_count
| table inbound_count outbound_count average_inbound_count average_outbound_count
---
If this reply helps you, Karma would be appreciated.

View solution in original post

0 Karma

weetabixsplunk
Explorer

Thank you!! ❤️

0 Karma

bowesmana
SplunkTrust
SplunkTrust

You do not need to make your search so complicated - using eventstats is not often needed and is a slow command to run. You can do it with stats, which will be far more efficient than 4 eventstats calls.

 

index=vs_email sampledesign@victoriasecret.com
| eval direction=case(RecipientAddress="sampledesign@victoriasecret.com", "inbound", RecipientAddress!="sampledesign@victoriasecret.com", "outbound")
| dedup MessageId
| bin _time span=1d
| stats count(eval(direction="inbound")) as inbound_count count(eval(direction="outbound")) as outbound_count by _time
| eventstats avg(inbound_count) as average_inbound_count avg(outbound_count) as average_outbound_count
| table _time inbound_count outbound_count average_inbound_count average_outbound_count

 

so

  • bin _time - will allow you to group by day
  • stats count... - will count the inbound and outbound messages by day (by _time at end)
  • eventstats will then calculate the average of counts for the days

 

0 Karma

richgalloway
SplunkTrust
SplunkTrust

The stats, eventstats, and streamstats expect field names rather than expressions.   To use an expression, embed the eval function.

index=vs_email sampledesign@victoriasecret.com
| eval direction=case(RecipientAddress="sampledesign@victoriasecret.com", "inbound", RecipientAddress!="sampledesign@victoriasecret.com", "outbound")
| dedup MessageId
| bin _time span=1d
| eventstats count(eval(direction="inbound")) as inbound_count
| eventstats count(eval(direction="outbound")) as outbound_count
| dedup _time
| eventstats avg(inbound_count) as average_inbound_count
| eventstats avg(outbound_count) as average_outbound_count
| table inbound_count outbound_count average_inbound_count average_outbound_count
---
If this reply helps you, Karma would be appreciated.
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 ...