Templated items selection by item name.
This commit is contained in:
@@ -47,23 +47,23 @@ function (angular, _, kbn) {
|
|||||||
} else {
|
} else {
|
||||||
// Handle templated target
|
// Handle templated target
|
||||||
|
|
||||||
var item_key = templateSrv.replace(target.item.name);
|
var itemname = templateSrv.replace(target.item.name);
|
||||||
var hostname = templateSrv.replace(target.host.name);
|
var hostname = templateSrv.replace(target.host.name);
|
||||||
|
|
||||||
// Extract zabbix hosts
|
// Extract zabbix hosts
|
||||||
var host_pattern = /([\w\.\s]+)/g;
|
var host_pattern = /([\w\.\s]+)/g;
|
||||||
var hosts = hostname.match(host_pattern);
|
var hosts = hostname.match(host_pattern);
|
||||||
|
|
||||||
// Extract zabbix keys
|
// Extract item names
|
||||||
var key_pattern = /([\w\.]+(?:\[[^\[]*\])|[\w\.]+)/g;
|
var itemname_pattern = /([^{},]+)/g;
|
||||||
var keys = item_key.match(key_pattern);
|
var itemnames = itemname.match(itemname_pattern);
|
||||||
|
|
||||||
if (keys.length < this.limitmetrics) {
|
if (itemnames.length < this.limitmetrics) {
|
||||||
// Find items by keys and perform queries
|
// Find items by item names and perform queries
|
||||||
var self = this;
|
var self = this;
|
||||||
return $q.all(_.map(hosts, function (hostname) {
|
return $q.all(_.map(hosts, function (hostname) {
|
||||||
return $q.all(_.map(keys, function (key) {
|
return $q.all(_.map(itemnames, function (name) {
|
||||||
return this.findZabbixItem(hostname, key);
|
return this.findZabbixItem(hostname, name);
|
||||||
}, this));
|
}, this));
|
||||||
}, this)).then(function (items) {
|
}, this)).then(function (items) {
|
||||||
items = _.flatten(items);
|
items = _.flatten(items);
|
||||||
@@ -315,17 +315,16 @@ function (angular, _, kbn) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
ZabbixAPIDatasource.prototype.findZabbixItem = function (host, key) {
|
ZabbixAPIDatasource.prototype.findZabbixItem = function (host, itemname) {
|
||||||
var params = {
|
var params = {
|
||||||
output: ['name', 'key_', 'value_type'],
|
output: ['name', 'key_', 'value_type'],
|
||||||
host: host,
|
host: host
|
||||||
search: {
|
|
||||||
key_: key
|
|
||||||
},
|
|
||||||
searchWildcardsEnabled: true,
|
|
||||||
searchByAny: true
|
|
||||||
}
|
}
|
||||||
return this.performZabbixAPIRequest('item.get', params);
|
return this.performZabbixAPIRequest('item.get', params).then(function (items) {
|
||||||
|
return _.filter(items, function (item) {
|
||||||
|
return expandItemName(item) == itemname;
|
||||||
|
});
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -443,7 +442,8 @@ function (angular, _, kbn) {
|
|||||||
.then(function (result) {
|
.then(function (result) {
|
||||||
return _.map(result, function (item) {
|
return _.map(result, function (item) {
|
||||||
return {
|
return {
|
||||||
text: item.key_,
|
//text: item.key_,
|
||||||
|
text: expandItemName(item),
|
||||||
expandable: false
|
expandable: false
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user