Class: Recmon::PingSensor
Overview
Periodically pings a host to check it is alive
Instance Method Summary collapse
-
#initialize(name, ip, freq = 120) ⇒ PingSensor
constructor
Create a new PingSensor to ping the given IP every 2 minutes.
-
#sense ⇒ Object
Called by Monitor.
Methods inherited from Sensor
Constructor Details
#initialize(name, ip, freq = 120) ⇒ PingSensor
Create a new PingSensor to ping the given IP every 2 minutes. ip
can be a hostname if it can be sucessfully resolved.
11 12 13 14 |
# File 'lib/recmon/ping-sensor.rb', line 11 def initialize(name, ip, freq=120) super(name, freq) @ip = IPAddr.new(ip) end |
Instance Method Details
#sense ⇒ Object
Called by Monitor. Sends a single ICMP ping to the IP. Of course, there is no point doing this if any firewall in between drops ICMP pings.
18 19 20 21 22 23 |
# File 'lib/recmon/ping-sensor.rb', line 18 def sense() `/sbin/ping -c1 #{@ip}` up = $?.exitstatus == 0 status = up ? "up" : "down" return("ping host=#{@name} status=#{status}") end |