Skip to content

Commit

Permalink
Merge pull request #32 from robbavey/v2_api
Browse files Browse the repository at this point in the history
Move CloudWatch to v2 of AWS SDK
  • Loading branch information
robbavey authored Jun 14, 2018
2 parents 1f4c5d1 + 97fe1ee commit 601ad77
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 11 deletions.
9 changes: 7 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 2.2.0
- Changed to use the underlying version of the AWS SDK to v2. [#32](https://github.com/logstash-plugins/logstash-input-cloudwatch/pull/32)
- Fixed License definition in gemspec to be valid SPDX identifier [#32](https://github.com/logstash-plugins/logstash-input-cloudwatch/pull/32)
- Fixed fatal error when using secret key attribute in config [#30](https://github.com/logstash-plugins/logstash-input-cloudwatch/issues/30)

## 2.1.1
- Docs: Set the default_codec doc attribute.

Expand All @@ -15,5 +20,5 @@
- Depend on logstash-core-plugin-api instead of logstash-core, removing the need to mass update plugins on major releases of logstash
# 1.1.1
- New dependency requirements for logstash-core for the 5.0 release
## 1.1.0
- Moved from jrgns/logstash-input-cloudwatch to logstash-plugins
## 1.1.0
- Moved from jrgns/logstash-input-cloudwatch to logstash-plugins
9 changes: 4 additions & 5 deletions lib/logstash/inputs/cloudwatch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
#

class LogStash::Inputs::CloudWatch < LogStash::Inputs::Base
include LogStash::PluginMixins::AwsConfig
include LogStash::PluginMixins::AwsConfig::V2

config_name "cloudwatch"

Expand Down Expand Up @@ -126,8 +126,6 @@ def aws_service_endpoint(region)
end

def register
AWS.config(:logger => @logger)

raise 'Interval needs to be higher than period' unless @interval >= @period
raise 'Interval must be divisible by period' unless @interval % @period == 0

Expand Down Expand Up @@ -230,8 +228,9 @@ def clients
@clients ||= Hash.new do |client_hash, namespace|
namespace = namespace[4..-1] if namespace[0..3] == 'AWS/'
namespace = 'EC2' if namespace == 'EBS'
cls = AWS.const_get(namespace)
client_hash[namespace] = cls::Client.new(aws_options_hash)
cls = Aws.const_get(namespace)
# TODO: Move logger configuration into mixin.
client_hash[namespace] = cls::Client.new(aws_options_hash.merge(:logger => @logger))
end
end

Expand Down
4 changes: 2 additions & 2 deletions logstash-input-cloudwatch.gemspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Gem::Specification.new do |s|
s.name = 'logstash-input-cloudwatch'
s.version = '2.1.1'
s.licenses = ['Apache License (2.0)']
s.version = '2.2.0'
s.licenses = ['Apache-2.0']
s.summary = "Pulls events from the Amazon Web Services CloudWatch API "
s.description = "This gem is a Logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This gem is not a stand-alone program"
s.authors = ["Jurgens du Toit"]
Expand Down
5 changes: 3 additions & 2 deletions spec/inputs/cloudwatch_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

describe LogStash::Inputs::CloudWatch do
before do
AWS.stub!
Aws.config[:stub_responses] = true
Thread.abort_on_exception = true
end

describe '#register' do
let(:config) {
{
'access_key_id' => '1234',
'secret_access_key' => 'secret',
'secret_access_key' => LogStash::Util::Password.new('secret'),
'namespace' => 'AWS/EC2',
'filters' => { 'instance-id' => 'i-12344321' },
'region' => 'us-east-1'
Expand All @@ -25,6 +25,7 @@
end
end


context "EC2 events" do
let(:config) {
{
Expand Down
26 changes: 26 additions & 0 deletions spec/integration/cloudwatch_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
require "logstash/devutils/rspec/spec_helper"
require "logstash/inputs/cloudwatch"
require "aws-sdk"

describe LogStash::Inputs::CloudWatch, :integration => true do

let(:settings) { { "access_key_id" => ENV['AWS_ACCESS_KEY_ID'],
"secret_access_key" => LogStash::Util::Password.new(ENV['AWS_SECRET_ACCESS_KEY']),
"region" => ENV["AWS_REGION"] || "us-east-1",
"namespace" => "AWS/S3",
'filters' => { "BucketName" => "*"},
'metrics' => ["BucketSizeBytes","NumberOfObjects"]

}}

def metrics_for(settings)
cw = LogStash::Inputs::CloudWatch.new(settings)
cw.register
cw.send('metrics_for', settings['namespace'])
end

#
it "should not raise a type error when using a password" do
expect{metrics_for(settings)}.not_to raise_error
end
end

0 comments on commit 601ad77

Please sign in to comment.