refactor: use constants instead magic values
This commit is contained in:
60
dist/datasource-zabbix/constants.js
vendored
Normal file
60
dist/datasource-zabbix/constants.js
vendored
Normal file
@@ -0,0 +1,60 @@
|
||||
"use strict";
|
||||
|
||||
System.register([], function (_export, _context) {
|
||||
"use strict";
|
||||
|
||||
var MODE_METRICS, MODE_TEXT, MODE_ITSERVICE, SEV_NOT_CLASSIFIED, SEV_INFORMATION, SEV_WARNING, SEV_AVERAGE, SEV_HIGH, SEV_DISASTER, SHOW_ALL_TRIGGERS, SHOW_ALL_EVENTS, SHOW_OK_EVENTS;
|
||||
return {
|
||||
setters: [],
|
||||
execute: function () {
|
||||
_export("MODE_METRICS", MODE_METRICS = 0);
|
||||
|
||||
_export("MODE_METRICS", MODE_METRICS);
|
||||
|
||||
_export("MODE_TEXT", MODE_TEXT = 2);
|
||||
|
||||
_export("MODE_TEXT", MODE_TEXT);
|
||||
|
||||
_export("MODE_ITSERVICE", MODE_ITSERVICE = 1);
|
||||
|
||||
_export("MODE_ITSERVICE", MODE_ITSERVICE);
|
||||
|
||||
_export("SEV_NOT_CLASSIFIED", SEV_NOT_CLASSIFIED = 0);
|
||||
|
||||
_export("SEV_NOT_CLASSIFIED", SEV_NOT_CLASSIFIED);
|
||||
|
||||
_export("SEV_INFORMATION", SEV_INFORMATION = 1);
|
||||
|
||||
_export("SEV_INFORMATION", SEV_INFORMATION);
|
||||
|
||||
_export("SEV_WARNING", SEV_WARNING = 2);
|
||||
|
||||
_export("SEV_WARNING", SEV_WARNING);
|
||||
|
||||
_export("SEV_AVERAGE", SEV_AVERAGE = 3);
|
||||
|
||||
_export("SEV_AVERAGE", SEV_AVERAGE);
|
||||
|
||||
_export("SEV_HIGH", SEV_HIGH = 4);
|
||||
|
||||
_export("SEV_HIGH", SEV_HIGH);
|
||||
|
||||
_export("SEV_DISASTER", SEV_DISASTER = 5);
|
||||
|
||||
_export("SEV_DISASTER", SEV_DISASTER);
|
||||
|
||||
_export("SHOW_ALL_TRIGGERS", SHOW_ALL_TRIGGERS = [0, 1]);
|
||||
|
||||
_export("SHOW_ALL_TRIGGERS", SHOW_ALL_TRIGGERS);
|
||||
|
||||
_export("SHOW_ALL_EVENTS", SHOW_ALL_EVENTS = [0, 1]);
|
||||
|
||||
_export("SHOW_ALL_EVENTS", SHOW_ALL_EVENTS);
|
||||
|
||||
_export("SHOW_OK_EVENTS", SHOW_OK_EVENTS = 1);
|
||||
|
||||
_export("SHOW_OK_EVENTS", SHOW_OK_EVENTS);
|
||||
}
|
||||
};
|
||||
});
|
||||
//# sourceMappingURL=constants.js.map
|
||||
1
dist/datasource-zabbix/constants.js.map
vendored
Normal file
1
dist/datasource-zabbix/constants.js.map
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../../src/datasource-zabbix/constants.js"],"names":["MODE_METRICS","MODE_TEXT","MODE_ITSERVICE","SEV_NOT_CLASSIFIED","SEV_INFORMATION","SEV_WARNING","SEV_AVERAGE","SEV_HIGH","SEV_DISASTER","SHOW_ALL_TRIGGERS","SHOW_ALL_EVENTS","SHOW_OK_EVENTS"],"mappings":";;;;;;;;;8BACaA,Y,GAAe,C;;;;2BACfC,S,GAAY,C;;;;gCACZC,c,GAAiB,C;;;;oCAGjBC,kB,GAAqB,C;;;;iCACrBC,e,GAAkB,C;;;;6BAClBC,W,GAAc,C;;;;6BACdC,W,GAAc,C;;;;0BACdC,Q,GAAW,C;;;;8BACXC,Y,GAAe,C;;;;mCAEfC,iB,GAAoB,CAAC,CAAD,EAAI,CAAJ,C;;;;iCACpBC,e,GAAkB,CAAC,CAAD,EAAI,CAAJ,C;;;;gCAClBC,c,GAAiB,C","file":"constants.js","sourcesContent":["// Editor modes\nexport const MODE_METRICS = 0;\nexport const MODE_TEXT = 2;\nexport const MODE_ITSERVICE = 1;\n\n// Triggers severity\nexport const SEV_NOT_CLASSIFIED = 0;\nexport const SEV_INFORMATION = 1;\nexport const SEV_WARNING = 2;\nexport const SEV_AVERAGE = 3;\nexport const SEV_HIGH = 4;\nexport const SEV_DISASTER = 5;\n\nexport const SHOW_ALL_TRIGGERS = [0, 1];\nexport const SHOW_ALL_EVENTS = [0, 1];\nexport const SHOW_OK_EVENTS = 1;\n"]}
|
||||
20
dist/datasource-zabbix/datasource.js
vendored
20
dist/datasource-zabbix/datasource.js
vendored
@@ -1,9 +1,9 @@
|
||||
'use strict';
|
||||
|
||||
System.register(['lodash', 'app/core/utils/datemath', './utils', './migrations', './metricFunctions', './dataProcessor', './responseHandler', './zabbix.js', './zabbixAlerting.service.js', './zabbixAPICore.service.js'], function (_export, _context) {
|
||||
System.register(['lodash', 'app/core/utils/datemath', './utils', './migrations', './metricFunctions', './constants', './dataProcessor', './responseHandler', './zabbix.js', './zabbixAlerting.service.js', './zabbixAPICore.service.js'], function (_export, _context) {
|
||||
"use strict";
|
||||
|
||||
var _, dateMath, utils, migrations, metricFunctions, dataProcessor, responseHandler, ZabbixAPIError, _slicedToArray, _createClass, ZabbixAPIDatasource;
|
||||
var _, dateMath, utils, migrations, metricFunctions, c, dataProcessor, responseHandler, ZabbixAPIError, _slicedToArray, _createClass, ZabbixAPIDatasource;
|
||||
|
||||
function _classCallCheck(instance, Constructor) {
|
||||
if (!(instance instanceof Constructor)) {
|
||||
@@ -114,6 +114,8 @@ System.register(['lodash', 'app/core/utils/datemath', './utils', './migrations',
|
||||
migrations = _migrations;
|
||||
}, function (_metricFunctions) {
|
||||
metricFunctions = _metricFunctions;
|
||||
}, function (_constants) {
|
||||
c = _constants;
|
||||
}, function (_dataProcessor) {
|
||||
dataProcessor = _dataProcessor.default;
|
||||
}, function (_responseHandler) {
|
||||
@@ -211,7 +213,7 @@ System.register(['lodash', 'app/core/utils/datemath', './utils', './migrations',
|
||||
// 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);
|
||||
|
||||
@@ -273,7 +275,7 @@ System.register(['lodash', 'app/core/utils/datemath', './utils', './migrations',
|
||||
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);
|
||||
|
||||
@@ -282,15 +284,15 @@ System.register(['lodash', 'app/core/utils/datemath', './utils', './migrations',
|
||||
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 [];
|
||||
@@ -515,10 +517,10 @@ System.register(['lodash', 'app/core/utils/datemath', './utils', './migrations',
|
||||
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);
|
||||
|
||||
|
||||
2
dist/datasource-zabbix/datasource.js.map
vendored
2
dist/datasource-zabbix/datasource.js.map
vendored
File diff suppressed because one or more lines are too long
18
dist/datasource-zabbix/query.controller.js
vendored
18
dist/datasource-zabbix/query.controller.js
vendored
@@ -1,9 +1,9 @@
|
||||
'use strict';
|
||||
|
||||
System.register(['app/plugins/sdk', 'angular', 'lodash', './utils', './metricFunctions', './migrations', './add-metric-function.directive', './metric-function-editor.directive', './css/query-editor.css!'], function (_export, _context) {
|
||||
System.register(['app/plugins/sdk', 'angular', 'lodash', './constants', './utils', './metricFunctions', './migrations', './add-metric-function.directive', './metric-function-editor.directive', './css/query-editor.css!'], function (_export, _context) {
|
||||
"use strict";
|
||||
|
||||
var QueryCtrl, angular, _, utils, metricFunctions, migrations, _createClass, ZabbixQueryController;
|
||||
var QueryCtrl, angular, _, c, utils, metricFunctions, migrations, _createClass, ZabbixQueryController;
|
||||
|
||||
function _classCallCheck(instance, Constructor) {
|
||||
if (!(instance instanceof Constructor)) {
|
||||
@@ -42,6 +42,8 @@ System.register(['app/plugins/sdk', 'angular', 'lodash', './utils', './metricFun
|
||||
angular = _angular.default;
|
||||
}, function (_lodash) {
|
||||
_ = _lodash.default;
|
||||
}, function (_constants) {
|
||||
c = _constants;
|
||||
}, function (_utils) {
|
||||
utils = _utils;
|
||||
}, function (_metricFunctions) {
|
||||
@@ -84,9 +86,9 @@ System.register(['app/plugins/sdk', 'angular', 'lodash', './utils', './metricFun
|
||||
_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
|
||||
@@ -120,7 +122,7 @@ System.register(['app/plugins/sdk', 'angular', 'lodash', './utils', './metricFun
|
||||
|
||||
// Load default values
|
||||
var targetDefaults = {
|
||||
mode: 0,
|
||||
mode: c.MODE_METRICS,
|
||||
group: { filter: "" },
|
||||
host: { filter: "" },
|
||||
application: { filter: "" },
|
||||
@@ -137,12 +139,12 @@ System.register(['app/plugins/sdk', 'angular', 'lodash', './utils', './metricFun
|
||||
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();
|
||||
|
||||
File diff suppressed because one or more lines are too long
21
dist/test/datasource-zabbix/constants.js
vendored
Normal file
21
dist/test/datasource-zabbix/constants.js
vendored
Normal 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;
|
||||
18
dist/test/datasource-zabbix/datasource.js
vendored
18
dist/test/datasource-zabbix/datasource.js
vendored
@@ -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);
|
||||
|
||||
|
||||
16
dist/test/datasource-zabbix/query.controller.js
vendored
16
dist/test/datasource-zabbix/query.controller.js
vendored
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user