sensu-plugins-aws 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d1510edf78fde0477592736fb6a25174068aea6f
4
- data.tar.gz: 3230a421cb5f4f07c7c8697b68500e9de59a480e
3
+ metadata.gz: d8e18850d95e6ba9318753d772c1e47a27a869ea
4
+ data.tar.gz: 7183226959ec68b20c3d10b6c389a657ed5673bc
5
5
  SHA512:
6
- metadata.gz: ad8f2bbd6f05d6333383f53d8c0ab50922fad826c73e83c308042bf308c96eaa64f8b9effd80522a28922d201535ef2e0824d70ddfa6220dd8027ce7d2edcb6c
7
- data.tar.gz: a47164e6147c093b74ac78d41df199ad1cfed09a7643e6e255647cb8c869f6a25b2175103caf96226955c0b2f90422aae7c0c40f34a328a242b7bfb0977a887b
6
+ metadata.gz: 001e818b18007dd33efbee3c123b04963803dd4d2906065c638107ac5fc6ea73cd533bf680d61c6a946ee9e2f25f9d9f12344683e9c8ad87586c4df60ba7c1f6
7
+ data.tar.gz: 8c61028e2fe855c90d9c9c6106822e1ae3045ed4f67bc953444cc9ec777f24b5579681d625a27e20877c5dce962792deee88aa538659f7003bf76c3a28939e5b
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -3,7 +3,15 @@ This project adheres to [Semantic Versioning](http://semver.org/).
3
3
 
4
4
  This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachangelog.com/)
5
5
 
6
- ## [1.1.0] - 2015-07-24
6
+ ## [1.2.0] - 2015-08-04
7
+ ### Added
8
+ - Added check-ec2-filter to compare filter results to given thresholds
9
+ - Added check-vpc-nameservers, which given a VPC will validate the name servers in the DHCP option set.
10
+
11
+ ### Fixed
12
+ - handler-ec2_node accounts for an empty instances array
13
+
14
+ ## [1.1.0] - 2015-07-24
7
15
  ### Added
8
16
  - Added new AWS SES handler - handler-ses.rb
9
17
  - Add metrics-ec2-filter to store node ids and count matching a given filter
@@ -20,6 +28,7 @@ WARNING: This release contains major breaking changes that will impact all user
20
28
  - Added support for checking multiple ELB instances at once by passing a comma separated list of ELB instance names in metrics-elb-full.rb
21
29
  - Added check-autoscaling-cpucredits.rb for checking T2 instances in autoscaling groups that are running low on CPU credits
22
30
  - Updated the fog and aws-sdk gems to the latest versions to improve performance, reduce 3rd party gem dependencies, and add support for newer AWS features.
31
+ - Add metrics-ec2-filter to store node ids and count matching a given filter
23
32
 
24
33
  ### Fixed
25
34
  - Renamed autoscaling-instance-count-metrics.rb -> metrics-autoscaling-instance-count.rb to match our naming scheme
data/README.md CHANGED
@@ -17,6 +17,8 @@
17
17
 
18
18
  **check-ebs-snapshots.rb**
19
19
 
20
+ **check-ec2-filter.rb**
21
+
20
22
  **check-ec2-network.rb**
21
23
 
22
24
  **check-eip-allocation.rb**
@@ -47,6 +49,8 @@
47
49
 
48
50
  **check-sqs-messages.rb**
49
51
 
52
+ **check-vpc-nameservers**
53
+
50
54
  **check_vpc_vpn.py**
51
55
 
52
56
  **handler-ec2_node.rb**
@@ -76,6 +80,7 @@
76
80
  * /bin/check-dynamodb-capacity.rb
77
81
  * /bin/check-dynamodb-throttle.rb
78
82
  * /bin/check-ebs-snapshots.rb
83
+ * /bin/check-ec2-filter.rb
79
84
  * /bin/check-ec2-network.rb
80
85
  * /bin/check-elb-certs.rb
81
86
  * /bin/check-elb-health-fog.rb
@@ -90,6 +95,7 @@
90
95
  * /bin/check-redshift-events.rb
91
96
  * /bin/check-ses-limit.rb
92
97
  * /bin/check-sqs-messages.rb
98
+ * /bin/check-vpc-nameservers.rb
93
99
  * /bin/check_vpc_vpn.py
94
100
  * /bin/handler-ec2_node.rb
95
101
  * /bin/handler-ses.rb
