I usually deal with at least two dozen servers on a weekly basis. I thought it would be a good idea to create a script that queries each of them and determines whether they're "up" or not.
- The servers run either Apache2 or IIS7.
- The hosting providers vary
- There are usually multiple sites on each server
- The setups are inconsistent, there isn't always a default apache "hello world" page when you access the ip directly.
- Sites are all Virtualhosts
I was thinking, would the best way to determine if they're up be just taking one site from each server and making an http HEAD request to make sure the response from the server is 200 OK? Obviously this would be prone to a "false positive" if:
- The site configuration/setup improperly returns a 200 OK when it should return a 4xx error code
- If an individual site (
<VirtualHost>
)'s configuration is disabled, or if the site has moved to a different server.
But for the most part, a HEAD request and relying on 200 OK should be reliable, right? As well as making sure the domain's A record matches what it's 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 probably write the script in Python or PHP, but this question is to discuss the logic only.