Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

for v6.4.0 #54

Open
Ephemeraler opened this issue Apr 13, 2023 · 6 comments
Open

for v6.4.0 #54

Ephemeraler opened this issue Apr 13, 2023 · 6 comments

Comments

@Ephemeraler
Copy link

user.log paramter had been changed, from user to username.

@mr-ns
Copy link

mr-ns commented Apr 13, 2023

I think you mean user.login rather than user.log.

Technically this changed occurred in Zabbix 5.4; user was still allowed though, but deprecated. Then in 6.4 the deprecated user was removed.

I have a patch, by the way, that takes care of this in a backward-compatible way. (I am maintaining my own clone of this repo now because it seems to take a while for issues to get fixed.) Happy to pass along the patch if you like.

@ksc98
Copy link

ksc98 commented Apr 19, 2023

A one-liner patch, here's what we're using:

---
 session.go | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/session.go b/session.go
index 6ebe0d5..3b9c32e 100644
--- a/session.go
+++ b/session.go
@@ -52,7 +52,7 @@ func (c *Session) login(username, password string) error {

        // login to API
        params := map[string]string{
-               "user":     username,
+               "username": username,
                "password": password,
        }

--

@mr-ns
Copy link

mr-ns commented Apr 20, 2023

I have to support both Zabbix < 5.4 and Zabbix >= 6.4 in my environment, so my patch is backward compatible:

diff --git a/go.mod b/go.mod
index db6a935..b74b8dc 100644
--- a/go.mod
+++ b/go.mod
@@ -1,3 +1,5 @@
 module github.com/cavaliercoder/go-zabbix
 
 go 1.16
+
+require github.com/hashicorp/go-version v1.6.0
diff --git a/go.sum b/go.sum
index e69de29..805e323 100644
--- a/go.sum
+++ b/go.sum
@@ -0,0 +1,2 @@
+github.com/hashicorp/go-version v1.6.0 h1:feTTfFNnjP967rlCxM/I9g701jU+RN74YKx2mOkIeek=
+github.com/hashicorp/go-version v1.6.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
diff --git a/session.go b/session.go
index d1b8e46..c13ded8 100644
--- a/session.go
+++ b/session.go
@@ -7,6 +7,8 @@ import (
 	"fmt"
 	"io/ioutil"
 	"net/http"
+
+	"github.com/hashicorp/go-version"
 )
 
 // ErrNotFound describes an empty result set for an API call.
@@ -51,9 +53,18 @@ func (c *Session) login(username, password string) error {
 		return fmt.Errorf("Failed to retrieve Zabbix API version: %v", err)
 	}
 
+	// "user" parameter changed to "username" in Zabbix 5.4. Use the
+	// new parameter unless we can unequivocally determine we are
+	// pre-5.4.
+	userParam := "username"
+	vZabbix, err := version.NewVersion(c.APIVersion)
+	if err == nil && vZabbix.LessThan(version.Must(version.NewVersion("5.4"))) {
+		userParam = "user"
+	}
+
 	// login to API
 	params := map[string]string{
-		"user":     username,
+		userParam:  username,
 		"password": password,
 	}
 

@ksc98
Copy link

ksc98 commented Apr 20, 2023

Looks good, I like it!

@LeroyZwakman
Copy link

found the same,opened PR #55

@fabiang
Copy link
Contributor

fabiang commented Dec 19, 2023

I've fixed this in my fork of this library: https://github.com/fabiang/go-zabbix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants