Git Product home page Git Product logo

python-zabbix's Introduction

python-zabbix

Very simple python module implementing Zabbix Sender protocol. You can find code in module subdir.

Install

With Debian:

apt-get install python-stdeb python-setuptools

cd module
python setup.py --command-packages=stdeb.command bdist_deb
apt-get install python-simplejson
dpkg -i deb_dist/python-zabbix_0.0.1-1_all.deb

From pip:

For now, protobix is only available from testpypip:

pip install -i https://testpypi.python.org/pypi protobix

Usage

Once module is installed, you can use it as follow

Send items as trappers

#!/usr/bin/env python

''' import module '''
import protobix

''' create DataContainer, providing data_type, zabbix server and port '''
zbx_container = protobix.DataContainer("items", "localhost", 10051)
''' set debug '''
zbx_container.set_debug(True)
zbx_container.set_verbosity(True)

''' Add items one after the other '''
hostname="myhost"
item="my.zabbix.item"
value=0
zbx_container.add_item( hostname, item, value)

''' or use bulk insert '''
data = {
    "myhost1": {
        "my.zabbix.item1": 0,
        "my.zabbix.item2": "item string"
    },
    "myhost2": {
        "my.zabbix.item1": 0,
        "my.zabbix.item2": "item string"
    }
}
zbx_container.add(data)

''' Send data to zabbix '''
ret = zbx_container.send(zbx_container)
''' If returns False, then we got a problem '''
if not ret:
    print "Ooops. Something went wrong when sending data to Zabbix"

print "Everything is OK"

Send Low Level Discovery as trappers

#!/usr/bin/env python

''' import module '''
import protobix

''' create DataContainer, providing data_type, zabbix server and port '''
zbx_container = protobix.DataContainer("lld", "localhost", 10051)
''' set debug '''
zbx_container.set_debug(True)
zbx_container.set_verbosity(True)

''' Add items one after the other '''
hostname="myhost"
item="my.zabbix.lld_item1"
value=[
    { 'my.zabbix.ldd_key1': 0,
      'my.zabbix.ldd_key2': 'lld string' },
    { 'my.zabbix.ldd_key3': 1,
      'my.zabbix.ldd_key4': 'another lld string' }
]
zbx_container.add_item( hostname, item, value)

''' or use bulk insert '''
data = {
    'myhost1': {
        'my.zabbix.lld_item1': [
            { 'my.zabbix.ldd_key1': 0,
              'my.zabbix.ldd_key2': 'lld string' },
            { 'my.zabbix.ldd_key3': 1,
              'my.zabbix.ldd_key4': 'another lld string' }
        ]
    'myhost2':
        'my.zabbix.lld_item2': [
            { 'my.zabbix.ldd_key10': 10,
              'my.zabbix.ldd_key20': 'yet an lld string' },
            { 'my.zabbix.ldd_key30': 2,
              'my.zabbix.ldd_key40': 'yet another lld string' }
        ]
}
zbx_container.add(data)

''' Send data to zabbix '''
ret = zbx_container.send(zbx_container)
''' If returns False, then we got a problem '''
if not ret:
    print "Ooops. Something went wrong when sending data to Zabbix"

print "Everything is OK"

python-zabbix's People

Contributors

jbfavre avatar shtouff avatar skinkie avatar

Watchers

zhaosong 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.