Module pyapi_zabbix.sender

class pyapi_zabbix.sender.ZabbixMetric(host, key, value, clock=None)

The ZabbixMetric contain one metric for zabbix server.

Parameters
  • host (str) – Hostname as it displayed in Zabbix.

  • key (str) – Key by which you will identify this metric.

  • value (str) – Metric value.

  • clock (int) – Unix timestamp. Current time will used if not specified.

>>> from pyapi_zabbix import ZabbixMetric
>>> ZabbixMetric('localhost', 'cpu[usage]', 20)
class pyapi_zabbix.sender.ZabbixResponse

The ZabbixResponse contains the parsed response from Zabbix.

parse(response)

Parse zabbix response.

class pyapi_zabbix.sender.ZabbixSender(zabbix_server='127.0.0.1', zabbix_port=10051, use_config=None, chunk_size=250, socket_wrapper=None, timeout=10)

The ZabbixSender send metrics to Zabbix server.

Implementation of zabbix protocol.

Parameters
  • zabbix_server (str) – Zabbix server ip address. Default: 127.0.0.1

  • zabbix_port (int) – Zabbix server port. Default: 10051

  • use_config (str) – Path to zabbix_agentd.conf file to load settings from. If value is True then default config path will used: /etc/zabbix/zabbix_agentd.conf

  • chunk_size (int) – Number of metrics send to the server at one time

  • socket_wrapper (function) –

    to provide a socket wrapper function to be used to wrap the socket connection to zabbix. Example:

    from pyapi_zabbix import ZabbixSender import ssl secure_connection_option = dict(..) zs = ZabbixSender(

    zabbix_server=zabbix_server, zabbix_port=zabbix_port, socket_wrapper=lambda sock:ssl.wrap_socket(sock,**secure_connection_option)

    )

  • timeout (int) – Number of seconds before call to Zabbix server times out Default: 10

>>> from pyapi_zabbix import ZabbixMetric, ZabbixSender
>>> metrics = []
>>> m = ZabbixMetric('localhost', 'cpu[usage]', 20)
>>> metrics.append(m)
>>> zbx = ZabbixSender('127.0.0.1')
>>> zbx.send(metrics)
send(metrics)

Send the metrics to zabbix server.

Parameters

metrics (list) – List of zabbix.sender.ZabbixMetric to send to Zabbix

Return type

pyapi_zabbix.sender.ZabbixResponse

Returns

Parsed response from Zabbix Server