Module pyzabbix.api

This module provide classes to work with Zabbix API.

class pyzabbix.api.ZabbixAPI(url='https://localhost/zabbix', use_authenticate=False, user='admin', password='zabbix')

ZabbixAPI class, implement interface to zabbix api.

  • url (str) – URL to zabbix api. Default: https://localhost/zabbix
  • use_authenticate (bool) – Use user.authenticate method if True else user.login.
  • user (str) – Zabbix user name. Default: admin.
  • password (str) – Zabbix user password. Default zabbix.
>>> from pyzabbix import ZabbixAPI
>>> z = ZabbixAPI('https://zabbix.server', user='admin', password='zabbix')
>>> # Get API Version
>>> z.api_info.version()
>>> u'2.2.1'
>>> # or
>>> z.do_request('apiinfo.version')
>>> {u'jsonrpc': u'2.0', u'result': u'2.2.1', u'id': u'1'}
>>> # Get all disabled hosts
>>> # or
>>> z.do_request('host.getobjects', {'status': 1})

Return version of server Zabbix API.

Return type:str
Returns:Version of server Zabbix API.
do_request(method, params=None)

Make request to Zabbix API.

  • method (str) – ZabbixAPI method, like: apiinfo.version.
  • params (str) – ZabbixAPI method arguments.
>>> from pyzabbix import ZabbixAPI
>>> z = ZabbixAPI()
>>> apiinfo = z.do_request('apiinfo.version')
get_id(item_type, item=None, with_id=False, hostid=None, **args)

Return id or ids of zabbix objects.

  • item_type (str) – Type of zabbix object. (eg host, item etc.)
  • item (str) – Name of zabbix object. If it is None, return list of all objects in the scope.
  • with_id (bool) – Returned values will be in zabbix json id format. Examlpe: {‘itemid: 128}
  • name (bool) – Return name instead of id.
  • hostid (int) – Filter objects by specific hostid.
  • tempateids – Filter objects which only belong to specific templates by template id.
  • app_name (str) – Filter object which only belong to specific application.
Return type:

int or list


Return single id, name or list of values.