sensu-plugins-aws 10.0.3 → 10.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
  SHA256:
3
- metadata.gz: c4d374e51efee898a5c8a79b78b93b3ced3eb090c8a09e48b8258ecc6e5f4299
4
- data.tar.gz: 304c60c4178e8bb39afd8c21da9e2cbeabfb97ab9ee6c75d5ae42d953722a887
3
+ metadata.gz: 35e5a15486f7584a9ba3511aa6511e5499749785c6eb479b2bf466e387f5453e
4
+ data.tar.gz: fba519f316d43e12c735671f13c4d83e267fc3deab9c3379408fbc2239968ef3
5
5
  SHA512:
6
- metadata.gz: ab9b02c01ece25c58a40e3b8a2dfef4df1c2b92b9a659ccfeb407a72e2c2ea87d7ab4a75cf493f06bf6f3902758a1e1ef956f4f6318edad9ad954b89dc1a8b3d
7
- data.tar.gz: 4ef3f5844d954b354f8d1bf34c5a44939177829e26ba2657be9bf15235aff975daea91e4c52c76c8d4c97d21a4bbe98eceee118cbaee6ae1c1148d15d85b6bfb
6
+ metadata.gz: 971426511c04536e2c5915af6e22b1429b54d2699ec24ef04caa0d5c42f04020f37ac8013a1434cbd5bafd368c8324a0bc1e2e1de33975acefb28085fcffb3f6
7
+ data.tar.gz: 694f183d1e74bc11f8596930d847fa439fe0a08154a9e3e90e17b535c780c9966889130cf8fdae078ff20cd695f42d39a709d82ad2e58223355e0a72977bfc52
data/CHANGELOG.md CHANGED
@@ -5,6 +5,10 @@ This CHANGELOG follows the format listed [here](https://github.com/sensu-plugins
5
5
 
6
6
  ## [Unreleased]
7
7
 
8
+ ## [10.1.0] - 2018-01-06
9
+ - check-cloudwatch-composite-metric.rb: add flags `zero_denominator_data_ok`, `no_denominator_data_ok`, and `numerator_default` to add ability to allow numerator in composite to be 0. While leaving the functionality of `no_data_ok` the same, this change allows us to check to alert if the numerator has no data since 0/X is a valid alert case. (@zbintliff)
10
+ - lib/cloudwatch-common.rb: added tests for majority of functions (@zbintliff)
11
+
8
12
  ## [10.0.3] - 2017-12-03
9
13
  ### Fixed
10
14
  - metrics-asg.rb: fix dimension name, handle the --scheme flag, make the --statistic flag work, support autoscaling groups containing spaces in their name (@multani)
@@ -406,7 +410,8 @@ WARNING: This release contains major breaking changes that will impact all user
406
410
  ### Added
407
411
  - initial release
408
412
 
409
- [Unreleased]: https://github.com/sensu-plugins/sensu-plugins-aws/compare/10.0.3...HEAD
413
+ [Unreleased]: https://github.com/sensu-plugins/sensu-plugins-aws/compare/10.1.0...HEAD
414
+ [10.1.0]: https://github.com/sensu-plugins/sensu-plugins-aws/compare/10.1.0...10.0.3
410
415
  [10.0.3]: https://github.com/sensu-plugins/sensu-plugins-aws/compare/10.0.2...10.0.3
411
416
  [10.0.2]: https://github.com/sensu-plugins/sensu-plugins-aws/compare/10.0.1...10.0.2
412
417
  [10.0.1]: https://github.com/sensu-plugins/sensu-plugins-aws/compare/10.0.0...10.0.1
@@ -85,14 +85,14 @@ class CloudWatchCompositeMetricCheck < Sensu::Plugin::Check::CLI
85
85
  description: 'CloudWatch metric unit'
86
86
 
87
87
  option :critical,
88
- description: 'Trigger a critical when value is over VALUE',
88
+ description: 'Trigger a critical when value is over VALUE as a Percent',
89
89
  short: '-c VALUE',
90
90
  long: '--critical VALUE',
91
91
  proc: proc(&:to_f),
92
92
  required: true
93
93
 
94
94
  option :warning,
95
- description: 'Trigger a warning when value is over VALUE',
95
+ description: 'Trigger a warning when value is over VALUE as a Percent',
96
96
  short: '-w VALUE',
97
97
  long: '--warning VALUE',
98
98
  proc: proc(&:to_f)
@@ -103,20 +103,97 @@ class CloudWatchCompositeMetricCheck < Sensu::Plugin::Check::CLI
103
103
  long: '--operator OPERATION',
104
104
  default: 'greater'
105
105
 
106
+ option :numerator_default,
107
+ long: '--numerator-default DEFAULT',
108
+ description: 'Default for numerator if no data is returned for metric',
109
+ proc: proc(&:to_f)
110
+
111
+ option :no_denominator_data_ok,
112
+ long: '--allow-no-denominator-data',
113
+ description: 'Returns ok if no data is returned from denominator metric',
114
+ boolean: true,
115
+ default: false
116
+
117
+ option :zero_denominator_data_ok,
118
+ long: '--allow-zero-denominator-data',
119
+ description: 'Returns ok if denominator metric is zero',
120
+ boolean: true,
121
+ default: false
122
+
106
123
  option :no_data_ok,
107
124
  short: '-O',
108
125
  long: '--allow-no-data',
109
- description: 'Returns ok if no data is returned from the metric',
126
+ description: 'Returns ok if no data is returned from either metric',
110
127
  boolean: true,
111
128
  default: false
112
-
113
129
  include CloudwatchCommon
114
130
 
115
131
  def metric_desc
116
132
  "#{config[:namespace]}-#{config[:numerator_metric_name]}/#{config[:denominator_metric_name]}(#{dimension_string})"
117
133
  end
118
134
 
135
+ def numerator_data(metric_payload)
136
+ if resp_has_no_data(metric_payload, config[:statistics])
137
+ # If the numerator response has no data in it, see if there was a predefined default.
138
+ # If there is no predefined default it will return nil
139
+ config[:numerator_default]
140
+ else
141
+ read_value(metric_payload, config[:statistics]).to_f
142
+ end
143
+ end
144
+
145
+ # rubocop:disable Style/GuardClause
146
+ def composite_check
147
+ numerator_metric_resp = get_metric(config[:numerator_metric_name])
148
+ denominator_metric_resp = get_metric(config[:denominator_metric_name])
149
+
150
+ ## If the numerator is empty, then we see if there is a default. If there is a default
151
+ ## then we will pretend the numerator _isnt_ empty. That is
152
+ ## if empty but there is no default this will be true. If it is empty and there is a default
153
+ ## this will be false (i.e. there is data, following standard of dealing in the negative here)
154
+ no_num_data = numerator_data(numerator_metric_resp).nil?
155
+ no_den_data = resp_has_no_data(denominator_metric_resp, config[:statistics])
156
+ no_data = no_num_data || no_den_data
157
+
158
+ # no data in numerator or denominator this is to keep backwards compatibility
159
+ if no_data && config[:no_data_ok]
160
+ return :ok, "#{metric_desc} returned no data but that's ok"
161
+ elsif no_den_data && config[:no_denominator_data_ok]
162
+ return :ok, "#{config[:denominator_metric_name]} returned no data but that's ok"
163
+ elsif no_data ## This is legacy case
164
+ return :unknown, "#{metric_desc} could not be retrieved"
165
+ end
166
+
167
+ ## Now both the denominator and numerator have data (or a valid default)
168
+ denominator_value = read_value(denominator_metric_resp, config[:statistics]).to_f
169
+ if denominator_value.zero? && config[:zero_denominator_data_ok]
170
+ return :ok, "#{metric_desc}: denominator value is zero but that's ok"
171
+ elsif denominator_value.zero?
172
+ return :unknown, "#{metric_desc}: denominator value is zero"
173
+ end
174
+
175
+ ## We already checked if this value is nil so we know its not
176
+ numerator_value = numerator_data(numerator_metric_resp)
177
+ value = (numerator_value / denominator_value * 100).to_i
178
+ base_msg = "#{metric_desc} is #{value}: comparison=#{config[:compare]}"
179
+
180
+ if compare(value, config[:critical], config[:compare])
181
+ return :critical, "#{base_msg} threshold=#{config[:critical]}"
182
+ elsif config[:warning] && compare(value, config[:warning], config[:compare])
183
+ return :warning, "#{base_msg} threshold=#{config[:warning]}"
184
+ else
185
+ threshold = config[:warning] || config[:critical]
186
+ return :ok, "#{base_msg}, will alarm at #{threshold}"
187
+ end
188
+ end
189
+ # rubocop:enable Style/GuardClause
190
+
119
191
  def run
120
- composite_check config
192
+ status, msg = composite_check
193
+ if respond_to?(status)
194
+ send(status, msg)
195
+ else
196
+ unknown 'unknown exit status called'
197
+ end
121
198
  end
122
199
  end
@@ -3,7 +3,7 @@ module CloudwatchCommon
3
3
  include Common
4
4
 
5
5
  def client
6
- Aws::CloudWatch::Client.new
6
+ @client ||= Aws::CloudWatch::Client.new
7
7
  end
8
8
 
9
9
  def read_value(resp, stats)
@@ -40,47 +40,13 @@ 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
- }
43
+ def get_metric(metric)
44
+ client.get_metric_statistics(composite_metrics_request(metric))
54
45
  end
