Monit - System Monitoring
monit is an extremely easy to install and configure system monitor which is very useful for checking local service (external services are possible but that's not really the strength of monit).
HTTP service check - blank Host: header bug
It appears that when monit is configured to check a URL of an HTTP service - eg:
check process thttpd with pidfile /var/run/thttpd.pid start program = "/etc/init.d/thttpd start" stop program = "/etc/init.d/thttpd stop" if failed url http://username:password@localhost/?monit_thttpd for 2 cycles then restart if 5 restarts within 5 cycles then timeout
That the HTTP headers sent include a blank Host: header when the URL is to localhost:
host$ strace -s 42 -p <pid of thttpd> ... read(1, "GET /?monit_thttpd HTTP/1.1\r\nHost: \r\n"..., 600) = 140 ...
According to the HTTP 1.1 RFC (2616) section 14.23 Host this is a valid request if no hostname was provided so monit is failing to pass through the expected information.
When monitoring apache this is not obvious because apache ignores the blank header. thttpd however returns a "400 Bad Request" - this seems to be a misinterpretation of the RFC which indicates that a bad request should be indicated for any HTTP 1.1 proxy that received a blank or missing Host header.
The work-around is to configure monit to check a non-localhost URL:
if failed url http://username:firstname.lastname@example.org/?monit_thttpd for 2 cycles then restart
As monit does include the Host: header in this case.