I’m trying to get data from an ssh server, but this action takes some time to run, so I need to wait for them, once I have them, I’ll use this data to send them through my Bot to Slack.
Here my code:
def sshPingRequest()
Net::SSH.start('xxxx.xxxxx.xxxxx', 'root', :port => "3132") do |ssh|
output = ssh.exec!("ansible -m ping c3")
result = output.split("\n").select { |line| line.include?("SUCCESS") || line.include?("FAILURE") }
puts "############## Done #############"
return result
end
end
SlackRubyBotServer::Events.configure do |config|
data = sshPingRequest() # Help
config.on :command, '/ans-ping' do |command|
command.logger.info 'Received a ping, responding with pong.'
{ text: data }
end
end
Basically I need to wait for the "result" variable to be ready from the first function, and after sending it in the second function.
Thanks in advance.