From: Torsten Schmidt Date: 2005-12-02T21:47:51+09:00 Subject: Re: url-monitoring script question ------=_Part_29900_31315885.1133527662739 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Hi @all, i'll be back with an issue of my web-monitoring-script. yesterday i got the following email from my cron-daemon: /usr/lib/ruby/1.8/net/protocol.rb:83:in `initialize': Connection refused - connect(2) (Errno::ECONNREFUSED) from /usr/lib/ruby/1.8/net/protocol.rb:83:in `new' from /usr/lib/ruby/1.8/net/protocol.rb:83:in `connect' from /usr/lib/ruby/1.8/net/protocol.rb:82:in `timeout' from /usr/lib/ruby/1.8/timeout.rb:55:in `timeout' from /usr/lib/ruby/1.8/net/protocol.rb:82:in `connect' from /usr/lib/ruby/1.8/net/protocol.rb:64:in `initialize' from /usr/lib/ruby/1.8/net/http.rb:430:in `open' from /usr/lib/ruby/1.8/net/http.rb:430:in `do_start' from /usr/lib/ruby/1.8/net/http.rb:419:in `start' from /usr/lib/ruby/1.8/net/http.rb:296:in `get_by_uri' from /usr/lib/ruby/1.8/net/http.rb:282:in `get_response' from /usr/local/bin/webcattest/WebCatMonitoring.rb:34 from /usr/local/bin/webcattest/WebCatMonitoring.rb:32:in `each' from /usr/local/bin/webcattest/WebCatMonitoring.rb:32 i was able to handle a timeout-error, but the error above was not handled. Unfortunately i don't know how to reproduce the connection-refused error where i can test my new rescue method: see rescue Exception =3D> err ------------------------------------------------------------------- require 'net/smtp' require 'net/http' apps =3D [ { :name =3D> 'url-test', :url =3D> 'test/url' }, #... ] for app in apps app[:url] =3D URI.parse("http://#{app[:url]}") end errors =3D [] for app in apps.sort { rand } begin res =3D Net::HTTP.get_response(app[:url]) error =3D nil if %w[ 301 302 ].include?res.response.code res =3D Net::HTTP.get_response( URI.parse(res.header["location"] )) end if res.response.code.to_i !=3D 200 error =3D ["

#{app[:name]}

error code: #{res.response.code }

"] #... errors << error end rescue Timeout::Error =3D> err errors << error =3D ["Timeout Error: #{app[:name]} not reachable!"] rescue Exception =3D> exception errors << "

#{app[:name]} with #{app[:url]} not reachable!
#{exception.message}
" end end # handling Emails... ------------------------------------------------------------------- Any ideas how to reproduce a connection-refused error or suggestions if my rescue Exception can handle this? (sorry for my bad english) Regards, Torsten ------=_Part_29900_31315885.1133527662739--