Module: check_mk
Branch: master
Commit: a9dc506a197fa8707b98161453fedc9fe1612032
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=a9dc506a197fa8…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Thu Aug 4 09:53:25 2016 +0200
3756 FIX Bulk import: Fixed exception when host name contained special characters
---
.werks/3756 | 10 ++++++++++
ChangeLog | 1 +
web/htdocs/wato.py | 8 ++++----
3 files changed, 15 insertions(+), 4 deletions(-)
diff --git a/.werks/3756 b/.werks/3756
new file mode 100644
index 0000000..7b89307
--- /dev/null
+++ b/.werks/3756
@@ -0,0 +1,10 @@
+Title: Bulk import: Fixed exception when host name contained special characters
+Level: 1
+Component: wato
+Class: fix
+Compatible: compat
+State: unknown
+Version: 1.4.0i1
+Date: 1470297185
+
+
diff --git a/ChangeLog b/ChangeLog
index 7f8b44f..c0db3eb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -525,6 +525,7 @@
* 3735 FIX: Fixed wrong host search link in case of deleting site with hosts
assigned
* 3754 FIX: Cluster nodes are now correctly validated for invalid characters
* 3755 FIX: Preventing to insert non ASCII characters in host addresses now
+ * 3756 FIX: Bulk import: Fixed exception when host name contained special characters
Notifications:
* 3263 Notifications: allow users to restrict by their contact groups...
diff --git a/web/htdocs/wato.py b/web/htdocs/wato.py
index 432ea6f..b4366b0 100644
--- a/web/htdocs/wato.py
+++ b/web/htdocs/wato.py
@@ -3074,7 +3074,7 @@ class ModeBulkImport(WatoMode):
file_id = "%s-%d" % (config.user_id, int(time.time()))
f = create_user_file(self._file_path(), "w")
- f.write(content)
+ f.write(content.encode("utf-8"))
f.close()
# make selections available to next page
@@ -3185,15 +3185,15 @@ class ModeBulkImport(WatoMode):
for col_num, value in enumerate(row):
attribute = html.var("attribute_%d" % col_num)
if attribute == "host_name":
- if not re.match('^[a-zA-Z0-9-_.]+$', value):
- raise MKUserError(None, _("Invalid host name: %r. Only the
characters a-z, A-Z, "
- "0-9, _, . and - are allowed.") %
value)
+ Hostname().validate_value(value, "host")
host_name = value
+
elif attribute and attribute != "-":
if attribute in attributes:
raise MKUserError(None, _("The attribute \"%s\" is
assigned to multiple columns. "
"You can not populate one attribute
from multiple columns. "
"The column to attribute associations
need to be unique.") % attribute)
+
# FIXME: Couldn't we decode all attributes?
if attribute == "alias":
attributes[attribute] = value.decode("utf-8")