alert_def.ts 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. ///<reference path="../../headers/common.d.ts" />
  2. import _ from 'lodash';
  3. import {
  4. QueryPartDef,
  5. QueryPart,
  6. } from 'app/core/components/query_part/query_part';
  7. var alertQueryDef = new QueryPartDef({
  8. type: 'query',
  9. params: [
  10. {name: "queryRefId", type: 'string', dynamicLookup: true},
  11. {name: "from", type: "string", options: ['1s', '10s', '1m', '5m', '10m', '15m', '1h']},
  12. {name: "to", type: "string", options: ['now']},
  13. ],
  14. defaultParams: ['#A', '5m', 'now', 'avg']
  15. });
  16. var conditionTypes = [
  17. {text: 'Query', value: 'query'},
  18. ];
  19. var evalFunctions = [
  20. {text: 'IS ABOVE', value: 'gt'},
  21. {text: 'IS BELOW', value: 'lt'},
  22. {text: 'IS OUTSIDE RANGE', value: 'outside_range'},
  23. {text: 'IS WITHIN RANGE', value: 'within_range'},
  24. {text: 'HAS NO VALUE' , value: 'no_value'}
  25. ];
  26. var evalOperators = [
  27. {text: 'OR', value: 'or'},
  28. {text: 'AND', value: 'and'},
  29. ];
  30. var reducerTypes = [
  31. {text: 'avg()', value: 'avg'},
  32. {text: 'min()', value: 'min'},
  33. {text: 'max()', value: 'max'},
  34. {text: 'sum()' , value: 'sum'},
  35. {text: 'count()', value: 'count'},
  36. {text: 'last()', value: 'last'},
  37. ];
  38. var noDataModes = [
  39. {text: 'Alerting', value: 'alerting'},
  40. {text: 'No Data', value: 'no_data'},
  41. {text: 'Keep Last State', value: 'keep_state'},
  42. ];
  43. var executionErrorModes = [
  44. {text: 'Alerting', value: 'alerting'},
  45. {text: 'Keep Last State', value: 'keep_state'},
  46. ];
  47. function createReducerPart(model) {
  48. var def = new QueryPartDef({type: model.type, defaultParams: []});
  49. return new QueryPart(model, def);
  50. }
  51. function getStateDisplayModel(state) {
  52. switch (state) {
  53. case 'ok': {
  54. return {
  55. text: 'OK',
  56. iconClass: 'icon-gf icon-gf-online',
  57. stateClass: 'alert-state-ok'
  58. };
  59. }
  60. case 'alerting': {
  61. return {
  62. text: 'ALERTING',
  63. iconClass: 'icon-gf icon-gf-critical',
  64. stateClass: 'alert-state-critical'
  65. };
  66. }
  67. case 'no_data': {
  68. return {
  69. text: 'NO DATA',
  70. iconClass: "fa fa-question",
  71. stateClass: 'alert-state-warning'
  72. };
  73. }
  74. case 'execution_error': {
  75. return {
  76. text: 'EXECUTION ERROR',
  77. iconClass: 'icon-gf icon-gf-critical',
  78. stateClass: 'alert-state-critical'
  79. };
  80. }
  81. case 'paused': {
  82. return {
  83. text: 'paused',
  84. iconClass: "fa fa-pause",
  85. stateClass: 'alert-state-paused'
  86. };
  87. }
  88. case 'pending': {
  89. return {
  90. text: 'PENDING',
  91. iconClass: "fa fa-exclamation",
  92. stateClass: 'alert-state-warning'
  93. };
  94. }
  95. }
  96. }
  97. function joinEvalMatches(matches, seperator: string) {
  98. return _.reduce(matches, (res, ev)=> {
  99. if (ev.Metric !== undefined && ev.Value !== undefined) {
  100. res.push(ev.Metric + "=" + ev.Value);
  101. }
  102. return res;
  103. }, []).join(seperator);
  104. }
  105. export default {
  106. alertQueryDef: alertQueryDef,
  107. getStateDisplayModel: getStateDisplayModel,
  108. conditionTypes: conditionTypes,
  109. evalFunctions: evalFunctions,
  110. evalOperators: evalOperators,
  111. noDataModes: noDataModes,
  112. executionErrorModes: executionErrorModes,
  113. reducerTypes: reducerTypes,
  114. createReducerPart: createReducerPart,
  115. joinEvalMatches: joinEvalMatches,
  116. };