Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unrecorevable error in livestatus module #33

Open
Seb-Solon opened this issue Aug 11, 2014 · 5 comments
Open

unrecorevable error in livestatus module #33

Seb-Solon opened this issue Aug 11, 2014 · 5 comments

Comments

@Seb-Solon
Copy link
Contributor

Comes from : shinken-solutions/shinken#1254

Hi,
We set Apache (Thruk) and Shinken in en_US.UTF-8, and added a comment with an accent in Thruk.
The result is a crash of the livestatus module

Maybe it is related with this issue: * shinken-solutions/shinken#628 Fix utf8 research bug in LiveStatus broker module shinken-solutions/shinken#634

@dgilm
Copy link

dgilm commented Sep 24, 2014

Confirmed:

==> /var/log/shinken/brokerd.log <==
2014-09-24 10:01:19,494 [1411545679] Error :   [Livestatus] Back trace of this exception: Traceback (most recent call last):
  File "/var/lib/shinken/modules/livestatus/livestatus_obj.py", line 52, in handle_request
    return self.handle_request_and_fail(data)
  File "/var/lib/shinken/modules/livestatus/livestatus_obj.py", line 119, in handle_request_and_fail
    response.format_live_data(result, query.columns, query.aliases)
  File "/var/lib/shinken/modules/livestatus/livestatus_response.py", line 187, in format_live_data
    self.output = dumps(lines)
  File "/usr/lib/python2.7/dist-packages/simplejson/__init__.py", line 286, in dumps
    return _default_encoder.encode(obj)
  File "/usr/lib/python2.7/dist-packages/simplejson/encoder.py", line 226, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/usr/lib/python2.7/dist-packages/simplejson/encoder.py", line 296, in iterencode
    return _iterencode(o, 0)
UnicodeDecodeError: 'utf8' codec can't decode byte 0xe9 in position 5: invalid continuation byte

@dgilm
Copy link

dgilm commented Sep 24, 2014

I know that this is not the right solution (there are more codifications than latin-1), but for your information, now I can use livestatus with thruk making the following change:

--- livestatus_response.py.orig 2014-09-24 10:11:44.524597684 +0200
+++ livestatus_response.py  2014-09-24 14:13:34.885018044 +0200
@@ -184,7 +184,7 @@
                 else:
                     lines.insert(0, columns)
             if self.outputformat == 'json':
-                self.output = dumps(lines)
+                self.output = dumps(lines, encoding='latin-1')
             else:
                 self.output = str(lines)

@naparuba
Copy link
Member

We should focus on utf8 only I think. It should be up to UIs to be sure
they manage encoding. We have to choice for one standard encoding, and I
think it's utf8 that must be choose, because it's the defacto standard,
even if it means droping some characters if the UI don't follow it (but at
leat it don't break the module).

On Wed, Sep 24, 2014 at 2:15 PM, David Gil [email protected] wrote:

I know that this is not the right solution (there are more codifications
than latin-1), but for your information, now I can use livestatus making
the following change:

--- livestatus_response.py.orig 2014-09-24 10:11:44.524597684 +0200
+++ livestatus_response.py 2014-09-24 14:13:34.885018044 +0200
@@ -184,7 +184,7 @@
else:
lines.insert(0, columns)
if self.outputformat == 'json':

  •            self.output = dumps(lines)
    
  •            self.output = dumps(lines, encoding='latin-1')
         else:
             self.output = str(lines)
    


Reply to this email directly or view it on GitHub
#33 (comment)
.

@dgilm
Copy link

dgilm commented Sep 25, 2014

Livestatus supports both utf8 and latin1 encodings.
https://mathias-kettner.de/checkmk_livestatus.html#Character%20encoding

Maybe adding a module option (data_encoding set to utf8 by default) to the livestatus module like the described in the previous link, might be useful for 'latin' users and it's quite easy to implement. In fact, the decode error only ocurrs using json/python.

dgilm added a commit to dgilm/mod-import-mysql that referenced this issue Sep 25, 2014
Avoid future problems with database fields encoded with latin1 and other codifications. This fixes a livestatus error (shinken-monitoring/mod-livestatus#33) creating a response with fields imported with this module encoded as latin1.
@dgilm
Copy link

dgilm commented Sep 25, 2014

I think we can implement a similiar aproach: shinken-monitoring/mod-import-mysql#7

Detect a different encoding than 'utf8' and encode/decode again to utf8 to avoid this kind of errors.

What do you think guys?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants