alert_def.ts 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. {text: 'median()', value: 'median'},
  38. ];
  39. var noDataModes = [
  40. {text: 'Alerting', value: 'alerting'},
  41. {text: 'No Data', value: 'no_data'},
  42. {text: 'Keep Last State', value: 'keep_state'},
  43. ];
  44. var executionErrorModes = [
  45. {text: 'Alerting', value: 'alerting'},
  46. {text: 'Keep Last State', value: 'keep_state'},
  47. ];
  48. function createReducerPart(model) {
  49. var def = new QueryPartDef({type: model.type, defaultParams: []});
  50. return new QueryPart(model, def);
  51. }
  52. function getStateDisplayModel(state) {
  53. switch (state) {
  54. case 'ok': {
  55. return {
  56. text: 'OK',
  57. iconClass: 'icon-gf icon-gf-online',
  58. stateClass: 'alert-state-ok'
  59. };
  60. }
  61. case 'alerting': {
  62. return {
  63. text: 'ALERTING',
  64. iconClass: 'icon-gf icon-gf-critical',
  65. stateClass: 'alert-state-critical'
  66. };
  67. }
  68. case 'no_data': {
  69. return {
  70. text: 'NO DATA',
  71. iconClass: "fa fa-question",
  72. stateClass: 'alert-state-warning'
  73. };
  74. }
  75. case 'execution_error': {
  76. return {
  77. text: 'EXECUTION ERROR',
  78. iconClass: 'icon-gf icon-gf-critical',
  79. stateClass: 'alert-state-critical'
  80. };
  81. }
  82. case 'paused': {
  83. return {
  84. text: 'paused',
  85. iconClass: "fa fa-pause",
  86. stateClass: 'alert-state-paused'
  87. };
  88. }
  89. case 'pending': {
  90. return {
  91. text: 'PENDING',
  92. iconClass: "fa fa-exclamation",
  93. stateClass: 'alert-state-warning'
  94. };
  95. }
  96. }
  97. }
  98. function joinEvalMatches(matches, seperator: string) {
  99. return _.reduce(matches, (res, ev)=> {
  100. if (ev.Metric !== undefined && ev.Value !== undefined) {
  101. res.push(ev.Metric + "=" + ev.Value);
  102. }
  103. return res;
  104. }, []).join(seperator);
  105. }
  106. export default {
  107. alertQueryDef: alertQueryDef,
  108. getStateDisplayModel: getStateDisplayModel,
  109. conditionTypes: conditionTypes,
  110. evalFunctions: evalFunctions,
  111. evalOperators: evalOperators,
  112. noDataModes: noDataModes,
  113. executionErrorModes: executionErrorModes,
  114. reducerTypes: reducerTypes,
  115. createReducerPart: createReducerPart,
  116. joinEvalMatches: joinEvalMatches,
  117. };