Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # :first_in sets how long it takes before the job is first run. In this case, it is run immediately
- SCHEDULER.every '3s', :first_in => 0 do |job|
- require 'rubygems'
- require 'nokogiri'
- require 'mechanize'
- @agent = Mechanize.new
- # Log into The Dude and save the cookie
- page = @agent.post('http://DUDESERVER/dude/main.html', {
- 'process' => 'login',
- 'page' => 'start',
- 'user' => 'USERNAME',
- 'password' => 'PASSWORD',
- })
- temp_jar = @agent.cookie_jar
- @agent = Mechanize.new
- @agent.cookie_jar = temp_jar
- # Pull the page that lists all devices reporting down and store it in an array
- page = @agent.get 'http://DUDESERVER/dude/main.html?devType=XXXXXX&mapFilter=XXXXXX&sList=3&page=devices'
- device_array = page.links
- # Get rid of bullshit
- device_array.reject! { |item| item.text == 'chart' }
- device_array.reject! { |item| item.text == 'add note' }
- device_array.reject! { |item| item.text == 'Bridge' }
- device_array.reject! { |item| item.text == 'DNS Server' }
- device_array.reject! { |item| item.text == 'Dude Server' }
- device_array.reject! { |item| item.text == 'FTP Server' }
- device_array.reject! { |item| item.text == 'HP Jet Direct' }
- device_array.reject! { |item| item.text == 'IMAP4 Server' }
- device_array.reject! { |item| item.text == 'Mail Server' }
- device_array.reject! { |item| item.text == 'MikroTik Device' }
- device_array.reject! { |item| item.text == 'News Server' }
- device_array.reject! { |item| item.text == 'POP3 Server' }
- device_array.reject! { |item| item.text == 'Printer' }
- device_array.reject! { |item| item.text == 'Router' }
- device_array.reject! { |item| item.text == 'Some Device' }
- device_array.reject! { |item| item.text == 'Switch' }
- device_array.reject! { |item| item.text == 'Time Server' }
- device_array.reject! { |item| item.text == 'Web Server' }
- device_array.reject! { |item| item.text == 'Windows Computer' }
- #limit to the first 10 items
- device_array = device_array.slice(0, 20)
- #format the array items
- dude_devices_down = device_array.each_slice(2).map{|s| s.join(' @ ') }.join('<br/>')
- #send to devices_down widget
- send_event('devices_down', {text: dude_devices_down})
- # Pull the page that lists all devices reporting partially down and store it in an array
- page = @agent.get 'http://DUDESERVER/dude/main.html?devType=XXXXXX&mapFilter=XXXXXX&sList=2&page=devices'
- device_array = page.links
- # Get rid of bullshit
- device_array.reject! { |item| item.text == 'chart' }
- device_array.reject! { |item| item.text == 'add note' }
- device_array.reject! { |item| item.text == 'Bridge' }
- device_array.reject! { |item| item.text == 'DNS Server' }
- device_array.reject! { |item| item.text == 'Dude Server' }
- device_array.reject! { |item| item.text == 'FTP Server' }
- device_array.reject! { |item| item.text == 'HP Jet Direct' }
- device_array.reject! { |item| item.text == 'IMAP4 Server' }
- device_array.reject! { |item| item.text == 'Mail Server' }
- device_array.reject! { |item| item.text == 'MikroTik Device' }
- device_array.reject! { |item| item.text == 'News Server' }
- device_array.reject! { |item| item.text == 'POP3 Server' }
- device_array.reject! { |item| item.text == 'Printer' }
- device_array.reject! { |item| item.text == 'Router' }
- device_array.reject! { |item| item.text == 'Some Device' }
- device_array.reject! { |item| item.text == 'Switch' }
- device_array.reject! { |item| item.text == 'Time Server' }
- device_array.reject! { |item| item.text == 'Web Server' }
- device_array.reject! { |item| item.text == 'Windows Computer' }
- #limit to the first 10 items
- device_array = device_array.slice(0, 20)
- #format the array items
- dude_devices_partially_down = device_array.each_slice(2).map{|s| s.join(' @ ') }.join('<br/>')
- #send to devices_partially_down widget
- send_event('devices_partially_down', {text: dude_devices_partially_down})
- # Pull the page that lists all devices reporting acked down and store it in an array
- page = @agent.get 'http://DUDESERVER/dude/main.html?devType=XXXXXX&mapFilter=XXXXXX&sList=4&page=devices'
- device_array = page.links
- # Get rid of bullshit
- device_array.reject! { |item| item.text == 'chart' }
- device_array.reject! { |item| item.text == 'add note' }
- device_array.reject! { |item| item.text == 'Bridge' }
- device_array.reject! { |item| item.text == 'DNS Server' }
- device_array.reject! { |item| item.text == 'Dude Server' }
- device_array.reject! { |item| item.text == 'FTP Server' }
- device_array.reject! { |item| item.text == 'HP Jet Direct' }
- device_array.reject! { |item| item.text == 'IMAP4 Server' }
- device_array.reject! { |item| item.text == 'Mail Server' }
- device_array.reject! { |item| item.text == 'MikroTik Device' }
- device_array.reject! { |item| item.text == 'News Server' }
- device_array.reject! { |item| item.text == 'POP3 Server' }
- device_array.reject! { |item| item.text == 'Printer' }
- device_array.reject! { |item| item.text == 'Router' }
- device_array.reject! { |item| item.text == 'Some Device' }
- device_array.reject! { |item| item.text == 'Switch' }
- device_array.reject! { |item| item.text == 'Time Server' }
- device_array.reject! { |item| item.text == 'Web Server' }
- device_array.reject! { |item| item.text == 'Windows Computer' }
- #limit to the first 10 items
- device_array = device_array.slice(0, 20)
- #format the array items
- dude_devices_acked_down = device_array.each_slice(2).map{|s| s.join(' @ ') }.join('<br/>')
- #send to devices_acked_down widget
- send_event('devices_acked_down', {text: dude_devices_acked_down})
- #log out
- @agent = Mechanize.new
- @agent.cookie_jar = temp_jar
- page = @agent.post 'http://DUDESERVER/dude/login.html?drop_cookie=true'
- end
Advertisement
Add Comment
Please, Sign In to add comment