Class: Recmon::PingSensor

Inherits:
Sensor
  • Object
show all
Defined in:
lib/recmon/ping-sensor.rb

Overview

Periodically pings a host to check it is alive

Instance Method Summary collapse

Methods inherited from Sensor

#check

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

#senseObject

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