@@ -0,0 +1,147 @@
1
+ #! /usr/bin/env ruby
2
+ #
3
+ # check-ec2-filter
4
+ #
5
+ # DESCRIPTION:
6
+ # This plugin retrieves EC2 instances matching a given filter and
7
+ # returns the number matched. Warning and Critical thresholds may be set as needed.
8
+ # Thresholds may be compared to the count using [equal, not, greater, less] operators.
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
+ # ./check-ec2-filter.rb -w 20 -f "{name:tag-value,values:[infrastructure]}"
22
+ # ./check-ec2-filter.rb -w 10 -c 5 -o less -f "{name:tag-value,values:[infrastructure]} {name:instance-state-name,values:[running]}"
23
+ #
24
+ # NOTES:
25
+ #
26
+ # LICENSE:
27
+ # Justin McCarty
28
+ # Released under the same terms as Sensu (the MIT license); see LICENSE
29
+ # for details.
30
+ #
31
+
32
+ require 'sensu-plugin/check/cli'
33
+ require 'aws-sdk'
34
+ require 'sensu-plugins-aws/filter'
35
+
36
+ class EC2Filter < Sensu::Plugin::Check::CLI
37
+ include Filter
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 :name,
57
+ description: 'Filter naming scheme, text to prepend to metric',
58
+ short: '-n NAME',
59
+ long: '--name NAME',
60
+ default: ''
61
+
62
+ option :filter,
63
+ short: '-f FILTER',
64
+ long: '--filter FILTER',
65
+ description: 'String representation of the filter to apply',
66
+ default: '{}'
67
+
68
+ option :warning,
69
+ description: 'Warning threshold for filter',
70
+ short: '-w COUNT',
71
+ long: '--warning COUNT'
72
+
73
+ option :critical,
74
+ description: 'Critical threshold for filter',
75
+ short: '-c COUNT',
76
+ long: '--critical COUNT'
77
+
78
+ option :compare,
79
+ description: 'Comparision operator for threshold: equal, not, greater, less',
80
+ short: '-o OPERATION',
81
+ long: '--opertor OPERATION',
82
+ default: 'equal'
83
+
84
+ def aws_config
85
+ { access_key_id: config[:aws_access_key],
86
+ secret_access_key: config[:aws_secret_access_key],
87
+ region: config[:aws_region]
88
+ }
89
+ end
90
+
91
+ def convert_operator
92
+ op = ->(c, t) { c == t }
93
+
94
+ if config[:compare] == 'greater'
95
+ op = ->(c, t) { c > t }
96
+ elsif config[:compare] == 'less'
97
+ op = ->(c, t) { c < t }
98
+ elsif config[:compare] == 'not'
99
+ op = ->(c, t) { c != t }
100
+ end
101
+
102
+ op
103
+ end
104
+
105
+ def run
106
+ client = Aws::EC2::Client.new aws_config
107
+
108
+ filter = Filter.parse(config[:filter])
109
+
110
+ if filter.empty?
111
+ options = {}
112
+ else
113
+ options = { filters: filter }
114
+ end
115
+
116
+ data = client.describe_instances(options)
117
+
118
+ instance_ids = Set.new
119
+
120
+ data[:reservations].each do |res|
121
+ res[:instances].each do |i|
122
+ instance_ids << i[:instance_id]
123
+ end
124
+ end
125
+
126
+ count = instance_ids.count
127
+ op = convert_operator
128
+ message = "Current count: #{count}"
129
+
130
+ unless config[:critical].nil?
131
+ if op.call count, config[:critical].to_i
132
+ critical message
133
+ end
134
+ end
135
+
136
+ unless config[:warning].nil?
137
+ if op.call count, config[:warning].to_i
138
+ warning message
139
+ end
140
+ end
141
+
142
+ ok message
143
+ rescue => e
144
+ puts "Error: exception: #{e}"
145
+ critical
146
+ end
147
+ end
@@ -0,0 +1,87 @@
1
+ #! /usr/bin/env ruby
2
+ #
3
+ # check-vpc-nameservers
4
+ #
5
+ # DESCRIPTION:
6
+ # Checks the VPCs nameservers are functional
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-vpc-nameservers.rb -v vpc-12345678
20
+ # ./check-vpc-nameservers.rb -v vpc-12345678 -r us-east-1
21
+ # ./check-vpc-nameservers.rb -v vpc-12345678 -r us-east-1 -q google.com,internal.private.servers
22
+ #
23
+ # NOTES:
24
+ #
25
+ # LICENSE:
26
+ # Shane Starcher <shane.starcher@gmail.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 'sensu-plugins-aws'
33
+ require 'aws-sdk'
34
+ require 'resolv'
35
+
36
+ class CheckVpcNameservers < Sensu::Plugin::Check::CLI
37
+ include Common
38
+ option :queries,
39
+ short: '-q queries',
40
+ long: '--queries google.com,example1.com',
41
+ proc: proc { |a| a.split(',') },
42
+ default: ['google.com'],
43
+ description: 'Comma seperated dns queries to test'
44
+
45
+ option :vpc_id,
46
+ short: '-v vpc_id',
47
+ long: '--vpc_id vpc-12345678',
48
+ required: true,
49
+ description: 'The vpc_id of the dhcp option set'
50
+
51
+ option :aws_region,
52
+ short: '-r R',
53
+ long: '--region REGION',
54
+ description: 'AWS region',
55
+ default: 'us-east-1'
56
+
57
+ def run
58
+ errors = []
59
+ ec2 = Aws::EC2::Client.new
60
+
61
+ dhcp_option_id = ec2.describe_vpcs(vpc_ids: [config[:vpc_id]]).vpcs[0].dhcp_options_id
62
+
63
+ options = ec2.describe_dhcp_options(dhcp_options_ids: [dhcp_option_id])
64
+
65
+ options.dhcp_options.each do |option|
66
+ option.dhcp_configurations.each do |map|
67
+ next if map.key != 'domain-name-servers'
68
+ map.values.each do |value|
69
+ ip = value.value
70
+ config[:queries].each do |query|
71
+ begin
72
+ Resolv::DNS.open(nameserver: [ip]).getaddress(query)
73
+ rescue Resolv::ResolvError => res_err
74
+ errors << "[#{ip}] #{res_err} "
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end
80
+
81
+ if errors.empty?
82
+ ok
83
+ else
84
+ warning errors.join("\n")
85
+ end
86
+ end
87
+ end
@@ -1,6 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
2
  #
