refactor: use constants instead magic values

This commit is contained in:
Alexander Zobnin
2017-06-08 13:53:02 +03:00
parent 3eb5dc49e6
commit fe455113d5
12 changed files with 158 additions and 46 deletions

View File

@@ -29,6 +29,10 @@ var _metricFunctions = require('./metricFunctions');
var metricFunctions = _interopRequireWildcard(_metricFunctions);
var _constants = require('./constants');
var c = _interopRequireWildcard(_constants);
var _dataProcessor = require('./dataProcessor');
var _dataProcessor2 = _interopRequireDefault(_dataProcessor);
@@ -82,7 +86,7 @@ var ZabbixAPIDatasource = function () {
// Alerting options
this.alertingEnabled = instanceSettings.jsonData.alerting;
this.addThresholds = instanceSettings.jsonData.addThresholds;
this.alertingMinSeverity = instanceSettings.jsonData.alertingMinSeverity || 2;
this.alertingMinSeverity = instanceSettings.jsonData.alertingMinSeverity || c.SEV_WARNING;
this.zabbix = new Zabbix(this.url, this.username, this.password, this.basicAuth, this.withCredentials, this.cacheTTL);
@@ -144,7 +148,7 @@ var ZabbixAPIDatasource = function () {
var useTrends = _this.isUseTrends([timeFrom, timeTo]);
// Metrics or Text query mode
if (target.mode !== 1) {
if (target.mode !== c.MODE_ITSERVICE) {
// Migrate old targets
target = migrations.migrate(target);
@@ -153,15 +157,15 @@ var ZabbixAPIDatasource = function () {
return [];
}
if (!target.mode || target.mode === 0) {
if (!target.mode || target.mode === c.MODE_METRICS) {
return _this.queryNumericData(target, timeFrom, timeTo, useTrends);
} else if (target.mode === 2) {
} else if (target.mode === c.MODE_TEXT) {
return _this.queryTextData(target, timeFrom, timeTo);
}
}
// IT services mode
else if (target.mode === 1) {
else if (target.mode === c.MODE_ITSERVICE) {
// Don't show undefined and hidden targets
if (target.hide || !target.itservice || !target.slaProperty) {
return [];
@@ -410,10 +414,10 @@ var ZabbixAPIDatasource = function () {
var timeFrom = Math.ceil(dateMath.parse(options.rangeRaw.from) / 1000);
var timeTo = Math.ceil(dateMath.parse(options.rangeRaw.to) / 1000);
var annotation = options.annotation;
var showOkEvents = annotation.showOkEvents ? [0, 1] : 1;
var showOkEvents = annotation.showOkEvents ? c.SHOW_ALL_EVENTS : c.SHOW_OK_EVENTS;
// Show all triggers
var showTriggers = [0, 1];
var showTriggers = c.SHOW_ALL_TRIGGERS;
var getTriggers = this.zabbix.getTriggers(this.replaceTemplateVars(annotation.group, {}), this.replaceTemplateVars(annotation.host, {}), this.replaceTemplateVars(annotation.application, {}), showTriggers);