b20n / bernhard Goto Github PK
View Code? Open in Web Editor NEWPython Riemann client.
License: Apache License 2.0
Python Riemann client.
License: Apache License 2.0
In python2.6, adding custom fields with "attributes": {}
will cause error if value in the dict is not ascii because str(value[key])
is used. We can use unicode
but in python3.x this will cause error.
I use a script to monitor riemann and report when things are messed up. I have the following code and cl == bernhard.Client()
:
def send_event(cl):
log.debug('Sending event')
try:
cl.send({'host': 'localhost',
'service':'Riemann Monitor',
'state':'ok',
'ttl':60})
log.debug('sent')
except Exception as e:
log.error(e)
pd_trigger('Cannot send event')
I had an issue where riemann was hung up or something which is fine because the code above should catch an exception but the issue was a socket timeout and somehow bernhard didn't throw an exception?
Exception sending event to Riemann over TCP socket: timed out
Traceback (most recent call last):
File "/opt/rh/rh-python36/root/usr/lib/python3.6/site-packages/bernhard/__init__.py", line 79, in write
response = self.read_exactly(self.sock, 4)
File "/opt/rh/rh-python36/root/usr/lib/python3.6/site-packages/bernhard/__init__.py", line 64, in read_exactly
data = sock.recv(size - len(buffer))
socket.timeout: timed out
I have yet to take a look at the bernhard code but will probably tomorrow, sometime next week, or whenever I get around to it. It would be nice if you could help me fix this issue though and get bernhard's client to throw an exception for socket timeouts. Thanks much.
Versions
Steps to reproduce
pip install protobuf==3.2.0
pip install bernhard
python -c "import bernhard"
Error that appears
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/bernhard/__init__.py", line 11, in <module>
from . import pb
File "/usr/local/lib/python2.7/dist-packages/bernhard/pb.py", line 34, in <module>
options=None),
File "/usr/local/lib/python2.7/dist-packages/google/protobuf/descriptor.py", line 494, in __new__
_message.Message._CheckCalledFromGeneratedFile()
TypeError: Descriptors should not be created directly, but only retrieved from their parent.
pip install protobuf==4.21.1
pip install bernhard
python -c "import bernhard"
, throws the error,Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/local/lib/python3.9/site-packages/bernhard/__init__.py", line 20, in <module>
from . import pb
File "/usr/local/lib/python3.9/site-packages/bernhard/pb.py", line 13, in <module>
DESCRIPTOR = _descriptor.FileDescriptor(
File "/usr/local/lib/python3.9/site-packages/google/protobuf/descriptor.py", line 1028, in __new__
return _message.default_pool.AddSerializedFile(serialized_pb)
TypeError: expected bytes, str found
Template copied from #29 ๐
This error occurs when trying to send from a windows client to a Linux Riemann server.
C:\python\site-packages\bernhard__init__.pyc in write(self, message)
50 rxlen = struct.unpack('!I', self.sock.recv(4))[0]
51 # Rx entire response
---> 52 response = self.sock.recv(rxlen, socket.MSG_WAITALL)
53 return response
54 except (socket.error, struct.error) as e:
AttributeError: 'module' object has no attribute 'MSG_WAITALL'
This is a known issue described here with a potential fix:
https://bugs.launchpad.net/myconnpy/+bug/437972
dtmilano/AndroidViewClient#90
I haven't investigated this at all yet, but are there any known issues?
This is more of a feature request than an issue.
From what I see all custom attributes are cast to string, while others fields (TTL) are defined as int64.
Any chance to allow sending numeric fields to Riemann?
The protocol buffer library doesn't let you set a list attribute with =
-- you need to use extend()
. Here's how I fixed it in the pyriemann client: sjl/pyriemann@e2e2227
The pyriemann client lets you create a Client
regardless of whether the Riemann server it's pointing at is alive or not. You only get an error when you actually try to send()
something, and then if the server comes up later it'll start working.
Bernhard currently throws an error when you try to create a Client
while Riemann is down.
pyriemann's behavior is really handy for us, because intermittent problems with Riemann during our app's startup don't prevent stats from being sent once it's back up again.
Currently, the protobuf package on PyPI doesn't work on Python 3. It will install, but try using it:
# python
Python 3.5.1 (default, Dec 15 2015, 14:52:59)
[GCC 4.2.1 Compatible Apple LLVM 7.0.2 (clang-700.1.81)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from google.protobuf import reflection
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/ttvrtkovic/pg/.venv/lib/python3.5/site-packages/google/protobuf/reflection.py", line 68, in <module>
from google.protobuf.internal import python_message
File "/Users/ttvrtkovic/pg/.venv/lib/python3.5/site-packages/google/protobuf/internal/python_message.py", line 848
except struct.error, e:
^
SyntaxError: invalid syntax
Cool, huh? So for the time being, bernhard is Python 2 only I guess.
There's a Python 3 fork called 'python3_protobuf', used by for example the Riak client (https://github.com/basho/riak-python-client/blob/master/setup.py). Do you think bernhard could work with this version? If so, I'd suggest conditionally depending on protobuf
on Python 2 and python3_protobuf
on Python 3.
(But I wouldn't do it like in the linked Riak setup.py, but rather like this: https://github.com/pytest-dev/pytest-asyncio/blob/master/setup.py#L47
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.