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,155 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# check-ecs-service-health
|
4
|
+
#
|
5
|
+
# DESCRIPTION:
|
6
|
+
# This plugin uses the AWS ECS API to check the running
|
7
|
+
# and desired task counts for services on a cluster.
|
8
|
+
# Any services with fewer running than desired tasks will
|
9
|
+
# are considered unhealthy.
|
10
|
+
#
|
11
|
+
# CRIT: 0 = running < desired
|
12
|
+
# WARN: 0 < running < desired
|
13
|
+
# OK: running >= desired
|
14
|
+
#
|
15
|
+
# OUTPUT:
|
16
|
+
# plain-text
|
17
|
+
#
|
18
|
+
# PLATFORMS:
|
19
|
+
# Linux, Windows, Mac
|
20
|
+
#
|
21
|
+
# DEPENDENCIES:
|
22
|
+
# gem: aws-sdk
|
23
|
+
# gem: sensu-plugin
|
24
|
+
#
|
25
|
+
# USAGE:
|
26
|
+
# ./check-ecs-service-health.rb -r {us-east-1|eu-west-1} -c default [-s my-service]
|
27
|
+
#
|
28
|
+
# NOTES:
|
29
|
+
#
|
30
|
+
# MULTIPLE CLUSTERS/SERVICES AUTOMATION
|
31
|
+
# Create multiple clusters/services with these scripts: https://github.com/ay-b/ecs-service-check-autocreate
|
32
|
+
# Don't forget to edit template file
|
33
|
+
#
|
34
|
+
# LICENSE:
|
35
|
+
# Norm MacLennan <nmaclennan@cimpress.com>
|
36
|
+
# Released under the same terms as Sensu (the MIT license); see LICENSE
|
37
|
+
# for details.
|
38
|
+
|
39
|
+
require 'sensu-plugin/check/cli'
|
40
|
+
require 'sensu-plugins-aws'
|
41
|
+
require 'aws-sdk'
|
42
|
+
|
43
|
+
class CheckEcsServiceHealth < Sensu::Plugin::Check::CLI
|
44
|
+
include Common
|
45
|
+
|
46
|
+
option :aws_region,
|
47
|
+
short: '-r AWS_REGION',
|
48
|
+
long: '--aws-region AWS_REGION',
|
49
|
+
description: 'The AWS region in which to check rules. Currently only available in us-east-1.',
|
50
|
+
default: 'us-east-1'
|
51
|
+
|
52
|
+
option :cluster_name,
|
53
|
+
short: '-c NAME',
|
54
|
+
long: '--cluster-name NAME',
|
55
|
+
description: 'The cluster to check services on.',
|
56
|
+
default: 'default'
|
57
|
+
|
58
|
+
option :services,
|
59
|
+
short: '-s SERVICE',
|
60
|
+
long: '--service NAME',
|
61
|
+
description: 'The service to check run status on.'
|
62
|
+
|
63
|
+
option :warn_as_crit,
|
64
|
+
short: '-w',
|
65
|
+
long: '--warn_as_crit',
|
66
|
+
description: 'Consider it critical when any desired tasks are not running. Otherwise, only 0 is critical.'
|
67
|
+
|
68
|
+
option :primary_status,
|
69
|
+
short: '-p',
|
70
|
+
long: '--primary_status',
|
71
|
+
description: 'Checking for deployments which only have a Primary Status.',
|
72
|
+
default: false
|
73
|
+
|
74
|
+
def ecs_client
|
75
|
+
@ecs_client ||= Aws::ECS::Client.new
|
76
|
+
end
|
77
|
+
|
78
|
+
# List of requested services or all services registered to the cluster
|
79
|
+
def service_list(cluster = 'default', services = nil)
|
80
|
+
return services.split ',' if services
|
81
|
+
collect_services(cluster)
|
82
|
+
end
|
83
|
+
|
84
|
+
def collect_services(cluster = 'default', token: nil)
|
85
|
+
response = ecs_client.list_services(cluster: cluster, next_token: token)
|
86
|
+
services = response.service_arns
|
87
|
+
services.push(*collect_services(cluster, token: response.next_token)) if response.next_token
|
88
|
+
services
|
89
|
+
end
|
90
|
+
|
91
|
+
def service_details(cluster = 'default', services = nil)
|
92
|
+
service_list(cluster, services).each_slice(10).to_a.map do |s|
|
93
|
+
ecs_client.describe_services(cluster: cluster, services: s)['services']
|
94
|
+
end.flatten
|
95
|
+
end
|
96
|
+
|
97
|
+
def bucket_service(running_count, desired_count)
|
98
|
+
if running_count.zero? && desired_count > 0
|
99
|
+
:critical
|
100
|
+
elsif running_count < desired_count
|
101
|
+
:warn
|
102
|
+
else
|
103
|
+
:ok
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
# Unhealthy if service has fewer running tasks than desired
|
108
|
+
def services_by_health(cluster = 'default', services = nil, primary_status = false)
|
109
|
+
bucket = nil
|
110
|
+
service_details(cluster, services).group_by do |service|
|
111
|
+
if primary_status
|
112
|
+
service.deployments.each do |x|
|
113
|
+
if x[:status].include? 'PRIMARY'
|
114
|
+
bucket = bucket_service(x[:running_count], x[:desired_count])
|
115
|
+
end
|
116
|
+
end
|
117
|
+
else
|
118
|
+
bucket = bucket_service(service[:running_count], service[:desired_count])
|
119
|
+
end
|
120
|
+
bucket
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
def run
|
125
|
+
service_healths = services_by_health(config[:cluster_name], config[:services], config[:primary_status])
|
126
|
+
|
127
|
+
unhealthy = []
|
128
|
+
unhealthy.concat(service_healths[:critical]) if service_healths.key? :critical
|
129
|
+
unhealthy.concat(service_healths[:warn]) if service_healths.key? :warn
|
130
|
+
|
131
|
+
if config[:primary_status]
|
132
|
+
unhealthy_p = nil
|
133
|
+
unhealthy = unhealthy.collect do |s|
|
134
|
+
s.deployments.each do |x|
|
135
|
+
if x[:status].include? 'PRIMARY'
|
136
|
+
unhealthy_p = "#{s.service_name} (#{x.running_count}/#{x.desired_count})"
|
137
|
+
end
|
138
|
+
end
|
139
|
+
unhealthy_p
|
140
|
+
end
|
141
|
+
else
|
142
|
+
unhealthy = unhealthy.collect { |s| "#{s.service_name} (#{s.running_count}/#{s.desired_count})" }
|
143
|
+
end
|
144
|
+
|
145
|
+
if service_healths.key?(:critical) || (config[:warn_as_crit] && service_healths.key?(:warn))
|
146
|
+
critical("Unhealthy ECS Services(Primary only = #{config[:primary_status]}): #{unhealthy.join ', '}")
|
147
|
+
elsif service_healths.key?(:warn)
|
148
|
+
warning("Unhealthy ECS Services(Primary only = #{config[:primary_status]}): #{unhealthy.join ', '}")
|
149
|
+
else
|
150
|
+
ok
|
151
|
+
end
|
152
|
+
rescue StandardError => e
|
153
|
+
unknown "An error occurred processing AWS ECS API: #{e.message}"
|
154
|
+
end
|
155
|
+
end
|
@@ -0,0 +1,145 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# check-efs-metric
|
4
|
+
#
|
5
|
+
# DESCRIPTION:
|
6
|
+
# This plugin checks a CloudWatch metric from the AWS/EFS namespace
|
7
|
+
# For more details, see https://docs.aws.amazon.com/efs/latest/ug/monitoring-cloudwatch.html#efs-metrics
|
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-efs-metric -w 25.0 -c 75.0 \
|
21
|
+
# -m PercentIOLimit -o greater -n my-efs-filesystem-name
|
22
|
+
#
|
23
|
+
# NOTES:
|
24
|
+
#
|
25
|
+
# LICENSE:
|
26
|
+
# Ivan Fetch
|
27
|
+
# Released under the same terms as Sensu (the MIT license); see LICENSE
|
28
|
+
# for details.
|
29
|
+
#
|
30
|
+
|
31
|
+
require 'sensu-plugins-aws'
|
32
|
+
require 'sensu-plugin/check/cli'
|
33
|
+
require 'aws-sdk'
|
34
|
+
|
35
|
+
# A Sensu plugin which uses cloudwatch-common to check EFS CloudWatch metrics
|
36
|
+
class EFSMetric < Sensu::Plugin::Check::CLI
|
37
|
+
include Common
|
38
|
+
include CloudwatchCommon
|
39
|
+
|
40
|
+
option :efs_name,
|
41
|
+
description: 'Name of the EFS file system, matching the Name tag',
|
42
|
+
short: '-n VALUE',
|
43
|
+
long: '--name VALUE',
|
44
|
+
proc: proc(&:to_s),
|
45
|
+
required: true
|
46
|
+
|
47
|
+
option :metric_name,
|
48
|
+
description: 'CloudWatch metric in the AWS/EFS namespace: E.G. PercentIOLimit',
|
49
|
+
short: '-m VALUE',
|
50
|
+
long: '--metric VALUE',
|
51
|
+
proc: proc(&:to_s),
|
52
|
+
required: true
|
53
|
+
|
54
|
+
option :statistics,
|
55
|
+
description: 'Statistic to retrieve from CloudWatch: E.G. Minimum or Maximum',
|
56
|
+
short: '-s statistic',
|
57
|
+
long: '--statistic statistic',
|
58
|
+
default: 'Average',
|
59
|
+
proc: proc(&:to_s)
|
60
|
+
|
61
|
+
option :critical,
|
62
|
+
description: 'Return critical when the metric is at this VALUE, also see the --operator option',
|
63
|
+
short: '-c VALUE',
|
64
|
+
long: '--critical VALUE',
|
65
|
+
proc: proc(&:to_f),
|
66
|
+
required: true
|
67
|
+
|
68
|
+
option :warning,
|
69
|
+
description: 'Return warning when the metric is at this VALUE, also see the --operator option',
|
70
|
+
short: '-w VALUE',
|
71
|
+
long: '--warning VALUE',
|
72
|
+
proc: proc(&:to_f)
|
73
|
+
|
74
|
+
option :period,
|
75
|
+
description: 'CloudWatch metric statistics period, in seconds. Must be a multiple of 60',
|
76
|
+
short: '-p VALUE',
|
77
|
+
long: '--period VALUE',
|
78
|
+
default: 60,
|
79
|
+
proc: proc(&:to_i)
|
80
|
+
|
81
|
+
option :compare,
|
82
|
+
description: 'Comparison operator for critical and warning thresholds: equal, not, greater, less',
|
83
|
+
short: '-o OPERATOR',
|
84
|
+
long: '--operator OPERATOR',
|
85
|
+
default: 'less'
|
86
|
+
|
87
|
+
option :unit,
|
88
|
+
description: 'CloudWatch metric unit, to be passed to the metrics request',
|
89
|
+
short: '-u UNIT',
|
90
|
+
long: '--unit UNIT'
|
91
|
+
|
92
|
+
option :no_data_ok,
|
93
|
+
description: 'Returns ok if no data is returned from the metric',
|
94
|
+
short: '-O',
|
95
|
+
long: '--allow-no-data',
|
96
|
+
boolean: true,
|
97
|
+
default: false
|
98
|
+
|
99
|
+
option :no_efs_ok,
|
100
|
+
description: 'Returns ok if the EFS file system specified by the -n option can not be found: This is useful if using a check in multiple environments where a file system may not always exist',
|
101
|
+
short: '-N',
|
102
|
+
long: '--allow-no-efs',
|
103
|
+
boolean: true,
|
104
|
+
default: false
|
105
|
+
|
106
|
+
option :aws_region,
|
107
|
+
description: 'AWS region',
|
108
|
+
short: '-r Region',
|
109
|
+
long: '--region REGION',
|
110
|
+
default: 'us-east-1'
|
111
|
+
|
112
|
+
# This is used by CloudwatchCommon to display the description for what is being checked.
|
113
|
+
def metric_desc
|
114
|
+
"#{config[:metric_name]} for #{config[:efs_name]}"
|
115
|
+
end
|
116
|
+
|
117
|
+
def run
|
118
|
+
config[:namespace] = 'AWS/EFS'
|
119
|
+
found_efs = false
|
120
|
+
|
121
|
+
efs = Aws::EFS::Client.new
|
122
|
+
filesystems = efs.describe_file_systems
|
123
|
+
filesystems.file_systems.each do |filesystem|
|
124
|
+
# Once Ruby < ver 2.4 is not supported, change this to:
|
125
|
+
# if filesystem.name.casecmp?(config[:efs_name])
|
126
|
+
# See : https://ruby-doc.org/core-2.4.0/String.html#method-i-casecmp
|
127
|
+
if filesystem.name.casecmp(config[:efs_name]).zero?
|
128
|
+
found_efs = true
|
129
|
+
config[:dimensions] = []
|
130
|
+
config[:dimensions] << { name: 'FileSystemId', value: filesystem.file_system_id }
|
131
|
+
check config
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
# rubocop:disable Style/GuardClause
|
136
|
+
unless found_efs
|
137
|
+
if config[:no_efs_ok]
|
138
|
+
ok "EFS file system #{config[:efs_name]} was not found in region #{config[:aws_region]} but that's ok"
|
139
|
+
else
|
140
|
+
critical "EFS file system #{config[:efs_name]} was not found in region #{config[:aws_region]}"
|
141
|
+
end
|
142
|
+
end
|
143
|
+
# rubocop:enable Style/GuardClause
|
144
|
+
end
|
145
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# check-ebs-snapshots
|
4
|
+
#
|
5
|
+
# DESCRIPTION:
|
6
|
+
# Alert on new eip allocations
|
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-eip-allocation.rb -r ${you_region} -e ${eips_allowed}
|
20
|
+
#
|
21
|
+
# NOTES:
|
22
|
+
#
|
23
|
+
# LICENSE:
|
24
|
+
# Shane Starcher <shane.starcher@gmail.com>
|
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 'sensu-plugins-aws'
|
31
|
+
require 'aws-sdk'
|
32
|
+
|
33
|
+
class CheckEipAllocation < Sensu::Plugin::Check::CLI
|
34
|
+
include Common
|
35
|
+
option :eips_allowed,
|
36
|
+
short: '-e EIPS_ALLOWED',
|
37
|
+
long: '--eips_allowed eip1,eip2',
|
38
|
+
required: true,
|
39
|
+
description: 'List of EIPs that are allowed to exist. Comma seperated.'
|
40
|
+
|
41
|
+
option :aws_region,
|
42
|
+
short: '-r R',
|
43
|
+
long: '--region REGION',
|
44
|
+
description: 'AWS region',
|
45
|
+
default: 'us-east-1'
|
46
|
+
|
47
|
+
def run
|
48
|
+
errors = []
|
49
|
+
ec2 = Aws::EC2::Client.new
|
50
|
+
|
51
|
+
eips = ec2.describe_addresses
|
52
|
+
eips[:addresses].each do |eip|
|
53
|
+
unless config[:eips_allowed].include? eip.public_ip
|
54
|
+
errors << eip.public_ip
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
if errors.empty?
|
59
|
+
ok
|
60
|
+
else
|
61
|
+
warning errors.join("\n")
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,113 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# check-elasticache-failover.rb
|
4
|
+
#
|
5
|
+
# DESCRIPTION:
|
6
|
+
# Checks if specified ElastiCache node is `primary` state.
|
7
|
+
#
|
8
|
+
# OUTPUT:
|
9
|
+
# CheckElastiCacheFailover OK: Node `mynode-001` (in replication group `my-group-1`, node group `0001`) is `primary`.
|
10
|
+
# or
|
11
|
+
# CheckElastiCacheFailover CRITICAL: Node `mynode-001` (in replication group `my-group-1`, node group `0001`) is **not** `primary`.
|
12
|
+
#
|
13
|
+
# PLATFORMS:
|
14
|
+
# Linux, Windows, BSD, Solaris, etc
|
15
|
+
#
|
16
|
+
# DEPENDENCIES:
|
17
|
+
# gem: sensu-plugin
|
18
|
+
# gem: aws-sdk >= 2
|
19
|
+
#
|
20
|
+
# USAGE:
|
21
|
+
# check-elasticache-failover.rb --region <your region> --replication-group <yours> --node-group <yours> --primary-node <yours>
|
22
|
+
#
|
23
|
+
# NOTES:
|
24
|
+
#
|
25
|
+
# LICENSE:
|
26
|
+
# y13i <email@y13i.com>
|
27
|
+
# Released under the same terms as Sensu (the MIT license); see LICENSE
|
28
|
+
# for details.
|
29
|
+
#
|
30
|
+
|
31
|
+
require 'sensu-plugin/check/cli'
|
32
|
+
require 'aws-sdk'
|
33
|
+
require 'sensu-plugins-aws/common'
|
34
|
+
|
35
|
+
class CheckElastiCacheFailover < Sensu::Plugin::Check::CLI
|
36
|
+
VERSION = '0.0.1'.freeze
|
37
|
+
|
38
|
+
option :profile,
|
39
|
+
description: 'Profile name of AWS shared credential file entry.',
|
40
|
+
long: '--profile PROFILE',
|
41
|
+
short: '-p PROFILE'
|
42
|
+
|
43
|
+
option :aws_region,
|
44
|
+
description: 'AWS region.',
|
45
|
+
short: '-r REGION',
|
46
|
+
long: '--region REGION'
|
47
|
+
|
48
|
+
option :severity,
|
49
|
+
description: 'Critical or Warning.',
|
50
|
+
short: '-s SEVERITY',
|
51
|
+
long: '--severity SEVERITY',
|
52
|
+
proc: :intern.to_proc,
|
53
|
+
default: :critical
|
54
|
+
|
55
|
+
option :replication_group,
|
56
|
+
description: 'Replication group to check.',
|
57
|
+
long: '--replication-group ID',
|
58
|
+
short: '-g ID'
|
59
|
+
|
60
|
+
option :node_group,
|
61
|
+
description: 'Node group to check.',
|
62
|
+
long: '--node-group ID',
|
63
|
+
short: '-n ID'
|
64
|
+
|
65
|
+
option :primary_node,
|
66
|
+
description: 'Cluster name that should be primary.',
|
67
|
+
long: '--primary-node NAME',
|
68
|
+
short: '-c NAME'
|
69
|
+
|
70
|
+
include Common
|
71
|
+
|
72
|
+
def run
|
73
|
+
replication_group = elasticache.client.describe_replication_groups.replication_groups.find do |g|
|
74
|
+
g.replication_group_id == config[:replication_group]
|
75
|
+
end
|
76
|
+
|
77
|
+
unknown 'Replication group not found.' if replication_group.nil?
|
78
|
+
|
79
|
+
node_group = replication_group.node_groups.find do |g|
|
80
|
+
g.node_group_id == config[:node_group]
|
81
|
+
end
|
82
|
+
|
83
|
+
unknown 'Node group not found.' if node_group.nil?
|
84
|
+
|
85
|
+
node = node_group.node_group_members.find do |n|
|
86
|
+
n.cache_cluster_id == config[:primary_node]
|
87
|
+
end
|
88
|
+
|
89
|
+
unknown 'Node not found.' if node.nil?
|
90
|
+
|
91
|
+
message = "Node `#{config[:primary_node]}` (in replication group `#{config[:replication_group]}`, node group `#{config[:node_group]}`) is "
|
92
|
+
|
93
|
+
if node.current_role == 'primary'
|
94
|
+
message += '`primary`.'
|
95
|
+
ok message
|
96
|
+
else
|
97
|
+
message += '**not** `primary`.'
|
98
|
+
send config[:severity], message
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
private
|
103
|
+
|
104
|
+
def elasticache
|
105
|
+
return @elasticache if @elasticache
|
106
|
+
|
107
|
+
c = {}
|
108
|
+
c.update aws_config
|
109
|
+
c.update(profile: config[:profile]) if config[:profile]
|
110
|
+
|
111
|
+
@elasticache = Aws::ElastiCache::Resource.new(c)
|
112
|
+
end
|
113
|
+
end
|