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

Ensure if host field is a String before using it as default subject #17

Open
wants to merge 1 commit into
base: main
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
2 changes: 1 addition & 1 deletion lib/logstash/outputs/sns.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def event_subject(event)
sns_subject
elsif sns_subject
LogStash::Json.dump(sns_subject)
elsif event.get("host")
elsif event.get("host").is_a?(String)
event.get("host")
else
NO_SUBJECT
Expand Down
7 changes: 6 additions & 1 deletion spec/outputs/sns_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,16 @@
expect(subject.send(:event_subject, event)).to eql(LogStash::Json.dump(["foo", "bar"]))
end

it "should return the host if 'sns_subject' not set" do
it "should return the host if 'sns_subject' not set and host is a string" do
event = LogStash::Event.new("host" => "foo")
expect(subject.send(:event_subject, event)).to eql("foo")
end

it "should return the 'NO SUBJECT' if host not a string" do
event = LogStash::Event.new("host" => { "name" => "foo" })
expect(subject.send(:event_subject, event)).to eql(LogStash::Outputs::Sns::NO_SUBJECT)
end

it "should return 'NO SUBJECT' when subject cannot be determined" do
event = LogStash::Event.new("foo" => "bar")
expect(subject.send(:event_subject, event)).to eql(LogStash::Outputs::Sns::NO_SUBJECT)
Expand Down