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,194 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# check-dynamodb-capacity
|
4
|
+
#
|
5
|
+
# DESCRIPTION:
|
6
|
+
# Check DynamoDB statuses by CloudWatch and DynamoDB 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
|
+
# Warning if any table's consumed read/write capacity is over 80%, critical if over 90%
|
20
|
+
# check-dynamodb-capacity --warning-over 80 --critical-over 90
|
21
|
+
#
|
22
|
+
# Critical if session table's consumed read capacity is over 90%, maximum of last one hour
|
23
|
+
# check-dynamodb-capacity --table_names session --capacity-for read --critical-over 90 --statistics maximum --period 3600
|
24
|
+
#
|
25
|
+
# NOTES:
|
26
|
+
#
|
27
|
+
# LICENSE:
|
28
|
+
# Copyright 2014 github.com/y13i
|
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 'time'
|
36
|
+
|
37
|
+
class CheckDynamoDB < 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 (defaults to us-east-1).',
|
54
|
+
default: 'us-east-1'
|
55
|
+
|
56
|
+
option :table_names,
|
57
|
+
short: '-t N',
|
58
|
+
long: '--table-names NAMES',
|
59
|
+
proc: proc { |a| a.split(/[,;]\s*/) },
|
60
|
+
description: 'Table names to check. Separated by , or ;. If not specified, check all tables'
|
61
|
+
|
62
|
+
option :end_time,
|
63
|
+
short: '-t T',
|
64
|
+
long: '--end-time TIME',
|
65
|
+
default: Time.now,
|
66
|
+
proc: proc { |a| Time.parse a },
|
67
|
+
description: 'CloudWatch metric statistics end time'
|
68
|
+
|
69
|
+
option :period,
|
70
|
+
short: '-p N',
|
71
|
+
long: '--period SECONDS',
|
72
|
+
default: 60,
|
73
|
+
# #YELLOW
|
74
|
+
proc: proc(&:to_i),
|
75
|
+
description: 'CloudWatch metric statistics period'
|
76
|
+
|
77
|
+
option :statistics,
|
78
|
+
short: '-S N',
|
79
|
+
long: '--statistics NAME',
|
80
|
+
default: :average,
|
81
|
+
proc: proc { |a| a.downcase.intern },
|
82
|
+
description: 'CloudWatch statistics method'
|
83
|
+
|
84
|
+
option :capacity_for,
|
85
|
+
short: '-c N',
|
86
|
+
long: '--capacity-for NAME',
|
87
|
+
default: %i[read write],
|
88
|
+
proc: proc { |a| a.split(/[,;]\s*/).map { |n| n.downcase.intern } },
|
89
|
+
description: 'Read/Write (or both) capacity to check.'
|
90
|
+
|
91
|
+
%w[warning critical].each do |severity|
|
92
|
+
option :"#{severity}_over",
|
93
|
+
long: "--#{severity}-over N",
|
94
|
+
# #YELLOW
|
95
|
+
proc: proc(&:to_f),
|
96
|
+
description: "Trigger a #{severity} if consumed capacity is over a percentage"
|
97
|
+
end
|
98
|
+
|
99
|
+
def aws_config
|
100
|
+
{ access_key_id: config[:aws_access_key],
|
101
|
+
secret_access_key: config[:aws_secret_access_key],
|
102
|
+
region: config[:aws_region] }
|
103
|
+
end
|
104
|
+
|
105
|
+
def dynamo_db
|
106
|
+
@dynamo_db ||= Aws::DynamoDB::Client.new aws_config
|
107
|
+
end
|
108
|
+
|
109
|
+
def cloud_watch
|
110
|
+
@cloud_watch ||= Aws::CloudWatch::Client.new aws_config
|
111
|
+
end
|
112
|
+
|
113
|
+
def tables
|
114
|
+
return @tables if @tables
|
115
|
+
table_names = dynamo_db.list_tables.table_names.to_a
|
116
|
+
table_names.select! { |table_name| config[:table_names].include? table_name } if config[:table_names]
|
117
|
+
@tables = []
|
118
|
+
table_names.each do |table_name|
|
119
|
+
@tables.push(dynamo_db.describe_table(
|
120
|
+
table_name: table_name
|
121
|
+
).table)
|
122
|
+
end
|
123
|
+
@tables
|
124
|
+
end
|
125
|
+
|
126
|
+
def cloud_watch_metric(metric_name, table_name)
|
127
|
+
cloud_watch.get_metric_statistics(
|
128
|
+
namespace: 'AWS/DynamoDB',
|
129
|
+
metric_name: metric_name,
|
130
|
+
dimensions: [
|
131
|
+
{
|
132
|
+
name: 'TableName',
|
133
|
+
value: table_name
|
134
|
+
}
|
135
|
+
],
|
136
|
+
start_time: config[:end_time] - config[:period],
|
137
|
+
end_time: config[:end_time],
|
138
|
+
statistics: [config[:statistics].to_s.capitalize],
|
139
|
+
period: config[:period],
|
140
|
+
unit: 'Count'
|
141
|
+
)
|
142
|
+
end
|
143
|
+
|
144
|
+
def latest_value(metric)
|
145
|
+
metric.datapoints.sort_by { |datapoint| datapoint[:timestamp] }.last[config[:statistics]]
|
146
|
+
end
|
147
|
+
|
148
|
+
def flag_alert(severity, message)
|
149
|
+
@severities[severity] = true
|
150
|
+
@message += message
|
151
|
+
end
|
152
|
+
|
153
|
+
def check_capacity(table)
|
154
|
+
config[:capacity_for].each do |r_or_w|
|
155
|
+
metric_name = "Consumed#{r_or_w.to_s.capitalize}CapacityUnits"
|
156
|
+
metric = cloud_watch_metric metric_name, table.table_name
|
157
|
+
metric_value = begin
|
158
|
+
latest_value(metric)
|
159
|
+
rescue StandardError
|
160
|
+
0
|
161
|
+
end
|
162
|
+
percentage = metric_value / table.provisioned_throughput.send("#{r_or_w}_capacity_units").to_f * 100
|
163
|
+
|
164
|
+
@severities.each_key do |severity|
|
165
|
+
threshold = config[:"#{severity}_over"]
|
166
|
+
next unless threshold
|
167
|
+
next if percentage < threshold
|
168
|
+
flag_alert severity, "; On table #{table.table_name} consumed #{r_or_w} capacity is #{sprintf '%.2f', percentage}% (expected_lower_than #{threshold})"
|
169
|
+
break
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
def run
|
175
|
+
@message = "#{tables.size} tables total"
|
176
|
+
@severities = {
|
177
|
+
critical: false,
|
178
|
+
warning: false
|
179
|
+
}
|
180
|
+
|
181
|
+
tables.each { |table| check_capacity table }
|
182
|
+
|
183
|
+
@message += "; (#{config[:statistics].to_s.capitalize} within #{config[:period]} seconds "
|
184
|
+
@message += "between #{config[:end_time] - config[:period]} to #{config[:end_time]})"
|
185
|
+
|
186
|
+
if @severities[:critical]
|
187
|
+
critical @message
|
188
|
+
elsif @severities[:warning]
|
189
|
+
warning @message
|
190
|
+
else
|
191
|
+
ok @message
|
192
|
+
end
|
193
|
+
end
|
194
|
+
end
|
@@ -0,0 +1,188 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# check-dynamodb-throttle
|
4
|
+
#
|
5
|
+
# DESCRIPTION:
|
6
|
+
# Check DynamoDB throttle by CloudWatch and DynamoDB 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
|
+
# Critical if session table's read throttle is over 50 for the last 5 minutes
|
20
|
+
# check-dynamodb-throttle --table_names session --throttle-for read --critical-over 50 --statistics sum --period 300
|
21
|
+
#
|
22
|
+
# NOTES:
|
23
|
+
#
|
24
|
+
# LICENSE:
|
25
|
+
# Copyright 2014 Sonian, Inc. and contributors. <support@sensuapp.org>
|
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
|
+
require 'time'
|
33
|
+
|
34
|
+
class CheckDynamoDB < 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 (defaults to us-east-1).',
|
51
|
+
default: 'us-east-1'
|
52
|
+
|
53
|
+
option :table_names,
|
54
|
+
short: '-t N',
|
55
|
+
long: '--table-names NAMES',
|
56
|
+
proc: proc { |a| a.split(/[,;]\s*/) },
|
57
|
+
description: 'Table names to check. Separated by , or ;. If not specified, check all tables'
|
58
|
+
|
59
|
+
option :end_time,
|
60
|
+
short: '-t T',
|
61
|
+
long: '--end-time TIME',
|
62
|
+
default: Time.now,
|
63
|
+
proc: proc { |a| Time.parse a },
|
64
|
+
description: 'CloudWatch metric statistics end time'
|
65
|
+
|
66
|
+
option :period,
|
67
|
+
short: '-p N',
|
68
|
+
long: '--period SECONDS',
|
69
|
+
default: 60,
|
70
|
+
proc: proc(&:to_i),
|
71
|
+
description: 'CloudWatch metric statistics period'
|
72
|
+
|
73
|
+
option :statistics,
|
74
|
+
short: '-S N',
|
75
|
+
long: '--statistics NAME',
|
76
|
+
default: :average,
|
77
|
+
proc: proc { |a| a.downcase.intern },
|
78
|
+
description: 'CloudWatch statistics method'
|
79
|
+
|
80
|
+
option :throttle_for,
|
81
|
+
short: '-c N',
|
82
|
+
long: '--throttle-for NAME',
|
83
|
+
default: %i[read write],
|
84
|
+
proc: proc { |a| a.split(/[,;]\s*/).map { |n| n.downcase.intern } },
|
85
|
+
description: 'Read/Write (or both) throttle to check.'
|
86
|
+
|
87
|
+
%w[warning critical].each do |severity|
|
88
|
+
option :"#{severity}_over",
|
89
|
+
long: "--#{severity}-over N",
|
90
|
+
proc: proc(&:to_f),
|
91
|
+
description: "Trigger a #{severity} if throttle is over the given number"
|
92
|
+
end
|
93
|
+
|
94
|
+
def aws_config
|
95
|
+
{ access_key_id: config[:aws_access_key],
|
96
|
+
secret_access_key: config[:aws_secret_access_key],
|
97
|
+
region: config[:aws_region] }
|
98
|
+
end
|
99
|
+
|
100
|
+
def dynamo_db
|
101
|
+
@dynamo_db ||= Aws::DynamoDB::Client.new aws_config
|
102
|
+
end
|
103
|
+
|
104
|
+
def cloud_watch
|
105
|
+
@cloud_watch ||= Aws::CloudWatch::Client.new aws_config
|
106
|
+
end
|
107
|
+
|
108
|
+
def tables
|
109
|
+
return @tables if @tables
|
110
|
+
table_names = dynamo_db.list_tables.table_names.to_a
|
111
|
+
table_names.select! { |table_name| config[:table_names].include? table_name } if config[:table_names]
|
112
|
+
@tables = []
|
113
|
+
table_names.each do |table_name|
|
114
|
+
@tables.push(dynamo_db.describe_table(
|
115
|
+
table_name: table_name
|
116
|
+
).table)
|
117
|
+
end
|
118
|
+
@tables
|
119
|
+
end
|
120
|
+
|
121
|
+
def cloud_watch_metric(metric_name, table_name)
|
122
|
+
cloud_watch.get_metric_statistics(
|
123
|
+
namespace: 'AWS/DynamoDB',
|
124
|
+
metric_name: metric_name,
|
125
|
+
dimensions: [
|
126
|
+
{
|
127
|
+
name: 'TableName',
|
128
|
+
value: table_name
|
129
|
+
}
|
130
|
+
],
|
131
|
+
start_time: config[:end_time] - config[:period],
|
132
|
+
end_time: config[:end_time],
|
133
|
+
statistics: [config[:statistics].to_s.capitalize],
|
134
|
+
period: config[:period],
|
135
|
+
unit: 'Count'
|
136
|
+
)
|
137
|
+
end
|
138
|
+
|
139
|
+
def latest_value(metric)
|
140
|
+
metric.datapoints.sort_by { |datapoint| datapoint[:timestamp] }.last[config[:statistics]]
|
141
|
+
end
|
142
|
+
|
143
|
+
def flag_alert(severity, message)
|
144
|
+
@severities[severity] = true
|
145
|
+
@message += message
|
146
|
+
end
|
147
|
+
|
148
|
+
def check_throttle(table)
|
149
|
+
config[:throttle_for].each do |r_or_w|
|
150
|
+
metric_name = "#{r_or_w.to_s.capitalize}ThrottleEvents"
|
151
|
+
metric = cloud_watch_metric metric_name, table.table_name
|
152
|
+
metric_value = begin
|
153
|
+
latest_value(metric)
|
154
|
+
rescue StandardError
|
155
|
+
0
|
156
|
+
end
|
157
|
+
|
158
|
+
@severities.each_key do |severity|
|
159
|
+
threshold = config[:"#{severity}_over"]
|
160
|
+
next unless threshold
|
161
|
+
next if metric_value < threshold
|
162
|
+
flag_alert severity, "; On table #{table.table_name} #{r_or_w.to_s.capitalize}ThrottleEvents is #{metric_value} (higher_than #{threshold})"
|
163
|
+
break
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
def run
|
169
|
+
@message = "#{tables.size} tables total"
|
170
|
+
@severities = {
|
171
|
+
critical: false,
|
172
|
+
warning: false
|
173
|
+
}
|
174
|
+
|
175
|
+
tables.each { |table| check_throttle table }
|
176
|
+
|
177
|
+
@message += "; (#{config[:statistics].to_s.capitalize} within #{config[:period]} seconds "
|
178
|
+
@message += "between #{config[:end_time] - config[:period]} to #{config[:end_time]})"
|
179
|
+
|
180
|
+
if @severities[:critical]
|
181
|
+
critical @message
|
182
|
+
elsif @severities[:warning]
|
183
|
+
warning @message
|
184
|
+
else
|
185
|
+
ok @message
|
186
|
+
end
|
187
|
+
end
|
188
|
+
end
|
@@ -0,0 +1,143 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# check-ebs-burst-limit
|
4
|
+
#
|
5
|
+
# DESCRIPTION:
|
6
|
+
# Check EC2 Volumes for volumes with low burst balance
|
7
|
+
# Optionally check only volumes attached to the current instance
|
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-ebs-burst-limit.rb -r ${you_region}
|
21
|
+
# ./check-ebs-burst-limit.rb -r ${you_region} -c 50
|
22
|
+
# ./check-ebs-burst-limit.rb -r ${you_region} -c 50 -t Name
|
23
|
+
# ./check-ebs-burst-limit.rb -r ${you_region} -w 50 -c 10
|
24
|
+
# ./check-ebs-burst-limit.rb -r ${you_region} -w 50 -c 10 -f "{name:tag-value,values:[infrastructure]}"
|
25
|
+
# ./check-ebs-burst-limit.rb -r ${you_region} -w 50 -c 10 -f "{name:tag-value,values:[infrastructure]}" -t Name
|
26
|
+
#
|
27
|
+
# LICENSE:
|
28
|
+
# Barry Martin <nyxcharon@gmail.com>
|
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 'sensu-plugins-aws'
|
35
|
+
require 'sensu-plugins-aws/filter'
|
36
|
+
require 'aws-sdk'
|
37
|
+
require 'net/http'
|
38
|
+
|
39
|
+
class CheckEbsBurstLimit < Sensu::Plugin::Check::CLI
|
40
|
+
include CloudwatchCommon
|
41
|
+
include Filter
|
42
|
+
|
43
|
+
option :aws_region,
|
44
|
+
short: '-r R',
|
45
|
+
long: '--region REGION',
|
46
|
+
description: 'AWS region, will be overridden by the -s option',
|
47
|
+
default: 'us-east-1'
|
48
|
+
|
49
|
+
option :tag,
|
50
|
+
description: 'Add volume TAG value to warn/critical message.',
|
51
|
+
short: '-t TAG',
|
52
|
+
long: '--tag TAG'
|
53
|
+
|
54
|
+
option :critical,
|
55
|
+
description: 'Trigger a critical when ebs burst limit is under VALUE',
|
56
|
+
short: '-c VALUE',
|
57
|
+
long: '--critical VALUE',
|
58
|
+
proc: proc(&:to_f),
|
59
|
+
required: true
|
60
|
+
|
61
|
+
option :warning,
|
62
|
+
description: 'Trigger a warning when ebs burst limit is under VALUE',
|
63
|
+
short: '-w VALUE',
|
64
|
+
long: '--warning VALUE',
|
65
|
+
proc: proc(&:to_f)
|
66
|
+
|
67
|
+
option :check_self,
|
68
|
+
short: '-s',
|
69
|
+
long: '--check-self',
|
70
|
+
description: 'Only check the instance on which this plugin is being run - this overrides the -r option and uses the region of the current instance',
|
71
|
+
boolean: true,
|
72
|
+
default: false
|
73
|
+
|
74
|
+
option :filter,
|
75
|
+
short: '-f FILTER',
|
76
|
+
long: '--filter FILTER',
|
77
|
+
description: 'String representation of the filter to apply',
|
78
|
+
default: '{}'
|
79
|
+
|
80
|
+
def volume_tag(volume, tag_name)
|
81
|
+
tag = volume.tags.select { |t| t.key == tag_name }.first
|
82
|
+
tag.nil? ? '' : tag.value
|
83
|
+
end
|
84
|
+
|
85
|
+
def run
|
86
|
+
errors = []
|
87
|
+
|
88
|
+
volume_filters = Filter.parse(config[:filter])
|
89
|
+
|
90
|
+
# Set the describe-volumes filter depending on whether -s was specified
|
91
|
+
if config[:check_self] == true
|
92
|
+
# Get the region from the availability zone, and override the -r option
|
93
|
+
my_instance_az = Net::HTTP.get(URI.parse('http://169.254.169.254/latest/meta-data/placement/availability-zone'))
|
94
|
+
Aws.config[:region] = my_instance_az.chop
|
95
|
+
my_instance_id = Net::HTTP.get(URI.parse('http://169.254.169.254/latest/meta-data/instance-id'))
|
96
|
+
volume_filters.push(
|
97
|
+
name: 'attachment.instance-id',
|
98
|
+
values: [my_instance_id]
|
99
|
+
)
|
100
|
+
else
|
101
|
+
# The -s option was not specified, look at all volumes which are attached
|
102
|
+
volume_filters.push(
|
103
|
+
name: 'attachment.status',
|
104
|
+
values: ['attached']
|
105
|
+
)
|
106
|
+
end
|
107
|
+
|
108
|
+
ec2 = Aws::EC2::Client.new
|
109
|
+
volumes = ec2.describe_volumes(
|
110
|
+
filters: volume_filters
|
111
|
+
)
|
112
|
+
config[:metric_name] = 'BurstBalance'
|
113
|
+
config[:namespace] = 'AWS/EBS'
|
114
|
+
config[:statistics] = 'Average'
|
115
|
+
config[:period] = 120
|
116
|
+
crit = false
|
117
|
+
should_warn = false
|
118
|
+
|
119
|
+
volumes[:volumes].each do |volume|
|
120
|
+
config[:dimensions] = []
|
121
|
+
config[:dimensions] << { name: 'VolumeId', value: volume[:volume_id] }
|
122
|
+
volume_tag = config[:tag] ? " (#{volume_tag(volume, config[:tag])})" : ''
|
123
|
+
resp = client.get_metric_statistics(metrics_request(config))
|
124
|
+
unless resp.datapoints.first.nil?
|
125
|
+
if resp.datapoints.first[:average] < config[:critical]
|
126
|
+
errors << "#{volume[:volume_id]}#{volume_tag} #{resp.datapoints.first[:average]}"
|
127
|
+
crit = true
|
128
|
+
elsif config[:warning] && resp.datapoints.first[:average] < config[:warning]
|
129
|
+
errors << "#{volume[:volume_id]}#{volume_tag} #{resp.datapoints.first[:average]}"
|
130
|
+
should_warn = true
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
if crit
|
136
|
+
critical "Volume(s) have exceeded critical threshold: #{errors}"
|
137
|
+
elsif should_warn
|
138
|
+
warning "Volume(s) have exceeded warning threshold: #{errors}"
|
139
|
+
else
|
140
|
+
ok 'No volume(s) exceed thresholds'
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|