Skip to content

Instantly share code, notes, and snippets.

@jhass
Created October 28, 2012 17:16
Show Gist options
  • Save jhass/3969183 to your computer and use it in GitHub Desktop.
Save jhass/3969183 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
ENV['RAILS_ENV'] ||= "production"
require 'rubygems'
require 'ansi_colors'
require './config/environment'
#user = User.find_by_username("mrzyx")
#handles = user.contacts.collect { |c| c.person.diaspora_handle }
handles = Person.all.collect { |person| person.diaspora_handle }
hosts = handles.collect { |handle| handle.split("@")[1] }.uniq.sort
online = 0
hosts.each do |host|
print "#{host}... "
begin
status = Faraday.get("http://#{host}/.well-known/host-meta").status
if status == 200
puts "online".ansi_green
online += 1
elsif [500,404].include?(status)
puts "offline (#{status})".ansi_red
else
puts "unknown (#{status})".ansi_yellow
end
rescue Errno::EHOSTUNREACH
puts "offline (no route to host)".ansi_red
rescue Errno::ETIMEDOUT
puts "offline (connection timed out)".ansi_red
rescue Faraday::Error::ConnectionFailed => e
puts "offline (#{e.message})".ansi_red
rescue FaradayMiddleware::RedirectLimitReached
puts "offline (redirect loop)".ansi_red
end
end
print "#{hosts.size}".ansi_blue
print " known hosts, "
print "#{online}".ansi_green
print " reachable, "
print "#{hosts.size-online}".ansi_red
puts " unreachable"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment