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,199 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# check-cloudwatch-composite-metric
|
4
|
+
#
|
5
|
+
# DESCRIPTION:
|
6
|
+
# This plugin retrieves a couple of values of two cloudwatch metrics,
|
7
|
+
# computes a percentage value based on the numerator metric and the denomicator metric
|
8
|
+
# and triggers alarms based on the thresholds specified.
|
9
|
+
# This plugin is an extension to the Andrew Matheny's check-cloudwatch-metric plugin
|
10
|
+
# and uses the CloudwatchCommon lib, extended as well.
|
11
|
+
#
|
12
|
+
# OUTPUT:
|
13
|
+
# plain-text
|
14
|
+
#
|
15
|
+
# PLATFORMS:
|
16
|
+
# Linux
|
17
|
+
#
|
18
|
+
# DEPENDENCIES:
|
19
|
+
# gem: aws-sdk
|
20
|
+
# gem: sensu-plugin
|
21
|
+
#
|
22
|
+
# USAGE:
|
23
|
+
# ./check-cloudwatch-composite-metric.rb --namespace AWS/ELB -N HTTPCode_Backend_4XX -D RequestCount --dimensions LoadBalancerName=test-elb --period 60 --statistics Maximum --operator equal --critical 0
|
24
|
+
#
|
25
|
+
# NOTES:
|
26
|
+
#
|
27
|
+
# LICENSE:
|
28
|
+
# Cornel Foltea
|
29
|
+
# Released under the same terms as Sensu (the MIT license); see LICENSE
|
30
|
+
# for details.
|
31
|
+
#
|
32
|
+
|
33
|
+
require 'sensu-plugins-aws'
|
34
|
+
require 'sensu-plugin/check/cli'
|
35
|
+
require 'aws-sdk'
|
36
|
+
|
37
|
+
class CloudWatchCompositeMetricCheck < Sensu::Plugin::Check::CLI
|
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: 'us-east-1'
|
43
|
+
|
44
|
+
option :namespace,
|
45
|
+
description: 'CloudWatch namespace for metric',
|
46
|
+
short: '-n NAME',
|
47
|
+
long: '--namespace NAME',
|
48
|
+
default: 'AWS/EC2'
|
49
|
+
|
50
|
+
option :numerator_metric_name,
|
51
|
+
description: 'Numerator metric name',
|
52
|
+
short: '-N NAME',
|
53
|
+
long: '--numerator-metric NAME',
|
54
|
+
required: true
|
55
|
+
|
56
|
+
option :denominator_metric_name,
|
57
|
+
description: 'Denominator metric name',
|
58
|
+
short: '-D NAME',
|
59
|
+
long: '--denominator-metric NAME',
|
60
|
+
required: true
|
61
|
+
|
62
|
+
option :dimensions,
|
63
|
+
description: 'Comma delimited list of DimName=Value',
|
64
|
+
short: '-d DIMENSIONS',
|
65
|
+
long: '--dimensions DIMENSIONS',
|
66
|
+
proc: proc { |d| CloudwatchCommon.parse_dimensions d },
|
67
|
+
default: []
|
68
|
+
|
69
|
+
option :period,
|
70
|
+
description: 'CloudWatch metric statistics period. Must be a multiple of 60',
|
71
|
+
short: '-p N',
|
72
|
+
long: '--period SECONDS',
|
73
|
+
default: 60,
|
74
|
+
proc: proc(&:to_i)
|
75
|
+
|
76
|
+
option :statistics,
|
77
|
+
short: '-s N',
|
78
|
+
long: '--statistics NAME',
|
79
|
+
default: 'Average',
|
80
|
+
description: 'CloudWatch statistics method'
|
81
|
+
|
82
|
+
option :unit,
|
83
|
+
short: '-u UNIT',
|
84
|
+
long: '--unit UNIT',
|
85
|
+
description: 'CloudWatch metric unit'
|
86
|
+
|
87
|
+
option :critical,
|
88
|
+
description: 'Trigger a critical when value is over VALUE as a Percent',
|
89
|
+
short: '-c VALUE',
|
90
|
+
long: '--critical VALUE',
|
91
|
+
proc: proc(&:to_f),
|
92
|
+
required: true
|
93
|
+
|
94
|
+
option :warning,
|
95
|
+
description: 'Trigger a warning when value is over VALUE as a Percent',
|
96
|
+
short: '-w VALUE',
|
97
|
+
long: '--warning VALUE',
|
98
|
+
proc: proc(&:to_f)
|
99
|
+
|
100
|
+
option :compare,
|
101
|
+
description: 'Comparision operator for threshold: equal, not, greater, less',
|
102
|
+
short: '-o OPERATION',
|
103
|
+
long: '--operator OPERATION',
|
104
|
+
default: 'greater'
|
105
|
+
|
106
|
+
option :numerator_default,
|
107
|
+
long: '--numerator-default DEFAULT',
|
108
|
+
description: 'Default for numerator if no data is returned for metric',
|
109
|
+
proc: proc(&:to_f)
|
110
|
+
|
111
|
+
option :no_denominator_data_ok,
|
112
|
+
long: '--allow-no-denominator-data',
|
113
|
+
description: 'Returns ok if no data is returned from denominator metric',
|
114
|
+
boolean: true,
|
115
|
+
default: false
|
116
|
+
|
117
|
+
option :zero_denominator_data_ok,
|
118
|
+
long: '--allow-zero-denominator-data',
|
119
|
+
description: 'Returns ok if denominator metric is zero',
|
120
|
+
boolean: true,
|
121
|
+
default: false
|
122
|
+
|
123
|
+
option :no_data_ok,
|
124
|
+
short: '-O',
|
125
|
+
long: '--allow-no-data',
|
126
|
+
description: 'Returns ok if no data is returned from either metric',
|
127
|
+
boolean: true,
|
128
|
+
default: false
|
129
|
+
include CloudwatchCommon
|
130
|
+
|
131
|
+
def metric_desc
|
132
|
+
"#{config[:namespace]}-#{config[:numerator_metric_name]}/#{config[:denominator_metric_name]}(#{dimension_string})"
|
133
|
+
end
|
134
|
+
|
135
|
+
def numerator_data(metric_payload)
|
136
|
+
if resp_has_no_data(metric_payload, config[:statistics])
|
137
|
+
# If the numerator response has no data in it, see if there was a predefined default.
|
138
|
+
# If there is no predefined default it will return nil
|
139
|
+
config[:numerator_default]
|
140
|
+
else
|
141
|
+
read_value(metric_payload, config[:statistics]).to_f
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
# rubocop:disable Style/GuardClause
|
146
|
+
def composite_check
|
147
|
+
numerator_metric_resp = get_metric(config[:numerator_metric_name])
|
148
|
+
denominator_metric_resp = get_metric(config[:denominator_metric_name])
|
149
|
+
|
150
|
+
## If the numerator is empty, then we see if there is a default. If there is a default
|
151
|
+
## then we will pretend the numerator _isnt_ empty. That is
|
152
|
+
## if empty but there is no default this will be true. If it is empty and there is a default
|
153
|
+
## this will be false (i.e. there is data, following standard of dealing in the negative here)
|
154
|
+
no_num_data = numerator_data(numerator_metric_resp).nil?
|
155
|
+
no_den_data = resp_has_no_data(denominator_metric_resp, config[:statistics])
|
156
|
+
no_data = no_num_data || no_den_data
|
157
|
+
|
158
|
+
# no data in numerator or denominator this is to keep backwards compatibility
|
159
|
+
if no_data && config[:no_data_ok]
|
160
|
+
return :ok, "#{metric_desc} returned no data but that's ok"
|
161
|
+
elsif no_den_data && config[:no_denominator_data_ok]
|
162
|
+
return :ok, "#{config[:denominator_metric_name]} returned no data but that's ok"
|
163
|
+
elsif no_data ## This is legacy case
|
164
|
+
return :unknown, "#{metric_desc} could not be retrieved"
|
165
|
+
end
|
166
|
+
|
167
|
+
## Now both the denominator and numerator have data (or a valid default)
|
168
|
+
denominator_value = read_value(denominator_metric_resp, config[:statistics]).to_f
|
169
|
+
if denominator_value.zero? && config[:zero_denominator_data_ok]
|
170
|
+
return :ok, "#{metric_desc}: denominator value is zero but that's ok"
|
171
|
+
elsif denominator_value.zero?
|
172
|
+
return :unknown, "#{metric_desc}: denominator value is zero"
|
173
|
+
end
|
174
|
+
|
175
|
+
## We already checked if this value is nil so we know its not
|
176
|
+
numerator_value = numerator_data(numerator_metric_resp)
|
177
|
+
value = (numerator_value / denominator_value * 100).to_i
|
178
|
+
base_msg = "#{metric_desc} is #{value}: comparison=#{config[:compare]}"
|
179
|
+
|
180
|
+
if compare(value, config[:critical], config[:compare])
|
181
|
+
return :critical, "#{base_msg} threshold=#{config[:critical]}"
|
182
|
+
elsif config[:warning] && compare(value, config[:warning], config[:compare])
|
183
|
+
return :warning, "#{base_msg} threshold=#{config[:warning]}"
|
184
|
+
else
|
185
|
+
threshold = config[:warning] || config[:critical]
|
186
|
+
return :ok, "#{base_msg}, will alarm at #{threshold}"
|
187
|
+
end
|
188
|
+
end
|
189
|
+
# rubocop:enable Style/GuardClause
|
190
|
+
|
191
|
+
def run
|
192
|
+
status, msg = composite_check
|
193
|
+
if respond_to?(status)
|
194
|
+
send(status, msg)
|
195
|
+
else
|
196
|
+
unknown 'unknown exit status called'
|
197
|
+
end
|
198
|
+
end
|
199
|
+
end
|
@@ -0,0 +1,123 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# check-cloudwatch-metric
|
4
|
+
#
|
5
|
+
# DESCRIPTION:
|
6
|
+
# This plugin retrieves the value of a cloudwatch metric and triggers
|
7
|
+
# alarms based on the thresholds specified
|
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-cloudwatch-metric -m CPUUtilization -d InstanceId=i-12345678,AvailabilityZone=us-east-1a -c 90
|
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'
|
31
|
+
require 'sensu-plugin/check/cli'
|
32
|
+
require 'aws-sdk'
|
33
|
+
|
34
|
+
class CloudWatchMetricCheck < Sensu::Plugin::Check::CLI
|
35
|
+
option :aws_region,
|
36
|
+
short: '-r AWS_REGION',
|
37
|
+
long: '--aws-region REGION',
|
38
|
+
description: 'AWS Region (defaults to us-east-1).',
|
39
|
+
default: 'us-east-1'
|
40
|
+
|
41
|
+
option :namespace,
|
42
|
+
description: 'CloudWatch namespace for metric',
|
43
|
+
short: '-n NAME',
|
44
|
+
long: '--namespace NAME',
|
45
|
+
default: 'AWS/EC2'
|
46
|
+
|
47
|
+
option :metric_name,
|
48
|
+
description: 'Metric name',
|
49
|
+
short: '-m NAME',
|
50
|
+
long: '--metric NAME',
|
51
|
+
required: true
|
52
|
+
|
53
|
+
option :dimensions,
|
54
|
+
description: 'Comma delimited list of DimName=Value',
|
55
|
+
short: '-d DIMENSIONS',
|
56
|
+
long: '--dimensions DIMENSIONS',
|
57
|
+
proc: proc { |d| CloudwatchCommon.parse_dimensions d },
|
58
|
+
default: []
|
59
|
+
|
60
|
+
option :period,
|
61
|
+
description: 'CloudWatch metric statistics period. Must be a multiple of 60',
|
62
|
+
short: '-p N',
|
63
|
+
long: '--period SECONDS',
|
64
|
+
default: 60,
|
65
|
+
proc: proc(&:to_i)
|
66
|
+
|
67
|
+
option :statistics,
|
68
|
+
short: '-s N',
|
69
|
+
long: '--statistics NAME',
|
70
|
+
default: 'Average',
|
71
|
+
description: 'CloudWatch statistics method'
|
72
|
+
|
73
|
+
option :unit,
|
74
|
+
short: '-u UNIT',
|
75
|
+
long: '--unit UNIT',
|
76
|
+
description: 'CloudWatch metric unit'
|
77
|
+
|
78
|
+
option :critical,
|
79
|
+
description: 'Trigger a critical when value is over VALUE',
|
80
|
+
short: '-c VALUE',
|
81
|
+
long: '--critical VALUE',
|
82
|
+
proc: proc(&:to_f),
|
83
|
+
required: true
|
84
|
+
|
85
|
+
option :warning,
|
86
|
+
description: 'Trigger a warning when value is over VALUE',
|
87
|
+
short: '-w VALUE',
|
88
|
+
long: '--warning VALUE',
|
89
|
+
proc: proc(&:to_f)
|
90
|
+
|
91
|
+
option :compare,
|
92
|
+
description: 'Comparision operator for threshold: equal, not, greater, less',
|
93
|
+
short: '-o OPERATION',
|
94
|
+
long: '--operator OPERATION',
|
95
|
+
default: 'greater'
|
96
|
+
|
97
|
+
option :no_data_ok,
|
98
|
+
short: '-O',
|
99
|
+
long: '--allow-no-data',
|
100
|
+
description: 'Returns ok if no data is returned from the metric',
|
101
|
+
boolean: true,
|
102
|
+
default: false
|
103
|
+
|
104
|
+
include CloudwatchCommon
|
105
|
+
|
106
|
+
def self.parse_dimensions(dimension_string)
|
107
|
+
dimension_string.split(',')
|
108
|
+
.collect { |d| d.split '=' }
|
109
|
+
.collect { |a| { name: a[0], value: a[1] } }
|
110
|
+
end
|
111
|
+
|
112
|
+
def dimension_string
|
113
|
+
config[:dimensions].map { |d| "#{d[:name]}=#{d[:value]}" }.join('&')
|
114
|
+
end
|
115
|
+
|
116
|
+
def metric_desc
|
117
|
+
"#{config[:namespace]}-#{config[:metric_name]}(#{dimension_string})"
|
118
|
+
end
|
119
|
+
|
120
|
+
def run
|
121
|
+
check config
|
122
|
+
end
|
123
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# check-configservice-rules
|
4
|
+
#
|
5
|
+
# DESCRIPTION:
|
6
|
+
# This plugin uses the AWS ConfigService API to check
|
7
|
+
# for rules compliance. CRITICAL for non-compliance,
|
8
|
+
# UNKNOWN for insufficient data.
|
9
|
+
#
|
10
|
+
# OUTPUT:
|
11
|
+
# plain-text
|
12
|
+
#
|
13
|
+
# PLATFORMS:
|
14
|
+
# Linux, Windows, Mac
|
15
|
+
#
|
16
|
+
# DEPENDENCIES:
|
17
|
+
# gem: aws-sdk
|
18
|
+
# gem: sensu-plugin
|
19
|
+
#
|
20
|
+
# USAGE:
|
21
|
+
# ./check-configservice-rules.rb -r {us-east-1|eu-west-1} [-c My_Config_Rule]
|
22
|
+
#
|
23
|
+
# NOTES:
|
24
|
+
# As of this writing, ConfigService rules are only available in us-east-1.
|
25
|
+
# All other region selections will return an AccessDeniedException
|
26
|
+
#
|
27
|
+
# LICENSE:
|
28
|
+
# Norm MacLennan <nmaclennan@cimpress.com>
|
29
|
+
# Released under the same terms as Sensu (the MIT license); see LICENSE
|
30
|
+
# for details.
|
31
|
+
|
32
|
+
require 'sensu-plugin/check/cli'
|
33
|
+
require 'sensu-plugins-aws'
|
34
|
+
require 'aws-sdk'
|
35
|
+
|
36
|
+
class CheckConfigServiceRules < Sensu::Plugin::Check::CLI
|
37
|
+
include Common
|
38
|
+
|
39
|
+
option :aws_region,
|
40
|
+
short: '-r AWS_REGION',
|
41
|
+
long: '--aws-region AWS_REGION',
|
42
|
+
description: 'The AWS region in which to check rules. Currently only available in us-east-1.',
|
43
|
+
default: 'us-east-1'
|
44
|
+
|
45
|
+
option :config_rules,
|
46
|
+
short: '-c rule1,rule2',
|
47
|
+
long: '--config-rules rule1,rule2',
|
48
|
+
description: 'A list of config rules to consider. Default is all rules.'
|
49
|
+
|
50
|
+
def get_config_rules_data(rules = nil)
|
51
|
+
options = { config_rule_names: rules.split(',') } if rules
|
52
|
+
config_client = Aws::ConfigService::Client.new
|
53
|
+
config_client.describe_compliance_by_config_rule(options).compliance_by_config_rules
|
54
|
+
end
|
55
|
+
|
56
|
+
def get_rule_names_by_compliance_type(rules, compliance_type)
|
57
|
+
rules.select { |r| r.compliance.compliance_type == compliance_type }.collect(&:config_rule_name)
|
58
|
+
end
|
59
|
+
|
60
|
+
def run
|
61
|
+
rules = get_config_rules_data(config[:config_rules])
|
62
|
+
|
63
|
+
noncompliant = get_rule_names_by_compliance_type rules, 'NON_COMPLIANT'
|
64
|
+
unknown = get_rule_names_by_compliance_type rules, 'INSUFFICIENT_DATA'
|
65
|
+
|
66
|
+
if noncompliant.any?
|
67
|
+
critical("Config rules in violation: #{noncompliant.join(',')}")
|
68
|
+
elsif unknown.any?
|
69
|
+
unknown("Config rules in unknown state: #{unknown.join(',')}")
|
70
|
+
else
|
71
|
+
ok
|
72
|
+
end
|
73
|
+
rescue StandardError => e
|
74
|
+
unknown "An error occurred processing AWS ConfigService API: #{e.message}"
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# check-direct-connect-virtual-interfaces
|
4
|
+
#
|
5
|
+
# DESCRIPTION:
|
6
|
+
# This plugin uses the AWS Direct Connect API to check the status
|
7
|
+
# of virtual interfaces
|
8
|
+
#
|
9
|
+
# CRIT: one or more interfaces status not 'available' (down)
|
10
|
+
# WARN: no virtual interfaces detected
|
11
|
+
# OK: all interfaces checked available
|
12
|
+
#
|
13
|
+
# OUTPUT:
|
14
|
+
# plain-text
|
15
|
+
#
|
16
|
+
# PLATFORMS:
|
17
|
+
# Linux, Windows, Mac
|
18
|
+
#
|
19
|
+
# DEPENDENCIES:
|
20
|
+
# gem: aws-sdk
|
21
|
+
# gem: sensu-plugin
|
22
|
+
#
|
23
|
+
# USAGE:
|
24
|
+
# ./check-direct-connect.rb -r {us-east-1|eu-west-1} [-c all]
|
25
|
+
#
|
26
|
+
# NOTES:
|
27
|
+
#
|
28
|
+
# LICENSE:
|
29
|
+
# Guillaume Delacour <guillaume.delacour@fr.clara.net>
|
30
|
+
# Released under the same terms as Sensu (the MIT license); see LICENSE
|
31
|
+
# for details.
|
32
|
+
|
33
|
+
require 'sensu-plugin/check/cli'
|
34
|
+
require 'sensu-plugins-aws'
|
35
|
+
require 'aws-sdk'
|
36
|
+
|
37
|
+
class CheckDcVirtualInterfacesHealth < Sensu::Plugin::Check::CLI
|
38
|
+
include Common
|
39
|
+
|
40
|
+
option :aws_region,
|
41
|
+
short: '-r AWS_REGION',
|
42
|
+
long: '--aws-region AWS_REGION',
|
43
|
+
description: 'The AWS region in which to check rules. Currently only available in us-east-1.',
|
44
|
+
default: 'us-east-1'
|
45
|
+
|
46
|
+
option :connection_id,
|
47
|
+
short: '-c CONNECTION_ID',
|
48
|
+
long: '--connection-id CONNECTION_ID',
|
49
|
+
description: 'The connection id to check. Default is to check all connection ids',
|
50
|
+
default: 'all'
|
51
|
+
|
52
|
+
def dc_client
|
53
|
+
@dc_client ||= Aws::DirectConnect::Client.new
|
54
|
+
end
|
55
|
+
|
56
|
+
def virtual_interfaces_details(connection_id = 'all')
|
57
|
+
if connection_id == 'all'
|
58
|
+
dc_client.describe_virtual_interfaces
|
59
|
+
else
|
60
|
+
dc_client.describe_virtual_interfaces(connection_id: connection_id)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def run
|
65
|
+
virtual_interfaces_healths = virtual_interfaces_details(config[:connection_id])
|
66
|
+
if virtual_interfaces_healths[0].length.zero?
|
67
|
+
warning('No virtual interfaces to check')
|
68
|
+
end
|
69
|
+
|
70
|
+
unhealthy = []
|
71
|
+
|
72
|
+
virtual_interfaces_healths[0].each do |virtual_interface|
|
73
|
+
unhealthy.push(virtual_interface.virtual_interface_name) if virtual_interface.virtual_interface_state != 'available'
|
74
|
+
end
|
75
|
+
|
76
|
+
if !unhealthy.length.zero?
|
77
|
+
critical("Not 'available' virtual interfaces: #{unhealthy.join ', '}")
|
78
|
+
else
|
79
|
+
ok(config[:connection_id].to_s)
|
80
|
+
end
|
81
|
+
rescue StandardError => e
|
82
|
+
unknown "An error occurred processing AWS DirectConnect API: #{e.message}"
|
83
|
+
end
|
84
|
+
end
|