Splunk Search

Manipulating data using conditionals, eval, or custom commands?

nickbyrne
New Member

We have enterprise data which we are querying and running through some 'hypothetical' business situations. So, ideally we'd like to perturb the data from time to time (and within date/time brackets) so as to inspect what that might look like in a report/graph.

Has anyone come across something like this? Can you use conditionals within streaming custom command say, or EVAL? By this I mean we could even get away with using an if statement to check whether the event occurred within a daterange, and if so, apply some logic to it and output to table using EVAL.

Looking for what the best approach here might be?


Edit: So consider 30 days of data. I might want to artificially raise 'bandwidth' by 20% for days 7 through
15.

0 Karma

sideview
SplunkTrust
SplunkTrust

You can use the if() function or the case() function in the eval command. When used in conjunction with all the other functions available to the eval command, you can do a wide assortment of manipulations.

For instance if you want to add a custom field to the events that reflects whether they occurred in the last 24 hours or merely in the last week or just in the last month, you could do

| eval period=case(_time>relative_time(now(), "-24h"),"last 24 hours",_time>relative_time(now(),"-7d"), "last 7 days",_time>relative_time(now(),"-30d"),"last 30 days")

http://docs.splunk.com/Documentation/Splunk/6.1.3/SearchReference/CommonEvalFunctions

Effectively this gives you powerful tools to filter, transform and change the key value pairs in your result rows. Trying to conditionally present those results however, takes you into a different realm. There you can use the Sideview modules ResultsValueSetter to pull dynamic field values down to the UI, and other modules to affect presentation or to present them entirely different ways. A pretty different topic though.

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Painting a Clearer Picture: Creating Cross-Domain Visibility with AI Canvas

Watch Now Painting a Clearer Picture: Creating Cross-Domain Visibility with AI Canvas     Do you ever feel ...

Build and Launch AI Agents from Your Splunk Workflows

Replay Tech Talk Build and Launch AI Agents from Your Splunk Workflows     We’ve all been there: juggling ...

index This | What kind of room has no doors?

IndexEducation Cover Art Banner Cisco.png August 2026 Edition  Hayyy Splunk Education Enthusiasts and the ...