Forum: Ruby on Rails pinging a host

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
893c14eebf7d0f1b46de0f44fcb5312a?d=identicon&s=25 Raymond Ward (Guest)
on 2007-04-18 17:34
(Received via mailing list)
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

--
Ray Ward
Ward Technologies, LLC
ray@wardtechnologies.com
630 544-2999
2f9a03aa0fcfe945229cb6126eda2cb2?d=identicon&s=25 Philip Hallstrom (Guest)
on 2007-04-18 17:43
(Received via mailing list)
> 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
893c14eebf7d0f1b46de0f44fcb5312a?d=identicon&s=25 Raymond Ward (Guest)
on 2007-04-18 18:50
(Received via mailing list)
-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:
> - 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
ray@wardtechnologies.com
630 544-2999
This topic is locked and can not be replied to.