simple_webmon 1.0.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/simple_webmon.rb +21 -0
- data/lib/simple_webmon/version.rb +1 -1
- data/spec/lib/simple_webmon_spec.rb +85 -32
- metadata +14 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0e3a74a386aff7a597f0897fa06aa000b389ea26
|
4
|
+
data.tar.gz: ee0b37c6d506206e38dab34bc363be86b152844a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0c2695aac94859d2cbbc50c6345433a76a8a39dec6470297ec05397e75b0565020c791612aa499c441794efcc8a55c0c775761cbf24ca6125b76d410600b2d01
|
7
|
+
data.tar.gz: 7ce04cd2f066fad0a8566d09fdb8346a616aedda6d232c03c983339de4407a01be78e279bb4e42bbc600ce700be5c159c9b80d05109b75d14f90a777546e1a3a
|
data/lib/simple_webmon.rb
CHANGED
@@ -4,10 +4,24 @@ require 'uri'
|
|
4
4
|
require 'timeout'
|
5
5
|
|
6
6
|
module SimpleWebmon
|
7
|
+
|
8
|
+
class Site
|
9
|
+
attr_reader :url, :timeout
|
10
|
+
attr_accessor :status
|
11
|
+
|
12
|
+
def initialize(url, timeout = 30)
|
13
|
+
@url = url
|
14
|
+
@timeout = timeout
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
7
18
|
class Monitor
|
8
19
|
|
9
20
|
def get_status(url)
|
10
21
|
res = Net::HTTP.get_response(URI.parse(url))
|
22
|
+
if res.code == "301"
|
23
|
+
res = Net::HTTP.get_response(URI.parse(res.header['location']))
|
24
|
+
end
|
11
25
|
res.message
|
12
26
|
end
|
13
27
|
|
@@ -23,5 +37,12 @@ module SimpleWebmon
|
|
23
37
|
status == 'OK' ? status : "ERROR: #{status}"
|
24
38
|
end
|
25
39
|
|
40
|
+
def check_sites(site_list)
|
41
|
+
site_list.each do |site|
|
42
|
+
site.status = check(site.url, site.timeout)
|
43
|
+
end
|
44
|
+
site_list
|
45
|
+
end
|
46
|
+
|
26
47
|
end
|
27
48
|
end
|
@@ -2,54 +2,107 @@ require 'spec_helper'
|
|
2
2
|
require 'simple_webmon'
|
3
3
|
|
4
4
|
describe SimpleWebmon do
|
5
|
-
|
6
|
-
|
5
|
+
context 'Monitor' do
|
6
|
+
before(:all) do
|
7
|
+
FakeWeb.allow_net_connect = false
|
7
8
|
|
8
|
-
|
9
|
-
|
9
|
+
FakeWeb.register_uri(:get, "http://good.example.com/",
|
10
|
+
body: "Hello World!")
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
12
|
+
FakeWeb.register_uri(:get, "http://servererror.example.com/",
|
13
|
+
body: "Internal Server Error",
|
14
|
+
status: ["500", "Internal Server Error"])
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
16
|
+
FakeWeb.register_uri(:get, "http://notfound.example.com/",
|
17
|
+
body: "Page Not Found",
|
18
|
+
status: ["404", "Not Found"])
|
18
19
|
|
19
|
-
|
20
|
-
|
21
|
-
end
|
22
|
-
|
23
|
-
let(:monitor) { SimpleWebmon::Monitor.new }
|
20
|
+
FakeWeb.register_uri(:get, "http://slow.example.com/",
|
21
|
+
response: sleep(10))
|
24
22
|
|
25
|
-
|
26
|
-
|
27
|
-
|
23
|
+
FakeWeb.register_uri(:get, "https://redirect.example.com/",
|
24
|
+
status: ["301", "Moved Permanently"],
|
25
|
+
location: "http://good.example.com/")
|
28
26
|
end
|
29
27
|
|
30
|
-
|
31
|
-
expect(monitor.get_status("http://servererror.example.com/")).to eq 'Internal Server Error'
|
32
|
-
end
|
33
|
-
end
|
28
|
+
let(:monitor) { SimpleWebmon::Monitor.new }
|
34
29
|
|
35
|
-
|
30
|
+
describe '.get_status' do
|
31
|
+
it "returns 'OK' when given a URL for a properly responding site" do
|
32
|
+
expect(monitor.get_status("http://good.example.com/")).to eq 'OK'
|
33
|
+
end
|
36
34
|
|
37
|
-
|
38
|
-
|
35
|
+
it "returns correct status message when given a URL that responds with an Internal Server Error" do
|
36
|
+
expect(monitor.get_status("http://servererror.example.com/")).to eq 'Internal Server Error'
|
37
|
+
end
|
39
38
|
end
|
40
39
|
|
41
|
-
|
42
|
-
|
40
|
+
describe '.check' do
|
41
|
+
it "returns 'ERROR' and timeout message when given a URL that doesn't respond in time" do
|
42
|
+
expect(monitor.check("http://slow.example.com/", 1)).to eq 'ERROR: Timeout'
|
43
|
+
end
|
44
|
+
|
45
|
+
it "returns 'OK' when given a URL that responds correctly" do
|
46
|
+
expect(monitor.check("http://good.example.com/")).to eq 'OK'
|
47
|
+
end
|
48
|
+
|
49
|
+
it "returns 'ERROR' and the correct status message when given a URL that fails" do
|
50
|
+
expect(monitor.check("http://servererror.example.com/")).to eq 'ERROR: Internal Server Error'
|
51
|
+
end
|
52
|
+
|
53
|
+
it "returns 'ERROR' and the correct status message when given a URL that fails" do
|
54
|
+
expect(monitor.check("http://notfound.example.com/")).to eq 'ERROR: Not Found'
|
55
|
+
end
|
56
|
+
|
57
|
+
it "returns 'OK' when given a URL that redirects to a site that responds correctly" do
|
58
|
+
expect(monitor.check("https://redirect.example.com")).to eq 'OK'
|
59
|
+
end
|
60
|
+
|
43
61
|
end
|
44
62
|
|
45
|
-
|
46
|
-
|
63
|
+
describe '.check_sites' do
|
64
|
+
let(:sites) {
|
65
|
+
[
|
66
|
+
SimpleWebmon::Site.new("http://good.example.com"),
|
67
|
+
SimpleWebmon::Site.new("http://slow.example.com", 1),
|
68
|
+
SimpleWebmon::Site.new("http://servererror.example.com"),
|
69
|
+
SimpleWebmon::Site.new("http://notfound.example.com")
|
70
|
+
]
|
71
|
+
}
|
72
|
+
|
73
|
+
it "accepts an array of Site objects and returns the same" do
|
74
|
+
expect(monitor.check_sites(sites)).to be_an(Array)
|
75
|
+
end
|
76
|
+
|
77
|
+
it "returned array has hostname and check response" do
|
78
|
+
response = monitor.check_sites(sites)
|
79
|
+
expect(response[0].status).to eq 'OK'
|
80
|
+
end
|
81
|
+
|
82
|
+
it "passes the timeout parameter along to check" do
|
83
|
+
response = monitor.check_sites(sites)
|
84
|
+
expect(response[1].status).to eq 'ERROR: Timeout'
|
85
|
+
end
|
86
|
+
|
87
|
+
it "returns correct status messages for each element passed in" do
|
88
|
+
response = monitor.check_sites(sites)
|
89
|
+
expect(response[0].status).to eq 'OK'
|
90
|
+
expect(response[1].status).to eq 'ERROR: Timeout'
|
91
|
+
expect(response[2].status).to eq 'ERROR: Internal Server Error'
|
92
|
+
expect(response[3].status).to eq 'ERROR: Not Found'
|
93
|
+
end
|
47
94
|
end
|
95
|
+
end
|
48
96
|
|
49
|
-
|
50
|
-
|
97
|
+
describe 'Site' do
|
98
|
+
it "can be created" do
|
99
|
+
expect(SimpleWebmon::Site.new("http://good.example.com")).to be_a(SimpleWebmon::Site)
|
51
100
|
end
|
52
101
|
|
102
|
+
it "stores a site URL and timeout settings" do
|
103
|
+
site = SimpleWebmon::Site.new("http://good.example.com", 10)
|
104
|
+
expect(site.url).to eq("http://good.example.com")
|
105
|
+
expect(site.timeout).to eq(10)
|
106
|
+
end
|
53
107
|
end
|
54
|
-
|
55
108
|
end
|
metadata
CHANGED
@@ -1,69 +1,69 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_webmon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Admire
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-12-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.3'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.3'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: fakeweb
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
description: Simple website monitoring.
|
@@ -73,8 +73,8 @@ executables: []
|
|
73
73
|
extensions: []
|
74
74
|
extra_rdoc_files: []
|
75
75
|
files:
|
76
|
-
- .gitignore
|
77
|
-
- .rspec
|
76
|
+
- ".gitignore"
|
77
|
+
- ".rspec"
|
78
78
|
- Gemfile
|
79
79
|
- LICENSE.txt
|
80
80
|
- README.md
|
@@ -94,12 +94,12 @@ require_paths:
|
|
94
94
|
- lib
|
95
95
|
required_ruby_version: !ruby/object:Gem::Requirement
|
96
96
|
requirements:
|
97
|
-
- -
|
97
|
+
- - ">="
|
98
98
|
- !ruby/object:Gem::Version
|
99
99
|
version: '0'
|
100
100
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
101
|
requirements:
|
102
|
-
- -
|
102
|
+
- - ">="
|
103
103
|
- !ruby/object:Gem::Version
|
104
104
|
version: '0'
|
105
105
|
requirements: []
|