Forum Discussion

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

Can token values be evaluated in a complex datapoint?

I would like to construct a conditional datapoint which returns a value if the instance WILDVALUE is equal to a match, otherwise a different value is returned.

Is it possible in expressions or groovy script complex datapoints to include tokens such as ##WILDVALUE##? 

These are some examples which are not currently working:

eq(##WILDVALUE##,"C:\")

or

if(output[##WILDVALUE##]=="C:\") {

    return(1);

} else {

    return(0);

}

  • thanks Chris, this helped me fill in the gap. I’m using this in the WMI DS for WinVolumeUsage, and this datapoint is now polling as I need it to evaluate only the remaining free space on C: drives. 

    osDrive = property = instanceProps.get("auto.driveletter")

    freeSpace_scale = (output["FREESPACE"].toFloat()/1024/1024/1024)

    if(osDrive=="C:"){

    return freeSpace_scale

    }

    Thanks again for the assistance!

  • Hi Jared, Apologies for the delayed response.

    It’s not something I have lots of experience with (To be honest I’d usually perform this logic in the collection script itself and not complex datapoint) but I may have a working solution:
     

    Essentially, I explicitly defined the output as a float before dividing as I know Groovy has a tendency to label everything as strings by default.

    wv = "##WILDVALUE##"

    if(wv=~"AWS"){

    bps = output["BYTESRECEIVEDPERSEC"] 

    bps_scale = (output["BYTESRECEIVEDPERSEC"].toFloat())/1024

    return bps_scale

    }

    else{

    return 0

    }
      

    (Note the default datapoint is a derive so I needed to make it a gauge as thats whats being pulled using the OUTPUT[] method.

  • Sorry I didn’t state what type of DS this was--it is WMI.

    Your replies were both a lot of help. I added DRIVELETTER as a WMI class property name, and then constructed this groovy script with the complex datapoint name “GB_Free_C_CHECK”:

    osDrive = property = instanceProps.get("auto.driveletter")

    if(osDrive=="C:"){

    return 1

    } else{

    return 0

    }

    then, I’m working off that datapoint to evaluate another expression datapoint:
    if(GB_Free_C_CHECK,FreeSpace/1024/1024/1024,0)
     

    Ideally I would like to combine both these into one for simplicity. But I can’t find how to evaluate instance properties within an expression (##INSTANCE## doesn’t validate), or perform math operations within a groovy statement (anything like freeSpace = (output["FREESPACE"] / 1024) returns NaN).

  • Hi Jared, I created this Groovy scripted Complex datapoint which returns 1 if the wildvalue is “drive1” and 0 otherwise

    wv = "##WILDVALUE##"

    if(wv=="drive1"){

    return 1   

    }

    else{

    return 0

    }   

     

    It uses the same approach that can be used to access the WILDVALUE in a standard data collection script.


     

    Some things to note, the DS I tested on was a SCRIPT (I don’t know with certainty if this datapoint would work in the same way for other collection/discovery methods).

    Hope this helps!

  • Anonymous's avatar
    Anonymous

    yep, to get that in you use:

    // get a host level property
    property = hostProps.get("<propname>")
    // get an instance level property
    property = instanceProps.get("<propname>")
    // get a task level property (in case you don't know where the prop might be)
    property = taskProps.get("<propname>")

    the value of the property would be stored in the property variable. More here.