bin/check-dynamodb-throttle.rb in sensu-plugins-aws-0.0.4 vs bin/check-dynamodb-throttle.rb in sensu-plugins-aws-1.0.0
- old
+ new
@@ -10,12 +10,11 @@
#
# PLATFORMS:
# Linux
#
# DEPENDENCIES:
-# gem: aws-sdk
-# gem: time
+# gem: aws-sdk-v1
# gem: sensu-plugin
#
# USAGE:
# Critical if session table's read throttle is over 50 for the last 5 minutes
# check-dynamodb-throttle --table_names session --throttle-for read --critical-over 50 --statistics sum --period 300
@@ -31,24 +30,27 @@
require 'sensu-plugin/check/cli'
require 'aws-sdk-v1'
require 'time'
class CheckDynamoDB < 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 :table_names,
short: '-t N',
long: '--table-names NAMES',
proc: proc { |a| a.split(/[,;]\s*/) },
@@ -88,13 +90,13 @@
proc: proc(&:to_f),
description: "Trigger a #{severity} if throttle is over the given number"
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 dynamo_db
@dynamo_db ||= AWS::DynamoDB.new aws_config
end