outpost 0.2.3 → 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore CHANGED
@@ -1 +1,3 @@
1
1
  .yardoc
2
+ .rvmrc
3
+ *.gem
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ rvm:
2
+ - ree
3
+ - 1.9.3
data/CHANGELOG.rdoc CHANGED
@@ -1,3 +1,16 @@
1
+ == 0.2.4
2
+ Special thanks to @brain-geek for an awesome job on Outpost! This release is his.
3
+
4
+ * Features:
5
+ * Added TCP Scout [@brain-geek]
6
+ * Added support for ranges in HTTP response codes [@brain-geek]
7
+ * Bugfix:
8
+ * Fixing NoMethodError on unavailable host [@brain-geek]
9
+ * Other:
10
+ * Travis CI support!
11
+ * Removing ruby-debug from dependency [@brain-geek]
12
+ * Making net-ping as outpost dependency [@brain-geek]
13
+
1
14
  == 0.2.3
2
15
  * Bugfix
3
16
  * Avoid using ActiveSupport methods
data/Gemfile CHANGED
@@ -5,6 +5,7 @@ group :test do
5
5
  gem 'net-ping', :require => false
6
6
  gem 'tinder', :require => false
7
7
 
8
+ gem 'rake'
8
9
  gem 'thin'
9
10
  gem 'rack'
10
11
  gem 'sinatra'
@@ -12,5 +13,5 @@ group :test do
12
13
  gem 'minitest', '~> 2.0.2', :platforms => :ruby_18
13
14
  gem 'ruby-debug', :platforms => :ruby_18
14
15
 
15
- gem 'ruby-debug19', :platforms => :ruby_19
16
+ # gem 'ruby-debug19', :platforms => :ruby_19
16
17
  end
data/Gemfile.lock CHANGED
@@ -3,7 +3,6 @@ GEM
3
3
  specs:
4
4
  activesupport (3.0.3)
5
5
  addressable (2.2.2)
6
- archive-tar-minitar (0.5.2)
7
6
  columnize (0.3.2)
8
7
  daemons (1.1.0)
9
8
  eventmachine (0.12.10)
@@ -13,8 +12,6 @@ GEM
13
12
  rack (>= 1.1.0, < 2)
14
13
  i18n (0.5.0)
15
14
  linecache (0.43)
16
- linecache19 (0.5.11)
17
- ruby_core_source (>= 0.1.4)
18
15
  mail (2.2.15)
19
16
  activesupport (>= 2.3.6)
20
17
  i18n (>= 0.4.0)
@@ -26,22 +23,13 @@ GEM
26
23
  net-ping (1.3.7)
27
24
  polyglot (0.3.1)
28
25
  rack (1.2.1)
26
+ rake (0.8.7)
29
27
  roauth (0.0.3)
30
28
  ruby-debug (0.10.4)
31
29
  columnize (>= 0.1)
32
30
  ruby-debug-base (~> 0.10.4.0)
33
31
  ruby-debug-base (0.10.4)
34
32
  linecache (>= 0.3)
35
- ruby-debug-base19 (0.11.24)
36
- columnize (>= 0.3.1)
37
- linecache19 (>= 0.5.11)
38
- ruby_core_source (>= 0.1.4)
39
- ruby-debug19 (0.11.6)
40
- columnize (>= 0.3.1)
41
- linecache19 (>= 0.5.11)
42
- ruby-debug-base19 (>= 0.11.19)
43
- ruby_core_source (0.1.4)
44
- archive-tar-minitar (>= 0.5.2)
45
33
  sinatra (1.1.2)
46
34
  rack (~> 1.1)
47
35
  tilt (~> 1.2)
@@ -71,8 +59,8 @@ DEPENDENCIES
71
59
  minitest (~> 2.0.2)
72
60
  net-ping
73
61
  rack
62
+ rake
74
63
  ruby-debug
75
- ruby-debug19
76
64
  sinatra
77
65
  thin
78
66
  tinder
data/README.markdown CHANGED
@@ -1,5 +1,7 @@
1
1
  # Outpost
