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!

New This Month in Splunk Observability Cloud - Metrics Usage Analytics, Enhanced K8s ...

The latest enhancements across the Splunk Observability portfolio deliver greater flexibility, better data and ...

Alerting Best Practices: How to Create Good Detectors

At their best, detectors and the alerts they trigger notify teams when applications aren’t performing as ...

Discover Powerful New Features in Splunk Cloud Platform: Enhanced Analytics, ...

Hey Splunky people! We are excited to share the latest updates in Splunk Cloud Platform 9.3.2408. In this ...