Check if Apple Services are online

After the hacking attempt of Apple Dev websites, all of Apple dev related websites went offline.

This script will send you a notification as soon a new service is online.

You’ll need Prowl, Ruby >= 1.9.2, the nokogiri and prowl gems.

Run this code via cron, and you’ll be notified directly on your phone.


#!/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;
  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 => '<YOUR_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

Download this code from GitHub: link

Updated Jan. 2, 2014: added “require ‘rubygems'” at the beginning of the script.

Leave a Reply

Your email address will not be published. Required fields are marked *

*