alert_tab_ctrl.ts 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. metricTargets = [{ refId: '- select query -' } ];
  10. /** @ngInject */
  11. constructor($scope, private $timeout) {
  12. $scope.alertTab = this; //HACK ATTACK!
  13. this.panelCtrl = $scope.ctrl;
  14. this.panel = this.panelCtrl.panel;
  15. this.panel.alerting = this.panel.alerting || {};
  16. this.panel.alerting.aggregator = this.panel.alerting.aggregator || 'avg';
  17. this.panel.alerting.interval = this.panel.alerting.interval || '60s';
  18. this.panel.alerting.queryRange = this.panel.alerting.queryRange || '10m';
  19. this.panel.alerting.warnOperator = this.panel.alerting.warnOperator || '>';
  20. this.panel.alerting.critOperator = this.panel.alerting.critOperator || '>';
  21. this.panel.alerting.title = this.panel.alerting.title || this.panel.title + ' alert';
  22. this.panel.targets.map(target => {
  23. this.metricTargets.push(target);
  24. });
  25. this.panel.alerting.queryRef = this.panel.alerting.queryRef || this.metricTargets[0].refId;
  26. this.convertThresholdsToAlertThresholds();
  27. }
  28. convertThresholdsToAlertThresholds() {
  29. if (this.panel.grid && this.panel.grid.threshold1) {
  30. this.panel.alerting.warnOperator = '>';
  31. this.panel.alerting.warnLevel = this.panel.grid.threshold1;
  32. }
  33. if (this.panel.grid && this.panel.grid.threshold2) {
  34. this.panel.alerting.critOperator = '>';
  35. this.panel.alerting.critLevel = this.panel.grid.threshold2;
  36. }
  37. }
  38. thresholdsUpdated() {
  39. if (this.panel.alerting.warnLevel) {
  40. this.panel.grid.threshold1 = parseInt(this.panel.alerting.warnLevel);
  41. }
  42. if (this.panel.alerting.critLevel) {
  43. this.panel.grid.threshold2 = parseInt(this.panel.alerting.critLevel);
  44. }
  45. this.panelCtrl.render();
  46. }
  47. }
  48. /** @ngInject */
  49. export function graphAlertEditor() {
  50. 'use strict';
  51. return {
  52. restrict: 'E',
  53. scope: true,
  54. templateUrl: 'public/app/plugins/panel/graph/partials/tab_alerting.html',
  55. controller: AlertTabCtrl,
  56. };
  57. }