class Pandur::Check
Public Class Methods
new(target)
click to toggle source
# File lib/pandur/check.rb, line 5 def initialize(target) @config = target end
Public Instance Methods
check(ssh)
click to toggle source
# File lib/pandur/check.rb, line 9 def check(ssh) logger.debug("Checking #{@config['name']}") if @config['pid_file'] print "Checking #{@config['name']}: " escaped_pid_file = @config['pid_file'].gsub('\'', '\\\'') if(ssh_exec!(ssh, "test -r '#{escaped_pid_file}' && test -n '`ps -ef | grep -v grep | grep \`cat '#{escaped_pid_file}'\``'")[2] > 0) puts "FAIL" else puts "OK" end else logger.debug("cannot check #{@config.inspect}") end end
Private Instance Methods
ssh_exec!(ssh, command)
click to toggle source
# File lib/pandur/check.rb, line 26 def ssh_exec!(ssh, command) stdout_data = "" stderr_data = "" exit_code = nil exit_signal = nil ssh.open_channel do |channel| channel.exec(command) do |ch, success| unless success abort "FAILED: couldn't execute command (ssh.channel.exec)" end channel.on_data do |ch,data| stdout_data+=data end channel.on_extended_data do |ch,type,data| stderr_data+=data end channel.on_request("exit-status") do |ch,data| exit_code = data.read_long end channel.on_request("exit-signal") do |ch, data| exit_signal = data.read_long end end end ssh.loop [stdout_data, stderr_data, exit_code, exit_signal] end