opticon 0.0.2 → 0.0.3

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/.loadpath ADDED
@@ -0,0 +1,5 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <loadpath>
3
+ <pathentry path="" type="src"/>
4
+ <pathentry path="org.rubypeople.rdt.launching.RUBY_CONTAINER" type="con"/>
5
+ </loadpath>
data/.project ADDED
@@ -0,0 +1,17 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <projectDescription>
3
+ <name>opticon</name>
4
+ <comment></comment>
5
+ <projects>
6
+ </projects>
7
+ <buildSpec>
8
+ <buildCommand>
9
+ <name>org.rubypeople.rdt.core.rubybuilder</name>
10
+ <arguments>
11
+ </arguments>
12
+ </buildCommand>
13
+ </buildSpec>
14
+ <natures>
15
+ <nature>org.rubypeople.rdt.core.rubynature</nature>
16
+ </natures>
17
+ </projectDescription>
data/CHANGELOG.txt CHANGED
@@ -1,3 +1,12 @@
1
+ === 0.0.3 :: 2008-03-02
2
+
3
+ * When a service doesn't respond, a ConnectionFailure is now correctly
4
+ recorded. You can change how long Opticon will wait for a connection by
5
+ setting the Opticon.default_timeout value. The timeout is 3 seconds by
6
+ default.
7
+ * Changed require paths to fix strange loading problems experienced
8
+ by some people.
9
+
1
10
  === 0.0.2 :: 2007-11-15
2
11
 
3
12
  * A series of tests on a service can now be specified as a block to the
data/History.txt ADDED
File without changes
data/Manifest.txt CHANGED
@@ -1,6 +1,7 @@
1
- Rakefile
2
- README.txt
1
+ .loadpath
2
+ .project
3
3
  CHANGELOG.txt
4
+ History.txt
4
5
  Manifest.txt
5
6
  README.txt
6
7
  Rakefile
data/Rakefile CHANGED
@@ -20,7 +20,8 @@ HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
20
20
  DEPS = ['actionmailer']
21
21
 
22
22
  NAME = "opticon"
23
- REV = File.read(".svn/entries")[/committed-rev="(d+)"/, 1] rescue nil
23
+ REV = nil
24
+ #REV = `svn info`[/Revision: (\d+)/, 1] rescue nil
24
25
  VERS = ENV['VERSION'] || (Opticon::VERSION::STRING + (REV ? ".#{REV}" : ""))
25
26
  CLEAN.include ['**/.*.sw?', '*.gem', '.config']
