Skip to content

Issues with Zabbix 7.0 LTS and API token #41

@tholomew92

Description

@tholomew92

Hi, I encountered an issue using this library where if I use API token I keep getting "Error: Invalid params. Not authorized."

Digging through the source code a bit the issue seems to be this check here:

        if need_auth:
            if not self.__session_id:
                raise ProcessingError("You're not logged in Zabbix API")
            if self.version < 6.4:
                request_json['auth'] = self.__session_id
            elif self.version <= 7.0 and self.__basic_cred is not None:
                request_json['auth'] = self.token
            else:
                headers["Authorization"] = f"Bearer {self.__session_id}"

Using 7.0 LTS and an api token makes it go the else case where it sets the session_id in the header but based on my test with both curl and just using request I need to set my token in the request body in the auth variable similar to how it does when the version is before 6.4. It starts working for me if I change the check to this instead:

        if need_auth:
            if not self.__session_id:
                raise ProcessingError("You're not logged in Zabbix API")
            if self.version <= 7.0 and self.__basic_cred is not None:
                request_json['auth'] = self.token
            elif self.version <= 7.0:
                request_json['auth'] = self.__session_id
            else:
                headers["Authorization"] = f"Bearer {self.__session_id}"

Whether or not this the actually correct solution for the library as a whole I don't know but it fixed the issue for me.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions