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") 
Happy Splunking!

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") 
Happy Splunking!
0 Karma

jip31
Motivator

perfect thanks renjith

0 Karma
Get Updates on the Splunk Community!

Extending Observability Content to Splunk Cloud

Watch Now!   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to leverage ...

More Control Over Your Monitoring Costs with Archived Metrics!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...

New in Observability Cloud - Explicit Bucket Histograms

Splunk introduces native support for histograms as a metric data type within Observability Cloud with Explicit ...