Project No Name (dot com)

This is kind of a cool concept. These days I guess it’s not enough to be just an interactive agency or just a traditional advertising company, you need to be able to do it all. Here it looks as though two companies have come to realize this and decided to do a merger. They set up a campaign to get the public to come up with a new name for what the company will be called. $1,000 bucks to whoever comes up with the best one and the best part is that you can submit as many names as you want! Now how many agencies have the balls to do something like that? Give it a shot!

Project No Name

Project No Name

http://www.projectnoname.com/

No Comments


Ruby Script to Check Site Availability

Recently, I’ve been looking around for scripts to check the availability of websites I’m hosting, then email me a status message if there is anything I should be worrying about. There are many services out there, but none are free. Fortunately this kind of thing can be done with a little ruby script and cron job.

Requirements

  • SMTP server.
  • Ruby 1.8.6 - This script uses core classes of Ruby and doesn’t require any rubygems
  • Ability to add cron jobs to your machine

Plan

Now, let’s think out some solutions for how we can check on a site’s availability. We could ping the server, but that only checks that the box is up and running. It doesn’t necessarily mean that our HTTP Service is serving up pages correctly. We could use curl or wget to pull down the default page being served, but what if it’s a holding space page, or a 404 error? This method would basically only tell us if the webserver is running or not, same as the ping method. Alternatively, we could test the to see what the response code of the page is. This way we can also find out what type of issue we are having on the server.

I also want this script to be a little more robust. Instead of having a hardcoded URL in my script,  I want it to pull a list of urls from a txt file. I also want each url report to be emailed to different email addresses since some of these sites are for work and some are personal.

Checking the Response Codes

There are lots of different response codes that we could receive from the server. The most familiar for anyone who’s ever browsed the net is the infamous 404 Page Not Found error. Let’s quickly take a look at what this error code means. Wikipedia states a 4** message means that “the request contains bad syntax or cannot be fulfilled.”, in english, something went wrong on the web surfers side. This can be because of a mistyped URL or the result of a clicked link that took us to a page that’s no longer available or has been moved. Now, the second two numbers tell us more specifically what kind of issue we’ve found, in our case *04, which Wikipedia explains as “The requested resource could not be found but may be available again in the future. Subsequent requests by the client are permissible.” or in other words, it’s lost, maybe only temporarily, but we can keep trying if we want.

Other response code groups include the following:

I’m not really interested in being notified of anything that starts with a 2**, since that means the site is up and functioning correctly. 3** are redirect codes, these might be useful, but I don’t really care about them. I should know if one of my sites is being redirected because I would have had to set it up that way. I am only going to check if the response code starts with a 2xx or 3xx, if it does then were fine and I dont need to be notified. If it doesn’t, then there’s an issue and I need to know about it.

To check the reponse code of the page, Ruby has a class in it’s core called Net:HTTPResponse, which will go out and touch a URL and return the reponse code the server supplied.

Sending the Email

This script uses the Ruby class Net::SMTP, which allows communication with an SMTP server. On my box I have postfix setup, which runs on port 25. When I send the email I want to be notified which url went down and what the response code is. I also added the HTTP version in there just in case.

Automatically Running the Script

To get this script to run automatically, I’m going to need to setup a cron job. To create a cron job we need to add a line to our crontab file, which can be found at /etc/crontab.

# [minutes] [hours] [day of month] [month] [day of week] [user] [command]
0,15,30,45 * * * * bawigga ~/scripts/check_uptime.rb

Above we can see that I set the script to run on the 0th, 15th, 30th, and 45th minute, of any (*) hour of any day of the month, of any month, of any day of the week, under the username bawigga, and we want to execute the check_uptime.rb script in my home/scripts directory.

The Script

#!/usr/bin/ruby
 
require 'net/http'
require 'net/smtp'
 
