flying 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/.travis.yml +1 -0
- data/README.markdown +25 -25
- data/lib/flying/aliases/aliases.rb +6 -3
- data/lib/flying/bots/up.rb +38 -8
- data/lib/flying/monitor.rb +49 -0
- data/lib/flying/version.rb +1 -1
- data/spec/lib/bots/up_spec.rb +34 -0
- data/spec/lib/flying_spec.rb +13 -0
- data/spec/spec_helper.rb +4 -1
- metadata +10 -6
- data/spec/bots/up_spec.rb +0 -20
data/.travis.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
script: bundle exec rspec spec
|
data/README.markdown
CHANGED
@@ -12,10 +12,10 @@ Create a Ruby file anywhere with the following content:
|
|
12
12
|
# flying.rb
|
13
13
|
require "flying"
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
15
|
+
site "http://www.google.com"
|
16
|
+
site "http://www.nytimes.com"
|
17
|
+
|
18
|
+
start # starts monitoring
|
19
19
|
```
|
20
20
|
|
21
21
|
Now, just run in your terminal:
|
@@ -31,32 +31,32 @@ We want to be able to use the following DSL:
|
|
31
31
|
```ruby
|
32
32
|
require "flying"
|
33
33
|
|
34
|
-
|
35
|
-
|
36
|
-
|
34
|
+
# Defines the interval between verifications
|
35
|
+
timer 1
|
36
|
+
|
37
|
+
# Send an email if any error occured
|
38
|
+
notify_me :email => "email@gmail.com"
|
37
39
|
|
38
|
-
|
39
|
-
|
40
|
+
# When an error happens, monitoring stops. :on_error_continue
|
41
|
+
# makes Flying ignore the error and continue monitoring.
|
42
|
+
site "http://www.google.com", :as => :google, :on_error => :continue
|
40
43
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
+
# If :google is down (above, :as => :google), Flying will notify the related services,
|
45
|
+
# e.g. 'www.mysite.com is probably not working properly because :google is offline'
|
46
|
+
site "http://www.mysite.com", :depends_on => :google
|
44
47
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
+
# Besides checking site availability, makes sure the response.body is a valid XML,
|
49
|
+
# ideal for making sure 3rd-party webservices are working.
|
50
|
+
site "http://www.fedex.com/webservice", :format => :xml
|
48
51
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
+
# Logs to the server via SSH, goes to a Rails app directory and do the following:
|
53
|
+
#
|
54
|
+
# - Reads production.log file and checks if any error happened (e.g. Errno... )
|
55
|
+
# - Looks for config/database.yml and tries connecting to all possible DBs, except
|
56
|
+
# 'development' and 'test'
|
57
|
+
rails_app "ssh://kurko@google.com", :path => "/var/rails/google"
|
52
58
|
|
53
|
-
|
54
|
-
#
|
55
|
-
# - Reads production.log file and checks if any error happened (e.g. Errno... )
|
56
|
-
# - Looks for config/database.yml and tries connecting to all possible DBs, except
|
57
|
-
# 'development' and 'test'
|
58
|
-
rails_app "ssh://kurko@google.com", :path => "/var/rails/google"
|
59
|
-
end
|
59
|
+
start
|
60
60
|
```
|
61
61
|
|
62
62
|
###License
|
@@ -1,7 +1,10 @@
|
|
1
1
|
module Kernel
|
2
2
|
def site(referer, *options)
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
bot = Flying::Bot::Up.new(referer, options)
|
4
|
+
Flying.add_bot(bot)
|
5
|
+
end
|
6
|
+
|
7
|
+
def start
|
8
|
+
Flying.start
|
6
9
|
end
|
7
10
|
end
|
data/lib/flying/bots/up.rb
CHANGED
@@ -3,27 +3,57 @@ require "net/http"
|
|
3
3
|
module Flying
|
4
4
|
module Bot
|
5
5
|
class Up
|
6
|
-
attr_reader :message
|
7
|
-
|
8
|
-
|
6
|
+
attr_reader :message, :error, :referer
|
7
|
+
#
|
8
|
+
# => Name
|
9
|
+
#
|
10
|
+
# How a service is known. Useful reusing and setting dependencies.
|
11
|
+
#
|
12
|
+
# e.g. `site "etc.com", :as => :google`
|
13
|
+
# name is :google.
|
14
|
+
#
|
15
|
+
# => Dependency
|
16
|
+
#
|
17
|
+
# When a service depends on another, it has dependencies. This is
|
18
|
+
# an array with the Name of each service.
|
19
|
+
#
|
20
|
+
attr_accessor :name, :dependency
|
21
|
+
|
22
|
+
def initialize(referer, options = {})
|
23
|
+
@referer = referer
|
24
|
+
@options = options
|
9
25
|
@message = "Ok."
|
26
|
+
@error = false
|
27
|
+
@name = options[:as] if options.include?(:as)
|
28
|
+
@dependency = []
|
29
|
+
|
30
|
+
# Dependency can be one or an array of symbols, whereas @dependency
|
31
|
+
# must be only a flat array
|
32
|
+
if options.include?(:depends_on)
|
33
|
+
@dependency << options[:depends_on] if options[:depends_on].kind_of? Symbol
|
34
|
+
@dependency = options[:depends_on] if options[:depends_on].kind_of? Array
|
35
|
+
end
|
10
36
|
end
|
11
37
|
|
12
|
-
|
38
|
+
# Starts assessment of the current service using variables set during
|
39
|
+
# initialization
|
40
|
+
def assess
|
41
|
+
@error = false
|
13
42
|
begin
|
14
|
-
response_code = get_http_response_code(referer)
|
43
|
+
response_code = get_http_response_code(@referer)
|
15
44
|
rescue
|
16
45
|
Flying.an_error_ocurred(true)
|
17
|
-
set_error_message(referer, false, $!)
|
46
|
+
set_error_message(@referer, false, $!)
|
18
47
|
return false
|
19
48
|
end
|
20
49
|
return true if ["200", "302"].include? response_code
|
21
50
|
Flying.an_error_ocurred(true)
|
22
|
-
set_error_message(referer, response_code.to_s)
|
51
|
+
set_error_message(@referer, response_code.to_s)
|
23
52
|
false
|
24
53
|
end
|
25
54
|
|
26
55
|
def set_error_message(referer, response_code, error_details = '')
|
56
|
+
@error = true
|
27
57
|
case response_code
|
28
58
|
when false
|
29
59
|
@message = message_unreachable
|
@@ -34,7 +64,7 @@ module Flying
|
|
34
64
|
else
|
35
65
|
@message = message_unknown_error + "(#{error_details})"
|
36
66
|
end
|
37
|
-
@message = referer + ": " + @message
|
67
|
+
@message = "\e[31m" + referer + ": " + @message + "\e[0m"
|
38
68
|
end
|
39
69
|
|
40
70
|
def get_http_response_code referer
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# This class instance holds the current monitoring.
|
2
|
+
module Flying
|
3
|
+
class Monitor
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
# This is where each bot instance is saved.
|
7
|
+
@bots = []
|
8
|
+
@an_error_ocurred = false
|
9
|
+
@first_attempt = true
|
10
|
+
@total_attempts = 0
|
11
|
+
end
|
12
|
+
|
13
|
+
def add_bot(bot)
|
14
|
+
@bots << bot
|
15
|
+
end
|
16
|
+
|
17
|
+
# Loops through each bot, making them perform verifications
|
18
|
+
def perform
|
19
|
+
puts "Running..."
|
20
|
+
looping = true
|
21
|
+
|
22
|
+
while(looping) do
|
23
|
+
@bots.each { |bot|
|
24
|
+
has_error = bot.error
|
25
|
+
assessment = bot.assess
|
26
|
+
if has_error == false && assessment == false
|
27
|
+
@an_error_ocurred = true
|
28
|
+
puts bot.message
|
29
|
+
elsif has_error && assessment
|
30
|
+
puts "\e[32m" + bot.referer + " is back online." + "\e[0m"
|
31
|
+
end
|
32
|
+
}
|
33
|
+
if @first_attempt
|
34
|
+
if @an_error_ocurred
|
35
|
+
puts "Some services are down. I'll continue monitoring the targets anyway."
|
36
|
+
else
|
37
|
+
puts "Everything's working fine. I'll continue monitoring the targets."
|
38
|
+
end
|
39
|
+
|
40
|
+
@first_attempt = false
|
41
|
+
end
|
42
|
+
@total_attempts += 1
|
43
|
+
sleep(5)
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
data/lib/flying/version.rb
CHANGED
@@ -0,0 +1,34 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Flying::Bot::Up do
|
4
|
+
context "initializing" do
|
5
|
+
it "sets an alias" do
|
6
|
+
bot = Flying::Bot::Up.new("http://www.google.com", :as => :google)
|
7
|
+
bot.name.should == :google
|
8
|
+
end
|
9
|
+
|
10
|
+
it "has a service as dependency" do
|
11
|
+
bot = Flying::Bot::Up.new("http://www.google.com", :depends_on => :google)
|
12
|
+
bot.dependency.should include(:google)
|
13
|
+
|
14
|
+
bot = Flying::Bot::Up.new("http://www.google.com", :depends_on => [:google, :fedex] )
|
15
|
+
bot.dependency.should include(:google)
|
16
|
+
bot.dependency.should include(:fedex)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context "assessing" do
|
21
|
+
subject { Flying::Bot::Up.new("http://www.google.com") }
|
22
|
+
|
23
|
+
it "checks if site is up" do
|
24
|
+
subject.stub(:get_http_response_code).and_return("302")
|
25
|
+
subject.assess.should be_true
|
26
|
+
end
|
27
|
+
|
28
|
+
it "returns false if 404 and saves a message" do
|
29
|
+
subject.stub(:get_http_response_code).and_return("404")
|
30
|
+
subject.assess.should be_false
|
31
|
+
subject.message.should =~ /google\.com.*target was simply not found \(404\)/
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Flying do
|
4
|
+
context "regarding errors" do
|
5
|
+
subject { Flying::Bot::Up.new("http://www.google.com") }
|
6
|
+
|
7
|
+
it "no error happened" do
|
8
|
+
subject.stub(:get_http_response_code).and_return("302")
|
9
|
+
subject.assess.should be_true
|
10
|
+
subject.error.should be_false
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flying
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-11-
|
12
|
+
date: 2011-11-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &70171055504220 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70171055504220
|
25
25
|
description: Verifies if each given server is not down.
|
26
26
|
email:
|
27
27
|
- chavedomundo@gmail.com
|
@@ -31,6 +31,7 @@ extra_rdoc_files: []
|
|
31
31
|
files:
|
32
32
|
- .gitignore
|
33
33
|
- .rspec
|
34
|
+
- .travis.yml
|
34
35
|
- Gemfile
|
35
36
|
- README.markdown
|
36
37
|
- Rakefile
|
@@ -38,8 +39,10 @@ files:
|
|
38
39
|
- lib/flying.rb
|
39
40
|
- lib/flying/aliases/aliases.rb
|
40
41
|
- lib/flying/bots/up.rb
|
42
|
+
- lib/flying/monitor.rb
|
41
43
|
- lib/flying/version.rb
|
42
|
-
- spec/bots/up_spec.rb
|
44
|
+
- spec/lib/bots/up_spec.rb
|
45
|
+
- spec/lib/flying_spec.rb
|
43
46
|
- spec/spec_helper.rb
|
44
47
|
homepage: https://github.com/kurko/flying
|
45
48
|
licenses: []
|
@@ -66,5 +69,6 @@ signing_key:
|
|
66
69
|
specification_version: 3
|
67
70
|
summary: Verifies if services are up and running.
|
68
71
|
test_files:
|
69
|
-
- spec/bots/up_spec.rb
|
72
|
+
- spec/lib/bots/up_spec.rb
|
73
|
+
- spec/lib/flying_spec.rb
|
70
74
|
- spec/spec_helper.rb
|
data/spec/bots/up_spec.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe Flying::Bot::Up do
|
4
|
-
subject { Flying::Bot::Up.new }
|
5
|
-
|
6
|
-
context "up" do
|
7
|
-
it "checks if site is up" do
|
8
|
-
subject.stub(:get_http_response_code).and_return("302")
|
9
|
-
subject.assess("http://www.google.com").should be_true
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
context "down" do
|
14
|
-
it "returns false if 404 and saves a message" do
|
15
|
-
subject.stub(:get_http_response_code).and_return("404")
|
16
|
-
subject.assess("http://www.google.com").should be_false
|
17
|
-
subject.message.should == "http://www.google.com: The target was simply not found (404)."
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|