Splunk Search

Inline Variable Definitions and Expansions With Eval

niall_munnelly
Path Finder

Hiya,

I swear I knew how to do this without macros, which seem like overkill, but I've lost it. Here's a simple example - define a field and expand that, so my search uses the value of that field:

eval hostname=server1| search host=%{hostname}

I've tried the usual shell and python syntax for variables as well as Splunk's token syntax , search host=$hostname$, but I'm getting zero results across the board, because it;s searching for the literal string. What do I need to do to expand that "hostname" variable/field? Thanks.

martin_mueller
SplunkTrust
SplunkTrust

Another guess, are you looking for this?

... | eval hostname = "server1" | where host=hostname
0 Karma

lguinn2
Legend

Are you thinking of the foreach command?

Doc page: foreach

There is also map, but that seems a bit far off the mark: map

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