bin/check-rds-events.rb in sensu-plugins-aws-2.1.1 vs bin/check-rds-events.rb in sensu-plugins-aws-2.2.0

- old
+ new

@@ -21,12 +21,19 @@ # DEPENDENCIES: # gem: aws-sdk-v1 # gem: sensu-plugin # # USAGE: -# ./check-rds-events.rb -r ${your_region} -k ${your_aws_secret_access_key} -a ${your_aws_access_key} +# Check's a specific RDS instance in a specific region for critical events +# check-rds-events.rb -r ${your_region} -k ${your_aws_secret_access_key} -a ${your_aws_access_key} -i ${your_rds_instance_id_name} # +# Checks all RDS instances in a specific region +# check-rds-events.rb -r ${your_region} -k ${your_aws_secret_access_key} -a ${your_aws_access_key} +# +# Checks all RDS instances in a specific region, should be using IAM role +# check-rds-events.rb -r ${your_region} +# # NOTES: # # LICENSE: # Tim Smith <tim@cozy.co> # Released under the same terms as Sensu (the MIT license); see LICENSE @@ -53,10 +60,15 @@ short: '-r AWS_REGION', long: '--aws-region REGION', description: 'AWS Region (defaults to us-east-1).', default: 'us-east-1' + option :db_instance_id, + short: '-i N', + long: '--db-instance-id NAME', + description: 'DB instance identifier' + def aws_config { access_key_id: config[:aws_access_key], secret_access_key: config[:aws_secret_access_key], region: config[:aws_region] } @@ -73,12 +85,22 @@ 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] } + if !config[:db_instance_id].nil? && !config[:db_instance_id].empty? + db_instance = rds.describe_db_instances(db_instance_identifier: config[:db_instance_id]) + if db_instance.nil? || db_instance.empty? + unknown "#{config[:db_instance_id]} instance not found" + else + clusters = [config[:db_instance_id]] + end + else + # fetch all clusters identifiers + clusters = rds.describe_db_instances[:db_instances].map { |db| db[:db_instance_identifier] } + end + maint_clusters = [] # fetch the last 15 minutes of events for each cluster # that way, we're only spammed with persistent notifications that we'd care about. clusters.each do |cluster_name| @@ -94,9 +116,10 @@ # draft the messages cluster_name_long = "#{cluster_name} (#{aws_config[:region]}) #{events_record[:events][-1][:message]}" maint_clusters.push(cluster_name_long) end + rescue => e unknown "An error occurred processing AWS RDS API: #{e.message}" end maint_clusters end