Skip to main content

Python module to work with zabbix.

Project description

|Build Status| |Coverage| |PyPi status| |PyPi version|

Zabbix module for Python

Install

You can install Zabbix modules for Python with pip:

::

pip install py-zabbix

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

Examples

ZabbixAPI


.. code:: python

    from pyzabbix.api 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 pyzabbix.api 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 pyzabbix.api import ZabbixAPI

    # Create ZabbixAPI class instance
    logger = logging.getLogger("pyzabbix")
    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 pyzabbix 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)

.. |Build Status| image:: https://travis-ci.org/adubkov/py-zabbix.svg?branch=master :target: https://travis-ci.org/adubkov/py-zabbix .. |Coverage| image:: https://coveralls.io/repos/github/adubkov/py-zabbix/badge.svg?branch=master :target: https://coveralls.io/github/adubkov/py-zabbix?branch=master .. |PyPi status| image:: https://img.shields.io/pypi/status/py-zabbix.svg :target: https://pypi.python.org/pypi/py-zabbix/ .. |PyPi version| image:: https://img.shields.io/pypi/v/py-zabbix.svg :target: https://pypi.python.org/pypi/py-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

py-zabbix-1.1.6.tar.gz (11.4 kB view details)

Uploaded Source

Built Distributions

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

py_zabbix-1.1.6-py3-none-any.whl (19.9 kB view details)

Uploaded Python 3

py_zabbix-1.1.6-py2-none-any.whl (19.9 kB view details)

Uploaded Python 2

File details

Details for the file py-zabbix-1.1.6.tar.gz.

File metadata

  • Download URL: py-zabbix-1.1.6.tar.gz
  • Upload date:
  • Size: 11.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.5

File hashes

Hashes for py-zabbix-1.1.6.tar.gz
Algorithm Hash digest
SHA256 c140d71a3d0c80a7b82446fa948ee8c0f7856215205629c1f584486486226ad9
MD5 81d58e00520a687b7db2a5a14eec02d6
BLAKE2b-256 42e6ff042ccfa077b201fa29e6db81c63a93c560263ad8509d82e04e12149a53

See more details on using hashes here.

File details

Details for the file py_zabbix-1.1.6-py3-none-any.whl.

File metadata

  • Download URL: py_zabbix-1.1.6-py3-none-any.whl
  • Upload date:
  • Size: 19.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.5

File hashes

Hashes for py_zabbix-1.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 fac8579859fd311427f40bed62098a95f0f995727ae2142b5429456290b7874e
MD5 fe04beb32f8f07d4bc5bcb9f9a494b06
BLAKE2b-256 94e2b779ce622bdf99bb48ee4fcb112e2e824c80e215589b24ee57ac30532708

See more details on using hashes here.

File details

Details for the file py_zabbix-1.1.6-py2-none-any.whl.

File metadata

  • Download URL: py_zabbix-1.1.6-py2-none-any.whl
  • Upload date:
  • Size: 19.9 kB
  • Tags: Python 2
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.5

File hashes

Hashes for py_zabbix-1.1.6-py2-none-any.whl
Algorithm Hash digest
SHA256 d7139f736e05c0fc0d844340b31f23a82916acea8a0e0dd0651b8fa1d439d887
MD5 8a816261b3e6a247ea786ad76fd69d6b
BLAKE2b-256 9b656d3366e21eb5ddfaf0b4a17b69d313d8b43ea5c845fc3a6fda0d4465f9d4

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