[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[monit-dev] Add a hostheader option to monit's http check.
From: |
Brady |
Subject: |
[monit-dev] Add a hostheader option to monit's http check. |
Date: |
Wed, 30 Sep 2009 17:58:33 -0700 |
Hello,
Hopefully this is the right approach for patch submission. This patch
adds support for a Host: header in the http process check module. This
allows the checking of an apache instance that serves virtual hosts
but throws
a 404 or other such error on the default host.
I did a cursory test on this using the config:
check process test with pidfile "/tmp/test.pid"
start program = "/bin/bash -c 'echo $$ > /tmp/test.pid ; /usr/bin/
nc -k -l 6000 | tee /tmp/test.txt'"
stop program = "/bin/false"
if failed host localhost port 6000 protocol http and request '/
testing' hostheader 'example.com' with timeout 20 seconds for 2 cycles
then restart
This produced the request:
GET /testing HTTP/1.1
Host: example.com
Accept: */*
Connection: close
User-Agent: monit/5.1
Please let me know if you have any comments, questions, or if I have
done this completely wrong. =)
Index: monitor.h
===================================================================
--- monitor.h (revision 34)
+++ monitor.h (working copy)
@@ -449,6 +449,7 @@
int port; /**<
Portnumber */
char *request; /**< Specific protocol
request */
char *request_checksum; /**< The optional checksum for a req.
document */
+ char *request_hostheader; /**< The optional Host: header
to use. */
int request_hashtype; /**< The optional type of hash for a req.
document */
char *pathname; /**< Pathname, in case of an
UNIX socket */
char *address; /**< Human readable destination of
the socket */
Index: protocols/http.c
===================================================================
--- protocols/http.c (revision 34)
+++ protocols/http.c (working copy)
@@ -112,6 +112,7 @@
char host[STRLEN];
char auth[STRLEN]= {0};
const char *request= NULL;
+ const char *hostheader= NULL;
ASSERT(s);
@@ -120,7 +121,10 @@
ASSERT(P);
request= P->request?P->request:"/";
-
+
+ Util_getHTTPHostHeader(s, host, STRLEN);
+ hostheader= P->request_hostheader?P->request_hostheader:host;
+
if(socket_print(s,
"GET %s HTTP/1.1\r\n"
"Host: %s\r\n"
@@ -128,8 +132,8 @@
"Connection: close\r\n"
"User-Agent: %s/%s\r\n"
"%s\r\n",
- request, Util_getHTTPHostHeader(s, host, STRLEN),
- prog, VERSION, get_auth_header(P, auth, STRLEN)) < 0) {
+ request, hostheader, prog, VERSION,
+ get_auth_header(P, auth, STRLEN)) < 0) {
LogError("HTTP: error sending data -- %s\n", STRERROR);
return FALSE;
}
Index: p.y
===================================================================
--- p.y (revision 34)
+++ p.y (working copy)
@@ -289,7 +289,7 @@
%token CHILDREN SYSTEM
%token RESOURCE MEMORY TOTALMEMORY LOADAVG1 LOADAVG5 LOADAVG15
%token MODE ACTIVE PASSIVE MANUAL CPU TOTALCPU CPUUSER CPUSYSTEM
CPUWAIT
-%token GROUP REQUEST DEPENDS BASEDIR SLOT EVENTQUEUE SECRET
+%token GROUP REQUEST DEPENDS BASEDIR SLOT EVENTQUEUE SECRET HOSTHEADER
%token UID GID MMONIT INSTANCE USERNAME PASSWORD
%token TIMESTAMP CHANGED SECOND MINUTE HOUR DAY
%token SSLAUTO SSLV2 SSLV3 TLSV1 CERTMD5
@@ -1063,17 +1063,23 @@
;
request : /* EMPTY */
- | REQUEST PATH {
+ | REQUEST PATH hostheader {
portset.request = Util_urlEncode($2);
FREE($2);
}
- | REQUEST PATH CHECKSUM STRING {
+ | REQUEST PATH CHECKSUM STRING hostheader {
portset.request = Util_urlEncode($2);
FREE($2);
portset.request_checksum = $4;
}
;
+hostheader : /* EMPTY */
+ | hostheader STRING {
+ portset.request_hostheader = $2;
+ }
+ ;
+
secret : SECRET STRING {
portset.request = $2;
}
@@ -2014,19 +2020,20 @@
ASSERT(port);
NEW(p);
- p->port = port->port;
- p->type = port->type;
- p->socket = port->socket;
- p->family = port->family;
- p->action = port->action;
- p->timeout = port->timeout;
- p->request = port->request;
- p->generic = port->generic;
- p->protocol = port->protocol;
- p->pathname = port->pathname;
- p->hostname = port->hostname;
- p->url_request = port->url_request;
- p->request_checksum = port->request_checksum;
+ p->port = port->port;
+ p->type = port->type;
+ p->socket = port->socket;
+ p->family = port->family;
+ p->action = port->action;
+ p->timeout = port->timeout;
+ p->request = port->request;
+ p->generic = port->generic;
+ p->protocol = port->protocol;
+ p->pathname = port->pathname;
+ p->hostname = port->hostname;
+ p->url_request = port->url_request;
+ p->request_checksum = port->request_checksum;
+ p->request_hostheader = port->request_hostheader;
memcpy(&p->ApacheStatus, &port->ApacheStatus, sizeof(struct
apache_status));
if (p->request_checksum) {
Index: gc.c
===================================================================
--- gc.c (revision 34)
+++ gc.c (working copy)
@@ -383,6 +383,7 @@
FREE((*p)->pathname);
FREE((*p)->SSL.certmd5);
FREE((*p)->request_checksum);
+ FREE((*p)->request_hostheader);
FREE(*p);
}
- [monit-dev] Add a hostheader option to monit's http check.,
Brady <=