|
|
|
@ -22,7 +22,6 @@ var alertQueryDef = new QueryPartDef({ |
|
|
|
export class AlertTabCtrl { |
|
|
|
export class AlertTabCtrl { |
|
|
|
panel: any; |
|
|
|
panel: any; |
|
|
|
panelCtrl: any; |
|
|
|
panelCtrl: any; |
|
|
|
alerting: any; |
|
|
|
|
|
|
|
metricTargets = [{ refId: '- select query -' } ]; |
|
|
|
metricTargets = [{ refId: '- select query -' } ]; |
|
|
|
schedulers = [{text: 'Grafana', value: 1}, {text: 'External', value: 0}]; |
|
|
|
schedulers = [{text: 'Grafana', value: 1}, {text: 'External', value: 0}]; |
|
|
|
transforms = [ |
|
|
|
transforms = [ |
|
|
|
@ -36,7 +35,7 @@ export class AlertTabCtrl { |
|
|
|
}, |
|
|
|
}, |
|
|
|
]; |
|
|
|
]; |
|
|
|
aggregators = ['avg', 'sum', 'min', 'max', 'last']; |
|
|
|
aggregators = ['avg', 'sum', 'min', 'max', 'last']; |
|
|
|
rule: any; |
|
|
|
alert: any; |
|
|
|
query: any; |
|
|
|
query: any; |
|
|
|
queryParams: any; |
|
|
|
queryParams: any; |
|
|
|
transformDef: any; |
|
|
|
transformDef: any; |
|
|
|
@ -71,33 +70,37 @@ export class AlertTabCtrl { |
|
|
|
$scope.ctrl = this; |
|
|
|
$scope.ctrl = this; |
|
|
|
|
|
|
|
|
|
|
|
this.metricTargets = this.panel.targets.map(val => val); |
|
|
|
this.metricTargets = this.panel.targets.map(val => val); |
|
|
|
this.rule = this.panel.alerting = this.panel.alerting || {}; |
|
|
|
|
|
|
|
|
|
|
|
this.initAlertModel(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
initAlertModel() { |
|
|
|
|
|
|
|
this.alert = this.panel.alert = this.panel.alert || {}; |
|
|
|
|
|
|
|
|
|
|
|
// set defaults
|
|
|
|
// set defaults
|
|
|
|
_.defaults(this.rule, this.defaultValues); |
|
|
|
_.defaults(this.alert, this.defaultValues); |
|
|
|
|
|
|
|
|
|
|
|
var defaultName = (this.panelCtrl.dashboard.title + ' ' + this.panel.title + ' alert'); |
|
|
|
var defaultName = (this.panelCtrl.dashboard.title + ' ' + this.panel.title + ' alert'); |
|
|
|
this.rule.name = this.rule.name || defaultName; |
|
|
|
this.alert.name = this.alert.name || defaultName; |
|
|
|
this.rule.description = this.rule.description || defaultName; |
|
|
|
this.alert.description = this.alert.description || defaultName; |
|
|
|
this.rule.queryRef = this.panel.alerting.queryRef || this.metricTargets[0].refId; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// great temp working model
|
|
|
|
// great temp working model
|
|
|
|
this.queryParams = { |
|
|
|
this.queryParams = { |
|
|
|
params: [ |
|
|
|
params: [ |
|
|
|
this.rule.query.refId, |
|
|
|
this.alert.query.refId, |
|
|
|
this.rule.query.from, |
|
|
|
this.alert.query.from, |
|
|
|
this.rule.query.to |
|
|
|
this.alert.query.to |
|
|
|
] |
|
|
|
] |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
// init the query part components model
|
|
|
|
// init the query part components model
|
|
|
|
this.query = new QueryPart(this.queryParams, alertQueryDef); |
|
|
|
this.query = new QueryPart(this.queryParams, alertQueryDef); |
|
|
|
this.convertThresholdsToAlertThresholds(); |
|
|
|
this.convertThresholdsToAlertThresholds(); |
|
|
|
this.transformDef = _.findWhere(this.transforms, {type: this.rule.transform.type}); |
|
|
|
this.transformDef = _.findWhere(this.transforms, {type: this.alert.transform.type}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
queryUpdated() { |
|
|
|
queryUpdated() { |
|
|
|
this.rule.query = { |
|
|
|
this.alert.query = { |
|
|
|
refId: this.query.params[0], |
|
|
|
refId: this.query.params[0], |
|
|
|
from: this.query.params[1], |
|
|
|
from: this.query.params[1], |
|
|
|
to: this.query.params[2], |
|
|
|
to: this.query.params[2], |
|
|
|
@ -106,16 +109,16 @@ export class AlertTabCtrl { |
|
|
|
|
|
|
|
|
|
|
|
transformChanged() { |
|
|
|
transformChanged() { |
|
|
|
// clear model
|
|
|
|
// clear model
|
|
|
|
this.rule.transform = {type: this.rule.transform.type}; |
|
|
|
this.alert.transform = {type: this.alert.transform.type}; |
|
|
|
this.transformDef = _.findWhere(this.transforms, {type: this.rule.transform.type}); |
|
|
|
this.transformDef = _.findWhere(this.transforms, {type: this.alert.transform.type}); |
|
|
|
|
|
|
|
|
|
|
|
switch (this.rule.transform.type) { |
|
|
|
switch (this.alert.transform.type) { |
|
|
|
case 'aggregation': { |
|
|
|
case 'aggregation': { |
|
|
|
this.rule.transform.method = 'avg'; |
|
|
|
this.alert.transform.method = 'avg'; |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
case "forecast": { |
|
|
|
case "forecast": { |
|
|
|
this.rule.transform.timespan = '7d'; |
|
|
|
this.alert.transform.timespan = '7d'; |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@ -124,45 +127,34 @@ export class AlertTabCtrl { |
|
|
|
convertThresholdsToAlertThresholds() { |
|
|
|
convertThresholdsToAlertThresholds() { |
|
|
|
if (this.panel.grid |
|
|
|
if (this.panel.grid |
|
|
|
&& this.panel.grid.threshold1 |
|
|
|
&& this.panel.grid.threshold1 |
|
|
|
&& this.rule.warnLevel === undefined |
|
|
|
&& this.alert.warnLevel === undefined |
|
|
|
) { |
|
|
|
) { |
|
|
|
this.rule.warning.op = '>'; |
|
|
|
this.alert.warning.op = '>'; |
|
|
|
this.rule.warning.level = this.panel.grid.threshold1; |
|
|
|
this.alert.warning.level = this.panel.grid.threshold1; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (this.panel.grid |
|
|
|
if (this.panel.grid |
|
|
|
&& this.panel.grid.threshold2 |
|
|
|
&& this.panel.grid.threshold2 |
|
|
|
&& this.rule.critical.level === undefined |
|
|
|
&& this.alert.critical.level === undefined |
|
|
|
) { |
|
|
|
) { |
|
|
|
this.rule.critical.op = '>'; |
|
|
|
this.alert.critical.op = '>'; |
|
|
|
this.rule.critical.level = this.panel.grid.threshold2; |
|
|
|
this.alert.critical.level = this.panel.grid.threshold2; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
delete() { |
|
|
|
delete() { |
|
|
|
this.rule = this.panel.alerting = this.defaultValues; |
|
|
|
this.alert = this.panel.alert = {}; |
|
|
|
this.rule.deleted = true; |
|
|
|
this.alert.deleted = true; |
|
|
|
|
|
|
|
this.initAlertModel(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
enable() { |
|
|
|
enable() { |
|
|
|
delete this.rule.deleted; |
|
|
|
delete this.alert.deleted; |
|
|
|
this.rule.enabled = true; |
|
|
|
this.alert.enabled = true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
disable() { |
|
|
|
disable() { |
|
|
|
this.rule.enabled = false; |
|
|
|
this.alert.enabled = false; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
thresholdsUpdated() { |
|
|
|
|
|
|
|
if (this.panel.alerting.warnLevel) { |
|
|
|
|
|
|
|
this.panel.grid.threshold1 = parseInt(this.panel.alerting.warnLevel); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (this.panel.alerting.critLevel) { |
|
|
|
|
|
|
|
this.panel.grid.threshold2 = parseInt(this.panel.alerting.critLevel); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.panelCtrl.render(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|