2
2
 
3
+ Build status: [![Build Status](https://secure.travis-ci.org/vinibaggio/outpost.png)](http://travis-ci.org/vinibaggio/outpost)
4
+
3
5
  ## Features
4
6
 
5
7
  Outpost is a tool to monitor the state of your service (not server). What does it mean?
@@ -95,7 +95,7 @@ module Outpost
95
95
  def initialize
96
96
  @reports = {}
97
97
  @last_status = nil
98
- @scouts = Hash.new { |h, k| h[k] = {} }
98
+ @scouts = Hash.new { |h, k| h[k] = [] }
99
99
  @notifiers = {}
100
100
  @name = self.class.name_template
101
101
 
@@ -115,8 +115,10 @@ module Outpost
115
115
  config.instance_eval(&block)
116
116
 
117
117
  scout_description.each do |scout, description|
118
- @scouts[scout][:description] = description
119
- @scouts[scout][:config] = config
118
+ @scouts[scout] << {
119
+ :description => description,
120
+ :config => config
121
+ }
120
122
  end
121
123
  end
122
124
 
@@ -128,8 +130,10 @@ module Outpost
128
130
  # Execute all the scouts associated with an Outpost-based class and returns
129
131
  # either :up or :down, depending on the results.
130
132
  def run
131
- scouts.map do |scout, options|
132
- @reports[options[:description]] = run_scout(scout, options)
133
+ scouts.map do |scout, configurations|
134
+ configurations.each do |options|
135
+ @reports[options[:description]] = run_scout(scout, options)
136
+ end
133
137
  end
134
138
 
135
139
  statuses = @reports.map { |_, r| r.status }
@@ -11,7 +11,7 @@ module Outpost
11
11
 
12
12
  # Method that will be used as an expectation to evaluate response code
13
13
  def evaluate_response_code(scout, response_code)
14
- if response_code.is_a?(Array)
14
+ if response_code.is_a?(Array) || response_code.is_a?(Range)
15
15
  response_code.include?(scout.response_code)
16
16
  else
17
17
  scout.response_code == response_code.to_i
@@ -21,7 +21,7 @@ module Outpost
21
21
  # Method that will be used as an expectation to evaluate response time
22
22
  def evaluate_response_time(scout, rules)
23
23
  rules.all? do |rule, comparison|
24
- scout.response_time.send(RESPONSE_TIME_MAPPING[rule], comparison)
24
+ scout.response_time.nil? ? false : scout.response_time.send(RESPONSE_TIME_MAPPING[rule], comparison)
25
25
  end
26
26
  end
27
27
  end
@@ -1,2 +1,3 @@
1
1
  require 'outpost/scouts/http'
2
2
  require 'outpost/scouts/ping'
3
+ require 'outpost/scouts/tcp'
@@ -1,10 +1,4 @@
1
- begin
2
- require 'net/ping/external'
3
- rescue LoadError => e
4
- puts "Please install net-ping gem: gem install net-ping".
5
- raise
6
- end
7
-
1
+ require 'net/ping/external'
8
2
  require 'outpost/expectations'
9
3
 
10
4
  module Outpost
@@ -14,8 +8,6 @@ module Outpost
14
8
  #
15
9
  # * Responds to response_time expectation
16
10
  # ({Outpost::Expectations::ResponseTime})
17
- #
18
- # It needs the 'net-ping' gem.
19
11
  class Ping < Outpost::Scout
20
12
  extend Outpost::Expectations::ResponseTime
21
13
  attr_reader :response_time
@@ -0,0 +1,38 @@
1
+ require 'net/ping/tcp'
2
+ require 'outpost/expectations'
3
+
4
+ module Outpost
5
+ module Scouts
6
+ # Uses net/ping tcp pinger to check if port is open
7
+ #
8
+ # * Responds to response_time expectation
9
+ # ({Outpost::Expectations::ResponseTime})
10
+ class Tcp < Ping
11
+ extend Outpost::Expectations::ResponseTime
12
+ attr_reader :response_time
13
+ report_data :response_time
14
+
15
+ # Configure the scout with given options.
16
+ # @param [Hash] Options to setup the scout
17
+ # @option options [String] :host The host that will be "pinged".
18
+ # @option options [Object] :pinger An object that can ping hosts.
19
+ # Defaults to Net::Ping::Tcp.new
20
+ def setup(options)
21
+ host = options[:host]
22
+ port = options[:port]
23
+ timeout= options[:timeout] || 3
24
+ pinger = options[:pinger] || Net::Ping::TCP
25
+
26
+ @pinger = pinger.new(host, port, timeout)
27
+ end
28
+
29
+ # Runs the scout, pinging the host and getting the duration.
30
+ def execute
31
+ if @pinger.ping?
32
+ # Miliseconds
33
+ @response_time = @pinger.duration * 1000
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -1,5 +1,5 @@
1
1
  module Outpost
2
- PATCH = 3
2
+ PATCH = 4
3
3
  MINOR = 2
4
4
  MAJOR = 0
5
5
  VERSION = "#{MAJOR}.#{MINOR}.#{PATCH}".freeze
data/outpost.gemspec CHANGED
@@ -16,4 +16,6 @@ Gem::Specification.new do |s|
16
16
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
17
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
18
  s.require_paths = ["lib"]
19
+
20
+ s.add_dependency "net-ping"
19
21
  end
@@ -34,16 +34,33 @@ describe Outpost::Application do
34
34
  end
35
35
 
36
36
  before(:each) do
37
- @scouts = ExampleOne.new.scouts
37
+ @example = ExampleOne.new
38
+ @scouts = @example.scouts
38
39
  end
39
40
 
40
41
  it "should create correct scout description" do
41
- assert_equal(ScoutMock, @scouts.keys.first)
42
- assert_equal('master http server', @scouts[ScoutMock][:description])
42
+ scouts = @scouts[ScoutMock]
43
+
44
+ assert scouts
45
+ assert_equal('master http server', scouts.first[:description])
46
+ end
47
+
48
+ it "should store more than one scout description" do
49
+ @example.add_scout ScoutMock => 'slave http server' do
50
+ options :host => 'example.com'
51
+ report :up, :response_code => 200
52
+ end
53
+
54
+ descriptions = @example.scouts[ScoutMock].map { |options| options[:description] }
55
+
56
+ assert_equal(2, @example.scouts[ScoutMock].size)
57
+ assert_equal('master http server', descriptions.first)
58
+ assert_equal('slave http server', descriptions.last)
43
59
  end
44
60
 
45
61
  it "should create correct scout config" do
46
- config = @scouts[ScoutMock][:config]
62
+ config = @scouts[ScoutMock].first[:config]
63
+
47
64
  assert_equal({:host => 'localhost'}, config.options)
48
65
  assert_equal({{:response_code => 200} => :up}, config.reports)
49
66
  end
@@ -44,6 +44,15 @@ describe Outpost::Expectations::ResponseCode do
44
44
  refute SubjectCode.evaluate_response_code(scout_stub, [500, 503])
45
45
  end
46
46
 
47
+ it "should return true when response code is included in the range" do
48
+ assert SubjectCode.evaluate_response_code(scout_stub, 200...300)
49
+ end
50
+
51
+ it "should refute when response code is not included in the range" do
52
+ refute SubjectCode.evaluate_response_code(scout_stub, 500..503)
53
+ end
54
+
55
+
47
56
  private
48
57
  def scout_stub
49
58
  build_stub(:response_code => 200)
@@ -14,6 +14,13 @@ describe Outpost::Expectations::ResponseTime do
14
14
  extend Outpost::Expectations::ResponseTime
15
15
  end
16
16
 
17
+ describe ".evaluation_response_time with nil" do
18
+ it "should fail gracefully" do
19
+ #this is common, as host can be not accessible for ping
20
+ refute SubjectTime.evaluate_response_time(build_stub(:response_time => nil), :less_than => 400)
21
+ end
22
+ end
23
+
17
24
  describe ".evaluate_response_time with less_than" do
18
25
  it "should return true when it matches" do
19
26
  assert SubjectTime.evaluate_response_time(scout_stub, :less_than => 5000)
@@ -0,0 +1,32 @@
1
+ require 'test_helper'
2
+
3
+ describe Outpost::Scouts::Tcp do
4
+ it "should set the time of ping in milliseconds" do
5
+ @server = Server.new
6
+ @server.boot(TestApp)
7
+ @server.wait_until_booted
8
+
9
+ config = config_stub(:port => 9595)
10
+ subject = Outpost::Scouts::Tcp.new "test", config
11
+ subject.execute
12
+
13
+ assert subject.response_time < 100
14
+ end
15
+
16
+ it "should set the time to nil when it fails" do
17
+ #nothing uses this port by deafult
18
+ config = config_stub(:port => 16)
19
+ subject = Outpost::Scouts::Tcp.new "test", config
20
+ subject.execute
21
+
22
+ assert subject.response_time.nil?
23
+ end
24
+
25
+ private
26
+
27
+ def config_stub(options={})
28
+ options = {:host => 'localhost'}.merge options
29
+
30
+ build_stub(:options => options)
31
+ end
32
+ end
data/test/test_helper.rb CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
  require 'bundler'
3
3
  Bundler.setup(:default, :test)
4
4
 
5
- require 'ruby-debug'
5
+ require 'ruby-debug' unless RUBY_VERSION > '1.9'
6
6
  require 'ostruct'
7
7
  require 'minitest/spec'
8
8
  require 'minitest/autorun'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: outpost
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,9 +9,19 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-08-06 00:00:00.000000000 -03:00
13
- default_executable:
14
- dependencies: []
12
+ date: 2011-12-22 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: net-ping
16
+ requirement: &70128800958440 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70128800958440
15
25
  description: Simple service monitoring with a clean DSL for configuration.
16
26
  email: vinibaggio@gmail.com
17
27
  executables: []
@@ -19,6 +29,7 @@ extensions: []
19
29
  extra_rdoc_files: []
20
30
  files:
21
31
  - .gitignore
32
+ - .travis.yml
22
33
  - CHANGELOG.rdoc
23
34
  - Gemfile
24
35
  - Gemfile.lock
@@ -41,6 +52,7 @@ files:
41
52
  - lib/outpost/scouts.rb
42
53
  - lib/outpost/scouts/http.rb
43
54
  - lib/outpost/scouts/ping.rb
55
+ - lib/outpost/scouts/tcp.rb
44
56
  - lib/outpost/version.rb
45
57
  - outpost.gemspec
46
58
  - test/integration/basic_application_test.rb
@@ -59,12 +71,12 @@ files:
59
71
  - test/outpost/scout_test.rb
60
72
  - test/outpost/scouts/http_test.rb
61
73
  - test/outpost/scouts/ping_test.rb
74
+ - test/outpost/scouts/tcp_test.rb
62
75
  - test/support/nothing_raised.rb
63
76
  - test/support/server.rb
64
77
  - test/support/stubs.rb
65
78
  - test/support/test_app.rb
66
79
  - test/test_helper.rb
67
- has_rdoc: true
68
80
  homepage: http://www.github.com/vinibaggio/outpost
69
81
  licenses: []
70
82
  post_install_message:
@@ -85,7 +97,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
85
97
  version: '0'
86
98
  requirements: []
87
99
  rubyforge_project: outpost
88
- rubygems_version: 1.6.2
100
+ rubygems_version: 1.8.11
89
101
  signing_key:
90
102
  specification_version: 3
91
103
  summary: Simple service monitoring with a clean DSL for configuration.
@@ -106,6 +118,7 @@ test_files:
106
118
  - test/outpost/scout_test.rb
107
119
  - test/outpost/scouts/http_test.rb
108
120
  - test/outpost/scouts/ping_test.rb
121
+ - test/outpost/scouts/tcp_test.rb
109
122
  - test/support/nothing_raised.rb
110
123
  - test/support/server.rb
111
124
  - test/support/stubs.rb