Hello,
Writing a flux script in Explore.
We are trying to load data from csv and alert based on threshold (column in csv) for a respective host.
I am getting error at the following line:
crit: (r) => r._value > alert_threshold,
I am not able to figure out what is wrong. How to use variable alert_threshold under monitor.check
Error
**type error @40:29-40:44: [t8206] is not Comparable**
You can run this script as it is to recreate:
import "csv"
import "influxdata/influxdb/monitor"
csvData = "
#datatype,string,long,string,double
#group,false,false,false,false
#default,,,,
,result,table,host,threshold
,mean,0,Computer_1,15.1
,mean,0,Computer_2,20.2
,mean,0,Computer_3,52.62
"
threshold_data = csv.from(csv: csvData)
getFieldValue = (threshold_data=<-,hostname) =>
threshold_data
|> reduce(
identity: {new_threshold: 90.0},
fn: (r,accumulator) => ({
new_threshold:
if r.host == hostname then r.threshold
else accumulator.new_threshold
})
)
alert_threshold=threshold_data
|> getFieldValue(hostname: "A700459-W10")
|>yield()
main_data = from(bucket: "amsv_bucket")
|> range(start: -7d)
|> filter(fn: (r) =>
r._measurement == "Processor" and
r._field == "Percent_Processor_Time"
)
|> group(columns: ["_measurement","host"])
|> aggregateWindow(every: 1d, fn: mean, createEmpty: false)
|> monitor.check(
crit: (r) => r._value > alert_threshold,
messageFn: (r) =>
if r._level == "crit" then "Critical alert for host ${r.host} !!"
else "Things are looking good for host ${r.host}.",
data: {
_check_name: "CPU Utilization (Used Percent_Processor_Time)",
_check_id: "Percent_Processor_Time",
_type: "threshold",
tags: {}
}
)
|> yield(name: "val1")