bin/check-s3-object.rb in sensu-plugins-aws-12.2.0 vs bin/check-s3-object.rb in sensu-plugins-aws-12.3.0
- old
+ new
@@ -100,10 +100,16 @@
description: 'Comparision operator for threshold: equal, not, greater, less',
short: '-o OPERATION',
long: '--operator-size OPERATION',
default: 'equal'
+ option :no_crit_on_multiple_objects,
+ description: 'If this flag is set, sort all matching objects by last_modified date and check against the newest. By default, this check will return a CRITICAL result if multiple matching objects are found.',
+ short: '-m',
+ long: '--ok-on-multiple-objects',
+ boolean: true
+
def aws_config
{ access_key_id: config[:aws_access_key],
secret_access_key: config[:aws_secret_access_key],
region: config[:aws_region] }
end
@@ -156,16 +162,21 @@
age = Time.now.to_i - output[:last_modified].to_i
size = output[:content_length]
elsif !config[:key_prefix].nil?
key_search = config[:key_prefix]
output = s3.list_objects(bucket: config[:bucket_name], prefix: key_search)
+ output = output.next_page while output.next_page?
if output.contents.size.to_i < 1
critical "Object with prefix \"#{key_search}\" not found in bucket #{config[:bucket_name]}"
end
if output.contents.size.to_i > 1
- critical "Your prefix \"#{key_search}\" return too much files, you need to be more specific"
+ if config[:no_crit_on_multiple_objects].nil?
+ critical "Your prefix \"#{key_search}\" return too much files, you need to be more specific"
+ else
+ output.contents.sort_by!(&:last_modified).reverse!
+ end
end
key_fullname = output.contents[0].key
age = Time.now.to_i - output.contents[0].last_modified.to_i
size = output.contents[0].size