gogetit 0.12.1 → 0.12.2
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 +4 -4
- data/lib/gogetit/util.rb +32 -6
- data/lib/gogetit/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 61751267d26d38a3483ce27309262a216614f6a1
|
|
4
|
+
data.tar.gz: 4ca2a6149614790a782b225786f16f8707f87a86
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 39493d947b7aa4464abdbcf49770911662b349461a151a2c9584d1f768c929cf17f1c03818b5ba86ee0797265affe056680693f8a156f3b7474cc547ee1f59fa
|
|
7
|
+
data.tar.gz: b90078303ea89a51598197c789b9b6ba8ac8d87da3368c9e0df19abaf7ac5fd724a9461e59375b2b7ad1027acdf06a6ed07bd779115208317ea700ee7c53c6e0
|
data/lib/gogetit/util.rb
CHANGED
|
@@ -3,6 +3,8 @@ require 'net/ssh'
|
|
|
3
3
|
require 'net/http'
|
|
4
4
|
require 'active_support/core_ext/hash'
|
|
5
5
|
require 'json'
|
|
6
|
+
require 'socket'
|
|
7
|
+
require 'timeout'
|
|
6
8
|
|
|
7
9
|
module Gogetit
|
|
8
10
|
module Util
|
|
@@ -11,16 +13,40 @@ module Gogetit
|
|
|
11
13
|
system(cmd)
|
|
12
14
|
end
|
|
13
15
|
|
|
16
|
+
def is_port_open?(ip, port)
|
|
17
|
+
begin
|
|
18
|
+
Timeout::timeout(1) do
|
|
19
|
+
begin
|
|
20
|
+
s = TCPSocket.new(ip, port)
|
|
21
|
+
s.close
|
|
22
|
+
return true
|
|
23
|
+
rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH, SocketError
|
|
24
|
+
return false
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
rescue Timeout::Error
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
return false
|
|
31
|
+
end
|
|
32
|
+
|
|
14
33
|
def get_http_content(url)
|
|
15
34
|
logger.info("Calling <#{__method__.to_s}> to get #{url}")
|
|
35
|
+
|
|
16
36
|
uri = URI.parse(url)
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
res.
|
|
37
|
+
|
|
38
|
+
if is_port_open?(uri.host, uri.port)
|
|
39
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
|
40
|
+
res = http.request_post(uri.path, nil)
|
|
41
|
+
if res.code == "200"
|
|
42
|
+
res.body
|
|
43
|
+
else
|
|
44
|
+
logger.info("Unable to reach the content of #{url}.")
|
|
45
|
+
false
|
|
46
|
+
end
|
|
21
47
|
else
|
|
22
|
-
logger.info("Unable to reach #{
|
|
23
|
-
|
|
48
|
+
logger.info("Unable to reach the server: #{uri.host} or port: #{uri.port}.")
|
|
49
|
+
false
|
|
24
50
|
end
|
|
25
51
|
end
|
|
26
52
|
|
data/lib/gogetit/version.rb
CHANGED