eir 0.0.1

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e2465bf45d8f376b3f4c991d3b10a0350b18aeec
4
+ data.tar.gz: 552c7430315e447ac15cfebf2099bad9767b383d
5
+ SHA512:
6
+ metadata.gz: 48babb50b062caad346fe6591e59c604e0b02d30942134cc1081e4a8ce5dfa989cdc65a1eab62cb729ad58645292ebe70a389796397d832ff6bf4b907ae63f6d
7
+ data.tar.gz: 622a41d0c8cca3b86e1dc6d97999c3593d786f0132e50a3969f5c8f390ace720bef602bb5532325295b75ee252781054d800d43c669a0366b0abc1cc6feef773
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .idea
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in eir.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Ben Snape
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # Eir
2
+
3
+ A really easy way to monitor the health of a list of endpoints over time.
4
+
5
+ ## Installation and Usage
6
+
7
+ Install:
8
+
9
+ $ gem install eir
10
+
11
+ In a new directory, create a `uris.yaml` YAML file of the URIs you wish to monitor:
12
+
13
+ - http://www.google.co.uk : Google
14
+ - http://www.yahoo.co.uk : Yahoo
15
+ - http://www.itv.com : ITV
16
+
17
+ From the console, navigate to your new directory and simply run:
18
+
19
+ $ eir
20
+
21
+ A lightweight Sinatra app will start at `http://localhost:8700`.
22
+
23
+ ## TODO
24
+
25
+ 1. Test connection error cases
26
+ 2. Parse/validate URIs
27
+ 3. Validate YAML
28
+ 4. A pre
29
+
30
+ ## Contributing
31
+
32
+ 1. Fork it ( http://github.com/<my-github-username>/eir/fork )
33
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
34
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
35
+ 4. Push to the branch (`git push origin my-new-feature`)
36
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+ require_relative 'lib/eir'
4
+
5
+ RSpec::Core::RakeTask.new
6
+
7
+ task :default => :spec
data/bin/eir ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+ $:.unshift(File.dirname(__FILE__) + '/../lib') unless $:.include?(File.dirname(__FILE__) + '/../lib')
3
+
4
+ require 'bundler/setup'
5
+ require 'eir'
6
+
7
+ Eir::Server.new.start
data/eir.gemspec ADDED
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'eir/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'eir'
8
+ spec.version = Eir::VERSION
9
+ spec.authors = ['Ben Snape']
10
+ spec.email = %w(bsnape@gmail.com)
11
+ spec.summary = %w{Monitor the health of URI's}
12
+ spec.description = %w{Easily monitor the health of arbitrary URI's defined in YAML config}
13
+ spec.homepage = 'http://www.bensnape.com'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = %w(lib)
20
+
21
+ spec.add_dependency 'rest-client', '~> 1.6.7'
22
+ spec.add_dependency 'sinatra', '~> 1.4.5'
23
+ spec.add_dependency 'haml', '~> 4'
24
+ spec.add_dependency 'puma', '~> 2.8.2'
25
+
26
+ spec.add_development_dependency 'bundler', '~> 1.5'
27
+ spec.add_development_dependency 'rake', '~> 10'
28
+ spec.add_development_dependency 'rspec', '~> 2'
29
+ spec.add_development_dependency 'rack-test', '~> 0.6.2'
30
+ end
@@ -0,0 +1,24 @@
1
+ require 'sinatra'
2
+ require 'json'
3
+ require 'logger'
4
+
5
+ configure { set :server, :puma }
6
+
7
+ class App < Sinatra::Base
8
+
9
+ configure do
10
+ set :root, File.dirname(__FILE__)
11
+ enable :logging
12
+ end
13
+
14
+ get '/status' do
15
+ status 200
16
+ end
17
+
18
+ get '/' do
19
+ @eir = Eir::Request.new
20
+ @responses = @eir.go
21
+ haml :dashboard, :layout => (request.xhr? ? false : :layout)
22
+ end
23
+
24
+ end
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative 'app'
4
+ require_relative '../../eir'
5
+
6
+ run App
@@ -0,0 +1,5 @@
1
+ body {background-color:black;}
2
+ p {color: white;}
3
+ .results p {color: black}
4
+ .success {background-color:#00ff00; margin: 10px 0 10px 0;}
5
+ .failure {background-color:#ff0512; margin: 10px 0 10px 0;}
@@ -0,0 +1,12 @@
1
+ GEM_LOCATION = File.dirname(__FILE__)
2
+ CURRENT_DIRECTORY = Dir.pwd
3
+
4
+ rackup "#{GEM_LOCATION}/config.ru"
5
+ pidfile "#{CURRENT_DIRECTORY}/server.pid"
6
+ daemonize true
7
+
8
+ port 8700
9
+
10
+ stdout_log = "#{CURRENT_DIRECTORY}/access.log"
11
+ stderr_log = "#{CURRENT_DIRECTORY}/error.log"
12
+ stdout_redirect(stdout_log, stderr_log, true)
@@ -0,0 +1,11 @@
1
+ #content
2
+ %p= "Last updated: #{Time.now.strftime('%H:%M:%S')}"
3
+ .results
4
+ #status-code
5
+ - @responses.each do |uri, code|
6
+ - if code == 200
7
+ .success
8
+ %p= uri
9
+ - else
10
+ .failure
11
+ %p= uri
@@ -0,0 +1,14 @@
1
+ !!!
2
+ %html
3
+ %head
4
+ %style * {font-family: 'Lucida Grande', Helvetica, sans-serif;padding:10px;margin:0px;text-align:center;} h2 {font-size:300px;}
5
+ %title Dashboard
6
+ %link{:rel => :stylesheet, :type => :'text/css', :href => '/style.css'}
7
+ %script(src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js")
8
+ :javascript
9
+ $(getUpdate);
10
+ function getUpdate() {
11
+ $("body").load("/");
12
+ setTimeout(getUpdate,10000);
13
+ }
14
+ %body= yield
@@ -0,0 +1,3 @@
1
+ - http://www.google.co.uk : Google
2
+ - http://www.yahoo.co.uk : Yahoo
3
+ - http://www.itv.com : ITV
@@ -0,0 +1,60 @@
1
+ module Eir
2
+ class Request
3
+
4
+ attr_reader :server_url
5
+ attr_accessor :uris
6
+
7
+ def initialize
8
+ path_to_yaml = find_yaml
9
+ @uris = validate_yaml path_to_yaml
10
+ @server_url = 'http://localhost:8700'
11
+ end
12
+
13
+ def find_yaml
14
+ if File.exist?("#{Dir.pwd}/uris.yaml")
15
+ uris_yaml_file = "#{Dir.pwd}/uris.yaml"
16
+ puts "Found local YAML file: #{uris_yaml_file}"
17
+ else
18
+ uris_yaml_file = "#{File.dirname(__FILE__)}/default_uris.yaml"
19
+ puts "No local YAML file found. Using default YAML file: #{uris_yaml_file}"
20
+ end
21
+ uris_yaml_file
22
+ end
23
+
24
+ def validate_yaml(path_to_yaml)
25
+ invalid_yaml_error = 'YAML structure incorrect. Please refer to the README.'
26
+ yaml = YAML.load_file path_to_yaml
27
+ raise invalid_yaml_error unless yaml.is_a? Array
28
+ yaml.each { |hash| raise invalid_yaml_error unless hash.is_a? Hash }
29
+ yaml
30
+ end
31
+
32
+ def get_http_response_code(uri)
33
+ begin
34
+ Timeout.timeout(5) do
35
+ request(uri).code
36
+ end
37
+ rescue
38
+ false
39
+ end
40
+ end
41
+
42
+ def go
43
+ responses = {}
44
+ @uris.each do |uri_name_hash|
45
+ uri_name_hash.each do |uri, name|
46
+ responses.merge!({ name => get_http_response_code(uri) })
47
+ end
48
+ end
49
+
50
+ responses
51
+ end
52
+
53
+ private
54
+
55
+ def request(uri)
56
+ RestClient.get uri
57
+ end
58
+
59
+ end
60
+ end
data/lib/eir/server.rb ADDED
@@ -0,0 +1,43 @@
1
+ module Eir
2
+ class Server
3
+
4
+ def initialize
5
+ @server_url = 'http://localhost:8700'
6
+ end
7
+
8
+ class FailedToStopSinatraError < StandardError
9
+ def message
10
+ 'Failed to stop the Sinatra Dashboard!'
11
+ end
12
+ end
13
+
14
+ class FailedToStartSinatraError < StandardError
15
+ def message
16
+ 'Failed to start the Sinatra Dashboard!'
17
+ end
18
+ end
19
+
20
+ def status
21
+ begin
22
+ RestClient.get("#{@server_url}/status").code
23
+ rescue Errno::ECONNREFUSED
24
+ false
25
+ end
26
+ end
27
+
28
+ def start
29
+ stop if File.exist? 'server.pid'
30
+ puts "Starting the server at #{@server_url}"
31
+ `bundle exec puma --config #{File.dirname(__FILE__)}/app/puma.rb`
32
+ Timeout.timeout(10, FailedToStartSinatraError) { sleep 1 until status == 200 }
33
+ end
34
+
35
+ def stop
36
+ pid = File.read('server.pid').to_i
37
+ puts "Destroying the server process ID: #{pid}"
38
+ `kill -9 #{pid}`
39
+ Timeout.timeout(10, FailedToStopSinatraError) { sleep 1 until status == false }
40
+ end
41
+
42
+ end
43
+ end
@@ -0,0 +1,3 @@
1
+ module Eir
2
+ VERSION = '0.0.1'
3
+ end
data/lib/eir.rb ADDED
@@ -0,0 +1,10 @@
1
+ require 'rest_client'
2
+ require 'yaml'
3
+ require 'sinatra'
4
+ require 'haml'
5
+ require 'puma'
6
+
7
+ require_relative 'eir/version'
8
+ require_relative 'eir/server'
9
+ require_relative 'eir/request'
10
+ require_relative 'eir/app/app'
data/spec/eir_spec.rb ADDED
@@ -0,0 +1,42 @@
1
+ require_relative 'spec_helper'
2
+
3
+ describe Eir do
4
+
5
+ it 'should look for custom YAML in the current directory' do
6
+ File.open('uris.yaml', 'w+') { |f| f.write('- http://www.google.co.uk : Google') }
7
+ Eir::Request.new.uris.should == [{ 'http://www.google.co.uk' => 'Google' }]
8
+ File.delete 'uris.yaml'
9
+ end
10
+
11
+ it 'should fall back to a list of default URIs if no local YAML file is present' do
12
+ Eir::Request.new.uris.should ==
13
+ [
14
+ { 'http://www.google.co.uk' => 'Google' },
15
+ { 'http://www.yahoo.co.uk' => 'Yahoo' },
16
+ { 'http://www.itv.com' => 'ITV' }
17
+ ]
18
+ end
19
+
20
+ it 'should make an HTTP request for each URI' do
21
+ @request = Eir::Request.new
22
+ @request.stub(:get_http_response_code).and_return(200)
23
+ responses = @request.go
24
+ responses.each { |uri, status_code| status_code.should == 200 }
25
+ end
26
+
27
+ it 'should return a hash of the URL alias and status code' do
28
+ @request = Eir::Request.new
29
+ @request.stub(:get_http_response_code).and_return(200)
30
+ responses = @request.go
31
+ responses.should == { 'Google' => 200, 'Yahoo' => 200, 'ITV' => 200 }
32
+ end
33
+
34
+ it 'should time out after 5 seconds for an unresponsive status call' do
35
+ @request = Eir::Request.new
36
+ @request.uris = [{ 'http://www.google.co.uk' => 'Google' }]
37
+ @request.stub(:request) { sleep 10 }
38
+ responses = @request.go
39
+ responses.should == { 'Google' => false }
40
+ end
41
+
42
+ end
@@ -0,0 +1,16 @@
1
+ require_relative 'spec_helper'
2
+
3
+ describe 'Sinatra Dashboard' do
4
+
5
+ include Rack::Test::Methods
6
+
7
+ def app
8
+ Sinatra::Application.new(App.new)
9
+ end
10
+
11
+ it 'should have a status endpoint' do
12
+ get '/status'
13
+ last_response.status.should == 200
14
+ end
15
+
16
+ end
@@ -0,0 +1,6 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ require 'eir'
3
+
4
+ require 'rspec'
5
+ require 'rack/test'
6
+ require 'sinatra'
metadata ADDED
@@ -0,0 +1,182 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: eir
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Ben Snape
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-06-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rest-client
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.6.7
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.6.7
27
+ - !ruby/object:Gem::Dependency
28
+ name: sinatra
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 1.4.5
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 1.4.5
41
+ - !ruby/object:Gem::Dependency
42
+ name: haml
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '4'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '4'
55
+ - !ruby/object:Gem::Dependency
56
+ name: puma
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 2.8.2
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 2.8.2
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.5'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.5'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '10'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '10'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '2'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '2'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rack-test
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 0.6.2
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 0.6.2
125
+ description: "[\"Easily\", \"monitor\", \"the\", \"health\", \"of\", \"arbitrary\",
126
+ \"URI's\", \"defined\", \"in\", \"YAML\", \"config\"]"
127
+ email:
128
+ - bsnape@gmail.com
129
+ executables:
130
+ - eir
131
+ extensions: []
132
+ extra_rdoc_files: []
133
+ files:
134
+ - ".gitignore"
135
+ - Gemfile
136
+ - LICENSE.txt
137
+ - README.md
138
+ - Rakefile
139
+ - bin/eir
140
+ - eir.gemspec
141
+ - lib/eir.rb
142
+ - lib/eir/app/app.rb
143
+ - lib/eir/app/config.ru
144
+ - lib/eir/app/public/style.css
145
+ - lib/eir/app/puma.rb
146
+ - lib/eir/app/views/dashboard.haml
147
+ - lib/eir/app/views/layout.haml
148
+ - lib/eir/default_uris.yaml
149
+ - lib/eir/request.rb
150
+ - lib/eir/server.rb
151
+ - lib/eir/version.rb
152
+ - spec/eir_spec.rb
153
+ - spec/sinatra_dashboard_spec.rb
154
+ - spec/spec_helper.rb
155
+ homepage: http://www.bensnape.com
156
+ licenses:
157
+ - MIT
158
+ metadata: {}
159
+ post_install_message:
160
+ rdoc_options: []
161
+ require_paths:
162
+ - lib
163
+ required_ruby_version: !ruby/object:Gem::Requirement
164
+ requirements:
165
+ - - ">="
166
+ - !ruby/object:Gem::Version
167
+ version: '0'
168
+ required_rubygems_version: !ruby/object:Gem::Requirement
169
+ requirements:
170
+ - - ">="
171
+ - !ruby/object:Gem::Version
172
+ version: '0'
173
+ requirements: []
174
+ rubyforge_project:
175
+ rubygems_version: 2.2.0
176
+ signing_key:
177
+ specification_version: 4
178
+ summary: "[\"Monitor\", \"the\", \"health\", \"of\", \"URI's\"]"
179
+ test_files:
180
+ - spec/eir_spec.rb
181
+ - spec/sinatra_dashboard_spec.rb
182
+ - spec/spec_helper.rb