gesund 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- gesund (0.0.1)
4
+ gesund (0.0.2)
5
5
  rack
6
6
  thor
7
7
 
data/README.md CHANGED
@@ -1,6 +1,10 @@
1
1
  # Gesund
2
2
 
3
- TODO: Write a gem description
3
+ To have healthy servers, it is important to have an automated check that can tell you if something is wrong. Gesund for the rescue!
4
+
5
+ Gesund is a simple health checker that provides ready classes to do various checks against running services, filesystem state and more. Currently the ```gesund``` gem itself only has a small number of file system checks, and several additional gems provide checks for redis, mysql, mongodb and http.
6
+
7
+ This project is early alpha - you are welcome to help out and make it shine.
4
8
 
5
9
  ## Installation
6
10
 
@@ -18,7 +22,38 @@ Or install it yourself as:
18
22
 
19
23
  ## Usage
20
24
 
21
- TODO: Write usage instructions here
25
+ First create a ```Gesundfile``` that will list the required checks, for example:
26
+
27
+ require "gesund/redis"
28
+ require "gesund/mysql"
29
+ require "gesund/mongo"
30
+ require "gesund/http"
31
+
32
+ check :file, "/tmp/testfile"
33
+ check :link, "/tmp/testlink"
34
+ check :directory, "/tmp"
35
+ check :redis_connection
36
+ check :mysql_connection
37
+ check :mongo_connection
38
+ check :http_status, url: "http://www.google.com/"
39
+
40
+ # vi: set ft=ruby ai ts=2 sw=2 et sts=2
41
+
42
+ Then you can either run it on the command line, or start a Rack server that will answer to requests with the results of the required checks.
43
+
44
+ Running on the command line -
45
+
46
+ $ gesund
47
+ 200: File /tmp/testfile is a file
48
+ 200: Symbolic link /tmp/testlink is a symlink
49
+ 200: Directory /tmp is a directory
50
+ 200: Redis PING = PONG
51
+ 500: Mysql::Error: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
52
+ 200: Mongo PING = OK
53
+ 500: HTTP GET request to http://www.google.com/ status is 302
54
+
55
+ RESULT: Health check failed!
56
+
22
57
 
23
58
  ## Contributing
24
59
 
data/lib/gesund/cli.rb CHANGED
@@ -3,19 +3,21 @@ require "thor"
3
3
  module Gesund
4
4
  class CLI < ::Thor
5
5
  include ::Thor::Actions
6
+ class_option :gesundfile, :banner => '<gesundfile>', :type => :string, :default => "Gesundfile", :aliases => [:"-c"]
6
7
 
7
8
  default_task :check
8
9
  desc "check", "Executes the list of checks found in Gesundfile"
9
- option :gesundfile, :type => :string, :default => "Gesundfile"
10
10
  def check
11
- ENV['GESUNDFILE'] = File.expand_path(options[:gesundfile]) if options[:gesundfile]
12
- checks = Gesund::Dsl.evaluate(ENV['GESUNDFILE'])
13
- Gesund::Output::Text.new Gesund::CheckRunner.run(checks)
11
+ gesundfile = File.expand_path(options[:gesundfile]) if options[:gesundfile]
12
+ checks = Gesund::Dsl.evaluate(gesundfile)
13
+ Gesund::Output::Text.new(checks)
14
14
  end
15
15
 
16
16
  desc "http", "Starts a web server that answers to requests with results of checks from Gesundfile"
17
17
  def http
18
- Gesund::RackApplication.start
18
+ gesundfile = File.expand_path(options[:gesundfile]) if options[:gesundfile]
19
+ checks = Gesund::Dsl.evaluate(gesundfile)
20
+ Gesund::Output::Rack.start(checks)
19
21
  end
20
22
 
21
23
  end
data/lib/gesund/dsl.rb CHANGED
@@ -7,7 +7,12 @@ class Gesund::Dsl
7
7
 
8
8
  def eval_gesundfile(gesundfile)
9
9
  @checks = []
10
- contents = File.read(gesundfile.to_s)
10
+ begin
11
+ contents = File.read(gesundfile.to_s)
12
+ rescue => e
13
+ puts "ERROR reading Gesundfile: #{e.message}"
14
+ exit 1
15
+ end
11
16
  instance_eval(contents, gesundfile.to_s, 1)
12
17
  return @checks
13
18
  end
