Module: check_mk
Branch: master
Commit: d4e245fce7a4e703cc4883031396b36cdd086146
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=d4e245fce7a4e7…
Author: Andreas Boesl <ab(a)mathias-kettner.de>
Date: Fri Apr 28 10:44:49 2017 +0200
4473 FIX agent_hp_msa: HP MSA agent no longer throws ssl validation errors
Starting with python 2.7.9, strict ssl certificate checking was introduced.
This werk simply deactivates this check again.
Change-Id: Ica4f78cb4f2b7d4336cabe5db234f405e036ceb7
---
.werks/4473 | 11 +++++++++++
agents/special/agent_hp_msa | 35 +++++++++++++++++++----------------
2 files changed, 30 insertions(+), 16 deletions(-)
diff --git a/.werks/4473 b/.werks/4473
new file mode 100644
index 0000000..7971ba9
--- /dev/null
+++ b/.werks/4473
@@ -0,0 +1,11 @@
+Title: agent_hp_msa: HP MSA agent no longer throws ssl validation errors
+Level: 1
+Component: checks
+Compatible: compat
+Edition: cre
+Version: 1.5.0i1
+Date: 1493368821
+Class: fix
+
+Starting with python 2.7.9, strict ssl certificate checking was introduced.
+This werk simply deactivates this check again.
diff --git a/agents/special/agent_hp_msa b/agents/special/agent_hp_msa
index 0157c9c..ea073ab 100755
--- a/agents/special/agent_hp_msa
+++ b/agents/special/agent_hp_msa
@@ -25,7 +25,15 @@
# Boston, MA 02110-1301 USA.
-import getopt, sys, socket, urllib2, traceback, re, hashlib
+import getopt, sys, socket, traceback, re, hashlib
+
+import requests
+try:
+ from requests.packages.urllib3.exceptions import InsecureRequestWarning
+ requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
+except:
+ pass
+
def usage():
sys.stderr.write("""Check_MK HP MSA Agent
@@ -162,37 +170,31 @@ class HTMLObjectParser(HTMLParser):
parser = HTMLObjectParser()
+
+
try:
+ session = requests.Session()
# Login
login_hash = hashlib.md5()
login_hash.update("%s_%s" % (username, password))
login_url = "https://%s/v3/api/login/%s" % (host_address,
login_hash.hexdigest())
socket.setdefaulttimeout(opt_timeout)
- req = urllib2.Request(login_url)
- handle = urllib2.urlopen(req)
- contents = handle.read()
+ r = session.get(login_url, verify=False)
# Extract sessionKey
- session_key = re.match('.*"response">(.*?)<.*',
contents).groups()[0]
-
- headers = {
- 'User-agent': 'Check_MK agent_hp_msa',
- 'sessionKey': session_key,
- }
+ session_key = re.match('.*"response">(.*?)<.*',
r.text).groups()[0]
+ session.headers.update({"sessionKey": session_key,
+ "User-agent": "Check_MK agent_hp_msa"})
# Query objects
for element in api_get_objects:
show_url = "https://%s/v3/api/show/%s" % (host_address, element)
- req = urllib2.Request(show_url, None, headers)
- handle = urllib2.urlopen(req)
-
- contents = handle.read()
- parser.feed(contents)
+ parser.feed(session.get(show_url, verify=False).text)
# Output sections
for section, lines in sections.items():
print "<<<hp_msa_%s>>>" % section
- print "\n".join(lines)
+ print "\n".join(map(lambda x: x.encode("utf-8"), lines))
except Exception, e:
if opt_debug:
@@ -204,3 +206,4 @@ except Exception, e:
sys.stderr.write("Connection error: %s" % e)
sys.exit(1)
+