Skip to content

Commit

Permalink
Update the API parameter from user to username - user is Deprecated i…
Browse files Browse the repository at this point in the history
…n version 6.4
  • Loading branch information
altmas5 committed Mar 17, 2023
1 parent b0a7b3f commit 4119b5c
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test-zabbix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ jobs:
TEST_ZABBIX_PASSWORD: zabbix
run: |
while true ; do
output=$(curl -X POST -H 'Content-Type: application/json-rpc' -d '{"jsonrpc":"2.0","method":"user.login","params":{"user":"'$TEST_ZABBIX_USER'","password":"'$TEST_ZABBIX_PASSWORD'"},"id":1,"auth":null}' $TEST_ZABBIX_URL || echo error)
output=$(curl -X POST -H 'Content-Type: application/json-rpc' -d '{"jsonrpc":"2.0","method":"user.login","params":{"username":"'$TEST_ZABBIX_USER'","password":"'$TEST_ZABBIX_PASSWORD'"},"id":1,"auth":null}' $TEST_ZABBIX_URL || echo error)
echo $output
echo $output | grep -v error > /dev/null && break
echo "Waiting 5s for Zabbix Server to be ready..."
Expand Down
4 changes: 2 additions & 2 deletions base.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ func (api *API) CallWithErrorParse(method string, params interface{}, result int

// Login Calls "user.login" API method and fills api.Auth field.
// This method modifies API structure and should not be called concurrently with other methods.
func (api *API) Login(user, password string) (auth string, err error) {
params := map[string]string{"user": user, "password": password}
func (api *API) Login(username, password string) (auth string, err error) {
params := map[string]string{"username": username, "password": password}
response, err := api.CallWithError("user.login", params)
if err != nil {
return
Expand Down
6 changes: 3 additions & 3 deletions base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,16 @@ func testGetAPI(t *testing.T) *zapi.API {
return _api
}

url, user, password := os.Getenv("TEST_ZABBIX_URL"), os.Getenv("TEST_ZABBIX_USER"), os.Getenv("TEST_ZABBIX_PASSWORD")
url, username, password := os.Getenv("TEST_ZABBIX_URL"), os.Getenv("TEST_ZABBIX_USER"), os.Getenv("TEST_ZABBIX_PASSWORD")
_api = zapi.NewAPI(url)
_api.SetClient(http.DefaultClient)
v := os.Getenv("TEST_ZABBIX_VERBOSE")
if v != "" && v != "0" {
_api.Logger = log.New(os.Stderr, "[zabbix] ", 0)
}

if user != "" {
auth, err := _api.Login(user, password)
if username != "" {
auth, err := _api.Login(username, password)
if err != nil {
t.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ if ! [[ "$ZABBIX_VERSION" == "$TEST_ZABBIX_VERSION"* ]]; then
fi

# Check login
ZABBIX_TOKEN=$(curl -s -X POST -H 'Content-Type: application/json-rpc' -d "{\"jsonrpc\":\"2.0\",\"method\":\"user.login\",\"id\":1,\"params\":{\"user\":\"$TEST_ZABBIX_USER\",\"password\":\"$TEST_ZABBIX_PASSWORD\"}}" "$TEST_ZABBIX_URL" | jq -c -r .result)
ZABBIX_TOKEN=$(curl -s -X POST -H 'Content-Type: application/json-rpc' -d "{\"jsonrpc\":\"2.0\",\"method\":\"user.login\",\"id\":1,\"params\":{\"username\":\"$TEST_ZABBIX_USER\",\"password\":\"$TEST_ZABBIX_PASSWORD\"}}" "$TEST_ZABBIX_URL" | jq -c -r .result)
if [[ "$ZABBIX_VERSION" == "null" ]]; then
echo "Zabbix login failed"
exit 2
Expand Down

0 comments on commit 4119b5c

Please sign in to comment.