Guest User

Untitled

a guest
Feb 8th, 2013
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.68 KB | None | 0 0
  1. # :first_in sets how long it takes before the job is first run. In this case, it is run immediately
  2. SCHEDULER.every '3s', :first_in => 0 do |job|
  3.  
  4. require 'rubygems'
  5. require 'nokogiri'
  6. require 'mechanize'
  7.  
  8. @agent = Mechanize.new
  9.  
  10.  
  11. # Log into The Dude and save the cookie
  12. page = @agent.post('http://DUDESERVER/dude/main.html', {
  13. 'process' => 'login',
  14. 'page' => 'start',
  15. 'user' => 'USERNAME',
  16. 'password' => 'PASSWORD',
  17. })
  18. temp_jar = @agent.cookie_jar
  19.  
  20. @agent = Mechanize.new
  21. @agent.cookie_jar = temp_jar
  22.  
  23. # Pull the page that lists all devices reporting down and store it in an array
  24. page = @agent.get 'http://DUDESERVER/dude/main.html?devType=XXXXXX&mapFilter=XXXXXX&sList=3&page=devices'
  25. device_array = page.links
  26.  
  27. # Get rid of bullshit
  28. device_array.reject! { |item| item.text == 'chart' }
  29. device_array.reject! { |item| item.text == 'add note' }
  30. device_array.reject! { |item| item.text == 'Bridge' }
  31. device_array.reject! { |item| item.text == 'DNS Server' }
  32. device_array.reject! { |item| item.text == 'Dude Server' }
  33. device_array.reject! { |item| item.text == 'FTP Server' }
  34. device_array.reject! { |item| item.text == 'HP Jet Direct' }
  35. device_array.reject! { |item| item.text == 'IMAP4 Server' }
  36. device_array.reject! { |item| item.text == 'Mail Server' }
  37. device_array.reject! { |item| item.text == 'MikroTik Device' }
  38. device_array.reject! { |item| item.text == 'News Server' }
  39. device_array.reject! { |item| item.text == 'POP3 Server' }
  40. device_array.reject! { |item| item.text == 'Printer' }
  41. device_array.reject! { |item| item.text == 'Router' }
  42. device_array.reject! { |item| item.text == 'Some Device' }
  43. device_array.reject! { |item| item.text == 'Switch' }
  44. device_array.reject! { |item| item.text == 'Time Server' }
  45. device_array.reject! { |item| item.text == 'Web Server' }
  46. device_array.reject! { |item| item.text == 'Windows Computer' }
  47.  
  48. #limit to the first 10 items
  49. device_array = device_array.slice(0, 20)
  50.  
  51. #format the array items
  52. dude_devices_down = device_array.each_slice(2).map{|s| s.join(' @ ') }.join('<br/>')
  53.  
  54. #send to devices_down widget
  55. send_event('devices_down', {text: dude_devices_down})
  56.  
  57. # Pull the page that lists all devices reporting partially down and store it in an array
  58. page = @agent.get 'http://DUDESERVER/dude/main.html?devType=XXXXXX&mapFilter=XXXXXX&sList=2&page=devices'
  59. device_array = page.links
  60.  
  61. # Get rid of bullshit
  62. device_array.reject! { |item| item.text == 'chart' }
  63. device_array.reject! { |item| item.text == 'add note' }
  64. device_array.reject! { |item| item.text == 'Bridge' }
  65. device_array.reject! { |item| item.text == 'DNS Server' }
  66. device_array.reject! { |item| item.text == 'Dude Server' }
  67. device_array.reject! { |item| item.text == 'FTP Server' }
  68. device_array.reject! { |item| item.text == 'HP Jet Direct' }
  69. device_array.reject! { |item| item.text == 'IMAP4 Server' }
  70. device_array.reject! { |item| item.text == 'Mail Server' }
  71. device_array.reject! { |item| item.text == 'MikroTik Device' }
  72. device_array.reject! { |item| item.text == 'News Server' }
  73. device_array.reject! { |item| item.text == 'POP3 Server' }
  74. device_array.reject! { |item| item.text == 'Printer' }
  75. device_array.reject! { |item| item.text == 'Router' }
  76. device_array.reject! { |item| item.text == 'Some Device' }
  77. device_array.reject! { |item| item.text == 'Switch' }
  78. device_array.reject! { |item| item.text == 'Time Server' }
  79. device_array.reject! { |item| item.text == 'Web Server' }
  80. device_array.reject! { |item| item.text == 'Windows Computer' }
  81.  
  82. #limit to the first 10 items
  83. device_array = device_array.slice(0, 20)
  84.  
  85. #format the array items
  86. dude_devices_partially_down = device_array.each_slice(2).map{|s| s.join(' @ ') }.join('<br/>')
  87.  
  88. #send to devices_partially_down widget
  89. send_event('devices_partially_down', {text: dude_devices_partially_down})
  90.  
  91. # Pull the page that lists all devices reporting acked down and store it in an array
  92. page = @agent.get 'http://DUDESERVER/dude/main.html?devType=XXXXXX&mapFilter=XXXXXX&sList=4&page=devices'
  93. device_array = page.links
  94.  
  95. # Get rid of bullshit
  96. device_array.reject! { |item| item.text == 'chart' }
  97. device_array.reject! { |item| item.text == 'add note' }
  98. device_array.reject! { |item| item.text == 'Bridge' }
  99. device_array.reject! { |item| item.text == 'DNS Server' }
  100. device_array.reject! { |item| item.text == 'Dude Server' }
  101. device_array.reject! { |item| item.text == 'FTP Server' }
  102. device_array.reject! { |item| item.text == 'HP Jet Direct' }
  103. device_array.reject! { |item| item.text == 'IMAP4 Server' }
  104. device_array.reject! { |item| item.text == 'Mail Server' }
  105. device_array.reject! { |item| item.text == 'MikroTik Device' }
  106. device_array.reject! { |item| item.text == 'News Server' }
  107. device_array.reject! { |item| item.text == 'POP3 Server' }
  108. device_array.reject! { |item| item.text == 'Printer' }
  109. device_array.reject! { |item| item.text == 'Router' }
  110. device_array.reject! { |item| item.text == 'Some Device' }
  111. device_array.reject! { |item| item.text == 'Switch' }
  112. device_array.reject! { |item| item.text == 'Time Server' }
  113. device_array.reject! { |item| item.text == 'Web Server' }
  114. device_array.reject! { |item| item.text == 'Windows Computer' }
  115.  
  116. #limit to the first 10 items
  117. device_array = device_array.slice(0, 20)
  118.  
  119. #format the array items
  120. dude_devices_acked_down = device_array.each_slice(2).map{|s| s.join(' @ ') }.join('<br/>')
  121.  
  122. #send to devices_acked_down widget
  123. send_event('devices_acked_down', {text: dude_devices_acked_down})
  124. #log out
  125. @agent = Mechanize.new
  126. @agent.cookie_jar = temp_jar
  127. page = @agent.post 'http://DUDESERVER/dude/login.html?drop_cookie=true'
  128. end
Advertisement
Add Comment
Please, Sign In to add comment