alert_def.ts 2.6 KB

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