Fix querying and authentication for Zabbix v7.0+ (#1931)
* Fix querying for Zabbix v7.2+ * Update check from 7.2 to 7.0 * Fix also select acknowledges key * Remove unsused methods * release commit 4.6.0 --------- Co-authored-by: yesoreyeram <153843+yesoreyeram@users.noreply.github.com>
This commit is contained in:
@@ -23,5 +23,31 @@ describe('Zabbix API connector', () => {
|
||||
zabbixAPIConnector.getProxies();
|
||||
expect(zabbixAPIConnector.request).toHaveBeenCalledWith('proxy.get', { output: ['proxyid', 'host'] });
|
||||
});
|
||||
|
||||
it('should send the with_hosts parameter when version is 7.0+', () => {
|
||||
const zabbixAPIConnector = new ZabbixAPIConnector(true, true, 123);
|
||||
zabbixAPIConnector.version = '7.0.0';
|
||||
zabbixAPIConnector.request = jest.fn();
|
||||
|
||||
zabbixAPIConnector.getGroups();
|
||||
expect(zabbixAPIConnector.request).toHaveBeenCalledWith('hostgroup.get', {
|
||||
output: ['name', 'groupid'],
|
||||
sortfield: 'name',
|
||||
with_hosts: true,
|
||||
});
|
||||
});
|
||||
|
||||
it('should send the real_hosts parameter when version is <7.0', () => {
|
||||
const zabbixAPIConnector = new ZabbixAPIConnector(true, true, 123);
|
||||
zabbixAPIConnector.version = '6.5.0';
|
||||
zabbixAPIConnector.request = jest.fn();
|
||||
|
||||
zabbixAPIConnector.getGroups();
|
||||
expect(zabbixAPIConnector.request).toHaveBeenCalledWith('hostgroup.get', {
|
||||
output: ['name', 'groupid'],
|
||||
sortfield: 'name',
|
||||
real_hosts: true,
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -142,9 +142,15 @@ export class ZabbixAPIConnector {
|
||||
const params = {
|
||||
output: ['name', 'groupid'],
|
||||
sortfield: 'name',
|
||||
real_hosts: true,
|
||||
};
|
||||
|
||||
// Zabbix v7.0 and later deprecated `real_hosts` parameter and replaced it with `with_hosts`
|
||||
if (semver.gte(this.version, '7.0.0')) {
|
||||
params['with_hosts'] = true;
|
||||
} else {
|
||||
params['real_hosts'] = true;
|
||||
}
|
||||
|
||||
return this.request('hostgroup.get', params);
|
||||
}
|
||||
|
||||
@@ -612,10 +618,10 @@ export class ZabbixAPIConnector {
|
||||
time_from: timeFrom,
|
||||
time_till: timeTo,
|
||||
objectids: objectids,
|
||||
select_acknowledges: 'extend',
|
||||
selectHosts: 'extend',
|
||||
value: showEvents,
|
||||
};
|
||||
params[getSelectAcknowledgesKey(this.version)] = 'extend';
|
||||
|
||||
if (limit) {
|
||||
params.limit = limit;
|
||||
@@ -639,13 +645,13 @@ export class ZabbixAPIConnector {
|
||||
evaltype: '0',
|
||||
sortfield: ['eventid'],
|
||||
sortorder: 'DESC',
|
||||
select_acknowledges: 'extend',
|
||||
selectTags: 'extend',
|
||||
selectSuppressionData: ['maintenanceid', 'suppress_until'],
|
||||
groupids,
|
||||
hostids,
|
||||
applicationids,
|
||||
};
|
||||
params[getSelectAcknowledgesKey(this.version)] = 'extend';
|
||||
|
||||
if (limit) {
|
||||
params.limit = limit;
|
||||
@@ -675,12 +681,13 @@ export class ZabbixAPIConnector {
|
||||
output: 'extend',
|
||||
eventids: eventids,
|
||||
preservekeys: true,
|
||||
select_acknowledges: 'extend',
|
||||
selectTags: 'extend',
|
||||
sortfield: 'clock',
|
||||
sortorder: 'DESC',
|
||||
};
|
||||
|
||||
params[getSelectAcknowledgesKey(this.version)] = 'extend';
|
||||
|
||||
return this.request('event.get', params);
|
||||
}
|
||||
|
||||
@@ -699,10 +706,10 @@ export class ZabbixAPIConnector {
|
||||
output: 'extend',
|
||||
eventids: eventids,
|
||||
preservekeys: true,
|
||||
select_acknowledges: 'extend',
|
||||
sortfield: 'clock',
|
||||
sortorder: 'DESC',
|
||||
};
|
||||
params[getSelectAcknowledgesKey(this.version)] = 'extend';
|
||||
|
||||
return this.request('event.get', params).then((events) => {
|
||||
return _.filter(events, (event) => event.acknowledges.length);
|
||||
@@ -976,3 +983,7 @@ export class ZabbixAPIError {
|
||||
return this.name + ' ' + this.data;
|
||||
}
|
||||
}
|
||||
|
||||
function getSelectAcknowledgesKey(version: string) {
|
||||
return semver.gte(version, '7.0.0') ? 'selectAcknowledges' : 'select_acknowledges';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user