Skip to content

Commit cf30135

Browse files
committed
Modify create_event() to only return fields that are set on event message
1 parent 804ade0 commit cf30135

5 files changed

Lines changed: 30 additions & 46 deletions

File tree

README.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ Requirements
7070
Changelog
7171
---------
7272

73+
Version 6.0.0
74+
^^^^^^^^^^^^^
75+
76+
* ``riemann_client.client.Client.create_dict`` only returns event fields that are set on the Protocol Buffers ``Event`` object
77+
* ``riemann-client send ...``` only outputs fields that were set on the sent message
78+
7379
Version 5.1.0
7480
^^^^^^^^^^^^^
7581

riemann_client/__init__.py

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

3-
__version__ = '5.1.1'
3+
__version__ = '6.0.0'
44
__author__ = 'Sam Clements <sam.clements@datasift.com>'

riemann_client/client.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -124,19 +124,17 @@ def create_dict(event):
124124
:param event: A protocol buffer ``Event`` object
125125
:returns: A dictionary of event attributes
126126
"""
127-
return {
128-
'time': event.time,
129-
'state': event.state,
130-
'host': event.host,
131-
'description': event.description,
132-
'service': event.service,
133-
'tags': list(event.tags),
134-
'ttl': event.ttl,
135-
'attributes': dict(((a.key, a.value) for a in event.attributes)),
136-
'metric_f': event.metric_f,
137-
'metric_d': event.metric_d,
138-
'metric_sint64': event.metric_sint64
139-
}
127+
128+
data = dict()
129+
130+
for descriptor, value in event.ListFields():
131+
if descriptor.name == 'tags':
132+
value = list(value)
133+
elif descriptor.name == 'attributes':
134+
value = dict(((a.key, a.value) for a in value))
135+
data[descriptor.name] = value
136+
137+
return data
140138

141139
def send_query(self, query):
142140
"""Sends a query to the Riemann server

riemann_client/tests/test_riemann_command.py

Lines changed: 11 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -16,34 +16,16 @@ def run_cli(args):
1616
return result
1717

1818

19-
def strip_whitespace(string):
19+
def strip(string):
2020
return re.sub('\s+', '', string)
2121

2222

23-
def compare_output(args, expected):
24-
output = strip_whitespace(run_cli(args).output)
25-
expected_output = strip_whitespace(expected)
26-
return output == expected_output
23+
def assert_output_eq(args, expected):
24+
assert strip(run_cli(args).output) == strip(expected)
2725

2826

29-
EMPTY_MESSAGE = """{
30-
"attributes": {},
31-
"description": "",
32-
"host": "%s",
33-
"metric_d": 0,
34-
"metric_f": 0,
35-
"metric_sint64": 0,
36-
"service": "",
37-
"state": "",
38-
"tags": [],
39-
"time": 0,
40-
"ttl": 0
41-
}
42-
"""
43-
44-
45-
def test_send_blank():
46-
assert compare_output(['send'], EMPTY_MESSAGE % socket.gethostname())
27+
def test_send_empty_message():
28+
assert_output_eq(['send'], '{"host": "%s"}' % socket.gethostname())
4729

4830

4931
POPULATED_MESSAGE = """{
@@ -52,9 +34,7 @@ def test_send_blank():
5234
},
5335
"description": "description",
5436
"host": "%s",
55-
"metric_d": 0,
5637
"metric_f": 11.1,
57-
"metric_sint64": 0,
5838
"service": "service",
5939
"state": "state",
6040
"tags": [
@@ -63,11 +43,11 @@ def test_send_blank():
6343
"time": 1408030991,
6444
"ttl": 120
6545
}
66-
"""
46+
""" % socket.gethostname()
6747

6848

6949
def test_send():
70-
assert compare_output([
50+
assert_output_eq([
7151
'send',
7252
'--attribute', 'key=value',
7353
'--description', 'description',
@@ -77,11 +57,11 @@ def test_send():
7757
'--tag', 'tag',
7858
'--time', '1408030991',
7959
'--ttl', '120'
80-
], POPULATED_MESSAGE % socket.gethostname())
60+
], POPULATED_MESSAGE)
8161

8262

8363
def test_send_short():
84-
assert compare_output([
64+
assert_output_eq([
8565
'send',
8666
'-a', 'key=value',
8767
'-d', 'description',
@@ -91,8 +71,8 @@ def test_send_short():
9171
'-t', 'tag',
9272
'-T', '1408030991',
9373
'-l', '120'
94-
], POPULATED_MESSAGE % socket.gethostname())
74+
], POPULATED_MESSAGE)
9575

9676

9777
def test_query():
98-
assert compare_output(['query', 'true'], '[]')
78+
assert_output_eq(['query', 'true'], '[]')

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='5.1.1',
14+
version='6.0.0',
1515

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

0 commit comments

Comments
 (0)