sensu-extensions 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -0
- data/lib/sensu/extensions/loader.rb +1 -1
- data/sensu-extensions.gemspec +1 -1
- data/spec/assets/config.json +1 -11
- data/spec/assets/extensions_symlinked/symlinked_check.rb +17 -0
- data/spec/extensions_spec.rb +2 -3
- data/spec/loader_spec.rb +3 -5
- metadata +4 -5
- data/lib/sensu/extensions/filters/attributes.rb +0 -71
- data/spec/filters/attributes_spec.rb +0 -53
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 04d00508af30e89a1a38b0650a63f074e811ada1
|
4
|
+
data.tar.gz: 5083b62566dba206901dc347e25c62ab3194d381
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0946b60f6b1cfd83a3f0cf8752be939efc4486de04d59c479c5a46ceafd72327de614d671de30c8f872a77a9a3556528f826b856bbf2439a17f8c9eb00d87081
|
7
|
+
data.tar.gz: a199a58d8a12fcbc7156426da9f2d71fbf12d0821d9b696c683a8f564c0dde70c1fc94a5bcb911235c5c66f054d2c8115c7cd73ad008252f8ba418b529a04ccd
|
data/.travis.yml
CHANGED
@@ -80,7 +80,7 @@ module Sensu
|
|
80
80
|
def load_directory(directory)
|
81
81
|
warning("loading extension files from directory", :directory => directory)
|
82
82
|
path = directory.gsub(/\\(?=\S)/, "/")
|
83
|
-
Dir.glob(File.join(path, "
|
83
|
+
Dir.glob(File.join(path, "**{,/*/**}/*.rb")).each do |file|
|
84
84
|
load_file(file)
|
85
85
|
end
|
86
86
|
end
|
data/sensu-extensions.gemspec
CHANGED
data/spec/assets/config.json
CHANGED
data/spec/extensions_spec.rb
CHANGED
@@ -40,21 +40,20 @@ describe "Sensu::Extensions" do
|
|
40
40
|
|
41
41
|
it "can load extensions from a directory" do
|
42
42
|
extensions = Sensu::Extensions.load(:extension_dir => @extension_dir)
|
43
|
-
expect(extensions.loaded_files.size).to eq(
|
43
|
+
expect(extensions.loaded_files.size).to eq(3)
|
44
44
|
expect(extensions.handler_exists?("test")).to be(true)
|
45
45
|
expect(extensions.check_exists?("mock_check")).to be(true)
|
46
46
|
end
|
47
47
|
|
48
48
|
it "can load extensions from one or more directories" do
|
49
49
|
extensions = Sensu::Extensions.load(:extension_dirs => [@extension_dir])
|
50
|
-
expect(extensions.loaded_files.size).to eq(
|
50
|
+
expect(extensions.loaded_files.size).to eq(3)
|
51
51
|
expect(extensions.handler_exists?("test")).to be(true)
|
52
52
|
expect(extensions.check_exists?("mock_check")).to be(true)
|
53
53
|
end
|
54
54
|
|
55
55
|
it "can load the built-in extensions" do
|
56
56
|
extensions = Sensu::Extensions.load
|
57
|
-
expect(extensions.filter_exists?("attributes")).to be(true)
|
58
57
|
expect(extensions.mutator_exists?("json")).to be(true)
|
59
58
|
expect(extensions.mutator_exists?("ruby_hash")).to be(true)
|
60
59
|
expect(extensions.mutator_exists?("only_check_output")).to be(true)
|
data/spec/loader_spec.rb
CHANGED
@@ -39,10 +39,10 @@ describe "Sensu::Extensions::Loader" do
|
|
39
39
|
expect(@loader.loaded_files).to be_empty
|
40
40
|
end
|
41
41
|
|
42
|
-
it "can load extensions from a directory" do
|
42
|
+
it "can load extensions from a directory containing directory symlinks" do
|
43
43
|
@loader.load_directory(@extension_dir)
|
44
|
-
expect(@loader.warnings.size).to eq(
|
45
|
-
expect(@loader.loaded_files.size).to eq(
|
44
|
+
expect(@loader.warnings.size).to eq(7)
|
45
|
+
expect(@loader.loaded_files.size).to eq(3)
|
46
46
|
extension = Sensu::Extension::Test.new
|
47
47
|
expect(extension).to respond_to(:name, :description, :definition, :safe_run, :stop, :has_key?, :[])
|
48
48
|
extension = Sensu::Extension::MockCheck.new
|
@@ -79,7 +79,6 @@ describe "Sensu::Extensions::Loader" do
|
|
79
79
|
expect(@loader.all).to include(extension)
|
80
80
|
expect(@loader.handler_exists?("debug")).to be(true)
|
81
81
|
expect(@loader.mutator_exists?("only_check_output")).to be(true)
|
82
|
-
expect(@loader.filter_exists?("attributes")).to be(true)
|
83
82
|
end
|
84
83
|
|
85
84
|
it "can load specific extension categories for a sensu client" do
|
@@ -93,7 +92,6 @@ describe "Sensu::Extensions::Loader" do
|
|
93
92
|
@loader.load_instances("server")
|
94
93
|
expect(@loader.handler_exists?("debug")).to be(true)
|
95
94
|
expect(@loader.mutator_exists?("only_check_output")).to be(true)
|
96
|
-
expect(@loader.filter_exists?("attributes")).to be(true)
|
97
95
|
expect(@loader.check_exists?("mock_check")).to be(false)
|
98
96
|
end
|
99
97
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sensu-extensions
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sean Porter
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-03-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sensu-em
|
@@ -164,7 +164,6 @@ files:
|
|
164
164
|
- README.md
|
165
165
|
- Rakefile
|
166
166
|
- lib/sensu/extensions.rb
|
167
|
-
- lib/sensu/extensions/filters/attributes.rb
|
168
167
|
- lib/sensu/extensions/handlers/debug.rb
|
169
168
|
- lib/sensu/extensions/loader.rb
|
170
169
|
- lib/sensu/extensions/mutators/json.rb
|
@@ -175,8 +174,8 @@ files:
|
|
175
174
|
- spec/assets/extensions/error.rb
|
176
175
|
- spec/assets/extensions/mock_check.rb
|
177
176
|
- spec/assets/extensions/test.rb
|
177
|
+
- spec/assets/extensions_symlinked/symlinked_check.rb
|
178
178
|
- spec/extensions_spec.rb
|
179
|
-
- spec/filters/attributes_spec.rb
|
180
179
|
- spec/handlers/debug_spec.rb
|
181
180
|
- spec/helpers.rb
|
182
181
|
- spec/loader_spec.rb
|
@@ -212,8 +211,8 @@ test_files:
|
|
212
211
|
- spec/assets/extensions/error.rb
|
213
212
|
- spec/assets/extensions/mock_check.rb
|
214
213
|
- spec/assets/extensions/test.rb
|
214
|
+
- spec/assets/extensions_symlinked/symlinked_check.rb
|
215
215
|
- spec/extensions_spec.rb
|
216
|
-
- spec/filters/attributes_spec.rb
|
217
216
|
- spec/handlers/debug_spec.rb
|
218
217
|
- spec/helpers.rb
|
219
218
|
- spec/loader_spec.rb
|
@@ -1,71 +0,0 @@
|
|
1
|
-
require "sensu/extension"
|
2
|
-
|
3
|
-
module Sensu
|
4
|
-
module Sandbox
|
5
|
-
def self.eval(eval_string, value=nil)
|
6
|
-
result = Proc.new do
|
7
|
-
$SAFE = (RUBY_VERSION < "2.1.0" ? 4 : 3)
|
8
|
-
Kernel.eval(eval_string)
|
9
|
-
end
|
10
|
-
result.call
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
module Extension
|
15
|
-
class Attributes < Filter
|
16
|
-
def name
|
17
|
-
"attributes"
|
18
|
-
end
|
19
|
-
|
20
|
-
def description
|
21
|
-
"filters events using event attributes"
|
22
|
-
end
|
23
|
-
|
24
|
-
def run(event, options)
|
25
|
-
status = filter_event?(options[:filter_name], event) ? 0 : 1
|
26
|
-
yield "", status
|
27
|
-
end
|
28
|
-
|
29
|
-
def eval_attribute_value(raw_eval_string, value)
|
30
|
-
begin
|
31
|
-
eval_string = raw_eval_string.gsub(/^eval:(\s+)?/, "")
|
32
|
-
!!Sandbox.eval(eval_string, value)
|
33
|
-
rescue => error
|
34
|
-
@logger.error("filter attribute eval error", {
|
35
|
-
:raw_eval_string => raw_eval_string,
|
36
|
-
:value => value,
|
37
|
-
:error => error.to_s
|
38
|
-
})
|
39
|
-
false
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
def attributes_match?(hash_one, hash_two)
|
44
|
-
hash_one.all? do |key, value_one|
|
45
|
-
value_two = hash_two[key]
|
46
|
-
case
|
47
|
-
when value_one == value_two
|
48
|
-
true
|
49
|
-
when value_one.is_a?(Hash) && value_two.is_a?(Hash)
|
50
|
-
attributes_match?(value_one, value_two)
|
51
|
-
when value_one.is_a?(String) && value_one.start_with?("eval:")
|
52
|
-
eval_attribute_value(value_one, value_two)
|
53
|
-
else
|
54
|
-
false
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
def filter_event?(filter_name, event)
|
60
|
-
if @settings.filter_exists?(filter_name)
|
61
|
-
filter = @settings[:filters][filter_name]
|
62
|
-
matched = attributes_match?(filter[:attributes], event)
|
63
|
-
filter[:negate] ? matched : !matched
|
64
|
-
else
|
65
|
-
@logger.error("unknown filter", :filter_name => filter_name)
|
66
|
-
false
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
@@ -1,53 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), "..", "helpers")
|
2
|
-
require "sensu/extensions/filters/attributes"
|
3
|
-
|
4
|
-
describe "Sensu::Extension::Attributes" do
|
5
|
-
include Helpers
|
6
|
-
|
7
|
-
before do
|
8
|
-
@extension = Sensu::Extension::Attributes.new
|
9
|
-
@extension.logger = logger
|
10
|
-
@extension.settings = settings
|
11
|
-
end
|
12
|
-
|
13
|
-
it "can determine if filter attributes match an event" do
|
14
|
-
attributes = {
|
15
|
-
:occurrences => 1
|
16
|
-
}
|
17
|
-
event = event_template
|
18
|
-
expect(@extension.attributes_match?(attributes, event)).to be(true)
|
19
|
-
event[:occurrences] = 2
|
20
|
-
expect(@extension.attributes_match?(attributes, event)).to be(false)
|
21
|
-
attributes[:occurrences] = "eval: value == 1 || value % 60 == 0"
|
22
|
-
event[:occurrences] = 1
|
23
|
-
expect(@extension.attributes_match?(attributes, event)).to be(true)
|
24
|
-
event[:occurrences] = 2
|
25
|
-
expect(@extension.attributes_match?(attributes, event)).to be(false)
|
26
|
-
event[:occurrences] = 120
|
27
|
-
expect(@extension.attributes_match?(attributes, event)).to be(true)
|
28
|
-
end
|
29
|
-
|
30
|
-
it "can run, filtering an event with a nonexistent filter" do
|
31
|
-
event = event_template
|
32
|
-
options = {:filter_name => "nonexistent"}
|
33
|
-
@extension.safe_run(event, options) do |output, status|
|
34
|
-
expect(output).to eq("")
|
35
|
-
expect(status).to eq(1)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
it "can run, filtering an event with a filter" do
|
40
|
-
event = event_template
|
41
|
-
event[:client][:environment] = "development"
|
42
|
-
options = {:filter_name => "production"}
|
43
|
-
@extension.safe_run(event, options) do |output, status|
|
44
|
-
expect(output).to eq("")
|
45
|
-
expect(status).to eq(0)
|
46
|
-
event[:client][:environment] = "production"
|
47
|
-
@extension.safe_run(event, options) do |output, status|
|
48
|
-
expect(output).to eq("")
|
49
|
-
expect(status).to eq(1)
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|