Module: check_mk
Branch: master
Commit: 2ddbccb3e9d49b124f3da169583620567bddef70
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=2ddbccb3e9d49b…
Author: Moritz Kiemer <mo(a)mathias-kettner.de>
Date: Mon Apr 1 14:31:01 2019 +0200
apache_status: refactor III
Change-Id: Icde1c8653de6335a1f2ee97a5a6b5877ffb37a3a
---
agents/plugins/apache_status | 47 ++++++++++++++++++++++----------------------
1 file changed, 24 insertions(+), 23 deletions(-)
diff --git a/agents/plugins/apache_status b/agents/plugins/apache_status
index 191e368..671d30a 100755
--- a/agents/plugins/apache_status
+++ b/agents/plugins/apache_status
@@ -133,6 +133,28 @@ def no_cert_verification():
return context
+def get_response(proto, address, portspec, page):
+ is_local = address in ("127.0.0.1", "[::1]",
"localhost")
+ url = '%s://%s%s/%s?auto' % (proto, address, portspec, page)
+ # Try to fetch the status page for each server
+ try:
+ request = urllib2.Request(url, headers={"Accept":
"text/plain"})
+ return urllib2.urlopen(request)
+ except urllib2.URLError, e:
+ if 'unknown protocol' in str(e):
+ # HACK: workaround misconfigurations where port 443 is used for
+ # serving non ssl secured http
+ url = 'http://%s%s/server-status?auto' % (address, portspec)
+ return urllib2.urlopen(url)
+ raise
+ except Exception, e:
+ if 'doesn\'t match' in str(e) and is_local:
+ # HACK: workaround if SSL port is found and localhost is using
+ # SSL connections but certificate does not match
+ return urllib2.urlopen(url, context=no_cert_verification())
+ raise
+
+
def main():
config = get_config()
servers = config["servers"]
@@ -148,31 +170,10 @@ def main():
for server in servers:
proto, address, port, page = _unpack_server(server)
portspec = ':%d' % port if port else ''
- is_local = address in ("127.0.0.1", "[::1]",
"localhost")
try:
- url = '%s://%s%s/%s?auto' % (proto, address, portspec, page)
- # Try to fetch the status page for each server
- try:
- request = urllib2.Request(url, headers={"Accept":
"text/plain"})
- fd = urllib2.urlopen(request)
- except urllib2.URLError, e:
- if 'unknown protocol' in str(e):
- # HACK: workaround misconfigurations where port 443 is used for
- # serving non ssl secured http
- url = 'http://%s%s/server-status?auto' % (address, portspec)
- fd = urllib2.urlopen(url)
- else:
- raise
- except Exception, e:
- if 'doesn\'t match' in str(e) and is_local:
- # HACK: workaround if SSL port is found and localhost is using
- # SSL connections but certificate does not match
- fd = urllib2.urlopen(url, context=no_cert_verification())
- else:
- raise
-
- for line in fd.read().split('\n'):
+ response = get_response(proto, address, portspec, page)
+ for line in response.read().split('\n'):
if not line.strip():
continue
if line.lstrip()[0] == '<':