Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update check-elb-nodes for AWS-SDK v2 #246

Merged
merged 1 commit into from
Oct 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ This CHANGELOG follows the format listed [here](https://github.com/sensu-plugins

## [Unreleased]
### Breaking Changes
- metrics-sqs.rb, check-elb-certs.rb: Update to AWS-SDK v2. With the update to SDK v2 this check no longer takes `aws_access_key` and `aws_secret_access_key` options.
- metrics-sqs.rb, check-elb-certs.rb, check-elb-nodes.rb, check-elb-health-sdk.rb: Update to AWS-SDK v2.
With the update to SDK v2 these checks no longer take `aws_access_key` and `aws_secret_access_key` options.
Credentials should be set in environment variables, a credential file, or with an IAM instance profile.
See http://docs.aws.amazon.com/sdkforruby/api/#Configuration for details on setting credentials (@eheydrick)

Expand Down
35 changes: 11 additions & 24 deletions bin/check-elb-nodes.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! /usr/bin/env ruby
#!/usr/bin/env ruby
#
# check-elb-nodes
#
Expand All @@ -13,7 +13,7 @@
# Linux
#
# DEPENDENCIES:
# gem: aws-sdk-v1
# gem: aws-sdk
# gem: sensu-plugin
#
# USAGE:
Expand All @@ -32,20 +32,11 @@
#

require 'sensu-plugin/check/cli'
require 'aws-sdk-v1'
require 'sensu-plugins-aws'
require 'aws-sdk'

class CheckELBNodes < 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']

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']
include Common

option :aws_region,
short: '-r AWS_REGION',
Expand Down Expand Up @@ -94,23 +85,19 @@ def aws_config
end

def run
AWS.start_memoizing
elb = AWS::ELB.new aws_config
elb = Aws::ElasticLoadBalancing::Client.new(aws_config)

begin
instances = elb.load_balancers[config[:load_balancer]].instances.health
rescue AWS::ELB::Errors::LoadBalancerNotFound
instance_health = elb.describe_instance_health(load_balancer_name: config[:load_balancer])
rescue Aws::ElasticLoadBalancing::Errors::LoadBalancerNotFound
unknown "A load balancer with the name '#{config[:load_balancer]}' was not found"
end

num_instances = instances.count.to_f
num_instances = instance_health.instance_states.size
state = { 'OutOfService' => [], 'InService' => [], 'Unknown' => [] }
instances.each do |instance|
# Force a requery of state
AWS.stop_memoizing if instance[:state] == 'Unknown'
state[instance[:state]] << instance[:instance].id
instance_health.instance_states.each do |instance|
state[instance.state] << instance.instance_id
end
AWS.stop_memoizing

message = "InService: #{state['InService'].count}"
if state['InService'].count > 0
Expand Down