Module: check_mk
Branch: master
Commit: 8616eb5e9f5b224fb95518664ead1b029202beda
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=8616eb5e9f5b22…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Wed Sep 16 10:18:21 2015 +0200
Event Console: Fixed MIB upload with Python<2.7
---
mkeventd/web/plugins/wato/mkeventd.py | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/mkeventd/web/plugins/wato/mkeventd.py
b/mkeventd/web/plugins/wato/mkeventd.py
index 22e6ab6..1a94b35 100644
--- a/mkeventd/web/plugins/wato/mkeventd.py
+++ b/mkeventd/web/plugins/wato/mkeventd.py
@@ -2021,7 +2021,7 @@ def validate_and_compile_mib(mibname, content):
def upload_mib(filename, mimetype, content):
validate_mib_file_name(filename)
- if zipfile.is_zipfile(cStringIO.StringIO(content)):
+ if is_zipfile(cStringIO.StringIO(content)):
msg = process_uploaded_zip_file(filename, content)
else:
if mimetype == "application/tar" or
filename.lower().endswith(".gz") or
filename.lower().endswith(".tgz"):
@@ -2055,6 +2055,17 @@ def process_uploaded_zip_file(filename, content):
"<br><br>\nProcessed %d MIB files, skipped %d MIB files"
% (success, fail)
+# Used zipfile.is_zipfile(cStringIO.StringIO(content)) before, but this only
+# possible with python 2.7. zipfile is only supporting checking of files by
+# their path.
+def is_zipfile(fo):
+ try:
+ zipfile.ZipFile(fo)
+ return True
+ except zipfile.BadZipfile:
+ return False
+
+
def validate_mib_file_name(filename):
if filename.startswith(".") or "/" in filename:
raise Exception(_("Invalid filename"))