IT-services: able to use regex for selecting of multiple services, issue #415

This commit is contained in:
Alexander Zobnin
2017-07-24 19:02:09 +03:00
parent 1d4cad85c0
commit 70f34db385
18 changed files with 298 additions and 119 deletions

View File

@@ -321,14 +321,7 @@ System.register(['lodash', 'app/core/utils/datemath', './utils', './migrations',
// IT services mode // IT services mode
else if (target.mode === c.MODE_ITSERVICE) { else if (target.mode === c.MODE_ITSERVICE) {
// Don't show undefined and hidden targets return _this.queryITServiceData(target, timeRange, options);
if (target.hide || !target.itservice || !target.slaProperty) {
return [];
}
return _this.zabbix.getSLA(target.itservice.serviceid, timeRange).then(function (slaObject) {
return responseHandler.handleSLAResponse(target.itservice, target.slaProperty, slaObject);
});
} }
}); });
@@ -485,15 +478,54 @@ System.register(['lodash', 'app/core/utils/datemath', './utils', './migrations',
} }
}); });
} }
}, {
key: 'queryITServiceData',
value: function queryITServiceData(target, timeRange, options) {
var _this4 = this;
// Don't show undefined and hidden targets
if (target.hide || !target.itservice && !target.itServiceFilter || !target.slaProperty) {
return [];
}
var itServiceIds = [];
var itServices = [];
var itServiceFilter = void 0;
var isOldVersion = target.itservice && !target.itServiceFilter;
if (isOldVersion) {
// Backward compatibility
itServiceFilter = '/.*/';
} else {
itServiceFilter = this.replaceTemplateVars(target.itServiceFilter, options.scopedVars);
}
return this.zabbix.getITServices(itServiceFilter).then(function (itservices) {
itServices = itservices;
if (isOldVersion) {
itServices = _.filter(itServices, { 'serviceid': target.itservice.serviceid });
}
itServiceIds = _.map(itServices, 'serviceid');
return itServiceIds;
}).then(function (serviceids) {
return _this4.zabbix.getSLA(serviceids, timeRange);
}).then(function (slaResponse) {
return _.map(itServiceIds, function (serviceid) {
var itservice = _.find(itServices, { 'serviceid': serviceid });
return responseHandler.handleSLAResponse(itservice, target.slaProperty, slaResponse);
});
});
}
}, { }, {
key: 'testDatasource', key: 'testDatasource',
value: function testDatasource() { value: function testDatasource() {
var _this4 = this; var _this5 = this;
var zabbixVersion = void 0; var zabbixVersion = void 0;
return this.zabbix.getVersion().then(function (version) { return this.zabbix.getVersion().then(function (version) {
zabbixVersion = version; zabbixVersion = version;
return _this4.zabbix.login(); return _this5.zabbix.login();
}).then(function () { }).then(function () {
return { return {
status: "success", status: "success",
@@ -519,14 +551,14 @@ System.register(['lodash', 'app/core/utils/datemath', './utils', './migrations',
}, { }, {
key: 'metricFindQuery', key: 'metricFindQuery',
value: function metricFindQuery(query) { value: function metricFindQuery(query) {
var _this5 = this; var _this6 = this;
var result = void 0; var result = void 0;
var parts = []; var parts = [];
// Split query. Query structure: group.host.app.item // Split query. Query structure: group.host.app.item
_.each(utils.splitTemplateQuery(query), function (part) { _.each(utils.splitTemplateQuery(query), function (part) {
part = _this5.replaceTemplateVars(part, {}); part = _this6.replaceTemplateVars(part, {});
// Replace wildcard to regex // Replace wildcard to regex
if (part === '*') { if (part === '*') {
@@ -563,7 +595,7 @@ System.register(['lodash', 'app/core/utils/datemath', './utils', './migrations',
}, { }, {
key: 'annotationQuery', key: 'annotationQuery',
value: function annotationQuery(options) { value: function annotationQuery(options) {
var _this6 = this; var _this7 = this;
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);
@@ -581,7 +613,7 @@ System.register(['lodash', 'app/core/utils/datemath', './utils', './migrations',
return getTriggers.then(function (triggers) { return getTriggers.then(function (triggers) {
// Filter triggers by description // Filter triggers by description
var triggerName = _this6.replaceTemplateVars(annotation.trigger, {}); var triggerName = _this7.replaceTemplateVars(annotation.trigger, {});
if (utils.isRegex(triggerName)) { if (utils.isRegex(triggerName)) {
triggers = _.filter(triggers, function (trigger) { triggers = _.filter(triggers, function (trigger) {
return utils.buildRegex(triggerName).test(trigger.description); return utils.buildRegex(triggerName).test(trigger.description);
@@ -598,7 +630,7 @@ System.register(['lodash', 'app/core/utils/datemath', './utils', './migrations',
}); });
var objectids = _.map(triggers, 'triggerid'); var objectids = _.map(triggers, 'triggerid');
return _this6.zabbix.getEvents(objectids, timeFrom, timeTo, showOkEvents).then(function (events) { return _this7.zabbix.getEvents(objectids, timeFrom, timeTo, showOkEvents).then(function (events) {
var indexedTriggers = _.keyBy(triggers, 'triggerid'); var indexedTriggers = _.keyBy(triggers, 'triggerid');
// Hide acknowledged events if option enabled // Hide acknowledged events if option enabled
@@ -632,23 +664,23 @@ System.register(['lodash', 'app/core/utils/datemath', './utils', './migrations',
}, { }, {
key: 'alertQuery', key: 'alertQuery',
value: function alertQuery(options) { value: function alertQuery(options) {
var _this7 = this; var _this8 = this;
var enabled_targets = filterEnabledTargets(options.targets); var enabled_targets = filterEnabledTargets(options.targets);
var getPanelItems = _.map(enabled_targets, function (t) { var getPanelItems = _.map(enabled_targets, function (t) {
var target = _.cloneDeep(t); var target = _.cloneDeep(t);
_this7.replaceTargetVariables(target, options); _this8.replaceTargetVariables(target, options);
return _this7.zabbix.getItemsFromTarget(target, { itemtype: 'num' }); return _this8.zabbix.getItemsFromTarget(target, { itemtype: 'num' });
}); });
return Promise.all(getPanelItems).then(function (results) { return Promise.all(getPanelItems).then(function (results) {
var items = _.flatten(results); var items = _.flatten(results);
var itemids = _.map(items, 'itemid'); var itemids = _.map(items, 'itemid');
return _this7.zabbix.getAlerts(itemids); return _this8.zabbix.getAlerts(itemids);
}).then(function (triggers) { }).then(function (triggers) {
triggers = _.filter(triggers, function (trigger) { triggers = _.filter(triggers, function (trigger) {
return trigger.priority >= _this7.alertingMinSeverity; return trigger.priority >= _this8.alertingMinSeverity;
}); });
if (!triggers || triggers.length === 0) { if (!triggers || triggers.length === 0) {
@@ -676,12 +708,12 @@ System.register(['lodash', 'app/core/utils/datemath', './utils', './migrations',
}, { }, {
key: 'replaceTargetVariables', key: 'replaceTargetVariables',
value: function replaceTargetVariables(target, options) { value: function replaceTargetVariables(target, options) {
var _this8 = this; var _this9 = this;
var parts = ['group', 'host', 'application', 'item']; var parts = ['group', 'host', 'application', 'item'];
_.forEach(parts, function (p) { _.forEach(parts, function (p) {
if (target[p] && target[p].filter) { if (target[p] && target[p].filter) {
target[p].filter = _this8.replaceTemplateVars(target[p].filter, options.scopedVars); target[p].filter = _this9.replaceTemplateVars(target[p].filter, options.scopedVars);
} }
}); });
target.textFilter = this.replaceTemplateVars(target.textFilter, options.scopedVars); target.textFilter = this.replaceTemplateVars(target.textFilter, options.scopedVars);
@@ -689,9 +721,9 @@ System.register(['lodash', 'app/core/utils/datemath', './utils', './migrations',
_.forEach(target.functions, function (func) { _.forEach(target.functions, function (func) {
func.params = _.map(func.params, function (param) { func.params = _.map(func.params, function (param) {
if (typeof param === 'number') { if (typeof param === 'number') {
return +_this8.templateSrv.replace(param.toString(), options.scopedVars); return +_this9.templateSrv.replace(param.toString(), options.scopedVars);
} else { } else {
return _this8.templateSrv.replace(param, options.scopedVars); return _this9.templateSrv.replace(param, options.scopedVars);
} }
}); });
}); });

File diff suppressed because one or more lines are too long

View File

@@ -20,24 +20,26 @@
<div class="gf-form-inline" ng-show="ctrl.target.mode == 1"> <div class="gf-form-inline" ng-show="ctrl.target.mode == 1">
<div class="gf-form max-width-20"> <div class="gf-form max-width-20">
<label class="gf-form-label query-keyword width-7">IT Service</label> <label class="gf-form-label query-keyword width-7">IT Service</label>
<div class="gf-form-select-wrapper max-width-20"> <input type="text"
<select class="gf-form-input" ng-model="ctrl.target.itServiceFilter"
ng-change="ctrl.selectITService()" bs-typeahead="ctrl.getITServices"
ng-model="ctrl.target.itservice" ng-blur="ctrl.onTargetBlur()"
bs-tooltip="ctrl.target.itservice.name.length > 25 ? ctrl.target.itservice.name : ''" data-min-length=0
ng-options="itservice.name for itservice in ctrl.itserviceList track by itservice.name"> data-items=100
<option value="">-- Select IT service --</option> class="gf-form-input"
</select> ng-class="{
</div> 'zbx-variable': ctrl.isVariable(ctrl.target.itServiceFilter),
'zbx-regex': ctrl.isRegex(ctrl.target.itServiceFilter)
}">
</input>
</div> </div>
<div class="gf-form"> <div class="gf-form">
<label class="gf-form-label query-keyword">IT service property</label> <label class="gf-form-label query-keyword">Property</label>
<div class="gf-form-select-wrapper"> <div class="gf-form-select-wrapper">
<select class="gf-form-input" <select class="gf-form-input"
ng-change="ctrl.selectITService()" ng-change="ctrl.selectITService()"
ng-model="ctrl.target.slaProperty" ng-model="ctrl.target.slaProperty"
ng-options="slaProperty.name for slaProperty in ctrl.slaPropertyList track by slaProperty.name"> ng-options="slaProperty.name for slaProperty in ctrl.slaPropertyList track by slaProperty.name">
<option value="">-- Property --</option>
</select> </select>
</div> </div>
</div> </div>

View File

@@ -91,11 +91,14 @@ System.register(['app/plugins/sdk', 'angular', 'lodash', './constants', './utils
2: { value: 'text', text: 'Text', mode: c.MODE_TEXT } 2: { value: 'text', text: 'Text', mode: c.MODE_TEXT }
}; };
_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" }];
// Map functions for bs-typeahead // Map functions for bs-typeahead
_this.getGroupNames = _.bind(_this.getMetricNames, _this, 'groupList'); _this.getGroupNames = _.bind(_this.getMetricNames, _this, 'groupList');
_this.getHostNames = _.bind(_this.getMetricNames, _this, 'hostList', true); _this.getHostNames = _.bind(_this.getMetricNames, _this, 'hostList', true);
_this.getApplicationNames = _.bind(_this.getMetricNames, _this, 'appList'); _this.getApplicationNames = _.bind(_this.getMetricNames, _this, 'appList');
_this.getItemNames = _.bind(_this.getMetricNames, _this, 'itemList'); _this.getItemNames = _.bind(_this.getMetricNames, _this, 'itemList');
_this.getITServices = _.bind(_this.getMetricNames, _this, 'itServiceList');
// Update metric suggestion when template variable was changed // Update metric suggestion when template variable was changed
$rootScope.$on('template-variable-value-updated', function () { $rootScope.$on('template-variable-value-updated', function () {
@@ -145,9 +148,8 @@ System.register(['app/plugins/sdk', 'angular', 'lodash', './constants', './utils
this.initFilters(); this.initFilters();
} else if (target.mode === c.MODE_ITSERVICE) { } 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" }]; _.defaults(target, { slaProperty: { name: "SLA", property: "sla" } });
this.itserviceList = [{ name: "test" }]; this.suggestITServices();
this.updateITServiceList();
} }
}; };
@@ -230,6 +232,16 @@ System.register(['app/plugins/sdk', 'angular', 'lodash', './constants', './utils
return items; return items;
}); });
} }
}, {
key: 'suggestITServices',
value: function suggestITServices() {
var _this6 = this;
return this.zabbix.getITService().then(function (itservices) {
_this6.metric.itServiceList = itservices;
return itservices;
});
}
}, { }, {
key: 'isRegex', key: 'isRegex',
value: function isRegex(str) { value: function isRegex(str) {
@@ -259,11 +271,11 @@ System.register(['app/plugins/sdk', 'angular', 'lodash', './constants', './utils
}, { }, {
key: 'isContainsVariables', key: 'isContainsVariables',
value: function isContainsVariables() { value: function isContainsVariables() {
var _this6 = this; var _this7 = this;
return _.some(['group', 'host', 'application'], function (field) { return _.some(['group', 'host', 'application'], function (field) {
if (_this6.target[field] && _this6.target[field].filter) { if (_this7.target[field] && _this7.target[field].filter) {
return utils.isTemplateVariable(_this6.target[field].filter, _this6.templateSrv.variables); return utils.isTemplateVariable(_this7.target[field].filter, _this7.templateSrv.variables);
} else { } else {
return false; return false;
} }
@@ -360,11 +372,11 @@ System.register(['app/plugins/sdk', 'angular', 'lodash', './constants', './utils
}, { }, {
key: 'updateITServiceList', key: 'updateITServiceList',
value: function updateITServiceList() { value: function updateITServiceList() {
var _this7 = this; var _this8 = this;
this.zabbix.getITService().then(function (iteservices) { this.zabbix.getITService().then(function (iteservices) {
_this7.itserviceList = []; _this8.itserviceList = [];
_this7.itserviceList = _this7.itserviceList.concat(iteservices); _this8.itserviceList = _this8.itserviceList.concat(iteservices);
}); });
} }
}, { }, {

File diff suppressed because one or more lines are too long

View File

@@ -186,6 +186,13 @@ System.register(['angular', 'lodash', './utils', './zabbixAPI.service.js', './za
return filterByQuery(items, itemFilter); return filterByQuery(items, itemFilter);
}); });
} }
}, {
key: 'getITServices',
value: function getITServices(itServiceFilter) {
return this.cachingProxy.getITServices().then(function (itServices) {
return findByFilter(itServices, itServiceFilter);
});
}
}, { }, {
key: 'getTriggers', key: 'getTriggers',
value: function getTriggers(groupFilter, hostFilter, appFilter, options) { value: function getTriggers(groupFilter, hostFilter, appFilter, options) {

File diff suppressed because one or more lines are too long

View File

@@ -46,7 +46,8 @@ System.register(['angular', 'lodash'], function (_export, _context) {
history: {}, history: {},
trends: {}, trends: {},
macros: {}, macros: {},
globalMacros: {} globalMacros: {},
itServices: {}
}; };
this.historyPromises = {}; this.historyPromises = {};
@@ -72,6 +73,9 @@ System.register(['angular', 'lodash'], function (_export, _context) {
this.itemPromises = {}; this.itemPromises = {};
this.getItemsOnce = callAPIRequestOnce(_.bind(this.zabbixAPI.getItems, this.zabbixAPI), this.itemPromises, getRequestHash); this.getItemsOnce = callAPIRequestOnce(_.bind(this.zabbixAPI.getItems, this.zabbixAPI), this.itemPromises, getRequestHash);
this.itServicesPromises = {};
this.getITServicesOnce = callAPIRequestOnce(_.bind(this.zabbixAPI.getITService, this.zabbixAPI), this.itServicesPromises, getRequestHash);
this.macroPromises = {}; this.macroPromises = {};
this.getMacrosOnce = callAPIRequestOnce(_.bind(this.zabbixAPI.getMacros, this.zabbixAPI), this.macroPromises, getRequestHash); this.getMacrosOnce = callAPIRequestOnce(_.bind(this.zabbixAPI.getMacros, this.zabbixAPI), this.macroPromises, getRequestHash);
@@ -126,6 +130,11 @@ System.register(['angular', 'lodash'], function (_export, _context) {
var params = [hostids, appids, itemtype]; var params = [hostids, appids, itemtype];
return this.proxyRequest(this.getItemsOnce, params, this.cache.items); return this.proxyRequest(this.getItemsOnce, params, this.cache.items);
} }
}, {
key: 'getITServices',
value: function getITServices() {
return this.proxyRequest(this.getITServicesOnce, [], this.cache.itServices);
}
}, { }, {
key: 'getMacros', key: 'getMacros',
value: function getMacros(hostids) { value: function getMacros(hostids) {

File diff suppressed because one or more lines are too long

View File

@@ -181,14 +181,7 @@ var ZabbixAPIDatasource = function () {
// IT services mode // IT services mode
else if (target.mode === c.MODE_ITSERVICE) { else if (target.mode === c.MODE_ITSERVICE) {
// Don't show undefined and hidden targets return _this.queryITServiceData(target, timeRange, options);
if (target.hide || !target.itservice || !target.slaProperty) {
return [];
}
return _this.zabbix.getSLA(target.itservice.serviceid, timeRange).then(function (slaObject) {
return _responseHandler2.default.handleSLAResponse(target.itservice, target.slaProperty, slaObject);
});
} }
}); });
@@ -345,6 +338,45 @@ var ZabbixAPIDatasource = function () {
} }
}); });
} }
}, {
key: 'queryITServiceData',
value: function queryITServiceData(target, timeRange, options) {
var _this4 = this;
// Don't show undefined and hidden targets
if (target.hide || !target.itservice && !target.itServiceFilter || !target.slaProperty) {
return [];
}
var itServiceIds = [];
var itServices = [];
var itServiceFilter = void 0;
var isOldVersion = target.itservice && !target.itServiceFilter;
if (isOldVersion) {
// Backward compatibility
itServiceFilter = '/.*/';
} else {
itServiceFilter = this.replaceTemplateVars(target.itServiceFilter, options.scopedVars);
}
return this.zabbix.getITServices(itServiceFilter).then(function (itservices) {
itServices = itservices;
if (isOldVersion) {
itServices = _lodash2.default.filter(itServices, { 'serviceid': target.itservice.serviceid });
}
itServiceIds = _lodash2.default.map(itServices, 'serviceid');
return itServiceIds;
}).then(function (serviceids) {
return _this4.zabbix.getSLA(serviceids, timeRange);
}).then(function (slaResponse) {
return _lodash2.default.map(itServiceIds, function (serviceid) {
var itservice = _lodash2.default.find(itServices, { 'serviceid': serviceid });
return _responseHandler2.default.handleSLAResponse(itservice, target.slaProperty, slaResponse);
});
});
}
/** /**
* Test connection to Zabbix API * Test connection to Zabbix API
@@ -354,12 +386,12 @@ var ZabbixAPIDatasource = function () {
}, { }, {
key: 'testDatasource', key: 'testDatasource',
value: function testDatasource() { value: function testDatasource() {
var _this4 = this; var _this5 = this;
var zabbixVersion = void 0; var zabbixVersion = void 0;
return this.zabbix.getVersion().then(function (version) { return this.zabbix.getVersion().then(function (version) {
zabbixVersion = version; zabbixVersion = version;
return _this4.zabbix.login(); return _this5.zabbix.login();
}).then(function () { }).then(function () {
return { return {
status: "success", status: "success",
@@ -398,14 +430,14 @@ var ZabbixAPIDatasource = function () {
}, { }, {
key: 'metricFindQuery', key: 'metricFindQuery',
value: function metricFindQuery(query) { value: function metricFindQuery(query) {
var _this5 = this; var _this6 = this;
var result = void 0; var result = void 0;
var parts = []; var parts = [];
// Split query. Query structure: group.host.app.item // Split query. Query structure: group.host.app.item
_lodash2.default.each(utils.splitTemplateQuery(query), function (part) { _lodash2.default.each(utils.splitTemplateQuery(query), function (part) {
part = _this5.replaceTemplateVars(part, {}); part = _this6.replaceTemplateVars(part, {});
// Replace wildcard to regex // Replace wildcard to regex
if (part === '*') { if (part === '*') {
@@ -447,7 +479,7 @@ var ZabbixAPIDatasource = function () {
}, { }, {
key: 'annotationQuery', key: 'annotationQuery',
value: function annotationQuery(options) { value: function annotationQuery(options) {
var _this6 = this; var _this7 = this;
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);
@@ -465,7 +497,7 @@ var ZabbixAPIDatasource = function () {
return getTriggers.then(function (triggers) { return getTriggers.then(function (triggers) {
// Filter triggers by description // Filter triggers by description
var triggerName = _this6.replaceTemplateVars(annotation.trigger, {}); var triggerName = _this7.replaceTemplateVars(annotation.trigger, {});
if (utils.isRegex(triggerName)) { if (utils.isRegex(triggerName)) {
triggers = _lodash2.default.filter(triggers, function (trigger) { triggers = _lodash2.default.filter(triggers, function (trigger) {
return utils.buildRegex(triggerName).test(trigger.description); return utils.buildRegex(triggerName).test(trigger.description);
@@ -482,7 +514,7 @@ var ZabbixAPIDatasource = function () {
}); });
var objectids = _lodash2.default.map(triggers, 'triggerid'); var objectids = _lodash2.default.map(triggers, 'triggerid');
return _this6.zabbix.getEvents(objectids, timeFrom, timeTo, showOkEvents).then(function (events) { return _this7.zabbix.getEvents(objectids, timeFrom, timeTo, showOkEvents).then(function (events) {
var indexedTriggers = _lodash2.default.keyBy(triggers, 'triggerid'); var indexedTriggers = _lodash2.default.keyBy(triggers, 'triggerid');
// Hide acknowledged events if option enabled // Hide acknowledged events if option enabled
@@ -523,23 +555,23 @@ var ZabbixAPIDatasource = function () {
}, { }, {
key: 'alertQuery', key: 'alertQuery',
value: function alertQuery(options) { value: function alertQuery(options) {
var _this7 = this; var _this8 = this;
var enabled_targets = filterEnabledTargets(options.targets); var enabled_targets = filterEnabledTargets(options.targets);
var getPanelItems = _lodash2.default.map(enabled_targets, function (t) { var getPanelItems = _lodash2.default.map(enabled_targets, function (t) {
var target = _lodash2.default.cloneDeep(t); var target = _lodash2.default.cloneDeep(t);
_this7.replaceTargetVariables(target, options); _this8.replaceTargetVariables(target, options);
return _this7.zabbix.getItemsFromTarget(target, { itemtype: 'num' }); return _this8.zabbix.getItemsFromTarget(target, { itemtype: 'num' });
}); });
return Promise.all(getPanelItems).then(function (results) { return Promise.all(getPanelItems).then(function (results) {
var items = _lodash2.default.flatten(results); var items = _lodash2.default.flatten(results);
var itemids = _lodash2.default.map(items, 'itemid'); var itemids = _lodash2.default.map(items, 'itemid');
return _this7.zabbix.getAlerts(itemids); return _this8.zabbix.getAlerts(itemids);
}).then(function (triggers) { }).then(function (triggers) {
triggers = _lodash2.default.filter(triggers, function (trigger) { triggers = _lodash2.default.filter(triggers, function (trigger) {
return trigger.priority >= _this7.alertingMinSeverity; return trigger.priority >= _this8.alertingMinSeverity;
}); });
if (!triggers || triggers.length === 0) { if (!triggers || triggers.length === 0) {
@@ -570,12 +602,12 @@ var ZabbixAPIDatasource = function () {
}, { }, {
key: 'replaceTargetVariables', key: 'replaceTargetVariables',
value: function replaceTargetVariables(target, options) { value: function replaceTargetVariables(target, options) {
var _this8 = this; var _this9 = this;
var parts = ['group', 'host', 'application', 'item']; var parts = ['group', 'host', 'application', 'item'];
_lodash2.default.forEach(parts, function (p) { _lodash2.default.forEach(parts, function (p) {
if (target[p] && target[p].filter) { if (target[p] && target[p].filter) {
target[p].filter = _this8.replaceTemplateVars(target[p].filter, options.scopedVars); target[p].filter = _this9.replaceTemplateVars(target[p].filter, options.scopedVars);
} }
}); });
target.textFilter = this.replaceTemplateVars(target.textFilter, options.scopedVars); target.textFilter = this.replaceTemplateVars(target.textFilter, options.scopedVars);
@@ -583,9 +615,9 @@ var ZabbixAPIDatasource = function () {
_lodash2.default.forEach(target.functions, function (func) { _lodash2.default.forEach(target.functions, function (func) {
func.params = _lodash2.default.map(func.params, function (param) { func.params = _lodash2.default.map(func.params, function (param) {
if (typeof param === 'number') { if (typeof param === 'number') {
return +_this8.templateSrv.replace(param.toString(), options.scopedVars); return +_this9.templateSrv.replace(param.toString(), options.scopedVars);
} else { } else {
return _this8.templateSrv.replace(param, options.scopedVars); return _this9.templateSrv.replace(param, options.scopedVars);
} }
}); });
}); });

View File

@@ -70,11 +70,14 @@ var ZabbixQueryController = exports.ZabbixQueryController = function (_QueryCtrl
2: { value: 'text', text: 'Text', mode: c.MODE_TEXT } 2: { value: 'text', text: 'Text', mode: c.MODE_TEXT }
}; };
_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" }];
// Map functions for bs-typeahead // Map functions for bs-typeahead
_this.getGroupNames = _lodash2.default.bind(_this.getMetricNames, _this, 'groupList'); _this.getGroupNames = _lodash2.default.bind(_this.getMetricNames, _this, 'groupList');
_this.getHostNames = _lodash2.default.bind(_this.getMetricNames, _this, 'hostList', true); _this.getHostNames = _lodash2.default.bind(_this.getMetricNames, _this, 'hostList', true);
_this.getApplicationNames = _lodash2.default.bind(_this.getMetricNames, _this, 'appList'); _this.getApplicationNames = _lodash2.default.bind(_this.getMetricNames, _this, 'appList');
_this.getItemNames = _lodash2.default.bind(_this.getMetricNames, _this, 'itemList'); _this.getItemNames = _lodash2.default.bind(_this.getMetricNames, _this, 'itemList');
_this.getITServices = _lodash2.default.bind(_this.getMetricNames, _this, 'itServiceList');
// Update metric suggestion when template variable was changed // Update metric suggestion when template variable was changed
$rootScope.$on('template-variable-value-updated', function () { $rootScope.$on('template-variable-value-updated', function () {
@@ -124,9 +127,8 @@ var ZabbixQueryController = exports.ZabbixQueryController = function (_QueryCtrl
this.initFilters(); this.initFilters();
} else if (target.mode === c.MODE_ITSERVICE) { } 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" }]; _lodash2.default.defaults(target, { slaProperty: { name: "SLA", property: "sla" } });
this.itserviceList = [{ name: "test" }]; this.suggestITServices();
this.updateITServiceList();
} }
}; };
@@ -212,6 +214,16 @@ var ZabbixQueryController = exports.ZabbixQueryController = function (_QueryCtrl
return items; return items;
}); });
} }
}, {
key: 'suggestITServices',
value: function suggestITServices() {
var _this6 = this;
return this.zabbix.getITService().then(function (itservices) {
_this6.metric.itServiceList = itservices;
return itservices;
});
}
}, { }, {
key: 'isRegex', key: 'isRegex',
value: function isRegex(str) { value: function isRegex(str) {
@@ -246,11 +258,11 @@ var ZabbixQueryController = exports.ZabbixQueryController = function (_QueryCtrl
}, { }, {
key: 'isContainsVariables', key: 'isContainsVariables',
value: function isContainsVariables() { value: function isContainsVariables() {
var _this6 = this; var _this7 = this;
return _lodash2.default.some(['group', 'host', 'application'], function (field) { return _lodash2.default.some(['group', 'host', 'application'], function (field) {
if (_this6.target[field] && _this6.target[field].filter) { if (_this7.target[field] && _this7.target[field].filter) {
return utils.isTemplateVariable(_this6.target[field].filter, _this6.templateSrv.variables); return utils.isTemplateVariable(_this7.target[field].filter, _this7.templateSrv.variables);
} else { } else {
return false; return false;
} }
@@ -365,11 +377,11 @@ var ZabbixQueryController = exports.ZabbixQueryController = function (_QueryCtrl
}, { }, {
key: 'updateITServiceList', key: 'updateITServiceList',
value: function updateITServiceList() { value: function updateITServiceList() {
var _this7 = this; var _this8 = this;
this.zabbix.getITService().then(function (iteservices) { this.zabbix.getITService().then(function (iteservices) {
_this7.itserviceList = []; _this8.itserviceList = [];
_this7.itserviceList = _this7.itserviceList.concat(iteservices); _this8.itserviceList = _this8.itserviceList.concat(iteservices);
}); });
} }

View File

@@ -201,6 +201,13 @@ function ZabbixFactory(zabbixAPIService, ZabbixCachingProxy, ZabbixDBConnector)
return filterByQuery(items, itemFilter); return filterByQuery(items, itemFilter);
}); });
} }
}, {
key: 'getITServices',
value: function getITServices(itServiceFilter) {
return this.cachingProxy.getITServices().then(function (itServices) {
return findByFilter(itServices, itServiceFilter);
});
}
/** /**
* Build query - convert target filters to array of Zabbix items * Build query - convert target filters to array of Zabbix items

View File

@@ -39,7 +39,8 @@ function ZabbixCachingProxyFactory() {
history: {}, history: {},
trends: {}, trends: {},
macros: {}, macros: {},
globalMacros: {} globalMacros: {},
itServices: {}
}; };
this.historyPromises = {}; this.historyPromises = {};
@@ -65,6 +66,9 @@ function ZabbixCachingProxyFactory() {
this.itemPromises = {}; this.itemPromises = {};
this.getItemsOnce = callAPIRequestOnce(_lodash2.default.bind(this.zabbixAPI.getItems, this.zabbixAPI), this.itemPromises, getRequestHash); this.getItemsOnce = callAPIRequestOnce(_lodash2.default.bind(this.zabbixAPI.getItems, this.zabbixAPI), this.itemPromises, getRequestHash);
this.itServicesPromises = {};
this.getITServicesOnce = callAPIRequestOnce(_lodash2.default.bind(this.zabbixAPI.getITService, this.zabbixAPI), this.itServicesPromises, getRequestHash);
this.macroPromises = {}; this.macroPromises = {};
this.getMacrosOnce = callAPIRequestOnce(_lodash2.default.bind(this.zabbixAPI.getMacros, this.zabbixAPI), this.macroPromises, getRequestHash); this.getMacrosOnce = callAPIRequestOnce(_lodash2.default.bind(this.zabbixAPI.getMacros, this.zabbixAPI), this.macroPromises, getRequestHash);
@@ -125,6 +129,11 @@ function ZabbixCachingProxyFactory() {
var params = [hostids, appids, itemtype]; var params = [hostids, appids, itemtype];
return this.proxyRequest(this.getItemsOnce, params, this.cache.items); return this.proxyRequest(this.getItemsOnce, params, this.cache.items);
} }
}, {
key: 'getITServices',
value: function getITServices() {
return this.proxyRequest(this.getITServicesOnce, [], this.cache.itServices);
}
}, { }, {
key: 'getMacros', key: 'getMacros',
value: function getMacros(hostids) { value: function getMacros(hostids) {

View File

@@ -126,15 +126,7 @@ class ZabbixAPIDatasource {
// IT services mode // IT services mode
else if (target.mode === c.MODE_ITSERVICE) { else if (target.mode === c.MODE_ITSERVICE) {
// Don't show undefined and hidden targets return this.queryITServiceData(target, timeRange, options);
if (target.hide || !target.itservice || !target.slaProperty) {
return [];
}
return this.zabbix.getSLA(target.itservice.serviceid, timeRange)
.then(slaObject => {
return responseHandler.handleSLAResponse(target.itservice, target.slaProperty, slaObject);
});
} }
}); });
@@ -276,6 +268,45 @@ class ZabbixAPIDatasource {
}); });
} }
queryITServiceData(target, timeRange, options) {
// Don't show undefined and hidden targets
if (target.hide || (!target.itservice && !target.itServiceFilter) || !target.slaProperty) {
return [];
}
let itServiceIds = [];
let itServices = [];
let itServiceFilter;
let isOldVersion = target.itservice && !target.itServiceFilter;
if (isOldVersion) {
// Backward compatibility
itServiceFilter = '/.*/';
} else {
itServiceFilter = this.replaceTemplateVars(target.itServiceFilter, options.scopedVars);
}
return this.zabbix.getITServices(itServiceFilter)
.then(itservices => {
itServices = itservices;
if (isOldVersion) {
itServices = _.filter(itServices, {'serviceid': target.itservice.serviceid});
}
itServiceIds = _.map(itServices, 'serviceid');
return itServiceIds;
})
.then(serviceids => {
return this.zabbix.getSLA(serviceids, timeRange);
})
.then(slaResponse => {
return _.map(itServiceIds, serviceid => {
let itservice = _.find(itServices, {'serviceid': serviceid});
return responseHandler.handleSLAResponse(itservice, target.slaProperty, slaResponse);
});
});
}
/** /**
* Test connection to Zabbix API * Test connection to Zabbix API
* @return {object} Connection status and Zabbix API version * @return {object} Connection status and Zabbix API version

View File

@@ -20,24 +20,26 @@
<div class="gf-form-inline" ng-show="ctrl.target.mode == 1"> <div class="gf-form-inline" ng-show="ctrl.target.mode == 1">
<div class="gf-form max-width-20"> <div class="gf-form max-width-20">
<label class="gf-form-label query-keyword width-7">IT Service</label> <label class="gf-form-label query-keyword width-7">IT Service</label>
<div class="gf-form-select-wrapper max-width-20"> <input type="text"
<select class="gf-form-input" ng-model="ctrl.target.itServiceFilter"
ng-change="ctrl.selectITService()" bs-typeahead="ctrl.getITServices"
ng-model="ctrl.target.itservice" ng-blur="ctrl.onTargetBlur()"
bs-tooltip="ctrl.target.itservice.name.length > 25 ? ctrl.target.itservice.name : ''" data-min-length=0
ng-options="itservice.name for itservice in ctrl.itserviceList track by itservice.name"> data-items=100
<option value="">-- Select IT service --</option> class="gf-form-input"
</select> ng-class="{
</div> 'zbx-variable': ctrl.isVariable(ctrl.target.itServiceFilter),
'zbx-regex': ctrl.isRegex(ctrl.target.itServiceFilter)
}">
</input>
</div> </div>
<div class="gf-form"> <div class="gf-form">
<label class="gf-form-label query-keyword">IT service property</label> <label class="gf-form-label query-keyword">Property</label>
<div class="gf-form-select-wrapper"> <div class="gf-form-select-wrapper">
<select class="gf-form-input" <select class="gf-form-input"
ng-change="ctrl.selectITService()" ng-change="ctrl.selectITService()"
ng-model="ctrl.target.slaProperty" ng-model="ctrl.target.slaProperty"
ng-options="slaProperty.name for slaProperty in ctrl.slaPropertyList track by slaProperty.name"> ng-options="slaProperty.name for slaProperty in ctrl.slaPropertyList track by slaProperty.name">
<option value="">-- Property --</option>
</select> </select>
</div> </div>
</div> </div>

View File

@@ -28,11 +28,20 @@ export class ZabbixQueryController extends QueryCtrl {
2: {value: 'text', text: 'Text', mode: c.MODE_TEXT} 2: {value: 'text', text: 'Text', mode: c.MODE_TEXT}
}; };
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"}
];
// Map functions for bs-typeahead // Map functions for bs-typeahead
this.getGroupNames = _.bind(this.getMetricNames, this, 'groupList'); this.getGroupNames = _.bind(this.getMetricNames, this, 'groupList');
this.getHostNames = _.bind(this.getMetricNames, this, 'hostList', true); this.getHostNames = _.bind(this.getMetricNames, this, 'hostList', true);
this.getApplicationNames = _.bind(this.getMetricNames, this, 'appList'); this.getApplicationNames = _.bind(this.getMetricNames, this, 'appList');
this.getItemNames = _.bind(this.getMetricNames, this, 'itemList'); this.getItemNames = _.bind(this.getMetricNames, this, 'itemList');
this.getITServices = _.bind(this.getMetricNames, this, 'itServiceList');
// Update metric suggestion when template variable was changed // Update metric suggestion when template variable was changed
$rootScope.$on('template-variable-value-updated', () => this.onVariableChange()); $rootScope.$on('template-variable-value-updated', () => this.onVariableChange());
@@ -88,15 +97,8 @@ export class ZabbixQueryController extends QueryCtrl {
this.initFilters(); this.initFilters();
} }
else if (target.mode === c.MODE_ITSERVICE) { else if (target.mode === c.MODE_ITSERVICE) {
this.slaPropertyList = [ _.defaults(target, {slaProperty: {name: "SLA", property: "sla"}});
{name: "Status", property: "status"}, this.suggestITServices();
{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();
} }
}; };
@@ -173,6 +175,14 @@ export class ZabbixQueryController extends QueryCtrl {
}); });
} }
suggestITServices() {
return this.zabbix.getITService()
.then(itservices => {
this.metric.itServiceList = itservices;
return itservices;
});
}
isRegex(str) { isRegex(str) {
return utils.isRegex(str); return utils.isRegex(str);
} }

View File

@@ -148,6 +148,11 @@ function ZabbixFactory(zabbixAPIService, ZabbixCachingProxy, ZabbixDBConnector)
.then(items => filterByQuery(items, itemFilter)); .then(items => filterByQuery(items, itemFilter));
} }
getITServices(itServiceFilter) {
return this.cachingProxy.getITServices()
.then(itServices => findByFilter(itServices, itServiceFilter));
}
/** /**
* Build query - convert target filters to array of Zabbix items * Build query - convert target filters to array of Zabbix items
*/ */

View File

@@ -23,7 +23,8 @@ function ZabbixCachingProxyFactory() {
history: {}, history: {},
trends: {}, trends: {},
macros: {}, macros: {},
globalMacros: {} globalMacros: {},
itServices: {}
}; };
this.historyPromises = {}; this.historyPromises = {};
@@ -56,6 +57,10 @@ function ZabbixCachingProxyFactory() {
this.getItemsOnce = callAPIRequestOnce(_.bind(this.zabbixAPI.getItems, this.zabbixAPI), this.getItemsOnce = callAPIRequestOnce(_.bind(this.zabbixAPI.getItems, this.zabbixAPI),
this.itemPromises, getRequestHash); this.itemPromises, getRequestHash);
this.itServicesPromises = {};
this.getITServicesOnce = callAPIRequestOnce(_.bind(this.zabbixAPI.getITService, this.zabbixAPI),
this.itServicesPromises, getRequestHash);
this.macroPromises = {}; this.macroPromises = {};
this.getMacrosOnce = callAPIRequestOnce(_.bind(this.zabbixAPI.getMacros, this.zabbixAPI), this.getMacrosOnce = callAPIRequestOnce(_.bind(this.zabbixAPI.getMacros, this.zabbixAPI),
this.macroPromises, getRequestHash); this.macroPromises, getRequestHash);
@@ -111,6 +116,10 @@ function ZabbixCachingProxyFactory() {
return this.proxyRequest(this.getItemsOnce, params, this.cache.items); return this.proxyRequest(this.getItemsOnce, params, this.cache.items);
} }
getITServices() {
return this.proxyRequest(this.getITServicesOnce, [], this.cache.itServices);
}
getMacros(hostids) { getMacros(hostids) {
// Merge global macros and host macros // Merge global macros and host macros
let promises = [ let promises = [