From bf7edc78146c6ddddf829590adfdbd81dc19666d Mon Sep 17 00:00:00 2001 From: Aaron Johnson Date: Tue, 17 Sep 2019 18:50:12 -0500 Subject: [PATCH] Added non-standard SSH port support --- callbacks.rb | 9 +++++++-- commands.rb | 3 ++- run.rb | 12 +++++------- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/callbacks.rb b/callbacks.rb index 6ff5854..efa5ab9 100644 --- a/callbacks.rb +++ b/callbacks.rb @@ -1,8 +1,13 @@ def process_callback_zone(message) host = message.data.split("|")[1] - zone = @probes[host].values.first + #zone = @probes[host].values.first + zone = @probes[host].select { |k,v| k == 'loc' } + zone = zone["loc"] puts "Selected: #{zone}" - tdata = process_tdata(host) + port = @probes[host].select { |k,v| k == 'port' } + port = port["port"] + #print " Port: #{port}\n" + tdata = process_tdata(host, port) #puts "Selected: #{zone} [#{tdata}]" send_message(message.message.chat.id, "#{zone}: #{tdata}") STDOUT.flush diff --git a/commands.rb b/commands.rb index 2ad294f..b401f68 100644 --- a/commands.rb +++ b/commands.rb @@ -102,8 +102,9 @@ def process_command_report(message, command, adm, simple=false) end @probes.each do |k,v| zone = v["loc"].to_s + port = v["port"].to_s host = k - tdata = process_tdata(host, simple) + tdata = process_tdata(host, port, simple) report = report + "#{zone}: #{tdata}\n" STDOUT.flush end diff --git a/run.rb b/run.rb index 35ba9be..925f221 100755 --- a/run.rb +++ b/run.rb @@ -164,7 +164,8 @@ puts "Temporary direcotry: #{@tmpdir}" puts "Temperature unit: #{@tunit}" puts "Probes loaded:" @probes.each do |k,v| - puts " [#{k}] #{v["loc"].to_s}" + #puts " [#{k}] #{v["loc"].to_s}" + puts " [" + "#{k}: ".bold + v['port'].to_s.green.bold + "] #{v['loc'].to_s}" end puts "Start time: " + timestamp + "\n\n\n\n" STDOUT.flush @@ -181,9 +182,6 @@ STDOUT.flush #end def host_lookup(select_loc) - #@probes.select { |k,v| v['loc'] == select_loc }.each do |host,loc| - # return host - #end return @probes.select { |k,v| v['loc'] == select_loc } end @@ -195,11 +193,11 @@ class String /^\s*[+-]?((\d+_?)*\d+(\.(\d+_?)*\d+)?|\.(\d+_?)*\d+)(\s*|([eE][+-]?(\d+_?)*\d+)\s*)$/ === self end end -def process_tdata(host, simple=false) +def process_tdata(host, port, simple=false) print "Processing #{host}: " STDOUT.flush - if system("nmap #{host} -p 22 2>&1 | grep 22 | grep open >/dev/null") - tdata = `ssh -oBatchMode=yes #{host} heatbot_gettemp`.chomp + if system("nmap #{host} -p #{port} 2>&1 | grep #{port} | grep open >/dev/null") + tdata = `ssh -p #{port} -oBatchMode=yes #{host} heatbot_gettemp`.chomp #if tdata.is_integer? if tdata.is_float? tdf = tdata.to_f