sensu-plugins-aws 4.0.0 → 4.1.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: c485509a9d40dee7713b4225ede97470a3f0cefb
4
- data.tar.gz: 9e8c41bcc8f9694fd3703b3c76d6707f381fe69a
3
+ metadata.gz: ffd1f6a42abd1a5201a34df72564a7774a7f3c29
4
+ data.tar.gz: 38cf5c5cc6c757dcef503d825c50938ef02f2158
5
5
  SHA512:
6
- metadata.gz: d28050bd2fe7ca47eca3d4117217d53bd3a5f4670d3aa8fc266a9cbee270047a658a57a4a8ffdee241001d9a5e09db0c0bf4a8c2da87e45d0c3be48d34962b66
7
- data.tar.gz: 9edec98c9020e813eefe61855430aa79e68fab69af5a6ff683ee92c6a0dbd397a217c4f284ec182728f9a72fa0809f6f29ba5a5f0cd23ab90362f4ed5970ccb4
6
+ metadata.gz: c56ed6c76d340f357509aae2676c0b0a1aac1ebff884aa71d50b3332207887c70102255885ea4359a320fbd7dc8bec463e0002baa23aaa35e6894e93a2176d72
7
+ data.tar.gz: ca41201cc25e0ba58658c5bdedf4717c6d8150fdcd5fd8f0d790ce4f8f4dacfe3f7fd6eea3cbb8996347cdb754be8104ae95ab6842c5212af3f2ec5e25bf10f4
data/CHANGELOG.md CHANGED
@@ -5,6 +5,20 @@ This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachang
5
5
 
6
6
  ## [Unreleased]
7
7
 
8
+ ## [4.1.0] - 2017-05-01
9
+ ### Added
10
+ - check-cloudwatch-composite-metric.rb: Allow calculation of percentage for cloudwatch metrics by composing two metrics (@cornelf) (numerator_metric/denominator_metric * 100) as a percentage. This is useful to skip pushing such metrics to graphite in order to get the percentage metric computed.
11
+ - check-cloudwatch-composite-metric.rb: protect against zero division errors (@cornelf)
12
+ - check-sqs-messages.rb now supports specifying multiple queues wihtout a prefix (@majormoses)
13
+ - check-asg-instances-created.rb is a new check that allows looking at the number od instances created in the last hour (@phoppe93)
14
+
15
+ ### Changed
16
+ - check-sns-subscriptions.rb improved error messages (@obazoud)
17
+
18
+ ### Fixed
19
+ - lib/sensu-plugins-aws/cloudwatch-common.rb use the most recent datapoint (@mivok)
20
+
21
+
8
22
  ## [4.0.0] - 2016-12-27
9
23
  ### Breaking Changes
10
24
  - `check-sqs-messages.rb`, `check-vpc-vpn.rb`, and `metrics-elb.rb` were updated to aws-sdk v2 and no longer take `aws_access_key` and `aws_secret_access_key` options.
@@ -275,7 +289,8 @@ WARNING: This release contains major breaking changes that will impact all user
275
289
  ### Added
276
290
  - initial release
277
291
 
278
- [Unreleased]: https://github.com/sensu-plugins/sensu-plugins-aws/compare/4.0.0...HEAD
292
+ [Unreleased]: https://github.com/sensu-plugins/sensu-plugins-aws/compare/4.1.0...HEAD
293
+ [4.1.0]: https://github.com/sensu-plugins/sensu-plugins-aws/compare/4.1.0...4.0.0
279
294
  [4.0.0]: https://github.com/sensu-plugins/sensu-plugins-aws/compare/3.2.1...4.0.0
280
295
  [3.2.1]: https://github.com/sensu-plugins/sensu-plugins-aws/compare/3.2.0...3.2.1
281
296
  [3.2.0]: https://github.com/sensu-plugins/sensu-plugins-aws/compare/3.1.0...3.2.0
data/README.md CHANGED
@@ -20,6 +20,10 @@
20
20
 
21
21
  **check-cloudwatch-alarm**
22
22
 
23
+ **check-cloudwatch-metric**
24
+
25
+ **check-cloudwatch-composite-metric**
26
+
23
27
  **check-cloudfront-tag**
24
28
 
25
29
  **check-configservice-rules**
@@ -153,6 +157,8 @@
153
157
  * /bin/check-configservice-rules.rb
154
158
  * /bin/check-cloudfront-tag.rb
155
159
  * /bin/check-cloudwatch-alarm.rb
160
+ * /bin/check-cloudwatch-metric.rb
161
+ * /bin/check-cloudwatch-composite-metric.rb
156
162
  * /bin/check-dynamodb-capacity.rb
157
163
  * /bin/check-dynamodb-throttle.rb
158
164
  * /bin/check-ebs-burst-limit.rb
