bin/check-ebs-snapshots.rb in sensu-plugins-aws-2.1.1 vs bin/check-ebs-snapshots.rb in sensu-plugins-aws-2.2.0

- old
+ new

@@ -16,12 +16,16 @@ # gem: sensu-plugin # # USAGE: # ./check-ebs-snapshots.rb -r ${you_region} # ./check-ebs-snapshots.rb -r ${you_region} -p 1 +# ./check-ebs-snapshots.rb -r ${you_region} -p -i +# ./check-ebs-snapshots.rb -r ${you_region} -i # # NOTES: +# When using -i flag any volume that has a tag-key of "IGNORE_BACKUP" will +# be ignored. # # LICENSE: # Shane Starcher <shane.starcher@gmail.com> # Released under the same terms as Sensu (the MIT license); see LICENSE # for details. @@ -43,15 +47,22 @@ short: '-r R', long: '--region REGION', description: 'AWS region', default: 'us-east-1' + option :check_ignored, + short: '-i', + long: '--ignore', + description: 'mark as true to ignore volumes with an IGNORE_BACKUP tag', + default: false, + boolean: true + def run errors = [] - ec2 = Aws::EC2::Client.new + @ec2 = Aws::EC2::Client.new - volumes = ec2.describe_volumes( + volumes = @ec2.describe_volumes( filters: [ { name: 'attachment.status', values: ['attached'] }, @@ -59,14 +70,13 @@ name: 'tag-key', values: ['Name'] } ] ) - volumes[:volumes].each do |volume| tags = volume[:tags].map { |a| Hash[*a] }.reduce(:merge) || {} - - snapshots = ec2.describe_snapshots( + next if config[:check_ignored] && tags.key?('IGNORE_BACKUP') + snapshots = @ec2.describe_snapshots( filters: [ { name: 'volume-id', values: [volume[:volume_id]] }