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

@@ -0,0 +1,21 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
// Editor modes
var MODE_METRICS = exports.MODE_METRICS = 0;
var MODE_TEXT = exports.MODE_TEXT = 2;
var MODE_ITSERVICE = exports.MODE_ITSERVICE = 1;
// Triggers severity
var SEV_NOT_CLASSIFIED = exports.SEV_NOT_CLASSIFIED = 0;
var SEV_INFORMATION = exports.SEV_INFORMATION = 1;
var SEV_WARNING = exports.SEV_WARNING = 2;
var SEV_AVERAGE = exports.SEV_AVERAGE = 3;
var SEV_HIGH = exports.SEV_HIGH = 4;
var SEV_DISASTER = exports.SEV_DISASTER = 5;
var SHOW_ALL_TRIGGERS = exports.SHOW_ALL_TRIGGERS = [0, 1];
var SHOW_ALL_EVENTS = exports.SHOW_ALL_EVENTS = [0, 1];
var SHOW_OK_EVENTS = exports.SHOW_OK_EVENTS = 1;

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);

View File

@@ -17,6 +17,10 @@ var _lodash = require('lodash');
var _lodash2 = _interopRequireDefault(_lodash);
var _constants = require('./constants');
var c = _interopRequireWildcard(_constants);
var _utils = require('./utils');
var utils = _interopRequireWildcard(_utils);
@@ -61,9 +65,9 @@ var ZabbixQueryController = exports.ZabbixQueryController = function (_QueryCtrl
_this.templateSrv = templateSrv;
_this.editorModes = {
0: { value: 'num', text: 'Metrics', mode: 0 },
1: { value: 'itservice', text: 'IT Services', mode: 1 },
2: { value: 'text', text: 'Text', mode: 2 }
0: { value: 'num', text: 'Metrics', mode: c.MODE_METRICS },
1: { value: 'itservice', text: 'IT Services', mode: c.MODE_ITSERVICE },
2: { value: 'text', text: 'Text', mode: c.MODE_TEXT }
};
// Map functions for bs-typeahead
@@ -97,7 +101,7 @@ var ZabbixQueryController = exports.ZabbixQueryController = function (_QueryCtrl
// Load default values
var targetDefaults = {
mode: 0,
mode: c.MODE_METRICS,
group: { filter: "" },
host: { filter: "" },
application: { filter: "" },
@@ -114,12 +118,12 @@ var ZabbixQueryController = exports.ZabbixQueryController = function (_QueryCtrl
return metricFunctions.createFuncInstance(func.def, func.params);
});
if (target.mode === 0 || target.mode === 2) {
if (target.mode === c.MODE_METRICS || target.mode === c.MODE_TEXT) {
this.downsampleFunctionList = [{ name: "avg", value: "avg" }, { name: "min", value: "min" }, { name: "max", value: "max" }, { name: "sum", value: "sum" }, { name: "count", value: "count" }];
this.initFilters();
} else if (target.mode === 1) {
} else if (target.mode === c.MODE_ITSERVICE) {
this.slaPropertyList = [{ name: "Status", property: "status" }, { name: "SLA", property: "sla" }, { name: "OK time", property: "okTime" }, { name: "Problem time", property: "problemTime" }, { name: "Down time", property: "downtimeTime" }];
this.itserviceList = [{ name: "test" }];
this.updateITServiceList();