alert_def.ts 3.0 KB

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