55
46
 
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
47
+ def composite_metrics_request(metric)
48
+ ## config is a class variable but don't want to change signature
49
+ metrics_request(config).merge(metric_name: metric)
84
50
  end
85
51
 
86
52
  def self.parse_dimensions(dimension_string)
@@ -17,8 +17,8 @@
17
17
  #
18
18
 
19
19
  module Common
20
- def initialize
21
- super()
20
+ def initialize(argv = ARGV)
21
+ super(argv)
22
22
  aws_config
23
23
  end
24
24
 
@@ -1,8 +1,8 @@
1
1
  module SensuPluginsAWS
2
2
  module Version
3
3
  MAJOR = 10
4
- MINOR = 0
5
- PATCH = 3
4
+ MINOR = 1
5
+ PATCH = 0
6
6
  VER_STRING = [MAJOR, MINOR, PATCH].compact.join('.')
7
7
  end
8
8
  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: 10.0.3
4
+ version: 10.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: 2017-12-03 00:00:00.000000000 Z
11
+ date: 2018-01-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk
@@ -445,7 +445,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
445
445
  version: '0'
446
446
  requirements: []
447
447
  rubyforge_project:
448
- rubygems_version: 2.7.3
448
+ rubygems_version: 2.7.4
449
449
  signing_key:
450
450
  specification_version: 4
451
451
  summary: Sensu plugins for working with an AWS environment