Advertisement
Guest User

Untitled

a guest
Jun 3rd, 2017
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.25 KB | None | 0 0
  1. from zabbix.api import ZabbixAPI
  2. from zabbix.api import ZabbixAPIException
  3.  
  4. class ZabbixClient(ZabbixAPI):
  5.  
  6.     def __init__(self, url='http://localhost', use_authenticate=False, user='Admin', password='zabbix'):
  7.         self.url=url
  8.         self.use_authenticate=use_authenticate
  9.         super(ZabbixClient,self).__init__(url=self.url,use_authenticate=self.use_authenticate, user=user, password=password)
  10.  
  11.    
  12.     def delete_host(self, hostid):
  13.         try:
  14.             deleted=self.host.delete(hostid)
  15.         except ZabbixAPIException as ex: <---------- here i want to use the exception imported from the zabbix.api file
  16.             pass
  17.             return False
  18.         return deleted
  19.  
  20. $ python zbx-reg.py
  21. Traceback (most recent call last):
  22.   File "zbx-reg.py", line 12, in <module>
  23.     from zabbix.api import ZabbixAPIException
  24. ImportError: cannot import name ZabbixAPIException
  25. (venv) rojo@minishift:~/os-zbx$
  26. $ python
  27. Python 2.7.12 (default, Nov 19 2016, 06:48:10)
  28. [GCC 5.4.0 20160609] on linux2
  29. Type "help", "copyright", "credits" or "license" for more information.
  30. >>> import zabbix.api
  31. >>> dir (zabbix.api)
  32. ['ZabbixAPI', '__builtins__', '__doc__', '__file__', '__name__', '__package__', '__warningregistry__', 'warnings']
  33. >>>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement