{"id":8795,"library":"zabbix-utils","title":"Zabbix Utils","description":"Zabbix Utils is an official Python library designed for seamless interaction with Zabbix components, including the Zabbix API, Zabbix sender protocol, and Zabbix get protocol. Currently at version 2.0.4, the library is actively maintained with frequent releases to ensure compatibility with the latest Zabbix server versions and to introduce new features and bug fixes.","status":"active","version":"2.0.4","language":"en","source_language":"en","source_url":"https://github.com/zabbix/python-zabbix-utils","tags":["Zabbix","monitoring","API","automation","devops","system administration"],"install":[{"cmd":"pip install zabbix-utils","lang":"bash","label":"Install stable version"},{"cmd":"pip install zabbix-utils[async]","lang":"bash","label":"Install with asynchronous dependencies"}],"dependencies":[{"reason":"Required for asynchronous API interactions (AsyncZabbixAPI, AsyncSender, AsyncGetter).","package":"aiohttp","optional":true}],"imports":[{"note":"For synchronous interaction with the Zabbix API.","symbol":"ZabbixAPI","correct":"from zabbix_utils import ZabbixAPI"},{"note":"For asynchronous interaction with the Zabbix API, requiring an async event loop.","symbol":"AsyncZabbixAPI","correct":"from zabbix_utils import AsyncZabbixAPI"},{"note":"For sending data to Zabbix server or proxy, similar to zabbix_sender utility.","symbol":"Sender","correct":"from zabbix_utils import Sender"},{"note":"For retrieving data from Zabbix agents, similar to zabbix_get utility.","symbol":"Getter","correct":"from zabbix_utils import Getter"}],"quickstart":{"code":"import os\nfrom zabbix_utils import ZabbixAPI\n\n# Configure Zabbix API access using environment variables\nZABBIX_URL = os.environ.get('ZABBIX_URL', 'http://127.0.0.1/zabbix')\nZABBIX_USER = os.environ.get('ZABBIX_USER', 'Admin')\nZABBIX_PASSWORD = os.environ.get('ZABBIX_PASSWORD', 'zabbix')\n\n# Initialize ZabbixAPI instance and log in\ntry:\n    api = ZabbixAPI(url=ZABBIX_URL)\n    api.login(user=ZABBIX_USER, password=ZABBIX_PASSWORD)\n    print(f\"Successfully logged into Zabbix API at {ZABBIX_URL}\")\n\n    # Example: Fetch all hosts\n    hosts = api.host.get(output=['hostid', 'name'])\n    if hosts:\n        print(\"\\nKnown hosts:\")\n        for host in hosts:\n            print(f\"  ID: {host['hostid']}, Name: {host['name']}\")\n    else:\n        print(\"No hosts found.\")\n\nexcept Exception as e:\n    print(f\"Error connecting to Zabbix API: {e}\")\nfinally:\n    # Always log out to close the session if logged in\n    if 'api' in locals() and api.is_logged_in:\n        api.logout()\n        print(\"Logged out from Zabbix API.\")\n","lang":"python","description":"This quickstart demonstrates how to establish a connection to the Zabbix API using `ZabbixAPI` class, authenticate with username and password (or token), and perform a basic API call to retrieve a list of hosts. It prioritizes environment variables for credentials, falling back to defaults if not set. Remember to replace placeholder values with your actual Zabbix server URL and credentials. For asynchronous operations, use `AsyncZabbixAPI` and `await` with an `async def` function."},"warnings":[{"fix":"Review the new response format for `Sender` and `Getter` methods and update parsing logic accordingly. Refer to official documentation or examples for the new structure.","message":"The format of responses from the `Sender` and `Getter` classes changed significantly in version 1.1.0. Existing code parsing these responses will break.","severity":"breaking","affected_versions":">=1.1.0"},{"fix":"For asynchronous operations, import `AsyncZabbixAPI` (or `AsyncSender`, `AsyncGetter`), define an `async` function, and `await` all API calls. Install `aiohttp` for async dependencies.","message":"Version 2.0.0 introduced asynchronous modules (`AsyncZabbixAPI`, `AsyncSender`, `AsyncGetter`). While synchronous modules still exist, users migrating to async will need to rewrite their code using `await` and an async event loop.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Upgrade your Zabbix server to use API tokens for authentication or downgrade `zabbix-utils` if compatible with your Zabbix server version and prior authentication methods.","message":"Support for HTTP authentication was discontinued for Zabbix server versions 7.2 and newer starting from `zabbix-utils` version 2.0.2.","severity":"breaking","affected_versions":">=2.0.2 (when connecting to Zabbix >=7.2)"},{"fix":"It is highly recommended to upgrade your Zabbix server to a currently supported version to ensure compatibility and receive security updates.","message":"Official support for Zabbix server version 5.0 was discontinued with the release of `zabbix-utils` version 2.0.3.","severity":"deprecated","affected_versions":">=2.0.3"},{"fix":"When calling such methods, append an underscore. For example, `api.configuration.import_()` instead of `api.configuration.import()`.","message":"Zabbix API methods with names that are Python keywords (e.g., `import`, `get`) require an underscore suffix when called through the `ZabbixAPI` object to avoid syntax errors.","severity":"gotcha","affected_versions":"All"},{"fix":"Upgrade to `zabbix-utils` version 2.0.4 or newer to ensure connection timeouts are respected and prevent scripts from hanging.","message":"A bug causing timeout parameters to be ignored for connections was fixed in version 2.0.4, which could lead to scripts hanging indefinitely on network issues in older versions.","severity":"gotcha","affected_versions":"<2.0.4"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Verify that the Zabbix server URL is correct, the Zabbix API is accessible, and the server is running. Check Zabbix server logs for any related errors.","cause":"This error typically indicates that the Zabbix server responded with something unexpected or invalid, often due to misconfiguration, network issues, or the Zabbix server being unavailable or returning an error status.","error":"zabbix_utils.exceptions.ProcessingError: Unexpected response was received from Zabbix."},{"fix":"Ensure the Zabbix server/proxy is running, the host and port are correct, and no firewalls are blocking the connection between your script and the Zabbix server/proxy. Consider increasing the timeout if latency is expected.","cause":"This indicates a network connectivity issue or that the Zabbix server/proxy is not listening on the specified host and port (default 10051 for sender). A firewall might also be blocking the connection.","error":"The connection to zabbixsrv.example.net:10051 timed out after 10 seconds while trying to send."},{"fix":"Upgrade `zabbix-utils` to the latest version (`pip install --upgrade zabbix-utils`). If the latest version still doesn't support your Zabbix server, you might need to use the `skip_version_check=True` parameter in `ZabbixAPI` (use with caution) or wait for a library update.","cause":"Your `zabbix-utils` library version does not officially support the Zabbix server version you are trying to connect to. This can happen when a new Zabbix server version is released before the library is updated.","error":"Zabbix API version mismatch. The Zabbix server version (X.Y) is not officially supported by this library version (A.B)."}]}