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!

Observability | How to Think About Instrumentation Overhead (White Paper)

Novice observability practitioners are often overly obsessed with performance. They might approach ...

Cloud Platform | Get Resiliency in the Cloud Event (Register Now!)

IDC Report: Enterprises Gain Higher Efficiency and Resiliency With Migration to Cloud  Today many enterprises ...

The Great Resilience Quest: 10th Leaderboard Update

The tenth leaderboard update (11.23-12.05) for The Great Resilience Quest is out &gt;&gt; As our brave ...