Giter VIP home page Giter VIP logo

py-zabbix's Introduction

Zabbix module for Python

That set of modules allow to work with Zabbix in Python.

Currently it contains:

  • Module for work with Zabbix API
  • Module for send metrics to Zabbix.

Those modules do not require addition modules, they use standard Python modules.

Install

You can install Zabbix modules for Python with pip:

pip install py-zabbix

API

This module provide classes to work with Zabbix API.

ZabbixAPI

Implement interface to Zabbix API.

Make request to Zabbix API

You can make zabbix api call with two ways:

result = zapi.host.getobjects(status=1)

or

result = zapi.do_request('host.getobjects', {'status':1})

Get Zabbix API version

zapi.api_version()

Get object ID

Return id or list with id of zabbix objects.

get_id(item_type, item=None, with_id=False, hostid=None, **args)

    item_type   (str): Type of zabbix object
    item        (str): Name of zabbix object
                      If None - will return list of all object in the scope
    with_id    (bool): Return values will be in zabbix format
                      Examlpe: {'itemid: 128}
    hostid      (int): Specify id of host for special cases
    templateid  (int): Specify scope to specific template
    app_name    (str): Specify scope to specific template

Example:

from zabbix.api import ZabbixAPI

# Create ZabbixAPI class instance
zapi = ZabbixAPI(url='https://localhost/zabbix/', user='admin', password='zabbix')

# Get all disabled hosts
result1 = zapi.host.getobjects(status=1)

# Other way to get all disabled hosts
result2 = zapi.do_request('host.getobjects', {'status':1})

hostnames1 = [host['host'] for host in result1]
hostnames2 = [host['host'] for host in result2['result']]

ZabbixAPIObjectClass

That class dynamically maps method to Zabbix API call.

Sender

This module provide classes to send metrics to Zabbix.

ZabbixMetric Class

ZabbixMetric class create metric-message to zabbix. Each message contains:

  • Hostname
  • Key
  • Value
  • Timestamp (current time using if not specified)

Example:

message = ZabbixMetric('localhost', 'cpu[usage]', '15.4')

ZabbixSender Class

ZabbixSender class allow send list of ZabbixMetric objects to Zabbix.

You can specify endpoint of zabbix to which you want send the message:

ZabbixSender('zabbix.local', 10051).send( ... )

or use zabbix setting from agent config file for that:

ZabbixSender(use_config = True).send( ... )

Example:

from zabbix.sender import ZabbixMetric, ZabbixSender

packet = [
  ZabbixMetric('centos', 'test[cpu_usage]', 2),
  ZabbixMetric('centos', 'test[system_status]', "OK"),
  ZabbixMetric('centos', 'test[disk_io]', '0.1'),
  ZabbixMetric('centos', 'test[cpu_usage]', 20, 1411598020),
  ZabbixMetric('centos', 'test[cpu_usage]', 30, 1411598120),
  ZabbixMetric('centos', 'test[cpu_usage]', 40, 1411598240),
]

result = ZabbixSender(use_config=True).send(packet)

py-zabbix's People

Contributors

adubkov avatar gescheit avatar b4hand avatar fxthomas avatar faolisilva avatar gomex avatar shapez avatar natict avatar

Watchers

cloud123 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.