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);
}
Jared Meidal
Posted 3 years ago·Last reply 3 years ago
5 comments
Jared Meidal
OP3 years agothanks 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!
Chris_Wallis
·3 years agoHi 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.
Jared Meidal
OP3 years agoSorry 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).
Chris_Wallis
·3 years agoHi 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!
LM User
·3 years agoyep, to get that in you use:
the value of the property would be stored in the property variable. More here.