Module: check_mk
Branch: master
Commit: fb7adbe809779b38f8696b04da75bffbe94df57a
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=fb7adbe809779b…
Author: Andreas Boesl <ab(a)mathias-kettner.de>
Date: Wed Mar 27 12:51:18 2019 +0100
agent_hivemanger: now uses python requests for the communication
Change-Id: Ib0e0f2ac2157ce0de6b0d672b4f81bd3a557ce18
---
.werks/7252 | 11 +++++++++++
agents/special/agent_hivemanager | 23 ++++++++++++-----------
2 files changed, 23 insertions(+), 11 deletions(-)
diff --git a/.werks/7252 b/.werks/7252
new file mode 100644
index 0000000..3103e67
--- /dev/null
+++ b/.werks/7252
@@ -0,0 +1,11 @@
+Title: agent_hivemanger: now uses python requests for the communication
+Level: 1
+Component: checks
+Class: feature
+Compatible: compat
+Edition: cre
+State: unknown
+Version: 1.6.0i1
+Date: 1553590614
+
+
diff --git a/agents/special/agent_hivemanager b/agents/special/agent_hivemanager
index 5ffed14..c5bb839 100755
--- a/agents/special/agent_hivemanager
+++ b/agents/special/agent_hivemanager
@@ -27,7 +27,7 @@
import sys
import json
import base64
-import urllib2
+import requests
try:
ip = sys.argv[1]
@@ -38,20 +38,19 @@ except:
sys.exit(2)
-def get_url(address):
- request = urllib2.Request(address)
+def get_data(address):
base64string = base64.encodestring('%s:%s' % (user,
password)).replace('\n', '')
- request.add_header("Authorization", "Basic %s" % base64string)
- request.add_header("Content-Type", "application/json")
+ headers = {"Authorization": "Basic %s" % base64string,
"Content-Type": "application/json"}
try:
- return urllib2.urlopen(request)
- except urllib2.HTTPError, e:
- print e
+ return requests.get(address, headers=headers).text
+ except Exception, e:
+ sys.stderr.write("Connection error: %s" % e)
sys.exit(2)
-print "<<<hivemanager_devices:sep(124)>>>"
-url = "https://%s/hm/api/v1/devices" % ip
+address = "https://%s/hm/api/v1/devices" % ip
+data = get_data(address)
+
informations = [
'hostName',
'clients',
@@ -68,7 +67,9 @@ informations = [
'location',
'networkPolicy',
]
-for line in json.loads(get_url(url).read()):
+
+print "<<<hivemanager_devices:sep(124)>>>"
+for line in json.loads(data):
if line['upTime'] == '':
line['upTime'] = "down"
print "|".join(map(str, ["%s::%s" % (x, y) for x, y in
line.items() if x in informations]))