Forum Discussion

JaredM's avatar
JaredM
Icon for Neophyte rankNeophyte
2 years ago

Complex Goovy Datapoint Conditional Statement

I would like to construct an evaluation in a complex datapoint for disk volume--my goals is to evaluate if a disk is both above 90% capacity and has less than 100GB space available. The current thresholds only based on percentages are less valuable with high capacity volumes.

This is a WMI collection type, and I have been able to return the values of theses variables:
output["FREESPACE"] 
output["CAPACITY"]

However, as soon as I attempt to put conditions into a groovy statement I am not able to return a value. I want to confirm that performing conditional statements is possible, and if so if anyone has an example of a statement I could borrow as a template.

I have tried this with no success so far:

if (((output["CAPACITY"]-output["FREESPACE"])/output["CAPACITY"])*100,output["FREESPACE"]/1024/1024/1024) {

    return(1);

} else {

    return(0);

}


even a simple operation doesn’t work, like this:

testSpace = output["FREESPACE"] - output["CAPACITY"];

return (testSpace);

Any help is appreciated.

  • thanks for your suggestion, I adjusted the code and completed it with a regular complex datapoint:

    if(&&(lt(FreeSpace/1024/1024/1024,100),gt(100*(Capacity-FreeSpace)/Capacity,90)) & lt(Capacity/1024/1024/1024,200),1,0)

    For me this addresses what I needed--I can now throw an alert if large volumes are:

    • less than 100GB AND over 90% used
    • includes a check to exclude drives below 200GB (in that case we depend upon a different datapoint which alert checking for a static threshold of 50GB free, on C:\ drives)
  • Anonymous's avatar
    Anonymous

    Why groovy? Just make a regular complex datapoint and do your calculation there. It supports lt(), gt(), eq(), if(), and other logic functions.

  • As another example, which makes me feel like I don’t get this or something is broken, if I use the following code…

    output["FREESPACE"] - output["CAPACITY"]

    the result is the same as:

    output["FREESPACE"]