Fix always fetch Zabbix version before issuing new requests (#2133)

Previously we were only fetching the version when the version was `0`.
This generally worked, but posed some problems when customers were
updating their Zabbix version, specifically when upgrading from a
version < `7.2.x` to `7.2.x` or above.

Before `7.2.x`, an `auth` parameter was still supported when issuing a
zabbix request, this was deprecated in `6.4.x` and later removed in
`7.2.x`. When a user was on a version < `7.2.x` all the outgoing
requests would add this `auth` parameter. When upgrading to `7.2.x` this
was a problem, because the version was not `0`, hence, not requiring
getting the version again, but also because we were still building the
request considering an older version and adding the `auth` parameter,
when this was no longer supported.

This PR removes the check for `version == 0`, though this now means that
every request that goes out will check the version before hand, I think
this will give us a more accurate representation of the version that
needs to be used.

fixes
https://github.com/orgs/grafana/projects/457/views/40?pane=issue&itemId=3683181283&issue=grafana%7Coss-big-tent-squad%7C135
This commit is contained in:
Jocelyn Collado-Kuri
2025-12-05 17:34:20 -08:00
committed by GitHub
parent 3da36ec2bb
commit e073382983
4 changed files with 56 additions and 19 deletions

View File

@@ -48,16 +48,13 @@ func (zabbix *Zabbix) GetAPI() *zabbixapi.ZabbixAPI {
func (ds *Zabbix) Request(ctx context.Context, apiReq *ZabbixAPIRequest) (*simplejson.Json, error) {
var resultJson *simplejson.Json
var err error
if ds.version == 0 {
version, err := ds.GetVersion(ctx)
if err != nil {
ds.logger.Error("Error querying Zabbix version", "error", err)
ds.version = -1
} else {
ds.logger.Debug("Got Zabbix version", "version", version)
ds.version = version
}
version, err := ds.GetVersion(ctx)
if err != nil {
ds.logger.Error("Error querying Zabbix version", "error", err)
ds.version = -1
} else {
ds.version = version
}
cachedResult, queryExistInCache := ds.cache.GetAPIRequest(apiReq)
@@ -68,7 +65,7 @@ func (ds *Zabbix) Request(ctx context.Context, apiReq *ZabbixAPIRequest) (*simpl
}
if IsCachedRequest(apiReq.Method) {
ds.logger.Debug("Writing result to cache", "method", apiReq.Method)
ds.logger.Debug("Writing result to cache", "method", apiReq.Method, "version", ds.version)
ds.cache.SetAPIRequest(apiReq, resultJson)
}
} else {
@@ -85,7 +82,7 @@ func (ds *Zabbix) Request(ctx context.Context, apiReq *ZabbixAPIRequest) (*simpl
// request checks authentication and makes a request to the Zabbix API.
func (zabbix *Zabbix) request(ctx context.Context, method string, params ZabbixAPIParams) (*simplejson.Json, error) {
zabbix.logger.Debug("Zabbix request", "method", method)
zabbix.logger.Debug("Zabbix request", "method", method, "version", zabbix.version)
// Skip auth for methods that are not required it
if method == "apiinfo.version" {