Guest User

Untitled

a guest
Jul 16th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. #!/usr/local/bin/ruby
  2.  
  3. require 'socket'
  4. require 'active_record'
  5. ActiveRecord::Base.establish_connection(
  6. :adapter => "sqlite3",
  7. :dbfile => "/rails/wakify/db/development.sqlite3"
  8. )
  9.  
  10. class Status < ActiveRecord::Base
  11. set_table_name "computers"
  12. end
  13.  
  14. server = TCPServer.open(55523)
  15.  
  16. loop do
  17. Thread.start(server.accept) do |c|
  18. c.puts("Connected!\n")
  19. ping = c.readline.chomp
  20. timestamp = Time.now.strftime("%m/%d/%Y @ %I:%M:%S%p")
  21. print "#{timestamp} --- Ping check from #{ping}\n"
  22. c.puts("#{ping} OK!")
  23. c.close
  24. suite = Status.first(:conditions => {:host => ping})
  25. print suite.empty?
  26. suite.lastping = Time.now.to_i
  27. suite.save(:validate => false)
  28. end
  29. end
Add Comment
Please, Sign In to add comment