Merge branch 'digiaiiris-fix-issue-190-trigger-url-with-macro'
Co-authored-by: Timo Myllymaki <timo.myllymaki@digia.com>
This commit is contained in:
@@ -78,13 +78,26 @@ export function containsMacro(itemName) {
|
|||||||
return MACRO_PATTERN.test(itemName);
|
return MACRO_PATTERN.test(itemName);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function replaceMacro(item, macros) {
|
export function replaceMacro(item, macros, isTriggerItem) {
|
||||||
let itemName = item.name;
|
let itemName = isTriggerItem ? item.url : item.name;
|
||||||
const item_macros = itemName.match(MACRO_PATTERN);
|
const item_macros = itemName.match(MACRO_PATTERN);
|
||||||
_.forEach(item_macros, macro => {
|
_.forEach(item_macros, macro => {
|
||||||
const host_macros = _.filter(macros, m => {
|
const host_macros = _.filter(macros, m => {
|
||||||
if (m.hostid) {
|
if (m.hostid) {
|
||||||
return m.hostid === item.hostid;
|
if (isTriggerItem) {
|
||||||
|
// Trigger item can have multiple hosts
|
||||||
|
// Check all trigger host ids against macro host id
|
||||||
|
let hostIdFound = false;
|
||||||
|
_.forEach(item.hosts, h => {
|
||||||
|
if (h.hostid === m.hostid) {
|
||||||
|
hostIdFound = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return hostIdFound;
|
||||||
|
} else {
|
||||||
|
// Check app host id against macro host id
|
||||||
|
return m.hostid === item.hostid;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// Add global macros
|
// Add global macros
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -234,13 +234,17 @@ export class Zabbix {
|
|||||||
.then(this.expandUserMacro.bind(this));
|
.then(this.expandUserMacro.bind(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
expandUserMacro(items) {
|
expandUserMacro(items, isTriggerItem) {
|
||||||
let hostids = getHostIds(items);
|
let hostids = getHostIds(items);
|
||||||
return this.getMacros(hostids)
|
return this.getMacros(hostids)
|
||||||
.then(macros => {
|
.then(macros => {
|
||||||
_.forEach(items, item => {
|
_.forEach(items, item => {
|
||||||
if (utils.containsMacro(item.name)) {
|
if (utils.containsMacro(isTriggerItem ? item.url : item.name)) {
|
||||||
item.name = utils.replaceMacro(item, macros);
|
if (isTriggerItem) {
|
||||||
|
item.url = utils.replaceMacro(item, macros, isTriggerItem);
|
||||||
|
} else {
|
||||||
|
item.name = utils.replaceMacro(item, macros);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return items;
|
return items;
|
||||||
@@ -285,7 +289,8 @@ export class Zabbix {
|
|||||||
return query;
|
return query;
|
||||||
})
|
})
|
||||||
.then(query => this.zabbixAPI.getTriggers(query.groupids, query.hostids, query.applicationids, options))
|
.then(query => this.zabbixAPI.getTriggers(query.groupids, query.hostids, query.applicationids, options))
|
||||||
.then(triggers => this.filterTriggersByProxy(triggers, proxyFilter));
|
.then(triggers => this.filterTriggersByProxy(triggers, proxyFilter))
|
||||||
|
.then(triggers => this.expandUserMacro.bind(this)(triggers, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
filterTriggersByProxy(triggers, proxyFilter) {
|
filterTriggersByProxy(triggers, proxyFilter) {
|
||||||
|
|||||||
Reference in New Issue
Block a user