From 479cc338337c22349d4b52fae2e59ff8708f331c Mon Sep 17 00:00:00 2001 From: Aaron Johnson Date: Sun, 15 Sep 2019 17:01:08 -0500 Subject: [PATCH] Added simple checks (Easter egg) --- commands.rb | 15 ++++++++++----- run.rb | 29 ++++++++++++++++++++++++++--- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/commands.rb b/commands.rb index 4129ef8..c2c0f28 100644 --- a/commands.rb +++ b/commands.rb @@ -74,7 +74,7 @@ def process_command_chatinfo(message) send_message(message.chat.id, reply) end -def process_command_check(message, command, adm) +def process_command_check(message, command, adm, simple=false) if is_chat_authorized?(message, @auth_chat) || message_from_admin?(message, adm) #begin interactive code options = [ ] @@ -92,15 +92,20 @@ def process_command_check(message, command, adm) end end -def process_command_report(message, command, adm) +def process_command_report(message, command, adm, simple=false) if is_chat_authorized?(message, @auth_chat) || message_from_admin?(message, adm) - confirmation = send_message(message.chat.id,"Generating full report... Please wait.") - report = "Full Report:\n\n" + if !simple + confirmation = send_message(message.chat.id,"Generating full report... Please wait.") + report = "Full Report:\n\n" + else + confirmation = send_message(message.chat.id,"Generating simple report... Please wait.") + report = "Simple Report:\n\n" + end @probes.each do |k,v| zone = v["loc"].to_s host = k #print "#{host}: #{zone} " - tdata = process_tdata(host) + tdata = process_tdata(host, simple) #tdata = `ssh #{host} heatbot_gettemp` #print "[#{tdata}°#{@tunit}]\n" #report = report + "#{zone}: #{tdata}°#{@tunit}\n" diff --git a/run.rb b/run.rb index 283938e..defbe34 100755 --- a/run.rb +++ b/run.rb @@ -164,19 +164,37 @@ class String #!!(self =~ /\A[-+]?[0-9]+\z/) end end -def process_tdata(host) +def process_tdata(host, 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` if tdata.is_integer? - print tdata + "°#{@tunit}\n" - return tdata + "°#{@tunit}" + print tdata + "°#{@tunit}" + if simple #This is mostly just an Easter egg + if tdata.to_i > 75 + sdata = "Hot" + elsif tdata.to_i < 50 + sdata = "Cold" + else + sdata = "Fair" + end + print " [#{sdata}]\n" + STDOUT.flush + return sdata + else + print "\n" + STDOUT.flush + return tdata + "°#{@tunit}" + end else puts "Unexpected output from [".red.bold + host.bold + "]: ".red.bold + tdata + STDOUT.flush return "CHECK PROBE" end else print "OFFLINE\n" + STDOUT.flush return "OFFLINE" end end @@ -304,6 +322,11 @@ def handle_message(message) process_command_check(message, command, adm) when '/report', '/r' process_command_report(message, command, adm) + #when '/simple', '/s', '/sc' + # process_command_check(message, command, adm, true) + #when '/sreport', '/simpler', '/simplereport', '/sr' + when '/simple', '/s', '/sreport', '/simpler', '/simplereport', '/sr' + process_command_report(message, command, adm, true) when '/test' process_command_test(message, command, adm) when '/pp', '/debug'