|
@@ -5,9 +5,14 @@ import { QueryPart } from 'app/core/components/query_part/query_part';
|
|
|
import alertDef from './state/alertDef';
|
|
import alertDef from './state/alertDef';
|
|
|
import config from 'app/core/config';
|
|
import config from 'app/core/config';
|
|
|
import appEvents from 'app/core/app_events';
|
|
import appEvents from 'app/core/app_events';
|
|
|
|
|
+import { BackendSrv } from 'app/core/services/backend_srv';
|
|
|
|
|
+import { DashboardSrv } from '../dashboard/services/DashboardSrv';
|
|
|
|
|
+import DatasourceSrv from '../plugins/datasource_srv';
|
|
|
|
|
+import { DataQuery } from '@grafana/ui/src/types/datasource';
|
|
|
|
|
+import { PanelModel } from 'app/features/dashboard/state';
|
|
|
|
|
|
|
|
export class AlertTabCtrl {
|
|
export class AlertTabCtrl {
|
|
|
- panel: any;
|
|
|
|
|
|
|
+ panel: PanelModel;
|
|
|
panelCtrl: any;
|
|
panelCtrl: any;
|
|
|
subTabIndex: number;
|
|
subTabIndex: number;
|
|
|
conditionTypes: any;
|
|
conditionTypes: any;
|
|
@@ -17,21 +22,21 @@ export class AlertTabCtrl {
|
|
|
evalOperators: any;
|
|
evalOperators: any;
|
|
|
noDataModes: any;
|
|
noDataModes: any;
|
|
|
executionErrorModes: any;
|
|
executionErrorModes: any;
|
|
|
- addNotificationSegment;
|
|
|
|
|
- notifications;
|
|
|
|
|
- alertNotifications;
|
|
|
|
|
|
|
+ addNotificationSegment: any;
|
|
|
|
|
+ notifications: any;
|
|
|
|
|
+ alertNotifications: any;
|
|
|
error: string;
|
|
error: string;
|
|
|
appSubUrl: string;
|
|
appSubUrl: string;
|
|
|
alertHistory: any;
|
|
alertHistory: any;
|
|
|
|
|
|
|
|
/** @ngInject */
|
|
/** @ngInject */
|
|
|
constructor(
|
|
constructor(
|
|
|
- private $scope,
|
|
|
|
|
- private backendSrv,
|
|
|
|
|
- private dashboardSrv,
|
|
|
|
|
- private uiSegmentSrv,
|
|
|
|
|
- private $q,
|
|
|
|
|
- private datasourceSrv
|
|
|
|
|
|
|
+ private $scope: any,
|
|
|
|
|
+ private backendSrv: BackendSrv,
|
|
|
|
|
+ private dashboardSrv: DashboardSrv,
|
|
|
|
|
+ private uiSegmentSrv: any,
|
|
|
|
|
+ private $q: any,
|
|
|
|
|
+ private datasourceSrv: DatasourceSrv
|
|
|
) {
|
|
) {
|
|
|
this.panelCtrl = $scope.ctrl;
|
|
this.panelCtrl = $scope.ctrl;
|
|
|
this.panel = this.panelCtrl.panel;
|
|
this.panel = this.panelCtrl.panel;
|
|
@@ -65,7 +70,7 @@ export class AlertTabCtrl {
|
|
|
this.alertNotifications = [];
|
|
this.alertNotifications = [];
|
|
|
this.alertHistory = [];
|
|
this.alertHistory = [];
|
|
|
|
|
|
|
|
- return this.backendSrv.get('/api/alert-notifications').then(res => {
|
|
|
|
|
|
|
+ return this.backendSrv.get('/api/alert-notifications').then((res: any) => {
|
|
|
this.notifications = res;
|
|
this.notifications = res;
|
|
|
|
|
|
|
|
this.initModel();
|
|
this.initModel();
|
|
@@ -76,7 +81,7 @@ export class AlertTabCtrl {
|
|
|
getAlertHistory() {
|
|
getAlertHistory() {
|
|
|
this.backendSrv
|
|
this.backendSrv
|
|
|
.get(`/api/annotations?dashboardId=${this.panelCtrl.dashboard.id}&panelId=${this.panel.id}&limit=50&type=alert`)
|
|
.get(`/api/annotations?dashboardId=${this.panelCtrl.dashboard.id}&panelId=${this.panel.id}&limit=50&type=alert`)
|
|
|
- .then(res => {
|
|
|
|
|
|
|
+ .then((res: any) => {
|
|
|
this.alertHistory = _.map(res, ah => {
|
|
this.alertHistory = _.map(res, ah => {
|
|
|
ah.time = this.dashboardSrv.getCurrent().formatDate(ah.time, 'MMM D, YYYY HH:mm:ss');
|
|
ah.time = this.dashboardSrv.getCurrent().formatDate(ah.time, 'MMM D, YYYY HH:mm:ss');
|
|
|
ah.stateModel = alertDef.getStateDisplayModel(ah.newState);
|
|
ah.stateModel = alertDef.getStateDisplayModel(ah.newState);
|
|
@@ -86,7 +91,7 @@ export class AlertTabCtrl {
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- getNotificationIcon(type): string {
|
|
|
|
|
|
|
+ getNotificationIcon(type: string): string {
|
|
|
switch (type) {
|
|
switch (type) {
|
|
|
case 'email':
|
|
case 'email':
|
|
|
return 'fa fa-envelope';
|
|
return 'fa fa-envelope';
|
|
@@ -114,20 +119,12 @@ export class AlertTabCtrl {
|
|
|
|
|
|
|
|
getNotifications() {
|
|
getNotifications() {
|
|
|
return this.$q.when(
|
|
return this.$q.when(
|
|
|
- this.notifications.map(item => {
|
|
|
|
|
|
|
+ this.notifications.map((item: any) => {
|
|
|
return this.uiSegmentSrv.newSegment(item.name);
|
|
return this.uiSegmentSrv.newSegment(item.name);
|
|
|
})
|
|
})
|
|
|
);
|
|
);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- changeTabIndex(newTabIndex) {
|
|
|
|
|
- this.subTabIndex = newTabIndex;
|
|
|
|
|
-
|
|
|
|
|
- if (this.subTabIndex === 2) {
|
|
|
|
|
- this.getAlertHistory();
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
notificationAdded() {
|
|
notificationAdded() {
|
|
|
const model: any = _.find(this.notifications, {
|
|
const model: any = _.find(this.notifications, {
|
|
|
name: this.addNotificationSegment.value,
|
|
name: this.addNotificationSegment.value,
|
|
@@ -154,7 +151,7 @@ export class AlertTabCtrl {
|
|
|
this.addNotificationSegment.fake = true;
|
|
this.addNotificationSegment.fake = true;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- removeNotification(an) {
|
|
|
|
|
|
|
+ removeNotification(an: any) {
|
|
|
// remove notifiers refeered to by id and uid to support notifiers added
|
|
// remove notifiers refeered to by id and uid to support notifiers added
|
|
|
// before and after we added support for uid
|
|
// before and after we added support for uid
|
|
|
_.remove(this.alert.notifications, (n: any) => n.uid === an.uid || n.id === an.id);
|
|
_.remove(this.alert.notifications, (n: any) => n.uid === an.uid || n.id === an.id);
|
|
@@ -220,7 +217,7 @@ export class AlertTabCtrl {
|
|
|
this.panelCtrl.render();
|
|
this.panelCtrl.render();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- graphThresholdChanged(evt) {
|
|
|
|
|
|
|
+ graphThresholdChanged(evt: any) {
|
|
|
for (const condition of this.alert.conditions) {
|
|
for (const condition of this.alert.conditions) {
|
|
|
if (condition.type === 'query') {
|
|
if (condition.type === 'query') {
|
|
|
condition.evaluator.params[evt.handleIndex] = evt.threshold.value;
|
|
condition.evaluator.params[evt.handleIndex] = evt.threshold.value;
|
|
@@ -234,8 +231,8 @@ export class AlertTabCtrl {
|
|
|
return {
|
|
return {
|
|
|
type: 'query',
|
|
type: 'query',
|
|
|
query: { params: ['A', '5m', 'now'] },
|
|
query: { params: ['A', '5m', 'now'] },
|
|
|
- reducer: { type: 'avg', params: [] },
|
|
|
|
|
- evaluator: { type: 'gt', params: [null] },
|
|
|
|
|
|
|
+ reducer: { type: 'avg', params: [] as any[] },
|
|
|
|
|
+ evaluator: { type: 'gt', params: [null] as any[] },
|
|
|
operator: { type: 'and' },
|
|
operator: { type: 'and' },
|
|
|
};
|
|
};
|
|
|
}
|
|
}
|
|
@@ -246,7 +243,7 @@ export class AlertTabCtrl {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
let firstTarget;
|
|
let firstTarget;
|
|
|
- let foundTarget = null;
|
|
|
|
|
|
|
+ let foundTarget: DataQuery = null;
|
|
|
|
|
|
|
|
for (const condition of this.alert.conditions) {
|
|
for (const condition of this.alert.conditions) {
|
|
|
if (condition.type !== 'query') {
|
|
if (condition.type !== 'query') {
|
|
@@ -285,7 +282,7 @@ export class AlertTabCtrl {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- buildConditionModel(source) {
|
|
|
|
|
|
|
+ buildConditionModel(source: any) {
|
|
|
const cm: any = { source: source, type: source.type };
|
|
const cm: any = { source: source, type: source.type };
|
|
|
|
|
|
|
|
cm.queryPart = new QueryPart(source.query, alertDef.alertQueryDef);
|
|
cm.queryPart = new QueryPart(source.query, alertDef.alertQueryDef);
|
|
@@ -296,7 +293,7 @@ export class AlertTabCtrl {
|
|
|
return cm;
|
|
return cm;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- handleQueryPartEvent(conditionModel, evt) {
|
|
|
|
|
|
|
+ handleQueryPartEvent(conditionModel: any, evt: any) {
|
|
|
switch (evt.name) {
|
|
switch (evt.name) {
|
|
|
case 'action-remove-part': {
|
|
case 'action-remove-part': {
|
|
|
break;
|
|
break;
|
|
@@ -317,7 +314,7 @@ export class AlertTabCtrl {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- handleReducerPartEvent(conditionModel, evt) {
|
|
|
|
|
|
|
+ handleReducerPartEvent(conditionModel: any, evt: any) {
|
|
|
switch (evt.name) {
|
|
switch (evt.name) {
|
|
|
case 'action': {
|
|
case 'action': {
|
|
|
conditionModel.source.reducer.type = evt.action.value;
|
|
conditionModel.source.reducer.type = evt.action.value;
|
|
@@ -336,7 +333,7 @@ export class AlertTabCtrl {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- addCondition(type) {
|
|
|
|
|
|
|
+ addCondition(type: string) {
|
|
|
const condition = this.buildDefaultCondition();
|
|
const condition = this.buildDefaultCondition();
|
|
|
// add to persited model
|
|
// add to persited model
|
|
|
this.alert.conditions.push(condition);
|
|
this.alert.conditions.push(condition);
|
|
@@ -344,7 +341,7 @@ export class AlertTabCtrl {
|
|
|
this.conditionModels.push(this.buildConditionModel(condition));
|
|
this.conditionModels.push(this.buildConditionModel(condition));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- removeCondition(index) {
|
|
|
|
|
|
|
+ removeCondition(index: number) {
|
|
|
this.alert.conditions.splice(index, 1);
|
|
this.alert.conditions.splice(index, 1);
|
|
|
this.conditionModels.splice(index, 1);
|
|
this.conditionModels.splice(index, 1);
|
|
|
}
|
|
}
|
|
@@ -378,7 +375,7 @@ export class AlertTabCtrl {
|
|
|
this.panelCtrl.render();
|
|
this.panelCtrl.render();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- evaluatorTypeChanged(evaluator) {
|
|
|
|
|
|
|
+ evaluatorTypeChanged(evaluator: any) {
|
|
|
// ensure params array is correct length
|
|
// ensure params array is correct length
|
|
|
switch (evaluator.type) {
|
|
switch (evaluator.type) {
|
|
|
case 'lt':
|
|
case 'lt':
|
|
@@ -411,7 +408,7 @@ export class AlertTabCtrl {
|
|
|
dashboardId: this.panelCtrl.dashboard.id,
|
|
dashboardId: this.panelCtrl.dashboard.id,
|
|
|
panelId: this.panel.id,
|
|
panelId: this.panel.id,
|
|
|
})
|
|
})
|
|
|
- .then(res => {
|
|
|
|
|
|
|
+ .then(() => {
|
|
|
this.alertHistory = [];
|
|
this.alertHistory = [];
|
|
|
this.panelCtrl.refresh();
|
|
this.panelCtrl.refresh();
|
|
|
});
|
|
});
|