bin/check-elb-certs.rb in sensu-plugins-aws-8.3.1 vs bin/check-elb-certs.rb in sensu-plugins-aws-9.0.0

- old
+ new

@@ -1,54 +1,43 @@ #! /usr/bin/env ruby # # check-elb-certs # # DESCRIPTION: -# This plugin looks up all ELBs in the organization and checks https +# This plugin looks up all ELBs in the region and checks https # endpoints for expiring certificates # # OUTPUT: # plain-text # # PLATFORMS: # Linux # # DEPENDENCIES: -# gem: aws-sdk-v1 +# gem: aws-sdk # 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 -# ./check-ec2-network.rb -r ${you_region} -i ${your_instance_id} -d NetworkOut --warning-over 1000000 --critical-over 1500000 +# ./check-elb-certs.rb -r ${your_region} -w ${days_to_warn} -c ${days_to_critical} # # NOTES: # # LICENSE: # Copyright (c) 2013, Peter Burkholder, pburkholder@pobox.com # Released under the same terms as Sensu (the MIT license); see LICENSE # for details. # require 'sensu-plugin/check/cli' -require 'aws-sdk-v1' +require 'sensu-plugins-aws' +require 'aws-sdk' require 'net/http' require 'openssl' class CheckELBCerts < 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'] or provide it as an option", - default: ENV['AWS_ACCESS_KEY'] + include Common - 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 :aws_region, short: '-r AWS_REGION', long: '--aws-region REGION', description: 'AWS Region (defaults to us-east-1).', default: 'us-east-1' @@ -88,19 +77,18 @@ def run ok_message = [] warning_message = [] critical_message = [] - AWS.start_memoizing + elb = Aws::ElasticLoadBalancing::Client.new(aws_config) - elb = AWS::ELB.new aws_config - begin - elb.load_balancers.each do |lb| - lb.listeners.each do |listener| - if listener.protocol.to_s == 'https' - url = URI.parse("https://#{lb.dns_name}:#{listener.port}") + elb.describe_load_balancers.load_balancer_descriptions.each do |lb| + lb.listener_descriptions.each do |listener| + elb_listener = listener['listener'] + if elb_listener.protocol.to_s == 'HTTPS' + url = URI.parse("https://#{lb.dns_name}:#{elb_listener.load_balancer_port}") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE cert = '' @@ -109,10 +97,10 @@ rescue => e critical "An issue occurred attempting to get cert: #{e.message}" end cert_days_remaining = ((cert.not_after - Time.now) / 86_400).to_i - message = sprintf '%s(%d)', lb.name, cert_days_remaining + message = sprintf '%s(%d)', lb.load_balancer_name, cert_days_remaining if config[:crit_under] > 0 && config[:crit_under] >= cert_days_remaining critical_message << message elsif config[:warn_under] > 0 && config[:warn_under] >= cert_days_remaining warning_message << message