It's my job to cope with a minimum of 24 servers every week. I figured it might be smart to produce a script that queries all of them and determines whether they are "up" or otherwise.

  • The servers run either Apache2 or IIS7.
  • The hosting companies vary
  • You will find usually multiple sites on each server
  • The configurations are sporadic, there is not always a default apache "hello world" page whenever you access the ip directly.
  • Sites are Virtualhosts

I believed, would the easiest method to determine whether they are up be just taking one site from each server and making an http Mind request to make certain the response in the server is 200 OK? Clearly this is vulnerable to a "false positive" if:

  1. The website configuration/setup incorrectly returns a 200 OK if this should return a 4xx error code
  2. If someone site ( <VirtualHost> )'s configuration is disabled, or maybe they have moved to another server.

But typically, a Mind request and depending on 200 OK ought to be reliable, right? In addition to ensuring the domain's An archive matches how it is listed as incase of site moves.

Pseudo code:

import http

list = {
  '72.0.0.0' : 'domain.com',
  '71.0.0.0' : 'blah.com',
}

serverNames = {
  'jetty' : '72.0.0.0',
  'bob'   : '71.0.0.0'
}

for each ( list as server => domain ) { 
    headRequest = http.head( domain )
    if ( headRequest.response == 200 && http.arecord(domain) == server ) { 
       print serverNames[server] + ' is up ';
    } else {
       print 'Server is either down or the site attached to the server lookup has moved.';
    }
}

I'll most likely write the script in Python or PHP, but this would be to discuss the logic only.

Logic appears seem in my experience. I recommend stretching it to make use of the mod_status module in your apache servers. After doing all of your mind check, likewise try to seize /server-status and employ that to make sure that the server is good. I am thinking something similar to this:

statusRequest = http.get('/server-status')
if(statusRequest == 200) {
 // Make sure you don't have insane load averages, etc
}
else { /* Check something IIS specific, or just be happy the head check worked */ }

Another technique I have used previously would be to also perform a look for something which I understand should provide a 404. This way you've got a better possibility of knowing when the server is simply providing 200's to anybody that asks. (I first viewed it once because of a poor config)