Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reworked, twisted-friendly, pip-friendly, exception-based version of the sender #4

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
16 changes: 16 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
*.log
*.pot
*.pyc
*.swp

.vagrant
.grunt

# extra
.idea
.DS_Store
._*
*~
*.egg-info
build
dist
90 changes: 88 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,97 @@ Python implementation of zabbix_sender.

This is a module that allows you to send data to a [Zabbix] server using Python. You don't need the zabbix_sender binary anymore.

Users of the [Twisted] library can use an asynchronous version of the sender.

Has been tested with Python 2.5.1 and 2.7

Python 2.5.1 doesn't have a json module (needed to implement zabbix protocol), so you can use [simplejson] instead.

Source code contains samples and comments to allows you start using it in no time. Here's a small example:
Installation
------------

Install the package using a pip from the original repository:
```bash
pip install "git+git://github.com/kmomberg/pyZabbixSender.git"
```
or from one of the mirrors, like:
```bash
pip install "git+git://github.com/baseride/pyZabbixSender.git"
```

Usage
-----

Here's a small example (synchronous code):

```python
from pyZabbixSender.sy import syZabbixSender

# Creating a sender object
z = syZabbixSender(server="zabbix-server", port=10051)

# Adding data (without timestamp)
z.addData(hostname="test_host", key="test_trap_1", value="12")
z.addData("test_host", "test_trap_2", "2.43")

# Adding data (with timestamp)
z.addData("test_host", "test_trap_2", "2.43", 1365787627)

# Ready to send your data?
results = z.sendData()

# Check if everything was sent as expected
if not results[0][0]:
print "oops! Sending data has been failed"
elif results[0][1]['info']['processed'] != 3:
print "oops! Zabbix doesn't recognize passed identities"

# Clear internal data to start populating again
z.clearData()

# Wants to send a single data point right now?
z.sendSingle("test_host","test_trap","12")
```

The asynchronous code looks mostly the same, except asynchronous calls to send...() functions:

```python
from pyZabbixSender.tx import txZabbixSender
from twisted.internet import reactor, defer

@defer.inlineCallbacks
def test():
# Creating a sender object
z = txZabbixSender(server="zabbix-server", port=10051)

# Adding data (without timestamp)
z.addData(hostname="test_host", key="test_trap_1", value="12")
z.addData("test_host", "test_trap_2", "2.43")

# Adding data (with timestamp)
z.addData("test_host", "test_trap_2", "2.43", 1365787627)

# Ready to send your data?
results = yield z.sendData() # NOTE an asynchronous call

# Check if everything was sent as expected
if not results[0][0]:
print "oops! Sending data has been failed"
elif results[0][1]['info']['processed'] != 3:
print "oops! Zabbix doesn't recognize passed identities"

# Clear internal data to start populating again
z.clearData()

# Wants to send a single data point right now?
yield z.sendSingle("test_host","test_trap","12") # NOTE an asynchronous call
```

The backward-compatible code looks mostly the same, except return value processing:

```python
from pyZabbixSender import pyZabbixSender

# Creating a sender object
z = pyZabbixSender(server="zabbix-server", port=10051)

Expand All @@ -35,8 +120,8 @@ z.clearData()
z.sendSingle("test_host","test_trap","12")
```

There are some more options, so take a look and discover how easy is to use it ;)

There are some more options, so take a look at the [wiki] page and discover how easy is to use it ;)

License
----
Expand All @@ -46,3 +131,4 @@ GNU GPLv2
[Zabbix]:http://www.zabbix.com/
[simplejson]:https://simplejson.readthedocs.org/en/latest/
[wiki]:https://github.com/kmomberg/pyZabbixSender/wiki
[Twisted]:https://twistedmatrix.com
1 change: 1 addition & 0 deletions pyZabbixSender/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from pyZabbixSender import pyZabbixSender
Loading