@@ -18,7 +23,8 @@ class Gesund::Dsl
18
23
  check_class = Gesund::Checks.const_get(camel_name)
19
24
  rescue NameError => e
20
25
  e.backtrace.join =~ /Gesundfile:(\d+)/
21
- puts "line number: #{$1}"
26
+ print "ERROR Gesundfile:#{$1}: "
27
+ puts "#{e.message}"
22
28
  exit 1
23
29
  end
24
30
  raise Gesund::Errors::CheckNotFound unless check_class
@@ -0,0 +1,26 @@
1
+ require "rack"
2
+
3
+ module Gesund::Output
4
+ class Rack
5
+ def self.start(checks)
6
+ app = self.new
7
+ app.checks = checks
8
+ ::Rack::Server.start app: app
9
+ end
10
+
11
+ attr_accessor :checks
12
+
13
+ def call(env)
14
+ results = Gesund::CheckRunner.run(self.checks)
15
+ body = []
16
+ failflag = false
17
+ results.each do |check|
18
+ failflag = true if check.first.to_i != 200
19
+ body << "#{check.first}: #{check.last.join}\n"
20
+ end
21
+ status = failflag ? 500 : 200
22
+ header = { "Content-Type" => "text/plain" }
23
+ [status, header, body]
24
+ end
25
+ end
26
+ end
@@ -1,8 +1,9 @@
1
1
  module Gesund::Output
2
2
  class Text
3
3
  def initialize(checks)
4
+ results = Gesund::CheckRunner.run(checks)
4
5
  failflag = false
5
- checks.each do |check|
6
+ results.each do |check|
6
7
  failflag = true if check.first.to_i != 200
7
8
  puts "#{check.first}: #{check.last.join}"
8
9
  end
data/lib/gesund/output.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require "gesund/output/text"
2
+ require "gesund/output/rack"
2
3
 
3
4
  module Gesund::Output
4
5
  end
@@ -1,3 +1,3 @@
1
1
  module Gesund
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/lib/gesund.rb CHANGED
@@ -2,7 +2,6 @@ require "gesund/version"
2
2
  require "gesund/errors"
3
3
  require "gesund/check"
4
4
  require "gesund/checks"
5
- require "gesund/rack_application"
6
5
  require "gesund/dsl"
7
6
  require "gesund/output"
8
7
  require "gesund/check_runner"
@@ -1,3 +1,3 @@
1
1
  describe Gesund::VERSION do
2
- it { should == "0.0.1" }
2
+ it { should == "0.0.2" }
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gesund
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-05-04 00:00:00.000000000 Z
12
+ date: 2013-05-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -120,9 +120,8 @@ files:
120
120
  - lib/gesund/dsl.rb
121
121
  - lib/gesund/errors.rb
122
122
  - lib/gesund/output.rb
123
- - lib/gesund/output/test.rb
123
+ - lib/gesund/output/rack.rb
124
124
  - lib/gesund/output/text.rb
125
- - lib/gesund/rack_application.rb
126
125
  - lib/gesund/version.rb
127
126
  - spec/lib/gesund/check_spec.rb
128
127
  - spec/lib/gesund/checks/directory_spec.rb
@@ -145,7 +144,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
145
144
  version: '0'
146
145
  segments:
147
146
  - 0
148
- hash: 36615820617307734
147
+ hash: -1461887031316332670
149
148
  required_rubygems_version: !ruby/object:Gem::Requirement
150
149
  none: false
151
150
  requirements:
@@ -154,7 +153,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
154
153
  version: '0'
155
154
  segments:
156
155
  - 0
157
- hash: 36615820617307734
156
+ hash: -1461887031316332670
158
157
  requirements: []
159
158
  rubyforge_project:
160
159
  rubygems_version: 1.8.25
@@ -1,8 +0,0 @@
1
- class Gesund::Output::Text
2
- def initialize(checks)
3
- checks.each do |check|
4
- print check.first == 200 ? "- " : "x "
5
- puts check.last
6
- end
7
- end
8
- end
@@ -1,14 +0,0 @@
1
- require "rack"
2
-
3
- class Gesund::RackApplication
4
-
5
- def self.start
6
- Rack::Server.start app: self.new
7
- end
8
-
9
- def call(env)
10
- # TODO: implement checks run
11
- [500, {"Content-Type" => "text/plain"}, ["TODO: not implemented yet"]]
12
- end
13
-
14
- end