sensu-plugin 1.4.7 → 2.0.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1ee4157c3228691cda625cfbcf332338f27830c1
4
- data.tar.gz: 197b857efa2675e3b64780688853c73f08e08c51
3
+ metadata.gz: e3baa8a659398d40bd3ee8ae30f9ce2fe69078eb
4
+ data.tar.gz: 802b2d8ab27edc4ca6834d2cf33b2ad0ece76b6e
5
5
  SHA512:
6
- metadata.gz: 292668bb594aa82898675e6012c1f12d284c4a9cf7086562c57787ca1545d3a7eec2cee9e5a24ab51a22fe5d520befa9e5639310cd882889a13ef663243901e6
7
- data.tar.gz: f560e992ac333a3b973a06bb06beef32cd1a332a62cf374ae38e607a985be396d9d987a0b821ca9f877e897d66bf1a5fd3b02d1f9cd14e29372b2d3139f33d91
6
+ metadata.gz: 826f3b874c986cce0e3923293a93bc4a612872496afb9ad4e75a997c6fadbdbc33c935d7bbc49fc12ae752677141b544ef7763079455b39941c8d6777808b4c3
7
+ data.tar.gz: 5299d3bd34f0fb9588d23f83a8d4666833defa5571aaa5d090556905dbff601ca43ccea8b8770155921588539375bd4891c67e77b8d5d3cd6e37aed32479e4ee
@@ -42,28 +42,13 @@ module Sensu
42
42
  end
43
43
  end
44
44
 
45
- # Evaluates whether deprecated filtering is explicitly disabled
46
- # via global Sensu configuration. Defaults to false,
47
- # i.e. deprecated filters are run by default.
48
- #
49
- # @return [TrueClass, FalseClass]
50
- def deprecated_filtering_globally_disabled?
51
- global_settings = settings.fetch('sensu_plugin', {})
52
- global_settings['disable_deprecated_filtering'].to_s == "true"
53
- end
54
-
55
45
  # Evaluates whether the event should be processed by any of the
56
46
  # filter methods in this library. Defaults to true,
57
47
  # i.e. deprecated filters are run by default.
58
48
  #
59
49
  # @return [TrueClass, FalseClass]
60
50
  def deprecated_filtering_enabled?
61
- if deprecated_filtering_globally_disabled?
62
- return false
63
- else
64
- @event['check']['enable_deprecated_filtering'].nil? || \
65
- @event['check']['enable_deprecated_filtering'].to_s == "true"
66
- end
51
+ @event['check'].fetch('enable_deprecated_filtering', false).to_s == "true"
67
52
  end
68
53
 
69
54
  # Evaluates whether the event should be processed by the
@@ -72,8 +57,7 @@ module Sensu
72
57
  #
73
58
  # @return [TrueClass, FalseClass]
74
59
  def deprecated_occurrence_filtering_enabled?
75
- @event['check']['enable_deprecated_occurrence_filtering'].nil? || \
76
- @event['check']['enable_deprecated_occurrence_filtering'].to_s == "true"
60
+ @event['check'].fetch('enable_deprecated_occurrence_filtering', false).to_s == "true"
77
61
  end
78
62
 
79
63
  # This works just like Plugin::CLI's autorun.
@@ -1,6 +1,6 @@
1
1
  module Sensu
2
2
  module Plugin
