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

Support for empty filters when namespace is AWS/EC2 #13

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
26 changes: 20 additions & 6 deletions lib/logstash/inputs/cloudwatch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class LogStash::Inputs::CloudWatch < LogStash::Inputs::Base
# Volumes: { 'attachment.status' => 'attached' }
# Each namespace uniquely support certian dimensions. Please consult the documentation
# to ensure you're using valid filters.
config :filters, :validate => :array, :required => true
config :filters, :validate => :array

# Use this for namespaces that need to combine the dimensions like S3 and SNS.
config :combined, :validate => :boolean, :default => false
Expand All @@ -125,6 +125,10 @@ def register
raise 'Interval needs to be higher than period' unless @interval >= @period
raise 'Interval must be divisible by peruid' unless @interval % @period == 0

if not defined?(@filters) and not @namespace == "AWS/EC2"
raise 'Filters must be defined for all namespaces except AWS/EC2'
end

@last_check = Time.now
end # def register

Expand All @@ -137,8 +141,12 @@ def run(queue)
# For every metric
metrics_for(@namespace).each do |metric|
@logger.info "Polling metric #{metric}"
@logger.info "Filters: #{aws_filters}"
@combined ? from_filters(queue, metric) : from_resources(queue, metric)
if defined?(@filters) != nil
@logger.info "Filters: #{aws_filters}"
@combined ? from_filters(queue, metric) : from_resources(queue, metric)
else
from_resources(queue, metric)
end
end
end # loop
end # def run
Expand Down Expand Up @@ -252,9 +260,15 @@ def resources
# See http://docs.aws.amazon.com/AmazonCloudWatch/latest/DeveloperGuide/CW_Support_For_AWS.html
case @namespace
when 'AWS/EC2'
instances = clients[@namespace].describe_instances(filters: aws_filters)[:reservation_set].collect do |r|
r[:instances_set].collect{ |i| i[:instance_id] }
end.flatten
if defined?(@filters) != nil
instances = clients[@namespace].describe_instances(filters: aws_filters)[:reservation_set].collect do |r|
r[:instances_set].collect{ |i| i[:instance_id] }
end.flatten
else
instances = clients[@namespace].describe_instances()[:reservation_set].collect do |r|
r[:instances_set].collect{ |i| i[:instance_id] }
end.flatten
end
@logger.debug "AWS/EC2 Instances: #{instances}"
{ 'InstanceId' => instances }
when 'AWS/EBS'
Expand Down