Class: Recmon::CommandSensor

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

Overview

Periodically execute a command and report success

Instance Method Summary collapse

Methods inherited from Sensor

#check

Constructor Details

#initialize(name, command, freq = 600) ⇒ CommandSensor

Create a new CommandSensor. The name is descriptive and the command should be runnable by the _recmon user



11
12
13
14
# File 'lib/recmon/command-sensor.rb', line 11

def initialize(name, command, freq=600)
  super(name, freq)
  @command = command
end

Instance Method Details

#senseObject

Ensure user _recmon has permission to run the command. An exit status of zero is required for success



18
19
20
21
22
23
# File 'lib/recmon/command-sensor.rb', line 18

def sense()
  `#{@command}`
  up = $?.exitstatus == 0
  status = up ? "up" : "down"
  return("#{@name} status=#{status}")
end