bin/check-ec2-network.rb in sensu-plugins-aws-0.0.4 vs bin/check-ec2-network.rb in sensu-plugins-aws-1.0.0

- old
+ new

@@ -10,11 +10,11 @@ # # PLATFORMS: # Linux # # DEPENDENCIES: -# gem: aws-sdk +# gem: aws-sdk-v1 # gem: sensu-plugin # # USAGE: # ./check-ec2-network.rb -r ${you_region} -i ${your_instance_id} --warning-over 1000000 --critical-over 1500000 # ./check-ec2-network.rb -r ${you_region} -i ${your_instance_id} -d NetworkIn --warning-over 1000000 --critical-over 1500000 @@ -30,24 +30,27 @@ require 'sensu-plugin/check/cli' require 'aws-sdk-v1' class CheckEc2Network < Sensu::Plugin::Check::CLI - option :access_key_id, - short: '-k N', - long: '--access-key-id ID', - description: 'AWS access key ID' + option :aws_access_key, + short: '-a AWS_ACCESS_KEY', + long: '--aws-access-key AWS_ACCESS_KEY', + description: "AWS Access Key. Either set ENV['AWS_ACCESS_KEY'] or provide it as an option", + default: ENV['AWS_ACCESS_KEY'] - option :secret_access_key, - short: '-s N', - long: '--secret-access-key KEY', - description: 'AWS secret access key' + option :aws_secret_access_key, + short: '-k AWS_SECRET_KEY', + long: '--aws-secret-access-key AWS_SECRET_KEY', + description: "AWS Secret Access Key. Either set ENV['AWS_SECRET_KEY'] or provide it as an option", + default: ENV['AWS_SECRET_KEY'] - option :region, - short: '-r R', - long: '--region REGION', - description: 'AWS region' + option :aws_region, + short: '-r AWS_REGION', + long: '--aws-region REGION', + description: 'AWS Region (defaults to us-east-1).', + default: 'us-east-1' option :instance_id, short: '-i instance-id', long: '--instance-id instance-ids', description: 'EC2 Instance ID to check.' @@ -75,14 +78,14 @@ long: "--#{severity}-over COUNT", description: "Trigger a #{severity} if network traffice is over specified Bytes" end def aws_config - hash = {} - hash.update access_key_id: config[:access_key_id], secret_access_key: config[:secret_access_key] if config[:access_key_id] && config[:secret_access_key] - hash.update region: config[:region] if config[:region] - hash + { access_key_id: config[:aws_access_key], + secret_access_key: config[:aws_secret_access_key], + region: config[:aws_region] + } end def ec2 @ec2 ||= AWS::EC2.new aws_config end @@ -104,13 +107,10 @@ } end def latest_value(metric) value = metric.statistics(statistics_options.merge unit: 'Bytes') - # #YELLOW - unless value.datapoints[0].nil? # rubocop:disable IfUnlessModifier, GuardClause - value.datapoints[0][:average].to_f - end + value.datapoints[0][:average].to_f unless value.datapoints[0].nil? end def check_metric(instance) metric = network_metric instance latest_value metric