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)
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)
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"

@ -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"
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'

Loading…
Cancel
Save