Skip to content

Instantly share code, notes, and snippets.

@sburlot
Last active December 20, 2015 13:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sburlot/6143548 to your computer and use it in GitHub Desktop.
Save sburlot/6143548 to your computer and use it in GitHub Desktop.
Monitor the Apple Status page and send a notification when a new service is enabled. See: http://blog.coriolis.ch/check-if-apple-services-are-online/
#!/usr/bin/ruby
# monitor the Apple Status page and send a notification when a new service is enabled
# Stephan Burlot, Coriolis Technologies, http://www.coriolis.ch
require 'rubygems'
require 'nokogiri'
require 'open-uri'
require 'yaml'
require 'prowl'
doc = Nokogiri::HTML(open('https://developer.apple.com/support/system-status/'))
script_dir = File.expand_path(File.dirname(__FILE__))
saved_service_filename = script_dir + "/services.yml"
#f = File.open("status.html")
#doc = Nokogiri::HTML(f)
#f.close
if (File.exists?(saved_service_filename))
saved_services = YAML::load_file saved_service_filename
else
saved_services = {}
end
services = {}
doc.xpath('//table[@class="status-table"]/tr/td').each do | td |
online = td.attr('class')
key = td.at_xpath('.//span').content.strip;
services[key] = online;
end
puts services
if (saved_services.length > 0)
# puts saved_services
result = {}
services.each {|key, value| result[key] = services[key] if saved_services[key] != value }
if !result.empty?
online = []
offline = []
result.each { |key, value| if value == "online"
online.push(key)
else
offline.push(key);
end
}
puts "Changed services: " + result.to_s
notif_text = ""
if (online.count > 0)
notif_text = online.join(", ") + (online.count > 1 ? " are ":" is ") + "now online. ";
end
if (offline.count > 0)
notif_text += offline.join(", ") + (offline.count > 1 ? " are ":" is ") + "now offline.";
end
puts notif_text
puts "online: " + online.to_s
puts "offline: " + offline.to_s
Prowl.add(:apikey => '<PROWL_API_KEY>',
:application => "Apple Status",
:event => '',
:description => notif_text,
:priority => 0
)
end
end
# save current services
File.open(saved_service_filename, "w") do |file|
file.write services.to_yaml
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment