Splunk Search

if then to differentiate fields / variables?

rkappler
Explorer

I have data over time on the aging of ssd's that gives me a date, identifying information and a 'health' number. I want to get rates of change of that health number. My search thus far is:
source=new.csv (NOT Health:0 NOT Health:MISSING date=20150407 OR date=20150529 OR date=20150727) | eval combo = IP + Disk | transaction combo
I need to differentiate the health based on date so that I can calculate rates of change based on time interval, in other words I'd like to do:

(MayHealth - AprilHealth)/52 and so on to get the rate of change per day for each date pair.

My problem is I'm floundering figuring out how to differentiate each health. I do programming in several languages but am new to Splunk, so my initial reaction was to do (pseudocode):
if date = 20150407 then health = AprilHealth
elif date = 20150529 the health = MayHealth
else health = JulyHealth

Any suggestions? I think I'm looking for an eval function, or possible a rename, or maybe a rename within an if (is that even possible) but am stuck.

regards, Richard

Tags (1)
0 Karma
1 Solution

rkappler
Explorer

We ended up doing:
...| eval apr=if(date=20150407, Health, NULL) | eval may=if(date=20150529, Health, NULL) | eval jul=if(date=20150727, Health, NULL) | ...

Thanks for the input though, I'm off to try they case statement

View solution in original post

0 Karma

rkappler
Explorer

We ended up doing:
...| eval apr=if(date=20150407, Health, NULL) | eval may=if(date=20150529, Health, NULL) | eval jul=if(date=20150727, Health, NULL) | ...

Thanks for the input though, I'm off to try they case statement

0 Karma

richgalloway
SplunkTrust
SplunkTrust

Perhaps the case statement will do.

... | eval health=case(date = 20150407, AprilHealth, date = 20150529, MayHealth,1=1, JulyHealth) | ...
---
If this reply helps you, Karma would be appreciated.
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!

Defend at Machine Speed: Your Guide to Security Sessions at .conf26

Splunk .conf26   With threats moving at machine speed and attack surfaces expanding across hybrid ...

Where Innovation Takes Flight: The Splunk4Aviation Flight Sim Lands at .conf26

If you hear someone at .conf26 shouting "gear down, GEAR DOWN" across the show floor, you have found us.  The ...

Turn Cisco Telemetry Into Action with Cisco Data Fabric, powered by the Splunk ...

The surge in machine data is already hitting enterprise budgets, and the agentic era will only intensify it. ...