| 
									
										
										
										
											2017-12-20 19:33:33 +08:00
										 |  |  | import _ from 'lodash'; | 
					
						
							| 
									
										
										
										
											2018-11-21 00:09:47 +08:00
										 |  |  | import coreModule from 'app/core/core_module'; | 
					
						
							| 
									
										
										
										
											2018-09-02 22:11:21 +08:00
										 |  |  | import { ThresholdMapper } from './state/ThresholdMapper'; | 
					
						
							| 
									
										
										
										
											2017-12-20 19:33:33 +08:00
										 |  |  | import { QueryPart } from 'app/core/components/query_part/query_part'; | 
					
						
							| 
									
										
										
										
											2018-09-02 22:11:21 +08:00
										 |  |  | import alertDef from './state/alertDef'; | 
					
						
							| 
									
										
										
										
											2017-12-20 19:33:33 +08:00
										 |  |  | import config from 'app/core/config'; | 
					
						
							|  |  |  | import appEvents from 'app/core/app_events'; | 
					
						
							| 
									
										
										
										
											2020-01-21 17:08:07 +08:00
										 |  |  | import { getBackendSrv } from '@grafana/runtime'; | 
					
						
							| 
									
										
										
										
											2019-05-13 15:38:19 +08:00
										 |  |  | import { DashboardSrv } from '../dashboard/services/DashboardSrv'; | 
					
						
							|  |  |  | import DatasourceSrv from '../plugins/datasource_srv'; | 
					
						
							| 
									
										
										
										
											2019-12-11 18:11:37 +08:00
										 |  |  | import { DataQuery, DataSourceApi } from '@grafana/data'; | 
					
						
							| 
									
										
										
										
											2019-05-13 15:38:19 +08:00
										 |  |  | import { PanelModel } from 'app/features/dashboard/state'; | 
					
						
							| 
									
										
										
										
											2019-09-23 20:17:00 +08:00
										 |  |  | import { getDefaultCondition } from './getAlertingValidationMessage'; | 
					
						
							| 
									
										
										
										
											2019-10-14 16:27:47 +08:00
										 |  |  | import { CoreEvents } from 'app/types'; | 
					
						
							| 
									
										
										
										
											2020-01-14 17:13:34 +08:00
										 |  |  | import kbn from 'app/core/utils/kbn'; | 
					
						
							| 
									
										
										
										
											2020-01-21 17:08:07 +08:00
										 |  |  | import { promiseToDigest } from 'app/core/utils/promiseToDigest'; | 
					
						
							| 
									
										
										
										
											2016-07-19 17:24:27 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-28 22:03:14 +08:00
										 |  |  | export class AlertTabCtrl { | 
					
						
							| 
									
										
										
										
											2019-05-13 15:38:19 +08:00
										 |  |  |   panel: PanelModel; | 
					
						
							| 
									
										
										
										
											2016-04-28 22:03:14 +08:00
										 |  |  |   panelCtrl: any; | 
					
						
							| 
									
										
										
										
											2016-07-31 15:31:32 +08:00
										 |  |  |   subTabIndex: number; | 
					
						
							| 
									
										
										
										
											2016-08-11 21:18:21 +08:00
										 |  |  |   conditionTypes: any; | 
					
						
							| 
									
										
										
										
											2016-06-11 16:54:24 +08:00
										 |  |  |   alert: any; | 
					
						
							| 
									
										
										
										
											2016-07-19 17:24:27 +08:00
										 |  |  |   conditionModels: any; | 
					
						
							| 
									
										
										
										
											2016-08-11 21:18:21 +08:00
										 |  |  |   evalFunctions: any; | 
					
						
							| 
									
										
										
										
											2016-11-13 05:16:46 +08:00
										 |  |  |   evalOperators: any; | 
					
						
							| 
									
										
										
										
											2016-09-07 02:40:12 +08:00
										 |  |  |   noDataModes: any; | 
					
						
							| 
									
										
										
										
											2016-11-07 19:42:39 +08:00
										 |  |  |   executionErrorModes: any; | 
					
						
							| 
									
										
										
										
											2019-05-13 15:38:19 +08:00
										 |  |  |   addNotificationSegment: any; | 
					
						
							|  |  |  |   notifications: any; | 
					
						
							|  |  |  |   alertNotifications: any; | 
					
						
							| 
									
										
										
										
											2016-08-18 15:03:46 +08:00
										 |  |  |   error: string; | 
					
						
							| 
									
										
										
										
											2016-08-18 15:58:20 +08:00
										 |  |  |   appSubUrl: string; | 
					
						
							| 
									
										
										
										
											2016-08-30 19:22:59 +08:00
										 |  |  |   alertHistory: any; | 
					
						
							| 
									
										
										
										
											2019-06-06 19:29:30 +08:00
										 |  |  |   newAlertRuleTag: any; | 
					
						
							| 
									
										
										
										
											2020-01-14 17:13:34 +08:00
										 |  |  |   alertingMinIntervalSecs: number; | 
					
						
							|  |  |  |   alertingMinInterval: string; | 
					
						
							|  |  |  |   frequencyWarning: any; | 
					
						
							| 
									
										
										
										
											2016-07-19 22:15:26 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-28 22:03:14 +08:00
										 |  |  |   /** @ngInject */ | 
					
						
							| 
									
										
										
										
											2017-12-19 23:06:54 +08:00
										 |  |  |   constructor( | 
					
						
							| 
									
										
										
										
											2019-05-13 15:38:19 +08:00
										 |  |  |     private $scope: any, | 
					
						
							|  |  |  |     private dashboardSrv: DashboardSrv, | 
					
						
							|  |  |  |     private uiSegmentSrv: any, | 
					
						
							|  |  |  |     private datasourceSrv: DatasourceSrv | 
					
						
							| 
									
										
										
										
											2017-12-19 23:06:54 +08:00
										 |  |  |   ) { | 
					
						
							| 
									
										
										
										
											2016-04-28 22:03:14 +08:00
										 |  |  |     this.panelCtrl = $scope.ctrl; | 
					
						
							|  |  |  |     this.panel = this.panelCtrl.panel; | 
					
						
							| 
									
										
										
										
											2016-07-26 18:29:52 +08:00
										 |  |  |     this.$scope.ctrl = this; | 
					
						
							| 
									
										
										
										
											2016-07-31 15:31:32 +08:00
										 |  |  |     this.subTabIndex = 0; | 
					
						
							| 
									
										
										
										
											2016-08-11 21:18:21 +08:00
										 |  |  |     this.evalFunctions = alertDef.evalFunctions; | 
					
						
							| 
									
										
										
										
											2016-11-13 05:16:46 +08:00
										 |  |  |     this.evalOperators = alertDef.evalOperators; | 
					
						
							| 
									
										
										
										
											2016-08-11 21:18:21 +08:00
										 |  |  |     this.conditionTypes = alertDef.conditionTypes; | 
					
						
							| 
									
										
										
										
											2016-09-07 02:40:12 +08:00
										 |  |  |     this.noDataModes = alertDef.noDataModes; | 
					
						
							| 
									
										
										
										
											2016-11-07 19:42:39 +08:00
										 |  |  |     this.executionErrorModes = alertDef.executionErrorModes; | 
					
						
							| 
									
										
										
										
											2016-08-18 15:58:20 +08:00
										 |  |  |     this.appSubUrl = config.appSubUrl; | 
					
						
							| 
									
										
										
										
											2019-01-02 17:57:12 +08:00
										 |  |  |     this.panelCtrl._enableAlert = this.enable; | 
					
						
							| 
									
										
										
										
											2020-01-14 17:13:34 +08:00
										 |  |  |     this.alertingMinIntervalSecs = config.alertingMinInterval; | 
					
						
							|  |  |  |     this.alertingMinInterval = kbn.secondsToHms(config.alertingMinInterval); | 
					
						
							| 
									
										
										
										
											2016-07-26 18:29:52 +08:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2016-05-11 19:04:03 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-26 18:29:52 +08:00
										 |  |  |   $onInit() { | 
					
						
							|  |  |  |     this.addNotificationSegment = this.uiSegmentSrv.newPlusButton(); | 
					
						
							| 
									
										
										
										
											2016-07-25 22:26:28 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-30 23:37:47 +08:00
										 |  |  |     // subscribe to graph threshold handle changes
 | 
					
						
							| 
									
										
										
										
											2018-08-29 20:26:50 +08:00
										 |  |  |     const thresholdChangedEventHandler = this.graphThresholdChanged.bind(this); | 
					
						
							| 
									
										
										
										
											2019-10-14 16:27:47 +08:00
										 |  |  |     this.panelCtrl.events.on(CoreEvents.thresholdChanged, thresholdChangedEventHandler); | 
					
						
							| 
									
										
										
										
											2016-06-12 04:33:02 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-30 22:14:18 +08:00
										 |  |  |     // set panel alert edit mode
 | 
					
						
							| 
									
										
										
										
											2017-12-20 19:33:33 +08:00
										 |  |  |     this.$scope.$on('$destroy', () => { | 
					
						
							| 
									
										
										
										
											2019-10-14 16:27:47 +08:00
										 |  |  |       this.panelCtrl.events.off(CoreEvents.thresholdChanged, thresholdChangedEventHandler); | 
					
						
							| 
									
										
										
										
											2016-08-11 03:37:10 +08:00
										 |  |  |       this.panelCtrl.editingThresholds = false; | 
					
						
							| 
									
										
										
										
											2016-06-12 04:33:02 +08:00
										 |  |  |       this.panelCtrl.render(); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2016-06-11 16:54:24 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-14 15:33:16 +08:00
										 |  |  |     // build notification model
 | 
					
						
							| 
									
										
										
										
											2016-07-26 18:29:52 +08:00
										 |  |  |     this.notifications = []; | 
					
						
							|  |  |  |     this.alertNotifications = []; | 
					
						
							| 
									
										
										
										
											2016-08-30 19:22:59 +08:00
										 |  |  |     this.alertHistory = []; | 
					
						
							| 
									
										
										
										
											2016-07-26 18:29:52 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-21 17:08:07 +08:00
										 |  |  |     return promiseToDigest(this.$scope)( | 
					
						
							|  |  |  |       getBackendSrv() | 
					
						
							|  |  |  |         .get('/api/alert-notifications/lookup') | 
					
						
							|  |  |  |         .then((res: any) => { | 
					
						
							|  |  |  |           this.notifications = res; | 
					
						
							| 
									
										
										
										
											2016-07-26 18:29:52 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-21 17:08:07 +08:00
										 |  |  |           this.initModel(); | 
					
						
							|  |  |  |           this.validateModel(); | 
					
						
							|  |  |  |         }) | 
					
						
							|  |  |  |     ); | 
					
						
							| 
									
										
										
										
											2016-09-06 15:14:11 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   getAlertHistory() { | 
					
						
							| 
									
										
										
										
											2020-01-21 17:08:07 +08:00
										 |  |  |     promiseToDigest(this.$scope)( | 
					
						
							|  |  |  |       getBackendSrv() | 
					
						
							|  |  |  |         .get(`/api/annotations?dashboardId=${this.panelCtrl.dashboard.id}&panelId=${this.panel.id}&limit=50&type=alert`) | 
					
						
							|  |  |  |         .then((res: any) => { | 
					
						
							|  |  |  |           this.alertHistory = _.map(res, ah => { | 
					
						
							|  |  |  |             ah.time = this.dashboardSrv.getCurrent().formatDate(ah.time, 'MMM D, YYYY HH:mm:ss'); | 
					
						
							|  |  |  |             ah.stateModel = alertDef.getStateDisplayModel(ah.newState); | 
					
						
							|  |  |  |             ah.info = alertDef.getAlertAnnotationInfo(ah); | 
					
						
							|  |  |  |             return ah; | 
					
						
							|  |  |  |           }); | 
					
						
							|  |  |  |         }) | 
					
						
							|  |  |  |     ); | 
					
						
							| 
									
										
										
										
											2016-07-25 22:26:28 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-13 15:38:19 +08:00
										 |  |  |   getNotificationIcon(type: string): string { | 
					
						
							| 
									
										
										
										
											2016-08-01 03:58:12 +08:00
										 |  |  |     switch (type) { | 
					
						
							| 
									
										
										
										
											2017-12-20 19:33:33 +08:00
										 |  |  |       case 'email': | 
					
						
							| 
									
										
										
										
											2020-04-13 04:20:02 +08:00
										 |  |  |         return 'envelope'; | 
					
						
							| 
									
										
										
										
											2017-12-20 19:33:33 +08:00
										 |  |  |       case 'slack': | 
					
						
							| 
									
										
										
										
											2020-04-13 04:20:02 +08:00
										 |  |  |         return 'slack'; | 
					
						
							| 
									
										
										
										
											2017-12-20 19:33:33 +08:00
										 |  |  |       case 'victorops': | 
					
						
							|  |  |  |         return 'fa fa-pagelines'; | 
					
						
							|  |  |  |       case 'webhook': | 
					
						
							| 
									
										
										
										
											2020-04-13 04:20:02 +08:00
										 |  |  |         return 'cube'; | 
					
						
							| 
									
										
										
										
											2017-12-20 19:33:33 +08:00
										 |  |  |       case 'pagerduty': | 
					
						
							|  |  |  |         return 'fa fa-bullhorn'; | 
					
						
							|  |  |  |       case 'opsgenie': | 
					
						
							| 
									
										
										
										
											2020-04-13 04:20:02 +08:00
										 |  |  |         return 'bell'; | 
					
						
							| 
									
										
										
										
											2017-12-20 19:33:33 +08:00
										 |  |  |       case 'hipchat': | 
					
						
							|  |  |  |         return 'fa fa-mail-forward'; | 
					
						
							|  |  |  |       case 'pushover': | 
					
						
							| 
									
										
										
										
											2020-04-13 04:20:02 +08:00
										 |  |  |         return 'mobile-android'; | 
					
						
							| 
									
										
										
										
											2017-12-20 19:33:33 +08:00
										 |  |  |       case 'kafka': | 
					
						
							| 
									
										
										
										
											2020-04-13 04:20:02 +08:00
										 |  |  |         return 'arrow-random'; | 
					
						
							| 
									
										
										
										
											2017-12-20 19:33:33 +08:00
										 |  |  |       case 'teams': | 
					
						
							|  |  |  |         return 'fa fa-windows'; | 
					
						
							| 
									
										
										
										
											2016-08-01 03:58:12 +08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-04-13 04:20:02 +08:00
										 |  |  |     return 'bell'; | 
					
						
							| 
									
										
										
										
											2016-08-01 03:58:12 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-26 18:29:52 +08:00
										 |  |  |   getNotifications() { | 
					
						
							| 
									
										
										
										
											2019-12-05 17:04:03 +08:00
										 |  |  |     return Promise.resolve( | 
					
						
							| 
									
										
										
										
											2019-05-13 15:38:19 +08:00
										 |  |  |       this.notifications.map((item: any) => { | 
					
						
							| 
									
										
										
										
											2017-12-19 23:06:54 +08:00
										 |  |  |         return this.uiSegmentSrv.newSegment(item.name); | 
					
						
							|  |  |  |       }) | 
					
						
							|  |  |  |     ); | 
					
						
							| 
									
										
										
										
											2016-07-26 18:29:52 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-25 22:26:28 +08:00
										 |  |  |   notificationAdded() { | 
					
						
							| 
									
										
										
										
											2019-04-15 18:11:52 +08:00
										 |  |  |     const model: any = _.find(this.notifications, { | 
					
						
							| 
									
										
										
										
											2017-12-20 19:33:33 +08:00
										 |  |  |       name: this.addNotificationSegment.value, | 
					
						
							| 
									
										
										
										
											2017-12-19 23:06:54 +08:00
										 |  |  |     }); | 
					
						
							| 
									
										
										
										
											2016-07-26 18:29:52 +08:00
										 |  |  |     if (!model) { | 
					
						
							|  |  |  |       return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-13 20:25:48 +08:00
										 |  |  |     this.alertNotifications.push({ | 
					
						
							|  |  |  |       name: model.name, | 
					
						
							|  |  |  |       iconClass: this.getNotificationIcon(model.type), | 
					
						
							| 
									
										
										
										
											2017-12-20 19:33:33 +08:00
										 |  |  |       isDefault: false, | 
					
						
							| 
									
										
										
										
											2019-02-13 18:14:53 +08:00
										 |  |  |       uid: model.uid, | 
					
						
							| 
									
										
										
										
											2016-09-13 20:25:48 +08:00
										 |  |  |     }); | 
					
						
							| 
									
										
										
										
											2019-01-28 20:20:29 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     // avoid duplicates using both id and uid to be backwards compatible.
 | 
					
						
							|  |  |  |     if (!_.find(this.alert.notifications, n => n.id === model.id || n.uid === model.uid)) { | 
					
						
							| 
									
										
										
										
											2019-01-18 22:19:06 +08:00
										 |  |  |       this.alert.notifications.push({ uid: model.uid }); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2016-07-25 22:26:28 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     // reset plus button
 | 
					
						
							|  |  |  |     this.addNotificationSegment.value = this.uiSegmentSrv.newPlusButton().value; | 
					
						
							|  |  |  |     this.addNotificationSegment.html = this.uiSegmentSrv.newPlusButton().html; | 
					
						
							| 
									
										
										
										
											2019-01-04 18:57:16 +08:00
										 |  |  |     this.addNotificationSegment.fake = true; | 
					
						
							| 
									
										
										
										
											2016-07-25 22:26:28 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-13 15:38:19 +08:00
										 |  |  |   removeNotification(an: any) { | 
					
						
							| 
									
										
										
										
											2019-01-28 20:20:29 +08:00
										 |  |  |     // remove notifiers refeered to by id and uid to support notifiers added
 | 
					
						
							|  |  |  |     // before and after we added support for uid
 | 
					
						
							| 
									
										
										
										
											2020-03-27 02:30:31 +08:00
										 |  |  |     _.remove(this.alert.notifications, (n: any) => n.uid === an.uid); | 
					
						
							|  |  |  |     _.remove(this.alertNotifications, (n: any) => n.uid === an.uid); | 
					
						
							| 
									
										
										
										
											2016-07-25 22:26:28 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-06 19:29:30 +08:00
										 |  |  |   addAlertRuleTag() { | 
					
						
							|  |  |  |     if (this.newAlertRuleTag.name) { | 
					
						
							|  |  |  |       this.alert.alertRuleTags[this.newAlertRuleTag.name] = this.newAlertRuleTag.value; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     this.newAlertRuleTag.name = ''; | 
					
						
							|  |  |  |     this.newAlertRuleTag.value = ''; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-01 20:38:34 +08:00
										 |  |  |   removeAlertRuleTag(tagName: string) { | 
					
						
							| 
									
										
										
										
											2019-06-06 19:29:30 +08:00
										 |  |  |     delete this.alert.alertRuleTags[tagName]; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-14 22:45:51 +08:00
										 |  |  |   initModel() { | 
					
						
							| 
									
										
										
										
											2018-08-29 20:26:50 +08:00
										 |  |  |     const alert = (this.alert = this.panel.alert); | 
					
						
							| 
									
										
										
										
											2016-09-30 23:37:47 +08:00
										 |  |  |     if (!alert) { | 
					
						
							| 
									
										
										
										
											2016-09-06 15:14:11 +08:00
										 |  |  |       return; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2016-06-14 22:45:51 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-14 17:13:34 +08:00
										 |  |  |     this.checkFrequency(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-21 19:09:12 +08:00
										 |  |  |     alert.conditions = alert.conditions || []; | 
					
						
							| 
									
										
										
										
											2016-07-19 17:24:27 +08:00
										 |  |  |     if (alert.conditions.length === 0) { | 
					
						
							| 
									
										
										
										
											2019-09-23 20:17:00 +08:00
										 |  |  |       alert.conditions.push(getDefaultCondition()); | 
					
						
							| 
									
										
										
										
											2016-07-19 17:24:27 +08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2016-06-14 22:45:51 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-06 17:20:38 +08:00
										 |  |  |     alert.noDataState = alert.noDataState || config.alertingNoDataOrNullValues; | 
					
						
							|  |  |  |     alert.executionErrorState = alert.executionErrorState || config.alertingErrorOrTimeout; | 
					
						
							| 
									
										
										
										
											2018-11-02 17:43:05 +08:00
										 |  |  |     alert.frequency = alert.frequency || '1m'; | 
					
						
							| 
									
										
										
										
											2016-06-15 16:41:21 +08:00
										 |  |  |     alert.handler = alert.handler || 1; | 
					
						
							|  |  |  |     alert.notifications = alert.notifications || []; | 
					
						
							| 
									
										
										
										
											2018-11-05 20:51:35 +08:00
										 |  |  |     alert.for = alert.for || '0m'; | 
					
						
							| 
									
										
										
										
											2019-06-06 19:29:30 +08:00
										 |  |  |     alert.alertRuleTags = alert.alertRuleTags || {}; | 
					
						
							| 
									
										
										
										
											2016-06-15 16:41:21 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-29 20:26:50 +08:00
										 |  |  |     const defaultName = this.panel.title + ' alert'; | 
					
						
							| 
									
										
										
										
											2016-06-14 22:45:51 +08:00
										 |  |  |     alert.name = alert.name || defaultName; | 
					
						
							| 
									
										
										
										
											2016-06-10 20:49:54 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-19 23:06:54 +08:00
										 |  |  |     this.conditionModels = _.reduce( | 
					
						
							|  |  |  |       alert.conditions, | 
					
						
							|  |  |  |       (memo, value) => { | 
					
						
							|  |  |  |         memo.push(this.buildConditionModel(value)); | 
					
						
							|  |  |  |         return memo; | 
					
						
							|  |  |  |       }, | 
					
						
							| 
									
										
										
											
												Chore: Fix all Typescript strict null errors  (#26204)
* Chore: Fix typescript strict null errors
* Added new limit
* Fixed ts issue
* fixed tests
* trying to fix type inference
* Fixing more ts errors
* Revert tsconfig option
* Fix
* Fixed code
* More fixes
* fix tests
* Updated snapshot
* Chore: More ts strict null fixes
* More fixes in some really messed up azure config components
* More fixes, current count: 441
* 419
* More fixes
* Fixed invalid initial state in explore
* Fixing tests
* Fixed tests
* Explore fix
* More fixes
* Progress
* Sub 300
* Now at 218
* Progress
* Update
* Progress
* Updated tests
* at 159
* fixed tests
* Progress
* YAy blow 100! at 94
* 10,9,8,7,6,5,4,3,2,1... lift off
* Fixed tests
* Fixed more type errors
Co-authored-by: Ryan McKinley <ryantxu@gmail.com>
											
										 
											2020-07-10 18:46:59 +08:00
										 |  |  |       [] as string[] | 
					
						
							| 
									
										
										
										
											2017-12-19 23:06:54 +08:00
										 |  |  |     ); | 
					
						
							| 
									
										
										
										
											2016-06-12 17:43:18 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-11 21:18:21 +08:00
										 |  |  |     ThresholdMapper.alertToGraphThresholds(this.panel); | 
					
						
							| 
									
										
										
										
											2016-09-06 15:14:11 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-26 23:14:40 +08:00
										 |  |  |     for (const addedNotification of alert.notifications) { | 
					
						
							| 
									
										
										
										
											2019-01-28 20:20:29 +08:00
										 |  |  |       // lookup notifier type by uid
 | 
					
						
							| 
									
										
										
										
											2019-04-15 18:11:52 +08:00
										 |  |  |       let model: any = _.find(this.notifications, { uid: addedNotification.uid }); | 
					
						
							| 
									
										
										
										
											2019-01-28 20:20:29 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |       // fallback to using id if uid is missing
 | 
					
						
							|  |  |  |       if (!model) { | 
					
						
							|  |  |  |         model = _.find(this.notifications, { id: addedNotification.id }); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-12 17:27:06 +08:00
										 |  |  |       if (model && model.isDefault === false) { | 
					
						
							| 
									
										
										
										
											2016-09-30 23:37:47 +08:00
										 |  |  |         model.iconClass = this.getNotificationIcon(model.type); | 
					
						
							|  |  |  |         this.alertNotifications.push(model); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-26 23:14:40 +08:00
										 |  |  |     for (const notification of this.notifications) { | 
					
						
							| 
									
										
										
										
											2016-09-30 23:37:47 +08:00
										 |  |  |       if (notification.isDefault) { | 
					
						
							|  |  |  |         notification.iconClass = this.getNotificationIcon(notification.type); | 
					
						
							|  |  |  |         this.alertNotifications.push(notification); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-06 15:14:11 +08:00
										 |  |  |     this.panelCtrl.editingThresholds = true; | 
					
						
							| 
									
										
										
										
											2016-06-12 17:43:18 +08:00
										 |  |  |     this.panelCtrl.render(); | 
					
						
							| 
									
										
										
										
											2016-06-10 20:49:54 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-14 17:13:34 +08:00
										 |  |  |   checkFrequency() { | 
					
						
							| 
									
										
										
										
											2020-01-16 23:38:49 +08:00
										 |  |  |     if (!this.alert.frequency) { | 
					
						
							|  |  |  |       return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-14 17:13:34 +08:00
										 |  |  |     this.frequencyWarning = ''; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     try { | 
					
						
							|  |  |  |       const frequencySecs = kbn.interval_to_seconds(this.alert.frequency); | 
					
						
							|  |  |  |       if (frequencySecs < this.alertingMinIntervalSecs) { | 
					
						
							|  |  |  |         this.frequencyWarning = | 
					
						
							|  |  |  |           'A minimum evaluation interval of ' + | 
					
						
							|  |  |  |           this.alertingMinInterval + | 
					
						
							|  |  |  |           ' have been configured in Grafana and will be used for this alert rule. ' + | 
					
						
							|  |  |  |           'Please contact the administrator to configure a lower interval.'; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } catch (err) { | 
					
						
							|  |  |  |       this.frequencyWarning = err; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-13 15:38:19 +08:00
										 |  |  |   graphThresholdChanged(evt: any) { | 
					
						
							| 
									
										
										
										
											2018-08-29 20:26:50 +08:00
										 |  |  |     for (const condition of this.alert.conditions) { | 
					
						
							| 
									
										
										
										
											2017-12-20 19:33:33 +08:00
										 |  |  |       if (condition.type === 'query') { | 
					
						
							| 
									
										
										
										
											2016-08-12 16:32:46 +08:00
										 |  |  |         condition.evaluator.params[evt.handleIndex] = evt.threshold.value; | 
					
						
							|  |  |  |         this.evaluatorParamsChanged(); | 
					
						
							| 
									
										
										
										
											2016-08-11 03:37:10 +08:00
										 |  |  |         break; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-18 15:03:46 +08:00
										 |  |  |   validateModel() { | 
					
						
							| 
									
										
										
										
											2016-09-30 23:37:47 +08:00
										 |  |  |     if (!this.alert) { | 
					
						
							| 
									
										
										
										
											2016-09-06 15:14:11 +08:00
										 |  |  |       return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-18 15:03:46 +08:00
										 |  |  |     let firstTarget; | 
					
						
							| 
									
										
										
											
												Chore: Fix all Typescript strict null errors  (#26204)
* Chore: Fix typescript strict null errors
* Added new limit
* Fixed ts issue
* fixed tests
* trying to fix type inference
* Fixing more ts errors
* Revert tsconfig option
* Fix
* Fixed code
* More fixes
* fix tests
* Updated snapshot
* Chore: More ts strict null fixes
* More fixes in some really messed up azure config components
* More fixes, current count: 441
* 419
* More fixes
* Fixed invalid initial state in explore
* Fixing tests
* Fixed tests
* Explore fix
* More fixes
* Progress
* Sub 300
* Now at 218
* Progress
* Update
* Progress
* Updated tests
* at 159
* fixed tests
* Progress
* YAy blow 100! at 94
* 10,9,8,7,6,5,4,3,2,1... lift off
* Fixed tests
* Fixed more type errors
Co-authored-by: Ryan McKinley <ryantxu@gmail.com>
											
										 
											2020-07-10 18:46:59 +08:00
										 |  |  |     let foundTarget: DataQuery | null = null; | 
					
						
							| 
									
										
										
										
											2016-08-18 15:03:46 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-11 18:11:37 +08:00
										 |  |  |     const promises: Array<Promise<any>> = []; | 
					
						
							| 
									
										
										
										
											2018-08-29 20:26:50 +08:00
										 |  |  |     for (const condition of this.alert.conditions) { | 
					
						
							| 
									
										
										
										
											2017-12-20 19:33:33 +08:00
										 |  |  |       if (condition.type !== 'query') { | 
					
						
							| 
									
										
										
										
											2016-08-18 15:03:46 +08:00
										 |  |  |         continue; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-29 20:26:50 +08:00
										 |  |  |       for (const target of this.panel.targets) { | 
					
						
							| 
									
										
										
										
											2016-08-18 15:03:46 +08:00
										 |  |  |         if (!firstTarget) { | 
					
						
							|  |  |  |           firstTarget = target; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         if (condition.query.params[0] === target.refId) { | 
					
						
							|  |  |  |           foundTarget = target; | 
					
						
							|  |  |  |           break; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       if (!foundTarget) { | 
					
						
							|  |  |  |         if (firstTarget) { | 
					
						
							|  |  |  |           condition.query.params[0] = firstTarget.refId; | 
					
						
							|  |  |  |           foundTarget = firstTarget; | 
					
						
							|  |  |  |         } else { | 
					
						
							| 
									
										
										
										
											2017-12-20 19:33:33 +08:00
										 |  |  |           this.error = 'Could not find any metric queries'; | 
					
						
							| 
									
										
										
										
											2019-12-11 18:11:37 +08:00
										 |  |  |           return; | 
					
						
							| 
									
										
										
										
											2016-08-18 15:03:46 +08:00
										 |  |  |         } | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-29 20:26:50 +08:00
										 |  |  |       const datasourceName = foundTarget.datasource || this.panel.datasource; | 
					
						
							| 
									
										
										
										
											2019-12-11 18:11:37 +08:00
										 |  |  |       promises.push( | 
					
						
							|  |  |  |         this.datasourceSrv.get(datasourceName).then( | 
					
						
							|  |  |  |           (foundTarget => (ds: DataSourceApi) => { | 
					
						
							|  |  |  |             if (!ds.meta.alerting) { | 
					
						
							|  |  |  |               return Promise.reject('The datasource does not support alerting queries'); | 
					
						
							|  |  |  |             } else if (ds.targetContainsTemplate && ds.targetContainsTemplate(foundTarget)) { | 
					
						
							|  |  |  |               return Promise.reject('Template variables are not supported in alert queries'); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             return Promise.resolve(); | 
					
						
							|  |  |  |           })(foundTarget) | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |       ); | 
					
						
							| 
									
										
										
										
											2016-08-18 15:03:46 +08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-12-11 18:11:37 +08:00
										 |  |  |     Promise.all(promises).then( | 
					
						
							|  |  |  |       () => { | 
					
						
							|  |  |  |         this.error = ''; | 
					
						
							|  |  |  |         this.$scope.$apply(); | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |       e => { | 
					
						
							|  |  |  |         this.error = e; | 
					
						
							|  |  |  |         this.$scope.$apply(); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     ); | 
					
						
							| 
									
										
										
										
											2016-08-18 15:03:46 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-13 15:38:19 +08:00
										 |  |  |   buildConditionModel(source: any) { | 
					
						
							| 
									
										
										
										
											2018-08-29 20:26:50 +08:00
										 |  |  |     const cm: any = { source: source, type: source.type }; | 
					
						
							| 
									
										
										
										
											2016-07-19 17:24:27 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-11 21:18:21 +08:00
										 |  |  |     cm.queryPart = new QueryPart(source.query, alertDef.alertQueryDef); | 
					
						
							| 
									
										
										
										
											2016-08-15 19:51:55 +08:00
										 |  |  |     cm.reducerPart = alertDef.createReducerPart(source.reducer); | 
					
						
							| 
									
										
										
										
											2016-07-19 22:15:26 +08:00
										 |  |  |     cm.evaluator = source.evaluator; | 
					
						
							| 
									
										
										
										
											2016-11-13 05:16:46 +08:00
										 |  |  |     cm.operator = source.operator; | 
					
						
							| 
									
										
										
										
											2016-07-19 22:15:26 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-19 17:24:27 +08:00
										 |  |  |     return cm; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-13 15:38:19 +08:00
										 |  |  |   handleQueryPartEvent(conditionModel: any, evt: any) { | 
					
						
							| 
									
										
										
										
											2016-08-15 23:53:44 +08:00
										 |  |  |     switch (evt.name) { | 
					
						
							| 
									
										
										
										
											2017-12-20 19:33:33 +08:00
										 |  |  |       case 'action-remove-part': { | 
					
						
							| 
									
										
										
										
											2016-08-15 23:53:44 +08:00
										 |  |  |         break; | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2017-12-20 19:33:33 +08:00
										 |  |  |       case 'get-part-actions': { | 
					
						
							| 
									
										
										
										
											2019-12-05 17:04:03 +08:00
										 |  |  |         return Promise.resolve([]); | 
					
						
							| 
									
										
										
										
											2016-08-15 23:53:44 +08:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2017-12-20 19:33:33 +08:00
										 |  |  |       case 'part-param-changed': { | 
					
						
							| 
									
										
										
										
											2016-08-18 16:01:56 +08:00
										 |  |  |         this.validateModel(); | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2017-12-20 19:33:33 +08:00
										 |  |  |       case 'get-param-options': { | 
					
						
							| 
									
										
										
										
											2018-08-29 20:26:50 +08:00
										 |  |  |         const result = this.panel.targets.map(target => { | 
					
						
							| 
									
										
										
										
											2016-08-18 16:01:56 +08:00
										 |  |  |           return this.uiSegmentSrv.newSegment({ value: target.refId }); | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-05 17:04:03 +08:00
										 |  |  |         return Promise.resolve(result); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       default: { | 
					
						
							|  |  |  |         return Promise.resolve(); | 
					
						
							| 
									
										
										
										
											2016-08-18 16:01:56 +08:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2016-08-15 23:53:44 +08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-12-05 17:04:03 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     return Promise.resolve(); | 
					
						
							| 
									
										
										
										
											2016-07-19 17:24:27 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-13 15:38:19 +08:00
										 |  |  |   handleReducerPartEvent(conditionModel: any, evt: any) { | 
					
						
							| 
									
										
										
										
											2016-08-15 23:53:44 +08:00
										 |  |  |     switch (evt.name) { | 
					
						
							| 
									
										
										
										
											2017-12-20 19:33:33 +08:00
										 |  |  |       case 'action': { | 
					
						
							| 
									
										
										
										
											2016-08-15 23:53:44 +08:00
										 |  |  |         conditionModel.source.reducer.type = evt.action.value; | 
					
						
							| 
									
										
										
										
											2017-12-21 15:39:31 +08:00
										 |  |  |         conditionModel.reducerPart = alertDef.createReducerPart(conditionModel.source.reducer); | 
					
						
							| 
									
										
										
										
											2016-08-15 23:53:44 +08:00
										 |  |  |         break; | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2017-12-20 19:33:33 +08:00
										 |  |  |       case 'get-part-actions': { | 
					
						
							| 
									
										
										
										
											2018-08-29 20:26:50 +08:00
										 |  |  |         const result = []; | 
					
						
							|  |  |  |         for (const type of alertDef.reducerTypes) { | 
					
						
							| 
									
										
										
										
											2016-08-15 23:53:44 +08:00
										 |  |  |           if (type.value !== conditionModel.source.reducer.type) { | 
					
						
							|  |  |  |             result.push(type); | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2019-12-05 17:04:03 +08:00
										 |  |  |         return Promise.resolve(result); | 
					
						
							| 
									
										
										
										
											2016-08-15 23:53:44 +08:00
										 |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-12-05 17:04:03 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     return Promise.resolve(); | 
					
						
							| 
									
										
										
										
											2016-08-15 19:51:55 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-13 15:38:19 +08:00
										 |  |  |   addCondition(type: string) { | 
					
						
							| 
									
										
										
										
											2019-09-23 20:17:00 +08:00
										 |  |  |     const condition = getDefaultCondition(); | 
					
						
							| 
									
										
										
										
											2016-07-19 17:24:27 +08:00
										 |  |  |     // add to persited model
 | 
					
						
							| 
									
										
										
										
											2016-08-18 15:03:46 +08:00
										 |  |  |     this.alert.conditions.push(condition); | 
					
						
							| 
									
										
										
										
											2016-07-19 17:24:27 +08:00
										 |  |  |     // add to view model
 | 
					
						
							|  |  |  |     this.conditionModels.push(this.buildConditionModel(condition)); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-13 15:38:19 +08:00
										 |  |  |   removeCondition(index: number) { | 
					
						
							| 
									
										
										
										
											2016-07-19 17:24:27 +08:00
										 |  |  |     this.alert.conditions.splice(index, 1); | 
					
						
							|  |  |  |     this.conditionModels.splice(index, 1); | 
					
						
							| 
									
										
										
										
											2016-04-28 22:03:14 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-11 16:13:33 +08:00
										 |  |  |   delete() { | 
					
						
							| 
									
										
										
										
											2019-10-14 16:27:47 +08:00
										 |  |  |     appEvents.emit(CoreEvents.showConfirmModal, { | 
					
						
							| 
									
										
										
										
											2017-12-20 19:33:33 +08:00
										 |  |  |       title: 'Delete Alert', | 
					
						
							|  |  |  |       text: 'Are you sure you want to delete this alert rule?', | 
					
						
							|  |  |  |       text2: 'You need to save dashboard for the delete to take effect', | 
					
						
							| 
									
										
										
										
											2020-04-13 04:20:02 +08:00
										 |  |  |       icon: 'trash-alt', | 
					
						
							| 
									
										
										
										
											2017-12-20 19:33:33 +08:00
										 |  |  |       yesText: 'Delete', | 
					
						
							| 
									
										
										
										
											2016-09-30 19:00:16 +08:00
										 |  |  |       onConfirm: () => { | 
					
						
							| 
									
										
										
										
											2016-09-30 23:37:47 +08:00
										 |  |  |         delete this.panel.alert; | 
					
						
							|  |  |  |         this.alert = null; | 
					
						
							| 
									
										
										
										
											2016-09-30 19:00:16 +08:00
										 |  |  |         this.panel.thresholds = []; | 
					
						
							|  |  |  |         this.conditionModels = []; | 
					
						
							| 
									
										
										
										
											2016-10-11 15:51:43 +08:00
										 |  |  |         this.panelCtrl.alertState = null; | 
					
						
							| 
									
										
										
										
											2016-09-30 19:00:16 +08:00
										 |  |  |         this.panelCtrl.render(); | 
					
						
							| 
									
										
										
										
											2017-12-20 19:33:33 +08:00
										 |  |  |       }, | 
					
						
							| 
									
										
										
										
											2016-09-30 19:00:16 +08:00
										 |  |  |     }); | 
					
						
							| 
									
										
										
										
											2016-06-11 16:13:33 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-02 17:57:12 +08:00
										 |  |  |   enable = () => { | 
					
						
							| 
									
										
										
										
											2016-09-30 23:37:47 +08:00
										 |  |  |     this.panel.alert = {}; | 
					
						
							| 
									
										
										
										
											2016-06-14 22:45:51 +08:00
										 |  |  |     this.initModel(); | 
					
						
							| 
									
										
										
										
											2018-11-05 20:51:35 +08:00
										 |  |  |     this.panel.alert.for = '5m'; //default value for new alerts. for existing alerts we use 0m to avoid breaking changes
 | 
					
						
							| 
									
										
										
										
											2019-01-02 17:57:12 +08:00
										 |  |  |   }; | 
					
						
							| 
									
										
										
										
											2016-06-12 04:33:02 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-12 00:25:41 +08:00
										 |  |  |   evaluatorParamsChanged() { | 
					
						
							|  |  |  |     ThresholdMapper.alertToGraphThresholds(this.panel); | 
					
						
							|  |  |  |     this.panelCtrl.render(); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-13 15:38:19 +08:00
										 |  |  |   evaluatorTypeChanged(evaluator: any) { | 
					
						
							| 
									
										
										
										
											2016-08-12 00:25:41 +08:00
										 |  |  |     // ensure params array is correct length
 | 
					
						
							|  |  |  |     switch (evaluator.type) { | 
					
						
							| 
									
										
										
										
											2017-12-20 19:33:33 +08:00
										 |  |  |       case 'lt': | 
					
						
							|  |  |  |       case 'gt': { | 
					
						
							| 
									
										
										
										
											2016-08-12 00:25:41 +08:00
										 |  |  |         evaluator.params = [evaluator.params[0]]; | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2017-12-20 19:33:33 +08:00
										 |  |  |       case 'within_range': | 
					
						
							|  |  |  |       case 'outside_range': { | 
					
						
							| 
									
										
										
										
											2016-08-12 00:25:41 +08:00
										 |  |  |         evaluator.params = [evaluator.params[0], evaluator.params[1]]; | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2017-12-20 19:33:33 +08:00
										 |  |  |       case 'no_value': { | 
					
						
							| 
									
										
										
										
											2016-08-12 00:25:41 +08:00
										 |  |  |         evaluator.params = []; | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2016-07-26 20:35:42 +08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2016-08-12 00:25:41 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     this.evaluatorParamsChanged(); | 
					
						
							| 
									
										
										
										
											2016-06-12 04:33:02 +08:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2016-07-21 16:29:11 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-14 15:33:16 +08:00
										 |  |  |   clearHistory() { | 
					
						
							| 
									
										
										
										
											2019-10-14 16:27:47 +08:00
										 |  |  |     appEvents.emit(CoreEvents.showConfirmModal, { | 
					
						
							| 
									
										
										
										
											2017-12-20 19:33:33 +08:00
										 |  |  |       title: 'Delete Alert History', | 
					
						
							| 
									
										
										
										
											2017-12-21 15:39:31 +08:00
										 |  |  |       text: 'Are you sure you want to remove all history & annotations for this alert?', | 
					
						
							| 
									
										
										
										
											2020-04-13 04:20:02 +08:00
										 |  |  |       icon: 'trash-alt', | 
					
						
							| 
									
										
										
										
											2017-12-20 19:33:33 +08:00
										 |  |  |       yesText: 'Yes', | 
					
						
							| 
									
										
										
										
											2016-10-14 15:33:16 +08:00
										 |  |  |       onConfirm: () => { | 
					
						
							| 
									
										
										
										
											2020-01-21 17:08:07 +08:00
										 |  |  |         promiseToDigest(this.$scope)( | 
					
						
							|  |  |  |           getBackendSrv() | 
					
						
							|  |  |  |             .post('/api/annotations/mass-delete', { | 
					
						
							|  |  |  |               dashboardId: this.panelCtrl.dashboard.id, | 
					
						
							|  |  |  |               panelId: this.panel.id, | 
					
						
							|  |  |  |             }) | 
					
						
							|  |  |  |             .then(() => { | 
					
						
							|  |  |  |               this.alertHistory = []; | 
					
						
							|  |  |  |               this.panelCtrl.refresh(); | 
					
						
							|  |  |  |             }) | 
					
						
							|  |  |  |         ); | 
					
						
							| 
									
										
										
										
											2017-12-20 19:33:33 +08:00
										 |  |  |       }, | 
					
						
							| 
									
										
										
										
											2016-10-14 15:33:16 +08:00
										 |  |  |     }); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2016-04-28 22:03:14 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** @ngInject */ | 
					
						
							| 
									
										
										
										
											2016-07-31 15:31:32 +08:00
										 |  |  | export function alertTab() { | 
					
						
							| 
									
										
										
										
											2017-12-20 19:33:33 +08:00
										 |  |  |   'use strict'; | 
					
						
							| 
									
										
										
										
											2016-04-28 22:03:14 +08:00
										 |  |  |   return { | 
					
						
							| 
									
										
										
										
											2017-12-20 19:33:33 +08:00
										 |  |  |     restrict: 'E', | 
					
						
							| 
									
										
										
										
											2016-04-28 22:03:14 +08:00
										 |  |  |     scope: true, | 
					
						
							| 
									
										
										
										
											2017-12-20 19:33:33 +08:00
										 |  |  |     templateUrl: 'public/app/features/alerting/partials/alert_tab.html', | 
					
						
							|  |  |  |     controller: AlertTabCtrl, | 
					
						
							| 
									
										
										
										
											2016-04-28 22:03:14 +08:00
										 |  |  |   }; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2018-11-21 00:09:47 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | coreModule.directive('alertTab', alertTab); |