On what terms can I rely on a script that determines if my servers are up?

I usually deal with at least two dozen servers on a weekly basis. I thought it would be nice to create a script that asks each of them and determines whether they are up or not.

  • Servers run either Apache2 or IIS7.
  • Hosting Providers Are Changing
  • Usually on each server there are several sites.
  • The settings are incompatible, there is always an apache default “hello world” page when you access ip directly.
  • All Virtualhosts Sites

I thought there would be a better way to determine if they should just take one site from each server and make a http HEAD request to make sure the response from server 200? Obviously, this would be prone to “false positive” if:

  • Site configuration / setup incorrectly returns 200 OK when it should return a 4xx error code.
  • If the configuration of an individual site ( <VirtualHost> ) is disabled or the site has moved to another server.

But for the most part, the HEAD request and 200 OK usage should be reliable, right? . Also, make sure that the record in domain A matches what it indicated, as this leads to the site moving.

Pseudocode:

 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 will probably write a script in Python or PHP, but this question should only discuss logic.

+4
source share
1 answer

The logic seems sound to me. I would suggest expanding it to use the mod_status module on your apache servers. After checking the head, try also to capture / server status and use this to verify that your server is healthy. I think something like 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 method that I have used in the past is to also check for something that I know should give 404. Thus, you will have a better chance of finding out if the server just sends 200 to everyone who asks. (I saw it once because of a bad configuration)

+3
source

All Articles