alert_def.ts 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. ///<reference path="../../headers/common.d.ts" />
  2. import {
  3. QueryPartDef,
  4. QueryPart,
  5. } from 'app/core/components/query_part/query_part';
  6. var alertQueryDef = new QueryPartDef({
  7. type: 'query',
  8. params: [
  9. {name: "queryRefId", type: 'string', dynamicLookup: true},
  10. {name: "from", type: "string", options: ['1s', '10s', '1m', '5m', '10m', '15m', '1h']},
  11. {name: "to", type: "string", options: ['now']},
  12. ],
  13. defaultParams: ['#A', '5m', 'now', 'avg']
  14. });
  15. var conditionTypes = [
  16. {text: 'Query', value: 'query'},
  17. ];
  18. var evalFunctions = [
  19. {text: 'IS ABOVE', value: 'gt'},
  20. {text: 'IS BELOW', value: 'lt'},
  21. {text: 'IS OUTSIDE RANGE', value: 'outside_range'},
  22. {text: 'IS WITHIN RANGE', value: 'within_range'},
  23. {text: 'HAS NO VALUE' , value: 'no_value'}
  24. ];
  25. var reducerTypes = [
  26. {text: 'avg()', value: 'avg'},
  27. {text: 'min()', value: 'min'},
  28. {text: 'max()', value: 'max'},
  29. {text: 'sum()' , value: 'sum'},
  30. {text: 'count()', value: 'count'},
  31. ];
  32. var noDataModes = [
  33. {text: 'OK', value: 'ok'},
  34. {text: 'Critical', value: 'critical'},
  35. {text: 'Warning', value: 'warning'},
  36. {text: 'Unknown', value: 'unknown'},
  37. ];
  38. function createReducerPart(model) {
  39. var def = new QueryPartDef({type: model.type, defaultParams: []});
  40. return new QueryPart(model, def);
  41. }
  42. var severityLevels = {
  43. 'critical': {text: 'Critical', iconClass: 'icon-gf icon-gf-critical', stateClass: 'alert-state-critical'},
  44. 'warning': {text: 'Warning', iconClass: 'icon-gf icon-gf-warning', stateClass: 'alert-state-warning'},
  45. };
  46. function getStateDisplayModel(state) {
  47. switch (state) {
  48. case 'ok': {
  49. return {
  50. text: 'OK',
  51. iconClass: 'icon-gf icon-gf-online',
  52. stateClass: 'alert-state-ok'
  53. };
  54. }
  55. case 'critical': {
  56. return {
  57. text: 'CRITICAL',
  58. iconClass: 'icon-gf icon-gf-critical',
  59. stateClass: 'alert-state-critical'
  60. };
  61. }
  62. case 'warning': {
  63. return {
  64. text: 'WARNING',
  65. iconClass: 'icon-gf icon-gf-warning',
  66. stateClass: 'alert-state-warning'
  67. };
  68. }
  69. case 'unknown': {
  70. return {
  71. text: 'UNKNOWN',
  72. iconClass: "fa fa-question",
  73. stateClass: 'alert-state-warning'
  74. };
  75. }
  76. case 'execution_error': {
  77. return {
  78. text: 'EXECUTION ERROR',
  79. iconClass: 'icon-gf icon-gf-critical',
  80. stateClass: 'alert-state-critical'
  81. };
  82. }
  83. case 'paused': {
  84. return {
  85. text: 'paused',
  86. iconClass: "fa fa-pause",
  87. stateClass: 'alert-state-paused'
  88. };
  89. }
  90. }
  91. }
  92. export default {
  93. alertQueryDef: alertQueryDef,
  94. getStateDisplayModel: getStateDisplayModel,
  95. conditionTypes: conditionTypes,
  96. evalFunctions: evalFunctions,
  97. severityLevels: severityLevels,
  98. noDataModes: noDataModes,
  99. reducerTypes: reducerTypes,
  100. createReducerPart: createReducerPart,
  101. };