bin/check-rds-events.rb in sensu-plugins-aws-0.0.4 vs bin/check-rds-events.rb in sensu-plugins-aws-1.0.0

- old
+ new

@@ -14,11 +14,11 @@ # # PLATFORMS: # Linux # # DEPENDENCIES: -# gem: aws-sdk +# gem: aws-sdk-v1 # gem: sensu-plugin # # USAGE: # ./check-rds-events.rb -r ${you_region} -s ${your_aws_secret_access_key} -a ${your_aws_access_key} # @@ -33,33 +33,46 @@ require 'sensu-plugin/check/cli' require 'aws-sdk-v1' class CheckRDSEvents < Sensu::Plugin::Check::CLI 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_ID'] or provide it as an option", - default: ENV['AWS_ACCESS_KEY_ID'] + 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 :aws_secret_access_key, - short: '-s AWS_SECRET_ACCESS_KEY', - long: '--aws-secret-access-key AWS_SECRET_ACCESS_KEY', - description: "AWS Secret Access Key. Either set ENV['AWS_SECRET_ACCESS_KEY'] or provide it as an option", - default: ENV['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 :aws_region, - short: '-r AWS_REGION', - long: '--aws-region REGION', - description: 'AWS Region (such as eu-west-1).', - default: 'us-east-1' + short: '-r AWS_REGION', + long: '--aws-region REGION', + description: 'AWS Region (defaults to us-east-1).', + default: 'us-east-1' - def run # rubocop:disable AbcSize - rds = AWS::RDS::Client.new( - access_key_id: config[:aws_access_key], + def aws_config + { access_key_id: config[:aws_access_key], secret_access_key: config[:aws_secret_access_key], - region: config[:aws_region]) + region: config[:aws_region] + } + end + def run + clusters = maint_clusters + if clusters.empty? + ok + else + critical("Clusters w/ critical events: #{clusters.join(',')}") + end + end + + def maint_clusters + rds = AWS::RDS::Client.new aws_config + begin # fetch all clusters identifiers clusters = rds.describe_db_instances[:db_instances].map { |db| db[:db_instance_identifier] } maint_clusters = [] @@ -72,13 +85,8 @@ maint_clusters.push(cluster_name) if events_record[:events][-1][:message] =~ /has started|is being|off-line|shutdown/ end rescue => e unknown "An error occurred processing AWS RDS API: #{e.message}" end - - if maint_clusters.empty? - ok - else - critical("Clusters w/ critical events: #{maint_clusters.join(',')}") - end + maint_clusters end end