Beispiel #1
0
def test_no_fields():
    data = [{'@message': 'one'},
            {'@message': 'two'}]
    out = fields(data)

    assert_equal(next(out), {'@message': 'one'})
    assert_equal(next(out), {'@message': 'two'})
Beispiel #2
0
def test_field_without_equals_is_skipped():
    data = [{'@message': 'hello'}]
    out = fields(data, ['noequals', 'field=good'])

    assert_equal(next(out), {'@message': 'hello',
                             '@fields': {
                               'field': 'good'}
                            } )
Beispiel #3
0
def test_existing_fields_are_overwritten():
    data = [{'@message': 'hello',
             '@fields': {
               'existing': 'field'}
            }]
    out = fields(data, ['existing=wood'])

    assert_equal(next(out), {'@message': 'hello',
                             '@fields': {
                               'existing': 'wood'}
                            })
Beispiel #4
0
def main():
    args = parser.parse_args()
    msgs = io.messages(sys.stdin)
    if not args.no_stamp:
        msgs = stamp(msgs)
    if args.tags:
        msgs = tag(msgs, args.tags)
    if args.fields:
        msgs = fields(msgs, args.fields)
    for msg in msgs:
        print(json.dumps(msg))
Beispiel #5
0
def test_multiple_fields_field():
    data = [{'@message': 'one'},
            {'@message': 'two'}]
    out = fields(data, ['foobar=baz', 'sausage=bacon'])

    assert_equal(next(out), {'@message': 'one',
                             '@fields': {
                               'foobar': 'baz', 'sausage': 'bacon' }
                            } )
    assert_equal(next(out), {'@message': 'two',
                             '@fields': {
                               'foobar': 'baz', 'sausage': 'bacon' }
                            } )
Beispiel #6
0
def test_single_field():
    data = [{'@message': 'one'},
            {'@message': 'two'}]
    out = fields(data, ['foobar=baz'])

    assert_equal(next(out), {'@message': 'one',
                             '@fields': {
                               'foobar': 'baz' }
                            } )
    assert_equal(next(out), {'@message': 'two',
                             '@fields': {
                               'foobar': 'baz' }
                            } )
Beispiel #7
0
def main():
    args = parser.parse_args()
    shpr = shipper.get_shipper(args.shipper)(args)

    msgs = io.messages(sys.stdin)
    if not args.no_stamp:
        msgs = stamp(msgs)
    if args.tags:
        msgs = tag(msgs, args.tags)
    if args.fields:
        msgs = fields(msgs, args.fields)
    for msg in msgs:
        payload = json.dumps(msg)
        if args.bulk:
            command = json.dumps({'index': {'_index': args.bulk_index, '_type': args.bulk_type}})
            payload = '{0}\n{1}\n'.format(command, payload)
        shpr.ship(payload)