grafana/public/app/features/alerting/threshold_mapper.ts

68 lines
1.8 KiB
TypeScript
Raw Normal View History

2016-08-11 08:18:21 -05:00
export class ThresholdMapper {
static alertToGraphThresholds(panel) {
2017-12-20 05:33:33 -06:00
if (panel.type !== 'graph') {
2016-08-11 08:18:21 -05:00
return false;
}
for (var i = 0; i < panel.alert.conditions.length; i++) {
let condition = panel.alert.conditions[i];
2017-12-20 05:33:33 -06:00
if (condition.type !== 'query') {
2016-08-11 08:18:21 -05:00
continue;
}
var evaluator = condition.evaluator;
var thresholds = (panel.thresholds = []);
2016-08-11 08:18:21 -05:00
switch (evaluator.type) {
2017-12-20 05:33:33 -06:00
case 'gt': {
2016-08-11 08:18:21 -05:00
let value = evaluator.params[0];
2017-12-20 05:33:33 -06:00
thresholds.push({ value: value, op: 'gt' });
2016-08-11 08:18:21 -05:00
break;
}
2017-12-20 05:33:33 -06:00
case 'lt': {
2016-08-11 08:18:21 -05:00
let value = evaluator.params[0];
2017-12-20 05:33:33 -06:00
thresholds.push({ value: value, op: 'lt' });
2016-08-11 08:18:21 -05:00
break;
}
2017-12-20 05:33:33 -06:00
case 'outside_range': {
2016-08-11 08:18:21 -05:00
let value1 = evaluator.params[0];
let value2 = evaluator.params[1];
if (value1 > value2) {
2017-12-20 05:33:33 -06:00
thresholds.push({ value: value1, op: 'gt' });
thresholds.push({ value: value2, op: 'lt' });
2016-08-11 08:18:21 -05:00
} else {
2017-12-20 05:33:33 -06:00
thresholds.push({ value: value1, op: 'lt' });
thresholds.push({ value: value2, op: 'gt' });
2016-08-11 08:18:21 -05:00
}
break;
}
2017-12-20 05:33:33 -06:00
case 'within_range': {
2016-08-11 08:18:21 -05:00
let value1 = evaluator.params[0];
let value2 = evaluator.params[1];
if (value1 > value2) {
2017-12-20 05:33:33 -06:00
thresholds.push({ value: value1, op: 'lt' });
thresholds.push({ value: value2, op: 'gt' });
2016-08-11 08:18:21 -05:00
} else {
2017-12-20 05:33:33 -06:00
thresholds.push({ value: value1, op: 'gt' });
thresholds.push({ value: value2, op: 'lt' });
2016-08-11 08:18:21 -05:00
}
break;
}
}
break;
2016-08-11 08:18:21 -05:00
}
for (var t of panel.thresholds) {
t.fill = true;
t.line = true;
2017-12-20 05:33:33 -06:00
t.colorMode = 'critical';
2016-08-11 08:18:21 -05:00
}
var updated = true;
return updated;
}
}