alert_def.ts 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. function createReducerPart(model) {
  33. var def = new QueryPartDef({type: model.type, defaultParams: []});
  34. return new QueryPart(model, def);
  35. }
  36. var severityLevels = {
  37. 'critical': {text: 'Critical', iconClass: 'icon-gf icon-gf-critical', stateClass: 'alert-state-critical'},
  38. 'warning': {text: 'Warning', iconClass: 'icon-gf icon-gf-warning', stateClass: 'alert-state-warning'},
  39. };
  40. function getStateDisplayModel(state) {
  41. switch (state) {
  42. case 'ok': {
  43. return {
  44. text: 'OK',
  45. iconClass: 'icon-gf icon-gf-online',
  46. stateClass: 'alert-state-ok'
  47. };
  48. }
  49. case 'critical': {
  50. return {
  51. text: 'CRITICAL',
  52. iconClass: 'icon-gf icon-gf-critical',
  53. stateClass: 'alert-state-critical'
  54. };
  55. }
  56. case 'warning': {
  57. return {
  58. text: 'WARNING',
  59. iconClass: 'icon-gf icon-gf-warning',
  60. stateClass: 'alert-state-warning'
  61. };
  62. }
  63. case 'pending': {
  64. return {
  65. text: 'PENDING',
  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. }
  85. }
  86. export default {
  87. alertQueryDef: alertQueryDef,
  88. getStateDisplayModel: getStateDisplayModel,
  89. conditionTypes: conditionTypes,
  90. evalFunctions: evalFunctions,
  91. severityLevels: severityLevels,
  92. reducerTypes: reducerTypes,
  93. createReducerPart: createReducerPart,
  94. };