Skip to content

Commit

Permalink
Merge pull request #2 from iLert/fix/encoding-issue
Browse files Browse the repository at this point in the history
fixes #1
  • Loading branch information
Birol Yildiz authored Jan 12, 2020
2 parents a194d7c + 301f0fe commit 2752dfc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/venv/
.idea
5 changes: 3 additions & 2 deletions ilert_nagios.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from xml.sax.saxutils import escape
from xml.sax.saxutils import quoteattr
import argparse
import io

PLUGIN_VERSION = "1.4"

Expand All @@ -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()
Expand Down Expand Up @@ -111,7 +112,7 @@ def create_xml(apikey, payload):
xml_doc += "<event><apiKey>%s</apiKey><payload>" % apikey

for entry in payload:
xml_doc += "<entry key=%s>%s</entry>" % (quoteattr(entry), escape(payload[entry]))
xml_doc += "<entry key=%s>%s</entry>" % (quoteattr(entry), unicode(escape(payload[entry]), encoding='utf-8', errors='ignore'))

# XML document end tag
xml_doc += "</payload></event>"
Expand Down

0 comments on commit 2752dfc

Please sign in to comment.