|
|
@ -134,13 +134,16 @@ from ansible.module_utils.urls import fetch_url, url_argument_spec
|
|
|
|
class icinga2_api:
|
|
|
|
class icinga2_api:
|
|
|
|
module = None
|
|
|
|
module = None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def __init__(self, module):
|
|
|
|
|
|
|
|
self.module = module
|
|
|
|
|
|
|
|
|
|
|
|
def call_url(self, path, data='', method='GET'):
|
|
|
|
def call_url(self, path, data='', method='GET'):
|
|
|
|
headers = {
|
|
|
|
headers = {
|
|
|
|
'Accept': 'application/json',
|
|
|
|
'Accept': 'application/json',
|
|
|
|
'X-HTTP-Method-Override': method,
|
|
|
|
'X-HTTP-Method-Override': method,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
url = self.module.params.get("url") + "/" + path
|
|
|
|
url = self.module.params.get("url") + "/" + path
|
|
|
|
rsp, info = fetch_url(module=self.module, url=url, data=data, headers=headers, method=method)
|
|
|
|
rsp, info = fetch_url(module=self.module, url=url, data=data, headers=headers, method=method, use_proxy=self.module.params['use_proxy'])
|
|
|
|
body = ''
|
|
|
|
body = ''
|
|
|
|
if rsp:
|
|
|
|
if rsp:
|
|
|
|
body = json.loads(rsp.read())
|
|
|
|
body = json.loads(rsp.read())
|
|
|
@ -248,8 +251,7 @@ def main():
|
|
|
|
variables = module.params["variables"]
|
|
|
|
variables = module.params["variables"]
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
icinga = icinga2_api()
|
|
|
|
icinga = icinga2_api(module=module)
|
|
|
|
icinga.module = module
|
|
|
|
|
|
|
|
icinga.check_connection()
|
|
|
|
icinga.check_connection()
|
|
|
|
except Exception as e:
|
|
|
|
except Exception as e:
|
|
|
|
module.fail_json(msg="unable to connect to Icinga. Exception message: %s" % (e))
|
|
|
|
module.fail_json(msg="unable to connect to Icinga. Exception message: %s" % (e))
|
|
|
|