Add tags filter to triggers query
This commit is contained in:
@@ -542,6 +542,19 @@ export class ZabbixDatasource extends DataSourceApi<ZabbixMetricsQuery, ZabbixDS
|
|||||||
const hostids = hosts?.map((h) => h.hostid);
|
const hostids = hosts?.map((h) => h.hostid);
|
||||||
const appids = apps?.map((a) => a.applicationid);
|
const appids = apps?.map((a) => a.applicationid);
|
||||||
const options = getTriggersOptions(target, timeRange);
|
const options = getTriggersOptions(target, timeRange);
|
||||||
|
|
||||||
|
const tagsFilter = this.replaceTemplateVars(target.tags?.filter, request.scopedVars);
|
||||||
|
// replaceTemplateVars() builds regex-like string, so we should trim it.
|
||||||
|
const tagsFilterStr = tagsFilter.replace('/^', '').replace('$/', '');
|
||||||
|
const tags = utils.parseTags(tagsFilterStr);
|
||||||
|
tags.forEach((tag) => {
|
||||||
|
// Zabbix uses {"tag": "<tag>", "value": "<value>", "operator": "<operator>"} format, where 1 means Equal
|
||||||
|
tag.operator = 1;
|
||||||
|
});
|
||||||
|
if (tags && tags.length) {
|
||||||
|
options.tags = tags;
|
||||||
|
}
|
||||||
|
|
||||||
const alerts = await this.zabbix.getHostAlerts(hostids, appids, options);
|
const alerts = await this.zabbix.getHostAlerts(hostids, appids, options);
|
||||||
return responseHandler.handleTriggersResponse(alerts, groups, timeRange, target);
|
return responseHandler.handleTriggersResponse(alerts, groups, timeRange, target);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -715,7 +715,7 @@ export class ZabbixAPIConnector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async getHostAlerts(hostids, applicationids, options): Promise<ZBXTrigger[]> {
|
async getHostAlerts(hostids, applicationids, options): Promise<ZBXTrigger[]> {
|
||||||
const { minSeverity, acknowledged, count, timeFrom, timeTo } = options;
|
const { minSeverity, acknowledged, tags, count, timeFrom, timeTo } = options;
|
||||||
const params: any = {
|
const params: any = {
|
||||||
output: 'extend',
|
output: 'extend',
|
||||||
hostids: hostids,
|
hostids: hostids,
|
||||||
@@ -747,6 +747,11 @@ export class ZabbixAPIConnector {
|
|||||||
params.lastChangeTill = timeTo;
|
params.lastChangeTill = timeTo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (tags) {
|
||||||
|
params.tags = tags;
|
||||||
|
params.evaltype = 0;
|
||||||
|
}
|
||||||
|
|
||||||
let triggers = await this.request('trigger.get', params);
|
let triggers = await this.request('trigger.get', params);
|
||||||
if (!count || acknowledged === 1) {
|
if (!count || acknowledged === 1) {
|
||||||
triggers = filterTriggersByAcknowledge(triggers, acknowledged);
|
triggers = filterTriggersByAcknowledge(triggers, acknowledged);
|
||||||
|
|||||||
Reference in New Issue
Block a user