Fixed #191 - display host name for multiple metrics.

This commit is contained in:
Alexander Zobnin
2016-04-11 23:12:38 +03:00
parent eb9722aef0
commit 49ea07451f
3 changed files with 15 additions and 10 deletions

View File

@@ -151,13 +151,13 @@ export class ZabbixAPIDatasource {
var valueType = trendValueFunc ? trendValueFunc.params[0] : "avg";
getHistory = self.zabbixAPI.getTrend(items, from, to).then(function(history) {
return self.queryProcessor.handleTrends(history, addHostName, valueType);
return self.queryProcessor.handleTrends(history, items, addHostName, valueType);
});
} else {
// Use history
getHistory = self.zabbixCache.getHistory(items, from, to).then(function(history) {
return self.queryProcessor.handleHistory(history, addHostName);
return self.queryProcessor.handleHistory(history, items, addHostName);
});
}

View File

@@ -217,7 +217,7 @@ angular.module('grafana.services').factory('QueryProcessor', function($q) {
* datapoints: [[<value>, <unixtime>], ...]
* }
*/
convertHistory(history, addHostName, convertPointCallback) {
convertHistory(history, items, addHostName, convertPointCallback) {
/**
* Response should be in the format:
* data: [
@@ -231,12 +231,13 @@ angular.module('grafana.services').factory('QueryProcessor', function($q) {
// Group history by itemid
var grouped_history = _.groupBy(history, 'itemid');
var hosts = _.indexBy(_.flatten(_.map(items, 'hosts')), 'hostid');
return _.map(grouped_history, function(hist, itemid) {
var item = self.cache.getItem(itemid);
var alias = item.name;
if (addHostName) {
var host = self.cache.getHost(item.hostid);
if (_.keys(hosts).length > 1 || addHostName) {
var host = hosts[item.hostid];
alias = host.name + ": " + alias;
}
return {
@@ -246,13 +247,13 @@ angular.module('grafana.services').factory('QueryProcessor', function($q) {
});
}
handleHistory(history, addHostName) {
return this.convertHistory(history, addHostName, convertHistoryPoint);
handleHistory(history, items, addHostName) {
return this.convertHistory(history, items, addHostName, convertHistoryPoint);
}
handleTrends(history, addHostName, valueType) {
handleTrends(history, items, addHostName, valueType) {
var convertPointCallback = _.partial(convertTrendPoint, valueType);
return this.convertHistory(history, addHostName, convertPointCallback);
return this.convertHistory(history, items, addHostName, convertPointCallback);
}
handleSLAResponse(itservice, slaProperty, slaObject) {

View File

@@ -155,7 +155,11 @@ function ZabbixAPIService($q, alertSrv, zabbixAPICoreService) {
'state'
],
sortfield: 'name',
webitems: true
webitems: true,
selectHosts: [
'hostid',
'name'
]
};
if (hostids) {
params.hostids = hostids;