Cache and queryProcessor refactor.
This commit is contained in:
@@ -49,7 +49,6 @@ function (angular, _, utils) {
|
||||
|
||||
this.filterHosts = function(groupFilter) {
|
||||
var groups = [];
|
||||
var hosts = [];
|
||||
|
||||
return self.cache.getGroups().then(function(groupList) {
|
||||
// Filter groups by regex
|
||||
@@ -69,15 +68,15 @@ function (angular, _, utils) {
|
||||
}
|
||||
}
|
||||
|
||||
if (groups) {
|
||||
var groupids = _.map(groups, 'groupid');
|
||||
return self.cache.getHosts().then(function(hosts) {
|
||||
return _.filter(hosts, function (hostObj) {
|
||||
return _.intersection(groupids, hostObj.groups).length;
|
||||
var hostids = _.flatten(_.map(groups, 'hosts'));
|
||||
if (hostids.length) {
|
||||
return self.cache.getHostsExtend().then(function(hosts) {
|
||||
return _.map(hostids, function(hostid) {
|
||||
return hosts[hostid];
|
||||
});
|
||||
});
|
||||
} else {
|
||||
return hosts;
|
||||
return [];
|
||||
}
|
||||
});
|
||||
};
|
||||
@@ -129,14 +128,12 @@ function (angular, _, utils) {
|
||||
|
||||
var promises = [
|
||||
this.filterHosts(groupFilter),
|
||||
this.filterApplications(groupFilter, hostFilter),
|
||||
this.cache.getItems(itemType),
|
||||
this.filterApplications(groupFilter, hostFilter)
|
||||
];
|
||||
|
||||
return $q.all(promises).then(function(results) {
|
||||
var hostList = results[0];
|
||||
var applicationList = results[1];
|
||||
var cachedItems = results[2];
|
||||
|
||||
// Filter hosts by regex
|
||||
if (utils.isRegex(hostFilter)) {
|
||||
@@ -144,8 +141,7 @@ function (angular, _, utils) {
|
||||
hosts = _.filter(hostList, function (hostObj) {
|
||||
return hostFilterPattern.test(hostObj.name);
|
||||
});
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
var findedHosts = _.find(hostList, {'name': hostFilter});
|
||||
if (findedHosts) {
|
||||
hosts.push(findedHosts);
|
||||
@@ -172,20 +168,18 @@ function (angular, _, utils) {
|
||||
} else {
|
||||
apps = undefined;
|
||||
if (hosts) {
|
||||
items = _.filter(cachedItems, function (itemObj) {
|
||||
return _.find(hosts, {'hostid': itemObj.hostid });
|
||||
});
|
||||
items = _.flatten(_.map(hosts, 'items'), true);
|
||||
}
|
||||
}
|
||||
|
||||
if (apps) {
|
||||
var appids = _.flatten(_.map(apps, 'applicationids'));
|
||||
/*var appids = _.flatten(_.map(apps, 'applicationids'));
|
||||
items = _.filter(cachedItems, function (itemObj) {
|
||||
return _.intersection(appids, itemObj.applications).length;
|
||||
});
|
||||
items = _.filter(items, function (itemObj) {
|
||||
return _.find(hosts, {'hostid': itemObj.hostid });
|
||||
});
|
||||
});*/
|
||||
}
|
||||
|
||||
if (!showDisabledItems) {
|
||||
|
||||
@@ -123,7 +123,8 @@ function (angular, _) {
|
||||
p.getGroups = function() {
|
||||
var params = {
|
||||
output: ['name'],
|
||||
sortfield: 'name'
|
||||
sortfield: 'name',
|
||||
selectHosts: []
|
||||
};
|
||||
|
||||
return this.request('hostgroup.get', params);
|
||||
@@ -168,6 +169,27 @@ function (angular, _) {
|
||||
return this.request('item.get', params);
|
||||
};
|
||||
|
||||
/**
|
||||
* Get Hosts list with host's items.
|
||||
* @return {[type]} [description]
|
||||
*/
|
||||
p.getHostsExtend = function() {
|
||||
var params = {
|
||||
output: ['name', 'host'],
|
||||
sortfield: 'name',
|
||||
selectGroups: [],
|
||||
selectItems: [
|
||||
'name', 'key_',
|
||||
'value_type',
|
||||
'hostid',
|
||||
'status',
|
||||
'state'
|
||||
]
|
||||
};
|
||||
|
||||
return this.request('host.get', params);
|
||||
};
|
||||
|
||||
p.getLastValue = function(itemid) {
|
||||
var params = {
|
||||
output: ['lastvalue'],
|
||||
|
||||
@@ -21,6 +21,7 @@ function (angular, _, utils) {
|
||||
this._hosts = undefined;
|
||||
this._applications = undefined;
|
||||
this._items = undefined;
|
||||
this._hostsExtend = undefined;
|
||||
this.storage = {
|
||||
history: {},
|
||||
trends: {}
|
||||
@@ -51,15 +52,17 @@ function (angular, _, utils) {
|
||||
this.zabbixAPI.getGroups(),
|
||||
this.zabbixAPI.getHosts(),
|
||||
this.zabbixAPI.getApplications(),
|
||||
this.zabbixAPI.getItems()
|
||||
this.zabbixAPI.getItems(),
|
||||
this.zabbixAPI.getHostsExtend()
|
||||
];
|
||||
|
||||
return $q.all(promises).then(function(results) {
|
||||
if (results.length) {
|
||||
self._groups = results[0];
|
||||
self._groups = convertGroups(results[0]);
|
||||
self._hosts = convertHosts(results[1]);
|
||||
self._applications = convertApplications(results[2]);
|
||||
self._items = convertItems(results[3]);
|
||||
self._hostsExtend = convertHostsExtend(results[4]);
|
||||
}
|
||||
self._initialized = true;
|
||||
});
|
||||
@@ -87,6 +90,17 @@ function (angular, _, utils) {
|
||||
}
|
||||
};
|
||||
|
||||
p.getHostsExtend = function() {
|
||||
var self = this;
|
||||
if (this._hostsExtend) {
|
||||
return $q.when(self._hostsExtend);
|
||||
} else {
|
||||
return this.refresh().then(function() {
|
||||
return self._hostsExtend;
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
p.getApplications = function() {
|
||||
var self = this;
|
||||
if (this._applications) {
|
||||
@@ -181,6 +195,25 @@ function (angular, _, utils) {
|
||||
});
|
||||
}
|
||||
|
||||
function convertGroups(groups) {
|
||||
return _.forEach(groups, function(group) {
|
||||
group.hosts = _.map(group.hosts, 'hostid');
|
||||
return group;
|
||||
});
|
||||
}
|
||||
|
||||
function convertHostsExtend(hosts) {
|
||||
return _.indexBy(_.map(hosts, function(host) {
|
||||
host.items = _.forEach(host.items, function(item) {
|
||||
item.applications = _.map(item.applications, 'applicationid');
|
||||
item.item = item.name;
|
||||
item.name = utils.expandItemName(item.item, item.key_);
|
||||
return item;
|
||||
});
|
||||
return host;
|
||||
}), 'hostid');
|
||||
}
|
||||
|
||||
/**
|
||||
* Group Zabbix applications by name
|
||||
* host.hosts - array of host ids
|
||||
|
||||
Reference in New Issue
Block a user