outpost 0.2.4 → 0.2.5

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9bc0f3503cbedc0a68018342b7caba9f595b3c4e
4
+ data.tar.gz: a5f5a87728d0c4d0eb8c84bb7bc24bf65f3deaf7
5
+ SHA512:
6
+ metadata.gz: 5ccad69413b0968d0a3e485324a9b9e789b82406508b89fc5f9011d8cfd9dcf004e36989ddeaa8d7566ab0e396af74f3dc3300957bac026db987b5633549130c
7
+ data.tar.gz: 50ffd6928a6aa8a441d83063ef253c5680994bddfdefa6eacb541c12ab570037935d5e767cda1e36d36573444988923420856d26ba233efc39d4b5d4c358fabc
@@ -1,3 +1,3 @@
1
1
  rvm:
2
- - ree
2
+ - 2.0.0
3
3
  - 1.9.3
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source :rubygems
1
+ source 'https://rubygems.org'
2
2
 
3
3
  group :test do
4
4
  gem 'mail', :require => false
@@ -6,12 +6,9 @@ group :test do
6
6
  gem 'tinder', :require => false
7
7
 
8
8
  gem 'rake'
9
- gem 'thin'
10
- gem 'rack'
11
- gem 'sinatra'
9
+
10
+ gem 'fakeweb'
12
11
 
13
12
  gem 'minitest', '~> 2.0.2', :platforms => :ruby_18
14
13
  gem 'ruby-debug', :platforms => :ruby_18
15
-
16
- # gem 'ruby-debug19', :platforms => :ruby_19
17
14
  end
@@ -1,66 +1,62 @@
1
1
  GEM
2
- remote: http://rubygems.org/
2
+ remote: https://rubygems.org/
3
3
  specs:
4
- activesupport (3.0.3)
5
- addressable (2.2.2)
6
- columnize (0.3.2)
7
- daemons (1.1.0)
8
- eventmachine (0.12.10)
9
- faraday (0.5.4)
10
- addressable (~> 2.2.2)
11
- multipart-post (~> 1.1.0)
12
- rack (>= 1.1.0, < 2)
13
- i18n (0.5.0)
14
- linecache (0.43)
15
- mail (2.2.15)
16
- activesupport (>= 2.3.6)
17
- i18n (>= 0.4.0)
4
+ columnize (0.3.6)
5
+ eventmachine (1.0.3)
6
+ fakeweb (1.3.0)
7
+ faraday (0.8.7)
8
+ multipart-post (~> 1.1)
9
+ faraday_middleware (0.9.0)
10
+ faraday (>= 0.7.4, < 0.9)
11
+ ffi (1.9.0)
12
+ hashie (1.2.0)
13
+ http_parser.rb (0.5.3)
14
+ json (1.7.7)
15
+ linecache (0.46)
16
+ rbx-require-relative (> 0.0.4)
17
+ mail (2.5.4)
18
18
  mime-types (~> 1.16)
19
19
  treetop (~> 1.4.8)
20
- mime-types (1.16)
20
+ mime-types (1.23)
21
21
  minitest (2.0.2)
22
- multipart-post (1.1.0)
23
- net-ping (1.3.7)
24
- polyglot (0.3.1)
25
- rack (1.2.1)
26
- rake (0.8.7)
27
- roauth (0.0.3)
22
+ multi_json (1.7.7)
23
+ multipart-post (1.2.0)
24
+ net-ping (1.6.1)
25
+ ffi (>= 1.0.0)
26
+ polyglot (0.3.3)
27
+ rake (10.1.0)
28
+ rbx-require-relative (0.0.9)
28
29
  ruby-debug (0.10.4)
29
30
  columnize (>= 0.1)
30
31
  ruby-debug-base (~> 0.10.4.0)
31
32
  ruby-debug-base (0.10.4)
32
33
  linecache (>= 0.3)
