Module: check_mk
Branch: master
Commit: 269442c7eba2c57b710422d0e8830c8a94c095d4
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=269442c7eba2c5…
Author: Tom Baerwinkel <tb(a)mathias-kettner.de>
Date: Thu Jun 28 16:50:43 2018 +0200
check_http: separate the argument parsing for urls and certificates
Change-Id: I6441ac34ce312a19d45aafa2c71c93319ddd7dd6
---
checks/check_http | 139 ++++++++++++++++++++++++++++++++++++------------------
1 file changed, 92 insertions(+), 47 deletions(-)
diff --git a/checks/check_http b/checks/check_http
index 85d3232..d1b1fcf 100644
--- a/checks/check_http
+++ b/checks/check_http
@@ -24,52 +24,42 @@
# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
# Boston, MA 02110-1301 USA.
-def check_http_arguments(params):
- description, settings = params
- args = []
- if "verbose" in settings:
- args += [ "-v" ]
+def _is_certificate_check(settings):
+ return "cert_days" in settings
- if "vhost" in settings:
- args += [ "-H", settings["vhost"] ]
-
- if "virthost" in settings:
- vhost, omit_ip = settings["virthost"]
- args += [ "-H", vhost ]
- else:
- omit_ip = False
-
- if "uri" in settings:
- args += [ '-u', settings["uri"] ]
-
- if "port" in settings:
- args += [ '-p', settings["port"] ]
+def _get_family_and_address(settings):
# Use the address family of the monitored host by default
- address_family = settings.get("address_family")
- if address_family == None:
- address_family = is_ipv6_primary(host_name()) and "ipv6" or
"ipv4"
+ family = settings.get("address_family")
+ if family == None:
+ family = is_ipv6_primary(host_name()) and "ipv6" or "ipv4"
- if address_family == "ipv6":
- args.append("-6")
+ if family == "ipv6":
address = "$_HOSTADDRESS_6$"
else:
address = "$_HOSTADDRESS_4$"
- ssl = settings.get("ssl")
- if ssl in [ True, "auto" ]:
- args.append('--ssl')
- elif ssl:
- args.append('--ssl=%s' % ssl)
+ return family, address
+
+
+def _certificate_args(address_family, address, settings):
+ args = []
if "cert_host" in settings:
- omit_ip = True
if settings.get("sni"):
args += [ '-H', settings['cert_host'] ]
else:
- args += [ '-H', address ]
args += [ '-I', settings['cert_host'] ]
+ args += [ '-H', address ]
+ else:
+ args += [ "-I", address ]
+
+ if address_family == 'ipv6':
+ args += ['-6']
+
+ if "port" in settings:
+ args += [ '-p', settings["port"] ]
if "cert_days" in settings:
# legacy behavior
@@ -79,8 +69,49 @@ def check_http_arguments(params):
warn, crit = settings["cert_days"]
args += [ '-C', '%d,%d' % (warn, crit) ]
- if settings.get("sni"):
- args.append('--sni')
+ if "sni" in settings:
+ args += ['--sni']
+
+ return args
+
+
+def _url_args(address_family, address, settings):
+ def _omit_ip(settings):
+ if "virthost" in settings:
+ return settings["virthost"][1]
+ return False
+
+ args = []
+
+ if (not _omit_ip(settings)) and ("proxy" not in settings):
+ args += [ "-I", address ]
+ elif "proxy" in settings:
+ args += [ "-I", settings["proxy"] ]
+
+ if "vhost" in settings:
+ args += [ "-H", settings["vhost"] ]
+
+ if "virthost" in settings:
+ vhost = settings["virthost"][0]
+ args += [ "-H", vhost ]
+
+ if address_family == 'ipv6':
+ args += ['-6']
+
+ if "port" in settings:
+ args += [ '-p', settings["port"] ]
+
+ if "uri" in settings:
+ args += [ '-u', settings["uri"] ]
+
+ ssl = settings.get("ssl")
+ if ssl in [ True, "auto" ]:
+ args += ['--ssl']
+ elif ssl:
+ args += ['--ssl=%s' % ssl]
+
+ if "sni" in settings:
+ args += ['--sni']
if "response_time" in settings:
args += [ '-w', '%f' %
(settings["response_time"][0]/1000.0),
@@ -117,17 +148,17 @@ def check_http_arguments(params):
if "expect_regex" in settings:
if len(settings['expect_regex']) >= 4 and
settings['expect_regex'][3]:
- args += [ '-l' ]
+ args += ['-l']
if settings['expect_regex'][1]:
- args += [ '-R' ]
+ args += ['-R']
else:
- args += [ '-r' ]
- args += [ settings['expect_regex'][0] ]
+ args += ['-r']
+ args += [settings['expect_regex'][0])
if settings['expect_regex'][2]:
- args += [ '--invert-regex' ]
+ args += ['--invert-regex']
if settings.get("extended_perfdata"):
- args += [ '--extended-perfdata' ]
+ args += ['--extended-perfdata']
if "post_data" in settings:
data, content_type = settings["post_data"]
@@ -137,7 +168,7 @@ def check_http_arguments(params):
args += [ '-j', settings["method"] ]
if settings.get("no_body"):
- args += [ '--no-body' ]
+ args += ['--no-body']
if "page_size" in settings:
args += [ '-m', '%d:%d' % settings["page_size"] ]
@@ -145,18 +176,32 @@ def check_http_arguments(params):
if "max_age" in settings:
args += [ '-M', settings["max_age"] ]
+ # FIXME: This option is deprecated. According to the monitoring-plugins
+ # the "urlize" plugin should be used.
if settings.get("urlize"):
- args += [ '-L' ]
+ args += ['-L']
- if (not omit_ip) and ("proxy" not in settings):
- args = [ "-I", address ] + args
- elif "proxy" in settings:
- args = [ "-I", settings["proxy"] ] + args
+ if "verbose" in settings:
+ args += ["-v"]
+
+ return args
+
+
+def check_http_arguments(params):
+ description, settings = params
+ args = []
+
+ address_family, address = _get_family_and_address(settings)
+
+ if _is_certificate_check(settings):
+ args += _certificate_args(address_family, address, settings)
+ else:
+ args += _url_args(address_family, address, settings)
return args
-def check_http_desc(params):
+def check_http_description(params):
description, settings = params
if description.startswith("^"):
@@ -174,7 +219,7 @@ def check_http_desc(params):
active_check_info['http'] = {
"command_line" : '$USER1$/check_http $ARG1$',
"argument_function" : check_http_arguments,
- "service_description" : check_http_desc,
+ "service_description" : check_http_description,
"has_perfdata" : True,
}