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

httpapi not working with Zabbix 7.2.0 #1431

Open
czertique opened this issue Dec 15, 2024 · 3 comments
Open

httpapi not working with Zabbix 7.2.0 #1431

czertique opened this issue Dec 15, 2024 · 3 comments

Comments

@czertique
Copy link

SUMMARY

Authentication (both user/password and API token) not working with Zabbix 7.2.0.

This is happening because auth payload property has been deprecated ever since Zabbix 6.4 and finally removed in Zabbix 7.2.

ISSUE TYPE
  • Bug Report
COMPONENT NAME

httpapi

ANSIBLE VERSION
ansible [core 2.17.7]
  config file = /etc/ansible/ansible.cfg
  python version = 3.10.12 (main, Nov  6 2024, 20:22:13) [GCC 11.4.0] (/usr/bin/python3)
  jinja version = 3.0.3
  libyaml = True
CONFIGURATION
CONFIG_FILE() = /etc/ansible/ansible.cfg
PERSISTENT_COMMAND_TIMEOUT(/etc/ansible/ansible.cfg) = 1000
PERSISTENT_CONNECT_TIMEOUT(/etc/ansible/ansible.cfg) = 1000
OS / ENVIRONMENT / Zabbix Version

I'm doing this on Ubuntu 22.04 but I believe it will behave the same on any other OS

STEPS TO REPRODUCE

Try to add new host to Zabbix (but will likely happen with any other API call against Zabbix). Tested both username/password and API auth key

- name: Add zabbix host to zabbix server
  delegate_to: zabbix_host
  tags:
    - zabbix
    - addhost
  vars:
    zabbix_interfaces:
      - type: 1
        ip: "1.2.3.4"
        dns: "host.domain"
        useip: "0"
    ansible_network_os: community.zabbix.zabbix
    ansible_connection: httpapi
    ansible_httpapi_port: 80
    ansible_httpapi_use_ssl: false
    ansible_zabbix_url_path: ''
    ansible_zabbix_auth_key: abc123
    # ansible_user: _ansible
    # ansible_httpapi_pass: ansible_pass
  community.zabbix.zabbix_host:
    host_name: "{{ inventory_hostname }}"
    visible_name: "{{ inventory_hostname }}"
    state: present
    status: enabled
    interfaces: "{{ zabbix_interfaces }}"
    link_templates:
      - Linux by Zabbix agent
    host_groups:
      - Linux servers
EXPECTED RESULTS

Host is added to Zabbix server

ACTUAL RESULTS

Task fails with error: 'message': 'Invalid request.', 'data': 'Invalid parameter \"/\": unexpected parameter \"auth\".'}

    "msg": "connection error occurred: REST API returned {'code': -32600, 'message': 'Invalid request.', 'data': 'Invalid parameter \"/\": unexpected parameter \"auth\".'} when sending {\"jsonrpc\": \"2.0\", \"method\": \"template.get\", \"id\": \"090b5f4c-a0b9-437f-84d0-442a378f25b1\", \"params\": {\"output\": [\"templateid\"], \"filter\": {\"host\": \"Linux by Zabbix agent\"}}, \"auth\": \"e6f472a89054c8246177864547e905b1a3bee93af69b854a580d242c7d0df1db\"}"
@czertique
Copy link
Author

This is my first issue ever on Github, I have read the issue guidelines, did not find any previous reports of this and tried to do it right, but if I missed something I apologize.

I have also made a patch that seems to be working for me, but as I am unable to test it properly, I did not make it into a pull request. I am not really sure whether this will work with different Zabbix versions and/or if this breaks anything else but it seems to be working for me. Also I am not sure whether it is OK to add dependency on re in the script, so I'll leave that to someone else.

*** plugins/httpapi/zabbix.py.orig      2024-12-15 14:38:07.708512502 +0000
--- plugins/httpapi/zabbix.py   2024-12-15 14:23:24.858674887 +0000
***************
*** 52,57 ****
--- 52,58 ----

  import json
  import base64
+ import re

  from uuid import uuid4

***************
*** 134,146 ****
          if not data:
              data = {}

-         if self.connection._auth:
-             data['auth'] = self.connection._auth['auth']
-
          hdrs = {
              'Content-Type': 'application/json-rpc',
              'Accept': 'application/json',
          }
          http_login_user = self.get_option('http_login_user')
          http_login_password = self.get_option('http_login_password')
          if http_login_user and http_login_user != '-42':
--- 135,152 ----
          if not data:
              data = {}

          hdrs = {
              'Content-Type': 'application/json-rpc',
              'Accept': 'application/json',
          }
+
+         if hasattr(self.connection, 'zbx_api_version') and re.match('^7\..*$', self.connection.zbx_api_version):
+             if self.connection._auth:
+                 hdrs['Authorization'] = ('Bearer %s' % (self.connection._auth['auth']))
+         else:
+             if self.connection._auth:
+                 data['auth'] = self.connection._auth['auth']
+
          http_login_user = self.get_option('http_login_user')
          http_login_password = self.get_option('http_login_password')
          if http_login_user and http_login_user != '-42':

@Airler
Copy link

Airler commented Dec 16, 2024

There are more changes for deprecated params required which were removed on 7.2 release.
For example groupids and hostids on maintenance.create and maintenance.update are also removed now.

@Airler
Copy link

Airler commented Dec 16, 2024

There are more changes for deprecated params required which were removed on 7.2 release. For example groupids and hostids on maintenance.create and maintenance.update are also removed now.

Just found a list of I hope all deprecated params removed in 7.2: https://www.zabbix.com/documentation/7.2/en/manual/api/changes

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

2 participants