33
- sinatra (1.1.2)
34
- rack (~> 1.1)
35
- tilt (~> 1.2)
36
- thin (1.2.7)
37
- daemons (>= 1.0.9)
38
- eventmachine (>= 0.12.6)
39
- rack (>= 1.0.0)
40
- tilt (1.2.2)
41
- tinder (1.4.3)
42
- activesupport
43
- eventmachine
44
- faraday (~> 0.5.1)
45
- mime-types
46
- multipart-post
47
- twitter-stream
48
- treetop (1.4.9)
34
+ simple_oauth (0.1.9)
35
+ tinder (1.9.2)
36
+ eventmachine (~> 1.0)
37
+ faraday (~> 0.8)
38
+ faraday_middleware (~> 0.9)
39
+ hashie (~> 1.0)
40
+ json (~> 1.7.5)
41
+ mime-types (~> 1.19)
42
+ multi_json (~> 1.5)
43
+ twitter-stream (~> 0.1)
44
+ treetop (1.4.14)
45
+ polyglot
49
46
  polyglot (>= 0.3.1)
50
- twitter-stream (0.1.10)
47
+ twitter-stream (0.1.16)
51
48
  eventmachine (>= 0.12.8)
52
- roauth (>= 0.0.2)
49
+ http_parser.rb (~> 0.5.1)
50
+ simple_oauth (~> 0.1.4)
53
51
 
54
52
  PLATFORMS
55
53
  ruby
56
54
 
57
55
  DEPENDENCIES
56
+ fakeweb
58
57
  mail
59
58
  minitest (~> 2.0.2)
60
59
  net-ping
61
- rack
62
60
  rake
63
61
  ruby-debug
64
- sinatra
65
- thin
66
62
  tinder
@@ -27,7 +27,7 @@ So, summing it all up, Nagios in Ruby, much cooler!
27
27
 
28
28
  ## Installing
29
29
 
30
- Outpost is tested with Ruby 1.8.7 and Ruby 1.9.2.
30
+ Outpost is tested with Ruby 1.8.7 and Ruby 1.9.3.
31
31
 
32
32
  gem install outpost
33
33
 
@@ -23,6 +23,7 @@ module Outpost
23
23
  @from = options[:from]
24
24
  @to = options[:to]
25
25
  @subject = options[:subject] || 'Outpost notification'
26
+ @delivery_method = options[:delivery_method] || []
26
27
 
27
28
  unless @from && @to
28
29
  raise ArgumentError, 'You need to set :from and :to to send emails.'
@@ -41,6 +42,8 @@ module Outpost
41
42
  mail.subject = @subject
42
43
  mail.body = build_message(outpost)
43
44
 
45
+ mail.send(:delivery_method, *@delivery_method) unless @delivery_method.empty?
46
+
44
47
  mail.deliver
45
48
  end
46
49
 
@@ -1,4 +1,5 @@
1
1
  require 'net/http'
2
+ require 'net/https'
2
3
  require 'outpost/expectations'
3
4
 
4
5
  module Outpost
@@ -26,21 +27,37 @@ module Outpost
26
27
  # @option options [String] :host The host that will be connected to.
27
28
  # @option options [Number] :port The port that will be used to.
28
29
  # @option options [String] :path The path that will be fetched from the
30
+ # @option options [Boolean] :ssl Should we use ssl?
29
31
  # host.
30
32
  # @option options [String] :http_class The class that will be used to
31
33
  # fetch the page, defaults to Net::HTTP
32
34
  def setup(options)
33
- @host = options[:host]
34
- @port = options[:port] || 80
35
- @path = options[:path] || '/'
36
- @http_class = options[:http_class] || Net::HTTP
35
+ @host = options.fetch(:host)
36
+ @path = options.fetch(:path, '/')
37
+ @ssl = options.fetch(:ssl, false)
38
+ @port = options.fetch(:port, (@ssl ? 443 : 80))
39
+ @http_class = options.fetch(:http_class, Net::HTTP)
40
+ @request_head = options.fetch(:request_head, false)
37
41
  end
38
42
 
39
43
  # Runs the scout, connecting to the host and getting the response code,
40
44
  # body and time.
41
45
  def execute
42
46
  previous_time = Time.now
