mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
tech(alerting): add default values for alerts
This commit is contained in:
parent
b58be91e71
commit
c76c2f30a8
@ -42,9 +42,7 @@ QueryRange: The time range for which the query should look back.
|
||||
Aggregator: How the result should be reduced into a single value. ex avg, sum, min, max
|
||||
State: Current state of the alert OK, WARN, CRITICAL, ACKNOWLEGED.
|
||||
|
||||
You can configure these settings in the Alerting tab on graph panels in edit mode. When the dashboard is saved the alert is created, updated based on what data you provide. If you wish to delete an alert you simply set the query to '- select query -' in the alerting tab and save the dashboard. (this will be improved within the UI later on).
|
||||
|
||||
|
||||
You can configure these settings in the Alerting tab on graph panels in edit mode. When the dashboard is saved the alert is created or updated based on the dashboard. If you wish to delete an alert you simply set the query to '- select query -' in the alerting tab and save the dashboard. (this will be improved within the UI later on).
|
||||
|
||||
## Api
|
||||
|
||||
|
@ -12,17 +12,23 @@ export class AlertTabCtrl {
|
||||
operators = ['>', '<', '<=', '>='];
|
||||
aggregators = ['avg', 'sum', 'min', 'max', 'median'];
|
||||
|
||||
defaultValues = {
|
||||
aggregator: 'avg',
|
||||
interval: '60s',
|
||||
queryRange: '10m',
|
||||
warnOperator: '>',
|
||||
critOperator: '>',
|
||||
queryRef: '- select query -'
|
||||
};
|
||||
|
||||
/** @ngInject */
|
||||
constructor($scope, private $timeout) {
|
||||
$scope.alertTab = this; //HACK ATTACK!
|
||||
this.panelCtrl = $scope.ctrl;
|
||||
this.panel = this.panelCtrl.panel;
|
||||
this.panel.alerting = this.panel.alerting || {};
|
||||
this.panel.alerting.aggregator = this.panel.alerting.aggregator || 'avg';
|
||||
this.panel.alerting.interval = this.panel.alerting.interval || '60s';
|
||||
this.panel.alerting.queryRange = this.panel.alerting.queryRange || '10m';
|
||||
this.panel.alerting.warnOperator = this.panel.alerting.warnOperator || '>';
|
||||
this.panel.alerting.critOperator = this.panel.alerting.critOperator || '>';
|
||||
|
||||
_.defaults(this.panel.alerting, this.defaultValues);
|
||||
|
||||
var defaultTitle = (this.panelCtrl.dashboard.title + ' ' + this.panel.title + ' alert');
|
||||
this.panel.alerting.title = this.panel.alerting.title || defaultTitle;
|
||||
|
||||
@ -35,12 +41,17 @@ export class AlertTabCtrl {
|
||||
}
|
||||
|
||||
convertThresholdsToAlertThresholds() {
|
||||
if (this.panel.grid && this.panel.grid.threshold1) {
|
||||
if (this.panel.grid
|
||||
&& this.panel.grid.threshold1
|
||||
&& this.panel.alerting.warnLevel === undefined) {
|
||||
this.panel.alerting.warnOperator = '>';
|
||||
this.panel.alerting.warnLevel = this.panel.grid.threshold1;
|
||||
}
|
||||
|
||||
if (this.panel.grid && this.panel.grid.threshold2) {
|
||||
if (this.panel.grid
|
||||
&& this.panel.grid.threshold2
|
||||
&& this.panel.alerting.critLevel === undefined
|
||||
) {
|
||||
this.panel.alerting.critOperator = '>';
|
||||
this.panel.alerting.critLevel = this.panel.grid.threshold2;
|
||||
}
|
||||
@ -48,7 +59,7 @@ export class AlertTabCtrl {
|
||||
|
||||
markAsDeleted() {
|
||||
if (this.panel.alerting) {
|
||||
this.panel.alerting.queryRef = this.metricTargets[0].refId;
|
||||
this.panel.alerting = this.defaultValues;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user