Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable 'event_key' for non-raw setup. #39

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.hec.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,12 @@ Example:

### event_key

Only for raw mode. The value specified by this key is sent as an event.
The value specified by this key is sent as an event.
All other keys are discarded.
When `raw` is set to `true`, this parameter is required.

* fluentd record: `1490924392 {"log": "GET / HTTP/1.1 200"}`
* event_key "log"
* sent as: `GET / HTTP/1.1 200`

### line_breaker
Expand Down
7 changes: 6 additions & 1 deletion lib/fluent/plugin/out_splunk_hec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,12 @@ def setup_client
end

def format_event(time, record)
msg = {'event' => record}
if @event_key
msg = {'event' => (record[@event_key] || '')}
else
msg = {'event' => record}
end

if @use_fluentd_time
msg['time'] = time.respond_to?('to_f') ? time.to_f : time
end
Expand Down
14 changes: 14 additions & 0 deletions test/test_out_splunk_hec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,20 @@ def merge_config(config1, config2)
assert_equal(event, JSON.parse(result['result']['_raw']))
end

test 'non raw with event_key' do
config = merge_config(test_config[:default_config_no_ack], %[
event_key log
])
d = create_driver(config)
event = {'log' => SecureRandom.hex}
time = Time.now.to_i - 100
d.emit(event, time)
d.run
result = get_events(test_config[:query_port], "source=\"#{DEFAULT_SOURCE_FOR_NO_ACK}\"")[0]
assert_equal(time, result['result']['_time'].to_i)
assert_equal(event['log'], result['result']['_raw'])
end

# Backward compability (sourcetype) test
test 'source_type = sourcetype_test' do
config = merge_config(test_config[:default_config_no_ack], %[
Expand Down