-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
57 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
"""Print events to the console as CSV.""" | ||
from __future__ import absolute_import | ||
import sys | ||
import csv | ||
|
||
|
||
from contextlib import contextmanager | ||
|
||
__all__ = ['Destination'] | ||
|
||
|
||
def print_events(): | ||
eid = None | ||
writer = csv.writer(sys.stdout) | ||
while True: | ||
event = yield eid | ||
envelope = event.get('envelope', {}) | ||
writer.writerow([ | ||
','.join(event.get('tags', [])), | ||
envelope.get('sender', ''), | ||
envelope.get('targets', ''), | ||
event.get('event', ''), | ||
event.get('timestamp', '')]) | ||
|
||
|
||
def make_sink(): | ||
sink = print_events() | ||
next(sink) | ||
yield sink | ||
|
||
Destination = contextmanager(make_sink) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
"""Print events to the console as JSON.""" | ||
from __future__ import absolute_import | ||
import sys | ||
import json | ||
|
||
|
||
from contextlib import contextmanager | ||
|
||
__all__ = ['Destination'] | ||
|
||
|
||
def print_events(): | ||
eid = None | ||
while True: | ||
event = yield eid | ||
print json.dumps(event) | ||
|
||
|
||
def make_sink(): | ||
sink = print_events() | ||
next(sink) | ||
yield sink | ||
|
||
Destination = contextmanager(make_sink) |