Module: check_mk
Branch: master
Commit: 071d511a89c478b5cacd7c505c769ce147280eed
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=071d511a89c478…
Author: Simon Betz <si(a)mathias-kettner.de>
Date: Mon Jul 30 12:17:44 2018 +0200
Give some variables a more significant name
Change-Id: I3ce26b04f6d6897b0a6e587d9ed8eb2752169ec1
---
cmk_base/piggyback.py | 69 ++++++++++++++++++++++++++-------------------------
1 file changed, 35 insertions(+), 34 deletions(-)
diff --git a/cmk_base/piggyback.py b/cmk_base/piggyback.py
index faac4df..1ab48c9 100644
--- a/cmk_base/piggyback.py
+++ b/cmk_base/piggyback.py
@@ -40,9 +40,9 @@ def get_piggyback_raw_data(piggyback_max_cachefile_age, hostname):
if not hostname:
return output
- for sourcehost, file_path in _get_piggyback_files(piggyback_max_cachefile_age,
hostname):
- console.verbose("Using piggyback raw data from host %s.\n" %
sourcehost)
- output += file(file_path).read()
+ for source_host, piggyback_file_path in
_get_piggyback_files(piggyback_max_cachefile_age, hostname):
+ console.verbose("Using piggyback raw data from host %s.\n" %
source_host)
+ output += file(piggyback_file_path).read()
return output
@@ -74,51 +74,51 @@ def _get_piggyback_files(piggyback_max_cachefile_age, hostname):
else:
raise
- for sourcehost in source_host_names:
- if sourcehost.startswith("."):
+ for source_host in source_host_names:
+ if source_host.startswith("."):
continue
- file_path = os.path.join(piggyback_dir, sourcehost)
+ piggyback_file_path = os.path.join(piggyback_dir, source_host)
try:
- file_age = cmk_base.utils.cachefile_age(file_path)
+ file_age = cmk_base.utils.cachefile_age(piggyback_file_path)
except MKGeneralException, e:
continue # File might've been deleted. That's ok.
# Skip piggyback files that are outdated at all
if file_age > piggyback_max_cachefile_age:
console.verbose("Piggyback file %s is outdated (%d seconds too old).
Skip processing.\n" %
- (file_path, file_age - piggyback_max_cachefile_age))
+ (piggyback_file_path, file_age - piggyback_max_cachefile_age))
continue
# Skip piggyback files that have not been updated in the last contact
# with the source host that is currently being handled.
try:
- source_update_age = _piggyback_source_host_update_age(sourcehost)
+ source_update_age = _piggyback_source_host_update_age(source_host)
except MKGeneralException, e:
- console.verbose("Piggyback file %s is outdated (Source not sending
piggyback). Skip processing.\n" % file_path)
+ console.verbose("Piggyback file %s is outdated (Source not sending
piggyback). Skip processing.\n" % piggyback_file_path)
continue # No source_status_file exists -> ignore data from this source
if file_age > source_update_age:
- console.verbose("Piggyback file %s is outdated (Not updated by source).
Skip processing.\n" % file_path)
+ console.verbose("Piggyback file %s is outdated (Not updated by source).
Skip processing.\n" % piggyback_file_path)
continue
- files.append((sourcehost, file_path))
+ files.append((source_host, piggyback_file_path))
return files
-def _piggyback_source_status_path(sourcehost):
- return os.path.join(cmk.paths.tmp_dir, "piggyback_sources", sourcehost)
+def _piggyback_source_status_path(source_host):
+ return os.path.join(cmk.paths.tmp_dir, "piggyback_sources", source_host)
-def _piggyback_source_host_update_age(sourcehost):
- return cmk_base.utils.cachefile_age(_piggyback_source_status_path(sourcehost))
+def _piggyback_source_host_update_age(source_host):
+ return cmk_base.utils.cachefile_age(_piggyback_source_status_path(source_host))
-def _remove_piggyback_file(file_path):
+def _remove_piggyback_file(piggyback_file_path):
try:
- os.remove(file_path)
+ os.remove(piggyback_file_path)
return True
except OSError, e:
if e.errno == 2: # No such file or directory
@@ -127,27 +127,27 @@ def _remove_piggyback_file(file_path):
raise
-def remove_source_status_file(sourcehost):
+def remove_source_status_file(source_host):
"""Remove the source_status_file of this piggyback host which will
mark the piggyback data from this source as outdated."""
- source_status_path = _piggyback_source_status_path(sourcehost)
+ source_status_path = _piggyback_source_status_path(source_host)
return _remove_piggyback_file(source_status_path)
-def store_piggyback_raw_data(sourcehost, piggybacked_raw_data):
+def store_piggyback_raw_data(source_host, piggybacked_raw_data):
for backedhost, lines in piggybacked_raw_data.items():
console.verbose("Storing piggyback data for: %s\n" % backedhost)
content = "\n".join(lines) + "\n"
- store.save_file(os.path.join(cmk.paths.tmp_dir, "piggyback",
backedhost, sourcehost), content)
+ store.save_file(os.path.join(cmk.paths.tmp_dir, "piggyback",
backedhost, source_host), content)
# Store the last contact with this piggyback source to be able to filter outdated
data later
# We use the mtime of this file later for comparision.
# Only do this for hosts that sent piggyback data this turn, cleanup the status file
when no
# piggyback data was sent this turn.
if piggybacked_raw_data:
- store.save_file(_piggyback_source_status_path(sourcehost), "")
+ store.save_file(_piggyback_source_status_path(source_host), "")
else:
- remove_source_status_file(sourcehost)
+ remove_source_status_file(source_host)
def cleanup_piggyback_files(piggyback_max_cachefile_age):
@@ -177,16 +177,17 @@ def _cleanup_old_source_status_files(piggyback_max_cachefile_age):
if entry[0] == ".":
continue
- file_path = os.path.join(base_dir, entry)
+ piggyback_file_path = os.path.join(base_dir, entry)
try:
- file_age = cmk_base.utils.cachefile_age(file_path)
+ file_age = cmk_base.utils.cachefile_age(piggyback_file_path)
except MKGeneralException, e:
continue # File might've been deleted. That's ok.
if file_age > piggyback_max_cachefile_age:
- console.verbose("Removing outdated piggyback source status file
%s\n" % file_path)
- _remove_piggyback_file(file_path)
+ console.verbose("Removing outdated piggyback source status file
%s\n" % piggyback_file_path)
+ _remove_piggyback_file(piggyback_file_path)
+
def _cleanup_old_piggybacked_files(piggyback_max_cachefile_age):
"""Remove piggyback data that is not needed anymore
@@ -211,12 +212,12 @@ def _cleanup_old_piggybacked_files(piggyback_max_cachefile_age):
if source_host_name[0] == ".":
continue
- file_path = os.path.join(backed_host_dir_path, source_host_name)
+ piggyback_file_path = os.path.join(backed_host_dir_path, source_host_name)
- delete_reason = _shall_cleanup_piggyback_file(piggyback_max_cachefile_age,
file_path, source_host_name, keep_sources)
+ delete_reason = _shall_cleanup_piggyback_file(piggyback_max_cachefile_age,
piggyback_file_path, source_host_name, keep_sources)
if delete_reason:
- console.verbose("Removing outdated piggyback file (%s) %s\n" %
(delete_reason, file_path))
- _remove_piggyback_file(file_path)
+ console.verbose("Removing outdated piggyback file (%s) %s\n" %
(delete_reason, piggyback_file_path))
+ _remove_piggyback_file(piggyback_file_path)
# Remove empty backed host directory
try:
@@ -228,12 +229,12 @@ def _cleanup_old_piggybacked_files(piggyback_max_cachefile_age):
raise
-def _shall_cleanup_piggyback_file(piggyback_max_cachefile_age, file_path,
source_host_name, keep_sources):
+def _shall_cleanup_piggyback_file(piggyback_max_cachefile_age, piggyback_file_path,
source_host_name, keep_sources):
if source_host_name not in keep_sources:
return "Source not sending piggyback data"
try:
- file_age = cmk_base.utils.cachefile_age(file_path)
+ file_age = cmk_base.utils.cachefile_age(piggyback_file_path)
except MKGeneralException, e:
return None # File might've been deleted. That's ok.