Module pyapi_zabbix.api
This module provide classes to work with Zabbix API.
- class pyapi_zabbix.api.ZabbixAPI(url=None, use_authenticate=False, use_basic_auth=False, user=None, password=None, api_token=None)
ZabbixAPI class, implement interface to zabbix api. :type url: str :param url: URL to zabbix api. Default: ZABBIX_URL or
https://localhost/zabbix
- Parameters
use_authenticate (bool) – Use user.authenticate method if True else user.login.
use_basic_auth (bool) – Using basic auth if True
user (str) – Zabbix user name. Default: ZABBIX_USER or ‘Admin’.
password (str) – Zabbix user password. Default ZABBIX_PASSWORD or zabbix.
password – Zabbix API Token.
>>> from pyapi_zabbix import ZabbixAPI >>> z = ZabbixAPI('https://zabbix.server', user='Admin', password='zabbix') >>> # z = ZabbixAPI('https://zabbix.server', api_token='xxxx') >>> # 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 >>> z.host.get(status=1) >>> # or >>> z.do_request('host.getobjects', {'status': 1})
- api_version()
Return version of server Zabbix API. :rtype: str :return: Version of server Zabbix API.
- static cred_to_base64(user, password)
Create header for basic authorization :type user: str :param user: Zabbix user :type password: str :param password: Zabbix user password :return: str
- do_request(method, params=None)
Make request to Zabbix API. :type method: str :param method: ZabbixAPI method, like: apiinfo.version. :type params: str :param params: ZabbixAPI method arguments. >>> from pyapi_zabbix 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. :type item_type: str :param item_type: Type of zabbix object. (eg host, item etc.) :type item: str :param item: Name of zabbix object. If it is None, return list of
all objects in the scope.
- Parameters
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
- Returns
Return single id, name or list of values.