the-gipper 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/gipper.rb +44 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 987914a4c031ecad18347557b75511032c20b9d0
|
4
|
+
data.tar.gz: 5bf4cf1365c7c6e9616af75f630dd1fe3c34adf5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c3853f79eae5fa2cf881cefc1520198f93ab5823a830e1ab2475567f000cafc99215804b4e42e0f599a736d1c268a33a5d830bfcd16468ce4a9c467e2d7f4365
|
7
|
+
data.tar.gz: 3163c654b3deb47df8b00dda40ea88e56b61168b5873e45bce1e88b32256314ef103bd5293dc5b220120e1d572312c460cff7b0e46da3b5782e45d6484285b3f
|
data/lib/gipper.rb
CHANGED
@@ -1,4 +1,8 @@
|
|
1
1
|
require 'logger'
|
2
|
+
require 'socket'
|
3
|
+
require 'uri'
|
4
|
+
require 'timeout'
|
5
|
+
require './test/models/counter'
|
2
6
|
|
3
7
|
class Gipper
|
4
8
|
|
@@ -34,6 +38,23 @@ class Gipper
|
|
34
38
|
g.env
|
35
39
|
end
|
36
40
|
|
41
|
+
def verify_service *fields, &block
|
42
|
+
options = fields[fields.size].is_a?(Hash) ? fields.delete(fields.size) : nil
|
43
|
+
|
44
|
+
fields.each do |field|
|
45
|
+
field = field.to_s
|
46
|
+
uri = URI.parse( check_field(field) )
|
47
|
+
|
48
|
+
unless is_port_open?( uri.host, uri.port )
|
49
|
+
@errors[field] = "isn't running" #options[:fail_message] ? options[:fail_message] : "isn't running"
|
50
|
+
|
51
|
+
if block
|
52
|
+
block.call
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
37
58
|
def verify *fields
|
38
59
|
options = fields[fields.size].is_a?(Hash) ? fields.delete(fields.size) : nil
|
39
60
|
|
@@ -41,6 +62,10 @@ class Gipper
|
|
41
62
|
unless check_field field
|
42
63
|
@errors[field] = "not set"
|
43
64
|
end
|
65
|
+
|
66
|
+
#if options.respond_to? :probe && options[:probe]
|
67
|
+
# @errors[field] = "does not respond on port blah"
|
68
|
+
#end
|
44
69
|
end
|
45
70
|
end
|
46
71
|
|
@@ -58,6 +83,25 @@ class Gipper
|
|
58
83
|
@env[field]
|
59
84
|
end
|
60
85
|
|
86
|
+
# Thanks to Chris Rice!
|
87
|
+
# http://stackoverflow.com/questions/517219/ruby-see-if-a-port-is-open
|
88
|
+
def is_port_open?(ip, port, timeout=1)
|
89
|
+
begin
|
90
|
+
Timeout::timeout(timeout) do
|
91
|
+
begin
|
92
|
+
s = TCPSocket.new(ip, port)
|
93
|
+
s.close
|
94
|
+
return true
|
95
|
+
rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH
|
96
|
+
return false
|
97
|
+
end
|
98
|
+
end
|
99
|
+
rescue Timeout::Error
|
100
|
+
end
|
101
|
+
|
102
|
+
return false
|
103
|
+
end
|
104
|
+
|
61
105
|
def reset
|
62
106
|
@env = ENV.to_h
|
63
107
|
@errors = {}
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: the-gipper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Trevor Grayson
|
@@ -37,7 +37,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
37
37
|
version: '0'
|
38
38
|
requirements: []
|
39
39
|
rubyforge_project:
|
40
|
-
rubygems_version: 2.
|
40
|
+
rubygems_version: 2.2.2
|
41
41
|
signing_key:
|
42
42
|
specification_version: 4
|
43
43
|
summary: Configuration Verification
|