sensu-plugin 1.3.0 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/sensu-handler.rb +44 -10
- data/lib/sensu-plugin.rb +1 -1
- data/lib/sensu-plugin/cli.rb +1 -0
- data/lib/sensu-plugin/utils.rb +17 -17
- data/test/deep_merge_test.rb +27 -0
- data/test/external_check_test.rb +8 -1
- data/test/external_handler_argument_test.rb +1 -1
- data/test/external_handler_test.rb +1 -1
- data/test/external_metric_test.rb +3 -3
- data/test/handle_filter_test.rb +93 -1
- data/test/handle_helper_test.rb +1 -1
- metadata +13 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3e879511e4d506f0d50d2ecd328eb8cab2c99b35
|
4
|
+
data.tar.gz: 717ac6db50d476cb67dcc4268d0d00340117bf35
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4321bb33eb3f14d9a971372de91da411417ae352e4c52fd0f671ef71c31d6902f1940f97c9c987dc397a61770da5293aa6902cfccfe6ed03c88639b46ecbb1d9
|
7
|
+
data.tar.gz: 5876be24bccca229feafc5f250136fe81f3e4cc20651fef37ad5f09718415eaf2d76d2de3d684cb6a3a845813855a65d57185d7f438aaa575f92765aac77fabd
|
data/lib/sensu-handler.rb
CHANGED
@@ -24,14 +24,38 @@ module Sensu
|
|
24
24
|
puts 'ignoring event -- no handler defined'
|
25
25
|
end
|
26
26
|
|
27
|
-
# Filters exit the proccess if the event should not be handled.
|
28
|
-
# Implementation of the default filters is below.
|
29
27
|
|
28
|
+
# Filters exit the proccess if the event should not be handled.
|
29
|
+
#
|
30
|
+
# Filtering events is deprecated and will be removed in a future release.
|
31
|
+
#
|
30
32
|
def filter
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
33
|
+
if deprecated_filtering_enabled?
|
34
|
+
puts 'warning: event filtering in sensu-plugin is deprecated, see http://bit.ly/sensu-plugin'
|
35
|
+
filter_disabled
|
36
|
+
filter_silenced
|
37
|
+
filter_dependencies
|
38
|
+
if deprecated_occurrence_filtering_enabled?
|
39
|
+
puts 'warning: occurrence filtering in sensu-plugin is deprecated, see http://bit.ly/sensu-plugin'
|
40
|
+
filter_repeated
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
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.)
|
47
|
+
#
|
48
|
+
# @return [TrueClass, FalseClass]
|
49
|
+
def deprecated_filtering_enabled?
|
50
|
+
@event['check']['enable_deprecated_filtering'].nil? || @event['check']['enable_deprecated_filtering'] == true
|
51
|
+
end
|
52
|
+
|
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)
|
55
|
+
#
|
56
|
+
# @return [TrueClass, FalseClass]
|
57
|
+
def deprecated_occurrence_filtering_enabled?
|
58
|
+
@event['check']['enable_deprecated_occurrence_filtering'].nil? || @event['check']['enable_deprecated_occurrence_filtering'] == true
|
35
59
|
end
|
36
60
|
|
37
61
|
# This works just like Plugin::CLI's autorun.
|
@@ -79,18 +103,28 @@ module Sensu
|
|
79
103
|
exit 0
|
80
104
|
end
|
81
105
|
|
106
|
+
# Return a hash of API settings derived first from ENV['SENSU_API_URL'] if set,
|
107
|
+
# then Sensu config `api` scope if configured, and finally falling back to
|
108
|
+
# to ipv4 localhost address on default API port.
|
109
|
+
#
|
110
|
+
# @return [Hash]
|
82
111
|
def api_settings
|
83
|
-
@api_settings
|
112
|
+
return @api_settings if @api_settings
|
113
|
+
case
|
114
|
+
when ENV['SENSU_API_URL']
|
84
115
|
uri = URI(ENV['SENSU_API_URL'])
|
85
|
-
{
|
116
|
+
@api_settings = {
|
86
117
|
'host' => uri.host,
|
87
118
|
'port' => uri.port,
|
88
119
|
'user' => uri.user,
|
89
120
|
'password' => uri.password
|
90
121
|
}
|
91
122
|
else
|
92
|
-
settings['api']
|
123
|
+
@api_settings = settings['api'] || {}
|
124
|
+
@api_settings['host'] ||= '127.0.0.1'
|
125
|
+
@api_settings['port'] ||= 4567
|
93
126
|
end
|
127
|
+
@api_settings
|
94
128
|
end
|
95
129
|
|
96
130
|
def api_request(method, path, &blk)
|
@@ -98,7 +132,7 @@ module Sensu
|
|
98
132
|
raise "api.json settings not found."
|
99
133
|
end
|
100
134
|
domain = api_settings['host'].start_with?('http') ? api_settings['host'] : 'http://' + api_settings['host']
|
101
|
-
uri = URI("#{domain}:#{api_settings['port']}#{path}")
|
135
|
+
uri = URI("#{domain}:#{api_settings['port']}#{path}")
|
102
136
|
req = net_http_req_class(method).new(uri)
|
103
137
|
if api_settings['user'] && api_settings['password']
|
104
138
|
req.basic_auth(api_settings['user'], api_settings['password'])
|
data/lib/sensu-plugin.rb
CHANGED
data/lib/sensu-plugin/cli.rb
CHANGED
data/lib/sensu-plugin/utils.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
1
3
|
module Sensu
|
2
4
|
module Plugin
|
3
5
|
module Utils
|
@@ -17,7 +19,7 @@ module Sensu
|
|
17
19
|
end
|
18
20
|
|
19
21
|
def settings
|
20
|
-
@settings ||= config_files.map {|f| load_config(f) }.reduce {|a, b|
|
22
|
+
@settings ||= config_files.map {|f| load_config(f) }.reduce {|a, b| deep_merge(a, b) }
|
21
23
|
end
|
22
24
|
|
23
25
|
def read_event(file)
|
@@ -44,23 +46,21 @@ module Sensu
|
|
44
46
|
Net::HTTP::Put
|
45
47
|
end
|
46
48
|
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
# Monkey Patching.
|
52
49
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
50
|
+
def deep_merge(hash_one, hash_two)
|
51
|
+
merged = hash_one.dup
|
52
|
+
hash_two.each do |key, value|
|
53
|
+
merged[key] = case
|
54
|
+
when hash_one[key].is_a?(Hash) && value.is_a?(Hash)
|
55
|
+
deep_merge(hash_one[key], value)
|
56
|
+
when hash_one[key].is_a?(Array) && value.is_a?(Array)
|
57
|
+
hash_one[key].concat(value).uniq
|
58
|
+
else
|
59
|
+
value
|
60
|
+
end
|
61
|
+
end
|
62
|
+
merged
|
63
|
+
end
|
63
64
|
end
|
64
|
-
merge(other_hash, &merger)
|
65
65
|
end
|
66
66
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'sensu-plugin/utils'
|
3
|
+
|
4
|
+
class TestDeepMerge < MiniTest::Test
|
5
|
+
include SensuPluginTestHelper
|
6
|
+
include Sensu::Plugin::Utils
|
7
|
+
|
8
|
+
def test_hash
|
9
|
+
merged = deep_merge({:a => "a"}, {:b => "b"})
|
10
|
+
assert(merged == {:a => "a", :b => "b"})
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_nested_hash
|
14
|
+
merged = deep_merge({:a => {:b => "c"}}, {:a => {:d => "e"}})
|
15
|
+
assert(merged == {:a => {:b => "c", :d => "e"}})
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_nested_array
|
19
|
+
merged = deep_merge({:a => ["b"]}, {:a => ["c"]})
|
20
|
+
assert(merged, {:a => ["b", "c"]})
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_conflicting_types
|
24
|
+
merged = deep_merge({:a => {:b => "c"}}, {:a => ["d"]})
|
25
|
+
assert(merged, {:a => {:b => "c"}})
|
26
|
+
end
|
27
|
+
end
|
data/test/external_check_test.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
class TestCheckExternal < MiniTest::
|
3
|
+
class TestCheckExternal < MiniTest::Test
|
4
4
|
include SensuPluginTestHelper
|
5
5
|
|
6
6
|
def setup
|
@@ -51,4 +51,11 @@ class TestCheckExternal < MiniTest::Unit::TestCase
|
|
51
51
|
output = run_script '--doesnotexist'
|
52
52
|
assert $?.exitstatus == 1 && output.include?('doesnotexist') && output.include?('invalid option')
|
53
53
|
end
|
54
|
+
|
55
|
+
def test_bad_require
|
56
|
+
set_script 'external/bad-require' # TODO better way to switch scripts?
|
57
|
+
output = run_script '2>&1'
|
58
|
+
assert_equal($?.exitstatus, 3)
|
59
|
+
assert_match(/LoadError/, output)
|
60
|
+
end
|
54
61
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
class TestMetricExternal < MiniTest::
|
3
|
+
class TestMetricExternal < MiniTest::Test
|
4
4
|
include SensuPluginTestHelper
|
5
5
|
|
6
6
|
def setup
|
@@ -14,7 +14,7 @@ class TestMetricExternal < MiniTest::Unit::TestCase
|
|
14
14
|
|
15
15
|
end
|
16
16
|
|
17
|
-
class TestGraphiteMetricExternal < MiniTest::
|
17
|
+
class TestGraphiteMetricExternal < MiniTest::Test
|
18
18
|
include SensuPluginTestHelper
|
19
19
|
|
20
20
|
def setup
|
@@ -28,7 +28,7 @@ class TestGraphiteMetricExternal < MiniTest::Unit::TestCase
|
|
28
28
|
|
29
29
|
end
|
30
30
|
|
31
|
-
class TestStatsdMetricExternal < MiniTest::
|
31
|
+
class TestStatsdMetricExternal < MiniTest::Test
|
32
32
|
include SensuPluginTestHelper
|
33
33
|
|
34
34
|
def setup
|
data/test/handle_filter_test.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
class TestFilterExternal < MiniTest::
|
3
|
+
class TestFilterExternal < MiniTest::Test
|
4
4
|
include SensuPluginTestHelper
|
5
5
|
|
6
6
|
def setup
|
@@ -113,4 +113,96 @@ class TestFilterExternal < MiniTest::Unit::TestCase
|
|
113
113
|
assert_equal(0, $?.exitstatus)
|
114
114
|
assert_match(/dependency event exists/, output)
|
115
115
|
end
|
116
|
+
|
117
|
+
def filter_deprecation_string
|
118
|
+
'warning: event filtering in sensu-plugin is deprecated, see http://bit.ly/sensu-plugin'
|
119
|
+
end
|
120
|
+
|
121
|
+
def test_filter_deprecation_warning_exists_by_default
|
122
|
+
event = {
|
123
|
+
'client' => { 'name' => 'test' },
|
124
|
+
'check' => { 'name' => 'test', 'refresh' => 30 },
|
125
|
+
'occurrences' => 60,
|
126
|
+
'action' => 'create'
|
127
|
+
}
|
128
|
+
output = run_script_with_input(JSON.generate(event))
|
129
|
+
assert_equal(0, $?.exitstatus)
|
130
|
+
assert_match(/#{filter_deprecation_string}/, output)
|
131
|
+
end
|
132
|
+
|
133
|
+
def test_filter_deprecation_warning_exists_when_explicitly_enabled
|
134
|
+
event = {
|
135
|
+
'client' => { 'name' => 'test' },
|
136
|
+
'check' => { 'name' => 'test', 'refresh' => 30, 'enable_deprecated_filtering' => true },
|
137
|
+
'occurrences' => 60,
|
138
|
+
'action' => 'create'
|
139
|
+
}
|
140
|
+
output = run_script_with_input(JSON.generate(event))
|
141
|
+
assert_equal(0, $?.exitstatus)
|
142
|
+
assert_match(/#{filter_deprecation_string}/, output)
|
143
|
+
end
|
144
|
+
|
145
|
+
def test_filter_deprecation_warning_does_not_exist_when_explicitly_disabled
|
146
|
+
event = {
|
147
|
+
'client' => { 'name' => 'test' },
|
148
|
+
'check' => {
|
149
|
+
'name' => 'unfiltered test',
|
150
|
+
'refresh' => 30,
|
151
|
+
'enable_deprecated_filtering' => false
|
152
|
+
},
|
153
|
+
'occurrences' => 60,
|
154
|
+
'action' => 'create',
|
155
|
+
}
|
156
|
+
output = run_script_with_input(JSON.generate(event))
|
157
|
+
assert_equal(0, $?.exitstatus)
|
158
|
+
refute_match(/#{filter_deprecation_string}/, output)
|
159
|
+
end
|
160
|
+
|
161
|
+
def occurrence_filter_deprecation_string
|
162
|
+
'warning: occurrence filtering in sensu-plugin is deprecated, see http://bit.ly/sensu-plugin'
|
163
|
+
end
|
164
|
+
|
165
|
+
def test_occurrence_filter_deprecation_warning_exists_by_default
|
166
|
+
event = {
|
167
|
+
'client' => { 'name' => 'test' },
|
168
|
+
'check' => { 'name' => 'test', 'refresh' => 30 },
|
169
|
+
'occurrences' => 60,
|
170
|
+
'action' => 'create'
|
171
|
+
}
|
172
|
+
output = run_script_with_input(JSON.generate(event))
|
173
|
+
assert_equal(0, $?.exitstatus)
|
174
|
+
assert_match(/#{occurrence_filter_deprecation_string}/, output)
|
175
|
+
end
|
176
|
+
|
177
|
+
def test_occurrence_filter_deprecation_warning_exists_when_explicitly_enabled
|
178
|
+
event = {
|
179
|
+
'client' => { 'name' => 'test' },
|
180
|
+
'check' => {
|
181
|
+
'name' => 'test',
|
182
|
+
'refresh' => 30,
|
183
|
+
'enable_deprecated_occurrence_filtering' => true
|
184
|
+
},
|
185
|
+
'occurrences' => 60,
|
186
|
+
'action' => 'create'
|
187
|
+
}
|
188
|
+
output = run_script_with_input(JSON.generate(event))
|
189
|
+
assert_equal(0, $?.exitstatus)
|
190
|
+
assert_match(/#{occurrence_filter_deprecation_string}/, output)
|
191
|
+
end
|
192
|
+
|
193
|
+
def test_occurrence_filter_deprecation_warning_does_not_exist_when_explicitly_disabled
|
194
|
+
event = {
|
195
|
+
'client' => { 'name' => 'test' },
|
196
|
+
'check' => {
|
197
|
+
'name' => 'unfiltered test',
|
198
|
+
'refresh' => 30,
|
199
|
+
'enable_deprecated_occurrence_filtering' => false
|
200
|
+
},
|
201
|
+
'occurrences' => 60,
|
202
|
+
'action' => 'create',
|
203
|
+
}
|
204
|
+
output = run_script_with_input(JSON.generate(event))
|
205
|
+
assert_equal(0, $?.exitstatus)
|
206
|
+
refute_match(/#{occurrence_filter_deprecation_string}/, output)
|
207
|
+
end
|
116
208
|
end
|
data/test/handle_helper_test.rb
CHANGED
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
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Decklin Foster
|
@@ -9,22 +9,22 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-
|
12
|
+
date: 2016-07-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: json
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
requirements:
|
18
|
-
- - "
|
18
|
+
- - "<="
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version:
|
20
|
+
version: 2.0.0
|
21
21
|
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
|
-
- - "
|
25
|
+
- - "<="
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
version:
|
27
|
+
version: 2.0.0
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: mixlib-cli
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
@@ -82,6 +82,7 @@ files:
|
|
82
82
|
- lib/sensu-plugin/cli.rb
|
83
83
|
- lib/sensu-plugin/metric/cli.rb
|
84
84
|
- lib/sensu-plugin/utils.rb
|
85
|
+
- test/deep_merge_test.rb
|
85
86
|
- test/external_check_test.rb
|
86
87
|
- test/external_handler_argument_test.rb
|
87
88
|
- test/external_handler_test.rb
|
@@ -110,17 +111,18 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
110
111
|
version: '0'
|
111
112
|
requirements: []
|
112
113
|
rubyforge_project:
|
113
|
-
rubygems_version: 2.
|
114
|
+
rubygems_version: 2.4.5.1
|
114
115
|
signing_key:
|
115
116
|
specification_version: 4
|
116
117
|
summary: Sensu Plugins
|
117
118
|
test_files:
|
118
|
-
- test/
|
119
|
-
- test/
|
119
|
+
- test/deep_merge_test.rb
|
120
|
+
- test/external_check_test.rb
|
120
121
|
- test/external_handler_argument_test.rb
|
121
|
-
- test/handle_filter_test.rb
|
122
122
|
- test/external_handler_test.rb
|
123
|
+
- test/external_metric_test.rb
|
124
|
+
- test/handle_filter_test.rb
|
125
|
+
- test/handle_helper_test.rb
|
123
126
|
- test/mutator_test.rb
|
124
|
-
- test/external_check_test.rb
|
125
127
|
- test/test_helper.rb
|
126
128
|
has_rdoc: false
|