Pinging a host


#1

Hello,

I am working on an App and am trying to return a page with the status of
a host (up/down). The host IP addresses are taken from a database and
then pinged using ping.rb. The code works if typed in irb but when
done from inside Rails, it always returns false.

The code is called from list.rhtml by

<%=h firewall.host_up(firewall.ip4_addr) %>

host_up is in the model rb script as
def host_up(ip4_addr)
require “ping.rb”
ping_obj =
Ping.pingecho(ip4_addr,timeout=5,service=“echo”)
if ping_obj == false
is_up = “Down”
end
if ping_obj == true
is_up = “UP”
end
ret_value ="device " + ip4_addr + " is "+ is_up
return ret_value
end

The code seems to execute (if a put a breakpoint call in host_up, it
gets called) just does not return a true when the host is up. Using
tcpdump, I can see that is does not ever actually try to send out
packets.

Thanks for any ideas or suggestions you might have.
Ray


Ray Ward
Ward Technologies, LLC
removed_email_address@domain.invalid
630 544-2999


#2

I am working on an App and am trying to return a page with the status of
a host (up/down). The host IP addresses are taken from a database and
then pinged using ping.rb. The code works if typed in irb but when
done from inside Rails, it always returns false.

  • Are you running irb on the same machine as Rails?
  • Any change you are inside a FreeBSD jail on the Rails machine?
  • Are there any error messages you can get out of the Ping library?
  • What about using script/console? Does that fail?
  • Are the users running irb and Rails different? Or the same?
  • What does ping.rb look like? Any chance it’s making a system call to
    the OS ping (which might fail if Rails user has no shell say)?

-p


#3

-irb was run from the same machine with the same user.
-I thought of the jail idea since my development box is an OpenBSD
machine but I moved it to a windows box and it did the same thing
(running from irb still worked).
-no errors that I can see.
-Just tried, it works from script/console
-users are the same

  • ping.rb calls socket. I did not look into socket.

Philip H. wrote:

  • Are the users running irb and Rails different? Or the same?

host_up is in the model rb script as
return ret_value


This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email



Ray Ward
Ward Technologies, LLC
removed_email_address@domain.invalid
630 544-2999