Expand user macros in items, closes #212

This commit is contained in:
Alexander Zobnin
2017-02-11 20:15:57 +03:00
parent 94c24e9be4
commit 48018744bd
12 changed files with 288 additions and 8 deletions

View File

@@ -20,7 +20,9 @@ function ZabbixCachingProxyFactory() {
applications: {},
items: {},
history: {},
trends: {}
trends: {},
macros: {},
globalMacros: {}
};
this.historyPromises = {};
@@ -45,6 +47,14 @@ function ZabbixCachingProxyFactory() {
this.itemPromises = {};
this.getItemsOnce = callAPIRequestOnce(_.bind(this.zabbixAPI.getItems, this.zabbixAPI),
this.itemPromises, getRequestHash);
this.macroPromises = {};
this.getMacrosOnce = callAPIRequestOnce(_.bind(this.zabbixAPI.getMacros, this.zabbixAPI),
this.macroPromises, getRequestHash);
this.globalMacroPromises = {};
this.getGlobalMacrosOnce = callAPIRequestOnce(_.bind(this.zabbixAPI.getGlobalMacros, this.zabbixAPI),
this.globalMacroPromises, getRequestHash);
}
isExpired(cacheObject) {
@@ -93,6 +103,16 @@ function ZabbixCachingProxyFactory() {
return this.proxyRequest(this.getItemsOnce, params, this.cache.items);
}
getMacros(hostids) {
// Merge global macros and host macros
let promises = [
this.proxyRequest(this.getMacrosOnce, [hostids], this.cache.macros),
this.proxyRequest(this.getGlobalMacrosOnce, [], this.cache.globalMacros)
];
return Promise.all(promises).then(_.flatten);
}
getHistoryFromCache(items, time_from, time_till) {
var historyStorage = this.cache.history;
var full_history;