@@ -0,0 +1,132 @@
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| CloudWatchCompositeMetricCheck.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',
89
+ short: '-c VALUE',
90
+ long: '--critical VALUE',
91
+ proc: proc(&:to_f),
92
+ required: true
93
+
94
+ option :warning,
95
+ description: 'Trigger a critical when value is over VALUE',
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 :no_data_ok,
107
+ short: '-O',
108
+ long: '--allow-no-data',
109
+ description: 'Returns ok if no data is returned from the metric',
110
+ boolean: true,
111
+ default: false
112
+
113
+ include CloudwatchCommon
114
+
115
+ def self.parse_dimensions(dimension_string)
116
+ dimension_string.split(',')
117
+ .collect { |d| d.split '=' }
118
+ .collect { |a| { name: a[0], value: a[1] } }
119
+ end
120
+
121
+ def dimension_string
122
+ config[:dimensions].map { |d| "#{d[:name]}=#{d[:value]}" }.join('&')
123
+ end
124
+
125
+ def metric_desc
126
+ "#{config[:namespace]}-#{config[:numerator_metric_name]}/#{config[:denominator_metric_name]}(#{dimension_string})"
127
+ end
128
+
129
+ def run
130
+ composite_check config
131
+ end
132
+ end
@@ -44,9 +44,9 @@ class CheckSNSSubscriptions < Sensu::Plugin::Check::CLI
44
44
 
45
45
  subscriptions = sns.list_subscriptions.subscriptions
46
46
 
47
- pending_confirmations = subscriptions.select { |subscription| subscription.subscription_arn == 'PendingConfirmation' }
47
+ pending_confirmations = subscriptions.select { |subscription| subscription.subscription_arn == 'PendingConfirmation' }.map(&:topic_arn)
48
48
 
49
- critical "#{pending_confirmations.size} pending confirmations" unless pending_confirmations.empty?
49
+ critical "#{pending_confirmations.size} pending confirmations (#{pending_confirmations})" unless pending_confirmations.empty?
50
50
  ok
51
51
  end
52
52
  end
@@ -46,7 +46,7 @@ class SQSMsgs < Sensu::Plugin::Check::CLI
46
46
  option :queue,
47
47
  short: '-q SQS_QUEUE',
48
48
  long: '--queue SQS_QUEUE',
49
- description: 'The name of the SQS you want to check the number of messages for',
49
+ description: 'A comma seperated list of the SQS queue(s) you want to check the number of messages for',
50
50
  default: ''
51
51
 
52
52
  option :prefix,
@@ -99,20 +99,33 @@ class SQSMsgs < Sensu::Plugin::Check::CLI
99
99
  Aws.config.update(aws_config)
100
100
  sqs = Aws::SQS::Resource.new
101
101
 
102
- if config[:prefix] == ''
103
- if config[:queue] == ''
102
+ if config[:prefix].empty?
103
+ if config[:queue].empty?
104
104
  critical 'Error, either QUEUE or PREFIX must be specified'
105
105
  end
106
106
 
107
- url = sqs.get_queue_by_name(queue_name: config[:queue]).url
108
- messages = sqs.client.get_queue_attributes(queue_url: url, attribute_names: ['All']).attributes[config[:metric]].to_i
107
+ warnings = []
108
+ crits = []
109
+ passing = []
110
+ queues = config[:queue].split(',')
111
+ queues.each do |q|
112
+ url = sqs.get_queue_by_name(queue_name: q).url
113
+ messages = sqs.client.get_queue_attributes(queue_url: url, attribute_names: ['All']).attributes[config[:metric]].to_i
109
114
 
110
- if (config[:crit_under] >= 0 && messages < config[:crit_under]) || (config[:crit_over] >= 0 && messages > config[:crit_over])
111
- critical "#{messages} message(s) in #{config[:queue]} queue"
112
- elsif (config[:warn_under] >= 0 && messages < config[:warn_under]) || (config[:warn_over] >= 0 && messages > config[:warn_over])
113
- warning "#{messages} message(s) in #{config[:queue]} queue"
115
+ if (config[:crit_under] >= 0 && messages < config[:crit_under]) || (config[:crit_over] >= 0 && messages > config[:crit_over])
116
+ crits << "#{messages} message(s) in #{q}"
117
+ elsif (config[:warn_under] >= 0 && messages < config[:warn_under]) || (config[:warn_over] >= 0 && messages > config[:warn_over])
118
+ warnings << "#{messages} message(s) in #{q}"
119
+ else
120
+ passing << "#{messages} message(s) in #{q}"
121
+ end
122
+ end
123
+ if crits.any?
124
+ critical crits.join(', ').to_s
125
+ elsif warnings.any?
126
+ warning warnings.join(', ').to_s
114
127
  else
115
- ok "#{messages} messages in #{config[:queue]} queue"
128
+ ok "all queue(s): #{queues} are OK"
116
129
  end
117
130
  else
118
131
  warn = false
@@ -100,7 +100,7 @@ class ElasticMetrics < Sensu::Plugin::Metric::CLI::Graphite
100
100
  r = cloud_watch_metric(key, static, cache_cluster_id)
101
101
  result['elasticache.' + cache_cluster_id + '.' + key] = r[:datapoints][0] unless r[:datapoints][0].nil?
102
102
  end
103
- return unless result.nil?
103
+ return if result.nil?
104
104
  result.each do |key, value|
