alert_def.ts 2.8 KB

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