8 years ago
Clear an alert with a NaN value
I recently wrote a datasource that pulled an API and alerted when the return value was greater than 0
The problem I ran into is the API never returned a 0, instead it would return NaN. I worked around this issue by using Key = Value datapoints and a "if (strv.isEmpty) {" statement. Basically, if their is a value returned the output in the script will be "events=[returned value]" the same as most key=value datapoints. If the returned value is empty, the script will fill out the entire string returning "events=0" which puts a 0 in the datapoint and allows the alert to clear.
This a nice workaround for a LogicMonitor Admin's bag of tricks.
//Print KeyValue
strv = response_obj['results']['2'];
if ( strv.isEmpty() ) {
println "events=0"
} else {
println "events=" + strv;
}
return(0);