diff options
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/check_http.c | 21 | ||||
-rw-r--r-- | plugins/t/check_http.t | 12 |
2 files changed, 26 insertions, 7 deletions
diff --git a/plugins/check_http.c b/plugins/check_http.c index 58cf83cf..e25e5db2 100644 --- a/plugins/check_http.c +++ b/plugins/check_http.c | |||
@@ -89,7 +89,8 @@ double critical_time = 0; | |||
89 | int check_critical_time = FALSE; | 89 | int check_critical_time = FALSE; |
90 | char user_auth[MAX_INPUT_BUFFER] = ""; | 90 | char user_auth[MAX_INPUT_BUFFER] = ""; |
91 | int display_html = FALSE; | 91 | int display_html = FALSE; |
92 | char *http_opt_headers; | 92 | char **http_opt_headers; |
93 | int http_opt_headers_count = 0; | ||
93 | int onredirect = STATE_OK; | 94 | int onredirect = STATE_OK; |
94 | int use_ssl = FALSE; | 95 | int use_ssl = FALSE; |
95 | int verbose = FALSE; | 96 | int verbose = FALSE; |
@@ -245,7 +246,12 @@ process_arguments (int argc, char **argv) | |||
245 | asprintf (&user_agent, "User-Agent: %s", optarg); | 246 | asprintf (&user_agent, "User-Agent: %s", optarg); |
246 | break; | 247 | break; |
247 | case 'k': /* Additional headers */ | 248 | case 'k': /* Additional headers */ |
248 | asprintf (&http_opt_headers, "%s", optarg); | 249 | if (http_opt_headers_count == 0) |
250 | http_opt_headers = malloc (sizeof (char *) * (++http_opt_headers_count)); | ||
251 | else | ||
252 | http_opt_headers = realloc (http_opt_headers, sizeof (char *) * (++http_opt_headers_count)); | ||
253 | http_opt_headers[http_opt_headers_count - 1] = optarg; | ||
254 | //asprintf (&http_opt_headers, "%s", optarg); | ||
249 | break; | 255 | break; |
250 | case 'L': /* show html link */ | 256 | case 'L': /* show html link */ |
251 | display_html = TRUE; | 257 | display_html = TRUE; |
@@ -767,9 +773,12 @@ check_http (void) | |||
767 | asprintf (&buf, "%sHost: %s\r\n", buf, host_name); | 773 | asprintf (&buf, "%sHost: %s\r\n", buf, host_name); |
768 | 774 | ||
769 | /* optionally send any other header tag */ | 775 | /* optionally send any other header tag */ |
770 | if (http_opt_headers) { | 776 | if (http_opt_headers_count) { |
771 | for ((pos = strtok(http_opt_headers, INPUT_DELIMITER)); pos; (pos = strtok(NULL, INPUT_DELIMITER))) | 777 | for (i = 0; i < http_opt_headers_count ; i++) { |
772 | asprintf (&buf, "%s%s\r\n", buf, pos); | 778 | for ((pos = strtok(http_opt_headers[i], INPUT_DELIMITER)); pos; (pos = strtok(NULL, INPUT_DELIMITER))) |
779 | asprintf (&buf, "%s%s\r\n", buf, pos); | ||
780 | } | ||
781 | free(http_opt_headers); | ||
773 | } | 782 | } |
774 | 783 | ||
775 | /* optionally send the authentication info */ | 784 | /* optionally send the authentication info */ |
@@ -1277,7 +1286,7 @@ certificate expiration times.")); | |||
1277 | -A, --useragent=STRING\n\ | 1286 | -A, --useragent=STRING\n\ |
1278 | String to be sent in http header as \"User Agent\"\n\ | 1287 | String to be sent in http header as \"User Agent\"\n\ |
1279 | -k, --header=STRING\n\ | 1288 | -k, --header=STRING\n\ |
1280 | Any other tags to be sent in http header, separated by semicolon\n\ | 1289 | Any other tags to be sent in http header. Use multiple times for additional headers\n\ |
1281 | -L, --link=URL\n\ | 1290 | -L, --link=URL\n\ |
1282 | Wrap output in HTML link (obsoleted by urlize)\n\ | 1291 | Wrap output in HTML link (obsoleted by urlize)\n\ |
1283 | -f, --onredirect=<ok|warning|critical|follow>\n\ | 1292 | -f, --onredirect=<ok|warning|critical|follow>\n\ |
diff --git a/plugins/t/check_http.t b/plugins/t/check_http.t index 408906d9..3154151f 100644 --- a/plugins/t/check_http.t +++ b/plugins/t/check_http.t | |||
@@ -9,7 +9,7 @@ use strict; | |||
9 | use Test::More; | 9 | use Test::More; |
10 | use NPTest; | 10 | use NPTest; |
11 | 11 | ||
12 | plan tests => 12; | 12 | plan tests => 14; |
13 | 13 | ||
14 | my $successOutput = '/OK.*HTTP.*second/'; | 14 | my $successOutput = '/OK.*HTTP.*second/'; |
15 | 15 | ||
@@ -34,6 +34,16 @@ cmp_ok( $res->return_code, '==', 0, "Webserver $host_tcp_http responded" ); | |||
34 | like( $res->output, $successOutput, "Output OK" ); | 34 | like( $res->output, $successOutput, "Output OK" ); |
35 | 35 | ||
36 | $res = NPTest->testCmd( | 36 | $res = NPTest->testCmd( |
37 | "./check_http $host_tcp_http -wt 300 -ct 600 -v -v -v -k 'bob:there;fred:here'" | ||
38 | ); | ||
39 | like( $res->output, '/bob:there\r\nfred:here\r\n/', "Got headers, delimited with ';'" ); | ||
40 | |||
41 | $res = NPTest->testCmd( | ||
42 | "./check_http $host_tcp_http -wt 300 -ct 600 -v -v -v -k 'bob:there;fred:here' -k 'carl:frown'" | ||
43 | ); | ||
44 | like( $res->output, '/bob:there\r\nfred:here\r\ncarl:frown\r\n/', "Got headers with multiple -k options" ); | ||
45 | |||
46 | $res = NPTest->testCmd( | ||
37 | "./check_http $host_nonresponsive -wt 1 -ct 2" | 47 | "./check_http $host_nonresponsive -wt 1 -ct 2" |
38 | ); | 48 | ); |
39 | cmp_ok( $res->return_code, '==', 2, "Webserver $host_nonresponsive not responding" ); | 49 | cmp_ok( $res->return_code, '==', 2, "Webserver $host_nonresponsive not responding" ); |