diff --git a/public/app/features/alerting/alert_def.ts b/public/app/features/alerting/alert_def.ts index c65a35878e7..dc5be8b41c4 100644 --- a/public/app/features/alerting/alert_def.ts +++ b/public/app/features/alerting/alert_def.ts @@ -131,6 +131,29 @@ function joinEvalMatches(matches, separator: string) { }, []).join(separator); } +function getAlertAnnotationInfo(ah) { + + // backward compatability, can be removed in grafana 5.x + // old way stored evalMatches in data property directly, + // new way stores it in evalMatches property on new data object + + if (_.isArray(ah.data)) { + return joinEvalMatches(ah.data, ', '); + } else if (_.isArray(ah.data.evalMatches)) { + return joinEvalMatches(ah.data.evalMatches, ', '); + } + + if (ah.data.error) { + return "Error: " + ah.data.error; + } + + if (ah.data.noData || ah.data.no_data) { + return "No Data"; + } + + return ""; +} + export default { alertQueryDef: alertQueryDef, getStateDisplayModel: getStateDisplayModel, @@ -141,6 +164,6 @@ export default { executionErrorModes: executionErrorModes, reducerTypes: reducerTypes, createReducerPart: createReducerPart, - joinEvalMatches: joinEvalMatches, + getAlertAnnotationInfo: getAlertAnnotationInfo, alertStateSortScore: alertStateSortScore, }; diff --git a/public/app/features/alerting/alert_tab_ctrl.ts b/public/app/features/alerting/alert_tab_ctrl.ts index 63d192099c0..938b24ebc21 100644 --- a/public/app/features/alerting/alert_tab_ctrl.ts +++ b/public/app/features/alerting/alert_tab_ctrl.ts @@ -81,25 +81,7 @@ export class AlertTabCtrl { this.alertHistory = _.map(res, ah => { ah.time = moment(ah.time).format('MMM D, YYYY HH:mm:ss'); ah.stateModel = alertDef.getStateDisplayModel(ah.newState); - ah.reason = ""; - - if (_.isArray(ah.data)) { - ah.reason = "Conditions"; - ah.metrics = alertDef.joinEvalMatches(ah.data, ', '); - } else if (_.isArray(ah.data.evalMatches)) { - ah.metrics = alertDef.joinEvalMatches(ah.data.evalMatches, ', '); - } - - if (ah.data.error) { - ah.metrics = "" + ah.data.error; - ah.reason = "Error"; - } - - if (ah.data.noData || ah.data.no_data) { - ah.metrics = ""; - ah.reason = "No Data"; - } - + ah.info = alertDef.getAlertAnnotationInfo(ah); return ah; }); }); diff --git a/public/app/features/alerting/partials/alert_tab.html b/public/app/features/alerting/partials/alert_tab.html index b18f49c69a1..2e7956d4a6e 100644 --- a/public/app/features/alerting/partials/alert_tab.html +++ b/public/app/features/alerting/partials/alert_tab.html @@ -161,7 +161,7 @@ {{ah.time}}