# Brian Wigginton
# http://www.bwigg.com/2008/10/ruby-script-to-check-site-availability/
# 10/7/2008
#
# Check's availabilty of a website. Needs to be run via a cron job.
# Example cron job line to be placed in crontab
#
# 0,15,30,45 * * * * username ~/scripts/check_uptime.rb
#
# This script uses a txt file to look for urls and email addresses.
# This text file needs to be in the following format
# -- lines with beginning with # signs will be ignored
# -- first thing should be the url
# -- then a space
# -- then email addresses seperated by commas, no white space.
# EXAMPLE
#       example.com admin@axample.com,bob@example.com
 
File.open("/home/user/scripts/sites.txt").each { |line|
	# get rid of CRLF
	line.chomp!
 
	next if(line[0..0] == '#' || line.empty?)
 
	url, emails = line.split(' ')
	emails = emails.split(",")
 
	# check if http:// was in the url if not add it in there
	url.insert(0, "http://") unless(url.match(/^http\:\/\//))
 
	# Get the HTTP_RESPONSE from the site we are checking
	res = Net::HTTP.get_response(URI.parse(url.to_s))
 
	# Check the response code and send an email if the code is bad
	unless(res.code =~ /2|3\d{2}/ ) then
		from = "admin@example.com"
		message = "From: admin@example.com\nSubject: #{url} Unavailable\n\n#{url} - #{res.code} - #{res.message}\nHTTP Version - #{res.http_version}\n\n"
		begin
			Net::SMTP.start('localhost',25 , 'example.com') do |smtp|
			smtp.send_message(message, from, emails)
		end
		rescue Exception => e
			print "Exception occured: " + e
		end
	end
}

1 Comment


[TIP] Ruby GUI Applications and Empty Console Window

While writing a Ruby GUI app I kept seeing an empty console window. As it turns out there are two ruby executables that you can use to run your Ruby scripts: ruby, which is a CUI (Console User Interface) and rubyw, a GUI (Graphical User Interface) used to launch GUI Apps. Using rubyw will prevent that empty console from showing up. Hope this helps someone!

# rubyw myapp.rb

Edit - 8/7/08

There are actually two filetypes you can use for your ruby scripts. .rb files will run with the ruby CLI interpreter, while .rbw scripts will run with the GUI interpreter. Remember though, with no console window you wont get any status messages or debug messages. While writing and testing your GUI apps use the ruby interpreter then when your finished change the filetype to .rbw.

Tags: ,

No Comments


Strange Rendering of Fonts in Firefox 3

Firefox 3 was having some font rendering issues on my machine. Certain web sites were displaying a wierd bold looking font in place of the default font described in the CSS. See this screenshot. After doing some searching around the internet I found out the issue.

Early in the year I had installed Adobe Type Manager and added a bunch of Helvetica Postscript Type-1 fonts. These were for some reason being used as Firefox’s default font. Removing them from the system fixed the issue.

1 Comment


Learning a New Language

Larry O’Brien over at knowing.net has a great series called 15 Exercises to Know a Programming Language, It’s an older article but after going through parts 1-3, theres really nothing in there that changes often enough to warrant any kind of an update.

  • Part 1 gets you used to using some of the more basic features of a language including, calculations, the standard libraries, file i/o, GUI development, and debugging.
  • Part 2 introduces some more advanced data structures, object oriented programming, idioms, memory issues, design patterns, and concurrency.
  • Part 3 presents web interaction, libraries, encryption, and databases.

There’s obviously a lot to learn when starting to cover a new language. Larry’s posted some great ideas for getting used to a new language, and once you accomplish all these, you go from playing with the language to knowing the language.

No Comments


Linux w/ Mac Scrolling

Is it possible to make it so that I laptop running synaptic drivers can make it so that you can scroll pages with two fingers on the pad?

Update: Thanks to okke in the comments, all you have to do is add a line to your xorg.conf file to enable 2 finger scrolling. There’s a wiki entry on the Gentoo Wiki about doing so.

2 Comments


New Wordpress Setup

After using Drupal for about 6 months now I felt it was time to move on to something a little easier to use. Welcome wordpress, its popularity is unrivaled. I’ll be testing this out over the next few weeks, to see if this is what I am searching for.

2 Comments



SetPageWidth