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
<h2><%=h firewall.host_up(firewall.ip4_addr) %></h2>
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
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
-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 Hallstrom wrote: