sensu-plugins-aws 0.0.1.alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/bin/check-rds.rb ADDED
@@ -0,0 +1,251 @@
1
+ #! /usr/bin/env ruby
2
+ #
3
+ # check-rds
4
+ #
5
+ # DESCRIPTION:
6
+ # Check RDS instance statuses by RDS and 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
+ # Critical if DB instance "sensu-admin-db" is not on ap-northeast-1a
20
+ # check-rds -i sensu-admin-db --availability-zone-critical ap-northeast-1a
21
+ #
22
+ # Warning if CPUUtilization is over 80%, critical if over 90%
23
+ # check-rds -i sensu-admin-db --cpu-warning-over 80 --cpu-critical-over 90
24
+ #
25
+ # Critical if CPUUtilization is over 90%, maximum of last one hour
26
+ # check-rds -i sensu-admin-db --cpu-critical-over 90 --statistics maximum --period 3600
27
+ #
28
+ # Warning if memory usage is over 80%, maximum of last 2 hour
29
+ # specifying "minimum" is intended actually since memory usage is calculated from CloudWatch "FreeableMemory" metric.
30
+ # check-rds -i sensu-admin-db --memory-warning-over 80 --statistics minimum --period 7200
31
+ #
32
+ # Disk usage, same as memory
33
+ # check-rds -i sensu-admin-db --disk-warning-over 80 --period 7200
34
+ #
35
+ # You can check multiple metrics simultaneously. Highest severity will be reported
36
+ # check-rds -i sensu-admin-db --cpu-warning-over 80 --cpu-critical-over 90 --memory-warning-over 60 --memory-critical-over 80
37
+ #
38
+ # NOTES:
39
+ #
40
+ # LICENSE:
41
+ # Copyright 2014 github.com/y13i
42
+ # Released under the same terms as Sensu (the MIT license); see LICENSE
43
+ # for details.
44
+ #
45
+
46
+ require 'rubygems' if RUBY_VERSION < '1.9.0'
47
+ require 'sensu-plugin/check/cli'
48
+ require 'aws-sdk'
49
+ require 'time'
50
+
51
+ class CheckRDS < Sensu::Plugin::Check::CLI
52
+ option :access_key_id,
53
+ short: '-k N',
54
+ long: '--access-key-id ID',
55
+ description: 'AWS access key ID',
56
+ default: ENV['AWS_ACCESS_KEY_ID']
57
+
58
+ option :secret_access_key,
59
+ short: '-s N',
60
+ long: '--secret-access-key KEY',
61
+ description: 'AWS secret access key',
62
+ default: ENV['AWS_SECRET_ACCESS_KEY']
63
+
64
+ option :region,
65
+ short: '-r R',
66
+ long: '--region REGION',
67
+ description: 'AWS region',
68
+ description: 'AWS Region (such as eu-west-1).',
69
+ default: 'us-east-1'
70
+
71
+ option :db_instance_id,
72
+ short: '-i N',
73
+ long: '--db-instance-id NAME',
74
+ description: 'DB instance identifier'
75
+
76
+ option :end_time,
77
+ short: '-t T',
78
+ long: '--end-time TIME',
79
+ default: Time.now,
80
+ proc: proc { |a| Time.parse a },
81
+ description: 'CloudWatch metric statistics end time'
82
+
83
+ option :period,
84
+ short: '-p N',
85
+ long: '--period SECONDS',
86
+ default: 60,
87
+ proc: proc(&:to_i),
88
+ description: 'CloudWatch metric statistics period'
89
+
90
+ option :statistics,
91
+ short: '-S N',
92
+ long: '--statistics NAME',
93
+ default: :average,
94
+ proc: proc { |a| a.downcase.intern },
95
+ description: 'CloudWatch statistics method'
96
+
97
+ %w(warning critical).each do |severity|
98
+ option :"availability_zone_#{severity}",
99
+ long: "--availability-zone-#{severity} AZ",
100
+ description: "Trigger a #{severity} if availability zone is different than given argument"
101
+
102
+ %w(cpu memory disk).each do |item|
103
+ option :"#{item}_#{severity}_over",
104
+ long: "--#{item}-#{severity}-over N",
105
+ proc: proc(&:to_f),
106
+ description: "Trigger a #{severity} if #{item} usage is over a percentage"
107
+ end
108
+ end
109
+
110
+ def aws_config
111
+ hash = {}
112
+ hash.update access_key_id: config[:access_key_id], secret_access_key: config[:secret_access_key] if config[:access_key_id] && config[:secret_access_key]
113
+ hash.update region: config[:region] if config[:region]
114
+ hash
115
+ end
116
+
117
+ def rds
118
+ @rds ||= AWS::RDS.new aws_config
119
+ end
120
+
121
+ def cloud_watch
122
+ @cloud_watch ||= AWS::CloudWatch.new aws_config
123
+ end
124
+
125
+ def find_db_instance(id)
126
+ db = rds.instances[id]
127
+ fail unless db.exists?
128
+ db
129
+ rescue
130
+ unknown 'DB instance not found.'
131
+ end
132
+
133
+ def cloud_watch_metric(metric_name)
134
+ cloud_watch.metrics.with_namespace('AWS/RDS').with_metric_name(metric_name).with_dimensions(name: 'DBInstanceIdentifier', value: @db_instance.id).first
135
+ end
136
+
137
+ def statistics_options
138
+ {
139
+ start_time: config[:end_time] - config[:period],
140
+ end_time: config[:end_time],
141
+ statistics: [config[:statistics].to_s.capitalize],
142
+ period: config[:period]
143
+ }
144
+ end
145
+
146
+ def latest_value(metric, unit)
147
+ values = metric.statistics(statistics_options.merge unit: unit).datapoints.sort_by { |datapoint| datapoint[:timestamp] }
148
+
149
+ # handle time periods that are too small to return usable values
150
+ values.empty? ? unknown('Requested time period did not return values from Cloudwatch. Try increasing your time period.') : values.last[config[:statistics]]
151
+ end
152
+
153
+ def flag_alert(severity, message)
154
+ @severities[severity] = true
155
+ @message += message
156
+ end
157
+
158
+ def memory_total_bytes(instance_class)
159
+ memory_total_gigabytes = {
160
+ 'db.t1.micro' => 0.615,
161
+ 'db.m1.small' => 1.7,
162
+ 'db.m3.medium' => 3.75,
163
+ 'db.m3.large' => 7.5,
164
+ 'db.m3.xlarge' => 15.0,
165
+ 'db.m3.2xlarge' => 30.0,
166
+ 'db.r3.large' => 15.0,
167
+ 'db.r3.xlarge' => 30.5,
168
+ 'db.r3.2xlarge' => 61.0,
169
+ 'db.r3.4xlarge' => 122.0,
170
+ 'db.r3.8xlarge' => 244.0,
171
+ 'db.m2.xlarge' => 17.1,
172
+ 'db.m2.2xlarge' => 34.2,
173
+ 'db.m2.4xlarge' => 68.4,
174
+ 'db.cr1.8xlarge' => 244.0,
175
+ 'db.m1.medium' => 3.75,
176
+ 'db.m1.large' => 7.5,
177
+ 'db.m1.xlarge' => 15.0,
178
+ 'db.t2.micro' => 1,
179
+ 'db.t2.small' => 2,
180
+ 'db.t2.medium' => 4
181
+ }
182
+
183
+ memory_total_gigabytes.fetch(instance_class) * 1024**3
184
+ end
185
+
186
+ def check_az(severity, expected_az)
187
+ return if @db_instance.availability_zone_name == expected_az
188
+ flag_alert severity, "; AZ is #{@db_instance.availability_zone_name} (expected #{expected_az})"
189
+ end
190
+
191
+ def check_cpu(severity, expected_lower_than)
192
+ @cpu_metric ||= cloud_watch_metric 'CPUUtilization'
193
+ @cpu_metric_value ||= latest_value @cpu_metric, 'Percent'
194
+ return if @cpu_metric_value < expected_lower_than
195
+ flag_alert severity, "; CPUUtilization is #{sprintf '%.2f', @cpu_metric_value}% (expected lower than #{expected_lower_than}%)"
196
+ end
197
+
198
+ def check_memory(severity, expected_lower_than)
199
+ @memory_metric ||= cloud_watch_metric 'FreeableMemory'
200
+ @memory_metric_value ||= latest_value @memory_metric, 'Bytes'
201
+ @memory_total_bytes ||= memory_total_bytes @db_instance.db_instance_class
202
+ @memory_usage_bytes ||= @memory_total_bytes - @memory_metric_value
203
+ @memory_usage_percentage ||= @memory_usage_bytes / @memory_total_bytes * 100
204
+ return if @memory_usage_percentage < expected_lower_than
205
+ flag_alert severity, "; Memory usage is #{sprintf '%.2f', @memory_usage_percentage}% (expected lower than #{expected_lower_than}%)"
206
+ end
207
+
208
+ def check_disk(severity, expected_lower_than)
209
+ @disk_metric ||= cloud_watch_metric 'FreeStorageSpace'
210
+ @disk_metric_value ||= latest_value @disk_metric, 'Bytes'
211
+ @disk_total_bytes ||= @db_instance.allocated_storage * 1024**3
212
+ @disk_usage_bytes ||= @disk_total_bytes - @disk_metric_value
213
+ @disk_usage_percentage ||= @disk_usage_bytes / @disk_total_bytes * 100
214
+ return if @disk_usage_percentage < expected_lower_than
215
+ flag_alert severity, "; Disk usage is #{sprintf '%.2f', @disk_usage_percentage}% (expected lower than #{expected_lower_than}%)"
216
+ end
217
+
218
+ def run
219
+ if config[:db_instance_id].nil? || config[:db_instance_id].empty?
220
+ unknown 'No DB instance provided. See help for usage details'
221
+ end
222
+
223
+ @db_instance = find_db_instance config[:db_instance_id]
224
+ @message = "#{config[:db_instance_id]}: "
225
+ @severities = {
226
+ critical: false,
227
+ warning: false
228
+ }
229
+
230
+ @severities.keys.each do |severity|
231
+ check_az severity, config[:"availability_zone_#{severity}"] if config[:"availability_zone_#{severity}"]
232
+
233
+ %w(cpu memory disk).each do |item|
234
+ send "check_#{item}", severity, config[:"#{item}_#{severity}_over"] if config[:"#{item}_#{severity}_over"]
235
+ end
236
+ end
237
+
238
+ if %w(cpu memory disk).any? { |item| %w(warning critical).any? { |severity| config[:"#{item}_#{severity}_over"] } }
239
+ @message += "(#{config[:statistics].to_s.capitalize} within #{config[:period]}s "
240
+ @message += "between #{config[:end_time] - config[:period]} to #{config[:end_time]})"
241
+ end
242
+
243
+ if @severities[:critical]
244
+ critical @message
245
+ elsif @severities[:warning]
246
+ warning @message
247
+ else
248
+ ok @message
249
+ end
250
+ end
251
+ end
@@ -0,0 +1,120 @@
1
+ #! /usr/bin/env ruby
2
+ #
3
+ # check-redshift-events
4
+ #
5
+ # DESCRIPTION:
6
+ # This plugin checks amazon redshift clusters for maintenance events
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
+ #
20
+ # check for instances in maint in us-east-1:
21
+ # ./check-redshift-events.rb -a ${your access key} -s ${your secret access key} -r us-east-1
22
+ #
23
+ # check for maint events on a single instance in us-east-1 (skip others):
24
+ # ./check-redshift-events.rb -a ${your access key} -s ${your secret access key} -r us-east-1 -i ${your cluster name}
25
+ #
26
+ # check for maint events on multiple instance in us-east-1 (skip others):
27
+ # ./check-redshift-events.rb -a ${your access key} -s ${your secret access key} -r us-east-1 -i ${cluster1,cluster2,cluster3}
28
+ #
29
+ # NOTES:
30
+ #
31
+ # LICENSE:
32
+ # Copyright (c) 2014, Tim Smith, tim@cozy.co
33
+ # Released under the same terms as Sensu (the MIT license); see LICENSE
34
+ # for details.
35
+ #
36
+
37
+ require 'sensu-plugin/check/cli'
38
+ require 'aws-sdk'
39
+
40
+ class CheckRedshiftEvents < Sensu::Plugin::Check::CLI
41
+ option :aws_access_key,
42
+ short: '-a AWS_ACCESS_KEY',
43
+ long: '--aws-access-key AWS_ACCESS_KEY',
44
+ description: "AWS Access Key. Either set ENV['AWS_ACCESS_KEY_ID'] or provide it as an option",
45
+ default: ENV['AWS_ACCESS_KEY_ID']
46
+
47
+ option :aws_secret_access_key,
48
+ short: '-s AWS_SECRET_ACCESS_KEY',
49
+ long: '--aws-secret-access-key AWS_SECRET_ACCESS_KEY',
50
+ description: "AWS Secret Access Key. Either set ENV['AWS_SECRET_ACCESS_KEY'] or provide it as an option",
51
+ default: ENV['AWS_SECRET_ACCESS_KEY']
52
+
53
+ option :aws_region,
54
+ short: '-r AWS_REGION',
55
+ long: '--aws-region REGION',
56
+ description: 'AWS Region (such as eu-west-1).',
57
+ default: 'us-east-1'
58
+
59
+ option :instances,
60
+ short: '-i INSTANCES',
61
+ long: '--instances INSTANCES',
62
+ description: 'Comma separated list of instances to check. Defaults to all clusters in the region',
63
+ proc: proc { |a| a.split(',') },
64
+ default: []
65
+
66
+ # setup a redshift connection using aws-sdk
67
+ def redshift
68
+ @redshift ||= AWS::Redshift::Client.new(
69
+ access_key_id: config[:aws_access_key],
70
+ secret_access_key: config[:aws_secret_access_key],
71
+ region: config[:aws_region])
72
+ end
73
+
74
+ # fetch all clusters in the region from AWS
75
+ def all_clusters
76
+ @clusters ||= redshift.describe_clusters[:clusters].map { |c| c[:cluster_identifier] }
77
+ end
78
+
79
+ # throw unknown message if the user passed us a missing instance
80
+ def check_missing_instances(instances)
81
+ missing_instances = instances.select { |i| !all_clusters.include?(i) }
82
+ unknown("Passed instance(s): #{missing_instances.join(',')} not found") unless missing_instances.empty?
83
+ end
84
+
85
+ # return an array of clusters that are in maintenance
86
+ def clusters_in_maint(clusters)
87
+ maint_clusters = []
88
+
89
+ # fetch the last 2 hours of events for each cluster
90
+ clusters.each do |cluster_name|
91
+ events_record = redshift.describe_events(start_time: (Time.now - 7200).iso8601, source_type: 'cluster', source_identifier: cluster_name)
92
+
93
+ next if events_record[:events].empty?
94
+
95
+ # if the last event is a start maint event then the cluster is still in maint
96
+ maint_clusters.push(cluster_name) if events_record[:events][-1][:event_id] == 'REDSHIFT-EVENT-2003'
97
+ end
98
+ maint_clusters
99
+ end
100
+
101
+ def run
102
+ begin
103
+ # make sure passed instances exist and only check those instances
104
+ unless config[:instances].empty?
105
+ check_missing_instances(config[:instances])
106
+ all_clusters.select! { |c| config[:instances].include?(c) }
107
+ end
108
+
109
+ maint_clusters = clusters_in_maint(all_clusters)
110
+ rescue => e
111
+ unknown "An error occurred processing AWS Redshift API: #{e.message}"
112
+ end
113
+
114
+ if maint_clusters.empty?
115
+ ok
116
+ else
117
+ critical("Clusters in maintenance: #{maint_clusters.join(',')}")
118
+ end
119
+ end
120
+ end
@@ -0,0 +1,91 @@
1
+ #! /usr/bin/env ruby
2
+ #
3
+ # check-ses-limit
4
+ #
5
+ # DESCRIPTION:
6
+ # Gets your SES sending limit and issues a warn and critical based on percentages
7
+ # you supply for your daily sending limit
8
+ # Checks how close you are getting in percentages to your 24 hour ses sending limit
9
+ #
10
+ # OUTPUT:
11
+ # plain-text
12
+ #
13
+ # PLATFORMS:
14
+ # Linux
15
+ #
16
+ # DEPENDENCIES:
17
+ # gem: aws-sdk
18
+ # gem: sensu-plugin
19
+ #
20
+ # USAGE:
21
+ # #YELLOW
22
+ #
23
+ # NOTES:
24
+ #
25
+ # LICENSE:
26
+ # Copyright (c) 2014, Joel <jjshoe@gmail.com>
27
+ # Released under the same terms as Sensu (the MIT license); see LICENSE
28
+ # for details.
29
+ #
30
+
31
+ require 'rubygems' if RUBY_VERSION < '1.9.0'
32
+ require 'sensu-plugin/check/cli'
33
+ require 'aws/ses'
34
+
35
+ class CheckSESLimit < Sensu::Plugin::Check::CLI
36
+ option :aws_access_key,
37
+ short: '-a AWS_ACCESS_KEY',
38
+ long: '--aws-access-key AWS_ACCESS_KEY',
39
+ description: "AWS Access Key. Either set ENV['AWS_ACCESS_KEY_ID'] or provide it as an option",
40
+ required: true
41
+
42
+ option :aws_secret_access_key,
43
+ short: '-s AWS_SECRET_ACCESS_KEY',
44
+ long: '--aws-secret-access-key AWS_SECRET_ACCESS_KEY',
45
+ description: "AWS Secret Access Key. Either set ENV['AWS_SECRET_ACCESS_KEY'] or provide it as an option",
46
+ required: true
47
+
48
+ option :warn_percent,
49
+ short: '-W WARN_PERCENT',
50
+ long: '--warn_perc WARN_PERCENT',
51
+ description: 'Warn when the percentage of mail sent is at or above this number',
52
+ default: 75,
53
+ proc: proc(&:to_i)
54
+
55
+ option :crit_percent,
56
+ short: '-C CRIT_PERCENT',
57
+ long: '--crit_perc CRIT_PERCENT',
58
+ description: 'Critical when the percentage of mail sent is at or above this number',
59
+ default: 90,
60
+ proc: proc(&:to_i)
61
+
62
+ def aws_config
63
+ hash = {}
64
+ hash.update access_key_id: config[:aws_access_key], secret_access_key: config[:aws_secret_access_key]\
65
+ if config[:aws_access_key] && config[:aws_secret_access_key]
66
+ hash
67
+ end
68
+
69
+ def run
70
+ begin
71
+ ses = AWS::SES::Base.new aws_config
72
+
73
+ response = ses.quota
74
+ rescue AWS::SES::ResponseError => e
75
+ critical "An issue occured while communicating with the AWS SES API: #{e.message}"
76
+ end
77
+
78
+ unless response.empty?
79
+ percent = (response.sent_last_24_hours.to_i / response.max_24_hour_send.to_i) * 100
80
+ message = "SES sending limit is at #{percent}%"
81
+
82
+ if config[:crit_percent] > 0 && config[:crit_percent] <= percent
83
+ critical message
84
+ elsif config[:warn_percent] > 0 && config[:warn_percent] <= percent
85
+ warning message
86
+ else
87
+ ok message
88
+ end
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,107 @@
1
+ #! /usr/bin/env ruby
2
+ #
3
+ # check-sqs-messages
4
+ #
5
+ # DESCRIPTION:
6
+ # This plugin checks the number of messages in an Amazon Web Services SQS queue.
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
+ # #YELLOW
20
+ #
21
+ #
22
+ # NOTES:
23
+ #
24
+ # LICENSE:
25
+ # Copyright (c) 2013, Justin Lambert <jlambert@letsevenup.com>
26
+ # Released under the same terms as Sensu (the MIT license); see LICENSE
27
+ # for details.
28
+ #
29
+
30
+ require 'rubygems' if RUBY_VERSION < '1.9.0'
31
+ require 'sensu-plugin/check/cli'
32
+ require 'aws-sdk'
33
+
34
+ class SQSMsgs < 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_ID'] or provide it as an option",
39
+ required: true
40
+
41
+ option :aws_secret_access_key,
42
+ short: '-s AWS_SECRET_ACCESS_KEY',
43
+ long: '--aws-secret-access-key AWS_SECRET_ACCESS_KEY',
44
+ description: "AWS Secret Access Key. Either set ENV['AWS_SECRET_ACCESS_KEY'] or provide it as an option",
45
+ required: true
46
+
47
+ option :aws_region,
48
+ description: 'AWS Region (such as us-east-1)',
49
+ short: '-r AWS_REGION',
50
+ long: '--aws-region AWS_REGION',
51
+ default: 'us-east-1'
52
+
53
+ option :queue,
54
+ short: '-q SQS_QUEUE',
55
+ long: '--queue SQS_QUEUE',
56
+ description: 'The name of the SQS you want to check the number of messages for',
57
+ required: true
58
+
59
+ option :warn_over,
60
+ short: '-w WARN_OVER',
61
+ long: '--warnnum WARN_OVER',
62
+ description: 'Number of messages in the queue considered to be a warning',
63
+ default: -1,
64
+ proc: proc(&:to_i)
65
+
66
+ option :crit_over,
67
+ short: '-c CRIT_OVER',
68
+ long: '--critnum CRIT_OVER',
69
+ description: 'Number of messages in the queue considered to be critical',
70
+ default: -1,
71
+ proc: proc(&:to_i)
72
+
73
+ option :warn_under,
74
+ short: '-W WARN_UNDER',
75
+ long: '--warnunder WARN_UNDER',
76
+ description: 'Minimum number of messages in the queue considered to be a warning',
77
+ default: -1,
78
+ proc: proc(&:to_i)
79
+
80
+ option :crit_under,
81
+ short: '-C CRIT_UNDER',
82
+ long: '--critunder CRIT_UNDER',
83
+ description: 'Minimum number of messages in the queue considered to be critical',
84
+ default: -1,
85
+ proc: proc(&:to_i)
86
+
87
+ def aws_config
88
+ hash = {}
89
+ hash.update access_key_id: config[:aws_access_key], secret_access_key: config[:aws_secret_access_key]\
90
+ if config[:aws_access_key] && config[:aws_secret_access_key]
91
+ hash
92
+ end
93
+
94
+ def run
95
+ AWS.config aws_config
96
+ sqs = AWS::SQS.new
97
+ messages = sqs.queues.named(config[:queue]).approximate_number_of_messages
98
+
99
+ if (config[:crit_under] >= 0 && messages < config[:crit_under]) || (config[:crit_over] >= 0 && messages > config[:crit_over])
100
+ critical "#{messages} message(s) in #{config[:queue]} queue"
101
+ elsif (config[:warn_under] >= 0 && messages < config[:warn_under]) || (config[:warn_over] >= 0 && messages > config[:warn_over])
102
+ warning "#{messages} message(s) in #{config[:queue]} queue"
103
+ else
104
+ ok "#{messages} messages in #{config[:queue]} queue"
105
+ end
106
+ end
107
+ end
@@ -0,0 +1,42 @@
1
+ #!/usr/bin/python
2
+
3
+ # #RED
4
+ import argparse
5
+ import boto.ec2
6
+ from boto.vpc import VPCConnection
7
+ import sys
8
+
9
+
10
+ def main():
11
+ try:
12
+ conn = boto.vpc.VPCConnection(aws_access_key_id=args.aws_access_key_id, aws_secret_access_key=args.aws_secret_access_key, region=boto.ec2.get_region(args.region))
13
+ except:
14
+ print "UNKNOWN: Unable to connect to reqion %s" % args.region
15
+ sys.exit(3)
16
+
17
+ errors = []
18
+ for vpn_connection in conn.get_all_vpn_connections():
19
+ for tunnel in vpn_connection.tunnels:
20
+ if tunnel.status != 'UP':
21
+ errors.append("[gateway: %s connection: %s tunnel: %s status: %s]" % (vpn_connection.vpn_gateway_id, vpn_connection.id, tunnel.outside_ip_address, tunnel.status))
22
+
23
+ if len(errors) > 1:
24
+ print 'CRITICAL: ' + ' '.join(errors)
25
+ sys.exit(2)
26
+ elif len(errors) > 0:
27
+ print 'WARN: ' + ' '.join(errors)
28
+ sys.exit(1)
29
+ else:
30
+ print 'OK'
31
+ sys.exit(0)
32
+
33
+ if __name__ == "__main__":
34
+ parser = argparse.ArgumentParser(description='Check status of all existing AWS VPC VPN Tunnels')
35
+
36
+ parser.add_argument('-a', '--aws-access-key-id', required=True, dest='aws_access_key_id', help='AWS Access Key')
37
+ parser.add_argument('-s', '--aws-secret-access-key', required=True, dest='aws_secret_access_key', help='AWS Secret Access Key')
38
+ parser.add_argument('-r', '--region', required=True, dest='region', help='AWS Region')
39
+
40
+ args = parser.parse_args()
41
+
42
+ main()