alert_tab_ctrl.ts 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. ///<reference path="../../../headers/common.d.ts" />
  2. import _ from 'lodash';
  3. import $ from 'jquery';
  4. import angular from 'angular';
  5. export class AlertTabCtrl {
  6. panel: any;
  7. panelCtrl: any;
  8. alerting: any;
  9. /** @ngInject */
  10. constructor($scope) {
  11. $scope.alertTab = this; //HACK ATTACK!
  12. this.panelCtrl = $scope.ctrl;
  13. this.panel = this.panelCtrl.panel;
  14. this.panel.alerting = this.panel.alerting || {};
  15. this.panel.alerting.aggregator = this.panel.alerting.aggregator || 'avg';
  16. this.panel.alerting.interval = this.panel.alerting.interval || '60s';
  17. this.panel.alerting.queryRange = this.panel.alerting.queryRange || '10m';
  18. this.convertThresholdsToAlertThresholds();
  19. }
  20. convertThresholdsToAlertThresholds() {
  21. if (this.panel.grid && this.panel.grid.threshold1) {
  22. this.panel.alerting.warnLevel = '< ' + this.panel.grid.threshold1;
  23. }
  24. if (this.panel.grid && this.panel.grid.threshold2) {
  25. this.panel.alerting.critLevel = '< ' + this.panel.grid.threshold2;
  26. }
  27. }
  28. thresholdsUpdated() {
  29. if (this.panel.alerting.warnLevel) {
  30. var threshold = this.panel.alerting.warnLevel
  31. .replace(' ', '')
  32. .replace('>', '')
  33. .replace('<', '')
  34. .replace('>=', '')
  35. .replace('<=', '');
  36. this.panel.grid.threshold1 = parseInt(threshold);
  37. }
  38. if (this.panel.alerting.critLevel) {
  39. var threshold = this.panel.alerting.critLevel
  40. .replace(' ', '')
  41. .replace('>', '')
  42. .replace('<', '')
  43. .replace('>=', '')
  44. .replace('<=', '');
  45. this.panel.grid.threshold2 = parseInt(threshold);
  46. }
  47. this.panelCtrl.render();
  48. }
  49. }
  50. /** @ngInject */
  51. export function graphAlertEditor() {
  52. 'use strict';
  53. return {
  54. restrict: 'E',
  55. scope: true,
  56. templateUrl: 'public/app/plugins/panel/graph/partials/tab_alerting.html',
  57. controller: AlertTabCtrl,
  58. };
  59. }