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:
@@ -494,7 +494,13 @@ func (ds *Zabbix) GetAllGroups(ctx context.Context) ([]Group, error) {
|
||||
params := ZabbixAPIParams{
|
||||
"output": []string{"name", "groupid"},
|
||||
"sortfield": "name",
|
||||
"real_hosts": true,
|
||||
}
|
||||
|
||||
// Zabbix v7.0 and later removed `real_hosts` parameter and replaced it with `with_hosts`
|
||||
if ds.version < 70 {
|
||||
params["real_hosts"] = true
|
||||
} else {
|
||||
params["with_hosts"] = true
|
||||
}
|
||||
|
||||
result, err := ds.Request(ctx, &ZabbixAPIRequest{Method: "hostgroup.get", Params: params})
|
||||
|
||||
@@ -89,10 +89,10 @@ func (zabbix *Zabbix) request(ctx context.Context, method string, params ZabbixA
|
||||
|
||||
// Skip auth for methods that are not required it
|
||||
if method == "apiinfo.version" {
|
||||
return zabbix.api.RequestUnauthenticated(ctx, method, params)
|
||||
return zabbix.api.RequestUnauthenticated(ctx, method, params, zabbix.version)
|
||||
}
|
||||
|
||||
result, err := zabbix.api.Request(ctx, method, params)
|
||||
result, err := zabbix.api.Request(ctx, method, params, zabbix.version)
|
||||
notAuthorized := isNotAuthorized(err)
|
||||
isTokenAuth := zabbix.settings.AuthType == settings.AuthTypeToken
|
||||
if err == zabbixapi.ErrNotAuthenticated || (notAuthorized && !isTokenAuth) {
|
||||
@@ -141,7 +141,7 @@ func (zabbix *Zabbix) Authenticate(ctx context.Context) error {
|
||||
zabbixPassword = jsonData.Get("password").MustString()
|
||||
}
|
||||
|
||||
err = zabbix.api.Authenticate(ctx, zabbixLogin, zabbixPassword)
|
||||
err = zabbix.api.Authenticate(ctx, zabbixLogin, zabbixPassword, zabbix.version)
|
||||
if err != nil {
|
||||
zabbix.logger.Error("Zabbix authentication error", "error", err)
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user