Permalink
Browse files

Ported the SNS plugin to use aws-sdk instead of fog

Conflicts:

	Gemfile.lock
  • Loading branch information...
1 parent 07cb39b commit eaee54a25ab880eff593f5ce48112b28cec3b793 @tucker250 tucker250 committed with hectcastro Mar 2, 2012
Showing with 46 additions and 72 deletions.
  1. +1 −1 Gemfile
  2. +16 −32 Gemfile.lock
  3. +8 −7 lib/logstash/outputs/sns.rb
  4. +1 −1 logstash.gemspec
  5. +20 −31 test/logstash/outputs/sns_test.rb
View
@@ -6,7 +6,7 @@ gem "uuidtools" # for naming amqp queues, License ???
gem "filewatch", "0.3.3" # for file tailing, BSD License
gem "jls-grok", "0.10.5" # for grok filter, BSD License
-gem "fog" # for AWS/SNS. MIT License
+gem "aws-sdk" # for AWS access: SNS and S3 log tailing. Apache 2.0 License
gem "jruby-elasticsearch", "0.0.11", :platforms => :jruby # BSD License
gem "onstomp" # for stomp protocol, Apache 2.0 License
gem "json" # Ruby license
View
@@ -1,56 +1,41 @@
GEM
remote: http://rubygems.org/
specs:
- addressable (2.2.6)
- backports (2.3.0)
- beefcake (0.3.7)
+ awesome_print (1.0.2)
+ aws-sdk (1.3.5)
+ httparty (~> 0.7)
+ json (~> 1.4)
+ nokogiri (>= 1.4.4)
+ uuidtools (~> 2.1)
bouncy-castle-java (1.5.0146.1)
bson (1.6.1)
bson (1.6.1-java)
bunny (0.7.9)
cabin (0.3.8)
- builder (3.0.0)
json
childprocess (0.3.1)
ffi (~> 1.0.6)
choice (0.1.4)
- excon (0.9.5)
ffi (1.0.11)
ffi (1.0.11-java)
ffi-rzmq (0.9.0)
filewatch (0.3.3)
- fog (1.1.2)
- builder
- excon (~> 0.9.0)
- formatador (~> 0.2.0)
- mime-types
- multi_json (~> 1.0.3)
- net-scp (~> 1.0.4)
- net-ssh (>= 2.1.3)
- nokogiri (~> 1.5.0)
- ruby-hmac
- formatador (0.2.1)
gelf (1.3.2)
json
gelfd (0.2.0)
gmetric (0.1.3)
haml (3.1.4)
- heroku (2.22.0)
- launchy (>= 0.3.2)
- netrc (~> 0.7.1)
- rest-client (~> 1.6.1)
- rubyzip
- http_parser.rb (0.5.3)
- http_parser.rb (0.5.3-java)
- jls-grok (0.10.6)
- cabin (~> 0.4.0)
+ httparty (0.8.1)
+ multi_json
+ multi_xml
+ jls-grok (0.10.5)
+ cabin (~> 0.3.0)
jruby-elasticsearch (0.0.11)
jruby-openssl (0.7.6.1)
bouncy-castle-java (>= 1.5.0146.1)
json (1.6.5)
json (1.6.5-java)
metaclass (0.0.1)
- mime-types (1.17.2)
minitest (2.11.1)
mizuno (0.5.0)
childprocess (>= 0.2.6)
@@ -61,16 +46,14 @@ GEM
metaclass (~> 0.0.1)
mongo (1.5.2)
bson (= 1.5.2)
- multi_json (1.0.4)
- net-scp (1.0.4)
- net-ssh (>= 1.99.1)
- net-ssh (2.3.0)
+ multi_json (1.1.0)
+ multi_xml (0.4.1)
+ nokogiri (1.5.0)
nokogiri (1.5.0-java)
rack (1.4.1)
rack-protection (1.2.0)
rack
redis (2.2.2)
- ruby-hmac (0.4.0)
sass (3.1.14)
shoulda (2.11.3)
sinatra (1.3.2)
@@ -89,12 +72,13 @@ PLATFORMS
ruby
DEPENDENCIES
+ awesome_print
+ aws-sdk
bunny
cabin (= 0.4.1)
ffi
ffi-rzmq (= 0.9.0)
filewatch (= 0.3.3)
- fog
gelf
gelfd (= 0.2.0)
gmetric (= 0.1.3)
@@ -23,8 +23,8 @@ class LogStash::Outputs::Sns < LogStash::Outputs::Base
# The path to YAML file containing a hash of the AWS credentials for your
# account. The contents of the file should look like this:
# ---
- # :aws_access_key_id: "12345"
- # :aws_secret_access_key: "54321"
+ # :access_key_id: "12345"
+ # :secret_access_key: "54321"
config :credentials, :validate => :string, :required => true
# When an ARN for an SNS topic is specified here, the message "Logstash
@@ -34,14 +34,14 @@ class LogStash::Outputs::Sns < LogStash::Outputs::Base
public
def register
- require "fog"
+ require "aws-sdk"
access_creds = YAML.load_file(@credentials)
- @sns = Fog::AWS::SNS.new(access_creds)
+ @sns = AWS::SNS.new(access_creds)
- # Try to get a list of the topics on this account to cause an error ASAP if the creds are bad
+ # Try to publish a "Logstash booted" message to the ARN provided to cause an error ASAP if the creds are bad
if @publish_boot_message_arn
- @sns.publish(@publish_boot_message_arn, "Logstash successfully booted", 'Subject' => "Logstash booted")
+ @sns.topics[@publish_boot_message_arn].publish("Logstash successfully booted", :subject => "Logstash booted")
end
end # def register
@@ -58,7 +58,8 @@ def receive(event)
@logger.debug("Sending event to SNS topic #{arn} with subject '#{subject}' and message:")
message.split("\n").each { |line| @logger.debug(line) }
- @sns.publish(arn, message, 'Subject' => subject.slice(0, MAX_SUBJECT_SIZE))
+ # Look up the topic and publish the message
+ @sns.topics[arn].publish(message, :subject => subject.slice(0, MAX_SUBJECT_SIZE))
end # def receive
public
View
@@ -26,8 +26,8 @@ Gem::Specification.new do |spec|
spec.add_dependency "awesome_print" # MIT License
spec.add_dependency "bunny" # for amqp support, MIT-style license
spec.add_dependency "cabin", "0.3.8" # for logging. apache 2 license
+ spec.add_dependency "aws-sdk" # for AWS access: SNS and S3 log tailing. Apache 2.0 License
spec.add_dependency "filewatch", "~> 0.3.3" # for file tailing, BSD License
- spec.add_dependency "fog" # for AWS/SNS. MIT License
spec.add_dependency "gelfd", "~> 0.2.0" #inputs/gelf, # License: Apache 2.0
spec.add_dependency "gelf" # outputs/gelf, # License: MIT-style
spec.add_dependency "gmetric", "~> 0.1.3" # outputs/ganglia, # License: MIT
@@ -1,11 +1,13 @@
require "test_helper"
require "logstash/outputs/sns"
-require 'fog'
+require "aws-sdk"
describe LogStash::Outputs::Sns do
before do
- # Fog mocks for SNS are not implemented, need to do it manually
- @sns = stub(:publish => true)
+ # Fake SNS object
+ @topic = stub()
+ @topic_collection = stub(:[] => @topic)
+ @sns = stub(:topics => @topic_collection)
# Some default values for an event
@event = LogStash::Event.new
@@ -14,58 +16,45 @@
@event.message = "Feb 1 15:37:27 localhost systemd-logind[384]: New session 265 of user ec2-user."
# Sample AWS credentials
- @aws_creds = { :aws_secret_access_key => '54321z', :aws_access_key_id => '12345a' }
+ @aws_creds = { :secret_access_key => '54321z', :access_key_id => '12345a' }
end
describe '.register' do
before do
YAML.stubs(:load_file => @aws_creds)
- Fog::AWS::SNS.stubs(:new => @sns)
+ AWS::SNS.stubs(:new => @sns)
end
- test 'registers an SNS proxy' do
+ test 'registers an SNS proxy without publishing a boot message' do
sns_output = LogStash::Outputs::Sns.new(
- 'credentials' => ['/fake/file.yml'],
- 'publish_boot_message_arn' => ['fake_arn']
+ 'credentials' => ['/fake/file.yml']
)
+ @topic_collection.expects(:[]).never
sns_output.register
end
test 'publishes a boot message when able to create a SNS proxy' do
sns_output = LogStash::Outputs::Sns.new(
'credentials' => ['/fake/file.yml'],
- 'publish_boot_message_arn' => ['fake_arn']
+ 'publish_boot_message_arn' => ['fake_boot_arn']
)
- @sns.expects(:publish).with('fake_arn', instance_of(String), has_entries('Subject' => instance_of(String)))
+ @topic_collection.expects(:[]).with('fake_boot_arn').returns(@topic)
+ @topic.expects(:publish).with(instance_of(String), has_entries(:subject => instance_of(String)))
sns_output.register
end
-
- test 'raises an exception when unable to create an SNS proxy' do
- sns_output = LogStash::Outputs::Sns.new(
- 'credentials' => ['/fake/file.yml'],
- 'publish_boot_message_arn' => ['fake_arn']
- )
-
- @sns.expects(:publish).raises(Excon::Errors::Timeout)
-
- assert_raises(Excon::Errors::Timeout) do
- sns_output.register
- end
- end
end
describe '.receive' do
before do
# Need to have a registered SNS proxy
YAML.stubs(:load_file => @aws_creds)
- Fog::AWS::SNS.stubs(:new => @sns)
+ AWS::SNS.stubs(:new => @sns)
@subject = LogStash::Outputs::Sns.new(
- 'credentials' => ['/fake/file.yml'],
- 'publish_boot_message_arn' => ['fake_arn']
+ 'credentials' => ['/fake/file.yml']
)
@subject.register
@@ -75,34 +64,34 @@
test 'does not send a message to SNS when an event should not be output' do
@subject.stubs(:output? => false)
- @sns.expects(:publish).never
+ @topic.expects(:publish).never
@subject.receive(@event)
end
test 'raises an exception when an event with no sns field is received' do
@event.fields.delete('sns')
- @sns.expects(:publish).never
+ @topic.expects(:publish).never
assert_raises(RuntimeError) { @subject.receive(@event) }
end
test 'uses the sns_subject when one is provided' do
@event.fields['sns_subject'] = 'Test subject'
- @sns.expects(:publish).with(@arn, instance_of(String), 'Subject' => 'Test subject')
+ @topic.expects(:publish).with(instance_of(String), :subject => 'Test subject')
@subject.receive(@event)
end
test 'uses the sns_message when one is provided' do
@event.fields['sns_message'] = 'Test message'
- @sns.expects(:publish).with(@arn, 'Test message', has_entries('Subject' => instance_of(String)))
+ @topic.expects(:publish).with('Test message', has_entries(:subject => instance_of(String)))
@subject.receive(@event)
end
test 'uses a default message and subject when no sns_message or sns_subject are provided' do
- @sns.expects(:publish).with(@arn, instance_of(String), has_entries('Subject' => instance_of(String)))
+ @topic.expects(:publish).with(instance_of(String), has_entries(:subject => instance_of(String)))
@subject.receive(@event)
end

0 comments on commit eaee54a

Please sign in to comment.