3
- VERSION = "1.4.7"
3
+ VERSION = "2.0.0"
4
4
  EXIT_CODES = {
5
5
  'OK' => 0,
6
6
  'WARNING' => 1,
@@ -60,11 +60,11 @@ module Sensu
60
60
  exit e.status
61
61
  rescue OptionParser::InvalidOption => e
62
62
  puts "Invalid check argument(s): #{e.message}, #{e.backtrace}"
63
- exit 1
63
+ exit 3
64
64
  rescue Exception => e
65
65
  # This can't call check.critical, as the check may have failed to construct
66
66
  puts "Check failed to run: #{e.message}, #{e.backtrace}"
67
- exit 2
67
+ exit 3
68
68
  end
69
69
  check.warning "Check did not exit! You should call an exit code method."
70
70
  end
@@ -39,7 +39,7 @@ class TestCheckExternal < MiniTest::Test
39
39
 
40
40
  def test_exception
41
41
  output = run_script '-f'
42
- assert $?.exitstatus == 2 && output.include?('failed')
42
+ assert $?.exitstatus == 3 && output.include?('failed')
43
43
  end
44
44
 
45
45
  def test_argv
@@ -49,7 +49,7 @@ class TestCheckExternal < MiniTest::Test
49
49
 
50
50
  def test_bad_commandline
51
51
  output = run_script '--doesnotexist'
52
- assert $?.exitstatus == 1 && output.include?('doesnotexist') && output.include?('invalid option')
52
+ assert $?.exitstatus == 3 && output.include?('doesnotexist') && output.include?('invalid option')
53
53
  end
54
54
 
55
55
  def test_bad_require
@@ -11,7 +11,12 @@ class TestFilterExternal < MiniTest::Test
11
11
  def test_create_not_enough_occurrences
12
12
  event = {
13
13
  'client' => { 'name' => 'test' },
14
- 'check' => { 'name' => 'test', 'occurrences' => 2 },
14
+ 'check' => {
15
+ 'name' => 'test',
16
+ 'occurrences' => 2,
17
+ 'enable_deprecated_filtering' => true,
18
+ 'enable_deprecated_occurrence_filtering' => true
19
+ },
15
20
  'occurrences' => 1,
16
21
  'action' => 'create'
17
22
  }
@@ -23,7 +28,12 @@ class TestFilterExternal < MiniTest::Test
23
28
  def test_create_enough_occurrences
24
29
  event = {
25
30
  'client' => { 'name' => 'test' },
26
- 'check' => { 'name' => 'test', 'occurrences' => 2 },
31
+ 'check' => {
32
+ 'name' => 'test',
33
+ 'occurrences' => 2,
34
+ 'enable_deprecated_filtering' => true,
35
+ 'enable_deprecated_occurrence_filtering' => true
36
+ },
27
37
  'occurrences' => 2,
28
38
  'action' => 'create'
29
39
  }
@@ -35,7 +45,12 @@ class TestFilterExternal < MiniTest::Test
35
45
  def test_resolve_not_enough_occurrences
36
46
  event = {
37
47
  'client' => { 'name' => 'test' },
38
- 'check' => { 'name' => 'test', 'occurrences' => 2 },
48
+ 'check' => {
49
+ 'name' => 'test',
50
+ 'occurrences' => 2,
51
+ 'enable_deprecated_filtering' => true,
52
+ 'enable_deprecated_occurrence_filtering' => true
53
+ },
39
54
  'occurrences' => 1,
40
55
  'action' => 'resolve'
41
56
  }
@@ -47,7 +62,11 @@ class TestFilterExternal < MiniTest::Test
47
62
  def test_resolve_enough_occurrences
48
63
  event = {
49
64
  'client' => { 'name' => 'test' },
50
- 'check' => { 'name' => 'test', 'occurrences' => 2 },
65
+ 'check' => {
66
+ 'name' => 'test',
67
+ 'occurrences' => 2,
68
+ 'enable_deprecated_filtering' => true
69
+ },
51
70
  'occurrences' => 2,
52
71
  'action' => 'resolve'
53
72
  }
@@ -59,7 +78,11 @@ class TestFilterExternal < MiniTest::Test
59
78
  def test_refresh_enough_occurrences
60
79
  event = {
61
80
  'client' => { 'name' => 'test' },
62
- 'check' => { 'name' => 'test' },
81
+ 'check' => {
82
+ 'name' => 'test',
83
+ 'enable_deprecated_filtering' => true,
84
+ 'enable_deprecated_occurrence_filtering' => true
85
+ },
63
86
  'occurrences' => 61,
64
87
  'action' => 'create'
65
88
  }
@@ -71,7 +94,11 @@ class TestFilterExternal < MiniTest::Test
71
94
  def test_refresh_not_enough_occurrences
72
95
  event = {
73
96
  'client' => { 'name' => 'test' },
74
- 'check' => { 'name' => 'test' },
97
+ 'check' => {
98
+ 'name' => 'test',
99
+ 'enable_deprecated_filtering' => true,
100
+ 'enable_deprecated_occurrence_filtering' => true
101
+ },
75
102
  'occurrences' => 60,
76
103
  'action' => 'create'
77
104
  }
@@ -107,7 +134,11 @@ class TestFilterExternal < MiniTest::Test
107
134
  def test_dependency_event_exists
108
135
  event = {
109
136
  'client' => { 'name' => 'test' },
110
- 'check' => { 'name' => 'test', 'dependencies' => ['foo', 'bar'] },
137
+ 'check' => {
138
+ 'name' => 'test',
139
+ 'dependencies' => ['foo', 'bar'],
140
+ 'enable_deprecated_filtering' => true
141
+ },
111
142
  'occurrences' => 1
112
143
  }
113
144
  output = run_script_with_input(JSON.generate(event))
@@ -119,7 +150,7 @@ class TestFilterExternal < MiniTest::Test
119
150
  'warning: event filtering in sensu-plugin is deprecated, see http://bit.ly/sensu-plugin'
120
151
  end
121
152
 
122
- def test_filter_deprecation_warning_exists_by_default
153
+ def test_filter_deprecation_warning_is_not_present_by_default
123
154
  event = {
124
155
  'client' => { 'name' => 'test' },
125
156
  'check' => { 'name' => 'test', 'refresh' => 30 },
@@ -128,7 +159,7 @@ class TestFilterExternal < MiniTest::Test
128
159
  }
129
160
  output = run_script_with_input(JSON.generate(event))
130
161
  assert_equal(0, $?.exitstatus)
131
- assert_match(/#{filter_deprecation_string}/, output)
162
+ refute_match(/#{filter_deprecation_string}/, output)
132
163
  end
133
164
 
134
165
  def test_filter_deprecation_warning_exists_when_explicitly_enabled
@@ -184,7 +215,7 @@ class TestFilterExternal < MiniTest::Test
184
215
  'warning: occurrence filtering in sensu-plugin is deprecated, see http://bit.ly/sensu-plugin'
185
216
  end
186
217
 
187
- def test_occurrence_filter_deprecation_warning_exists_by_default
218
+ def test_occurrence_filter_deprecation_warning_not_present_by_default
188
219
  event = {
189
220
  'client' => { 'name' => 'test' },
190
221
  'check' => { 'name' => 'test', 'refresh' => 30 },
@@ -193,15 +224,16 @@ class TestFilterExternal < MiniTest::Test
193
224
  }
194
225
  output = run_script_with_input(JSON.generate(event))
195
226
  assert_equal(0, $?.exitstatus)
196
- assert_match(/#{occurrence_filter_deprecation_string}/, output)
227
+ refute_match(/#{occurrence_filter_deprecation_string}/, output)
197
228
  end
198
229
 
199
- def test_occurrence_filter_deprecation_warning_exists_when_explicitly_enabled
230
+ def test_occurrence_filter_deprecation_warning_present_when_explicitly_enabled
200
231
  event = {
201
232
  'client' => { 'name' => 'test' },
202
233
  'check' => {
203
234
  'name' => 'test',
204
235
  'refresh' => 30,
236
+ 'enable_deprecated_filtering' => true,
205
237
  'enable_deprecated_occurrence_filtering' => true
206
238
  },
207
239
  'occurrences' => 60,
@@ -212,12 +244,13 @@ class TestFilterExternal < MiniTest::Test
212
244
  assert_match(/#{occurrence_filter_deprecation_string}/, output)
213
245
  end
214
246
 
215
- def test_occurrence_filter_deprecation_warning_does_not_exist_when_explicitly_disabled
247
+ def test_occurrence_filter_deprecation_warning_not_present_when_explicitly_disabled
216
248
  event = {
217
249
  'client' => { 'name' => 'test' },
218
250
  'check' => {
219
251
  'name' => 'unfiltered test',
220
252
  'refresh' => 30,
253
+ 'enable_deprecated_filtering' => true,
221
254
  'enable_deprecated_occurrence_filtering' => false
222
255
  },
223
256
  'occurrences' => 60,
@@ -1,5 +1,4 @@
1
1
  require 'rubygems'
2
- gem 'minitest' if RUBY_VERSION < '1.9.0'
3
2
  require 'minitest/autorun'
4
3
 
5
4
  module SensuPluginTestHelper
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sensu-plugin
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.7
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Decklin Foster
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-02-20 00:00:00.000000000 Z
12
+ date: 2017-03-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
@@ -29,16 +29,16 @@ dependencies:
29
29
  name: mixlib-cli
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
- - - "~>"
32
+ - - ">="
33
33
  - !ruby/object:Gem::Version
34
- version: '1.5'
34
+ version: 1.5.0
35
35
  type: :runtime
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
- - - "~>"
39
+ - - ">="
40
40
  - !ruby/object:Gem::Version
41
- version: '1.5'
41
+ version: 1.5.0
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: rake
44
44
  requirement: !ruby/object:Gem::Requirement
@@ -101,9 +101,9 @@ require_paths:
101
101
  - lib
102
102
  required_ruby_version: !ruby/object:Gem::Requirement
103
103
  requirements:
104
- - - ">="
104
+ - - "~>"
105
105
  - !ruby/object:Gem::Version
106
- version: '0'
106
+ version: '2.0'
107
107
  required_rubygems_version: !ruby/object:Gem::Requirement
108
108
  requirements:
109
109
  - - ">="
@@ -111,17 +111,17 @@ required_rubygems_version: !ruby/object:Gem::Requirement
111
111
  version: '0'
112
112
  requirements: []
113
113
  rubyforge_project:
114
- rubygems_version: 2.6.11
114
+ rubygems_version: 2.6.6
115
115
  signing_key:
116
116
  specification_version: 4
117
117
  summary: Sensu Plugins
118
118
  test_files:
119
+ - test/deep_merge_test.rb
119
120
  - test/external_check_test.rb
120
- - test/handle_helper_test.rb
121
+ - test/external_handler_argument_test.rb
122
+ - test/external_handler_test.rb
121
123
  - test/external_metric_test.rb
122
124
  - test/handle_filter_test.rb
123
- - test/deep_merge_test.rb
125
+ - test/handle_helper_test.rb
124
126
  - test/mutator_test.rb
125
127
  - test/test_helper.rb
126
- - test/external_handler_argument_test.rb
127
- - test/external_handler_test.rb