Skip to content

Commit

Permalink
Add filtering option in check-ebs-burst-limit.rb
Browse files Browse the repository at this point in the history
  • Loading branch information
boutetnico authored and majormoses committed May 9, 2019
1 parent 2f21313 commit cffd23a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
This CHANGELOG follows the format listed [here](https://github.com/sensu-plugins/community/blob/master/HOW_WE_CHANGELOG.md)

## [Unreleased]
### Added
- `check-ebs-burst-limit.rb`: `--filter` option added to filter which volume to check. (@boutetnico)

## [18.3.0] - 2019-05-07
### Added
Expand Down
19 changes: 15 additions & 4 deletions bin/check-ebs-burst-limit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# ./check-ebs-burst-limit.rb -r ${you_region}
# ./check-ebs-burst-limit.rb -r ${you_region} -c 50
# ./check-ebs-burst-limit.rb -r ${you_region} -w 50 -c 10
# ./check-ebs-burst-limit.rb -r ${you_region} -w 50 -c 10 -f "{name:tag-value,values:[infrastructure]}"
#
# LICENSE:
# Barry Martin <[email protected]>
Expand All @@ -29,11 +30,13 @@

require 'sensu-plugin/check/cli'
require 'sensu-plugins-aws'
require 'sensu-plugins-aws/filter'
require 'aws-sdk'
require 'net/http'

class CheckEbsBurstLimit < Sensu::Plugin::Check::CLI
include CloudwatchCommon
include Filter

option :aws_region,
short: '-r R',
Expand Down Expand Up @@ -61,29 +64,37 @@ class CheckEbsBurstLimit < Sensu::Plugin::Check::CLI
boolean: true,
default: false

option :filter,
short: '-f FILTER',
long: '--filter FILTER',
description: 'String representation of the filter to apply',
default: '{}'

def run
errors = []

volume_filters = Filter.parse(config[:filter])

# Set the describe-volumes filter depending on whether -s was specified
if config[:check_self] == true
# Get the region from the availability zone, and override the -r option
my_instance_az = Net::HTTP.get(URI.parse('http://169.254.169.254/latest/meta-data/placement/availability-zone'))
Aws.config[:region] = my_instance_az.chop
my_instance_id = Net::HTTP.get(URI.parse('http://169.254.169.254/latest/meta-data/instance-id'))
volume_filters = [
volume_filters.push(
{
name: 'attachment.instance-id',
values: [my_instance_id]
}
]
)
else
# The -s option was not specified, look at all volumes which are attached
volume_filters = [
volume_filters.push(
{
name: 'attachment.status',
values: ['attached']
}
]
)
end

ec2 = Aws::EC2::Client.new
Expand Down

0 comments on commit cffd23a

Please sign in to comment.