Matt Feenstra is an Architect and Developer, living and working in Palm Desert, CA
Monday, September 30, 2013
httpd status code / health check
#!/usr/bin/perl -w
use strict;
# Matt Feenstra 09/30/13
my $result = `/usr/bin/curl -IL -m 10 --write-out \"\%{http_code}\" --silent --output /dev/null $ARGV[0]`;
if($result =~ /(\d{1,3})/) {
if($1 == 0) { print "Error, httpd not working: $ARGV[0]\n"; exit(1); }
if($1 < 200 && $1 > 0) { print "informational: $result\n"; exit(0); }
if($1 >= 200 && $1 < 300) { print "Success: $result\n"; exit(0); }
if($1 >= 300 && $1 < 400) { print "redirected: $result\n"; exit(0); }
if($1 >= 400 && $1 < 500) { print "client error: $result\n"; exit(1); }
if($1 >= 500 && $1 < 600) { print "server error: $result\n"; exit(1); }
}
else { print "unknown result: $result\n"; exit(1); }
Subscribe to:
Posts (Atom)