frankyaorenjie / zabbixpythonapi Goto Github PK
View Code? Open in Web Editor NEWZabbix API for python
Zabbix API for python
如果python环境是2.6的话,会出现下面的提示
zapi.py:29: DeprecationWarning: object.__new__() takes no parameters
cls._state[cls] = super(ZabbixAPI, cls).__new__(cls, *args, **kw)
然后会出现lastclock不按预期结果的问题,好多都是0
我的main方法如下:
if __name__ == "__main__":
hostMap = {
"12077":"test1",
"12078":"test2",
}
zapi = ZabbixAPI(url='', user='', password='‘)
if not zapi.is_login():
zapi.login()
itemData= zapi.Item.get(
{
"output": "extend",
"hostids": hostMap.keys(),
"webitems":True,
"search": {
"key_": "web.test.error"
},
}
)
for i in itemData:
print i
python2.7的话一切正常 :)
不是重要的问题,仅反馈一下
==========================分割线===============================
好像事情没那么简单,可能是我那台虚拟机的问题 😢
Zabbix 2.4
ZabbixAPI Err: The "user.login" method must be called without the "auth" parameter
def json_obj(self, method, params):
obj = { 'jsonrpc' : '2.0',
'method' : method,
'params' : params,
'id' : self.__id}
##### Zabbix 2.4 #####
if self.isLogin():
obj['auth'] = self.__auth
######################
return json.dumps(obj)
I use 2to3 to convert,but it not works.
So,please write a python3 version :)
The example of use in the README.md doesn't work.
from zapi import ZabbixAPI
ZAPI = ZabbixAPI(url='http://localhost/zabbix', user=UNAME, password=PWORD)
ZAPI.login()
Traceback (most recent call last):
File "zapi_example.py", line 8, in <module>
ZAPI.login()
File "./zapi.py", line 50, in login
raise ZabbixAPIException(e)
zapi.ZabbixAPIException: The "user.login" method must be called without the "auth" parameter.
I'm not passing any parameters to the .login() method.
我想调试这段代码,其中graphid:49931,hostids[16913,17411]这些指的是啥。?
# python -c "from zabbix.zapi import *;zapi=ZabbixAPI(url='http://your.zabbix.address', user='admin', password='zabbix')"
/usr/lib/python2.6/site-packages/zabbix/zapi.py:25: DeprecationWarning: object.__new__() takes no parameters
cls._state[cls] = super(ZabbixAPI, cls).__new__(cls, *args, **kw)
OS: CentOS 6.4 X86_64
Python: 2.6.6
Using zapi.alert.get({'output': 'extend', 'limit': 1}), I get the following:
HttpError: 500 Server Error: Internal server Error...
What could I be doing wrong or is there a bug?
This is a follow-up to #5 which I can't reopen.
The example in README.md still does not work.
zapi.host.get({'hostids':[hostid],'output':'extend'})
Traceback (most recent call last):
File "zapi_example.py", line 18, in <module>
zapi.host.get({'hostids':[hostid],'output':'extend'})
File "/root/zabbix_api/zapi.py", line 43, in __getattr__
raise ZabbixAPIException('No such API object: %s' % name)
zapi.ZabbixAPIException: No such API object: host
print zapi.getHostByHostid(hostid)
Traceback (most recent call last):
File "zapi_example.py", line 20, in <module>
print zapi.getHostByHostid(hostid)
File "/root/zabbix_api/zapi.py", line 43, in __getattr__
raise ZabbixAPIException('No such API object: %s' % name)
zapi.ZabbixAPIException: No such API object: getHostByHostid
Using Python 2.7.6 and Zabbix 2.4.5
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.