43
- response = @http_class.get_response(@host, @path, @port)
47
+ if @request_head
48
+ response = @http_class.request_head(@host, @path, @port)
49
+ else
50
+ uri = (@ssl ? URI::HTTPS : URI::HTTP).build({
51
+ host: @host,
52
+ port: @port,
53
+ path: @path
54
+ })
55
+ http = @http_class.new(uri.host, uri.port)
56
+ http.use_ssl = @ssl
57
+
58
+ request = @http_class::Get.new(uri.request_uri)
59
+ response = http.request(request)
60
+ end
44
61
 
45
62
  @response_time = (Time.now - previous_time) * 1000 # Miliseconds
46
63
  @response_code = response.code.to_i
@@ -1,5 +1,5 @@
1
1
  module Outpost
2
- PATCH = 4
2
+ PATCH = 5
3
3
  MINOR = 2
4
4
  MAJOR = 0
5
5
  VERSION = "#{MAJOR}.#{MINOR}.#{PATCH}".freeze
@@ -3,12 +3,6 @@ require 'test_helper'
3
3
  require 'outpost/scouts/http'
4
4
 
5
5
  describe "basic application integration test" do
6
- before(:each) do
7
- @server = Server.new
8
- @server.boot(TestApp)
9
- @server.wait_until_booted
10
- end
11
-
12
6
  class ExampleSuccess < Outpost::Application
13
7
  using Outpost::Scouts::Http => 'master http server' do
14
8
  options :host => 'localhost', :port => 9595
@@ -3,12 +3,6 @@ require 'test_helper'
3
3
  require 'outpost/scouts'
4
4
 
5
5
  describe "using more complex application integration test" do
6
- before(:each) do
7
- @server = Server.new
8
- @server.boot(TestApp)
9
- @server.wait_until_booted
10
- end
11
-
12
6
  class ExamplePingAndHttp < Outpost::Application
13
7
  using Outpost::Scouts::Http => 'master http server' do
14
8
  options :host => 'localhost', :port => 9595, :path => '/'
@@ -4,11 +4,7 @@ require 'outpost/scouts/http'
4
4
  require 'outpost/notifiers/email'
5
5
 
6
6
  describe "creating outpost apps without subclassing" do
7
- before(:each) do
8
- @server = Server.new
9
- @server.boot(TestApp)
10
- @server.wait_until_booted
11
-
7
+ before do
12
8
  Mail.defaults do
13
9
  delivery_method :test
14
10
  end
@@ -15,10 +15,6 @@ describe "using only report data integration test" do
15
15
  end
16
16
 
17
17
  before(:each) do
18
- @server = Server.new
19
- @server.boot(TestApp)
20
- @server.wait_until_booted
21
-
22
18
  @outpost = RetrieveServerData.new
23
19
  @outpost.run
24
20
  end
@@ -1,5 +1,7 @@
1
1
  require 'test_helper'
2
2
 
3
+ require 'tmpdir'
4
+
3
5
  describe Outpost::Notifiers::Email do
4
6
  before(:each) do
5
7
  Mail.defaults do
@@ -40,6 +42,32 @@ describe Outpost::Notifiers::Email do
40
42
  end
41
43
  end
42
44
 
45
+ describe "#delivery_method" do
46
+ it "should use other delivery method if present" do
47
+ subject = Outpost::Notifiers::Email.new(
48
+ :from => 'mail@localhost',
49
+ :to => 'mailer@example.com',
50
+ #using file_delivery send method for testing
51
+ :delivery_method => [:file, {:location => Dir.tmpdir}]
52
+ )
53
+
54
+ subject.notify(outpost_stub)
55
+
56
+ assert_equal Mail::TestMailer.deliveries, []
57
+ end
58
+
59
+ it "should use default if not present" do
60
+ subject = Outpost::Notifiers::Email.new(
61
+ :from => 'mail@example.com',
62
+ :to => 'mailer@example.com'
63
+ )
64
+
65
+ subject.notify(outpost_stub)
66
+
67
+ assert_equal ["mail@example.com"], Mail::TestMailer.deliveries.first.from
68
+ end
69
+ end
70
+
43
71
  describe "#notify" do
