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,129 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# check-asg-instance-created
|
4
|
+
#
|
5
|
+
# DESCRIPTION:
|
6
|
+
# Check AutoScalingGroup Instances are Terminated & Launching last hour.
|
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
|
+
# all AutoScalingGroup
|
20
|
+
# ./check-asg-instance-created -r ${your_region}
|
21
|
+
# one AutoScalingGroup
|
22
|
+
# ./check-asg-instance-created -r ${your_region} -g 'AutoScalingGroupName'
|
23
|
+
#
|
24
|
+
# NOTES:
|
25
|
+
# Based heavily on Peter Hoppe check-asg-instance-created
|
26
|
+
#
|
27
|
+
# LICENSE:
|
28
|
+
# Peter Hoppe <peter.hoppe.extern@bertelsmann.de>
|
29
|
+
# Released under the same terms as Sensu (the MIT license); see LICENSE
|
30
|
+
# for details.
|
31
|
+
#
|
32
|
+
|
33
|
+
require 'sensu-plugin/check/cli'
|
34
|
+
require 'aws-sdk'
|
35
|
+
require 'sensu-plugins-aws'
|
36
|
+
|
37
|
+
class CheckAsgInstanceCreated < Sensu::Plugin::Check::CLI
|
38
|
+
include Common
|
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: ENV['AWS_REGION']
|
44
|
+
|
45
|
+
option :asg_group_name,
|
46
|
+
short: '-g G',
|
47
|
+
long: '--asg_group_name AutoScalingGroupName',
|
48
|
+
description: 'AutoScalingGroupName to check'
|
49
|
+
|
50
|
+
option :warning_limit,
|
51
|
+
short: '-w W',
|
52
|
+
long: '--warning_limit Warning Limit',
|
53
|
+
description: 'Warning Limit for launching and terminated instances',
|
54
|
+
proc: proc(&:to_i)
|
55
|
+
|
56
|
+
option :critical_limit,
|
57
|
+
short: '-c C',
|
58
|
+
long: '--critical_limit Critical Limit',
|
59
|
+
description: 'Critical Limit for launching and terminated instances',
|
60
|
+
proc: proc(&:to_i)
|
61
|
+
|
62
|
+
def asg
|
63
|
+
@asg = Aws::AutoScaling::Client.new
|
64
|
+
end
|
65
|
+
|
66
|
+
def describe_activities(asg_group_name)
|
67
|
+
asg.describe_scaling_activities(
|
68
|
+
auto_scaling_group_name: asg_group_name.to_s
|
69
|
+
)
|
70
|
+
end
|
71
|
+
|
72
|
+
def run
|
73
|
+
warning = 3
|
74
|
+
critical = 4
|
75
|
+
result_launched = ''
|
76
|
+
result_terminated = ''
|
77
|
+
instance_launching = 0
|
78
|
+
instance_terminating = 0
|
79
|
+
time_now = Time.now
|
80
|
+
time_utc_offset = time_now - time_now.utc_offset
|
81
|
+
|
82
|
+
if !config[:warning_limit].nil?
|
83
|
+
warning = config[:warning_limit]
|
84
|
+
elsif !config[:critical_limit].nil?
|
85
|
+
critical = config[:critical_limit]
|
86
|
+
end
|
87
|
+
|
88
|
+
if config[:asg_group_name].nil?
|
89
|
+
asg.describe_auto_scaling_groups.auto_scaling_groups.each do |asg_group|
|
90
|
+
describe_activities(asg_group.auto_scaling_group_name).each do |activities|
|
91
|
+
activities.activities.each do |activity|
|
92
|
+
if Time.parse(activity.start_time.inspect) > (time_utc_offset - 3600)
|
93
|
+
if activity.description.include? 'Launching'
|
94
|
+
instance_launching += 1
|
95
|
+
result_launched = " #{instance_launching} Instances Launching in AutoScalingGroup #{asg_group.auto_scaling_group_name}"
|
96
|
+
elsif activity.description.include? 'Terminating'
|
97
|
+
instance_terminating += 1
|
98
|
+
result_terminated = " #{instance_terminating} Instances Terminated in AutoScalingGroup #{asg_group.auto_scaling_group_name}"
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
else
|
105
|
+
describe_activities(config[:asg_group_name]).each do |activities|
|
106
|
+
activities.activities.each do |activity|
|
107
|
+
if Time.parse(activity.start_time.inspect) > (time_utc_offset - 3600)
|
108
|
+
if activity.description.include? 'Launching'
|
109
|
+
instance_launching += 1
|
110
|
+
result_launched = " #{instance_launching} Instances Launching in AutoScalingGroup #{config[:asg_group_name]}"
|
111
|
+
elsif activity.description.include? 'Terminating'
|
112
|
+
instance_terminating += 1
|
113
|
+
result_terminated = " #{instance_terminating} Instances Terminated in AutoScalingGroup #{config[:asg_group_name]}"
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
if instance_terminating.zero? && instance_launching.zero?
|
120
|
+
ok 'No instances Launched & Terminated last hour'
|
121
|
+
elsif instance_terminating >= critical && instance_launching >= critical
|
122
|
+
critical "#{result_launched} \n #{result_terminated}"
|
123
|
+
elsif instance_terminating >= warning && instance_launching >= warning
|
124
|
+
warning "#{result_launched} \n #{result_terminated}"
|
125
|
+
else
|
126
|
+
ok "#{result_launched} \n #{result_terminated}"
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# check-autoscaling-instances-inservice
|
4
|
+
#
|
5
|
+
# DESCRIPTION:
|
6
|
+
# Check AutoScaling Instances inService.
|
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-autoscaling-instances-inservices.rb -r ${your_region}
|
20
|
+
# one autoScalingGroup
|
21
|
+
# ./check-autoscaling-instances-inservices.rb -r ${your_region} -g 'autoScalingGroupName'
|
22
|
+
#
|
23
|
+
# NOTES:
|
24
|
+
# Based heavily on Yohei Kawahara's check-ec2-network
|
25
|
+
#
|
26
|
+
# LICENSE:
|
27
|
+
# Peter Hoppe <peter.hoppe.extern@bertelsmann.de>
|
28
|
+
# Released under the same terms as Sensu (the MIT license); see LICENSE
|
29
|
+
# for details.
|
30
|
+
#
|
31
|
+
|
32
|
+
require 'sensu-plugins-aws'
|
33
|
+
require 'sensu-plugin/check/cli'
|
34
|
+
require 'aws-sdk'
|
35
|
+
|
36
|
+
class CheckAsgInstancesInService < Sensu::Plugin::Check::CLI
|
37
|
+
include Common
|
38
|
+
option :aws_region,
|
39
|
+
short: '-r AWS_REGION',
|
40
|
+
long: '--aws-region REGION',
|
41
|
+
description: 'AWS Region (defaults to us-east-1).',
|
42
|
+
default: ENV['AWS_REGION']
|
43
|
+
|
44
|
+
option :group,
|
45
|
+
short: '-g G',
|
46
|
+
long: '--autoscaling-group GROUP',
|
47
|
+
description: 'AutoScaling group to check'
|
48
|
+
|
49
|
+
def asg
|
50
|
+
@asg ||= Aws::AutoScaling::Client.new
|
51
|
+
end
|
52
|
+
|
53
|
+
def describe_asg(asg_name)
|
54
|
+
asg.describe_auto_scaling_groups(
|
55
|
+
auto_scaling_group_names: [asg_name.to_s]
|
56
|
+
)
|
57
|
+
end
|
58
|
+
|
59
|
+
def run
|
60
|
+
warning = 0
|
61
|
+
critical = 0
|
62
|
+
instance_in_service = 0
|
63
|
+
result = ''
|
64
|
+
if config[:group].nil?
|
65
|
+
asg.describe_auto_scaling_groups.auto_scaling_groups.each do |group|
|
66
|
+
grp_name = group.auto_scaling_group_name
|
67
|
+
instance_in_service = 0
|
68
|
+
group.instances.each do |instance|
|
69
|
+
if instance.lifecycle_state == 'InService'
|
70
|
+
instance_in_service += 1
|
71
|
+
end
|
72
|
+
end
|
73
|
+
if instance_in_service.zero?
|
74
|
+
critical = 1
|
75
|
+
result += "#{grp_name}: no Instances inService #{instance_in_service} \n"
|
76
|
+
elsif instance_in_service < group.min_size
|
77
|
+
warning = 1
|
78
|
+
result += "#{grp_name} Intance are not okay #{instance_in_service} \n"
|
79
|
+
else
|
80
|
+
result += "#{grp_name} Intance are inService #{instance_in_service} \n"
|
81
|
+
end
|
82
|
+
end
|
83
|
+
else
|
84
|
+
selected_group = describe_asg(config[:group])[0][0]
|
85
|
+
min_size = selected_group.min_size
|
86
|
+
selected_group.instances.each do |instance|
|
87
|
+
if instance.lifecycle_state == 'InService'
|
88
|
+
instance_in_service += 1
|
89
|
+
end
|
90
|
+
end
|
91
|
+
if instance_in_service.zero?
|
92
|
+
critical = 1
|
93
|
+
result += "#{config[:group]}: no Instances inService #{instance_in_service} \n"
|
94
|
+
elsif instance_in_service < min_size
|
95
|
+
warning = 1
|
96
|
+
result += "#{config[:group]} Intance are not okay #{instance_in_service} \n"
|
97
|
+
else
|
98
|
+
result += "#{config[:group]} Intance are inService #{instance_in_service} \n"
|
99
|
+
end
|
100
|
+
end
|
101
|
+
if critical == 1
|
102
|
+
critical result
|
103
|
+
elsif warning == 1
|
104
|
+
warning result
|
105
|
+
else
|
106
|
+
ok result
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
@@ -0,0 +1,160 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# check-autoscaling-cpucredits
|
4
|
+
#
|
5
|
+
# DESCRIPTION:
|
6
|
+
# Check AutoScaling CPU Credits through CloudWatch API.
|
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-autoscaling-cpucredits.rb -r ${your_region} --warning-under 100 --critical-under 50
|
20
|
+
#
|
21
|
+
# NOTES:
|
22
|
+
# Based heavily on Yohei Kawahara's check-ec2-network
|
23
|
+
#
|
24
|
+
# LICENSE:
|
25
|
+
# Gavin Hamill <gavin@bashton.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 'aws-sdk'
|
32
|
+
|
33
|
+
class CheckEc2CpuCredits < Sensu::Plugin::Check::CLI
|
34
|
+
option :aws_access_key,
|
35
|
+
short: '-a AWS_ACCESS_KEY',
|
36
|
+
long: '--aws-access-key AWS_ACCESS_KEY',
|
37
|
+
description: "AWS Access Key. Either set ENV['AWS_ACCESS_KEY'] or provide it as an option",
|
38
|
+
default: ENV['AWS_ACCESS_KEY']
|
39
|
+
|
40
|
+
option :aws_secret_access_key,
|
41
|
+
short: '-k AWS_SECRET_KEY',
|
42
|
+
long: '--aws-secret-access-key AWS_SECRET_KEY',
|
43
|
+
description: "AWS Secret Access Key. Either set ENV['AWS_SECRET_KEY'] or provide it as an option",
|
44
|
+
default: ENV['AWS_SECRET_KEY']
|
45
|
+
|
46
|
+
option :aws_region,
|
47
|
+
short: '-r AWS_REGION',
|
48
|
+
long: '--aws-region REGION',
|
49
|
+
description: 'AWS Region (defaults to us-east-1).',
|
50
|
+
default: 'us-east-1'
|
51
|
+
|
52
|
+
option :group,
|
53
|
+
short: '-g G',
|
54
|
+
long: '--autoscaling-group GROUP',
|
55
|
+
description: 'AutoScaling group to check'
|
56
|
+
|
57
|
+
option :end_time,
|
58
|
+
short: '-t T',
|
59
|
+
long: '--end-time TIME',
|
60
|
+
default: Time.now,
|
61
|
+
description: 'CloudWatch metric statistics end time'
|
62
|
+
|
63
|
+
option :period,
|
64
|
+
short: '-p N',
|
65
|
+
long: '--period SECONDS',
|
66
|
+
default: 60,
|
67
|
+
description: 'CloudWatch metric statistics period'
|
68
|
+
|
69
|
+
option :countmetric,
|
70
|
+
short: '-d M',
|
71
|
+
long: '--countmetric METRIC',
|
72
|
+
default: 'CPUCreditBalance',
|
73
|
+
description: 'Select any CloudWatch _Count_ based metric (Status Checks / CPU Credits)'
|
74
|
+
|
75
|
+
option :warning_under,
|
76
|
+
short: '-w N',
|
77
|
+
long: '--warning-under VALUE',
|
78
|
+
description: 'Issue a warning if the CloudWatch _Count_ based metric (Status Check / CPU Credits) is below this value'
|
79
|
+
|
80
|
+
option :critical_under,
|
81
|
+
short: '-c N',
|
82
|
+
long: '--critical-under VALUE',
|
83
|
+
description: 'Issue a critical if the CloudWatch _Count_ based metric (Status Check / CPU Credits) is below this value'
|
84
|
+
|
85
|
+
def aws_config
|
86
|
+
{ access_key_id: config[:aws_access_key],
|
87
|
+
secret_access_key: config[:aws_secret_access_key],
|
88
|
+
region: config[:aws_region] }
|
89
|
+
end
|
90
|
+
|
91
|
+
def asg
|
92
|
+
@asg ||= Aws::AutoScaling::Client.new aws_config
|
93
|
+
end
|
94
|
+
|
95
|
+
def cloud_watch
|
96
|
+
@cloud_watch ||= Aws::CloudWatch::Client.new aws_config
|
97
|
+
end
|
98
|
+
|
99
|
+
def get_count_metric(group)
|
100
|
+
cloud_watch.get_metric_statistics(
|
101
|
+
namespace: 'AWS/EC2',
|
102
|
+
metric_name: config[:countmetric].to_s,
|
103
|
+
dimensions: [
|
104
|
+
{
|
105
|
+
name: 'AutoScalingGroupName',
|
106
|
+
value: group
|
107
|
+
}
|
108
|
+
],
|
109
|
+
start_time: config[:end_time] - 600,
|
110
|
+
end_time: config[:end_time],
|
111
|
+
statistics: ['Average'],
|
112
|
+
period: config[:period],
|
113
|
+
unit: 'Count'
|
114
|
+
)
|
115
|
+
end
|
116
|
+
|
117
|
+
def latest_value(value)
|
118
|
+
value.datapoints[0][:average].to_f unless value.datapoints[0].nil?
|
119
|
+
end
|
120
|
+
|
121
|
+
def check_metric(group)
|
122
|
+
metric = get_count_metric group
|
123
|
+
latest_value metric unless metric.nil?
|
124
|
+
end
|
125
|
+
|
126
|
+
def check_group(group, reportstring, warnflag, critflag)
|
127
|
+
metric_value = check_metric group
|
128
|
+
if !metric_value.nil? && metric_value < config[:critical_under].to_f
|
129
|
+
critflag = 1
|
130
|
+
reportstring = reportstring + group + ': ' + metric_value.to_s + ' '
|
131
|
+
elsif !metric_value.nil? && metric_value < config[:warning_under].to_f
|
132
|
+
warnflag = 1
|
133
|
+
reportstring = reportstring + group + ': ' + metric_value.to_s + ' '
|
134
|
+
end
|
135
|
+
[reportstring, warnflag, critflag]
|
136
|
+
end
|
137
|
+
|
138
|
+
def run
|
139
|
+
warnflag = 0
|
140
|
+
critflag = 0
|
141
|
+
reportstring = ''
|
142
|
+
if config[:group].nil?
|
143
|
+
asg.describe_auto_scaling_groups.auto_scaling_groups.each do |group|
|
144
|
+
if group.desired_capacity > 0
|
145
|
+
reportstring, warnflag, critflag = check_group(group.auto_scaling_group_name, reportstring, warnflag, critflag)
|
146
|
+
end
|
147
|
+
end
|
148
|
+
else
|
149
|
+
reportstring, warnflag, critflag = check_group(config[:group], reportstring, warnflag, critflag)
|
150
|
+
end
|
151
|
+
|
152
|
+
if critflag == 1
|
153
|
+
critical reportstring
|
154
|
+
elsif warnflag == 1
|
155
|
+
warning reportstring
|
156
|
+
else
|
157
|
+
ok 'All checked AutoScaling Groups are cool'
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
@@ -0,0 +1,123 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# check-beanstalk-elb-metric
|
4
|
+
#
|
5
|
+
# DESCRIPTION:
|
6
|
+
# This plugin finds the desired ELB in a beanstalk environment and queries
|
7
|
+
# for the requested cloudwatch metric for that ELB
|
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-beanstalk-elb-metric -e MyAppEnv -m Latency -c 100
|
21
|
+
#
|
22
|
+
# NOTES:
|
23
|
+
#
|
24
|
+
# LICENSE:
|
25
|
+
# Andrew Matheny
|
26
|
+
# Released under the same terms as Sensu (the MIT license); see LICENSE
|
27
|
+
# for details.
|
28
|
+
#
|
29
|
+
|
30
|
+
require 'sensu-plugins-aws/cloudwatch-common'
|
31
|
+
require 'sensu-plugin/check/cli'
|
32
|
+
require 'aws-sdk'
|
33
|
+
|
34
|
+
class BeanstalkELBCheck < Sensu::Plugin::Check::CLI
|
35
|
+
option :environment,
|
36
|
+
description: 'Application environment name',
|
37
|
+
short: '-e ENVIRONMENT_NAME',
|
38
|
+
long: '--environment ENVIRONMENT_NAME',
|
39
|
+
required: true
|
40
|
+
|
41
|
+
option :elb_idx,
|
42
|
+
description: 'Index of ELB. Useful for multiple ELB environments',
|
43
|
+
short: '-i ELB_NUM',
|
44
|
+
long: '--elb-idx ELB_NUM',
|
45
|
+
default: 0,
|
46
|
+
proc: proc(&:to_i)
|
47
|
+
|
48
|
+
option :metric_name,
|
49
|
+
description: 'ELB CloudWatch Metric',
|
50
|
+
short: '-m METRIC_NAME',
|
51
|
+
long: '--metric METRIC_NAME',
|
52
|
+
required: true
|
53
|
+
|
54
|
+
option :period,
|
55
|
+
description: 'CloudWatch metric statistics period. Must be a multiple of 60',
|
56
|
+
short: '-p N',
|
57
|
+
long: '--period SECONDS',
|
58
|
+
default: 60,
|
59
|
+
proc: proc(&:to_i)
|
60
|
+
|
61
|
+
option :statistics,
|
62
|
+
short: '-s N',
|
63
|
+
long: '--statistics NAME',
|
64
|
+
default: 'Average',
|
65
|
+
description: 'CloudWatch statistics method'
|
66
|
+
|
67
|
+
option :unit,
|
68
|
+
short: '-u UNIT',
|
69
|
+
long: '--unit UNIT',
|
70
|
+
description: 'CloudWatch metric unit'
|
71
|
+
|
72
|
+
option :critical,
|
73
|
+
description: 'Trigger a critical when value is over VALUE',
|
74
|
+
short: '-c VALUE',
|
75
|
+
long: '--critical VALUE',
|
76
|
+
proc: proc(&:to_f),
|
77
|
+
required: true
|
78
|
+
|
79
|
+
option :warning,
|
80
|
+
description: 'Trigger a warning when value is over VALUE',
|
81
|
+
short: '-w VALUE',
|
82
|
+
long: '--warning VALUE',
|
83
|
+
proc: proc(&:to_f)
|
84
|
+
|
85
|
+
option :compare,
|
86
|
+
description: 'Comparision operator for threshold: equal, not, greater, less',
|
87
|
+
short: '-o OPERATION',
|
88
|
+
long: '--operator OPERATION',
|
89
|
+
default: 'greater'
|
90
|
+
|
91
|
+
option :no_data_ok,
|
92
|
+
short: '-n',
|
93
|
+
long: '--allow-no-data',
|
94
|
+
description: 'Returns ok if no data is returned from the metric',
|
95
|
+
boolean: true,
|
96
|
+
default: false
|
97
|
+
|
98
|
+
include CloudwatchCommon
|
99
|
+
|
100
|
+
def metric_desc
|
101
|
+
@metric_desc ||= "BeanstalkELB/#{config[:environment]}/#{elb_name}/#{config[:metric_name]}"
|
102
|
+
end
|
103
|
+
|
104
|
+
def elb_name
|
105
|
+
@elb_name ||= Aws::ElasticBeanstalk::Client.new
|
106
|
+
.describe_environment_resources(environment_name: config[:environment])
|
107
|
+
.environment_resources
|
108
|
+
.load_balancers[config[:elb_idx]]
|
109
|
+
.name
|
110
|
+
end
|
111
|
+
|
112
|
+
def run
|
113
|
+
new_config = config.clone
|
114
|
+
new_config[:namespace] = 'AWS/ELB'
|
115
|
+
new_config[:dimensions] = [
|
116
|
+
{
|
117
|
+
name: 'LoadBalancerName',
|
118
|
+
value: elb_name
|
119
|
+
}
|
120
|
+
]
|
121
|
+
check new_config
|
122
|
+
end
|
123
|
+
end
|