threshold_mapper.ts 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. export class ThresholdMapper {
  2. static alertToGraphThresholds(panel) {
  3. for (var i = 0; i < panel.alert.conditions.length; i++) {
  4. let condition = panel.alert.conditions[i];
  5. if (condition.type !== 'query') {
  6. continue;
  7. }
  8. var evaluator = condition.evaluator;
  9. var thresholds = (panel.thresholds = []);
  10. switch (evaluator.type) {
  11. case 'gt': {
  12. let value = evaluator.params[0];
  13. thresholds.push({ value: value, op: 'gt' });
  14. break;
  15. }
  16. case 'lt': {
  17. let value = evaluator.params[0];
  18. thresholds.push({ value: value, op: 'lt' });
  19. break;
  20. }
  21. case 'outside_range': {
  22. let value1 = evaluator.params[0];
  23. let value2 = evaluator.params[1];
  24. if (value1 > value2) {
  25. thresholds.push({ value: value1, op: 'gt' });
  26. thresholds.push({ value: value2, op: 'lt' });
  27. } else {
  28. thresholds.push({ value: value1, op: 'lt' });
  29. thresholds.push({ value: value2, op: 'gt' });
  30. }
  31. break;
  32. }
  33. case 'within_range': {
  34. let value1 = evaluator.params[0];
  35. let value2 = evaluator.params[1];
  36. if (value1 > value2) {
  37. thresholds.push({ value: value1, op: 'lt' });
  38. thresholds.push({ value: value2, op: 'gt' });
  39. } else {
  40. thresholds.push({ value: value1, op: 'gt' });
  41. thresholds.push({ value: value2, op: 'lt' });
  42. }
  43. break;
  44. }
  45. }
  46. break;
  47. }
  48. for (var t of panel.thresholds) {
  49. t.fill = true;
  50. t.line = true;
  51. t.colorMode = 'critical';
  52. }
  53. var updated = true;
  54. return updated;
  55. }
  56. }