sensu-plugins-aws-boutetnico 1.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +3 -0
- data/LICENSE +22 -0
- data/README.md +333 -0
- data/bin/check-alb-target-group-health.rb +100 -0
- data/bin/check-asg-instances-created.rb +129 -0
- data/bin/check-asg-instances-inservice.rb +109 -0
- data/bin/check-autoscaling-cpucredits.rb +160 -0
- data/bin/check-beanstalk-elb-metric.rb +123 -0
- data/bin/check-beanstalk-health.rb +123 -0
- data/bin/check-certificate-expiry.rb +123 -0
- data/bin/check-cloudfront-tag.rb +70 -0
- data/bin/check-cloudwatch-alarm.rb +102 -0
- data/bin/check-cloudwatch-alarms.rb +89 -0
- data/bin/check-cloudwatch-composite-metric.rb +199 -0
- data/bin/check-cloudwatch-metric.rb +123 -0
- data/bin/check-configservice-rules.rb +76 -0
- data/bin/check-direct-connect-virtual-interfaces.rb +84 -0
- data/bin/check-dynamodb-capacity.rb +194 -0
- data/bin/check-dynamodb-throttle.rb +188 -0
- data/bin/check-ebs-burst-limit.rb +143 -0
- data/bin/check-ebs-snapshots.rb +104 -0
- data/bin/check-ec2-cpu_balance.rb +139 -0
- data/bin/check-ec2-filter.rb +190 -0
- data/bin/check-ec2-network.rb +133 -0
- data/bin/check-ecs-service-health.rb +155 -0
- data/bin/check-efs-metric.rb +145 -0
- data/bin/check-eip-allocation.rb +64 -0
- data/bin/check-elasticache-failover.rb +113 -0
- data/bin/check-elb-certs.rb +132 -0
- data/bin/check-elb-health-fog.rb +114 -0
- data/bin/check-elb-health-sdk.rb +176 -0
- data/bin/check-elb-health.rb +116 -0
- data/bin/check-elb-instances-inservice.rb +103 -0
- data/bin/check-elb-latency.rb +166 -0
- data/bin/check-elb-nodes.rb +133 -0
- data/bin/check-elb-sum-requests.rb +157 -0
- data/bin/check-emr-cluster.rb +144 -0
- data/bin/check-emr-steps.rb +90 -0
- data/bin/check-eni-status.rb +110 -0
- data/bin/check-expiring-reservations.rb +117 -0
- data/bin/check-instance-events.rb +154 -0
- data/bin/check-instance-health.rb +108 -0
- data/bin/check-instance-reachability.rb +107 -0
- data/bin/check-instances-count.rb +94 -0
- data/bin/check-kms-key.rb +73 -0
- data/bin/check-rds-events.rb +141 -0
- data/bin/check-rds-pending.rb +91 -0
- data/bin/check-rds.rb +382 -0
- data/bin/check-redshift-events.rb +108 -0
- data/bin/check-reserved-instances.rb +80 -0
- data/bin/check-route.rb +122 -0
- data/bin/check-route53-domain-expiration.rb +78 -0
- data/bin/check-s3-bucket-visibility.rb +176 -0
- data/bin/check-s3-bucket.rb +86 -0
- data/bin/check-s3-object.rb +205 -0
- data/bin/check-s3-tag.rb +70 -0
- data/bin/check-sensu-client.rb +184 -0
- data/bin/check-ses-limit.rb +89 -0
- data/bin/check-ses-statistics.rb +149 -0
- data/bin/check-sns-subscriptions.rb +52 -0
- data/bin/check-sqs-messages.rb +168 -0
- data/bin/check-subnet-ip-consumption.rb +234 -0
- data/bin/check-trustedadvisor-service-limits.rb +90 -0
- data/bin/check-vpc-nameservers.rb +87 -0
- data/bin/check-vpc-vpn.rb +98 -0
- data/bin/handler-ec2_node.rb +241 -0
- data/bin/handler-scale-asg-down.rb +131 -0
- data/bin/handler-scale-asg-up.rb +131 -0
- data/bin/handler-ses.rb +107 -0
- data/bin/handler-sns.rb +64 -0
- data/bin/metrics-asg.rb +156 -0
- data/bin/metrics-autoscaling-instance-count.rb +101 -0
- data/bin/metrics-billing.rb +97 -0
- data/bin/metrics-cloudfront.rb +159 -0
- data/bin/metrics-ec2-count.rb +137 -0
- data/bin/metrics-ec2-filter.rb +97 -0
- data/bin/metrics-elasticache.rb +166 -0
- data/bin/metrics-elb.rb +169 -0
- data/bin/metrics-emr-steps.rb +82 -0
- data/bin/metrics-rds.rb +153 -0
- data/bin/metrics-reservation-utilization.rb +84 -0
- data/bin/metrics-s3.rb +107 -0
- data/bin/metrics-ses.rb +62 -0
- data/bin/metrics-sqs.rb +98 -0
- data/bin/metrics-waf.rb +111 -0
- data/lib/sensu-plugins-aws.rb +4 -0
- data/lib/sensu-plugins-aws/cloudwatch-common.rb +92 -0
- data/lib/sensu-plugins-aws/common.rb +35 -0
- data/lib/sensu-plugins-aws/filter.rb +47 -0
- data/lib/sensu-plugins-aws/version.rb +8 -0
- metadata +456 -0
@@ -0,0 +1,132 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# check-elb-certs
|
4
|
+
#
|
5
|
+
# DESCRIPTION:
|
6
|
+
# This plugin looks up all ELBs in the region and checks https
|
7
|
+
# endpoints for expiring certificates
|
8
|
+
#
|
9
|
+
# OUTPUT:
|
10
|
+
# plain-text
|
11
|
+
#
|
12
|
+
# PLATFORMS:
|
13
|
+
# Linux
|
14
|
+
#
|
15
|
+
# DEPENDENCIES:
|
16
|
+
# gem: aws-sdk
|
17
|
+
# gem: sensu-plugin
|
18
|
+
#
|
19
|
+
# USAGE:
|
20
|
+
# ./check-elb-certs.rb -r ${your_region} -w ${days_to_warn} -c ${days_to_critical}
|
21
|
+
#
|
22
|
+
# NOTES:
|
23
|
+
#
|
24
|
+
# LICENSE:
|
25
|
+
# Copyright (c) 2013, Peter Burkholder, pburkholder@pobox.com
|
26
|
+
# Released under the same terms as Sensu (the MIT license); see LICENSE
|
27
|
+
# for details.
|
28
|
+
#
|
29
|
+
|
30
|
+
require 'sensu-plugin/check/cli'
|
31
|
+
require 'sensu-plugins-aws'
|
32
|
+
require 'aws-sdk'
|
33
|
+
require 'net/http'
|
34
|
+
require 'openssl'
|
35
|
+
|
36
|
+
class CheckELBCerts < Sensu::Plugin::Check::CLI
|
37
|
+
include Common
|
38
|
+
|
39
|
+
option :aws_region,
|
40
|
+
short: '-r AWS_REGION',
|
41
|
+
long: '--aws-region REGION',
|
42
|
+
description: 'AWS Region (defaults to us-east-1).',
|
43
|
+
default: 'us-east-1'
|
44
|
+
|
45
|
+
option :warn_under,
|
46
|
+
short: '-w WARN_NUM',
|
47
|
+
long: '--warn WARN_NUM',
|
48
|
+
description: 'Warn on minimum number of days to SSL/TLS certificate expiration',
|
49
|
+
default: 30,
|
50
|
+
proc: proc(&:to_i)
|
51
|
+
|
52
|
+
option :crit_under,
|
53
|
+
short: '-c CRIT_NUM',
|
54
|
+
long: '--crit CRIT_NUM',
|
55
|
+
description: 'Minimum number of days to SSL/TLS certificate expiration',
|
56
|
+
default: 5,
|
57
|
+
proc: proc(&:to_i)
|
58
|
+
|
59
|
+
option :verbose,
|
60
|
+
short: '-v',
|
61
|
+
long: '--verbose',
|
62
|
+
description: 'Provide SSL/TLS certificate expiration details even when OK',
|
63
|
+
default: false
|
64
|
+
|
65
|
+
def cert_message(count, descriptor, limit)
|
66
|
+
message = (count == 1 ? '1 ELB cert is ' : "#{count} ELB certs are ")
|
67
|
+
message += "#{descriptor} #{limit} day"
|
68
|
+
message += (limit == 1 ? '' : 's') # rubocop:disable UselessAssignment
|
69
|
+
end
|
70
|
+
|
71
|
+
def aws_config
|
72
|
+
{ access_key_id: config[:aws_access_key],
|
73
|
+
secret_access_key: config[:aws_secret_access_key],
|
74
|
+
region: config[:aws_region] }
|
75
|
+
end
|
76
|
+
|
77
|
+
def run
|
78
|
+
ok_message = []
|
79
|
+
warning_message = []
|
80
|
+
critical_message = []
|
81
|
+
|
82
|
+
elb = Aws::ElasticLoadBalancing::Client.new(aws_config)
|
83
|
+
|
84
|
+
begin
|
85
|
+
elb.describe_load_balancers.load_balancer_descriptions.each do |lb|
|
86
|
+
lb.listener_descriptions.each do |listener|
|
87
|
+
elb_listener = listener['listener']
|
88
|
+
if elb_listener.protocol.to_s == 'HTTPS'
|
89
|
+
url = URI.parse("https://#{lb.dns_name}:#{elb_listener.load_balancer_port}")
|
90
|
+
http = Net::HTTP.new(url.host, url.port)
|
91
|
+
http.use_ssl = true
|
92
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
93
|
+
cert = ''
|
94
|
+
|
95
|
+
begin
|
96
|
+
http.start { cert = http.peer_cert }
|
97
|
+
rescue StandardError => e
|
98
|
+
critical "An issue occurred attempting to get cert: #{e.message}"
|
99
|
+
end
|
100
|
+
|
101
|
+
cert_days_remaining = ((cert.not_after - Time.now) / 86_400).to_i
|
102
|
+
message = sprintf '%s(%d)', lb.load_balancer_name, cert_days_remaining
|
103
|
+
|
104
|
+
if config[:crit_under] > 0 && config[:crit_under] >= cert_days_remaining
|
105
|
+
critical_message << message
|
106
|
+
elsif config[:warn_under] > 0 && config[:warn_under] >= cert_days_remaining
|
107
|
+
warning_message << message
|
108
|
+
else
|
109
|
+
ok_message << message
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
rescue StandardError => e
|
115
|
+
unknown "An error occurred processing AWS ELB API: #{e.message}"
|
116
|
+
end
|
117
|
+
|
118
|
+
if !critical_message.empty?
|
119
|
+
message = cert_message(critical_message.length, 'expiring within', config[:crit_under])
|
120
|
+
message += ': ' + critical_message.sort.join(' ')
|
121
|
+
critical message
|
122
|
+
elsif !warning_message.empty?
|
123
|
+
message = cert_message(warning_message.length, 'expiring within', config[:warn_under])
|
124
|
+
message += ': ' + warning_message.sort.join(' ')
|
125
|
+
warning message
|
126
|
+
else
|
127
|
+
message = cert_message(ok_message.length, 'valid for at least', config[:warn_under])
|
128
|
+
message += ': ' + ok_message.sort.join(' ') if config[:verbose]
|
129
|
+
ok message
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
@@ -0,0 +1,114 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# check-elb-health-fog
|
4
|
+
#
|
5
|
+
#
|
6
|
+
# DESCRIPTION:
|
7
|
+
# This plugin checks the health of an Amazon Elastic Load Balancer.
|
8
|
+
#
|
9
|
+
# OUTPUT:
|
10
|
+
# plain-text
|
11
|
+
#
|
12
|
+
# PLATFORMS:
|
13
|
+
# Linux
|
14
|
+
#
|
15
|
+
# DEPENDENCIES:
|
16
|
+
# gem: fog
|
17
|
+
# gem: sensu-plugin
|
18
|
+
#
|
19
|
+
# USAGE:
|
20
|
+
# ./check-ec2-network.rb -r ${you_region} -i ${your_instance_id} --warning-over 1000000 --critical-over 1500000
|
21
|
+
# ./check-ec2-network.rb -r ${you_region} -i ${your_instance_id} -d NetworkIn --warning-over 1000000 --critical-over 1500000
|
22
|
+
# ./check-ec2-network.rb -r ${you_region} -i ${your_instance_id} -d NetworkOut --warning-over 1000000 --critical-over 1500000
|
23
|
+
#
|
24
|
+
# NOTES:
|
25
|
+
#
|
26
|
+
# LICENSE:
|
27
|
+
# Copyright (c) 2014, Panagiotis Papadomitsos <pj@ezgr.net>
|
28
|
+
# Released under the same terms as Sensu (the MIT license); see LICENSE
|
29
|
+
# for details.
|
30
|
+
#
|
31
|
+
|
32
|
+
require 'sensu-plugin/check/cli'
|
33
|
+
require 'net/http'
|
34
|
+
require 'uri'
|
35
|
+
require 'fog/aws'
|
36
|
+
|
37
|
+
class ELBHealth < Sensu::Plugin::Check::CLI
|
38
|
+
option :aws_access_key,
|
39
|
+
short: '-a AWS_ACCESS_KEY',
|
40
|
+
long: '--aws-access-key AWS_ACCESS_KEY',
|
41
|
+
description: "AWS Access Key. Either set ENV['AWS_ACCESS_KEY'] or provide it as an option",
|
42
|
+
default: ENV['AWS_ACCESS_KEY']
|
43
|
+
|
44
|
+
option :aws_secret_access_key,
|
45
|
+
short: '-k AWS_SECRET_KEY',
|
46
|
+
long: '--aws-secret-access-key AWS_SECRET_KEY',
|
47
|
+
description: "AWS Secret Access Key. Either set ENV['AWS_SECRET_KEY'] or provide it as an option",
|
48
|
+
default: ENV['AWS_SECRET_KEY']
|
49
|
+
|
50
|
+
option :aws_region,
|
51
|
+
short: '-r AWS_REGION',
|
52
|
+
long: '--aws-region REGION',
|
53
|
+
description: 'AWS Region (such as eu-west-1). If you do not specify a region, it will be detected by the server the script is run on'
|
54
|
+
|
55
|
+
option :elb_name,
|
56
|
+
short: '-n ELB_NAME',
|
57
|
+
long: '--elb-name ELB_NAME',
|
58
|
+
description: 'The Elastic Load Balancer name of which you want to check the health',
|
59
|
+
required: true
|
60
|
+
|
61
|
+
option :instances,
|
62
|
+
short: '-i INSTANCES',
|
63
|
+
long: '--instances INSTANCES',
|
64
|
+
description: 'Comma separated list of specific instances IDs inside the ELB of which you want to check the health'
|
65
|
+
|
66
|
+
option :verbose,
|
67
|
+
short: '-v',
|
68
|
+
long: '--verbose',
|
69
|
+
description: 'Enable a little bit more verbose reports about instance health',
|
70
|
+
boolean: true,
|
71
|
+
default: false
|
72
|
+
|
73
|
+
def query_instance_region
|
74
|
+
instance_az = nil
|
75
|
+
Timeout.timeout(3) do
|
76
|
+
instance_az = Net::HTTP.get(URI('http://169.254.169.254/latest/meta-data/placement/availability-zone/'))
|
77
|
+
end
|
78
|
+
instance_az[0...-1]
|
79
|
+
rescue StandardError
|
80
|
+
raise "Cannot obtain this instance's Availability Zone. Maybe not running on AWS?"
|
81
|
+
end
|
82
|
+
|
83
|
+
def aws_config
|
84
|
+
{ aws_access_key_id: config[:aws_access_key],
|
85
|
+
aws_secret_access_key: config[:aws_secret_access_key],
|
86
|
+
region: config[:aws_region] }
|
87
|
+
end
|
88
|
+
|
89
|
+
def run
|
90
|
+
aws_region = config[:aws_region].nil? || config[:aws_region].empty? ? query_instance_region : config[:aws_region]
|
91
|
+
begin
|
92
|
+
elb = Fog::AWS::ELB.new aws_config
|
93
|
+
if config[:instances]
|
94
|
+
instances = config[:instances].split(',')
|
95
|
+
health = elb.describe_instance_health(config[:elb_name], instances)
|
96
|
+
else
|
97
|
+
health = elb.describe_instance_health(config[:elb_name])
|
98
|
+
end
|
99
|
+
unhealthy_instances = {}
|
100
|
+
health.body['DescribeInstanceHealthResult']['InstanceStates'].each do |instance|
|
101
|
+
unhealthy_instances[instance['InstanceId']] = instance['State'] unless instance['State'].eql?('InService')
|
102
|
+
end
|
103
|
+
if unhealthy_instances.empty?
|
104
|
+
ok "All instances on ELB #{aws_region}::#{config[:elb_name]} healthy!"
|
105
|
+
elsif config[:verbose]
|
106
|
+
critical "Unhealthy instances detected: #{unhealthy_instances.map { |id, state| '[' + id + '::' + state + ']' }.join(' ')}"
|
107
|
+
else
|
108
|
+
critical "Detected [#{unhealthy_instances.size}] unhealthy instances"
|
109
|
+
end
|
110
|
+
rescue StandardError => e
|
111
|
+
warning "An issue occured while communicating with the AWS EC2 API: #{e.message}"
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
@@ -0,0 +1,176 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# check-elb-health-sdk
|
4
|
+
#
|
5
|
+
# DESCRIPTION:
|
6
|
+
# This plugin checks the health of an Amazon Elastic Load Balancer or all ELBs in a given region.
|
7
|
+
#
|
8
|
+
# OUTPUT:
|
9
|
+
# plain-text
|
10
|
+
#
|
11
|
+
# PLATFORMS:
|
12
|
+
# Linux
|
13
|
+
#
|
14
|
+
# DEPENDENCIES:
|
15
|
+
# gem: aws-sdk
|
16
|
+
# gem: sensu-plugin
|
17
|
+
#
|
18
|
+
# USAGE:
|
19
|
+
# check-elb-health-sdk.rb -r region
|
20
|
+
# check-elb-health-sdk.rb -r region -n my-elb
|
21
|
+
# check-elb-health-sdk.rb -r region -n my-elb -i instance1,instance2
|
22
|
+
# check-alb-health-sdk.rb -r all
|
23
|
+
#
|
24
|
+
# Copyright (c) 2015, Benjamin Kett <bkett@umn.edu>
|
25
|
+
#
|
26
|
+
# Released under the same terms as Sensu (the MIT license); see LICENSE
|
27
|
+
# for details.
|
28
|
+
|
29
|
+
require 'sensu-plugin/check/cli'
|
30
|
+
require 'sensu-plugins-aws'
|
31
|
+
require 'aws-sdk'
|
32
|
+
|
33
|
+
class ELBHealth < Sensu::Plugin::Check::CLI
|
34
|
+
include Common
|
35
|
+
|
36
|
+
option :aws_region,
|
37
|
+
short: '-r AWS_REGION',
|
38
|
+
long: '--aws-region REGION',
|
39
|
+
description: 'AWS Region (defaults to us-east-1).',
|
40
|
+
default: 'us-east-1'
|
41
|
+
|
42
|
+
option :elb_name,
|
43
|
+
short: '-n ELB_NAME',
|
44
|
+
long: '--elb-name ELB_NAME',
|
45
|
+
description: 'The Elastic Load Balancer name of which you want to check the health'
|
46
|
+
|
47
|
+
option :instance_tag,
|
48
|
+
short: '-t',
|
49
|
+
long: '--instance-tag INSTANCE_TAG',
|
50
|
+
description: "Specify instance tag to be included in the check output. E.g. 'Name' tag"
|
51
|
+
|
52
|
+
option :instances,
|
53
|
+
short: '-i INSTANCES',
|
54
|
+
long: '--instances INSTANCES',
|
55
|
+
description: 'Comma separated list of specific instances IDs inside the ELB of which you want to check the health'
|
56
|
+
|
57
|
+
option :verbose,
|
58
|
+
short: '-v',
|
59
|
+
long: '--verbose',
|
60
|
+
description: 'Enable a little bit more verbose reports about instance health',
|
61
|
+
boolean: true,
|
62
|
+
default: false
|
63
|
+
|
64
|
+
option :warn_only,
|
65
|
+
short: '-w',
|
66
|
+
long: '--warn-only',
|
67
|
+
description: 'Warn instead of critical when unhealthy instances are found',
|
68
|
+
default: false
|
69
|
+
|
70
|
+
def aws_config
|
71
|
+
{ access_key_id: config[:aws_access_key],
|
72
|
+
secret_access_key: config[:aws_secret_access_key],
|
73
|
+
region: config[:aws_region] }
|
74
|
+
end
|
75
|
+
|
76
|
+
def elb
|
77
|
+
@elb = Aws::ElasticLoadBalancing::Client.new(aws_config)
|
78
|
+
end
|
79
|
+
|
80
|
+
def ec2
|
81
|
+
@ec2 = Aws::EC2::Client.new(aws_config)
|
82
|
+
end
|
83
|
+
|
84
|
+
def ec2_regions
|
85
|
+
Aws.partition('aws').regions.map(&:name)
|
86
|
+
end
|
87
|
+
|
88
|
+
def instances_to_check(instances)
|
89
|
+
all_instances = instances.split(',')
|
90
|
+
all_instances.map! { |instance| { instance_id: instance } }
|
91
|
+
end
|
92
|
+
|
93
|
+
def elbs
|
94
|
+
@elbs = elb.describe_load_balancers.load_balancer_descriptions.to_a
|
95
|
+
@elbs.select! { |elb| config[:elb_name].include? elb.load_balancer_name } if config[:elb_name]
|
96
|
+
@elbs
|
97
|
+
end
|
98
|
+
|
99
|
+
def check_health(elb)
|
100
|
+
unhealthy_instances = {}
|
101
|
+
instance_health = if config[:instances]
|
102
|
+
@elb.describe_instance_health(
|
103
|
+
load_balancer_name: elb.load_balancer_name,
|
104
|
+
instances: instances_to_check(config[:instances])
|
105
|
+
)
|
106
|
+
else
|
107
|
+
@elb.describe_instance_health(load_balancer_name: elb.load_balancer_name)
|
108
|
+
end
|
109
|
+
|
110
|
+
instance_health.instance_states.each do |instance_health_states|
|
111
|
+
if instance_health_states.state != 'InService'
|
112
|
+
instance_id = instance_health_states.instance_id
|
113
|
+
state_message = instance_health_states.state
|
114
|
+
|
115
|
+
if config[:instance_tag]
|
116
|
+
selected_tag = ec2.describe_tags(
|
117
|
+
filters: [{ name: 'resource-id', values: [instance_id] }]
|
118
|
+
).tags.select { |tag| tag[:key] == config[:instance_tag] }
|
119
|
+
unless selected_tag.empty?
|
120
|
+
state_message = "#{selected_tag[0][:value]}::#{instance_health_states[:state]}"
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
unhealthy_instances[instance_id] = state_message
|
125
|
+
end
|
126
|
+
end
|
127
|
+
if unhealthy_instances.empty?
|
128
|
+
'OK'
|
129
|
+
else
|
130
|
+
unhealthy_instances
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
def run
|
135
|
+
aws_regions = ec2_regions
|
136
|
+
@message = ''
|
137
|
+
critical = false
|
138
|
+
|
139
|
+
unless config[:aws_region].casecmp('all').zero?
|
140
|
+
if aws_regions.include? config[:aws_region]
|
141
|
+
aws_regions.clear.push(config[:aws_region])
|
142
|
+
else
|
143
|
+
critical 'Invalid region specified!'
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
aws_regions.each do |r| # Iterate each possible region
|
148
|
+
config[:aws_region] = r
|
149
|
+
region_critical = false
|
150
|
+
@message += (elbs.size > 1 ? config[:aws_region] + ': ' : '')
|
151
|
+
elbs.each do |elb|
|
152
|
+
result = check_health(elb)
|
153
|
+
if result != 'OK'
|
154
|
+
@message += "#{elb.load_balancer_name} unhealthy => #{result.map { |id, state| '[' + id + '::' + state + ']' }.join(' ')}. "
|
155
|
+
critical = true
|
156
|
+
region_critical = true
|
157
|
+
else
|
158
|
+
@message += "#{elb.load_balancer_name} => healthy. " unless config[:verbose] == false
|
159
|
+
end
|
160
|
+
end
|
161
|
+
if elbs.size > 1 && config[:verbose] != true && region_critical == false
|
162
|
+
@message += 'OK. '
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
if critical
|
167
|
+
if config[:warn_only]
|
168
|
+
warning @message
|
169
|
+
else
|
170
|
+
critical @message
|
171
|
+
end
|
172
|
+
else
|
173
|
+
ok @message
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|
@@ -0,0 +1,116 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# check-elb-health
|
4
|
+
#
|
5
|
+
# DESCRIPTION:
|
6
|
+
# This plugin checks the health of an Amazon Elastic Load Balancer.
|
7
|
+
#
|
8
|
+
# OUTPUT:
|
9
|
+
# plain-text
|
10
|
+
#
|
11
|
+
# PLATFORMS:
|
12
|
+
# Linux
|
13
|
+
#
|
14
|
+
# DEPENDENCIES:
|
15
|
+
# gem: right-aws
|
16
|
+
# gem: sensu-plugin
|
17
|
+
#
|
18
|
+
# USAGE:
|
19
|
+
# ./check-elb-health.rb --elb-name MyELB
|
20
|
+
#
|
21
|
+
# NOTES:
|
22
|
+
#
|
23
|
+
# LICENSE:
|
24
|
+
# Copyright (c) 2012, Panagiotis Papadomitsos <pj@ezgr.net>
|
25
|
+
# Released under the same terms as Sensu (the MIT license); see LICENSE
|
26
|
+
# for details.
|
27
|
+
#
|
28
|
+
|
29
|
+
require 'sensu-plugin/check/cli'
|
30
|
+
require 'net/http'
|
31
|
+
require 'uri'
|
32
|
+
require 'right_aws'
|
33
|
+
|
34
|
+
class ELBHealth < Sensu::Plugin::Check::CLI
|
35
|
+
option :aws_access_key,
|
36
|
+
short: '-a AWS_ACCESS_KEY',
|
37
|
+
long: '--aws-access-key AWS_ACCESS_KEY',
|
38
|
+
description: "AWS Access Key. Either set ENV['AWS_ACCESS_KEY'] or provide it as an option",
|
39
|
+
default: ENV['AWS_ACCESS_KEY']
|
40
|
+
|
41
|
+
option :aws_secret_access_key,
|
42
|
+
short: '-k AWS_SECRET_KEY',
|
43
|
+
long: '--aws-secret-access-key AWS_SECRET_KEY',
|
44
|
+
description: "AWS Secret Access Key. Either set ENV['AWS_SECRET_KEY'] or provide it as an option",
|
45
|
+
default: ENV['AWS_SECRET_KEY']
|
46
|
+
|
47
|
+
option :aws_region,
|
48
|
+
short: '-r AWS_REGION',
|
49
|
+
long: '--aws-region REGION',
|
50
|
+
description: 'AWS Region (such as eu-west-1). If you do not specify a region, it will be detected by the server the script is run on'
|
51
|
+
|
52
|
+
option :elb_name,
|
53
|
+
short: '-n ELB_NAME',
|
54
|
+
long: '--elb-name ELB_NAME',
|
55
|
+
description: 'The Elastic Load Balancer name of which you want to check the health',
|
56
|
+
required: true
|
57
|
+
|
58
|
+
option :instances,
|
59
|
+
short: '-i INSTANCES',
|
60
|
+
long: '--instances INSTANCES',
|
61
|
+
description: 'Comma separated list of specific instances IDs inside the ELB of which you want to check the health'
|
62
|
+
|
63
|
+
option :verbose,
|
64
|
+
short: '-v',
|
65
|
+
long: '--verbose',
|
66
|
+
description: 'Enable a little bit more verbose reports about instance health',
|
67
|
+
boolean: true,
|
68
|
+
default: false
|
69
|
+
|
70
|
+
def query_instance_region
|
71
|
+
instance_az = nil
|
72
|
+
Timeout.timeout(3) do
|
73
|
+
instance_az = Net::HTTP.get(URI('http://169.254.169.254/latest/meta-data/placement/availability-zone/'))
|
74
|
+
end
|
75
|
+
instance_az[0...-1]
|
76
|
+
rescue StandardError
|
77
|
+
raise "Cannot obtain this instance's Availability Zone. Maybe not running on AWS?"
|
78
|
+
end
|
79
|
+
|
80
|
+
def run
|
81
|
+
begin
|
82
|
+
aws_region = config[:aws_region].nil? || config[:aws_region].empty? ? query_instance_region : config[:aws_region]
|
83
|
+
elb = RightAws::ElbInterface.new(config[:aws_access_key], config[:aws_secret_access_key],
|
84
|
+
logger: Logger.new('/dev/null'),
|
85
|
+
cache: false,
|
86
|
+
server: "elasticloadbalancing.#{aws_region}.amazonaws.com")
|
87
|
+
if config[:instances]
|
88
|
+
instances = config[:instances].split(',')
|
89
|
+
health = elb.describe_instance_health(config[:elb_name], instances)
|
90
|
+
else
|
91
|
+
health = elb.describe_instance_health(config[:elb_name])
|
92
|
+
end
|
93
|
+
rescue StandardError => e
|
94
|
+
critical "An issue occured while communicating with the AWS EC2 API: #{e.message}"
|
95
|
+
end
|
96
|
+
# #YELLOW
|
97
|
+
unless health.empty? # rubocop:disable UnlessElse
|
98
|
+
unhealthy_instances = {}
|
99
|
+
health.each do |instance|
|
100
|
+
unhealthy_instances[instance[:instance_id]] = instance[:state] unless instance[:state].eql?('InService')
|
101
|
+
end
|
102
|
+
# #YELLOW
|
103
|
+
unless unhealthy_instances.empty? # rubocop:disable UnlessElse
|
104
|
+
if config[:verbose]
|
105
|
+
critical "Unhealthy instances detected: #{unhealthy_instances.map { |id, state| '[' + id + '::' + state + ']' }.join(' ')}"
|
106
|
+
else
|
107
|
+
critical "Detected [#{unhealthy_instances.size}] unhealthy instances"
|
108
|
+
end
|
109
|
+
else
|
110
|
+
ok "All instances on ELB #{aws_region}::#{config[:elb_name]} healthy!"
|
111
|
+
end
|
112
|
+
else
|
113
|
+
critical 'Failed to retrieve ELB instance health data'
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|