105
105
  output key.downcase.to_s, value.average, value[:timestamp].to_i
106
106
  end
@@ -7,7 +7,7 @@ module CloudwatchCommon
7
7
  end
8
8
 
9
9
  def read_value(resp, stats)
10
- resp.datapoints.first.send(stats.downcase)
10
+ resp.datapoints.sort_by(&:timestamp).last.send(stats.downcase)
11
11
  end
12
12
 
13
13
  def resp_has_no_data(resp, stats)
@@ -40,6 +40,49 @@ module CloudwatchCommon
40
40
  }
41
41
  end
42
42
 
43
+ def composite_metrics_request(config, metric, fixed_time_now = Time.now)
44
+ {
45
+ namespace: config[:namespace],
46
+ metric_name: config[metric],
47
+ dimensions: config[:dimensions],
48
+ start_time: fixed_time_now - config[:period] * 10,
49
+ end_time: fixed_time_now,
50
+ period: config[:period],
51
+ statistics: [config[:statistics]],
52
+ unit: config[:unit]
53
+ }
54
+ end
55
+
56
+ def composite_check(config)
57
+ fixed_time_now = Time.now
58
+ numerator_metric_resp = client.get_metric_statistics(composite_metrics_request(config, :numerator_metric_name, fixed_time_now))
59
+ denominator_metric_resp = client.get_metric_statistics(composite_metrics_request(config, :denominator_metric_name, fixed_time_now))
60
+
61
+ no_data = resp_has_no_data(numerator_metric_resp, config[:statistics]) || \
62
+ resp_has_no_data(denominator_metric_resp, config[:statistics])
63
+ if no_data && config[:no_data_ok]
64
+ ok "#{metric_desc} returned no data but that's ok"
65
+ elsif no_data && !config[:no_data_ok]
66
+ unknown "#{metric_desc} could not be retrieved"
67
+ end
68
+
69
+ denominator_value = read_value(denominator_metric_resp, config[:statistics]).to_f
70
+ if denominator_value.zero?
71
+ ok "#{metric_desc} denominator value is zero but that's ok"
72
+ end
73
+ numerator_value = read_value(numerator_metric_resp, config[:statistics]).to_f
74
+ value = (numerator_value / denominator_value * 100).to_i
75
+ base_msg = "#{metric_desc} is #{value}: comparison=#{config[:compare]}"
76
+
77
+ if compare(value, config[:critical], config[:compare])
78
+ critical "#{base_msg} threshold=#{config[:critical]}"
79
+ elsif config[:warning] && compare(value, config[:warning], config[:compare])
80
+ warning "#{base_msg} threshold=#{config[:warning]}"
81
+ else
82
+ ok "#{base_msg}, will alarm at #{!config[:warning].nil? ? config[:warning] : config[:critical]}"
83
+ end
84
+ end
85
+
43
86
  def check(config)
44
87
  resp = client.get_metric_statistics(metrics_request(config))
45
88
 
@@ -1,7 +1,7 @@
1
1
  module SensuPluginsAWS
2
2
  module Version
3
3
  MAJOR = 4
4
- MINOR = 0
4
+ MINOR = 1
5
5
  PATCH = 0
6
6
  VER_STRING = [MAJOR, MINOR, PATCH].compact.join('.')
7
7
  end
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.0.0
4
+ version: 4.1.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: 2016-12-27 00:00:00.000000000 Z
11
+ date: 2017-05-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk
@@ -164,20 +164,6 @@ dependencies:
164
164
  - - "~>"
165
165
  - !ruby/object:Gem::Version
166
166
  version: '0.10'
167
- - !ruby/object:Gem::Dependency
168
- name: rainbow
169
- requirement: !ruby/object:Gem::Requirement
170
- requirements:
171
- - - "<"
172
- - !ruby/object:Gem::Version
173
- version: 2.2.0
174
- type: :development
175
- prerelease: false
176
- version_requirements: !ruby/object:Gem::Requirement
177
- requirements:
178
- - - "<"
179
- - !ruby/object:Gem::Version
180
- version: 2.2.0
181
167
  - !ruby/object:Gem::Dependency
182
168
  name: rake
183
169
  requirement: !ruby/object:Gem::Requirement
@@ -264,6 +250,7 @@ executables:
264
250
  - check-certificate-expiry.rb
265
251
  - check-cloudfront-tag.rb
266
252
  - check-cloudwatch-alarm.rb
253
+ - check-cloudwatch-composite-metric.rb
267
254
  - check-cloudwatch-metric.rb
268
255
  - check-configservice-rules.rb
269
256
  - check-dynamodb-capacity.rb
@@ -342,6 +329,7 @@ files:
342
329
  - bin/check-certificate-expiry.rb
343
330
  - bin/check-cloudfront-tag.rb
344
331
  - bin/check-cloudwatch-alarm.rb
332
+ - bin/check-cloudwatch-composite-metric.rb
345
333
  - bin/check-cloudwatch-metric.rb
346
334
  - bin/check-configservice-rules.rb
347
335
  - bin/check-dynamodb-capacity.rb