44
72
  it "should send a simple email" do
45
73
  subject = Outpost::Notifiers::Email.new(
@@ -1,12 +1,42 @@
1
1
  require 'test_helper'
2
+ require 'ostruct'
2
3
 
3
4
  describe Outpost::Scouts::Http do
4
5
  class NetHttpStub
6
+ class Get
7
+ def initialize(*args); end
8
+ end
9
+
10
+ def initialize *args; end
11
+ def use_ssl= *args; end
12
+
13
+ def request(*args, &block)
14
+ self.class.response
15
+ end
16
+
17
+ class << self
18
+ def response(*args, &block)
19
+ if (block)
20
+ @response = block
21
+ else
22
+ @response.call
23
+ end
24
+ end
25
+
26
+ def request_head(*args)
27
+ throw "Unexpected call"
28
+ end
29
+ end
30
+ end
31
+
32
+ class NetHttpHeadStub < NetHttpStub
5
33
  class << self
6
- def response(&block); @response = block; end
34
+ def request_head(*args)
35
+ OpenStruct.new :code => 200, :body => 'Body'
36
+ end
7
37
 
8
38
  def get_response(*args)
9
- @response.call
39
+ throw "Unexpected call"
10
40
  end
11
41
  end
12
42
  end
@@ -47,6 +77,16 @@ describe Outpost::Scouts::Http do
47
77
  refute @subject.response_body
48
78
  end
49
79
 
80
+ it "should make HEAD request if option is passed" do
81
+ config_stub = config_stub(:host => 'localhost', :http_class => NetHttpHeadStub, :request_head => true)
82
+ @subject = Outpost::Scouts::Http.new("description", config_stub)
83
+
84
+ @subject.run
85
+
86
+ assert_equal 200 , @subject.response_code
87
+ assert_equal 'Body', @subject.response_body
88
+ end
89
+
50
90
  private
51
91
 
52
92
  def config_stub(options={})
@@ -2,15 +2,24 @@ require 'test_helper'
2
2
 
3
3
  describe Outpost::Scouts::Tcp do
4
4
  it "should set the time of ping in milliseconds" do
5
- @server = Server.new
6
- @server.boot(TestApp)
7
- @server.wait_until_booted
5
+ cls = Class.new do
6
+ def initialize(host, port, timeout)
7
+ end
8
8
 
9
- config = config_stub(:port => 9595)
9
+ def duration
10
+ 0.01
11
+ end
12
+
13
+ def ping?
14
+ true
15
+ end
16
+ end
17
+
18
+ config = config_stub(:port => 9595, :pinger => cls)
10
19
  subject = Outpost::Scouts::Tcp.new "test", config
11
20
  subject.execute
12
21
 
13
- assert subject.response_time < 100
22
+ assert subject.response_time.to_i < 100
14
23
  end
15
24
 
16
25
  it "should set the time to nil when it fails" do
@@ -0,0 +1,6 @@
1
+ require 'fakeweb'
2
+
3
+ FakeWeb.allow_net_connect = false
4
+ FakeWeb.register_uri(:get, "http://localhost:9595", :body => 'Up and running!', :status => 200)
5
+ FakeWeb.register_uri(:get, "http://localhost:9595/fail", :body => 'Omg fail', :status => 500)
6
+ FakeWeb.register_uri(:get, "http://localhost:9595/warning", :body => 'Omg need payment', :status => 402)
@@ -8,8 +8,7 @@ require 'minitest/spec'
8
8
  require 'minitest/autorun'
9
9
 
10
10
  # Integration test helpers
11
- require 'support/test_app'
12
- require 'support/server'
11
+ require 'support/requests'
13
12
  require 'support/stubs'
14
13
  require 'support/nothing_raised'
15
14
 
@@ -19,5 +18,4 @@ require 'outpost/notifiers'
19
18
  require 'outpost/scouts'
20
19
 
21
20
  include Support::Stubs
22
- include Support::NothingRaised
23
-
21
+ include Support::NothingRaised
metadata CHANGED
@@ -1,27 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: outpost
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
5
- prerelease:
4
+ version: 0.2.5
6
5
  platform: ruby
7
6
  authors:
8
7
  - Vinicius Baggio Fuentes
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2011-12-22 00:00:00.000000000 Z
11
+ date: 2013-09-05 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: net-ping
16
- requirement: &70128800958440 !ruby/object:Gem::Requirement
17
- none: false
15
+ requirement: !ruby/object:Gem::Requirement
18
16
  requirements:
19
- - - ! '>='
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :runtime
23
21
  prerelease: false
24
- version_requirements: *70128800958440
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
25
27
  description: Simple service monitoring with a clean DSL for configuration.
26
28
  email: vinibaggio@gmail.com
27
29
  executables: []
@@ -73,33 +75,31 @@ files:
73
75
  - test/outpost/scouts/ping_test.rb
74
76
  - test/outpost/scouts/tcp_test.rb
75
77
  - test/support/nothing_raised.rb
76
- - test/support/server.rb
78
+ - test/support/requests.rb
77
79
  - test/support/stubs.rb
78
- - test/support/test_app.rb
79
80
  - test/test_helper.rb
80
81
  homepage: http://www.github.com/vinibaggio/outpost
81
82
  licenses: []
83
+ metadata: {}
82
84
  post_install_message:
83
85
  rdoc_options: []
84
86
  require_paths:
85
87
  - lib
86
88
  required_ruby_version: !ruby/object:Gem::Requirement
87
- none: false
88
89
  requirements:
89
- - - ! '>='
90
+ - - '>='
90
91
  - !ruby/object:Gem::Version
91
92
  version: '0'
92
93
  required_rubygems_version: !ruby/object:Gem::Requirement
93
- none: false
94
94
  requirements:
95
- - - ! '>='
95
+ - - '>='
96
96
  - !ruby/object:Gem::Version
97
97
  version: '0'
98
98
  requirements: []
99
99
  rubyforge_project: outpost
100
- rubygems_version: 1.8.11
100
+ rubygems_version: 2.0.3
101
101
  signing_key:
102
- specification_version: 3
102
+ specification_version: 4
103
103
  summary: Simple service monitoring with a clean DSL for configuration.
104
104
  test_files:
105
105
  - test/integration/basic_application_test.rb
@@ -120,7 +120,6 @@ test_files:
120
120
  - test/outpost/scouts/ping_test.rb
121
121
  - test/outpost/scouts/tcp_test.rb
122
122
  - test/support/nothing_raised.rb
123
- - test/support/server.rb
123
+ - test/support/requests.rb
124
124
  - test/support/stubs.rb
125
- - test/support/test_app.rb
126
125
  - test/test_helper.rb
@@ -1,29 +0,0 @@
1
- require 'rack/handler/thin'
2
- require 'net/http'
3
-
4
- class Server
5
- def wait_until_booted
6
- while !responsive?
7
- sleep 0.1
8
- end
9
- end
10
-
11
- # Got it from Capybara, but simplified it a bit.
12
- # lib/capybara/server.rb
13
- def responsive?
14
- res = Net::HTTP.start('localhost', 9595) { |http| http.get('/') }
15
-
16
- res.is_a?(Net::HTTPSuccess) or res.is_a?(Net::HTTPRedirection)
17
- rescue Errno::ECONNREFUSED, Errno::EBADF
18
- return false
19
- end
20
-
21
- def boot(app)
22
- if not responsive?
23
- Thread.new do
24
- Thin::Logging.silent = true
25
- Rack::Handler::Thin.run(app, :Port => 9595)
26
- end
27
- end
28
- end
29
- end
@@ -1,15 +0,0 @@
1
- require 'sinatra/base'
2
-
3
- class TestApp < Sinatra::Base
4
- get '/' do
5
- [200, 'Up and running!']
6
- end
7
-
8
- get '/fail' do
9
- [500, 'Omg fail']
10
- end
11
-
12
- get '/warning' do
13
- [402, 'Omg need payment']
14
- end
15
- end