3
3
  # CHANGELOG:
4
+ # * 0.6.0:
5
+ # - Fixed ec2_node_should_be_deleted to account for an empty insances array
4
6
  # * 0.5.0:
5
7
  # - Adds configuration to filter by state reason
6
8
  # * 0.4.0:
@@ -130,7 +132,7 @@ class Ec2Node < Sensu::Handler
130
132
  states = @event['client']['ec2_states'] || settings['ec2_node']['ec2_states'] || ['shutting-down', 'terminated', 'stopping', 'stopped']
131
133
  begin
132
134
  instances = ec2.describe_instances(instance_ids: [@event['client']['name']]).reservations[0]
133
- if instances.nil?
135
+ if instances.nil? || instances.empty?
134
136
  true
135
137
  else
136
138
  instance = instances.instances[0]
@@ -29,8 +29,10 @@
29
29
 
30
30
  require 'sensu-plugin/metric/cli'
31
31
  require 'aws-sdk'
32
+ require 'sensu-plugins-aws/filter'
32
33
 
33
34
  class EC2Filter < Sensu::Plugin::Metric::CLI::Graphite
35
+ include Filter
34
36
  option :aws_access_key,
35
37
  short: '-a AWS_ACCESS_KEY',
36
38
  long: '--aws-access-key AWS_ACCESS_KEY',
@@ -74,35 +76,11 @@ class EC2Filter < Sensu::Plugin::Metric::CLI::Graphite
74
76
  }
75
77
  end
76
78
 
77
- def convert_filter(input)
78
- filter = []
79
- items = input.scan(/{.*?}/)
80
-
81
- items.each do |item|
82
- if item.strip.empty?
83
- fail 'Invalid filter syntax'
84
- end
85
-
86
- entry = {}
87
- name = item.scan(/name:(.*?),/)
88
- value = item.scan(/values:\[(.*?)\]/)
89
-
90
- if name.nil? || name.empty? || value.nil? || value.empty?
91
- fail 'Unable to parse filter entry'
92
- end
93
-
94
- entry[:name] = name[0][0].strip
95
- entry[:values] = value[0][0].split(',')
96
- filter << entry
97
- end
98
- filter
99
- end
100
-
101
79
  def run
102
80
  begin
103
81
  client = Aws::EC2::Client.new aws_config
104
82
 
105
- filter = convert_filter(config[:filter])
83
+ filter = Filter.parse(config[:filter])
106
84
 
107
85
  options = { filters: filter }
108
86
 
@@ -1,3 +1,4 @@
1
1
 
2
2
  require 'sensu-plugins-aws/version'
3
3
  require 'sensu-plugins-aws/common'
