Skip to content

Commit 198f514

Browse files
committed
Merge branch 'small-fixes' into feature/v7
2 parents b9f06c0 + 5533e05 commit 198f514

8 files changed

Lines changed: 76 additions & 40 deletions

File tree

README.rst

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,31 +28,31 @@ Usage
2828

2929
As a command line tool::
3030

31-
riemann-client [--host HOST] [--port PORT] send [-s SERVICE] [-S STATE] [-m METRIC] [...]
32-
riemann-client [--host HOST] [--port PORT] query QUERY
31+
riemann-client [--host HOST] [--port PORT] send [-s SERVICE] [-S STATE] [-m METRIC] [...]
32+
riemann-client [--host HOST] [--port PORT] query QUERY
3333

3434
The host and port used by the command line tool can also be set with the
3535
``RIEMANN_HOST`` and ``RIEMANN_PORT`` environment variables. By default,
3636
``localhost:5555`` will be used.
3737

3838
As a library::
3939

40-
import riemann_client.client
40+
import riemann_client.client
4141

42-
with riemann_client.client.Client() as client:
43-
client.event(service="riemann-client", state="awesome")
44-
client.query("service = 'riemann-client'")
42+
with riemann_client.client.Client() as client:
43+
client.event(service="riemann-client", state="awesome")
44+
client.query("service = 'riemann-client'")
4545

4646
A more detailed example, using both a non-default transport and a queued
4747
client::
4848

49-
from riemann_client.transport import TCPTransport
50-
from riemann_client.client import QueuedClient
49+
from riemann_client.transport import TCPTransport
50+
from riemann_client.client import QueuedClient
5151

52-
with QueuedClient(TCPTransport("localhost", 5555)) as client:
53-
client.event(service="one", metric_f=0.1)
54-
client.event(service="two", metric_f=0.2)
55-
client.flush()
52+
with QueuedClient(TCPTransport("localhost", 5555)) as client:
53+
client.event(service="one", metric_f=0.1)
54+
client.event(service="two", metric_f=0.2)
55+
client.flush()
5656

5757
The ``QueuedClient`` class modifies the ``event()`` method to add events to a
5858
queue instead of immediately sending them, and adds the ``flush()`` method to
@@ -64,7 +64,7 @@ Installation
6464
``riemann-client`` requires Python 2.6 or above, and can be installed with
6565
``pip install riemann-client``. It will use Google's `protobuf`_ library when
6666
running under Python 2, and `GreatFruitOmsk`_'s `protobuf-py3`_ fork when
67-
running under Python 3. Python 3 support is experimental and is likley to use
67+
running under Python 3. Python 3 support is experimental and is likely to use
6868
Google's `protobuf` once it supports Python 3 fully.
6969

7070
.. _protobuf: https://pypi.python.org/pypi/protobuf
@@ -79,7 +79,7 @@ Requirements
7979
* `protobuf-py3`_ (when using Python 3)
8080

8181
Testing (Linux/OSX)
82-
-------
82+
-------------------
8383

8484
Testing is done with `tox`_::
8585

riemann_client/__init__.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,19 @@
11
"""A Python Riemann client and command line tool"""
22

3-
__version__ = '6.1.3'
3+
from .client import (
4+
Client, QueuedClient # noqa
5+
)
6+
7+
from .transport import (
8+
RiemannError, SocketTransport, UDPTransport, # noqa
9+
TCPTransport, TLSTransport, BlankTransport, # noqa
10+
)
11+
12+
13+
try:
14+
from .client import AutoFlushingQueuedClient # noqa
15+
except ImportError:
16+
pass
17+
18+
__version__ = '6.4.0'
419
__author__ = 'Sam Clements <sam.clements@datasift.com>'

riemann_client/__main__.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
"""Riemann command line client"""
2+
3+
from __future__ import absolute_import
4+
5+
from . import command
6+
7+
8+
if __name__ == '__main__':
9+
command.main()

riemann_client/client.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ def emit(self, record):
2424
Timer = None
2525
import time
2626

27-
import riemann_client.riemann_pb2
28-
import riemann_client.transport
27+
from . import riemann_pb2
28+
from .transport import UDPTransport, TCPTransport
2929

3030
logger = logging.getLogger(__name__)
3131
logger.addHandler(NullHandler())
@@ -64,7 +64,7 @@ class Client(object):
6464

6565
def __init__(self, transport=None):
6666
if transport is None:
67-
transport = riemann_client.transport.TCPTransport()
67+
transport = TCPTransport()
6868
self.transport = transport
6969

7070
def __enter__(self):
@@ -81,7 +81,7 @@ def create_event(data):
8181
:param dict data: The attributes to be set on the event
8282
:returns: A protocol buffer ``Event`` object
8383
"""
84-
event = riemann_client.riemann_pb2.Event()
84+
event = riemann_pb2.Event()
8585
event.host = socket.gethostname()
8686
event.tags.extend(data.pop('tags', []))
8787

@@ -100,7 +100,7 @@ def send_events(self, events):
100100
:param events: A list or iterable of ``Event`` objects
101101
:returns: The response message from Riemann
102102
"""
103-
message = riemann_client.riemann_pb2.Msg()
103+
message = riemann_pb2.Msg()
104104
for event in events:
105105
message.events.add().MergeFrom(event)
106106
return self.transport.send(message)
@@ -160,7 +160,7 @@ def send_query(self, query):
160160
161161
:returns: The response message from Riemann
162162
"""
163-
message = riemann_client.riemann_pb2.Msg()
163+
message = riemann_pb2.Msg()
164164
message.query.string = query
165165
return self.transport.send(message)
166166

@@ -172,7 +172,7 @@ def query(self, query):
172172
:returns: A list of event dictionaries taken from the response
173173
:raises Exception: if used with a :py:class:`.UDPTransport`
174174
"""
175-
if isinstance(self.transport, riemann_client.transport.UDPTransport):
175+
if isinstance(self.transport, UDPTransport):
176176
raise Exception('Cannot query the Riemann server over UDP')
177177
response = self.send_query(query)
178178
return [self.create_dict(e) for e in response.events]
@@ -218,7 +218,7 @@ def send_events(self, events):
218218

