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

60
dist/datasource-zabbix/constants.js vendored Normal file
View 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

View 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"]}

View File

@@ -1,9 +1,9 @@
'use strict'; '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"; "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) { function _classCallCheck(instance, Constructor) {
if (!(instance instanceof Constructor)) { if (!(instance instanceof Constructor)) {
@@ -114,6 +114,8 @@ System.register(['lodash', 'app/core/utils/datemath', './utils', './migrations',
migrations = _migrations; migrations = _migrations;
}, function (_metricFunctions) { }, function (_metricFunctions) {
metricFunctions = _metricFunctions; metricFunctions = _metricFunctions;
}, function (_constants) {
c = _constants;
}, function (_dataProcessor) { }, function (_dataProcessor) {
dataProcessor = _dataProcessor.default; dataProcessor = _dataProcessor.default;
}, function (_responseHandler) { }, function (_responseHandler) {
@@ -211,7 +213,7 @@ System.register(['lodash', 'app/core/utils/datemath', './utils', './migrations',
// Alerting options // Alerting options
this.alertingEnabled = instanceSettings.jsonData.alerting; this.alertingEnabled = instanceSettings.jsonData.alerting;
this.addThresholds = instanceSettings.jsonData.addThresholds; 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); 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]); var useTrends = _this.isUseTrends([timeFrom, timeTo]);
// Metrics or Text query mode // Metrics or Text query mode
if (target.mode !== 1) { if (target.mode !== c.MODE_ITSERVICE) {
// Migrate old targets // Migrate old targets
target = migrations.migrate(target); target = migrations.migrate(target);
@@ -282,15 +284,15 @@ System.register(['lodash', 'app/core/utils/datemath', './utils', './migrations',
return []; return [];
} }
if (!target.mode || target.mode === 0) { if (!target.mode || target.mode === c.MODE_METRICS) {
return _this.queryNumericData(target, timeFrom, timeTo, useTrends); 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); return _this.queryTextData(target, timeFrom, timeTo);
} }
} }
// IT services mode // IT services mode
else if (target.mode === 1) { else if (target.mode === c.MODE_ITSERVICE) {
// Don't show undefined and hidden targets // Don't show undefined and hidden targets
if (target.hide || !target.itservice || !target.slaProperty) { if (target.hide || !target.itservice || !target.slaProperty) {
return []; 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 timeFrom = Math.ceil(dateMath.parse(options.rangeRaw.from) / 1000);
var timeTo = Math.ceil(dateMath.parse(options.rangeRaw.to) / 1000); var timeTo = Math.ceil(dateMath.parse(options.rangeRaw.to) / 1000);
var annotation = options.annotation; 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 // 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); var getTriggers = this.zabbix.getTriggers(this.replaceTemplateVars(annotation.group, {}), this.replaceTemplateVars(annotation.host, {}), this.replaceTemplateVars(annotation.application, {}), showTriggers);

File diff suppressed because one or more lines are too long

View File

@@ -1,9 +1,9 @@
'use strict'; '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"; "use strict";
var QueryCtrl, angular, _, utils, metricFunctions, migrations, _createClass, ZabbixQueryController; var QueryCtrl, angular, _, c, utils, metricFunctions, migrations, _createClass, ZabbixQueryController;
function _classCallCheck(instance, Constructor) { function _classCallCheck(instance, Constructor) {
if (!(instance instanceof Constructor)) { if (!(instance instanceof Constructor)) {
@@ -42,6 +42,8 @@ System.register(['app/plugins/sdk', 'angular', 'lodash', './utils', './metricFun
angular = _angular.default; angular = _angular.default;
}, function (_lodash) { }, function (_lodash) {
_ = _lodash.default; _ = _lodash.default;
}, function (_constants) {
c = _constants;
}, function (_utils) { }, function (_utils) {
utils = _utils; utils = _utils;
}, function (_metricFunctions) { }, function (_metricFunctions) {
@@ -84,9 +86,9 @@ System.register(['app/plugins/sdk', 'angular', 'lodash', './utils', './metricFun
_this.templateSrv = templateSrv; _this.templateSrv = templateSrv;
_this.editorModes = { _this.editorModes = {
0: { value: 'num', text: 'Metrics', mode: 0 }, 0: { value: 'num', text: 'Metrics', mode: c.MODE_METRICS },
1: { value: 'itservice', text: 'IT Services', mode: 1 }, 1: { value: 'itservice', text: 'IT Services', mode: c.MODE_ITSERVICE },
2: { value: 'text', text: 'Text', mode: 2 } 2: { value: 'text', text: 'Text', mode: c.MODE_TEXT }
}; };
// Map functions for bs-typeahead // Map functions for bs-typeahead
@@ -120,7 +122,7 @@ System.register(['app/plugins/sdk', 'angular', 'lodash', './utils', './metricFun
// Load default values // Load default values
var targetDefaults = { var targetDefaults = {
mode: 0, mode: c.MODE_METRICS,
group: { filter: "" }, group: { filter: "" },
host: { filter: "" }, host: { filter: "" },
application: { filter: "" }, application: { filter: "" },
@@ -137,12 +139,12 @@ System.register(['app/plugins/sdk', 'angular', 'lodash', './utils', './metricFun
return metricFunctions.createFuncInstance(func.def, func.params); 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.downsampleFunctionList = [{ name: "avg", value: "avg" }, { name: "min", value: "min" }, { name: "max", value: "max" }, { name: "sum", value: "sum" }, { name: "count", value: "count" }];
this.initFilters(); 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.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.itserviceList = [{ name: "test" }];
this.updateITServiceList(); this.updateITServiceList();

File diff suppressed because one or more lines are too long

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 metricFunctions = _interopRequireWildcard(_metricFunctions);
var _constants = require('./constants');
var c = _interopRequireWildcard(_constants);
var _dataProcessor = require('./dataProcessor'); var _dataProcessor = require('./dataProcessor');
var _dataProcessor2 = _interopRequireDefault(_dataProcessor); var _dataProcessor2 = _interopRequireDefault(_dataProcessor);
@@ -82,7 +86,7 @@ var ZabbixAPIDatasource = function () {
// Alerting options // Alerting options
this.alertingEnabled = instanceSettings.jsonData.alerting; this.alertingEnabled = instanceSettings.jsonData.alerting;
this.addThresholds = instanceSettings.jsonData.addThresholds; 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); 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]); var useTrends = _this.isUseTrends([timeFrom, timeTo]);
// Metrics or Text query mode // Metrics or Text query mode
if (target.mode !== 1) { if (target.mode !== c.MODE_ITSERVICE) {
// Migrate old targets // Migrate old targets
target = migrations.migrate(target); target = migrations.migrate(target);
@@ -153,15 +157,15 @@ var ZabbixAPIDatasource = function () {
return []; return [];
} }
if (!target.mode || target.mode === 0) { if (!target.mode || target.mode === c.MODE_METRICS) {
return _this.queryNumericData(target, timeFrom, timeTo, useTrends); 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); return _this.queryTextData(target, timeFrom, timeTo);
} }
} }
// IT services mode // IT services mode
else if (target.mode === 1) { else if (target.mode === c.MODE_ITSERVICE) {
// Don't show undefined and hidden targets // Don't show undefined and hidden targets
if (target.hide || !target.itservice || !target.slaProperty) { if (target.hide || !target.itservice || !target.slaProperty) {
return []; return [];
@@ -410,10 +414,10 @@ var ZabbixAPIDatasource = function () {
var timeFrom = Math.ceil(dateMath.parse(options.rangeRaw.from) / 1000); var timeFrom = Math.ceil(dateMath.parse(options.rangeRaw.from) / 1000);
var timeTo = Math.ceil(dateMath.parse(options.rangeRaw.to) / 1000); var timeTo = Math.ceil(dateMath.parse(options.rangeRaw.to) / 1000);
var annotation = options.annotation; 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 // 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); 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 _lodash2 = _interopRequireDefault(_lodash);
var _constants = require('./constants');
var c = _interopRequireWildcard(_constants);
var _utils = require('./utils'); var _utils = require('./utils');
var utils = _interopRequireWildcard(_utils); var utils = _interopRequireWildcard(_utils);
@@ -61,9 +65,9 @@ var ZabbixQueryController = exports.ZabbixQueryController = function (_QueryCtrl
_this.templateSrv = templateSrv; _this.templateSrv = templateSrv;
_this.editorModes = { _this.editorModes = {
0: { value: 'num', text: 'Metrics', mode: 0 }, 0: { value: 'num', text: 'Metrics', mode: c.MODE_METRICS },
1: { value: 'itservice', text: 'IT Services', mode: 1 }, 1: { value: 'itservice', text: 'IT Services', mode: c.MODE_ITSERVICE },
2: { value: 'text', text: 'Text', mode: 2 } 2: { value: 'text', text: 'Text', mode: c.MODE_TEXT }
}; };
// Map functions for bs-typeahead // Map functions for bs-typeahead
@@ -97,7 +101,7 @@ var ZabbixQueryController = exports.ZabbixQueryController = function (_QueryCtrl
// Load default values // Load default values
var targetDefaults = { var targetDefaults = {
mode: 0, mode: c.MODE_METRICS,
group: { filter: "" }, group: { filter: "" },
host: { filter: "" }, host: { filter: "" },
application: { filter: "" }, application: { filter: "" },
@@ -114,12 +118,12 @@ var ZabbixQueryController = exports.ZabbixQueryController = function (_QueryCtrl
return metricFunctions.createFuncInstance(func.def, func.params); 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.downsampleFunctionList = [{ name: "avg", value: "avg" }, { name: "min", value: "min" }, { name: "max", value: "max" }, { name: "sum", value: "sum" }, { name: "count", value: "count" }];
this.initFilters(); 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.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.itserviceList = [{ name: "test" }];
this.updateITServiceList(); this.updateITServiceList();

View File

@@ -0,0 +1,16 @@
// Editor modes
export const MODE_METRICS = 0;
export const MODE_TEXT = 2;
export const MODE_ITSERVICE = 1;
// Triggers severity
export const SEV_NOT_CLASSIFIED = 0;
export const SEV_INFORMATION = 1;
export const SEV_WARNING = 2;
export const SEV_AVERAGE = 3;
export const SEV_HIGH = 4;
export const SEV_DISASTER = 5;
export const SHOW_ALL_TRIGGERS = [0, 1];
export const SHOW_ALL_EVENTS = [0, 1];
export const SHOW_OK_EVENTS = 1;

View File

@@ -3,6 +3,7 @@ import * as dateMath from 'app/core/utils/datemath';
import * as utils from './utils'; import * as utils from './utils';
import * as migrations from './migrations'; import * as migrations from './migrations';
import * as metricFunctions from './metricFunctions'; import * as metricFunctions from './metricFunctions';
import * as c from './constants';
import dataProcessor from './dataProcessor'; import dataProcessor from './dataProcessor';
import responseHandler from './responseHandler'; import responseHandler from './responseHandler';
import './zabbix.js'; import './zabbix.js';
@@ -40,7 +41,7 @@ class ZabbixAPIDatasource {
// Alerting options // Alerting options
this.alertingEnabled = instanceSettings.jsonData.alerting; this.alertingEnabled = instanceSettings.jsonData.alerting;
this.addThresholds = instanceSettings.jsonData.addThresholds; 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); this.zabbix = new Zabbix(this.url, this.username, this.password, this.basicAuth, this.withCredentials, this.cacheTTL);
@@ -92,7 +93,7 @@ class ZabbixAPIDatasource {
let useTrends = this.isUseTrends([timeFrom, timeTo]); let useTrends = this.isUseTrends([timeFrom, timeTo]);
// Metrics or Text query mode // Metrics or Text query mode
if (target.mode !== 1) { if (target.mode !== c.MODE_ITSERVICE) {
// Migrate old targets // Migrate old targets
target = migrations.migrate(target); target = migrations.migrate(target);
@@ -101,15 +102,15 @@ class ZabbixAPIDatasource {
return []; return [];
} }
if (!target.mode || target.mode === 0) { if (!target.mode || target.mode === c.MODE_METRICS) {
return this.queryNumericData(target, timeFrom, timeTo, useTrends); 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); return this.queryTextData(target, timeFrom, timeTo);
} }
} }
// IT services mode // IT services mode
else if (target.mode === 1) { else if (target.mode === c.MODE_ITSERVICE) {
// Don't show undefined and hidden targets // Don't show undefined and hidden targets
if (target.hide || !target.itservice || !target.slaProperty) { if (target.hide || !target.itservice || !target.slaProperty) {
return []; return [];
@@ -342,10 +343,10 @@ class ZabbixAPIDatasource {
var timeFrom = Math.ceil(dateMath.parse(options.rangeRaw.from) / 1000); var timeFrom = Math.ceil(dateMath.parse(options.rangeRaw.from) / 1000);
var timeTo = Math.ceil(dateMath.parse(options.rangeRaw.to) / 1000); var timeTo = Math.ceil(dateMath.parse(options.rangeRaw.to) / 1000);
var annotation = options.annotation; 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 // Show all triggers
var showTriggers = [0, 1]; var showTriggers = c.SHOW_ALL_TRIGGERS;
var getTriggers = this.zabbix var getTriggers = this.zabbix
.getTriggers(this.replaceTemplateVars(annotation.group, {}), .getTriggers(this.replaceTemplateVars(annotation.group, {}),

View File

@@ -1,6 +1,7 @@
import {QueryCtrl} from 'app/plugins/sdk'; import {QueryCtrl} from 'app/plugins/sdk';
import angular from 'angular'; import angular from 'angular';
import _ from 'lodash'; import _ from 'lodash';
import * as c from './constants';
import * as utils from './utils'; import * as utils from './utils';
import * as metricFunctions from './metricFunctions'; import * as metricFunctions from './metricFunctions';
import * as migrations from './migrations'; import * as migrations from './migrations';
@@ -22,9 +23,9 @@ export class ZabbixQueryController extends QueryCtrl {
this.templateSrv = templateSrv; this.templateSrv = templateSrv;
this.editorModes = { this.editorModes = {
0: {value: 'num', text: 'Metrics', mode: 0}, 0: {value: 'num', text: 'Metrics', mode: c.MODE_METRICS},
1: {value: 'itservice', text: 'IT Services', mode: 1}, 1: {value: 'itservice', text: 'IT Services', mode: c.MODE_ITSERVICE},
2: {value: 'text', text: 'Text', mode: 2} 2: {value: 'text', text: 'Text', mode: c.MODE_TEXT}
}; };
// Map functions for bs-typeahead // Map functions for bs-typeahead
@@ -56,7 +57,7 @@ export class ZabbixQueryController extends QueryCtrl {
// Load default values // Load default values
var targetDefaults = { var targetDefaults = {
mode: 0, mode: c.MODE_METRICS,
group: { filter: "" }, group: { filter: "" },
host: { filter: "" }, host: { filter: "" },
application: { filter: "" }, application: { filter: "" },
@@ -73,8 +74,8 @@ export class ZabbixQueryController extends QueryCtrl {
return metricFunctions.createFuncInstance(func.def, func.params); return metricFunctions.createFuncInstance(func.def, func.params);
}); });
if (target.mode === 0 || if (target.mode === c.MODE_METRICS ||
target.mode === 2) { target.mode === c.MODE_TEXT) {
this.downsampleFunctionList = [ this.downsampleFunctionList = [
{name: "avg", value: "avg"}, {name: "avg", value: "avg"},
@@ -86,7 +87,7 @@ export class ZabbixQueryController extends QueryCtrl {
this.initFilters(); this.initFilters();
} }
else if (target.mode === 1) { else if (target.mode === c.MODE_ITSERVICE) {
this.slaPropertyList = [ this.slaPropertyList = [
{name: "Status", property: "status"}, {name: "Status", property: "status"},
{name: "SLA", property: "sla"}, {name: "SLA", property: "sla"},