alert_def.ts 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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', '24h', '48h']},
  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 alertStateSortScore = {
  20. alerting: 1,
  21. no_data: 2,
  22. pending: 3,
  23. ok: 4,
  24. paused: 5,
  25. };
  26. var evalFunctions = [
  27. {text: 'IS ABOVE', value: 'gt'},
  28. {text: 'IS BELOW', value: 'lt'},
  29. {text: 'IS OUTSIDE RANGE', value: 'outside_range'},
  30. {text: 'IS WITHIN RANGE', value: 'within_range'},
  31. {text: 'HAS NO VALUE' , value: 'no_value'}
  32. ];
  33. var evalOperators = [
  34. {text: 'OR', value: 'or'},
  35. {text: 'AND', value: 'and'},
  36. ];
  37. var reducerTypes = [
  38. {text: 'avg()', value: 'avg'},
  39. {text: 'min()', value: 'min'},
  40. {text: 'max()', value: 'max'},
  41. {text: 'sum()' , value: 'sum'},
  42. {text: 'count()', value: 'count'},
  43. {text: 'last()', value: 'last'},
  44. {text: 'median()', value: 'median'},
  45. ];
  46. var noDataModes = [
  47. {text: 'Alerting', value: 'alerting'},
  48. {text: 'No Data', value: 'no_data'},
  49. {text: 'Keep Last State', value: 'keep_state'},
  50. {text: 'Ok', value: 'ok'},
  51. ];
  52. var executionErrorModes = [
  53. {text: 'Alerting', value: 'alerting'},
  54. {text: 'Keep Last State', value: 'keep_state'},
  55. ];
  56. function createReducerPart(model) {
  57. var def = new QueryPartDef({type: model.type, defaultParams: []});
  58. return new QueryPart(model, def);
  59. }
  60. function getStateDisplayModel(state) {
  61. switch (state) {
  62. case 'ok': {
  63. return {
  64. text: 'OK',
  65. iconClass: 'icon-gf icon-gf-online',
  66. stateClass: 'alert-state-ok'
  67. };
  68. }
  69. case 'alerting': {
  70. return {
  71. text: 'ALERTING',
  72. iconClass: 'icon-gf icon-gf-critical',
  73. stateClass: 'alert-state-critical'
  74. };
  75. }
  76. case 'no_data': {
  77. return {
  78. text: 'NO DATA',
  79. iconClass: "fa fa-question",
  80. stateClass: 'alert-state-warning'
  81. };
  82. }
  83. case 'execution_error': {
  84. return {
  85. text: 'EXECUTION ERROR',
  86. iconClass: 'icon-gf icon-gf-critical',
  87. stateClass: 'alert-state-critical'
  88. };
  89. }
  90. case 'paused': {
  91. return {
  92. text: 'paused',
  93. iconClass: "fa fa-pause",
  94. stateClass: 'alert-state-paused'
  95. };
  96. }
  97. case 'pending': {
  98. return {
  99. text: 'PENDING',
  100. iconClass: "fa fa-exclamation",
  101. stateClass: 'alert-state-warning'
  102. };
  103. }
  104. }
  105. }
  106. function joinEvalMatches(matches, seperator: string) {
  107. return _.reduce(matches, (res, ev)=> {
  108. if (ev.Metric !== undefined && ev.Value !== undefined) {
  109. res.push(ev.Metric + "=" + ev.Value);
  110. }
  111. return res;
  112. }, []).join(seperator);
  113. }
  114. export default {
  115. alertQueryDef: alertQueryDef,
  116. getStateDisplayModel: getStateDisplayModel,
  117. conditionTypes: conditionTypes,
  118. evalFunctions: evalFunctions,
  119. evalOperators: evalOperators,
  120. noDataModes: noDataModes,
  121. executionErrorModes: executionErrorModes,
  122. reducerTypes: reducerTypes,
  123. createReducerPart: createReducerPart,
  124. joinEvalMatches: joinEvalMatches,
  125. alertStateSortScore: alertStateSortScore,
  126. };