steto 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -10,7 +10,7 @@ module Cocaine
10
10
  begin
11
11
  run_without_exit_status
12
12
  ensure
13
- @exit_status = $?.exitstatus
13
+ @exit_status = $?.exitstatus if $?
14
14
  end
15
15
  end
16
16
  alias_method :run, :run_with_exit_status
data/lib/steto/engine.rb CHANGED
@@ -18,7 +18,12 @@ module Steto
18
18
 
19
19
  def check
20
20
  Parallel.each(checks, :in_threads => 4) do |check|
21
- check.check
21
+ begin
22
+ check.check
23
+ rescue => e
24
+ check.status = :unknown
25
+ check.text = e.to_s
26
+ end
22
27
  end
23
28
  self
24
29
  end
@@ -6,6 +6,7 @@ module Steto
6
6
  attr_accessor :command, :options
7
7
 
8
8
  def initialize(attributes = {})
9
+ self.command = ""
9
10
  self.options = {}
10
11
  self.attributes = attributes
11
12
  end
@@ -29,11 +30,16 @@ module Steto
29
30
  end
30
31
 
31
32
  def status_from_command_line
32
- { 0 => :ok,
33
- 1 => :warning,
34
- 2 => :critical,
35
- 3 => :unknown
36
- }[command_line.exit_status]
33
+ case command_line.exit_status
34
+ when 0
35
+ :ok
36
+ when 1
37
+ :warning
38
+ when 2
39
+ :critical
40
+ else
41
+ :unknown
42
+ end
37
43
  end
38
44
 
39
45
  end
@@ -7,7 +7,23 @@ module Steto
7
7
  end
8
8
 
9
9
  def check
10
- self.status = @block.call
10
+ self.status = status_from_response(@block.call)
11
11
  end
12
+
13
+ def status_from_response(response)
14
+ case response
15
+ when Steto::Status
16
+ response
17
+ when Symbol
18
+ Status.new(response)
19
+ when true
20
+ Status.new(:ok)
21
+ when false
22
+ Status.new(:critical)
23
+ when nil
24
+ Status.new(:unknown)
25
+ end
26
+ end
27
+
12
28
  end
13
29
  end
data/lib/steto/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Steto
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -12,6 +12,15 @@ describe Steto::Engine do
12
12
  subject.check
13
13
  end
14
14
 
15
+ it "should set as unknown a failing check" do
16
+ failing_check = Steto::ProcCheck.new(:name => :fail) do
17
+ raise "fail"
18
+ end
19
+ subject.checks << failing_check
20
+ subject.check
21
+ failing_check.status.should be_unknown
22
+ end
23
+
15
24
  end
16
25
 
17
26
  describe "#config" do
@@ -45,4 +45,13 @@ describe Steto::NagiosCheck do
45
45
 
46
46
  end
47
47
 
48
+ describe "#status_from_command_line" do
49
+
50
+ it "should return unknown when exitstatus is not defined" do
51
+ subject.command_line.stub :exit_status => nil
52
+ subject.status_from_command_line.should == :unknown
53
+ end
54
+
55
+ end
56
+
48
57
  end
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+
3
+ describe Steto::ProcCheck do
4
+
5
+ describe "#status_from_response" do
6
+
7
+ it "should return ok when response is true" do
8
+ subject.status_from_response(true).should be_ok
9
+ end
10
+
11
+ it "should return critical when response is false" do
12
+ subject.status_from_response(false).should be_critical
13
+ end
14
+
15
+ it "should return unknown when response is nil" do
16
+ subject.status_from_response(nil).should be_unknown
17
+ end
18
+
19
+ it "should return a Status when response is Symbol" do
20
+ subject.status_from_response(:ok).should be_ok
21
+ end
22
+
23
+ it "should return the response when it is a Status" do
24
+ subject.status_from_response(Steto::Status.new(:ok)).should be_ok
25
+ end
26
+
27
+ end
28
+
29
+
30
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: steto
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Alban Peignier
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2012-05-28 00:00:00 Z
19
+ date: 2012-05-30 00:00:00 Z
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  prerelease: false
@@ -138,6 +138,7 @@ files:
138
138
  - spec/steto/engine_spec.rb
139
139
  - spec/steto/logger_reporter_spec.rb
140
140
  - spec/steto/nagios_check_spec.rb
141
+ - spec/steto/proc_check_spec.rb
141
142
  - steto.gemspec
142
143
  homepage: https://github.com/tryphon/steto
143
144
  licenses: []
@@ -179,3 +180,4 @@ test_files:
179
180
  - spec/steto/engine_spec.rb
180
181
  - spec/steto/logger_reporter_spec.rb
181
182
  - spec/steto/nagios_check_spec.rb
183
+ - spec/steto/proc_check_spec.rb