Send logout to ZabbixAPI before exit (#58393)
This commit is contained in:
parent
a688d2ee39
commit
f6490422d9
1 changed files with 12 additions and 2 deletions
|
@ -157,6 +157,7 @@ class Proxy(object):
|
|||
def add_proxy(self, data):
|
||||
try:
|
||||
if self._module.check_mode:
|
||||
self._zapi.logout()
|
||||
self._module.exit_json(changed=True)
|
||||
|
||||
parameters = {}
|
||||
|
@ -165,24 +166,29 @@ class Proxy(object):
|
|||
parameters[item] = data[item]
|
||||
|
||||
proxy_ids_list = self._zapi.proxy.create(parameters)
|
||||
self._zapi.logout()
|
||||
self._module.exit_json(changed=True,
|
||||
result="Successfully added proxy %s (%s)" %
|
||||
(data['host'], data['status']))
|
||||
if len(proxy_ids_list) >= 1:
|
||||
return proxy_ids_list['proxyids'][0]
|
||||
except Exception as e:
|
||||
self._zapi.logout()
|
||||
self._module.fail_json(msg="Failed to create proxy %s: %s" %
|
||||
(data['host'], e))
|
||||
|
||||
def delete_proxy(self, proxy_id, proxy_name):
|
||||
try:
|
||||
if self._module.check_mode:
|
||||
self._zapi.logout()
|
||||
self._module.exit_json(changed=True)
|
||||
self._zapi.proxy.delete([proxy_id])
|
||||
self._zapi.logout()
|
||||
self._module.exit_json(changed=True,
|
||||
result="Successfully deleted" +
|
||||
" proxy %s" % proxy_name)
|
||||
result="Successfully deleted"
|
||||
+ " proxy %s" % proxy_name)
|
||||
except Exception as e:
|
||||
self._zapi.logout()
|
||||
self._module.fail_json(msg="Failed to delete proxy %s: %s" %
|
||||
(proxy_name, str(e)))
|
||||
|
||||
|
@ -204,6 +210,7 @@ class Proxy(object):
|
|||
def update_proxy(self, proxy_id, data):
|
||||
try:
|
||||
if self._module.check_mode:
|
||||
self._zapi.logout()
|
||||
self._module.exit_json(changed=True)
|
||||
parameters = {'proxyid': proxy_id}
|
||||
|
||||
|
@ -222,14 +229,17 @@ class Proxy(object):
|
|||
|
||||
if len(parameters) > 1:
|
||||
self._zapi.proxy.update(parameters)
|
||||
self._zapi.logout()
|
||||
self._module.exit_json(
|
||||
changed=True,
|
||||
result="Successfully updated proxy %s (%s)" %
|
||||
(data['host'], proxy_id)
|
||||
)
|
||||
else:
|
||||
self._zapi.logout()
|
||||
self._module.exit_json(changed=False)
|
||||
except Exception as e:
|
||||
self._zapi.logout()
|
||||
self._module.fail_json(msg="Failed to update proxy %s: %s" %
|
||||
(data['host'], e))
|
||||
|
||||
|
|
Loading…
Reference in a new issue