mpounsett / nagiosplugin

A Python class library which helps with writing Nagios (Icinga) compatible plugins.
https://nagiosplugin.readthedocs.io/
Other
28 stars 14 forks source link

UTF-8 output broken #12

Closed mpounsett closed 9 years ago

mpounsett commented 9 years ago

Original report by Christian Kauhaus (Bitbucket: ckauhaus, GitHub: ckauhaus).


Using umlauts in various output-related strings causes UnicodeDecodeErrors.

For example, using a ScalarContext like this:

nagiosplugin.ScalarContext(
  'cert_expiration_days',
  fmt_metric="Zeritifikat läuft in {value} Tagen ab."
)

results in

Traceback (most recent call last):
  File "C:\Python27\lib\threading.py", line 810, in __bootstrap_inner
    self.run()
  File "C:\Python27\lib\threading.py", line 763, in run
    self.__target(*self.__args, **self.__kwargs)
  File "C:\Python27\lib\site-packages\nagiosplugin\runtime.py", line 108, in run
    self.output.add(check)
  File "C:\Python27\lib\site-packages\nagiosplugin\output.py", line 27, in add
    self.status = self.format_status(check)
  File "C:\Python27\lib\site-packages\nagiosplugin\output.py", line 41, in format_status
    summary_str = check.summary_str.strip()
  File "C:\Python27\lib\site-packages\nagiosplugin\check.py", line 143, in summary_str
    return self.summary.problem(self.results) or ''
  File "C:\Python27\lib\site-packages\nagiosplugin\summary.py", line 51, in problem
    return str(results.first_significant)
  File "C:\Python27\lib\site-packages\nagiosplugin\result.py", line 57, in __str__
    return '{0} ({1})'.format(desc, self.hint)
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe4' in position 13: ordinal not in range(128)

Same problem on Linux machines.

mpounsett commented 9 years ago

Original comment by Christian Kauhaus (Bitbucket: ckauhaus, GitHub: ckauhaus).


Clarify UTF-8 test

Re #12

mpounsett commented 9 years ago

Original comment by Christian Kauhaus (Bitbucket: ckauhaus, GitHub: ckauhaus).


Fix handling of non-ASCII characters on Python 2.7

Re #12

mpounsett commented 9 years ago

Original comment by Christian Kauhaus (Bitbucket: ckauhaus, GitHub: ckauhaus).


Originally reported by Adrian.vonButtlar@uni-hamburg.de