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
Legend

@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") 
---
What goes around comes around. If it helps, hit it with Karma 🙂

View solution in original post

0 Karma

renjith_nair
Legend

@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") 
---
What goes around comes around. If it helps, hit it with Karma 🙂
0 Karma

jip31
Motivator

perfect thanks renjith

0 Karma
Get Updates on the Splunk Community!

Aligning Observability Costs with Business Value: Practical Strategies

 Join us for an engaging Tech Talk on Aligning Observability Costs with Business Value: Practical ...

Mastering Data Pipelines: Unlocking Value with Splunk

 In today's AI-driven world, organizations must balance the challenges of managing the explosion of data with ...

Splunk Up Your Game: Why It's Time to Embrace Python 3.9+ and OpenSSL 3.0

Did you know that for Splunk Enterprise 9.4, Python 3.9 is the default interpreter? This shift is not just a ...