sensu-extension 1.0.0 → 1.1.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/extension.rb +10 -4
- data/lib/sensu/extension/constants.rb +1 -1
- data/sensu-extension.gemspec +3 -2
- data/spec/base_spec.rb +26 -1
- data/spec/categories_spec.rb +10 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 89f56995875626d482529538e59ff354aa515c59
|
4
|
+
data.tar.gz: d3fa3efd43cc6ba69badddb4fd062736ee414c7d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 568e9391e63a6661442ef7fccbbe585c14c726db4ccb005f60fa71362f1eb90bc5591b10b8c895011624888350612aeed8f50e528f8058835525bafd5983c604
|
7
|
+
data.tar.gz: 566da231ab3061573cb7765f9b3a12406ac4c36b59ca146d6e36d73972a1fd00072a19b61398d65c0ab10747de31caa1b7c579d180d29ef69e01fa8ae29daec0
|
data/lib/sensu/extension.rb
CHANGED
@@ -57,9 +57,11 @@ module Sensu
|
|
57
57
|
# an output string and exit code.
|
58
58
|
#
|
59
59
|
# @param data [Object, nil] provided by Sensu.
|
60
|
+
# @param options [Hash] provided by Sensu, may contain
|
61
|
+
# connection objects, eg. redis.
|
60
62
|
# @param callback [Proc] provided by Sensu, expecting to be
|
61
63
|
# called with two parameters, an output string and exit code.
|
62
|
-
def run(data=nil, &callback)
|
64
|
+
def run(data=nil, options={}, &callback)
|
63
65
|
callback.call("noop", 0)
|
64
66
|
end
|
65
67
|
|
@@ -93,12 +95,16 @@ module Sensu
|
|
93
95
|
# not override this method!
|
94
96
|
#
|
95
97
|
# @param data [Object, nil) to dup() and pass to run().
|
98
|
+
# @param options [Hash] to pass to run().
|
96
99
|
# @param callback [Proc] to pass to run().
|
97
|
-
def safe_run(data=nil, &callback)
|
100
|
+
def safe_run(data=nil, options={}, &callback)
|
98
101
|
begin
|
99
|
-
data ?
|
102
|
+
data_copy = data ? data.dup : data
|
103
|
+
run(data_copy, options, &callback)
|
100
104
|
rescue => error
|
101
|
-
|
105
|
+
klass = error.class.name
|
106
|
+
backtrace = error.backtrace.map { |line| "\s\s#{line}" }.join("\n")
|
107
|
+
callback.call("#{klass}: #{error}\n#{backtrace}", 2)
|
102
108
|
end
|
103
109
|
end
|
104
110
|
|
data/sensu-extension.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |spec|
|
4
4
|
spec.name = "sensu-extension"
|
5
|
-
spec.version = "1.
|
5
|
+
spec.version = "1.1.0"
|
6
6
|
spec.authors = ["Sean Porter"]
|
7
7
|
spec.email = ["portertech@gmail.com"]
|
8
8
|
spec.summary = "The Sensu extension library"
|
@@ -20,5 +20,6 @@ Gem::Specification.new do |spec|
|
|
20
20
|
spec.add_development_dependency "bundler", "~> 1.6"
|
21
21
|
spec.add_development_dependency "rake"
|
22
22
|
spec.add_development_dependency "rspec"
|
23
|
-
spec.add_development_dependency "
|
23
|
+
spec.add_development_dependency "bouncy-castle-java" if RUBY_PLATFORM =~ /java/
|
24
|
+
spec.add_development_dependency "codeclimate-test-reporter" unless RUBY_VERSION < "1.9"
|
24
25
|
end
|
data/spec/base_spec.rb
CHANGED
@@ -59,6 +59,19 @@ describe "Sensu::Extension::Base" do
|
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
62
|
+
it "can run with options" do
|
63
|
+
async_wrapper do
|
64
|
+
callback = Proc.new do |output, status|
|
65
|
+
expect(output).to eq("noop")
|
66
|
+
expect(status).to eq(0)
|
67
|
+
async_done
|
68
|
+
end
|
69
|
+
event = {:foo => 1}
|
70
|
+
options = {:test => 1}
|
71
|
+
@extension.run(event, options, &callback)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
62
75
|
it "can pass duplicated event data to run" do
|
63
76
|
async_wrapper do
|
64
77
|
event = {:foo => 1}
|
@@ -70,11 +83,23 @@ describe "Sensu::Extension::Base" do
|
|
70
83
|
end
|
71
84
|
end
|
72
85
|
|
86
|
+
it "can pass options to run" do
|
87
|
+
async_wrapper do
|
88
|
+
event = {:foo => 1}
|
89
|
+
options = {:test => 1}
|
90
|
+
@extension.safe_run(event, options) do |output, status|
|
91
|
+
expect(output).to eq("noop")
|
92
|
+
expect(status).to eq(0)
|
93
|
+
async_done
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
73
98
|
it "can catch some run errors" do
|
74
99
|
async_wrapper do
|
75
100
|
@extension.safe_run do |output, status|
|
76
101
|
raise "boom" if status == 0
|
77
|
-
expect(output).to eq("boom")
|
102
|
+
expect(output.split("\n").first).to eq("RuntimeError: boom")
|
78
103
|
expect(status).to eq(2)
|
79
104
|
async_done
|
80
105
|
end
|
data/spec/categories_spec.rb
CHANGED
@@ -21,6 +21,16 @@ describe "Sensu::Extension::Check" do
|
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
+
describe "Sensu::Extension::Filter" do
|
25
|
+
include Helpers
|
26
|
+
|
27
|
+
it "inherits Base" do
|
28
|
+
expect(Sensu::Extension::Filter.superclass).to eq(Sensu::Extension::Base)
|
29
|
+
extension = Sensu::Extension::Filter.new
|
30
|
+
expect(extension).to respond_to(:name, :description, :definition, :safe_run, :stop, :has_key?, :[])
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
24
34
|
describe "Sensu::Extension::Mutator" do
|
25
35
|
include Helpers
|
26
36
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sensu-extension
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.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: 2014-
|
11
|
+
date: 2014-12-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sensu-em
|
@@ -119,7 +119,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
119
119
|
version: '0'
|
120
120
|
requirements: []
|
121
121
|
rubyforge_project:
|
122
|
-
rubygems_version: 2.2.
|
122
|
+
rubygems_version: 2.2.2
|
123
123
|
signing_key:
|
124
124
|
specification_version: 4
|
125
125
|
summary: The Sensu extension library
|