sensu-plugin 1.4.4 → 1.4.5
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 +4 -4
- data/lib/sensu-handler.rb +24 -6
- data/lib/sensu-plugin.rb +1 -1
- data/test/handle_filter_test.rb +22 -0
- data/test/test_helper.rb +8 -0
- 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: 199e68bec79e47836d7e573bb0fc039261a0c2d1
|
4
|
+
data.tar.gz: 1a45e9b8588e9b731bae15a330a6f292253911d7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4202e7fe226e1103a6f1f99e60cc3ef6538aab9e6736928330e49d3699ad66f9f1dadd34c8fccd4903650c35655445d3d6121607b89578bbbcb934e8fcc5a93b
|
7
|
+
data.tar.gz: a0addd66de1c4688a9af53ac93a931c2e4805cb63abdf260e34faeab3a2dd5dc74a4b91fbd4908baf85203724b7f84118b5c07ad654d1c48604db2f51810204f
|
data/lib/sensu-handler.rb
CHANGED
@@ -42,20 +42,38 @@ module Sensu
|
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
|
-
# Evaluates whether
|
46
|
-
#
|
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
|
-
|
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
|
54
|
-
# filter_repeated
|
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? ||
|
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.
|
data/lib/sensu-plugin.rb
CHANGED
data/test/handle_filter_test.rb
CHANGED
@@ -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
|
data/test/test_helper.rb
CHANGED
@@ -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
|
+
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:
|
12
|
+
date: 2017-03-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: json
|