sensu-plugins-aws 8.3.1 → 9.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +11 -2
- data/README.md +24 -1
- data/bin/check-elb-certs.rb +13 -25
- data/bin/check-elb-health-sdk.rb +34 -35
- data/bin/check-elb-nodes.rb +11 -24
- data/bin/metrics-ec2-count.rb +22 -28
- data/bin/metrics-sqs.rb +14 -23
- data/lib/sensu-plugins-aws/version.rb +3 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d9c9a5b05f0eceeb66ab977506327e6016be83d6
|
4
|
+
data.tar.gz: eb220191ac04bbd05993e433b8d074395fef0655
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5e911db3dc5e23437a8c9cfd5b597a8474163de76cd63a369acddee9a119bae38f8ac120498c1aa5cd7dcd5430cd61484ca22c2ae5e51514649bfb7883f04db4
|
7
|
+
data.tar.gz: 51cf5702327ff35954abd5f679fac936bdd34ac0a83de53ada5ce4dab7d306f8ad50aaf74d2f5e73d5eec14606827971da06894152cdbef425d37882bea7f3cd
|
data/CHANGELOG.md
CHANGED
@@ -5,6 +5,14 @@ This CHANGELOG follows the format listed [here](https://github.com/sensu-plugins
|
|
5
5
|
|
6
6
|
## [Unreleased]
|
7
7
|
|
8
|
+
## [9.0.0] - 2017-10-16
|
9
|
+
### Breaking Changes
|
10
|
+
- metrics-sqs.rb, check-elb-certs.rb, check-elb-nodes.rb, check-elb-health-sdk.rb, metrics-ec2-count.rb: Update to AWS-SDK v2.
|
11
|
+
With the update to SDK v2 these checks no longer take `aws_access_key` and `aws_secret_access_key` options.
|
12
|
+
Credentials should be set in a credential file or with an IAM instance profile.
|
13
|
+
See the [auth section](https://github.com/sensu-plugins/sensu-plugins-aws/blob/master/README.md#authentication) of the README for
|
14
|
+
details on setting credentials. (@eheydrick)
|
15
|
+
|
8
16
|
## [8.3.1] - 2017-10-12
|
9
17
|
### Fixed
|
10
18
|
- check-eni-status.rb: fixed `ok` message to be correct (@damiendurant)
|
@@ -375,10 +383,11 @@ WARNING: This release contains major breaking changes that will impact all user
|
|
375
383
|
### Added
|
376
384
|
- initial release
|
377
385
|
|
378
|
-
[Unreleased]: https://github.com/sensu-plugins/sensu-plugins-aws/compare/
|
386
|
+
[Unreleased]: https://github.com/sensu-plugins/sensu-plugins-aws/compare/9.0.0...HEAD
|
387
|
+
[9.0.0]: https://github.com/sensu-plugins/sensu-plugins-aws/compare/8.3.1...9.0.0
|
379
388
|
[8.3.1]: https://github.com/sensu-plugins/sensu-plugins-aws/compare/8.3.0...8.3.1
|
380
389
|
[8.3.0]: https://github.com/sensu-plugins/sensu-plugins-aws/compare/8.2.0...8.3.0
|
381
|
-
[8.2.0]:https://github.com/sensu-plugins/sensu-plugins-aws/compare/8.1.0...8.2.0
|
390
|
+
[8.2.0]: https://github.com/sensu-plugins/sensu-plugins-aws/compare/8.1.0...8.2.0
|
382
391
|
[8.1.0]: https://github.com/sensu-plugins/sensu-plugins-aws/compare/8.0.0...8.1.0
|
383
392
|
[8.0.0]: https://github.com/sensu-plugins/sensu-plugins-aws/compare/7.1.0...8.0.0
|
384
393
|
[7.1.0]: https://github.com/sensu-plugins/sensu-plugins-aws/compare/7.0.1...7.1.0
|
data/README.md
CHANGED
@@ -252,4 +252,27 @@
|
|
252
252
|
|
253
253
|
[Installation and Setup](http://sensu-plugins.io/docs/installation_instructions.html)
|
254
254
|
|
255
|
-
Note: In addition to the standard installation requirements the installation of this gem will require compiling the nokogiri gem. Due to this you'll need certain
|
255
|
+
Note: In addition to the standard installation requirements the installation of this gem will require compiling the nokogiri gem. Due to this you'll need certain development packages on your system. On Ubuntu systems install build-essential, libxml2-dev and zlib1g-dev. On CentOS install gcc and zlib-devel.
|
256
|
+
|
257
|
+
## Authentication
|
258
|
+
|
259
|
+
AWS credentials are required to execute these checks. Starting with AWS-SDK v2 there are a few
|
260
|
+
methods of passing credentials to the check:
|
261
|
+
|
262
|
+
1. Use a [credential file](http://docs.aws.amazon.com/sdk-for-ruby/v2/developer-guide/setup-config.html#aws-ruby-sdk-credentials-shared). Place the credentials in `~/.aws/credentials`. On Unix-like systems this is going to be `/opt/sensu/.aws/credentials`. Be sure to restrict the file to the `sensu` user.
|
263
|
+
```
|
264
|
+
[default]
|
265
|
+
aws_access_key_id = <access_key>
|
266
|
+
aws_secret_access_key = <secret_access_key>
|
267
|
+
```
|
268
|
+
|
269
|
+
2. Use an [EC2 instance profile](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html). If the checks are executing on an EC2 instance you can give the instance an IAM role and authentication will be handled automatically.
|
270
|
+
|
271
|
+
See the [AWS-SDK docs](http://docs.aws.amazon.com/sdkforruby/api/#Configuration) for more details on
|
272
|
+
credential configuration.
|
273
|
+
|
274
|
+
Some of the checks accept credentials with `aws_access_key` and `aws_secret_access_key` options
|
275
|
+
however this method is deprecated as it is insecure to pass credentials on the command line. Support
|
276
|
+
for these options will be removed in future releases.
|
277
|
+
|
278
|
+
No matter which authentication method is used you should restrict AWS API access to the minimum required to run the checks. In general this is done by limiting the sensu IAM user/role to the necessary `Describe` calls for the services being checked.
|
data/bin/check-elb-certs.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
# check-elb-certs
|
4
4
|
#
|
5
5
|
# DESCRIPTION:
|
6
|
-
# This plugin looks up all ELBs in the
|
6
|
+
# This plugin looks up all ELBs in the region and checks https
|
7
7
|
# endpoints for expiring certificates
|
8
8
|
#
|
9
9
|
# OUTPUT:
|
@@ -13,13 +13,11 @@
|
|
13
13
|
# Linux
|
14
14
|
#
|
15
15
|
# DEPENDENCIES:
|
16
|
-
# gem: aws-sdk
|
16
|
+
# gem: aws-sdk
|
17
17
|
# gem: sensu-plugin
|
18
18
|
#
|
19
19
|
# USAGE:
|
20
|
-
# ./check-
|
21
|
-
# ./check-ec2-network.rb -r ${you_region} -i ${your_instance_id} -d NetworkIn --warning-over 1000000 --critical-over 1500000
|
22
|
-
# ./check-ec2-network.rb -r ${you_region} -i ${your_instance_id} -d NetworkOut --warning-over 1000000 --critical-over 1500000
|
20
|
+
# ./check-elb-certs.rb -r ${your_region} -w ${days_to_warn} -c ${days_to_critical}
|
23
21
|
#
|
24
22
|
# NOTES:
|
25
23
|
#
|
@@ -30,22 +28,13 @@
|
|
30
28
|
#
|
31
29
|
|
32
30
|
require 'sensu-plugin/check/cli'
|
33
|
-
require '
|
31
|
+
require 'sensu-plugins-aws'
|
32
|
+
require 'aws-sdk'
|
34
33
|
require 'net/http'
|
35
34
|
require 'openssl'
|
36
35
|
|
37
36
|
class CheckELBCerts < Sensu::Plugin::Check::CLI
|
38
|
-
|
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']
|
37
|
+
include Common
|
49
38
|
|
50
39
|
option :aws_region,
|
51
40
|
short: '-r AWS_REGION',
|
@@ -90,15 +79,14 @@ class CheckELBCerts < Sensu::Plugin::Check::CLI
|
|
90
79
|
warning_message = []
|
91
80
|
critical_message = []
|
92
81
|
|
93
|
-
|
94
|
-
|
95
|
-
elb = AWS::ELB.new aws_config
|
82
|
+
elb = Aws::ElasticLoadBalancing::Client.new(aws_config)
|
96
83
|
|
97
84
|
begin
|
98
|
-
elb.
|
99
|
-
lb.
|
100
|
-
|
101
|
-
|
85
|
+
elb.describe_load_balancers.load_balancer_descriptions.each do |lb|
|
86
|
+
lb.listener_descriptions.each do |listener|
|
87
|
+
elb_listener = listener['listener']
|
88
|
+
if elb_listener.protocol.to_s == 'HTTPS'
|
89
|
+
url = URI.parse("https://#{lb.dns_name}:#{elb_listener.load_balancer_port}")
|
102
90
|
http = Net::HTTP.new(url.host, url.port)
|
103
91
|
http.use_ssl = true
|
104
92
|
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
@@ -111,7 +99,7 @@ class CheckELBCerts < Sensu::Plugin::Check::CLI
|
|
111
99
|
end
|
112
100
|
|
113
101
|
cert_days_remaining = ((cert.not_after - Time.now) / 86_400).to_i
|
114
|
-
message = sprintf '%s(%d)', lb.
|
102
|
+
message = sprintf '%s(%d)', lb.load_balancer_name, cert_days_remaining
|
115
103
|
|
116
104
|
if config[:crit_under] > 0 && config[:crit_under] >= cert_days_remaining
|
117
105
|
critical_message << message
|
data/bin/check-elb-health-sdk.rb
CHANGED
@@ -12,13 +12,14 @@
|
|
12
12
|
# Linux
|
13
13
|
#
|
14
14
|
# DEPENDENCIES:
|
15
|
-
# gem: aws-sdk
|
15
|
+
# gem: aws-sdk
|
16
16
|
# gem: sensu-plugin
|
17
17
|
#
|
18
18
|
# USAGE:
|
19
19
|
# check-elb-health-sdk.rb -r region
|
20
20
|
# check-elb-health-sdk.rb -r region -n my-elb
|
21
21
|
# check-elb-health-sdk.rb -r region -n my-elb -i instance1,instance2
|
22
|
+
# check-alb-health-sdk.rb -r all
|
22
23
|
#
|
23
24
|
# Copyright (c) 2015, Benjamin Kett <bkett@umn.edu>
|
24
25
|
#
|
@@ -26,20 +27,11 @@
|
|
26
27
|
# for details.
|
27
28
|
|
28
29
|
require 'sensu-plugin/check/cli'
|
29
|
-
require '
|
30
|
+
require 'sensu-plugins-aws'
|
31
|
+
require 'aws-sdk'
|
30
32
|
|
31
33
|
class ELBHealth < Sensu::Plugin::Check::CLI
|
32
|
-
|
33
|
-
short: '-a AWS_ACCESS_KEY',
|
34
|
-
long: '--aws-access-key AWS_ACCESS_KEY',
|
35
|
-
description: "AWS Access Key. Either set ENV['AWS_ACCESS_KEY'] or provide it as an option",
|
36
|
-
default: ENV['AWS_ACCESS_KEY']
|
37
|
-
|
38
|
-
option :aws_secret_access_key,
|
39
|
-
short: '-k AWS_SECRET_KEY',
|
40
|
-
long: '--aws-secret-access-key AWS_SECRET_KEY',
|
41
|
-
description: "AWS Secret Access Key. Either set ENV['AWS_SECRET_KEY'] or provide it as an option",
|
42
|
-
default: ENV['AWS_SECRET_KEY']
|
34
|
+
include Common
|
43
35
|
|
44
36
|
option :aws_region,
|
45
37
|
short: '-r AWS_REGION',
|
@@ -82,43 +74,50 @@ class ELBHealth < Sensu::Plugin::Check::CLI
|
|
82
74
|
end
|
83
75
|
|
84
76
|
def elb
|
85
|
-
@elb =
|
77
|
+
@elb = Aws::ElasticLoadBalancing::Client.new(aws_config)
|
86
78
|
end
|
87
79
|
|
88
80
|
def ec2
|
89
|
-
@ec2 =
|
81
|
+
@ec2 = Aws::EC2::Client.new(aws_config)
|
90
82
|
end
|
91
83
|
|
92
84
|
def ec2_regions
|
93
|
-
|
94
|
-
|
85
|
+
Aws.partition('aws').regions.map(&:name)
|
86
|
+
end
|
95
87
|
|
96
|
-
|
88
|
+
def instances_to_check(instances)
|
89
|
+
all_instances = instances.split(',')
|
90
|
+
all_instances.map! { |instance| { instance_id: instance } }
|
97
91
|
end
|
98
92
|
|
99
93
|
def elbs
|
100
|
-
@elbs = elb.
|
101
|
-
@elbs.select! { |elb| config[:elb_name].include? elb.
|
94
|
+
@elbs = elb.describe_load_balancers.load_balancer_descriptions.to_a
|
95
|
+
@elbs.select! { |elb| config[:elb_name].include? elb.load_balancer_name } if config[:elb_name]
|
102
96
|
@elbs
|
103
97
|
end
|
104
98
|
|
105
99
|
def check_health(elb)
|
106
100
|
unhealthy_instances = {}
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
101
|
+
instance_health = if config[:instances]
|
102
|
+
@elb.describe_instance_health(
|
103
|
+
load_balancer_name: elb.load_balancer_name,
|
104
|
+
instances: instances_to_check(config[:instances])
|
105
|
+
)
|
106
|
+
else
|
107
|
+
@elb.describe_instance_health(load_balancer_name: elb.load_balancer_name)
|
108
|
+
end
|
109
|
+
|
110
|
+
instance_health.instance_states.each do |instance_health_states|
|
111
|
+
if instance_health_states.state != 'InService'
|
112
|
+
instance_id = instance_health_states.instance_id
|
113
|
+
state_message = instance_health_states.state
|
116
114
|
|
117
115
|
if config[:instance_tag]
|
118
|
-
|
119
|
-
|
116
|
+
selected_tag = ec2.describe_tags(
|
117
|
+
filters: [{ name: 'resource-id', values: [instance_id] }]
|
118
|
+
).tags.select { |tag| tag[:key] == config[:instance_tag] }
|
120
119
|
unless selected_tag.empty?
|
121
|
-
state_message = "#{selected_tag[0][:value]}::#{
|
120
|
+
state_message = "#{selected_tag[0][:value]}::#{instance_health_states[:state]}"
|
122
121
|
end
|
123
122
|
end
|
124
123
|
|
@@ -150,13 +149,13 @@ class ELBHealth < Sensu::Plugin::Check::CLI
|
|
150
149
|
region_critical = false
|
151
150
|
@message += (elbs.size > 1 ? config[:aws_region] + ': ' : '')
|
152
151
|
elbs.each do |elb|
|
153
|
-
result = check_health
|
152
|
+
result = check_health(elb)
|
154
153
|
if result != 'OK'
|
155
|
-
@message += "#{elb.
|
154
|
+
@message += "#{elb.load_balancer_name} unhealthy => #{result.map { |id, state| '[' + id + '::' + state + ']' }.join(' ')}. "
|
156
155
|
critical = true
|
157
156
|
region_critical = true
|
158
157
|
else
|
159
|
-
@message += "#{elb.
|
158
|
+
@message += "#{elb.load_balancer_name} => healthy. " unless config[:verbose] == false
|
160
159
|
end
|
161
160
|
end
|
162
161
|
if elbs.size > 1 && config[:verbose] != true && region_critical == false
|
data/bin/check-elb-nodes.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
#!/usr/bin/env ruby
|
2
2
|
#
|
3
3
|
# check-elb-nodes
|
4
4
|
#
|
@@ -13,7 +13,7 @@
|
|
13
13
|
# Linux
|
14
14
|
#
|
15
15
|
# DEPENDENCIES:
|
16
|
-
# gem: aws-sdk
|
16
|
+
# gem: aws-sdk
|
17
17
|
# gem: sensu-plugin
|
18
18
|
#
|
19
19
|
# USAGE:
|
@@ -32,20 +32,11 @@
|
|
32
32
|
#
|
33
33
|
|
34
34
|
require 'sensu-plugin/check/cli'
|
35
|
-
require '
|
35
|
+
require 'sensu-plugins-aws'
|
36
|
+
require 'aws-sdk'
|
36
37
|
|
37
38
|
class CheckELBNodes < Sensu::Plugin::Check::CLI
|
38
|
-
|
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']
|
39
|
+
include Common
|
49
40
|
|
50
41
|
option :aws_region,
|
51
42
|
short: '-r AWS_REGION',
|
@@ -94,23 +85,19 @@ class CheckELBNodes < Sensu::Plugin::Check::CLI
|
|
94
85
|
end
|
95
86
|
|
96
87
|
def run
|
97
|
-
|
98
|
-
elb = AWS::ELB.new aws_config
|
88
|
+
elb = Aws::ElasticLoadBalancing::Client.new(aws_config)
|
99
89
|
|
100
90
|
begin
|
101
|
-
|
102
|
-
rescue
|
91
|
+
instance_health = elb.describe_instance_health(load_balancer_name: config[:load_balancer])
|
92
|
+
rescue Aws::ElasticLoadBalancing::Errors::LoadBalancerNotFound
|
103
93
|
unknown "A load balancer with the name '#{config[:load_balancer]}' was not found"
|
104
94
|
end
|
105
95
|
|
106
|
-
num_instances =
|
96
|
+
num_instances = instance_health.instance_states.size
|
107
97
|
state = { 'OutOfService' => [], 'InService' => [], 'Unknown' => [] }
|
108
|
-
|
109
|
-
|
110
|
-
AWS.stop_memoizing if instance[:state] == 'Unknown'
|
111
|
-
state[instance[:state]] << instance[:instance].id
|
98
|
+
instance_health.instance_states.each do |instance|
|
99
|
+
state[instance.state] << instance.instance_id
|
112
100
|
end
|
113
|
-
AWS.stop_memoizing
|
114
101
|
|
115
102
|
message = "InService: #{state['InService'].count}"
|
116
103
|
if state['InService'].count > 0
|
data/bin/metrics-ec2-count.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
|
1
|
+
#!/usr/bin/env ruby
|
2
2
|
#
|
3
|
-
# ec2-count
|
3
|
+
# metrics-ec2-count
|
4
4
|
#
|
5
5
|
# DESCRIPTION:
|
6
|
-
# This plugin retrieves number of EC2 instances
|
6
|
+
# This plugin retrieves number of EC2 instances.
|
7
7
|
#
|
8
8
|
# OUTPUT:
|
9
9
|
# plain-text
|
@@ -12,11 +12,15 @@
|
|
12
12
|
# Linux
|
13
13
|
#
|
14
14
|
# DEPENDENCIES:
|
15
|
-
# gem: aws-sdk
|
15
|
+
# gem: aws-sdk
|
16
16
|
# gem: sensu-plugin
|
17
17
|
#
|
18
18
|
# USAGE:
|
19
|
-
# #
|
19
|
+
# # get metrics on the status of all instances in the region
|
20
|
+
# metrics-ec2-count.rb -t status
|
21
|
+
#
|
22
|
+
# # get metrics on all instance types in the region
|
23
|
+
# metrics-ec2-count.rb -t instance
|
20
24
|
#
|
21
25
|
# NOTES:
|
22
26
|
#
|
@@ -27,27 +31,18 @@
|
|
27
31
|
#
|
28
32
|
|
29
33
|
require 'sensu-plugin/metric/cli'
|
30
|
-
require '
|
34
|
+
require 'sensu-plugins-aws'
|
35
|
+
require 'aws-sdk'
|
31
36
|
|
32
37
|
class EC2Metrics < Sensu::Plugin::Metric::CLI::Graphite
|
38
|
+
include Common
|
39
|
+
|
33
40
|
option :scheme,
|
34
41
|
description: 'Metric naming scheme, text to prepend to metric',
|
35
42
|
short: '-s SCHEME',
|
36
43
|
long: '--scheme SCHEME',
|
37
44
|
default: 'sensu.aws.ec2'
|
38
45
|
|
39
|
-
option :aws_access_key,
|
40
|
-
short: '-a AWS_ACCESS_KEY',
|
41
|
-
long: '--aws-access-key AWS_ACCESS_KEY',
|
42
|
-
description: "AWS Access Key. Either set ENV['AWS_ACCESS_KEY'] or provide it as an option",
|
43
|
-
default: ENV['AWS_ACCESS_KEY']
|
44
|
-
|
45
|
-
option :aws_secret_access_key,
|
46
|
-
short: '-k AWS_SECRET_KEY',
|
47
|
-
long: '--aws-secret-access-key AWS_SECRET_KEY',
|
48
|
-
description: "AWS Secret Access Key. Either set ENV['AWS_SECRET_KEY'] or provide it as an option",
|
49
|
-
default: ENV['AWS_SECRET_KEY']
|
50
|
-
|
51
46
|
option :aws_region,
|
52
47
|
short: '-r AWS_REGION',
|
53
48
|
long: '--aws-region REGION',
|
@@ -72,14 +67,14 @@ class EC2Metrics < Sensu::Plugin::Metric::CLI::Graphite
|
|
72
67
|
end
|
73
68
|
|
74
69
|
options = { include_all_instances: true }
|
75
|
-
|
70
|
+
status_data = client.describe_instance_status(options)
|
76
71
|
|
77
|
-
total =
|
72
|
+
total = status_data.instance_statuses.count
|
78
73
|
status = {}
|
79
74
|
|
80
75
|
unless total.nil?
|
81
|
-
|
82
|
-
stat = value
|
76
|
+
status_data.instance_statuses.each do |value|
|
77
|
+
stat = value.instance_state.name
|
83
78
|
status[stat] = if status[stat].nil?
|
84
79
|
1
|
85
80
|
else
|
@@ -88,7 +83,7 @@ class EC2Metrics < Sensu::Plugin::Metric::CLI::Graphite
|
|
88
83
|
end
|
89
84
|
end
|
90
85
|
|
91
|
-
unless
|
86
|
+
unless status_data.nil? # rubocop: disable Style/GuardClause
|
92
87
|
# We only return data when we have some to return
|
93
88
|
output config[:scheme] + '.total', total
|
94
89
|
status.each do |name, count|
|
@@ -105,9 +100,9 @@ class EC2Metrics < Sensu::Plugin::Metric::CLI::Graphite
|
|
105
100
|
data = {}
|
106
101
|
|
107
102
|
instances = client.describe_instances
|
108
|
-
instances
|
109
|
-
i
|
110
|
-
type = instance
|
103
|
+
instances.reservations.each do |i|
|
104
|
+
i.instances.each do |instance|
|
105
|
+
type = instance.instance_type
|
111
106
|
data[type] = if data[type].nil?
|
112
107
|
1
|
113
108
|
else
|
@@ -126,8 +121,7 @@ class EC2Metrics < Sensu::Plugin::Metric::CLI::Graphite
|
|
126
121
|
|
127
122
|
def run
|
128
123
|
begin
|
129
|
-
|
130
|
-
client = AWS::EC2::Client.new aws_config
|
124
|
+
client = Aws::EC2::Client.new(aws_config)
|
131
125
|
|
132
126
|
if config[:type] == 'instance'
|
133
127
|
by_instances_type(client)
|
data/bin/metrics-sqs.rb
CHANGED
@@ -12,12 +12,12 @@
|
|
12
12
|
# Linux
|
13
13
|
#
|
14
14
|
# DEPENDENCIES:
|
15
|
-
# gem: aws-sdk
|
15
|
+
# gem: aws-sdk
|
16
16
|
# gem: sensu-plugin
|
17
17
|
#
|
18
18
|
# USAGE:
|
19
|
-
# metrics-sqs -q my_queue
|
20
|
-
# metrics-sqs -p queue_prefix_
|
19
|
+
# metrics-sqs -q my_queue
|
20
|
+
# metrics-sqs -p queue_prefix_
|
21
21
|
#
|
22
22
|
# NOTES:
|
23
23
|
#
|
@@ -28,9 +28,12 @@
|
|
28
28
|
#
|
29
29
|
|
30
30
|
require 'sensu-plugin/metric/cli'
|
31
|
-
require '
|
31
|
+
require 'sensu-plugins-aws'
|
32
|
+
require 'aws-sdk'
|
32
33
|
|
33
34
|
class SQSMetrics < Sensu::Plugin::Metric::CLI::Graphite
|
35
|
+
include Common
|
36
|
+
|
34
37
|
option :queue,
|
35
38
|
description: 'Name of the queue',
|
36
39
|
short: '-q QUEUE',
|
@@ -49,18 +52,6 @@ class SQSMetrics < Sensu::Plugin::Metric::CLI::Graphite
|
|
49
52
|
long: '--scheme SCHEME',
|
50
53
|
default: ''
|
51
54
|
|
52
|
-
option :aws_access_key,
|
53
|
-
description: "AWS Access Key. Either set ENV['AWS_ACCESS_KEY'] or provide it as an option",
|
54
|
-
short: '-a AWS_ACCESS_KEY',
|
55
|
-
long: '--aws-access-key AWS_ACCESS_KEY',
|
56
|
-
default: ENV['AWS_ACCESS_KEY']
|
57
|
-
|
58
|
-
option :aws_secret_access_key,
|
59
|
-
description: "AWS Secret Access Key. Either set ENV['AWS_SECRET_ACCESS_KEY'] or provide it as an option",
|
60
|
-
short: '-k AWS_SECRET_KEY',
|
61
|
-
long: '--aws-secret-access-key AWS_SECRET_KEY',
|
62
|
-
default: ENV['AWS_SECRET_KEY']
|
63
|
-
|
64
55
|
option :aws_region,
|
65
56
|
description: 'AWS Region (defaults to us-east-1).',
|
66
57
|
short: '-r AWS_REGION',
|
@@ -79,24 +70,24 @@ class SQSMetrics < Sensu::Plugin::Metric::CLI::Graphite
|
|
79
70
|
end
|
80
71
|
|
81
72
|
def record_queue_metrics(q_name, q)
|
82
|
-
output scheme(q_name), q.
|
83
|
-
output "#{scheme(q_name)}.delayed", q.
|
84
|
-
output "#{scheme(q_name)}.not_visible", q.
|
73
|
+
output scheme(q_name), q.attributes['ApproximateNumberOfMessages'].to_i
|
74
|
+
output "#{scheme(q_name)}.delayed", q.attributes['ApproximateNumberOfMessagesDelayed'].to_i
|
75
|
+
output "#{scheme(q_name)}.not_visible", q.attributes['ApproximateNumberOfMessagesNotVisible'].to_i
|
85
76
|
end
|
86
77
|
|
87
78
|
def run
|
88
79
|
begin
|
89
|
-
sqs =
|
80
|
+
sqs = Aws::SQS::Resource.new(aws_config)
|
90
81
|
|
91
82
|
if config[:prefix] == ''
|
92
83
|
if config[:queue] == ''
|
93
84
|
critical 'Error, either QUEUE or PREFIX must be specified'
|
94
85
|
end
|
95
86
|
|
96
|
-
record_queue_metrics(config[:queue], sqs.
|
87
|
+
record_queue_metrics(config[:queue], sqs.get_queue_by_name(queue_name: config[:queue]))
|
97
88
|
else
|
98
|
-
sqs.queues
|
99
|
-
record_queue_metrics(q.
|
89
|
+
sqs.queues(queue_name_prefix: config[:prefix]).each do |q|
|
90
|
+
record_queue_metrics(q.attributes['QueueArn'].split(':').last, q)
|
100
91
|
end
|
101
92
|
end
|
102
93
|
rescue => e
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sensu-plugins-aws
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 9.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sensu-Plugins and contributors
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-10-
|
11
|
+
date: 2017-10-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk
|