Advertisement
Guest User

Offline Servers

a guest
Jul 23rd, 2014
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.63 KB | None | 0 0
  1. require_relative 'my_db.rb'
  2.  
  3. clients = [
  4.     {name: 'OS-client1', id: '1'},
  5.     {name: 'OS-client2', id: '2'},
  6.     {name: 'OS-client3', id: '3'},
  7.     {name: 'OS-client4', id: '4'},
  8.     ]
  9.  
  10. SCHEDULER.every '30s', :first_in => 0 do |job|
  11.     clients.each do |client|
  12.     begin
  13.             db = MyDb.conn
  14.  
  15.             sql = "SELECT computerid FROM Computers WHERE LastContact < DATE_ADD(NOW(),Interval -120 Second) AND OS LIKE '%Server%' AND clientid = `#{client[:id]}`"
  16.  
  17.             results = db.query(sql)
  18.  
  19.             current_client[:name] = results.count
  20.  
  21.             send_event(client[:name], { value: current_client[:name] } )
  22. end
  23. db.close
  24. end
  25. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement