Module: check_mk
Branch: master
Commit: d6eb1f3eab9f1fdb461f3f127eae15428fc2fee3
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=d6eb1f3eab9f1f…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Wed Feb 20 19:34:53 2019 +0100
Cleaned up host_cookie_path handling a bit
Change-Id: I38cbc84093890c9af3327b9c7e45f6a966e52822
---
agents/special/agent_vsphere | 33 ++++++++++-----------------------
1 file changed, 10 insertions(+), 23 deletions(-)
diff --git a/agents/special/agent_vsphere b/agents/special/agent_vsphere
index f163f45..18f8a17 100755
--- a/agents/special/agent_vsphere
+++ b/agents/special/agent_vsphere
@@ -39,9 +39,10 @@ import socket
import sys
import time
from xml.dom import minidom # type: ignore
-
from dateutil import tz
+import cmk.utils.paths
+
class MKQueryServerException(Exception):
pass
@@ -333,10 +334,6 @@ telegram_list = {
'<ns1:path>vm</ns1:path><ns1:skip>false</ns1:skip></ns1:selectSet>'\
'</ns1:objectSet></ns1:specSet><ns1:options></ns1:options></ns1:RetrievePropertiesEx>',
- "logout":
- '<ns1:Logout xsi:type="ns1:LogoutRequestType">'\
- '<ns1:_this type="SessionManager">%(sessionManager)s</ns1:_this></ns1:Logout>',
-
"continuetoken":
'<ns1:ContinueRetrievePropertiesEx xsi:type="ns1:ContinueRetrievePropertiesExRequestType">'\
'<ns1:_this type="PropertyCollector">%(propertyCollector)s</ns1:_this><ns1:token>%(token)s</ns1:token></ns1:ContinueRetrievePropertiesEx>',
@@ -912,7 +909,7 @@ def get_pattern(pattern, line):
def delete_server_cookie():
- if host_cookie_path and os.path.exists(host_cookie_path):
+ if os.path.exists(host_cookie_path):
os.unlink(host_cookie_path)
@@ -1028,7 +1025,7 @@ def retrieve_systeminfo():
def login():
global server_cookie
- if host_cookie_path and os.path.exists(host_cookie_path):
+ if os.path.exists(host_cookie_path):
server_cookie = file(host_cookie_path, "r").read()
else:
payload = telegram_list["login"]
@@ -1040,7 +1037,10 @@ def login():
error = "Cannot login to vSphere Server. Login response is not 'OK'. Please check the credentials"
else:
server_cookie = reply_headers.get("Set-Cookie")
- if host_cookie_path and server_cookie:
+ if server_cookie:
+ if not os.path.exists(os.path.dirname(host_cookie_path)):
+ os.makedirs(os.path.dirname(host_cookie_path))
+
cookie_file = file(host_cookie_path, "w")
os.chmod(host_cookie_path, 0600)
cookie_file.write(server_cookie)
@@ -1289,19 +1289,10 @@ if tracefile:
tracefile.write("Tracefile %s Host address: %s\n" %
(datetime.datetime.now().strftime("%Y-%m-%d %H:%M"), host_address))
-host_cookie_path = None
last_cookie_access_time = None
server_cookie = None
server_handle = None
-
-# Cookie storage is only available in OMD setups
-if "OMD_SITE" in os.environ:
- cookie_path = os.path.expanduser("~/tmp/check_mk/agents/agent_vsphere")
-
- if not os.path.exists(cookie_path):
- os.makedirs(cookie_path)
-
- host_cookie_path = "%s/cookie.%s" % (cookie_path, host_address)
+host_cookie_path = "%s/agents/agent_vsphere/cookie.%s" % (cmk.utils.paths.tmp_dir, host_address)
connect_to_server()
retrieve_systeminfo()
@@ -1313,7 +1304,7 @@ if not systeminfo:
# The cookie access time is required to determine the agents check interval
# This is required later on by the performancecounters. Depending on the
# interval we need more or less real-time samples
-if host_cookie_path and os.path.exists(host_cookie_path):
+if os.path.exists(host_cookie_path):
last_cookie_access_time = os.stat(host_cookie_path).st_mtime
os.utime(host_cookie_path, None) # Touch the cookie file, whenever it is accessed
@@ -1806,10 +1797,6 @@ if not error:
section_systemtime()
- # We only logout in non OMD-setups
- if not host_cookie_path:
- query_server(telegram_list["logout"])
-
break
except MKQueryServerException, e:
# There was a problem during the query.
Module: check_mk
Branch: master
Commit: 80ea76313cce4b2e08ab8d839a110b98fd555ff6
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=80ea76313cce4b…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Wed Feb 20 20:07:50 2019 +0100
Refactored global error variable to exception handling
Change-Id: I511a0a139aa2273b4fb2c6907c5621d160d3d827
---
agents/special/agent_vsphere | 66 +++++++++++++++++++-------------------------
1 file changed, 29 insertions(+), 37 deletions(-)
diff --git a/agents/special/agent_vsphere b/agents/special/agent_vsphere
index d10883e..d2be352 100755
--- a/agents/special/agent_vsphere
+++ b/agents/special/agent_vsphere
@@ -45,6 +45,7 @@ from dateutil import tz
from pathlib2 import Path
import cmk.utils.paths
+from cmk.utils.exceptions import MKGeneralException
class MKQueryServerException(Exception):
@@ -992,7 +993,6 @@ def encode_url(text):
def connect_to_server():
# Initialize server connection
try:
- global server_handle
netloc = host_address + ":" + str(opt_port)
if opt_no_cert:
@@ -1010,12 +1010,12 @@ def connect_to_server():
sys.stderr.flush()
server_handle.connect()
+ return server_handle
except Exception, e:
if opt_debug:
raise
- global error
- error = "Cannot connect to vSphere Server. Please check the IP and SSL certificate (if applicable) "\
- "and try again. This error is not related to the login credentials. Error message: %r" % e
+ raise MKGeneralException("Cannot connect to vSphere Server. Please check the IP and SSL certificate (if applicable) "\
+ "and try again. This error is not related to the login credentials. Error message: %r" % e)
def retrieve_systeminfo():
@@ -1038,11 +1038,10 @@ def login():
query_server(payload, payload_params = {"username": encode_url(user),
"password": encode_url(secret)})
- # TODO: Refactor to exception
if "InvalidLogin" in reply_data:
- global error
- error = "Cannot login to vSphere Server. Login response is not 'OK'. Please check the credentials"
- return None
+ raise MKGeneralException(
+ "Cannot login to vSphere Server. Login response is not 'OK'. Please check the credentials"
+ )
server_cookie = reply_headers.get("Set-Cookie", "").decode("utf-8")
@@ -1183,9 +1182,6 @@ opt_vm_piggyname = "alias"
opt_spaces = "underscore"
opt_no_cert = False
-error = None
-error_exit = 1
-
host_address = None
user = None
secret = None
@@ -1242,6 +1238,8 @@ for o, a in opts:
usage()
sys.exit(0)
+error_exit = 0 if opt_agent else 1
+
# If the --pysphere option is set we use the legacy pysphere agent, though 50 times slower...
if opt_pysphere:
path_vsphere_pysphere = os.path.dirname(os.path.abspath(__file__))
@@ -1299,28 +1297,27 @@ if tracefile:
last_cookie_access_time = None
server_cookie = None
-server_handle = None
host_cookie_path = Path(
"%s/agents/agent_vsphere/cookie.%s" % (cmk.utils.paths.tmp_dir, host_address))
-connect_to_server()
-retrieve_systeminfo()
+try:
+ server_handle = connect_to_server()
+ retrieve_systeminfo()
-if not systeminfo:
- sys.stderr.write("Unable to get data from Web API" + "\n")
- sys.exit(1)
+ if not systeminfo:
+ sys.stderr.write("Unable to get data from Web API" + "\n")
+ sys.exit(1)
-# The cookie access time is required to determine the agents check interval
-# This is required later on by the performancecounters. Depending on the
-# interval we need more or less real-time samples
-# TODO: Decouple login secret and perfcounter timer
-if host_cookie_path.exists():
- last_cookie_access_time = host_cookie_path.stat().st_mtime
- os.utime(str(host_cookie_path), None) # Touch the cookie file, whenever it is accessed
+ # The cookie access time is required to determine the agents check interval
+ # This is required later on by the performancecounters. Depending on the
+ # interval we need more or less real-time samples
+ # TODO: Decouple login secret and perfcounter timer
+ if host_cookie_path.exists():
+ last_cookie_access_time = host_cookie_path.stat().st_mtime
+ os.utime(str(host_cookie_path), None) # Touch the cookie file, whenever it is accessed
-server_cookie = login()
+ server_cookie = login()
-if not error:
# If the data aquisition fails, e.g. invalid cookie we try another run
run_count = 0
while run_count < 2:
@@ -1819,16 +1816,11 @@ if not error:
except Exception, e:
if opt_debug:
raise
- error = "Error while processing received data"
-
-write_output(vsphere_output, opt_agent, host_address)
-
-if opt_agent:
- error_exit = 0
-
-if tracefile:
- tracefile.close()
+ raise MKGeneralException("Error while processing received data")
-if error:
- sys.stderr.write(error + "\n")
+except MKGeneralException as e:
+ sys.stderr.write("%s\n" % e)
sys.exit(error_exit)
+
+write_output(vsphere_output, opt_agent, host_address)
+sys.exit(0)
Module: check_mk
Branch: master
Commit: 831152369a7548432dacd80f7d219534b65c1454
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=831152369a7548…
Author: Sven Panne <sp(a)mathias-kettner.de>
Date: Thu Feb 21 08:12:56 2019 +0100
Improve linter script.
Change-Id: Ia8c26293171ccb1ec4538c93cb41895aebf0d002
---
scripts/run-cxx-linter | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/scripts/run-cxx-linter b/scripts/run-cxx-linter
index ef5ff68..4c76662 100755
--- a/scripts/run-cxx-linter
+++ b/scripts/run-cxx-linter
@@ -3,6 +3,13 @@ set -e
TARGET=$1
PATCHSET_REVISION=$2
+# To really compute *only* the files which need checking, we better make sure
+# that our project is up-to-date without any further changes first (i.e. target
+# "all-am"). Having an up-to-date project file before running a linter is a good
+# idea, too (i.e. target "compile_commands.json"). The latter target implies the
+# former, so we just do that.
+make compile_commands.json
+
# ATTENTION! Extremely cunning hack ahead! Find out which files have been
# changed in the current directory for the given commit. Transform those file
# names into --what-if=... options for make and do a dry run with them. This