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AAS1D,EAAUC,OAAO,GAC1B0D,EAAS3D,EAAUC,OAAO,GAE5ByD,EAASC,GACXnB,EAAWvF,KAAK,CAAED,MAAO0G,EAAQD,GAAI,KAAMF,QAAAA,IAC3Cf,EAAWvF,KAAK,CAAED,MAAO2G,EAAQF,GAAI,KAAMF,QAAAA,MAE3Cf,EAAWvF,KAAK,CAAED,MAAO0G,EAAQD,GAAI,KAAMF,QAAAA,IAC3Cf,EAAWvF,KAAK,CAAED,MAAO2G,EAAQF,GAAI,KAAMF,QAAAA,KAE7C,OAGJ,MAGF,IAAK,MAAMK,KAAK3K,EAAMuJ,WACpBoB,EAAEC,KAAO5K,EAAM6K,QAAQC,eACvBH,EAAEI,KAAO/K,EAAM6K,QAAQC,eACvBH,EAAEK,UAAY,WAIhB,OADgB","sources":["webpack://grafana/./public/app/angular/core_module.ts","webpack://grafana/./public/app/angular/promiseToDigest.ts","webpack://grafana/./public/app/features/alerting/AlertTabCtrl.ts","webpack://grafana/./public/app/features/alerting/state/ThresholdMapper.ts"],"sourcesContent":["import angular from 'angular';\n\nconst coreModule = angular.module('grafana.core', ['ngRoute']);\n\n// legacy modules\nconst angularModules = [\n coreModule,\n angular.module('grafana.controllers', []),\n angular.module('grafana.directives', []),\n angular.module('grafana.factories', []),\n angular.module('grafana.services', []),\n angular.module('grafana.filters', []),\n angular.module('grafana.routes', []),\n];\n\nexport { angularModules, coreModule };\n\nexport default coreModule;\n","import { IScope } from 'angular';\n\nexport const promiseToDigest = ($scope: IScope) => (promise: Promise) => promise.finally($scope.$evalAsync);\n","import { find, map, reduce, remove } from 'lodash';\n\nimport { DataQuery, DataSourceApi, rangeUtil } from '@grafana/data';\nimport { getBackendSrv } from '@grafana/runtime';\nimport coreModule from 'app/angular/core_module';\nimport { promiseToDigest } from 'app/angular/promiseToDigest';\nimport appEvents from 'app/core/app_events';\nimport config from 'app/core/config';\nimport { QueryPart } from 'app/features/alerting/state/query_part';\nimport { PanelModel } from 'app/features/dashboard/state';\nimport { CoreEvents } from 'app/types';\n\nimport { ShowConfirmModalEvent } from '../../types/events';\nimport { DashboardSrv } from '../dashboard/services/DashboardSrv';\nimport { DatasourceSrv } from '../plugins/datasource_srv';\n\nimport { getDefaultCondition } from './getAlertingValidationMessage';\nimport { ThresholdMapper } from './state/ThresholdMapper';\nimport alertDef from './state/alertDef';\n\nexport class AlertTabCtrl {\n panel: PanelModel;\n panelCtrl: any;\n subTabIndex: number;\n conditionTypes: any;\n alert: any;\n conditionModels: any;\n evalFunctions: any;\n evalOperators: any;\n noDataModes: any;\n executionErrorModes: any;\n addNotificationSegment: any;\n notifications: any;\n alertNotifications: any;\n error?: string;\n appSubUrl: string;\n alertHistory: any;\n newAlertRuleTag: any;\n alertingMinIntervalSecs: number;\n alertingMinInterval: string;\n frequencyWarning: any;\n\n /** @ngInject */\n constructor(\n private $scope: any,\n private dashboardSrv: DashboardSrv,\n private uiSegmentSrv: any,\n private datasourceSrv: DatasourceSrv\n ) {\n this.panelCtrl = $scope.ctrl;\n this.panel = this.panelCtrl.panel;\n this.$scope.ctrl = this;\n this.subTabIndex = 0;\n this.evalFunctions = alertDef.evalFunctions;\n this.evalOperators = alertDef.evalOperators;\n this.conditionTypes = alertDef.conditionTypes;\n this.noDataModes = alertDef.noDataModes;\n this.executionErrorModes = alertDef.executionErrorModes;\n this.appSubUrl = config.appSubUrl;\n this.panelCtrl._enableAlert = this.enable;\n this.alertingMinIntervalSecs = config.alertingMinInterval;\n this.alertingMinInterval = rangeUtil.secondsToHms(config.alertingMinInterval);\n }\n\n $onInit() {\n this.addNotificationSegment = this.uiSegmentSrv.newPlusButton();\n\n // subscribe to graph threshold handle changes\n const thresholdChangedEventHandler = this.graphThresholdChanged.bind(this);\n this.panelCtrl.events.on(CoreEvents.thresholdChanged, thresholdChangedEventHandler);\n\n // set panel alert edit mode\n this.$scope.$on('$destroy', () => {\n this.panelCtrl.events.off(CoreEvents.thresholdChanged, thresholdChangedEventHandler);\n this.panelCtrl.editingThresholds = false;\n this.panelCtrl.render();\n });\n\n // build notification model\n this.notifications = [];\n this.alertNotifications = [];\n this.alertHistory = [];\n\n return promiseToDigest(this.$scope)(\n getBackendSrv()\n .get('/api/alert-notifications/lookup')\n .then((res: any) => {\n this.notifications = res;\n\n this.initModel();\n this.validateModel();\n })\n );\n }\n\n getAlertHistory() {\n promiseToDigest(this.$scope)(\n getBackendSrv()\n .get(`/api/annotations?dashboardId=${this.panelCtrl.dashboard.id}&panelId=${this.panel.id}&limit=50&type=alert`)\n .then((res: any) => {\n this.alertHistory = map(res, (ah) => {\n ah.time = this.dashboardSrv.getCurrent()?.formatDate(ah.time, 'MMM D, YYYY HH:mm:ss');\n ah.stateModel = alertDef.getStateDisplayModel(ah.newState);\n ah.info = alertDef.getAlertAnnotationInfo(ah);\n return ah;\n });\n })\n );\n }\n\n getNotificationIcon(type: string): string {\n switch (type) {\n case 'email':\n return 'envelope';\n case 'slack':\n return 'slack';\n case 'victorops':\n return 'fa fa-pagelines';\n case 'webhook':\n return 'cube';\n case 'pagerduty':\n return 'fa fa-bullhorn';\n case 'opsgenie':\n return 'bell';\n case 'hipchat':\n return 'fa fa-mail-forward';\n case 'pushover':\n return 'mobile-android';\n case 'kafka':\n return 'arrow-random';\n case 'teams':\n return 'fa fa-windows';\n }\n return 'bell';\n }\n\n getNotifications() {\n return Promise.resolve(\n this.notifications.map((item: any) => {\n return this.uiSegmentSrv.newSegment(item.name);\n })\n );\n }\n\n notificationAdded() {\n const model: any = find(this.notifications, {\n name: this.addNotificationSegment.value,\n });\n if (!model) {\n return;\n }\n\n this.alertNotifications.push({\n name: model.name,\n iconClass: this.getNotificationIcon(model.type),\n isDefault: false,\n uid: model.uid,\n });\n\n // avoid duplicates using both id and uid to be backwards compatible.\n if (!find(this.alert.notifications, (n) => n.id === model.id || n.uid === model.uid)) {\n this.alert.notifications.push({ uid: model.uid });\n }\n\n // reset plus button\n this.addNotificationSegment.value = this.uiSegmentSrv.newPlusButton().value;\n this.addNotificationSegment.html = this.uiSegmentSrv.newPlusButton().html;\n this.addNotificationSegment.fake = true;\n }\n\n removeNotification(an: any) {\n // remove notifiers referred to by id and uid to support notifiers added\n // before and after we added support for uid\n remove(this.alert.notifications, (n: any) => n.uid === an.uid || n.id === an.id);\n remove(this.alertNotifications, (n: any) => n.uid === an.uid || n.id === an.id);\n }\n\n addAlertRuleTag() {\n if (this.newAlertRuleTag.name) {\n this.alert.alertRuleTags[this.newAlertRuleTag.name] = this.newAlertRuleTag.value;\n }\n this.newAlertRuleTag.name = '';\n this.newAlertRuleTag.value = '';\n }\n\n removeAlertRuleTag(tagName: string) {\n delete this.alert.alertRuleTags[tagName];\n }\n\n initModel() {\n const alert = (this.alert = this.panel.alert);\n if (!alert) {\n return;\n }\n\n this.checkFrequency();\n\n alert.conditions = alert.conditions || [];\n if (alert.conditions.length === 0) {\n alert.conditions.push(getDefaultCondition());\n }\n\n alert.noDataState = alert.noDataState || config.alertingNoDataOrNullValues;\n alert.executionErrorState = alert.executionErrorState || config.alertingErrorOrTimeout;\n alert.frequency = alert.frequency || '1m';\n alert.handler = alert.handler || 1;\n alert.notifications = alert.notifications || [];\n alert.for = alert.for || '0m';\n alert.alertRuleTags = alert.alertRuleTags || {};\n\n const defaultName = this.panel.title + ' alert';\n alert.name = alert.name || defaultName;\n\n this.conditionModels = reduce(\n alert.conditions,\n (memo, value) => {\n memo.push(this.buildConditionModel(value));\n return memo;\n },\n [] as string[]\n );\n\n ThresholdMapper.alertToGraphThresholds(this.panel);\n\n for (const addedNotification of alert.notifications) {\n let identifier = addedNotification.uid;\n // lookup notifier type by uid\n let model: any = find(this.notifications, { uid: identifier });\n\n // fallback using id if uid is missing\n if (!model && addedNotification.id) {\n identifier = addedNotification.id;\n model = find(this.notifications, { id: identifier });\n }\n\n if (!model) {\n appEvents.publish(\n new ShowConfirmModalEvent({\n title: 'Notifier with invalid identifier is detected',\n text: `Do you want to delete notifier with invalid identifier: ${identifier} from the dashboard JSON?`,\n text2: 'After successful deletion, make sure to save the dashboard for storing the update JSON.',\n icon: 'trash-alt',\n confirmText: 'Delete',\n yesText: 'Delete',\n onConfirm: async () => {\n this.removeNotification(addedNotification);\n },\n })\n );\n }\n\n if (model && model.isDefault === false) {\n model.iconClass = this.getNotificationIcon(model.type);\n this.alertNotifications.push(model);\n }\n }\n\n for (const notification of this.notifications) {\n if (notification.isDefault) {\n notification.iconClass = this.getNotificationIcon(notification.type);\n this.alertNotifications.push(notification);\n }\n }\n\n this.panelCtrl.editingThresholds = true;\n this.panelCtrl.render();\n }\n\n checkFrequency() {\n this.frequencyWarning = '';\n\n if (!this.alert.frequency) {\n return;\n }\n\n if (!this.alert.frequency.match(/^\\d+([dhms])$/)) {\n this.frequencyWarning =\n 'Invalid frequency, has to be numeric followed by one of the following units: \"d, h, m, s\"';\n return;\n }\n\n try {\n const frequencySecs = rangeUtil.intervalToSeconds(this.alert.frequency);\n if (frequencySecs < this.alertingMinIntervalSecs) {\n this.frequencyWarning =\n 'A minimum evaluation interval of ' +\n this.alertingMinInterval +\n ' have been configured in Grafana and will be used for this alert rule. ' +\n 'Please contact the administrator to configure a lower interval.';\n }\n } catch (err) {\n this.frequencyWarning = err;\n }\n }\n\n graphThresholdChanged(evt: any) {\n for (const condition of this.alert.conditions) {\n if (condition.type === 'query') {\n condition.evaluator.params[evt.handleIndex] = evt.threshold.value;\n this.evaluatorParamsChanged();\n break;\n }\n }\n }\n\n validateModel() {\n if (!this.alert) {\n return;\n }\n\n let firstTarget;\n let foundTarget: DataQuery | null = null;\n\n const promises: Array> = [];\n for (const condition of this.alert.conditions) {\n if (condition.type !== 'query') {\n continue;\n }\n\n for (const target of this.panel.targets) {\n if (!firstTarget) {\n firstTarget = target;\n }\n if (condition.query.params[0] === target.refId) {\n foundTarget = target;\n break;\n }\n }\n\n if (!foundTarget) {\n if (firstTarget) {\n condition.query.params[0] = firstTarget.refId;\n foundTarget = firstTarget;\n } else {\n this.error = 'Could not find any metric queries';\n return;\n }\n }\n\n const datasourceName = foundTarget.datasource || this.panel.datasource;\n promises.push(\n this.datasourceSrv.get(datasourceName).then(\n ((foundTarget) => (ds: DataSourceApi) => {\n if (!ds.meta.alerting) {\n return Promise.reject('The datasource does not support alerting queries');\n } else if (ds.targetContainsTemplate && ds.targetContainsTemplate(foundTarget)) {\n return Promise.reject('Template variables are not supported in alert queries');\n }\n return Promise.resolve();\n })(foundTarget)\n )\n );\n }\n Promise.all(promises).then(\n () => {\n this.error = '';\n this.$scope.$apply();\n },\n (e) => {\n this.error = e;\n this.$scope.$apply();\n }\n );\n }\n\n buildConditionModel(source: any) {\n const cm: any = { source: source, type: source.type };\n\n cm.queryPart = new QueryPart(source.query, alertDef.alertQueryDef);\n cm.reducerPart = alertDef.createReducerPart(source.reducer);\n cm.evaluator = source.evaluator;\n cm.operator = source.operator;\n\n return cm;\n }\n\n handleQueryPartEvent(conditionModel: any, evt: any) {\n switch (evt.name) {\n case 'action-remove-part': {\n break;\n }\n case 'get-part-actions': {\n return Promise.resolve([]);\n }\n case 'part-param-changed': {\n this.validateModel();\n }\n case 'get-param-options': {\n const result = this.panel.targets.map((target) => {\n return this.uiSegmentSrv.newSegment({ value: target.refId });\n });\n\n return Promise.resolve(result);\n }\n default: {\n return Promise.resolve();\n }\n }\n\n return Promise.resolve();\n }\n\n handleReducerPartEvent(conditionModel: any, evt: any) {\n switch (evt.name) {\n case 'action': {\n conditionModel.source.reducer.type = evt.action.value;\n conditionModel.reducerPart = alertDef.createReducerPart(conditionModel.source.reducer);\n this.evaluatorParamsChanged();\n break;\n }\n case 'get-part-actions': {\n const result = [];\n for (const type of alertDef.reducerTypes) {\n if (type.value !== conditionModel.source.reducer.type) {\n result.push(type);\n }\n }\n return Promise.resolve(result);\n }\n }\n\n return Promise.resolve();\n }\n\n addCondition(type: string) {\n const condition = getDefaultCondition();\n // add to persited model\n this.alert.conditions.push(condition);\n // add to view model\n this.conditionModels.push(this.buildConditionModel(condition));\n }\n\n removeCondition(index: number) {\n this.alert.conditions.splice(index, 1);\n this.conditionModels.splice(index, 1);\n }\n\n delete() {\n appEvents.publish(\n new ShowConfirmModalEvent({\n title: 'Delete Alert',\n text: 'Are you sure you want to delete this alert rule?',\n text2: 'You need to save dashboard for the delete to take effect',\n icon: 'trash-alt',\n yesText: 'Delete',\n onConfirm: () => {\n delete this.panel.alert;\n this.alert = null;\n this.panel.thresholds = [];\n this.conditionModels = [];\n this.panelCtrl.alertState = null;\n this.panelCtrl.render();\n },\n })\n );\n }\n\n enable = () => {\n this.panel.alert = {};\n this.initModel();\n this.panel.alert.for = '5m'; //default value for new alerts. for existing alerts we use 0m to avoid breaking changes\n };\n\n evaluatorParamsChanged() {\n ThresholdMapper.alertToGraphThresholds(this.panel);\n this.panelCtrl.render();\n }\n\n evaluatorTypeChanged(evaluator: any) {\n // ensure params array is correct length\n switch (evaluator.type) {\n case 'lt':\n case 'gt': {\n evaluator.params = [evaluator.params[0]];\n break;\n }\n case 'within_range':\n case 'outside_range': {\n evaluator.params = [evaluator.params[0], evaluator.params[1]];\n break;\n }\n case 'no_value': {\n evaluator.params = [];\n }\n }\n\n this.evaluatorParamsChanged();\n }\n\n clearHistory() {\n appEvents.publish(\n new ShowConfirmModalEvent({\n title: 'Delete Alert History',\n text: 'Are you sure you want to remove all history & annotations for this alert?',\n icon: 'trash-alt',\n yesText: 'Yes',\n onConfirm: () => {\n promiseToDigest(this.$scope)(\n getBackendSrv()\n .post('/api/annotations/mass-delete', {\n dashboardId: this.panelCtrl.dashboard.id,\n panelId: this.panel.id,\n })\n .then(() => {\n this.alertHistory = [];\n this.panelCtrl.refresh();\n })\n );\n },\n })\n );\n }\n}\n\n/** @ngInject */\nexport function alertTab() {\n 'use strict';\n return {\n restrict: 'E',\n scope: true,\n templateUrl: 'public/app/features/alerting/partials/alert_tab.html',\n controller: AlertTabCtrl,\n };\n}\n\ncoreModule.directive('alertTab', alertTab);\n","import { config } from 'app/core/config';\nimport { PanelModel } from 'app/features/dashboard/state';\n\nexport const hiddenReducerTypes = ['percent_diff', 'percent_diff_abs'];\nexport class ThresholdMapper {\n static alertToGraphThresholds(panel: PanelModel) {\n if (!panel.alert || config.unifiedAlertingEnabled) {\n return false; // no update when no alerts\n }\n\n for (let i = 0; i < panel.alert.conditions.length; i++) {\n const condition = panel.alert.conditions[i];\n if (condition.type !== 'query') {\n continue;\n }\n\n const evaluator = condition.evaluator;\n const thresholds: any[] = (panel.thresholds = []);\n const visible = hiddenReducerTypes.indexOf(condition.reducer?.type) === -1;\n\n switch (evaluator.type) {\n case 'gt': {\n const value = evaluator.params[0];\n thresholds.push({ value: value, op: 'gt', visible });\n break;\n }\n case 'lt': {\n const value = evaluator.params[0];\n thresholds.push({ value: value, op: 'lt', visible });\n break;\n }\n case 'outside_range': {\n const value1 = evaluator.params[0];\n const value2 = evaluator.params[1];\n\n if (value1 > value2) {\n thresholds.push({ value: value1, op: 'gt', visible });\n thresholds.push({ value: value2, op: 'lt', visible });\n } else {\n thresholds.push({ value: value1, op: 'lt', visible });\n thresholds.push({ value: value2, op: 'gt', visible });\n }\n\n break;\n }\n case 'within_range': {\n const value1 = evaluator.params[0];\n const value2 = evaluator.params[1];\n\n if (value1 > value2) {\n thresholds.push({ value: value1, op: 'lt', visible });\n thresholds.push({ value: value2, op: 'gt', visible });\n } else {\n thresholds.push({ value: value1, op: 'gt', visible });\n thresholds.push({ value: value2, op: 'lt', visible });\n }\n break;\n }\n }\n break;\n }\n\n for (const t of panel.thresholds) {\n t.fill = panel.options.alertThreshold;\n t.line = panel.options.alertThreshold;\n t.colorMode = 'critical';\n }\n\n const updated = true;\n return updated;\n }\n}\n"],"names":["coreModule","angular","angularModules","promiseToDigest","$scope","promise","finally","$evalAsync","AlertTabCtrl","constructor","dashboardSrv","uiSegmentSrv","datasourceSrv","this","panel","alert","initModel","for","panelCtrl","ctrl","subTabIndex","evalFunctions","alertDef","evalOperators","conditionTypes","noDataModes","executionErrorModes","appSubUrl","config","_enableAlert","enable","alertingMinIntervalSecs","alertingMinInterval","rangeUtil","$onInit","addNotificationSegment","newPlusButton","thresholdChangedEventHandler","graphThresholdChanged","bind","events","on","CoreEvents","$on","off","editingThresholds","render","notifications","alertNotifications","alertHistory","getBackendSrv","get","then","res","validateModel","getAlertHistory","dashboard","id","map","ah","time","getCurrent","formatDate","stateModel","newState","info","getNotificationIcon","type","getNotifications","Promise","resolve","item","newSegment","name","notificationAdded","model","find","value","push","iconClass","isDefault","uid","n","html","fake","removeNotification","an","remove","addAlertRuleTag","newAlertRuleTag","alertRuleTags","removeAlertRuleTag","tagName","checkFrequency","conditions","length","getDefaultCondition","noDataState","executionErrorState","frequency","handler","defaultName","title","conditionModels","reduce","memo","buildConditionModel","ThresholdMapper","addedNotification","identifier","appEvents","ShowConfirmModalEvent","text","text2","icon","confirmText","yesText","onConfirm","async","notification","frequencyWarning","match","err","evt","condition","evaluator","params","handleIndex","threshold","evaluatorParamsChanged","firstTarget","foundTarget","promises","target","targets","query","refId","error","datasourceName","datasource","ds","meta","alerting","targetContainsTemplate","reject","all","$apply","e","source","cm","queryPart","QueryPart","reducerPart","reducer","operator","handleQueryPartEvent","conditionModel","result","handleReducerPartEvent","action","addCondition","removeCondition","index","splice","delete","thresholds","alertState","evaluatorTypeChanged","clearHistory","post","dashboardId","panelId","refresh","alertTab","restrict","scope","templateUrl","controller","hiddenReducerTypes","i","visible","indexOf","op","value1","value2","t","fill","options","alertThreshold","line","colorMode"],"sourceRoot":""}