[hostname]: itemname alias for multiple hosts items.

This commit is contained in:
Alexander Zobnin
2015-05-29 23:35:14 +03:00
parent ff3fe7f219
commit 81f10ea6a9

View File

@@ -61,14 +61,21 @@ function (angular, _, kbn) {
var hosts = hostname.match(host_pattern); var hosts = hostname.match(host_pattern);
// Extract item names // Extract item names
var delete_hostname_pattern = /(?:\[[\w\.]+\]\:\s)/g;
var itemname_pattern = /([^{},]+)/g; var itemname_pattern = /([^{},]+)/g;
var itemnames = itemname.match(itemname_pattern); // Remove hostnames from item name
// [hostname]: itemname --> itemname
var itemnames = itemname.replace(delete_hostname_pattern, '').match(itemname_pattern);
//var aliases = itemname.match(itemname_pattern);
if (itemnames && (itemnames.length < this.limitmetrics)) { if (itemnames && (itemnames.length < this.limitmetrics)) {
// Find items by item names 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 this.findZabbixItem(hostname, itemnames); if (hosts.length > 1) {
var selectHosts = true;
}
return this.findZabbixItem(hostname, itemnames, selectHosts);
}, this)).then(function (items) { }, this)).then(function (items) {
items = _.flatten(items); items = _.flatten(items);
return self.performTimeSeriesQuery(items, from, to) return self.performTimeSeriesQuery(items, from, to)
@@ -140,8 +147,9 @@ function (angular, _, kbn) {
var grouped_history = _.groupBy(response, 'itemid'); var grouped_history = _.groupBy(response, 'itemid');
return $q.when(_.map(grouped_history, function (history, itemid) { return $q.when(_.map(grouped_history, function (history, itemid) {
var item = indexed_items[itemid];
var series = { var series = {
target: expandItemName(indexed_items[itemid]), target: (item.hosts ? '['+item.hosts[0].name+']: ' : '') + expandItemName(item),
datapoints: _.map(history, function (p) { datapoints: _.map(history, function (p) {
// Value must be a number for properly work // Value must be a number for properly work
var value = Number(p.value); var value = Number(p.value);
@@ -337,10 +345,13 @@ function (angular, _, kbn) {
}; };
ZabbixAPIDatasource.prototype.findZabbixItem = function (host, itemnames) { ZabbixAPIDatasource.prototype.findZabbixItem = function (host, itemnames, /* optional */ selectHosts) {
var params = { var params = {
output: ['name', 'key_', 'value_type'], output: ['name', 'key_', 'value_type'],
host: host host: host
};
if (selectHosts) {
params.selectHosts = ['name'];
} }
return this.performZabbixAPIRequest('item.get', params).then(function (items) { return this.performZabbixAPIRequest('item.get', params).then(function (items) {
return _.filter(items, function (item) { return _.filter(items, function (item) {
@@ -435,7 +446,7 @@ function (angular, _, kbn) {
return _.map(result, function (item) { return _.map(result, function (item) {
var itemname = expandItemName(item) var itemname = expandItemName(item)
return { return {
text: (item.hosts ? item.hosts[0].name + ': ' : '') + itemname, text: (item.hosts ? '['+item.hosts[0].name+']: ' : '') + itemname,
expandable: false expandable: false
}; };
}); });