Skip to main content

Python module to work with zabbix.

Project description

|PyPi status| |PyPi version|

Zabbix module for Python

Install

You can install Zabbix modules for Python with pip:

::

pip install pyapi-zabbix

Official documentation for pyapi-zabbix <https://pyapi-zabbix.readthedocs.org/en/latest/>__

Examples

ZabbixAPI


.. code:: python

    from pyapi_zabbix import ZabbixAPI

    # Create ZabbixAPI class instance
    zapi = ZabbixAPI(url='https://localhost/zabbix/', user='Admin', password='zabbix')

    # Get all monitored hosts
    result1 = zapi.host.get(monitored_hosts=1, output='extend')

    # Get all disabled hosts
    result2 = zapi.do_request('host.get',
                              {
                                  'filter': {'status': 1},
                                  'output': 'extend'
                              })

    # Filter results
    hostnames1 = [host['host'] for host in result1]
    hostnames2 = [host['host'] for host in result2['result']]

    # Logout from Zabbix
    zapi.user.logout()

Or use 'with' statement to logout automatically:

.. code:: python

    from pyapi_zabbix import ZabbixAPI

    # Create ZabbixAPI class instance
    with ZabbixAPI(url='https://localhost/zabbix/', user='Admin', password='zabbix') as zapi:

        # Get all monitored hosts
        result1 = zapi.host.get(monitored_hosts=1, output='extend')

Enable logging:

.. code:: python

    import sys
    import logging
    from pyapi_zabbix import ZabbixAPI

    # Create ZabbixAPI class instance
    logger = logging.getLogger("pyapi_zabbix")
    logger.setLevel(logging.DEBUG)
    handler = logging.StreamHandler(sys.stdout)
    logger.addHandler(handler)

    zapi = ZabbixAPI(url='http://localhost', user='Admin', password='zabbix')

Note that passwords and auth tokens are hidden when raw messages are logged or raised in exceptions ( but not hidden if print() is used):

.. code:: python

    ZabbixAPI.login(Admin,********)
    Call user.login method
    urllib2.Request(http://localhost/api_jsonrpc.php, {"jsonrpc": "2.0", "method": "user.login", "params": {"user": "Admin", "password": "********"}, "id": "1"})
    Response Body: {
        "jsonrpc": "2.0",
        "result": "********",
        "id": "1"
    }


ZabbixSender

.. code:: python

from pyapi_zabbix import ZabbixMetric, ZabbixSender

# Send metrics to zabbix trapper
packet = [
  ZabbixMetric('hostname1', 'test[cpu_usage]', 2),
  ZabbixMetric('hostname1', 'test[system_status]', "OK"),
  ZabbixMetric('hostname1', 'test[disk_io]', '0.1'),
  ZabbixMetric('hostname1', 'test[cpu_usage]', 20, 1411598020),
]

result = ZabbixSender(use_config=True).send(packet)

.. |PyPi status| image:: https://img.shields.io/pypi/status/pyapi-zabbix.svg :target: https://pypi.python.org/pypi/pyapi-zabbix/ .. |PyPi version| image:: https://img.shields.io/pypi/v/pyapi-zabbix.svg :target: https://pypi.python.org/pypi/pyapi-zabbix/

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyapi-zabbix-1.0.0.tar.gz (18.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyapi_zabbix-1.0.0-py3-none-any.whl (19.3 kB view details)

Uploaded Python 3

File details

Details for the file pyapi-zabbix-1.0.0.tar.gz.

File metadata

  • Download URL: pyapi-zabbix-1.0.0.tar.gz
  • Upload date:
  • Size: 18.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.2

File hashes

Hashes for pyapi-zabbix-1.0.0.tar.gz
Algorithm Hash digest
SHA256 361af500cd7918a822b942afb11d30a9e3f85f4b8f15daf05732c51d6f7926ea
MD5 7c40da54eeffbc35d5929d520d002c02
BLAKE2b-256 92c12ccb83e834ed5da0e87a35c0e2b8143e463379fe8985b4af31cc0130248d

See more details on using hashes here.

File details

Details for the file pyapi_zabbix-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: pyapi_zabbix-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 19.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.2

File hashes

Hashes for pyapi_zabbix-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a2a9a9cde2dd9802f52f45448621b563b3cd984680a10d75749311bd2e992ff4
MD5 fc200c19f56311d3cc856ad8dbedb413
BLAKE2b-256 a00968215dfa2484c5c60ab875696cb66779b6eb5dd9314e8186362479405686

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page