@@ -10,6 +10,13 @@ needs to store stateful information, consider writing a daemon that runs on its
1010own as opposed to an xinetd application. However, if your needs are light, and
1111you want HTTP REST-like capabilities, perhaps this meets your needs.
1212
13+ ##### Version 0.3 with support for HA Proxy HTTP header
14+ Version 0.3 was updated to parse HA Proxy's ` X-Haproxy-Server-State ` HTTP
15+ header when HAProxy uses the configuration ` option httpchk ` with `http-check
16+ send-state`. By default, this xinetd script can send results back to HA Proxy
17+ with both ` option tcp-check ` and ` option httpchk ` without differing
18+ configuration. See ** HA Proxy Use** below.
19+
1320
1421## Using for your purposes
1522
@@ -42,29 +49,43 @@ http_response 200 "Success"
4249
4350### Available functions
4451
45- #### get_http_req_uri_params_value < ; param-name> ;
52+ * #### get_http_req_uri_params_value < ; param-name> ;
4653This function will obtain the value of a paramter provided in the HTTP request.
4754``` bash
4855# if GET Request URI (GET_REQ_URI) is "/?uptime=seconds&format=json"
4956format_value=$( get_http_req_uri_params_value " format" )
5057# Result: format_value == json
5158```
5259
53- #### http_response < ; http-code> ; < ; message> ;
60+ * #### get_haproxy_server_state_value < ; param-name> ;
61+ This function will obtain the value of a paramter provided in the HTTP request
62+ header ** X-Haproxy-Server-State** .
63+ ``` bash
64+ # if `X-Haproxy-Server-State: UP; name=backend/server; node=haproxy-name; weight=1/2; scur=0/1; qcur=0; throttle=86%
65+ HA_NAME=$( get_haproxy_server_state_value name)
66+ # Result: HA_NAME == backend/server
67+ HA_WEIGHT=$( get_haproxy_server_state_value weight)
68+ # Result: HA_WEIGHT == 1/2
69+ HA_STATE=$( get_haproxy_server_state_value state)
70+ # Result: HA_STATE == UP
71+ ```
72+
73+
74+ * #### http_response < ; http-code> ; < ; message> ;
5475This function will return a HTTP response and exit.
5576It will do nothing and return if the --http-response option is not set to 1,
5677or if the request came from the command line and not as a HTTP request.
5778``` bash
5879http_response 301 " I did not find what you were looking for."
5980```
6081
61- #### decrease_health_value
82+ * #### decrease_health_value
6283This function will decrease the global health value
6384``` bash
6485decrease_health_value
6586```
6687
67- #### display_health_value
88+ * #### display_health_value
6889This function displays the global helath value in a HTTP response or standard
6990output for the command line, and then exits.
7091``` bash
@@ -76,7 +97,7 @@ display_health_value
7697
7798``` bash
7899linux$ xinetdhttpservice.sh --help
79- xinetd_http_service 0.2
100+ xinetd_http_service 0.3
80101https://github.com/rglaue/xinetd_bash_http_service
81102Copyright (C) 2018 Russell Glaue, CAIT, WIU < http://www.cait.org>
82103
@@ -107,7 +128,7 @@ Examples:
107128
108129### Test to see how HTTP headers are parsed
109130
110- #### HTTP GET
131+ * #### HTTP GET
111132
112133```bash
113134linux$ echo "GET /test123?var1=val1 HTTP/1.0" | xinetdhttpservice.sh --http-status --show-headers
@@ -124,7 +145,7 @@ HTTP_REQ_METHOD=GET
124145HTTP_REQ_URI_PARAMS=var1=val1
125146```
126147
127- #### HTTP POST
148+ * #### HTTP POST
128149
129150```bash
130151linux$ xinetdhttpservice.sh --show-headers <<HTTP_EOF
@@ -170,7 +191,7 @@ HTTP_SERVER=127.0.0.1:8080
170191--END:HTTP_POST_CONTENT--
171192```
172193
173- #### HTTP POST Config: MAX_HTTP_POST_LENGTH
194+ * #### HTTP POST Config: MAX_HTTP_POST_LENGTH
174195
175196At the top of the xinetdhttpservice.sh bash script, there is a global variable
176197that define the maximum allowed length of posted data. Posted data that has a
@@ -180,7 +201,7 @@ length greater than this will be cut off.
180201MAX_HTTP_POST_LENGTH=200
181202```
182203
183- #### HTTP POST Config: READ_BUFFER_LENGTH
204+ * #### HTTP POST Config: READ_BUFFER_LENGTH
184205
185206If a non-compliant HTTP client is posting data that is shorter than the
186207Content-Length, then the READ_BUFFER_LENGTH should be set to 1. By default
@@ -249,6 +270,62 @@ WEIGHT_VALUE=119
249270[xinetdhttpservice_config]: https://github.com/rglaue/xinetd_bash_http_service/blob/master/xinetdhttpservice_config
250271
251272
273+ ### As a HAProxy server check
274+
275+ First setup the xinetd service, as described previously. Once setup, you should
276+ be able to get the service status via TCP or HTTP check in HAProxy. This can be
277+ tested as follows. Both TCP and HTTP checks will work without differing
278+ configuration in the xinetd_bash_http_service script because the `http_response`
279+ function only delivers output if the client made an HTTP request.
280+
281+ * #### Testing the health checks
282+ ```bash
283+ # TCP Checks
284+ shell$ echo | nc 192.168.2.11 8080
285+ Service OK
286+ # HTTP Checks
287+ shell$ curl http://192.168.2.11:8080
288+ Service OK
289+ ```
290+
291+ * #### Ensure xinetd script outputs for both HTTP and TCP
292+ ```bash
293+ # At the end of your xinetd_bash_http_service script
294+ # send the HTTP response and exit
295+ http_response 200 "Service OK"
296+ # or send a TCP response and exit
297+ echo "Service OK"
298+ exit 0
299+ # end of script
300+ ```
301+
302+ * #### Configure HA Proxy
303+ ```bash
304+ frontend some-fe-server
305+ bind 192.168.1.1:1234
306+ mode tcp
307+ default_backend some-be-server-pool
308+
309+ # Both of these backends will work, but use http checks with the
310+ # ' http-check send-state' if you want to receive the HA Proxy state.
311+
312+ # tcp checks
313+ #backend some-be-server-pool
314+ # option tcp-check
315+ # tcp-check expect string "Service OK"
316+ # server srv1 192.168.2.11:80 check port 8080
317+ # server srv2 192.168.2.12:80 check port 8080
318+
319+ # http checks
320+ backend some-be-server-pool
321+ option httpchk GET /
322+ http-check send-state
323+ http-check expect string "Service OK"
324+ server srv1 192.168.2.11:80 check port 8080
325+ server srv2 192.168.2.12:80 check port 8080
326+ ```
327+
328+
252329## License
253330
254331Copyright (C) 2018 [Center for the Application of Information Technologies](http://www.cait.org),
0 commit comments