Skip to content

Make package installable #9

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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
include README.md
recursive-include zabbixAPI/examples *.py
41 changes: 41 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
Zabbix
######

This is an implementation of the Zabbix API in Python.
Please note that the Zabbix API is still in a draft state,
and subject to change.

Implementations of the Zabbix API in other languages may
be found on the wiki.

Zabbix 1.8 and 2.0 are supported.

Documentation
-------------

* http://www.zabbix.com/wiki/doc/api
* http://www.zabbix.com/documentation/2.0/manual/appendix/api/api
* http://www.zabbix.com/forum/showthread.php?t=15218

License
-------

`LGPL 2.1 <http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html>`

Zabbix API Python Library.

Original Ruby Library is Copyright (C) 2009 Andrew Nelson nelsonab(at)red-tux(dot)net

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
43 changes: 43 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/python2
# -*- coding: utf-8 -*-

"""
ZabbixAPI

This software is licensed as described in the README.md file, which you should
have received as part of this distribution.
"""
import os
from setuptools import setup, find_packages, findall


def read(fname):
return open(os.path.join(os.path.dirname(__file__), fname)).read()

setup(
name='zabbixAPI',
url='https://github.com/ricco386/zabbixAPI',
version='0.1',
license='GNU LGPL 2.1',
author='Aleksandr Balezin',
author_email='gescheit@list.ru',
description='Zabbix API',
long_description=read('README.md'),
keywords="zabbix api monitoring",
py_modules=['zabbixAPI'],
packages=['zabbixAPI'],
platforms='any',
classifiers = [
"Programming Language :: Python",
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 3",
"License :: OSI Approved :: GNU Library or Lesser General Public \
License (LGPL)",
"Operating System :: OS Independent",
"Development Status :: 4 - Beta",
"Natural Language :: English",
"Topic :: System :: Monitoring",
"Topic :: System :: Networking :: Monitoring",
"Topic :: System :: Systems Administration",
]
)
13 changes: 0 additions & 13 deletions zabbix/README

This file was deleted.

28 changes: 0 additions & 28 deletions zabbix/setup.py

This file was deleted.

Empty file added zabbixAPI/__init__.py
Empty file.
Empty file added zabbixAPI/examples/__init__.py
Empty file.
66 changes: 66 additions & 0 deletions zabbixAPI/examples/zabbix_add_group_host.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
"""Example script that do an API call to create a sample test data on Zabbix
server.
When you run this script it will create for you a test group, test host.
For all newly created items in zabbix minimal data required has been used.

You have to define connection parameters in this script in order to run it.
Script was tested on zabbix API 1.4 which is part of Zabbix 2.0.0 or higher.

@author: richard.kellner
@created: 27.10.2012
"""
from zabbix_api import ZabbixAPI

"""You need to specify connection variables"""
server="http://127.0.0.1"
username="api"
password="apipass"

def create_group(group):
"""Function that will create host group on Zabbix Server."""
result = zapi.hostgroup.create({ 'name' : group })
try:
result['groupids']
except NameError:
"""API throws an exception if such group already exists"""
print 'There was na error while creating group'

print 'Group "'+ group +'" has been created with id: '+ \
result['groupids'][0]
return result['groupids'][0]

def create_host(host):
"""Function that will create host on Zabbix Server."""
result = zapi.host.create({ "host" : (host),
"interfaces" : [{
"type": 1,
"main": 1,
"useip" : 1,
"ip" : "127.0.0.1",
"dns" : "",
"port" : "10050",
}],
"groups" : [{
"groupid" : groupid,
}],
})
try:
result['hostids']
except NameError:
"""API throws an exception if such host already exists"""
print 'There was na error while creating host'
print 'Host "'+ host +'" has been created with id: '+ \
result['hostids'][0]
return result['hostids'][0]

def test_API_version():
"""Method to check if server has compatible version of API."""
if zapi.api_version() <= 1.4:
raise Exception('Example script works only with API 1.4 or higher.')

zapi = ZabbixAPI(server=server, path="", log_level=30)
zapi.login(username, password)

test_API_version()
groupid = create_group('test_API_group')
hostid = create_host('test_API_host')
25 changes: 25 additions & 0 deletions zabbixAPI/examples/zabbix_test_connection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"""Example script that do an API connection to Zabbix server and print API
version.

You have to define connection parameters in this script in order to run it.

@author: richard.kellner
@created: 28.10.2012
"""
import sys
from zabbix_api import ZabbixAPI, ZabbixAPIException

"""You need to specify connection variables"""
server="http://127.0.0.1"
username="api"
password="apipass"

zapi = ZabbixAPI(server=server, path="", log_level=30)
zapi.login(username, password)

try:
zapi.login(username, password)
print "Logged in: %s" % str(zapi.test_login())
print "Zabbix API Version: %s" % zapi.api_version()
except ZabbixAPIException, e:
sys.stderr.write(str(e) + '\n')
File renamed without changes.
8 changes: 6 additions & 2 deletions zabbix/zabbix_rpc_test.py → zabbixAPI/zabbix_rpc_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/python
import optparse
import sys
import traceback
from getpass import getpass
from zabbix_api import ZabbixAPI, ZabbixAPIException

Expand All @@ -18,6 +17,8 @@ def get_options():
dest="username", help="Username (Will prompt if not given)")
parser.add_option("-p", "--password", action="store", type="string", \
dest="password", help="Password (Will prompt if not given)")
parser.add_option("-l", "--log_level", action="store", type="int", \
dest="log_level", help="Log Level (Default value 30)")

options, args = parser.parse_args()

Expand All @@ -34,6 +35,9 @@ def get_options():
if not options.username and not options.password:
show_help(parser)

if not options.log_level:
options.log_level = 30

return options, args

def show_help(p):
Expand All @@ -48,7 +52,7 @@ def errmsg(msg):
if __name__ == "__main__":
options, args = get_options()

zapi = ZabbixAPI(server=options.server,log_level=3)
zapi = ZabbixAPI(server=options.server,log_level=options.log_level)

try:
zapi.login(options.username, options.password)
Expand Down