Python modules for zabbix.
Branch: master
Clone or download
adubkov Merge pull request #106 from v-zhuravlev/case_sensitive_user
renamed user 'admin'  in docs and tests
Latest commit a26aadc Feb 18, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
docs
pyzabbix
tests renamed admin to Admin in docs Feb 16, 2019
zabbix zabbix module renamed to pyzabbix Mar 21, 2016
.coveragerc Increased test coverage Jun 29, 2016
.gitignore Add basic .gitignore. Oct 16, 2015
.travis.yml
LICENSE Add python modules for work with zabbix Feb 11, 2015
README.rst Merge branch 'master' into case_sensitive_user Feb 18, 2019
setup.py fix build for python2 and update version Oct 6, 2018

README.rst

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 documentaion for py-zabbix

Examples

ZabbixAPI

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:

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')

    # 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']]

ZabbixSender

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)