26
27
  RDOC_OPTS = ['--quiet', '--title', "opticon documentation",
data/examples/sample.rb CHANGED
@@ -5,7 +5,7 @@ begin
5
5
  gem 'opticon'
6
6
  rescue Gem::LoadError
7
7
  # try to load local copy if gem is not available
8
- $: << 'lib'
8
+ $: << File.dirname(__FILE__)+'/../lib'
9
9
  end
10
10
 
11
11
  require 'opticon'
data/lib/opticon/http.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'net/http'
2
2
  require 'net/https'
3
3
  require 'uri'
4
+ require 'timeout'
4
5
 
5
6
  module Opticon
6
7
  module HTTP
@@ -28,11 +29,14 @@ module Opticon
28
29
  http.use_ssl = uri.scheme == "https"
29
30
 
30
31
  response = nil
31
- http.start do
32
- path = uri.path.empty? ? '/' : uri.path
33
- response = http.request_get(path)
32
+
33
+ timeout(Opticon.default_timeout) do
34
+ http.start do
35
+ path = uri.path.empty? ? '/' : uri.path
36
+ response = http.request_get(path)
37
+ end
34
38
  end
35
-
39
+
36
40
  response
37
41
  end
38
42
  end
@@ -1,4 +1,4 @@
1
- require 'opticon/mailer'
1
+ require File.dirname(File.expand_path(__FILE__))+'/mailer'
2
2
  require 'pstore'
3
3
 
4
4
  module Opticon
@@ -1,5 +1,5 @@
1
1
  require 'uri'
2
- require 'opticon/tester'
2
+ require File.dirname(File.expand_path(__FILE__))+'/tester'
3
3
 
4
4
  module Opticon
5
5
  class Service
@@ -62,7 +62,7 @@ module Opticon
62
62
 
63
63
  debug = "#{@uri} #{tester_type} #{condition.inspect}?"
64
64
 
65
- if tester.test(condition)
65
+ if tester.run(condition)
66
66
  puts "#{debug} ==> PASSED!" if ARGV.include?("-v")
67
67
  else
68
68
  puts "#{debug} ==> FAILED!" if ARGV.include?("-v")
@@ -1,5 +1,5 @@
1
- require 'opticon/http'
2
- require 'opticon/failure'
1
+ require File.dirname(File.expand_path(__FILE__))+'/http'
2
+ require File.dirname(File.expand_path(__FILE__))+'/failure'
3
3
 
4
4
  module Opticon
5
5
  module Tester
@@ -10,11 +10,12 @@ module Opticon
10
10
  include Opticon::HTTP
11
11
 
12
12
  # Wrapper for calling the test method.
13
- # Generally you'll want to invoke this instead of invoking test directly.
13
+ # Call this instead of invoking test directly.
14
14
  def run(condition)
15
15
  begin
16
16
  test(condition)
17
- rescue SocketError, TimeoutError, Net::HTTPError, Errno::ECONNREFUSED
17
+ rescue SocketError, TimeoutError, Net::HTTPError,
18
+ Errno::ECONNREFUSED, Timeout::Error => e
18
19
  @failure = Opticon::Failure::ConnectionFailure.new(uri, condition, nil)
19
20
  @failure.exception = $!
20
21
  false
@@ -24,6 +25,7 @@ module Opticon
24
25
 
25
26
  # Tests that the service responds with some given HTTP status code.
26
27
  class ResponseCodeTester < Base
28
+ protected
27
29
  def test(condition)
28
30
  case condition
29
31
  when :ok
@@ -50,14 +52,15 @@ module Opticon
50
52
 
51
53
  private
52
54
  def responds_with_code(codes)
53
-
55
+ r = self.response
56
+
54
57
  if codes.kind_of? Integer
55
- result = codes == response.code.to_i
58
+ result = codes == r.code.to_i
56
59
  else
57
- result = codes.include? response.code.to_i
60
+ result = codes.include? r.code.to_i
58
61
  end
59
62
 
60
- @failure = Opticon::Failure::ResponseCodeTestFailure.new(uri, codes, response) unless result
63
+ @failure = Opticon::Failure::ResponseCodeTestFailure.new(uri, codes, r) unless result
61
64
  return result
62
65
  end
63
66
 
@@ -85,35 +88,38 @@ module Opticon
85
88
  # Tests that the service responds with content that matches some given
86
89
  # string or regular expression.
87
90
  class ContentTester < Base
91
+ protected
88
92
  def test(condition)
89
- unless (200..206).include?(response.code.to_i)
90
- @failure = Opticon::Failure::ContentTestFailure.new(uri, condition, response)
91
- if (300..307).include?(response.code.to_i)
92
- @failure.exception = RuntimeError.new("Request was redirected to #{response['location']}.")
93
+ r = self.response
94
+
95
+ unless (200..206).include?(r.code.to_i)
96
+ @failure = Opticon::Failure::ContentTestFailure.new(uri, condition, r)
97
+ if (300..307).include?(r.code.to_i)
98
+ @failure.exception = RuntimeError.new("Request was redirected to #{r['location']}.")
93
99
  else
94
- @failure.exception = RuntimeError.new("Request returned code '#{response.message}'"+
100
+ @failure.exception = RuntimeError.new("Request returned code '#{r.message}'"+
95
101
  " (#{response.code}) but response must be a 2xx HTTP status code.")
96
102
  end
97
103
  return false
98
104
  end
99
105
 
100
- unless response.class.body_permitted?
101
- @failure = Opticon::Failure::ContentTestFailure.new(uri, condition, response)
102
- @failure.exception = RuntimeError.new("Response did not include a body (HTTP response: #{response.inspect})")
106
+ unless r.class.body_permitted?
107
+ @failure = Opticon::Failure::ContentTestFailure.new(uri, condition, r)
108
+ @failure.exception = RuntimeError.new("Response did not include a body (HTTP response: #{r.inspect})")
103
109
  return false
104
110
  end
105
111
 
106
112
  case condition
107
113
  when Regexp
108
- result = condition =~ response.body
114
+ result = condition =~ r.body
109
115
  when String
110
- result = response.body.include? condition
116
+ result = r.body.include? condition
111
117
  end
112
118
 
113
119
  if result
114
120
  @failure = nil
115
121
  else
116
- @failure = Opticon::Failure::ContentTestFailure.new(uri, condition, response)
122
+ @failure = Opticon::Failure::ContentTestFailure.new(uri, condition, r)
117
123
  end
118
124
 
119
125
  result
@@ -2,7 +2,7 @@ module Opticon #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 0
5
- TINY = 2
5
+ TINY = 3
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
data/lib/opticon.rb CHANGED
@@ -13,7 +13,16 @@ module Opticon
13
13
  end
14
14
  module_function :default_notifiers, 'default_notifiers='
15
15
 
16
+ @@default_timeout = 3
17
+ def default_timeout
18
+ @@default_timeout
19
+ end
20
+ def default_timeout=(timeout)
21
+ @@default_timeout = timeout
22
+ end
23
+ module_function :default_timeout, 'default_timeout='
24
+
16
25
  end
17
26
 
18
- require 'opticon/service'
19
- require 'opticon/notifier'
27
+ require File.dirname(File.expand_path(__FILE__))+'/opticon/service'
28
+ require File.dirname(File.expand_path(__FILE__))+'/opticon/notifier'
@@ -27,7 +27,7 @@ class Opticon::HTTPTest < Test::Unit::TestCase
27
27
 
28
28
  def test_response_code_tester_cant_connect
29
29
  tester = Opticon::Tester::ResponseCodeTester.new
30
- tester.uri = "http://there.is.no.such.server.foobarblah/test"
30
+ tester.uri = "http://there.is.no.such.server.foobarblah:1234/test"
31
31
 
32
32
  assert !tester.run(:success)
33
33
  assert_kind_of Opticon::Failure::ConnectionFailure, tester.failure
metadata CHANGED
@@ -1,38 +1,45 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.2
3
- specification_version: 1
4
2
  name: opticon
5
3
  version: !ruby/object:Gem::Version
6
- version: 0.0.2
7
- date: 2007-11-15 00:00:00 -05:00
8
- summary: Peace of mind through automated monitoring of your HTTP services.
9
- require_paths:
10
- - lib
11
- email: matt [at] roughest.net
12
- homepage: http://opticon.rubyforge.org
13
- rubyforge_project: opticon
14
- description: Peace of mind through automated monitoring of your HTTP services.
15
- autorequire:
16
- default_executable:
17
- bindir: bin
18
- has_rdoc: true
19
- required_ruby_version: !ruby/object:Gem::Version::Requirement
20
- requirements:
21
- - - ">"
22
- - !ruby/object:Gem::Version
23
- version: 0.0.0
24
- version:
4
+ version: 0.0.3
25
5
  platform: ruby
26
- signing_key:
27
- cert_chain:
28
- post_install_message:
29
6
  authors:
30
7
  - Matt Zukowski
31
- files:
32
- - Rakefile
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-04-02 00:00:00 -04:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: actionmailer
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: "0"
23
+ version:
24
+ description: Peace of mind through automated monitoring of your HTTP services.
25
+ email: matt [at] roughest.net
26
+ executables: []
27
+
28
+ extensions: []
29
+
30
+ extra_rdoc_files:
31
+ - CHANGELOG.txt
32
+ - History.txt
33
+ - Manifest.txt
33
34
  - README.txt
35
+ files:
36
+ - .loadpath
37
+ - .project
34
38
  - CHANGELOG.txt
39
+ - History.txt
35
40
  - Manifest.txt
41
+ - README.txt
42
+ - Rakefile
36
43
  - examples/sample.rb
37
44
  - lib/opticon.rb
38
45
  - lib/opticon/failure.rb
@@ -52,30 +59,37 @@ files:
52
59
  - test/opticon/tester_test.rb
53
60
  - test/opticon_test.rb
54
61
  - test/test_helper.rb
62
+ has_rdoc: true
63
+ homepage: http://opticon.rubyforge.org
64
+ post_install_message:
65
+ rdoc_options:
66
+ - --main
67
+ - README.txt
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: "0"
75
+ version:
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: "0"
81
+ version:
82
+ requirements: []
83
+
84
+ rubyforge_project: opticon
85
+ rubygems_version: 1.0.1
86
+ signing_key:
87
+ specification_version: 2
88
+ summary: Peace of mind through automated monitoring of your HTTP services.
55
89
  test_files:
56
90
  - test/opticon_test.rb
57
- - test/opticon/service_test.rb
58
- - test/opticon/tester_test.rb
59
91
  - test/opticon/mailer_test.rb
60
- - test/opticon/email_notifier_test.rb
61
92
  - test/opticon/http_test.rb
62
- rdoc_options: []
63
-
64
- extra_rdoc_files: []
65
-
66
- executables: []
67
-
68
- extensions: []
69
-
70
- requirements: []
71
-
72
- dependencies:
73
- - !ruby/object:Gem::Dependency
74
- name: actionmailer
75
- version_requirement:
76
- version_requirements: !ruby/object:Gem::Version::Requirement
77
- requirements:
78
- - - ">"
79
- - !ruby/object:Gem::Version
80
- version: 0.0.0
81
- version:
93
+ - test/opticon/tester_test.rb
94
+ - test/opticon/email_notifier_test.rb
95
+ - test/opticon/service_test.rb