Fix: d.for.Each is not a function errors (#2005)

Fixes #2002
This commit is contained in:
Zoltán Bedi
2025-05-05 13:58:42 +02:00
committed by GitHub
parent c0d212d3ae
commit 8136184a54
3 changed files with 102 additions and 3 deletions

View File

@@ -0,0 +1,5 @@
---
'grafana-zabbix': patch
---
Fix: frontend error when running count triggers

View File

@@ -50,4 +50,98 @@ describe('Zabbix API connector', () => {
}); });
}); });
}); });
describe('getHostAlerts function', () => {
it('should return number when count is enabled and acknowledged is 1 and version is 7 or greater', async () => {
const zabbixAPIConnector = new ZabbixAPIConnector(true, true, 123);
zabbixAPIConnector.version = '7.0.0';
zabbixAPIConnector.request = jest.fn(() => Promise.resolve(triggers));
const result = await zabbixAPIConnector.getHostAlerts(undefined, undefined, { count: true, acknowledged: 1 });
expect(result).toBe(0);
}); });
});
describe('getHostICAlerts function', () => {
it('should return number when count is enabled and acknowledged is 1 and version is 7 or greater', async () => {
const zabbixAPIConnector = new ZabbixAPIConnector(true, true, 123);
zabbixAPIConnector.version = '7.0.0';
zabbixAPIConnector.request = jest.fn(() => Promise.resolve(triggers));
const result = await zabbixAPIConnector.getHostICAlerts(undefined, undefined, undefined, {
count: true,
acknowledged: 1,
});
expect(result).toBe(0);
});
});
describe('getHostPCAlerts function', () => {
it('should return number when count is enabled and acknowledged is 1 and version is 7 or greater', async () => {
const zabbixAPIConnector = new ZabbixAPIConnector(true, true, 123);
zabbixAPIConnector.version = '7.0.0';
zabbixAPIConnector.request = jest.fn(() => Promise.resolve(triggers));
const result = await zabbixAPIConnector.getHostPCAlerts(undefined, undefined, undefined, {
count: true,
acknowledged: 1,
});
expect(result).toBe(0);
});
});
});
const triggers = [
{
comments: 'For passive agents only, host availability is used with `3m` as a time threshold.',
correlation_mode: '0',
correlation_tag: '',
description: 'Linux: Zabbix agent is not available',
error: '',
event_name: 'Linux: Zabbix agent is not available (for {$AGENT.TIMEOUT})',
expression: '{30619}=0',
flags: '0',
hostgroups: [
{
flags: '0',
groupid: '4',
name: 'Zabbix servers',
uuid: '6f6799aa69e844b4b3918f779f2abf08',
},
],
hosts: [
{
host: 'Zabbix server',
hostid: '10084',
name: 'Zabbix server',
},
],
lastEvent: {
acknowledged: '0',
clock: '1741858886',
eventid: '23',
name: 'Linux: Zabbix agent is not available (for 3m)',
ns: '223852878',
object: '0',
objectid: '22391',
severity: '3',
source: '0',
value: '1',
},
lastchange: '1741858886',
manual_close: '1',
opdata: '',
priority: '3',
recovery_expression: '',
recovery_mode: '0',
state: '0',
status: '0',
templateid: '22377',
triggerid: '22391',
type: '0',
url: '',
url_name: '',
uuid: '',
value: '1',
},
];

View File

@@ -793,7 +793,7 @@ export class ZabbixAPIConnector {
triggers = triggers.length; triggers = triggers.length;
} }
// When version is 7.0.0 or higher, groups are returned as hostgroups // When version is 7.0.0 or higher, groups are returned as hostgroups
if (semver.gte(this.version, '7.0.0')) { if (semver.gte(this.version, '7.0.0') && !count) {
triggers.forEach((trigger) => { triggers.forEach((trigger) => {
trigger.groups = trigger.hostgroups; trigger.groups = trigger.hostgroups;
}); });
@@ -848,7 +848,7 @@ export class ZabbixAPIConnector {
triggers = triggers.length; triggers = triggers.length;
} }
// When version is 7.0.0 or higher, groups are returned as hostgroups // When version is 7.0.0 or higher, groups are returned as hostgroups
if (semver.gte(this.version, '7.0.0')) { if (semver.gte(this.version, '7.0.0') && !count) {
triggers.forEach((trigger) => { triggers.forEach((trigger) => {
trigger.groups = trigger.hostgroups; trigger.groups = trigger.hostgroups;
}); });
@@ -897,7 +897,7 @@ export class ZabbixAPIConnector {
triggers = triggers.length; triggers = triggers.length;
} }
// When version is 7.0.0 or higher, groups are returned as hostgroups // When version is 7.0.0 or higher, groups are returned as hostgroups
if (semver.gte(this.version, '7.0.0')) { if (semver.gte(this.version, '7.0.0') && !count) {
triggers.forEach((trigger) => { triggers.forEach((trigger) => {
trigger.groups = trigger.hostgroups; trigger.groups = trigger.hostgroups;
}); });