4
+ require 'sensu-plugins-aws/filter'
@@ -0,0 +1,47 @@
1
+ #
2
+ # DESCRIPTION:
3
+ # Filter methods for aws quieries
4
+ #
5
+ # DEPENDENCIES:
6
+ #
7
+ # USAGE:
8
+ # Filter.parse(string)
9
+ #
10
+ # NOTES:
11
+ #
12
+ # LICENSE:
13
+ # Justin McCarty (jmccarty3@gmail.com)
14
+ # Released under the same terms as Sensu (the MIT license); see LICENSE
15
+ # for details.
16
+ #
17
+
18
+ module Filter
19
+ def self.parse(input)
20
+ filter = []
21
+
22
+ if input == '{}'
23
+ return filter
24
+ end
25
+
26
+ items = input.scan(/{.*?}/)
27
+
28
+ items.each do |item|
29
+ if item.strip.empty?
30
+ fail 'Invalid filter syntax'
31
+ end
32
+
33
+ entry = {}
34
+ name = item.scan(/name:(.*?),/)
35
+ value = item.scan(/values:\[(.*?)\]/)
36
+
37
+ if name.nil? || name.empty? || value.nil? || value.empty?
38
+ fail 'Unable to parse filter entry'
39
+ end
40
+
41
+ entry[:name] = name[0][0].strip
42
+ entry[:values] = value[0][0].split(',')
43
+ filter << entry
44
+ end
45
+ filter
46
+ end
47
+ end
@@ -5,7 +5,7 @@ module SensuPluginsAWS
5
5
  # This defines the version of the gem
6
6
  module Version
7
7
  MAJOR = 1
8
- MINOR = 1
8
+ MINOR = 2
9
9
  PATCH = 0
10
10
 
11
11
  VER_STRING = [MAJOR, MINOR, PATCH].compact.join('.')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sensu-plugins-aws
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sensu-Plugins and contributors
@@ -30,7 +30,7 @@ cert_chain:
30
30
  8sHuVruarogxxKPBzlL2is4EUb6oN/RdpGx2l4254+nyR+abg//Ed27Ym0PkB4lk
31
31
  HP0m8WSjZmFr109pE/sVsM5jtOCvogyujQOjNVGN4gz1wwPr
32
32
  -----END CERTIFICATE-----
33
- date: 2015-07-24 00:00:00.000000000 Z
33
+ date: 2015-08-04 00:00:00.000000000 Z
34
34
  dependencies:
35
35
  - !ruby/object:Gem::Dependency
36
36
  name: sensu-plugin
@@ -242,6 +242,7 @@ executables:
242
242
  - handler-ses.rb
243
243
  - handler-ec2_node.rb
244
244
  - check_vpc_vpn.py
245
+ - check-vpc-nameservers.rb
245
246
  - check-sqs-messages.rb
246
247
  - check-ses-limit.rb
247
248
  - check-redshift-events.rb
@@ -257,6 +258,7 @@ executables:
257
258
  - check-elb-certs.rb
258
259
  - check-eip-allocation.rb
259
260
  - check-ec2-network.rb
261
+ - check-ec2-filter.rb
260
262
  - check-ebs-snapshots.rb
261
263
  - check-dynamodb-throttle.rb
262
264
  - check-dynamodb-capacity.rb
@@ -271,6 +273,7 @@ files:
271
273
  - bin/check-dynamodb-capacity.rb
272
274
  - bin/check-dynamodb-throttle.rb
273
275
  - bin/check-ebs-snapshots.rb
276
+ - bin/check-ec2-filter.rb
274
277
  - bin/check-ec2-network.rb
275
278
  - bin/check-eip-allocation.rb
276
279
  - bin/check-elb-certs.rb
@@ -286,6 +289,7 @@ files:
286
289
  - bin/check-redshift-events.rb
287
290
  - bin/check-ses-limit.rb
288
291
  - bin/check-sqs-messages.rb
292
+ - bin/check-vpc-nameservers.rb
289
293
  - bin/check_vpc_vpn.py
290
294
  - bin/handler-ec2_node.rb
291
295
  - bin/handler-ses.rb
@@ -299,6 +303,7 @@ files:
299
303
  - bin/metrics-sqs.rb
300
304
  - lib/sensu-plugins-aws.rb
301
305
  - lib/sensu-plugins-aws/common.rb
306
+ - lib/sensu-plugins-aws/filter.rb
302
307
  - lib/sensu-plugins-aws/version.rb
303
308
  homepage: https://github.com/sensu-plugins/sensu-plugins-aws
304
309
  licenses:
@@ -326,7 +331,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
326
331
  version: '0'
327
332
  requirements: []
328
333
  rubyforge_project:
329
- rubygems_version: 2.4.6
334
+ rubygems_version: 2.4.8
330
335
  signing_key:
331
336
  specification_version: 4
332
337
  summary: Sensu plugins for working with an AWS environment
metadata.gz.sig CHANGED
Binary file