### Install Zabbix Utils via pip Source: https://github.com/zabbix/python-zabbix-utils/blob/main/README.md Installs the basic python-zabbix-utils library from the Python Package Index (PyPI). This is the standard method for installing the core library. ```bash $ pip install zabbix_utils ``` -------------------------------- ### Install Zabbix Utils with Async Dependencies via pip Source: https://github.com/zabbix/python-zabbix-utils/blob/main/README.md Installs the python-zabbix-utils library from PyPI along with additional dependencies required for asynchronous operations, such as aiohttp. ```bash $ pip install zabbix_utils[async] ``` -------------------------------- ### Install Zabbix Utils from Source via setup.py Source: https://github.com/zabbix/python-zabbix-utils/blob/main/README.md Installs the python-zabbix-utils library from the cloned source directory using the setup.py script. This method requires cloning the repository first. ```bash $ cd python-zabbix-utils/ $ python3 setup.py install ``` -------------------------------- ### Install Async Dependencies via apt (Debian) Source: https://github.com/zabbix/python-zabbix-utils/blob/main/README.md Installs the aiohttp library, required for asynchronous functionality, using the apt package manager on Debian/Ubuntu and derivatives. ```bash # apt install python3-aiohttp ``` -------------------------------- ### Install Zabbix Utils via apt (Debian) Source: https://github.com/zabbix/python-zabbix-utils/blob/main/README.md Installs the python-zabbix-utils library using the apt package manager on Debian/Ubuntu and derivatives, assuming the Zabbix repository is configured. ```bash # apt install python3-zabbix-utils ``` -------------------------------- ### Install Async Dependencies via dnf (RHEL) Source: https://github.com/zabbix/python-zabbix-utils/blob/main/README.md Installs the aiohttp library, required for asynchronous functionality, using the dnf package manager on RHEL and derivatives. Requires the EPEL repository. ```bash # dnf install epel-release # dnf install python3-aiohttp ``` -------------------------------- ### Clone Zabbix Utils Repository from GitHub Source: https://github.com/zabbix/python-zabbix-utils/blob/main/README.md Clones the official python-zabbix-utils repository from GitHub to a local directory. This is the first step for installing directly from source. ```bash $ git clone https://github.com/zabbix/python-zabbix-utils ``` -------------------------------- ### Install Zabbix Utils via dnf (RHEL) Source: https://github.com/zabbix/python-zabbix-utils/blob/main/README.md Installs the python-zabbix-utils library using the dnf package manager on Red Hat Enterprise Linux and derivatives, assuming the Zabbix repository is configured. ```bash # dnf install python3-zabbix-utils ``` -------------------------------- ### Getting Zabbix Agent Data Asynchronously (Python) Source: https://github.com/zabbix/python-zabbix-utils/blob/main/README.md Shows how to use the `zabbix_utils.AsyncGetter` class for asynchronous retrieval of item values from a Zabbix agent. It uses `asyncio` to run an asynchronous function that initializes the `AsyncGetter` and awaits the `get` method call. ```python import asyncio from zabbix_utils import AsyncGetter async def main(): agent = AsyncGetter(host='127.0.0.1', port=10050) resp = await agent.get('system.uname') print(resp.value) # Linux test_server 5.15.0-3.60.5.1.el9uek.x86_64 asyncio.run(main()) ``` -------------------------------- ### Getting Zabbix Agent Data Synchronously (Python) Source: https://github.com/zabbix/python-zabbix-utils/blob/main/README.md Demonstrates how to use the `zabbix_utils.Getter` class to retrieve an item value from a Zabbix agent synchronously. It initializes the `Getter` with the agent's host and port, then calls the `get` method with the item key. ```python from zabbix_utils import Getter agent = Getter(host='127.0.0.1', port=10050) resp = agent.get('system.uname') print(resp.value) # Linux test_server 5.15.0-3.60.5.1.el9uek.x86_64 ``` -------------------------------- ### Authenticating ZabbixAPI with API Token (Synchronous Python) Source: https://github.com/zabbix/python-zabbix-utils/blob/main/README.md Provides a concise example of authenticating with the synchronous ZabbixAPI class using an API token instead of a username and password. This method is supported since Zabbix 5.4. ```python api = ZabbixAPI(url="127.0.0.1") api.login(token="xxxxxxxx") ``` -------------------------------- ### Sending Multiple Item Values with Zabbix Sender (Synchronous Python) Source: https://github.com/zabbix/python-zabbix-utils/blob/main/README.md Explains how to create a list of ItemValue objects, each representing an item value to be sent, and send them all at once using the synchronous sender.send() method. Shows examples of different value types and timestamps. ```python from zabbix_utils import ItemValue, Sender items = [ ItemValue('host1', 'item.key1', 10), ItemValue('host1', 'item.key2', 'test message'), ItemValue('host2', 'item.key1', -1, 1695713666), ItemValue('host3', 'item.key1', '{"msg":"test message"}'), ItemValue('host2', 'item.key1', 0, 1695713666, 100) ] sender = Sender(server='127.0.0.1', port=10051) response = sender.send(items) print(response) # {"processed": 5, "failed": 0, "total": 5, "time": "0.001661", "chunk": 1} ``` -------------------------------- ### Authenticating and Querying Users with ZabbixAPI (Synchronous Python) Source: https://github.com/zabbix/python-zabbix-utils/blob/main/README.md Demonstrates how to initialize the ZabbixAPI class for synchronous interaction, log in using a username and password, retrieve a list of users with specific output fields, iterate through the results, and log out. ```python from zabbix_utils import ZabbixAPI api = ZabbixAPI(url="127.0.0.1") api.login(user="User", password="zabbix") users = api.user.get( output=['userid','name'] ) for user in users: print(user['name']) api.logout() ``` -------------------------------- ### Importing Configuration with ZabbixAPI (Handling Keywords - Python) Source: https://github.com/zabbix/python-zabbix-utils/blob/main/README.md Illustrates how to call API methods that match Python keywords (like 'import') by appending an underscore (_) to the method name. Shows reading an XML template file and using api.configuration.import_. ```python from zabbix_utils import ZabbixAPI api = ZabbixAPI(url="127.0.0.1") api.login(token="xxxxxxxx") template_source = '' with open('template_example.xml', mode='r', encoding='utf-8') as f: template_source = f.read() response = api.configuration.import_( source=template_source, format="xml", rules={...} ) if response: print("Template imported successfully") ``` -------------------------------- ### Authenticating and Querying Users with AsyncZabbixAPI (Asynchronous Python) Source: https://github.com/zabbix/python-zabbix-utils/blob/main/README.md Shows how to use the AsyncZabbixAPI class for asynchronous API calls. It initializes the API, logs in asynchronously, retrieves users, and iterates through them within an async function, then runs it using asyncio.run. ```python import asyncio from zabbix_utils import AsyncZabbixAPI async def main(): api = AsyncZabbixAPI(url="127.0.0.1") await api.login(user="User", password="zabbix") users = await api.user.get( output=['userid','name'] ) for user in users: print(user['name']) await api.logout() asyncio.run(main()) ``` -------------------------------- ### Sending Values to Multiple Zabbix Clusters with Zabbix Sender (Synchronous Python) Source: https://github.com/zabbix/python-zabbix-utils/blob/main/README.md Shows how to initialize the synchronous Sender with a list of Zabbix cluster configurations (each cluster being a list of server/proxy addresses). Sending a value will attempt to send to each cluster, and the response includes details for each. ```python from zabbix_utils import Sender zabbix_clusters = [ ['zabbix.cluster1.node1', 'zabbix.cluster1.node2:10051'], ['zabbix.cluster2.node1:10051', 'zabbix.cluster2.node2:20051', 'zabbix.cluster2.node3'] ] sender = Sender(clusters=zabbix_clusters) response = sender.send_value('host', 'item.key', 'value', 1695713666) print(response) # {"processed": 2, "failed": 0, "total": 2, "time": "0.000103", "chunk": 2} print(response.details) # { # zabbix.cluster1.node1:10051: [{"processed": 1, "failed": 0, "total": 1, "time": "0.000050", "chunk": 1}], # zabbix.cluster2.node2:20051: [{"processed": 1, "failed": 0, "total": 1, "time": "0.000053", "chunk": 1}] # } ``` -------------------------------- ### Enabling Debug Logging for zabbix_utils (Python) Source: https://github.com/zabbix/python-zabbix-utils/blob/main/README.md Explains how to enable debug logging for the `zabbix_utils` library using Python's standard `logging` module. It configures basic logging with a specific format and sets the level to `DEBUG` to see detailed output from the library's operations. ```python import logging from zabbix_utils import Getter logging.basicConfig( format=u'[%(asctime)s] %(levelname)s %(message)s', level=logging.DEBUG ) agent = Getter(host='127.0.0.1', port=10050) resp = agent.get('system.uname') print(resp.value) ``` -------------------------------- ### Comparing Zabbix API Versions (Python) Source: https://github.com/zabbix/python-zabbix-utils/blob/main/README.md Demonstrates how to retrieve the API version using api.api_version() or api.version and compare it with numbers or strings. Also shows accessing major/minor version components and checking for LTS status. ```python # Method to get version ver = api.api_version() print(type(ver).__name__, ver) # APIVersion 7.0.0 # ZabbixAPI prototype with version ver = api.version print(type(ver).__name__, ver) # APIVersion 7.0.0 # Comparing versions print(ver > 6.0) # True print(ver != 7.0) # False print(ver != "7.0.0") # False # Version additional methods print(ver.major) # 7.0 print(ver.minor) # 0 print(ver.is_lts()) # True ``` -------------------------------- ### Sending Single Item Value with Zabbix Sender (Synchronous Python) Source: https://github.com/zabbix/python-zabbix-utils/blob/main/README.md Shows how to use the synchronous Sender class to send a single item value to a Zabbix server or proxy using the Zabbix sender protocol. Initializes the sender with server address and port and calls send_value. ```python from zabbix_utils import Sender sender = Sender(server='127.0.0.1', port=10051) response = sender.send_value('host', 'item.key', 'value', 1695713666) print(response) # {"processed": 1, "failed": 0, "total": 1, "time": "0.000338", "chunk": 1} ``` -------------------------------- ### Sending Single Item Value with AsyncZabbix Sender (Asynchronous Python) Source: https://github.com/zabbix/python-zabbix-utils/blob/main/README.md Demonstrates sending a single item value asynchronously using the AsyncSender class within an async function and running it with asyncio.run. Initializes the sender and awaits the send_value call. ```python import asyncio from zabbix_utils import AsyncSender async def main(): sender = AsyncSender(server='127.0.0.1', port=10051) response = await sender.send_value('host', 'item.key', 'value', 1695713666) print(response) # {"processed": 1, "failed": 0, "total": 1, "time": "0.000338", "chunk": 1} asyncio.run(main()) ``` -------------------------------- ### Authenticating AsyncZabbixAPI with API Token (Asynchronous Python) Source: https://github.com/zabbix/python-zabbix-utils/blob/main/README.md Shows how to authenticate asynchronously with the AsyncZabbixAPI class using an API token. When using a token, explicitly calling api.logout() is not necessary. ```python api = AsyncZabbixAPI(url="127.0.0.1") await api.login(token="xxxxxxxx") ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.