Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions plugins/doc_fragments/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,13 @@ class ModuleDocFragment(object):
description: Whether to validate the SSL certificate of the Checkmk server.
default: true
type: bool
proxy_url:
description: The URL of your proxy server.
type: str
proxy_user:
description: The username to authenticate against your proxy server.
type: str
proxy_pass:
description: The password to authenticate against your proxy server.
type: str
"""
20 changes: 19 additions & 1 deletion plugins/module_utils/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
__metaclass__ = type

import json
from urllib.parse import urlparse

from ansible.module_utils.urls import fetch_url
from ansible_collections.checkmk.general.plugins.module_utils.types import RESULT
Expand All @@ -34,6 +35,9 @@ def __init__(self, module, logger=None):
site = self.params.get("site")
user = self.params.get("automation_user")
secret = self.params.get("automation_secret")
self.proxy_url = self.params.get("proxy_url")
self.proxy_user = self.params.get("proxy_user")
self.proxy_pass = self.params.get("proxy_pass")
self.url = "%s/%s/check_mk/api/1.0" % (server, site)
self.headers = {
"Accept": "application/json",
Expand Down Expand Up @@ -75,6 +79,19 @@ def _fetch(
# TODO: If the REST API at some point actually cancels requests
# properly, we can go back to the initial back-off mechanism.

if self.proxy_url:
proxy_uri = urlparse(self.proxy_url)
if self.proxy_user and self.proxy_pass:
proxy_uri = proxy_uri._replace(
netloc=f"{self.proxy_user}:{self.proxy_pass}@{proxy_uri.netloc}"
)

# Set up the proxy_env dictionary for fetch_url
proxy_env = {
"https": proxy_uri.geturl(),
"http": proxy_uri.geturl().replace("https", "http"),
}

num_of_retries = 1
timeout = 60
for i in range(num_of_retries):
Expand All @@ -84,7 +101,8 @@ def _fetch(
data=None if not data else self.module.jsonify(data),
headers=self.headers,
method=method,
use_proxy=None,
use_proxy=True,
proxy_env=proxy_env,
timeout=timeout,
)

Expand Down
13 changes: 13 additions & 0 deletions plugins/module_utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,19 @@ def base_argument_spec():
no_log=True,
fallback=(env_fallback, ["CHECKMK_VAR_AUTOMATION_SECRET"]),
),
proxy_url=dict(
type="str",
fallback=(env_fallback, ["CHECKMK_VAR_PROXY_URL"]),
),
proxy_user=dict(
type="str",
fallback=(env_fallback, ["CHECKMK_VAR_PROXY_USER"]),
),
proxy_pass=dict(
type="str",
no_log=True,
fallback=(env_fallback, ["CHECKMK_VAR_PROXY_PASS"]),
),
)


Expand Down
Loading