sensu-plugin 1.4.4 → 1.4.5

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: a04e3d35dcd589036160b24040b8a6ec4d35f4f7
4
- data.tar.gz: 009d80cc7864e9e83770e085cf86b466526d8be1
3
+ metadata.gz: 199e68bec79e47836d7e573bb0fc039261a0c2d1
4
+ data.tar.gz: 1a45e9b8588e9b731bae15a330a6f292253911d7
5
5
  SHA512:
6
- metadata.gz: 7c4d8da32fe8006478ea1bd6bcf415547bbf5ce99699cdd4b085bc313a01b88930ed9a7ce97a28b3b614333ff21b593b297572e5d18b0f80585f30009ff0ab22
7
- data.tar.gz: 94cbaef69b207ba420b02b7c1de2d2bbb6e7e6c235ab8d6074d0fee430148e9174892b518ec27fea6ae2a7bf9dd0a23bcbca78990e9382a5b053dfc82689df42
6
+ metadata.gz: 4202e7fe226e1103a6f1f99e60cc3ef6538aab9e6736928330e49d3699ad66f9f1dadd34c8fccd4903650c35655445d3d6121607b89578bbbcb934e8fcc5a93b
7
+ data.tar.gz: a0addd66de1c4688a9af53ac93a931c2e4805cb63abdf260e34faeab3a2dd5dc74a4b91fbd4908baf85203724b7f84118b5c07ad654d1c48604db2f51810204f
@@ -42,20 +42,38 @@ module Sensu
42
42
  end
43
43
  end
44
44
 
45
- # Evaluates whether the event should be processed by any of the filter methods in
46
- # this library. Defaults to true (i.e. deprecated filters are run by default.)
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
+ # Evaluates whether the event should be processed by any of the
56
+ # filter methods in this library. Defaults to true,
57
+ # i.e. deprecated filters are run by default.
47
58
  #
48
59
  # @return [TrueClass, FalseClass]
49
60
  def deprecated_filtering_enabled?
50
- @event['check']['enable_deprecated_filtering'].nil? || @event['check']['enable_deprecated_filtering'] == true
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
67
  end
52
68
 
53
- # Evaluates whether the event should be processed by the filter_repeated method. Defaults to true (i.e.
54
- # filter_repeated will filter events by default)
69
+ # Evaluates whether the event should be processed by the
70
+ # filter_repeated method. Defaults to true, i.e. filter_repeated
71
+ # will filter events by default.
55
72
  #
56
73
  # @return [TrueClass, FalseClass]
57
74
  def deprecated_occurrence_filtering_enabled?
58
- @event['check']['enable_deprecated_occurrence_filtering'].nil? || @event['check']['enable_deprecated_occurrence_filtering'] == true
75
+ @event['check']['enable_deprecated_occurrence_filtering'].nil? || \
76
+ @event['check']['enable_deprecated_occurrence_filtering'].to_s == "true"
59
77
  end
60
78
 
61
79
  # This works just like Plugin::CLI's autorun.
@@ -1,6 +1,6 @@
1
1
  module Sensu
2
2
  module Plugin
3
- VERSION = "1.4.4"
3
+ VERSION = "1.4.5"
4
4
  EXIT_CODES = {
5
5
  'OK' => 0,
6
6
  'WARNING' => 1,
@@ -1,4 +1,5 @@
1
1
  require 'test_helper'
2
+ require 'tempfile'
2
3
 
3
4
  class TestFilterExternal < MiniTest::Test
4
5
  include SensuPluginTestHelper
@@ -158,6 +159,27 @@ class TestFilterExternal < MiniTest::Test
158
159
  refute_match(/#{filter_deprecation_string}/, output)
159
160
  end
160
161
 
162
+ def test_filter_deprecation_warning_does_not_exist_when_globaly_disabled
163
+ event = {
164
+ 'client' => { 'name' => 'test' },
165
+ 'check' => {
166
+ 'name' => 'globaly unfiltered test',
167
+ 'refresh' => 30
168
+ },
169
+ 'occurrences' => 60,
170
+ 'action' => 'create',
171
+ }
172
+
173
+ settings_file = Tempfile.new('global_filter_disable')
174
+ settings_file.write('{"sensu_plugin": { "disable_deprecated_filtering": true }}')
175
+ settings_file.close
176
+ ENV['SENSU_CONFIG_FILES'] = settings_file.path
177
+ output = run_script_in_env_with_input(JSON.generate(event), ENV)
178
+ ENV['SENSU_CONFIG_FILES'] = nil
179
+ assert_equal(0, $?.exitstatus)
180
+ refute_match(/#{filter_deprecation_string}/, output)
181
+ end
182
+
161
183
  def occurrence_filter_deprecation_string
162
184
  'warning: occurrence filtering in sensu-plugin is deprecated, see http://bit.ly/sensu-plugin'
163
185
  end
@@ -21,6 +21,14 @@ module SensuPluginTestHelper
21
21
  end
22
22
  end
23
23
 
24
+ def run_script_in_env_with_input(input, env, *args)
25
+ IO.popen(env, ([@script] + args).join(' '), 'r+') do |child|
26
+ child.puts input
27
+ child.close_write
28
+ child.read
29
+ end
30
+ end
31
+
24
32
  def fixture_path
25
33
  File.expand_path('../fixtures', __FILE__)
26
34
  end
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.4
4
+ version: 1.4.5
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: 2016-12-08 00:00:00.000000000 Z
12
+ date: 2017-03-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json