sensu-extension 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dfdd3db0fa88d97218101b74858cefdbcbb8c909
4
- data.tar.gz: 7c3e63a492dd1ad24947ceb5f2c0536797f9b600
3
+ metadata.gz: 21c7b06cebe3494d4c2120d9197c0cfef8e8587b
4
+ data.tar.gz: e47c912539ab3b791791aa343be02deeb780a372
5
5
  SHA512:
6
- metadata.gz: 711b0389397edb3a4829547288d3b679e2a8a0ccc884b46b18dda7097af2d9fbc9262f3b57226387c50b6c4351ccdb22e52c2c2a0b4cd6b107e10ed84b3c7c9b
7
- data.tar.gz: 95986606220f2a1d18a4a6aa8714bb24dafa53a610485ad44e7ad3112544cd579d6409468b1ed709a4a5f96aae0f02a93deae7e3443a083ad7ab59c5b04bea1e
6
+ metadata.gz: 032310825d74e68d6367ee9c71433d887bde7c95b543b642179f28318822a00d7986f06e7b651944bb7680e95adca18f2b2e84378e439c193d57abaf6fe9cc2c
7
+ data.tar.gz: 94c6f87fa29b2d612f95fb959dcddfe16cb1f86b64dad41e450067af51f213885c0689fc0c849a7bd26fea0dd778529bd74279455093aff62ca6d68aec70d572
@@ -15,11 +15,14 @@ module Sensu
15
15
  attr_accessor :settings
16
16
 
17
17
  # Initialize the extension, call post_init() when the
18
- # eventmachine reactor starts up.
18
+ # eventmachine reactor starts up, stop() when it stops.
19
19
  def initialize
20
20
  EM.next_tick do
21
21
  post_init
22
22
  end
23
+ EM.add_shutdown_hook do
24
+ stop
25
+ end
23
26
  end
24
27
 
25
28
  # Override this method to set the extension's name.
@@ -60,14 +63,10 @@ module Sensu
60
63
  callback.call("noop", 0)
61
64
  end
62
65
 
63
- # Override this method to do something before Sensu stops, such
64
- # as connection or file cleanup. You must yield or call the
65
- # callback.
66
- #
67
- # @param callback [Proc] provided by Sensu, expecting to be
68
- # called.
69
- def stop(&callback)
70
- callback.call
66
+ # Override this method to do something when the eventmachine
67
+ # reactor stops, such as connection or file cleanup.
68
+ def stop
69
+ true
71
70
  end
72
71
 
73
72
  # Retrieve the definition object corresponding to a key, acting
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "sensu-extension"
5
- spec.version = "0.0.1"
5
+ spec.version = "0.0.2"
6
6
  spec.authors = ["Sean Porter"]
7
7
  spec.email = ["portertech@gmail.com"]
8
8
  spec.summary = "The Sensu extension library"
data/spec/base_spec.rb CHANGED
@@ -10,11 +10,12 @@ describe "Sensu::Extension::Base" do
10
10
  end
11
11
 
12
12
  it "can provide the extension API" do
13
- @extension.should respond_to(:name, :description, :definition, :safe_run, :stop, :has_key?, :[])
13
+ @extension.should respond_to(:name, :description, :definition, :safe_run, :has_key?, :[])
14
14
  end
15
15
 
16
16
  it "can provide default method return values" do
17
17
  @extension.post_init.should be_true
18
+ @extension.stop.should be_true
18
19
  @extension.name.should eq("base")
19
20
  @extension.description.should eq("extension description (change me)")
20
21
  @extension.definition.should eq({:type => "extension", :name => "base"})
@@ -35,20 +36,30 @@ describe "Sensu::Extension::Base" do
35
36
  @extension.settings.should eq(settings)
36
37
  end
37
38
 
38
- it "can handle provided callbacks" do
39
+ it "can run without data" do
39
40
  async_wrapper do
40
41
  callback = Proc.new do |output, status|
41
42
  output.should eq("noop")
42
43
  status.should eq(0)
43
- @extension.stop do
44
- async_done
45
- end
44
+ async_done
46
45
  end
47
46
  @extension.run(&callback)
48
47
  end
49
48
  end
50
49
 
51
- it "can pass event data to run" do
50
+ it "can run with event data" do
51
+ async_wrapper do
52
+ callback = Proc.new do |output, status|
53
+ output.should eq("noop")
54
+ status.should eq(0)
55
+ async_done
56
+ end
57
+ event = {:foo => 1}
58
+ @extension.run(event, &callback)
59
+ end
60
+ end
61
+
62
+ it "can pass duplicated event data to run" do
52
63
  async_wrapper do
53
64
  event = {:foo => 1}
54
65
  @extension.safe_run(event) do |output, status|
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: 0.0.1
4
+ version: 0.0.2
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-05-21 00:00:00.000000000 Z
11
+ date: 2014-05-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sensu-em