net-tnsping 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +11 -0
- data/MANIFEST +8 -11
- data/README +50 -49
- data/Rakefile +22 -0
- data/lib/net/tnsping.rb +27 -21
- data/test/tc_tns_ping.rb +13 -22
- metadata +7 -3
data/CHANGES
CHANGED
@@ -1,3 +1,14 @@
|
|
1
|
+
== 1.2.0 - 20-Jul-2007
|
2
|
+
* Changed the TNSPing class name to Ping::TNS in order to follow the naming
|
3
|
+
convention in net-ping. The TNSPingError class was likewise changed to
|
4
|
+
Ping::TNS::Error. However, I've setup class aliases for the sake of backwards
|
5
|
+
compatability. However, new programs should use the new class names.
|
6
|
+
* Fixed an initialization warning.
|
7
|
+
* Added a Rakefile with tasks for testing and installation. This also means
|
8
|
+
the install.rb file was removed, since installation is now handled by the
|
9
|
+
Rakefile.
|
10
|
+
* Some updates to the test suite.
|
11
|
+
|
1
12
|
== 1.1.0 - 16-Jun-2005
|
2
13
|
* The prerequisite "net-pingsimple" was changed to "net-ping", because
|
3
14
|
that project name changed.
|
data/MANIFEST
CHANGED
@@ -1,11 +1,8 @@
|
|
1
|
-
CHANGES
|
2
|
-
MANIFEST
|
3
|
-
README
|
4
|
-
|
5
|
-
net-tnsping.gemspec
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
lib/net/tnsping.rb
|
10
|
-
|
11
|
-
test/tc_tns_ping.rb
|
1
|
+
* CHANGES
|
2
|
+
* MANIFEST
|
3
|
+
* README
|
4
|
+
* Rakefile
|
5
|
+
* net-tnsping.gemspec
|
6
|
+
* examples/test_tnsping.rb
|
7
|
+
* lib/net/tnsping.rb
|
8
|
+
* test/tc_tns_ping.rb
|
data/README
CHANGED
@@ -10,23 +10,24 @@
|
|
10
10
|
== Installation
|
11
11
|
|
12
12
|
=== Manual Installation
|
13
|
-
|
14
|
-
|
13
|
+
rake test (optional)
|
14
|
+
rake install
|
15
15
|
|
16
16
|
=== Gem Installation
|
17
|
+
rake test (optional)
|
17
18
|
ruby net-tnsping.gemspec
|
18
19
|
gem install net-tnsping-<version>.gem
|
19
20
|
|
20
21
|
=== Installation Note
|
21
22
|
You will have to manually tweak one instance variable (@db) in the
|
22
|
-
test suite in order to get all tests to pass.
|
23
|
+
test suite in order to get all tests to pass. Set it to a known database
|
23
24
|
name.
|
24
25
|
|
25
26
|
== Synopsis
|
26
27
|
require "net/tnsping"
|
27
28
|
include Net
|
28
29
|
|
29
|
-
t =
|
30
|
+
t = Ping::TNS.new("my_db")
|
30
31
|
|
31
32
|
if t.ping?
|
32
33
|
puts "Database appears to be up and running"
|
@@ -39,52 +40,52 @@ VERSION
|
|
39
40
|
The version number of this package, returned as a String.
|
40
41
|
|
41
42
|
== Class Methods
|
42
|
-
|
43
|
-
Creates and returns a new
|
44
|
-
found in the tnsnames.ora file, then a
|
43
|
+
Ping::TNS.new(db, driver="OCI8", host=nil, port=1521, timeout=5)
|
44
|
+
Creates and returns a new Ping::TNS object. If the db specified cannot be
|
45
|
+
found in the tnsnames.ora file, then a Ping::TNS::Error is raised.
|
45
46
|
|
46
47
|
== Instance Methods
|
47
|
-
|
48
|
-
Returns the name of the database that the
|
48
|
+
Ping::TNS#db
|
49
|
+
Returns the name of the database that the Ping::TNS#ping_database? method
|
49
50
|
will attempt to connect to.
|
50
51
|
|
51
|
-
|
52
|
-
Sets the name of the database that the
|
52
|
+
Ping::TNS#db=(database)
|
53
|
+
Sets the name of the database that the Ping::TNS#ping_database? method
|
53
54
|
will attempt to connect to.
|
54
55
|
|
55
|
-
|
56
|
-
Returns the name of the driver used by the
|
56
|
+
Ping::TNS#driver
|
57
|
+
Returns the name of the driver used by the Ping::TNS#ping_database? method.
|
57
58
|
The default is OCI8.
|
58
59
|
|
59
|
-
|
60
|
-
Sets the name of the driver used by the
|
60
|
+
Ping::TNS#driver=(driver)
|
61
|
+
Sets the name of the driver used by the Ping::TNS#ping_database? method.
|
61
62
|
|
62
|
-
|
63
|
-
Returns the dsn string that is used by
|
63
|
+
Ping::TNS#dsn
|
64
|
+
Returns the dsn string that is used by Ping::TNS#ping_database?.
|
64
65
|
|
65
|
-
|
66
|
-
Sets the dsn string that is used by
|
66
|
+
Ping::TNS#dsn=(string)
|
67
|
+
Sets the dsn string that is used by Ping::TNS#ping_database?. It should
|
67
68
|
be in the form "dbi:driver:database".
|
68
69
|
|
69
|
-
|
70
|
-
Returns the host that the
|
71
|
-
be nil, in which case, the
|
70
|
+
Ping::TNS#host
|
71
|
+
Returns the host that the Ping::TNS#ping_listener? call will use. This may
|
72
|
+
be nil, in which case, the Ping::TNS#hosts method will list which hosts it
|
72
73
|
will attempt to ping.
|
73
74
|
|
74
|
-
|
75
|
-
Sets the host that the
|
75
|
+
Ping::TNS#host=(host)
|
76
|
+
Sets the host that the Ping::TNS#ping_listener? call will use. If this is
|
76
77
|
set, then a ping will only be attempted against this host, irregardless
|
77
78
|
of what is in the tnsnames.ora file.
|
78
79
|
|
79
|
-
|
80
|
+
Ping::TNS#oracle_home
|
80
81
|
Returns the path to the oracle home directory. The default is either
|
81
82
|
ENV["ORACLE_HOME"] or ENV["ORA_HOME"].
|
82
83
|
|
83
|
-
|
84
|
+
Ping::TNS#oracle_home=(path)
|
84
85
|
Sets the path to the oracle home directory.
|
85
86
|
|
86
|
-
|
87
|
-
|
87
|
+
Ping::TNS#ping?
|
88
|
+
Ping::TNS#ping_listener?
|
88
89
|
Performs a TCP ping on the listener. The host and port are determined from
|
89
90
|
your tnsnames.ora file. If more than one host and/or port are found in the
|
90
91
|
tnsnames.ora file, then each will be tried. So long as at least one of
|
@@ -93,7 +94,7 @@ TNSPing#ping_listener?
|
|
93
94
|
If you specify a host and port in the constructor, then the attempt will
|
94
95
|
only be made against that host on the given port.
|
95
96
|
|
96
|
-
|
97
|
+
Ping::TNS#ping_database?(dsn=nil, timeout=nil, user=nil, passwd=nil)
|
97
98
|
Attempts to make a connection using a bogus login and password via the DBI
|
98
99
|
class. If an ORA-01017 Oracle error is returned, that means the database
|
99
100
|
is up and running and true is returned.
|
@@ -103,45 +104,45 @@ TNSPing#ping_database?(dsn=nil, timeout=nil, user=nil, passwd=nil)
|
|
103
104
|
should not pass any arguments to this method.
|
104
105
|
|
105
106
|
In the event that this method fails, false is returned and the error can
|
106
|
-
be viewed via
|
107
|
+
be viewed via Ping::TNS#exception.
|
107
108
|
|
108
|
-
|
109
|
-
A shortcut method that merely calls
|
109
|
+
Ping::TNS#ping_all?
|
110
|
+
A shortcut method that merely calls Ping::TNS#ping? and Ping::TNS#ping_database?
|
110
111
|
in succession. Returns true if both succeed, false otherwise.
|
111
112
|
|
112
|
-
|
113
|
-
Returns the port that the
|
114
|
-
may be nil, in which case the
|
113
|
+
Ping::TNS#port
|
114
|
+
Returns the port that the Ping::TNS#ping_listener? will ping against. This
|
115
|
+
may be nil, in which case the Ping::TNS#ports method will list which ports
|
115
116
|
it will attempt to ping against.
|
116
117
|
|
117
|
-
|
118
|
-
Sets the port that the
|
118
|
+
Ping::TNS#port=(num)
|
119
|
+
Sets the port that the Ping::TNS#ping_listener? method will use. If this is
|
119
120
|
set, then a ping will only be attempted on this port, irregardless of what
|
120
121
|
is in the tnsnames.ora file.
|
121
122
|
|
122
|
-
|
123
|
+
Ping::TNS#timeout
|
123
124
|
Returns the timeout value used by all internal ping methods.
|
124
125
|
|
125
|
-
|
126
|
+
Ping::TNS#timeout=(seconds)
|
126
127
|
Sets the timeout used by all internal ping methods.
|
127
128
|
|
128
|
-
|
129
|
+
Ping::TNS#tns_admin
|
129
130
|
Returns the path to the tns admin directory. The default is
|
130
131
|
ENV["TNS_ADMIN"].
|
131
132
|
|
132
|
-
|
133
|
+
Ping::TNS#tns_admin=(path)
|
133
134
|
Sets the path to the tns admin directory.
|
134
135
|
|
135
|
-
|
136
|
+
Ping::TNS#tns_file
|
136
137
|
Returns the full path to the tnsnames.ora file.
|
137
138
|
|
138
|
-
|
139
|
+
Ping::TNS#tns_file=(path)
|
139
140
|
Sets the path to the tnsnames.ora file.
|
140
141
|
|
141
142
|
== Notes
|
142
|
-
The
|
143
|
+
The Ping::TNS class is a subclass of Ping::TCP.
|
143
144
|
|
144
|
-
This is NOT a wrapper for the tnsping utility.
|
145
|
+
This is NOT a wrapper for the tnsping utility. It performs two actions.
|
145
146
|
First, it attempts to ping the database using the appropriate port via TCP.
|
146
147
|
Then, it attempts to make a connection using a bogus name and password,
|
147
148
|
looking for error ORA-1017.
|
@@ -150,10 +151,10 @@ TNSPing#tns_file=(path)
|
|
150
151
|
Q: "Why didn't you just wrap a backticked tnsping call?"
|
151
152
|
|
152
153
|
A: First, because the output is unpredictable. On two different platforms I
|
153
|
-
received two different output streams for the same datasource.
|
154
|
+
received two different output streams for the same datasource. Who knows
|
154
155
|
what it's like on other platforms?
|
155
156
|
|
156
|
-
Second, tnsping *only* tells you if the listener is up.
|
157
|
+
Second, tnsping *only* tells you if the listener is up. It doesn't
|
157
158
|
actually test that the datasource is up and running.
|
158
159
|
|
159
160
|
Q: "Why didn't you write an extension using the tnsping source?"
|
@@ -172,7 +173,7 @@ TNSPing#tns_file=(path)
|
|
172
173
|
with some questions I had.
|
173
174
|
|
174
175
|
== Copyright
|
175
|
-
(C) 2003-
|
176
|
+
(C) 2003-2007 Daniel J. Berger
|
176
177
|
All rights reserved.
|
177
178
|
|
178
179
|
== Warranty
|
@@ -185,5 +186,5 @@ TNSPing#tns_file=(path)
|
|
185
186
|
|
186
187
|
== Author
|
187
188
|
Daniel J. Berger
|
188
|
-
djberg96 at
|
189
|
+
djberg96 at nospam at gmail dot com
|
189
190
|
imperator on IRC (irc.freenode.net)
|
data/Rakefile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/testtask'
|
3
|
+
|
4
|
+
desc "Install the net-tnsping package (non-gem)"
|
5
|
+
task :install do
|
6
|
+
dest = File.join(Config::CONFIG['sitelibdir'], 'net')
|
7
|
+
Dir.mkdir(dest) unless File.exists? dest
|
8
|
+
cp 'lib/net/tnsping.rb', dest, :verbose => true
|
9
|
+
end
|
10
|
+
|
11
|
+
desc "Install the net-tnsping package as a gem"
|
12
|
+
task :install_gem do
|
13
|
+
ruby 'net-tnsping.gemspec'
|
14
|
+
file = Dir["*.gem"].first
|
15
|
+
sh "gem install #{file}"
|
16
|
+
end
|
17
|
+
|
18
|
+
Rake::TestTask.new do |t|
|
19
|
+
t.libs << 'lib'
|
20
|
+
t.warning = true
|
21
|
+
t.test_files = FileList['test/tc*']
|
22
|
+
end
|
data/lib/net/tnsping.rb
CHANGED
@@ -2,21 +2,22 @@ require "dbi"
|
|
2
2
|
require "net/ping"
|
3
3
|
|
4
4
|
module Net
|
5
|
-
class
|
6
|
-
|
5
|
+
class Ping::TNS < Ping::TCP
|
6
|
+
class Error < StandardError; end
|
7
7
|
|
8
|
-
VERSION =
|
8
|
+
VERSION = '1.2.0'
|
9
9
|
|
10
10
|
attr_accessor :db, :dsn, :tns_file, :host, :tns_admin
|
11
|
-
attr_accessor :
|
11
|
+
attr_accessor :ora_home, :driver, :timeout
|
12
12
|
attr_reader :hosts, :ports, :port
|
13
13
|
|
14
|
-
# Creates and returns a new
|
15
|
-
# be found in the tnsnames.ora file, then a
|
14
|
+
# Creates and returns a new Ping::TNS object. If the db specified cannot
|
15
|
+
# be found in the tnsnames.ora file, then a Ping::TNS::Error is raised.
|
16
16
|
#
|
17
17
|
def initialize(db, driver="OCI8", host=nil, port=1521, timeout=5)
|
18
18
|
@db = db
|
19
19
|
@dsn = "dbi:#{driver}:" << db
|
20
|
+
@host = host
|
20
21
|
@timeout = timeout
|
21
22
|
@port = port
|
22
23
|
@tns_admin = tns_admin
|
@@ -24,15 +25,15 @@ module Net
|
|
24
25
|
@hosts = [] # for each dsn. Try them in order.
|
25
26
|
@sid = nil
|
26
27
|
|
27
|
-
@tns_admin
|
28
|
-
@
|
28
|
+
@tns_admin = ENV['TNS_ADMIN']
|
29
|
+
@ora_home = ENV['ORACLE_HOME'] || ENV['ORA_HOME']
|
29
30
|
|
30
31
|
if @tns_admin
|
31
|
-
@tns_file = @tns_admin
|
32
|
-
elsif @
|
33
|
-
@tns_file = @
|
32
|
+
@tns_file = File.join(@tns_admin, 'tnsnames.ora')
|
33
|
+
elsif @ora_home
|
34
|
+
@tns_file = File.join(@ora_home, 'network', 'admin', 'tnsnames.ora')
|
34
35
|
else
|
35
|
-
@tns_file = ENV["HOME"] +
|
36
|
+
@tns_file = File.join(ENV["HOME"] + 'tnsnames.ora')
|
36
37
|
end
|
37
38
|
|
38
39
|
yield self if block_given?
|
@@ -40,7 +41,7 @@ module Net
|
|
40
41
|
# If the host is not specified, look for it in the tnsnames.or file
|
41
42
|
if host.nil?
|
42
43
|
err_msg = "tnsnames.ora file could not be found"
|
43
|
-
raise
|
44
|
+
raise Error, err_msg unless File.exists?(@tns_file)
|
44
45
|
parse_tns_file
|
45
46
|
else
|
46
47
|
@hosts.push(host)
|
@@ -48,7 +49,7 @@ module Net
|
|
48
49
|
end
|
49
50
|
end
|
50
51
|
|
51
|
-
# Sets the port that the
|
52
|
+
# Sets the port that the Ping::TNS#ping_listener? method will use. If
|
52
53
|
# this is set, then a ping will only be attempted on this port,
|
53
54
|
# regardless of what is in the tnsnames.ora file.
|
54
55
|
#
|
@@ -69,7 +70,7 @@ module Net
|
|
69
70
|
#
|
70
71
|
def ping?
|
71
72
|
if @hosts.empty?
|
72
|
-
raise
|
73
|
+
raise Error, "No hosts found"
|
73
74
|
end
|
74
75
|
|
75
76
|
# Use 1521 if no ports were found in the tnsnames.ora file.
|
@@ -100,16 +101,16 @@ module Net
|
|
100
101
|
# passed to the constructor (or have a default otherwise set). You
|
101
102
|
# generally should not pass any arguments to this method.
|
102
103
|
# In the event that this method fails, false is returned and the error
|
103
|
-
# can be viewed via
|
104
|
+
# can be viewed via Ping::TNS#exception.
|
104
105
|
#--
|
105
|
-
# I have intentionally set the user and password to something
|
106
|
+
# I have intentionally set the user and password to something random in
|
106
107
|
# order to avoid the possibility of accidentally guessing them. In
|
107
108
|
# case of cosmic coincidence, set them yourself.
|
108
109
|
#
|
109
|
-
def ping_database?(dsn=@dsn, timeout=@timeout, user=@sid, passwd=
|
110
|
+
def ping_database?(dsn=@dsn, timeout=@timeout, user=@sid, passwd=Time.now.to_s)
|
110
111
|
re = /ORA-01017/
|
111
112
|
dbh = nil
|
112
|
-
user ||=
|
113
|
+
user ||= Time.now.to_s
|
113
114
|
rv = false
|
114
115
|
begin
|
115
116
|
Timeout.timeout(timeout){
|
@@ -180,7 +181,7 @@ module Net
|
|
180
181
|
}
|
181
182
|
|
182
183
|
unless found
|
183
|
-
raise
|
184
|
+
raise Error, "unable to find '#{db}' in #{file}"
|
184
185
|
end
|
185
186
|
|
186
187
|
# Break each 'key = value' line into its parts
|
@@ -200,6 +201,11 @@ module Net
|
|
200
201
|
}
|
201
202
|
end
|
202
203
|
|
203
|
-
alias
|
204
|
+
alias ping_listener? ping?
|
205
|
+
alias oracle_home ora_home
|
206
|
+
alias oracle_home= ora_home=
|
204
207
|
end
|
208
|
+
|
209
|
+
TNSPing = Ping::TNS # Alias for backwards compatability
|
210
|
+
TNSPingError = Ping::TNS::Error # Alias for backwards compatability
|
205
211
|
end
|
data/test/tc_tns_ping.rb
CHANGED
@@ -1,31 +1,22 @@
|
|
1
|
-
|
1
|
+
########################################################################
|
2
2
|
# tc_tns_ping.rb
|
3
3
|
#
|
4
|
-
# Test suite for the tns-ping package.
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
if base == "test" || base =~ /net-tnsping.*/
|
9
|
-
Dir.chdir("..") if base == "test"
|
10
|
-
$LOAD_PATH.unshift(Dir.pwd)
|
11
|
-
$LOAD_PATH.unshift(Dir.pwd + "/lib")
|
12
|
-
end
|
13
|
-
|
4
|
+
# Test suite for the tns-ping package. This should be run via the
|
5
|
+
# 'rake test' Rake task.
|
6
|
+
########################################################################
|
14
7
|
require "test/unit"
|
15
8
|
require "net/tnsping"
|
16
9
|
include Net
|
17
10
|
|
18
|
-
|
19
|
-
# You'll need to change the db and host if you want to run these tests.
|
20
|
-
|
21
|
-
class TC_TNSPing < Test::Unit::TestCase
|
11
|
+
class TC_TNS_Ping < Test::Unit::TestCase
|
22
12
|
def setup
|
23
|
-
@db =
|
24
|
-
@tp =
|
13
|
+
@db = 'changme' # Change to a valid host in your network
|
14
|
+
@tp = Ping::TNS.new(@db)
|
25
15
|
end
|
26
16
|
|
27
17
|
def test_version
|
28
|
-
assert_equal("1.
|
18
|
+
assert_equal("1.2.0", Ping::TNS::VERSION)
|
19
|
+
assert_equal("1.2.0", TNSPing::VERSION) # Testing the alias really
|
29
20
|
end
|
30
21
|
|
31
22
|
def test_db
|
@@ -99,14 +90,14 @@ class TC_TNSPing < Test::Unit::TestCase
|
|
99
90
|
end
|
100
91
|
|
101
92
|
def test_bad_db
|
102
|
-
|
103
|
-
assert_raises(TNSPingError){
|
93
|
+
assert_raises(Ping::TNS::Error){ Ping::TNS.new('bogus_db') }
|
94
|
+
assert_raises(TNSPingError){ Ping::TNS.new('bogus_db') } # Alias test
|
104
95
|
@tp.port = 9999
|
105
96
|
assert_equal(false, @tp.ping_listener?)
|
106
97
|
end
|
107
98
|
|
108
99
|
def teardown
|
109
|
-
@db
|
110
|
-
@tp
|
100
|
+
@db = nil
|
101
|
+
@tp = nil
|
111
102
|
end
|
112
103
|
end
|
metadata
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.
|
2
|
+
rubygems_version: 0.9.4
|
3
3
|
specification_version: 1
|
4
4
|
name: net-tnsping
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 1.
|
7
|
-
date:
|
6
|
+
version: 1.2.0
|
7
|
+
date: 2007-07-20 00:00:00 -06:00
|
8
8
|
summary: A package for pinging Oracle listeners and databases
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -23,6 +23,9 @@ required_ruby_version: !ruby/object:Gem::Version::Requirement
|
|
23
23
|
version: 0.0.0
|
24
24
|
version:
|
25
25
|
platform: ruby
|
26
|
+
signing_key:
|
27
|
+
cert_chain:
|
28
|
+
post_install_message:
|
26
29
|
authors:
|
27
30
|
- Daniel J. Berger
|
28
31
|
files:
|
@@ -30,6 +33,7 @@ files:
|
|
30
33
|
- CHANGES
|
31
34
|
- MANIFEST
|
32
35
|
- README
|
36
|
+
- Rakefile
|
33
37
|
- test/tc_tns_ping.rb
|
34
38
|
test_files:
|
35
39
|
- test/tc_tns_ping.rb
|