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.
Files changed (7) hide show
  1. data/CHANGES +11 -0
  2. data/MANIFEST +8 -11
  3. data/README +50 -49
  4. data/Rakefile +22 -0
  5. data/lib/net/tnsping.rb +27 -21
  6. data/test/tc_tns_ping.rb +13 -22
  7. 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
- install.rb
5
- net-tnsping.gemspec
6
-
7
- examples/test_tnsping.rb
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
- ruby test/tc_tns_ping.rb (optional)
14
- ruby install.rb
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. Set it to a known database
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 = TNSPing.new("my_db")
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
- TNSPing.new(db, driver="OCI8", host=nil, port=1521, timeout=5)
43
- Creates and returns a new TNSPing object. If the db specified cannot be
44
- found in the tnsnames.ora file, then a TNSPingError is raised.
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
- TNSPing#db
48
- Returns the name of the database that the TNSPing#ping_database? method
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
- TNSPing#db=(database)
52
- Sets the name of the database that the TNSPing#ping_database? method
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
- TNSPing#driver
56
- Returns the name of the driver used by the TNSPing#ping_database? method.
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
- TNSPing#driver=(driver)
60
- Sets the name of the driver used by the TNSPing#ping_database? method.
60
+ Ping::TNS#driver=(driver)
61
+ Sets the name of the driver used by the Ping::TNS#ping_database? method.
61
62
 
62
- TNSPing#dsn
63
- Returns the dsn string that is used by TNSPing#ping_database?.
63
+ Ping::TNS#dsn
64
+ Returns the dsn string that is used by Ping::TNS#ping_database?.
64
65
 
65
- TNSPing#dsn=(string)
66
- Sets the dsn string that is used by TNSPing#ping_database?. It should
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
- TNSPing#host
70
- Returns the host that the TNSPing#ping_listener? call will use. This may
71
- be nil, in which case, the TNSPing#hosts method will list which hosts it
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
- TNSPing#host=(host)
75
- Sets the host that the TNSPing#ping_listener? call will use. If this is
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
- TNSPing#oracle_home
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
- TNSPing#oracle_home=(path)
84
+ Ping::TNS#oracle_home=(path)
84
85
  Sets the path to the oracle home directory.
85
86
 
86
- TNSPing#ping?
87
- TNSPing#ping_listener?
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
- TNSPing#ping_database?(dsn=nil, timeout=nil, user=nil, passwd=nil)
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 TNSPing#exception.
107
+ be viewed via Ping::TNS#exception.
107
108
 
108
- TNSPing#ping_all?
109
- A shortcut method that merely calls TNSPing#ping? and TNSPing#ping_database?
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
- TNSPing#port
113
- Returns the port that the TNSPing#ping_listener? will ping against. This
114
- may be nil, in which case the TNSPing#ports method will list which ports
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
- TNSPing#port=(num)
118
- Sets the port that the TNSPing#ping_listener? method will use. If this is
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
- TNSPing#timeout
123
+ Ping::TNS#timeout
123
124
  Returns the timeout value used by all internal ping methods.
124
125
 
125
- TNSPing#timeout=(seconds)
126
+ Ping::TNS#timeout=(seconds)
126
127
  Sets the timeout used by all internal ping methods.
127
128
 
128
- TNSPing#tns_admin
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
- TNSPing#tns_admin=(path)
133
+ Ping::TNS#tns_admin=(path)
133
134
  Sets the path to the tns admin directory.
134
135
 
135
- TNSPing#tns_file
136
+ Ping::TNS#tns_file
136
137
  Returns the full path to the tnsnames.ora file.
137
138
 
138
- TNSPing#tns_file=(path)
139
+ Ping::TNS#tns_file=(path)
139
140
  Sets the path to the tnsnames.ora file.
140
141
 
141
142
  == Notes
142
- The TNSPing class is a subclass of PingTCP.
143
+ The Ping::TNS class is a subclass of Ping::TCP.
143
144
 
144
- This is NOT a wrapper for the tnsping utility. It performs two actions.
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. Who knows
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. It doesn't
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-2005 Daniel J. Berger
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 yahoo dot com
189
+ djberg96 at nospam at gmail dot com
189
190
  imperator on IRC (irc.freenode.net)
@@ -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
@@ -2,21 +2,22 @@ require "dbi"
2
2
  require "net/ping"
3
3
 
4
4
  module Net
5
- class TNSPingError < StandardError; end
6
- class TNSPing < PingTCP
5
+ class Ping::TNS < Ping::TCP
6
+ class Error < StandardError; end
7
7
 
8
- VERSION = "1.1.0"
8
+ VERSION = '1.2.0'
9
9
 
10
10
  attr_accessor :db, :dsn, :tns_file, :host, :tns_admin
11
- attr_accessor :oracle_home, :driver, :timeout
11
+ attr_accessor :ora_home, :driver, :timeout
12
12
  attr_reader :hosts, :ports, :port
13
13
 
14
- # Creates and returns a new TNSPing object. If the db specified cannot
15
- # be found in the tnsnames.ora file, then a TNSPingError is raised.
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 = ENV["TNS_ADMIN"]
28
- @oracle_home = ENV["ORACLE_HOME"] || ENV["ORA_HOME"]
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 + "/tnsnames.ora"
32
- elsif @oracle_home
33
- @tns_file = @oracle_home + "/network/admin/tnsnames.ora"
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"] + "/tnsnames.ora"
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 TNSPingError, err_msg unless File.exists?(@tns_file)
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 TNSPing#ping_listener? method will use. If
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 TNSPingError, "No hosts found"
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 TNSPing#exception.
104
+ # can be viewed via Ping::TNS#exception.
104
105
  #--
105
- # I have intentionally set the user and password to something zany in
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="xz949")
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 ||= "pzoyadf244"
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 TNSPingError, "unable to find #{db} in #{file}"
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 :ping_listener? :ping?
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
@@ -1,31 +1,22 @@
1
- #########################################
1
+ ########################################################################
2
2
  # tc_tns_ping.rb
3
3
  #
4
- # Test suite for the tns-ping package.
5
- #########################################
6
- base = File.basename(Dir.pwd)
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
- # NOTE:
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 = "changme"
24
- @tp = TNSPing.new(@db)
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.1.0", TNSPing::VERSION)
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
- bad_db = "foo123bar"
103
- assert_raises(TNSPingError){ TNSPing.new(bad_db) }
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 = nil
110
- @tp = nil
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.8.10
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.1.0
7
- date: 2005-06-16
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