Installation

Help on if condition in eval

jip31
Motivator

Hi

I use the query below

index="perfmon-fr" sourcetype="perfmon:logicaldisk" instance="C:" counter="% Free Space" 
| dedup host 
| eval time = strftime(_time, "%m/%d/%Y %H:%M") 
| eval Value = round(Value, 1). " %" 
| eval TotalSpace = TotalSpaceKB/1024 
| eval TotalSpace = round(TotalSpace/1024,1). " MB" 
| rename Value as Free_Space 
| eval Free_Space= if(Free_Space>15, "GOOD", "BAD") 
| table Free_Space

But I have always a "BAD" result even if Free_Space < 15
What is the problem please??

Tags (1)
0 Karma
1 Solution

renjith_nair
SplunkTrust
SplunkTrust

@jip31,

| eval Value = round(Value, 1). " %" will result in Value% , for e.g. 80% and then you are doing a numerical comparison against that which is always false.

Try

 | eval Value = round(Value, 1)
 | eval TotalSpace = TotalSpaceKB/1024 
 | eval TotalSpace = round(TotalSpace/1024,1). " MB" 
 | rename Value as Free_Space 
 | eval Free_Space= if(Free_Space>15, "GOOD", "BAD") 
 | table Free_Space

or even simpler

  | eval TotalSpace = TotalSpaceKB/1024 
  | eval TotalSpace = round(TotalSpace/1024,1). " MB" 
  | eval Free_Space = if(Value>15, "GOOD", "BAD") 
Happy Splunking!

View solution in original post

0 Karma

renjith_nair
SplunkTrust
SplunkTrust

@jip31,

| eval Value = round(Value, 1). " %" will result in Value% , for e.g. 80% and then you are doing a numerical comparison against that which is always false.

Try

 | eval Value = round(Value, 1)
 | eval TotalSpace = TotalSpaceKB/1024 
 | eval TotalSpace = round(TotalSpace/1024,1). " MB" 
 | rename Value as Free_Space 
 | eval Free_Space= if(Free_Space>15, "GOOD", "BAD") 
 | table Free_Space

or even simpler

  | eval TotalSpace = TotalSpaceKB/1024 
  | eval TotalSpace = round(TotalSpace/1024,1). " MB" 
  | eval Free_Space = if(Value>15, "GOOD", "BAD") 
Happy Splunking!
0 Karma

jip31
Motivator

perfect thanks renjith

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