Class: Recmon::SSHSensor

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

Overview

SSHSensor periodically checks that an SSH service is available

Instance Method Summary collapse

Methods inherited from Sensor

#check

Constructor Details

#initialize(name, user = "_recmon", port = 22, freq = 300) ⇒ SSHSensor

Create a new SSHSensor to periodically test SSH at the named host



9
10
11
12
13
# File 'lib/recmon/ssh-sensor.rb', line 9

def initialize(name, user="_recmon", port=22, freq=300)
  super(name, freq)
  @user = user
  @port = port
end

Instance Method Details

#senseObject

Called by Monitor. sense() attempts to log in to the host in batch mode so you MUST set up a private key authentication for this user or this sensor will generate false negatives.



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

def sense()
  `/usr/bin/ssh -p#{@port} -o "BatchMode yes" #{@user}@#{@name} pwd`
  up = $?.exitstatus == 0
  status = up ? "up" : "down"
  return("SSH at host=#{@name} for user=#{@user} status=#{status}")
end