alert_tab_ctrl.ts 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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.warnOperator = '<';
  23. this.panel.alerting.warnLevel = this.panel.grid.threshold1;
  24. }
  25. if (this.panel.grid && this.panel.grid.threshold2) {
  26. this.panel.alerting.critOperator = '<';
  27. this.panel.alerting.critLevel = this.panel.grid.threshold2;
  28. }
  29. }
  30. thresholdsUpdated() {
  31. if (this.panel.alerting.warnLevel) {
  32. this.panel.grid.threshold1 = parseInt(this.panel.alerting.warnLevel);
  33. }
  34. if (this.panel.alerting.critLevel) {
  35. this.panel.grid.threshold2 = parseInt(this.panel.alerting.critLevel);
  36. }
  37. this.panelCtrl.render();
  38. }
  39. }
  40. /** @ngInject */
  41. export function graphAlertEditor() {
  42. 'use strict';
  43. return {
  44. restrict: 'E',
  45. scope: true,
  46. templateUrl: 'public/app/plugins/panel/graph/partials/tab_alerting.html',
  47. controller: AlertTabCtrl,
  48. };
  49. }