219219
def clear_queue(self):
220220
"""Resets the message/queue to a blank :py:class:`.Msg` object"""
221-
self.queue = riemann_client.riemann_pb2.Msg()
221+
self.queue = riemann_pb2.Msg()
222222

223223

224224
if RLock and Timer: # noqa
@@ -363,3 +363,6 @@ def stop_timer(self):
363363
a :py:meth:`.flush` event will reactviate the timer
364364
"""
365365
self.timer.cancel()
366+
367+
368+
__all__ = 'Client', 'QueuedClient', 'AutoFlushingQueuedClient'

riemann_client/command.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,23 @@
77

88
import click
99

10-
import riemann_client
11-
import riemann_client.client
12-
import riemann_client.transport
10+
from . import __version__
11+
from .client import Client
12+
from .transport import (
13+
RiemannError, UDPTransport, TCPTransport,
14+
TLSTransport, BlankTransport
15+
)
1316

1417
__all__ = ['main']
1518

1619

17-
class CommandLineClient(riemann_client.client.Client):
20+
class CommandLineClient(Client):
1821
"""Prints to STDERR when an error message is recived from Riemann"""
1922

2023
def __exit__(self, exc_type, exc_value, traceback):
2124
super(CommandLineClient, self).__exit__(exc_type, exc_value, traceback)
2225

23-
if isinstance(exc_type, riemann_client.transport.RiemannError):
26+
if isinstance(exc_type, RiemannError):
2427
click.echo("The server responded with an error: {0}".format(
2528
exc_value.message), file=sys.stderr)
2629
exit(1)
@@ -41,7 +44,7 @@ def echo_event(data):
4144

4245

4346
@click.group()
44-
@click.version_option(version=riemann_client.__version__)
47+
@click.version_option(version=__version__)
4548
@click.option('--host', '-H', type=click.STRING, default='localhost',
4649
envvar='RIEMANN_HOST', help='Riemann server hostname.')
4750
@click.option('--port', '-P', type=click.INT, default=5555,
@@ -67,16 +70,16 @@ def main(ctx, host, port, transport_type, timeout, ca_certs):
6770
if transport_type == 'udp':
6871
if timeout is not None:
6972
ctx.fail('--timeout cannot be used with the UDP transport')
70-
transport = riemann_client.transport.UDPTransport(host, port)
73+
transport = UDPTransport(host, port)
7174
elif transport_type == 'tcp':
72-
transport = riemann_client.transport.TCPTransport(host, port, timeout)
75+
transport = TCPTransport(host, port, timeout)
7376
elif transport_type == 'tls':
7477
if ca_certs is None:
7578
ctx.fail('--ca-certs must be set when using the TLS transport')
76-
transport = riemann_client.transport.TLSTransport(
79+
transport = TLSTransport(
7780
host, port, timeout, ca_certs)
7881
elif transport_type == 'none':
79-
transport = riemann_client.transport.BlankTransport()
82+
transport = BlankTransport()
8083

8184
ctx.obj = transport
8285

riemann_client/riemann_pb2.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
"""Wraps the riemann_pb2_py2 and riemann_pb2_py3 modules"""
1+
"""Wraps the riemann_py2_pb2 and riemann_py3_pb2 modules"""
22

33
import sys
44

55
__all__ = ['Event', 'Msg', 'Query', 'Attribute']
66

77
if sys.version_info >= (3,):
8-
from riemann_client.riemann_py3_pb2 import (Event, Msg, Query, Attribute)
8+
from .riemann_py3_pb2 import (Event, Msg, Query, Attribute)
99
else:
10-
from riemann_client.riemann_py2_pb2 import (Event, Msg, Query, Attribute)
10+
from .riemann_py2_pb2 import (Event, Msg, Query, Attribute)

riemann_client/transport.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import ssl
1010
import struct
1111

12-
import riemann_client.riemann_pb2
12+
from . import riemann_pb2
1313

1414

1515
# Default arguments
@@ -138,7 +138,7 @@ def send(self, message):
138138
self.socket.sendall(struct.pack('!I', len(message)) + message)
139139

140140
length = struct.unpack('!I', self.socket.recv(4))[0]
141-
response = riemann_client.riemann_pb2.Msg()
141+
response = riemann_pb2.Msg()
142142
response.ParseFromString(socket_recvall(self.socket, length))
143143

144144
if not response.ok:
@@ -190,7 +190,7 @@ def send(self, message):
190190
"""
191191
for event in message.events:
192192
self.events.append(event)
193-
reply = riemann_client.riemann_pb2.Msg()
193+
reply = riemann_pb2.Msg()
194194
reply.ok = True
195195
return reply
196196

@@ -200,3 +200,9 @@ def disconnect(self):
200200

201201
def __len__(self):
202202
return len(self.events)
203+
204+
205+
__all__ = (
206+
'RiemannError', 'SocketTransport', 'UDPTransport',
207+
'TCPTransport', 'TLSTransport', 'BlankTransport',
208+
)

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
setuptools.setup(
1313
name='riemann-client',
14-
version='6.5.0',
14+
version='6.6.0',
1515

1616
author="Sam Clements",
1717
author_email="sam.clements@datasift.com",

0 commit comments

Comments
 (0)