Module: check_mk
Branch: master
Commit: c40a74053b54934630078c86189ba78da4e80e14
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=c40a74053b5493…
Author: Moritz Kiemer <mo(a)mathias-kettner.de>
Date: Tue Mar 26 13:53:54 2019 +0100
7384 check_http: Improve WATO rule
The WATO rule to configure the active check 'check_http' now provides a more
user friendly way to configure proxy settings.
Change-Id: I43b4c50759e786db96059eb8ba343dce5fbee91a
---
.werks/7384 | 11 ++++++
checks/check_http | 28 ++++++++------
cmk/gui/plugins/wato/active_checks.py | 70 +++++++++++++++--------------------
3 files changed, 58 insertions(+), 51 deletions(-)
diff --git a/.werks/7384 b/.werks/7384
new file mode 100644
index 0000000..6f76afd
--- /dev/null
+++ b/.werks/7384
@@ -0,0 +1,11 @@
+Title: check_http: Improve WATO rule
+Level: 1
+Component: checks
+Compatible: compat
+Edition: cre
+Version: 1.6.0i1
+Date: 1553667609
+Class: feature
+
+The WATO rule to configure the active check 'check_http' now provides a more
+user friendly way to configure proxy settings.
diff --git a/checks/check_http b/checks/check_http
index 933deb3..f5d26a8 100644
--- a/checks/check_http
+++ b/checks/check_http
@@ -30,7 +30,19 @@ def _transform_check_http(params):
return params
name, mode = params
mode_name = 'cert' if "cert_days" in mode else 'url'
- return {"name": name, "mode": (mode_name, mode)}
+
+ transformed = {"name": name, "mode": (mode_name, mode)}
+ # The proxy option has ben isolated in version 1.6.0i1
+ proxy_address = mode.get("proxy")
+ if proxy_address:
+ proxy = transformed.setdefault("proxy", {"address":
proxy_address})
+ # ':' outside a IPv6 address indicates port
+ if ':' in proxy_address.split(']')[-1]:
+ proxy["address"], proxy["port"] =
proxy_address.rsplit(':', 1)
+ if "proxy_auth" in mode:
+ proxy["auth"] = mode["proxy_auth"]
+
+ return transformed
def _get_family_and_address(settings):
@@ -53,18 +65,12 @@ def _get_proxy(params):
if not proxy:
return None
- # ':' outside a IPv6 address indicates port
- if ':' in proxy.split(']')[-1]:
- address, port = proxy.rsplit(':', 1)
- else:
- address, port = proxy, None
-
- auth = params.get("proxy_auth")
+ auth = proxy.get("auth")
if auth:
auth = passwordstore_get_cmdline("%s:%%s" % auth[0], auth[1])
- proset = collections.namedtuple("ProxySettings", ("address",
"port", "auth"))
- return proset(address, port, auth)
+ ProxySettings = collections.namedtuple("ProxySettings",
("address", "port", "auth"))
+ return ProxySettings(proxy.get("address"), proxy.get("port"),
auth)
def _certificate_args(address_family, address, proxy, settings):
@@ -222,7 +228,7 @@ def check_http_arguments(params):
mode_name, settings = params["mode"]
address_family, address = _get_family_and_address(settings)
- proxy = _get_proxy(settings)
+ proxy = _get_proxy(params)
if mode_name == 'cert':
return _certificate_args(address_family, address, proxy, settings)
diff --git a/cmk/gui/plugins/wato/active_checks.py
b/cmk/gui/plugins/wato/active_checks.py
index 48d5c22..d664b4b 100644
--- a/cmk/gui/plugins/wato/active_checks.py
+++ b/cmk/gui/plugins/wato/active_checks.py
@@ -966,6 +966,22 @@ class RulespecActiveChecksHttp(HostRulespec):
def _portspec(self, default):
return Integer(title=_("TCP Port"), minvalue=1, maxvalue=65535,
default_value=default)
+ def _proxyspec(self):
+ return Dictionary(
+ title=_("Use proxy"),
+ elements=[
+ ("address", TextAscii(title=_("Proxy server
address"))),
+ ("port", self._portspec(80)),
+ ("auth",
+ Tuple(
+ title=_("Proxy basic authorization"),
+ elements=[
+ TextAscii(title=_("Username"), size=12,
allow_empty=False),
+ IndividualOrStoredPassword(title=_("Password"),),
+ ])),
+ ],
+ required_keys=["address"])
+
@property
def valuespec(self):
return Transform(
@@ -986,6 +1002,7 @@ class RulespecActiveChecksHttp(HostRulespec):
"a caret (<tt>^</tt>), the service
description will not be prefixed with either "
"<tt>HTTP</tt> or
<tt>HTTPS</tt>."),
allow_empty=False)),
+ ("proxy", self._proxyspec()),
("mode",
CascadingDropdown(
title=_("Mode of the Check"),
@@ -1096,27 +1113,6 @@ class RulespecActiveChecksHttp(HostRulespec):
IndividualOrStoredPassword(title=_("Password"),)
])),
(
- "proxy",
- TextAscii(
- title=_("Proxy host"),
- help=_(
- "To use a proxy you have to use
the Port of the proxy, "
- "specify the virtual host and the
URL to fetch, "
- "use the HTTP Method CONNECT, and
use SSL/HTTPS "
- "for the connection")),
- ),
- ("proxy_auth",
- Tuple(
- title=_("Proxy-Authorization"),
- help=_(
- "Credentials for HTTP Proxy with
basic authentication"
- ),
- elements=[
- TextAscii(
- title=_("Username"),
size=12, allow_empty=False),
-
IndividualOrStoredPassword(title=_("Password"),),
- ])),
- (
"onredirect",
DropdownChoice(
title=_("How to handle
redirect"),
@@ -1296,25 +1292,6 @@ class RulespecActiveChecksHttp(HostRulespec):
),
),
),
- (
- "proxy",
- TextAscii(
- title=_("Proxy host"),
- help=
- _("To use a proxy you have to specify
the Port of the proxy. "
- )),
- ),
- ("proxy_auth",
- Tuple(
- title=_("Proxy-Authorization"),
- help=_(
- "Credentials for HTTP Proxy with
basic authentication"
- ),
- elements=[
- TextAscii(
- title=_("Username"),
size=12, allow_empty=False),
-
IndividualOrStoredPassword(title=_("Password"),),
- ])),
],
required_keys=["cert_days"],
)),
@@ -1336,6 +1313,19 @@ class RulespecActiveChecksHttp(HostRulespec):
mode_name = 'cert' if "cert_days" in mode else 'url'
+ transformed = {"name": params[0], "mode": (mode_name, mode)}
+
+ # The proxy option has been isolated in version 1.6.0i1
+ proxy_address = mode.pop("proxy", None)
+ if proxy_address:
+ proxy = transformed.setdefault("proxy", {"address":
proxy_address})
+ # ':' outside a IPv6 address indicates port
+ if ':' in proxy_address.split(']')[-1]:
+ proxy["address"], proxy["port"] =
proxy_address.rsplit(':', 1)
+ auth = mode.pop("proxy_auth", None)
+ if auth:
+ proxy["auth"] = auth
+
return {"name": name, "mode": (mode_name, mode)}