diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..929f160 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/venv/ +.idea \ No newline at end of file diff --git a/ilert_nagios.py b/ilert_nagios.py index 06e3e42..0ac58c1 100755 --- a/ilert_nagios.py +++ b/ilert_nagios.py @@ -17,6 +17,7 @@ from xml.sax.saxutils import escape from xml.sax.saxutils import quoteattr import argparse +import io PLUGIN_VERSION = "1.4" @@ -36,7 +37,7 @@ def persist_event(api_key, directory, payload): try: # atomic write using tmp file, see http://stackoverflow.com/questions/2333872 - with open(file_path_tmp, "w") as f: + with io.open(file_path_tmp, mode="w", encoding="utf-8") as f: f.write(xml_doc) # make sure all data is on disk f.flush() @@ -111,7 +112,7 @@ def create_xml(apikey, payload): xml_doc += "%s" % apikey for entry in payload: - xml_doc += "%s" % (quoteattr(entry), escape(payload[entry])) + xml_doc += "%s" % (quoteattr(entry), unicode(escape(payload[entry]), encoding='utf-8', errors='ignore')) # XML document end tag xml_doc += ""