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

@@ -126,15 +126,7 @@ class ZabbixAPIDatasource {
// IT services mode
else if (target.mode === c.MODE_ITSERVICE) {
// Don't show undefined and hidden targets
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);
});
return this.queryITServiceData(target, timeRange, options);
}
});
@@ -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
* @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 max-width-20">
<label class="gf-form-label query-keyword width-7">IT Service</label>
<div class="gf-form-select-wrapper max-width-20">
<select class="gf-form-input"
ng-change="ctrl.selectITService()"
ng-model="ctrl.target.itservice"
bs-tooltip="ctrl.target.itservice.name.length > 25 ? ctrl.target.itservice.name : ''"
ng-options="itservice.name for itservice in ctrl.itserviceList track by itservice.name">
<option value="">-- Select IT service --</option>
</select>
</div>
<input type="text"
ng-model="ctrl.target.itServiceFilter"
bs-typeahead="ctrl.getITServices"
ng-blur="ctrl.onTargetBlur()"
data-min-length=0
data-items=100
class="gf-form-input"
ng-class="{
'zbx-variable': ctrl.isVariable(ctrl.target.itServiceFilter),
'zbx-regex': ctrl.isRegex(ctrl.target.itServiceFilter)
}">
</input>
</div>
<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">
<select class="gf-form-input"
ng-change="ctrl.selectITService()"
ng-model="ctrl.target.slaProperty"
ng-options="slaProperty.name for slaProperty in ctrl.slaPropertyList track by slaProperty.name">
<option value="">-- Property --</option>
ng-change="ctrl.selectITService()"
ng-model="ctrl.target.slaProperty"
ng-options="slaProperty.name for slaProperty in ctrl.slaPropertyList track by slaProperty.name">
</select>
</div>
</div>

View File

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

View File

@@ -148,6 +148,11 @@ function ZabbixFactory(zabbixAPIService, ZabbixCachingProxy, ZabbixDBConnector)
.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
*/

View File

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