ZABBIX Forums  
  #61  
Old 24-02-2012, 13:17
Brazarabit Brazarabit is offline
Junior Member
 
Join Date: Feb 2012
Posts: 1
Default hi there

very interesting thank
Reply With Quote
  #62  
Old 24-02-2012, 15:43
mcmyst mcmyst is offline
Member
 
Join Date: Feb 2012
Location: France
Posts: 69
Default

Quote:
Originally Posted by mcmyst View Post
Hi,

Thank you for your job on this library !

I am discovering the functionnality of the zabbix API, I would like to be able to see all the details about an item, but I can't see how ?

I know how to list all items id about a particular host:
Code:
list_item = zapi.item.get({"filter":{"hostids":hostid}})
for item in list_item:
	if item['itemid'] == '26062':
		print item
Now that I have the item id, what is the way to describe it ?

Thank you.
I have reached to do it with:
Code:
list_item = zapi.item.get({"output": "extend","filter":{"hostids":hostid}})
Reply With Quote
  #63  
Old 30-03-2012, 14:04
Yello Yello is offline
Senior Member
 
Join Date: Apr 2011
Posts: 282
Default

Hi,
When do you plan to add 'item.exists' to the api library?


Regards,
David
Reply With Quote
  #64  
Old 30-03-2012, 15:38
gescheit gescheit is offline
Senior Member
 
Join Date: Jul 2007
Location: Russia, Moscow
Posts: 130
Default

Module (https://github.com/gescheit/scripts/tree/master/zabbix) translate all methods to zabbix server. So dont need any action in this module, then zabbix add new methods in API.
Reply With Quote
  #65  
Old 14-04-2012, 03:56
frankymryao frankymryao is offline
Member
 
Join Date: Oct 2011
Location: Shanghai
Posts: 51
Default

Hi my friend, I am working on the python library of zabbix as well. My library more focus on Class and abstract and relation between Class because of I need to communicate with our CMDB. Your core thought of decorator is merge into my library. A lot thanks to you! My library:http://baniu.me/2012/04/zabbix-api-v0-1/
Reply With Quote
  #66  
Old 18-04-2012, 19:14
mcmyst mcmyst is offline
Member
 
Join Date: Feb 2012
Location: France
Posts: 69
Default

Hello,

I am working on a program to synchronise our equipment/connection database with zabbix. I am using your library to do this in python.
I am facing a problem about encoding:

Code:
zabbix_api.ZabbixAPIException:(u'Error -32602:Invalid params.,
[ CHost::create ] Incorrect characters used for Hostname 
[ SWT_Ranc\xc3\x83\xc2\xa9_01 ] while sending {"params": 
[{"ip": IP_ADDR, "host": "SWT_Ranc\\u00c3\\u0083\\u00c2\\u00a9_01", 
"useip": 1, "port": 10050, "groups": [{"groupid": "130"}]}], "jsonrpc": "2.0", 
"method": "host.create", "auth": "52fadd077508d4170738ea71f9dd046e", "id": 2}', 
-32602)
Here is my code

Code:
host_name = host_tab_infos[1].decode('latin1')
host_name = host_name.replace(":","").replace(";","").replace(",","")
host_name = host_name.encode('utf-8')
zapi.host.create({"host": host_name,"ip": host_ip,"port": 10050,"useip": 1,"groups": [{"groupid": 6}]})
My database is encoded in latin1 and I am trying to encode it in utf-8 (the name should be SWT_Rancé_01).

Do you have an idea ?

Thank you

Last edited by mcmyst; 19-04-2012 at 07:15.
Reply With Quote
  #67  
Old 02-05-2012, 11:19
frankymryao frankymryao is offline
Member
 
Join Date: Oct 2011
Location: Shanghai
Posts: 51
Default

a little updated

create object(host, item and etc) dynamically:

def __getattr__(self, name):
if name not in self._zabbix_api_object_list:
raise ZabbixAPIException('No such API object: %s' % name)
if not self.__dict__.has_key(name):
self.__dict__[name] = ZabbixAPIObjectFactory(self, name)
return self.__dict__[name]
Reply With Quote
  #68  
Old 04-05-2012, 11:46
Yello Yello is offline
Senior Member
 
Join Date: Apr 2011
Posts: 282
Default

Quote:
Originally Posted by mcmyst View Post
Hello,

Here is my code

Code:
host_name = host_tab_infos[1].decode('latin1')
host_name = host_name.replace(":","").replace(";","").replace(",","")
host_name = host_name.encode('utf-8')
zapi.host.create({"host": host_name,"ip": host_ip,"port": 10050,"useip": 1,"groups": [{"groupid": 6}]})
Have you tried something like this:

host_name = unicode(host_tab_infos[1],"utf-8")

Regards,
David
Reply With Quote
  #69  
Old 14-05-2012, 11:47
mcmyst mcmyst is offline
Member
 
Join Date: Feb 2012
Location: France
Posts: 69
Default

Quote:
Originally Posted by Yello View Post
Have you tried something like this:

host_name = unicode(host_tab_infos[1],"utf-8")

Regards,
David
Yes I have already tried it.
In fact I think zabbix refuse a hostname with accent, it is not a problem of encoding...


Thank you
Reply With Quote
  #70  
Old 30-10-2012, 15:47
mcmyst mcmyst is offline
Member
 
Join Date: Feb 2012
Location: France
Posts: 69
Default

For people willing to manage IT service with this library, you need to modify the zabbix_api.py file as follow:
Code:
diff zabbix_api_final.py zabbix_api_original.py
128,129d127
<     service = None
<
157d154
<         self.service = ZabbixAPISubClass(self, dict({"prefix": "service"}, **kwargs))
And then, this should work:
Code:
print zapi.service.get({"output": "extend","serviceids":"1"})
[{u'status': u'0', u'showsla': u'1', u'name': u'SLA XXXXX', u'algorithm': u'1', u'triggerid': u'0', u'serviceid': u'1', u'sortorder': u'0', u'goodsla': u'99.9000'}]
Reply With Quote
Reply

Tags
api, python

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 03:25.