Splunk Search

Why is the 'foreach' command losing event data?

jpawloski
Path Finder

I'm running Splunk 6.2. I'm dealing with events that have varying amounts of multivalue fields (some events have one, others have up to 12+). The fields follow a field_name0001naming convention, like so :

 base search | eval dataReceived="" | foreach datarcvd_000* [eval dataReceived=dataReceived."<<FIELD>>"." ".'<<FIELD>>'." " ] | table _time dataReceived

When I run this against a week's worth of events, there are several that return nothing in the dataReceived field despite the raw event fields being present, and it's always the same handful of events that return null. But what really throws me is that if I filter the base search to return a single uncooperative event, the foreach works and it suddenly starts returning data in dataReceived as expect. What gives?

0 Karma
1 Solution

woodcock
Esteemed Legend

Try this:

base search
| eval dataReceived=""
| foreach datarcvd_000* [eval dataReceived=if(isnotnull(<<FIELD>>), dataReceived."<<FIELD>>"." ".'<<FIELD>>'." ", dataReceived]
| table _time dataReceived

View solution in original post

woodcock
Esteemed Legend

Try this:

base search
| eval dataReceived=""
| foreach datarcvd_000* [eval dataReceived=if(isnotnull(<<FIELD>>), dataReceived."<<FIELD>>"." ".'<<FIELD>>'." ", dataReceived]
| table _time dataReceived

woodcock
Esteemed Legend

If any event does not contain ALL possible datarcvd_000* values, then your original eval will fail.

0 Karma

jpawloski
Path Finder

You've done it once again, woodcock. Thanks!

0 Karma
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

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 ...