Net::Ping:Class (NoMethodError)

Hi,
can someone pls help and suggest the workaround, when I run the
following code, it return error

require 'rubygems'
require 'net/ping'

class PingIp

def ping_system(ping_system)
    @ping_address = "ping_system"
      #result = Ping.pingecho(ip_address,5,80)
      result = Net::Ping.ping(@ping_address, 5)
if result
    puts "system is alive"
else
    puts "system is offline"
end
      return result
  end
  end # end of class

  instance = PingIp.new
  instance.ping_system('10.55.89.66')

Error message

undefined method `ping' for Net::Ping:Class (NoMethodError)

I am using ruby 1.9.2

Thanks

···

--
Posted via http://www.ruby-forum.com/.

This is an example for ICP ping but I assume you will want a http ping
perhaps?

#!/usr/local/bin/ruby

require 'net/ping'

host = ARGV[0]

u = Net::Ping::ICMP.new(host)

def pingable?(addr, u)
  #output = `ping -c 4 #{addr}`
  #[(!output.include? "100% packet loss"), output]
  [u.ping?,"some output"]
end

res = pingable?(host, u)
if res[0]
  #puts "OK: #{res[1]}"
  puts "OK: Works fine!"
  exit 0
else
  #puts "Critical: #{res[1]}"
  puts "Critical: Has issues!"
  exit 1
end
#END

you can use the net ping for ports etc...
an http ping is like:
#!/usr/local/bin/ruby

require 'net/ping'

host = ARGV[0]

u = Net::Ping::HTTP.new(host)

def pingable?(addr, u)
  #output = `ping -c 4 #{addr}`
  #[(!output.include? "100% packet loss"), output]
  [u.ping?,"some output"]
end

res = pingable?(host, u)
if res[0]
  #puts "OK: #{res[1]}"
  puts "OK: Works fine!"
  exit 0
else
  #puts "Critical: #{res[1]}"
  puts "Critical: Has issues!"
  exit 1
end
#END

hope it helps.

Eliezer

···

On 09/10/2013 07:14 PM, Bal Sidhu wrote:

Hi,
can someone pls help and suggest the workaround, when I run the
following code, it return error

require 'rubygems'
require 'net/ping'

class PingIp

def ping_system(ping_system)
    @ping_address = "ping_system"
      #result = Ping.pingecho(ip_address,5,80)
      result = Net::Ping.ping(@ping_address, 5)
if result
    puts "system is alive"
else
    puts "system is offline"
end
      return result
  end
  end # end of class

  instance = PingIp.new
  instance.ping_system('10.55.89.66')

Error message

undefined method `ping' for Net::Ping:Class (NoMethodError)

I am using ruby 1.9.2

Thanks