Added simple checks (Easter egg)

pull/2/head
Aaron Johnson 6 years ago
parent ae76468203
commit 479cc33833

@ -74,7 +74,7 @@ def process_command_chatinfo(message)
send_message(message.chat.id, reply) send_message(message.chat.id, reply)
end 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) if is_chat_authorized?(message, @auth_chat) || message_from_admin?(message, adm)
#begin interactive code #begin interactive code
options = [ ] options = [ ]
@ -92,15 +92,20 @@ def process_command_check(message, command, adm)
end end
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) if is_chat_authorized?(message, @auth_chat) || message_from_admin?(message, adm)
confirmation = send_message(message.chat.id,"Generating full report... Please wait.") if !simple
report = "Full Report:\n\n" 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| @probes.each do |k,v|
zone = v["loc"].to_s zone = v["loc"].to_s
host = k host = k
#print "#{host}: #{zone} " #print "#{host}: #{zone} "
tdata = process_tdata(host) tdata = process_tdata(host, simple)
#tdata = `ssh #{host} heatbot_gettemp` #tdata = `ssh #{host} heatbot_gettemp`
#print "[#{tdata}°#{@tunit}]\n" #print "[#{tdata}°#{@tunit}]\n"
#report = report + "#{zone}: #{tdata}°#{@tunit}\n" #report = report + "#{zone}: #{tdata}°#{@tunit}\n"

@ -164,19 +164,37 @@ class String
#!!(self =~ /\A[-+]?[0-9]+\z/) #!!(self =~ /\A[-+]?[0-9]+\z/)
end end
end end
def process_tdata(host) def process_tdata(host, simple=false)
print "Processing #{host}: " print "Processing #{host}: "
STDOUT.flush
if system("nmap #{host} -p 22 2>&1 | grep 22 | grep open >/dev/null") if system("nmap #{host} -p 22 2>&1 | grep 22 | grep open >/dev/null")
tdata = `ssh -oBatchMode=yes #{host} heatbot_gettemp` tdata = `ssh -oBatchMode=yes #{host} heatbot_gettemp`
if tdata.is_integer? if tdata.is_integer?
print tdata + "°#{@tunit}\n" print tdata + "°#{@tunit}"
return 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 else
puts "Unexpected output from [".red.bold + host.bold + "]: ".red.bold + tdata puts "Unexpected output from [".red.bold + host.bold + "]: ".red.bold + tdata
STDOUT.flush
return "CHECK PROBE" return "CHECK PROBE"
end end
else else
print "OFFLINE\n" print "OFFLINE\n"
STDOUT.flush
return "OFFLINE" return "OFFLINE"
end end
end end
@ -304,6 +322,11 @@ def handle_message(message)
process_command_check(message, command, adm) process_command_check(message, command, adm)
when '/report', '/r' when '/report', '/r'
process_command_report(message, command, adm) 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' when '/test'
process_command_test(message, command, adm) process_command_test(message, command, adm)
when '/pp', '/debug' when '/pp', '/debug'

Loading…
Cancel
Save