Skip to content

zffocussss/py-zabbix

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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)

About

Python modules for zabbix.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TSQL 98.5%
  • Python 1.5%