sensu-extension 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/extension.rb +17 -8
- data/sensu-extension.gemspec +1 -1
- data/spec/base_spec.rb +15 -7
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 941ab203672e43dcfb491dfb58773b4a6736cd09
|
4
|
+
data.tar.gz: 9de1c6b6854722ce87a26834bf3e7ae09c81cc51
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 02c4d28bcbf8755a5eef699a27affa19299526cdb89a5942c0b08c7f0e46873175fe9a291f79abbd29fb24f8f981fa554966da20c8d5948dc1d6cb4819b92b7f
|
7
|
+
data.tar.gz: 2381e0dde4d250db42c83ff48e20470626346640250882d32a86b9539e2316a359a111ab9708dc4ba14c5a1e246fb6d5e8ffc95407744fbfd39d0309f84aea1d
|
data/lib/sensu/extension.rb
CHANGED
@@ -63,10 +63,13 @@ module Sensu
|
|
63
63
|
# @param data [Object, nil] provided by Sensu.
|
64
64
|
# @param options [Hash] provided by Sensu, may contain
|
65
65
|
# connection objects, eg. redis.
|
66
|
-
# @
|
67
|
-
# called with two parameters, an output string
|
68
|
-
|
69
|
-
|
66
|
+
# @yield [output, status] callback/block provided by Sensu,
|
67
|
+
# expecting to be called with two parameters, an output string
|
68
|
+
# and exit status code.
|
69
|
+
# @yieldparam output [String]
|
70
|
+
# @yieldparam status [Integer]
|
71
|
+
def run(data=nil, options={})
|
72
|
+
yield("noop", 0)
|
70
73
|
end
|
71
74
|
|
72
75
|
# Override this method to do something when the eventmachine
|
@@ -102,18 +105,24 @@ module Sensu
|
|
102
105
|
# has an absolue arity of 1 or more.
|
103
106
|
# @param options [Hash] to pass to run(), if run() has an
|
104
107
|
# absolute arity of 2.
|
105
|
-
# @
|
106
|
-
|
108
|
+
# @yield [output, status] callback/block provided by Sensu,
|
109
|
+
# expecting to be called with two parameters, an output string
|
110
|
+
# and exit status code.
|
111
|
+
# @yieldparam output [String]
|
112
|
+
# @yieldparam status [Integer]
|
113
|
+
def safe_run(data=nil, options={})
|
107
114
|
begin
|
108
115
|
@run_arity ||= method(:run).arity.abs
|
109
116
|
arguments = []
|
110
117
|
arguments << (data ? data.dup : data) if @run_arity >= 1
|
111
118
|
arguments << options if @run_arity == 2
|
112
|
-
run(*arguments,
|
119
|
+
run(*arguments) do |output, status|
|
120
|
+
yield(output, status)
|
121
|
+
end
|
113
122
|
rescue => error
|
114
123
|
klass = error.class.name
|
115
124
|
backtrace = error.backtrace.map { |line| "\s\s#{line}" }.join("\n")
|
116
|
-
|
125
|
+
yield("#{klass}: #{error}\n#{backtrace}", 2)
|
117
126
|
end
|
118
127
|
end
|
119
128
|
|
data/sensu-extension.gemspec
CHANGED
data/spec/base_spec.rb
CHANGED
@@ -38,6 +38,16 @@ describe "Sensu::Extension::Base" do
|
|
38
38
|
end
|
39
39
|
|
40
40
|
it "can run without data" do
|
41
|
+
async_wrapper do
|
42
|
+
@extension.run do |output, status|
|
43
|
+
expect(output).to eq("noop")
|
44
|
+
expect(status).to eq(0)
|
45
|
+
async_done
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
it "can run a proc without data" do
|
41
51
|
async_wrapper do
|
42
52
|
callback = Proc.new do |output, status|
|
43
53
|
expect(output).to eq("noop")
|
@@ -50,26 +60,24 @@ describe "Sensu::Extension::Base" do
|
|
50
60
|
|
51
61
|
it "can run with event data" do
|
52
62
|
async_wrapper do
|
53
|
-
|
63
|
+
event = {:foo => 1}
|
64
|
+
@extension.run(event) do |output, status|
|
54
65
|
expect(output).to eq("noop")
|
55
66
|
expect(status).to eq(0)
|
56
67
|
async_done
|
57
68
|
end
|
58
|
-
event = {:foo => 1}
|
59
|
-
@extension.run(event, &callback)
|
60
69
|
end
|
61
70
|
end
|
62
71
|
|
63
72
|
it "can run with options" do
|
64
73
|
async_wrapper do
|
65
|
-
|
74
|
+
event = {:foo => 1}
|
75
|
+
options = {:test => 1}
|
76
|
+
@extension.run(event, options) do |output, status|
|
66
77
|
expect(output).to eq("noop")
|
67
78
|
expect(status).to eq(0)
|
68
79
|
async_done
|
69
80
|
end
|
70
|
-
event = {:foo => 1}
|
71
|
-
options = {:test => 1}
|
72
|
-
@extension.run(event, options, &callback)
|
73
81
|
end
|
74
82
|
end
|
75
83
|
|
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.4.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: 2016-02-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: eventmachine
|
@@ -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.
|
122
|
+
rubygems_version: 2.4.5.1
|
123
123
|
signing_key:
|
124
124
|
specification_version: 4
|
125
125
|
summary: The Sensu extension library
|
@@ -127,4 +127,3 @@ test_files:
|
|
127
127
|
- spec/base_spec.rb
|
128
128
|
- spec/categories_spec.rb
|
129
129
|
- spec/helpers.rb
|
130
|
-
has_rdoc:
|