summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--NEWS1
-rw-r--r--plugins/check_http.c23
-rwxr-xr-xplugins/tests/check_http.t69
3 files changed, 82 insertions, 11 deletions
diff --git a/NEWS b/NEWS
index f4e662a..01e8663 100644
--- a/NEWS
+++ b/NEWS
@@ -1,6 +1,7 @@
1This file documents the major additions and syntax changes between releases. 1This file documents the major additions and syntax changes between releases.
2 2
31.4.14 ... 31.4.14 ...
4 check_http has options to specify the HTTP method (#2155152)
4 check_users thresholds were not working excatly as documented (>= rather than >) 5 check_users thresholds were not working excatly as documented (>= rather than >)
5 Updated tinderbox_build script to point to new tinderbox server 6 Updated tinderbox_build script to point to new tinderbox server
6 check_ifoperstatus -n flag now works as expected (sf.net #1569488) 7 check_ifoperstatus -n flag now works as expected (sf.net #1569488)
diff --git a/plugins/check_http.c b/plugins/check_http.c
index 69ed2fa..df5daf2 100644
--- a/plugins/check_http.c
+++ b/plugins/check_http.c
@@ -187,6 +187,7 @@ process_arguments (int argc, char **argv)
187 {"nohtml", no_argument, 0, 'n'}, 187 {"nohtml", no_argument, 0, 'n'},
188 {"ssl", no_argument, 0, 'S'}, 188 {"ssl", no_argument, 0, 'S'},
189 {"post", required_argument, 0, 'P'}, 189 {"post", required_argument, 0, 'P'},
190 {"method", required_argument, 0, 'j'},
190 {"IP-address", required_argument, 0, 'I'}, 191 {"IP-address", required_argument, 0, 'I'},
191 {"url", required_argument, 0, 'u'}, 192 {"url", required_argument, 0, 'u'},
192 {"port", required_argument, 0, 'p'}, 193 {"port", required_argument, 0, 'p'},
@@ -228,7 +229,7 @@ process_arguments (int argc, char **argv)
228 } 229 }
229 230
230 while (1) { 231 while (1) {
231 c = getopt_long (argc, argv, "Vvh46t:c:w:A:k:H:P:T:I:a:e:p:s:R:r:u:f:C:nlLSm:M:N", longopts, &option); 232 c = getopt_long (argc, argv, "Vvh46t:c:w:A:k:H:P:j:T:I:a:e:p:s:R:r:u:f:C:nlLSm:M:N", longopts, &option);
232 if (c == -1 || c == EOF) 233 if (c == -1 || c == EOF)
233 break; 234 break;
234 235
@@ -344,10 +345,16 @@ process_arguments (int argc, char **argv)
344 strncpy (user_auth, optarg, MAX_INPUT_BUFFER - 1); 345 strncpy (user_auth, optarg, MAX_INPUT_BUFFER - 1);
345 user_auth[MAX_INPUT_BUFFER - 1] = 0; 346 user_auth[MAX_INPUT_BUFFER - 1] = 0;
346 break; 347 break;
347 case 'P': /* HTTP POST data in URL encoded format */ 348 case 'P': /* HTTP POST data in URL encoded format; ignored if settings already */
348 if (http_method || http_post_data) break; 349 if (! http_post_data)
349 http_method = strdup("POST"); 350 http_post_data = strdup (optarg);
350 http_post_data = strdup (optarg); 351 if (! http_method)
352 http_method = strdup("POST");
353 break;
354 case 'j': /* Set HTTP method */
355 if (http_method)
356 free(http_method);
357 http_method = strdup (optarg);
351 break; 358 break;
352 case 's': /* string or substring */ 359 case 's': /* string or substring */
353 strncpy (string_expect, optarg, MAX_INPUT_BUFFER - 1); 360 strncpy (string_expect, optarg, MAX_INPUT_BUFFER - 1);
@@ -817,7 +824,7 @@ check_http (void)
817 asprintf (&buf, "%sAuthorization: Basic %s\r\n", buf, auth); 824 asprintf (&buf, "%sAuthorization: Basic %s\r\n", buf, auth);
818 } 825 }
819 826
820 /* either send http POST data */ 827 /* either send http POST data (any data, not only POST)*/
821 if (http_post_data) { 828 if (http_post_data) {
822 if (http_content_type) { 829 if (http_content_type) {
823 asprintf (&buf, "%sContent-Type: %s\r\n", buf, http_content_type); 830 asprintf (&buf, "%sContent-Type: %s\r\n", buf, http_content_type);
@@ -1313,6 +1320,8 @@ print_help (void)
1313 printf (" %s\n", _("URL to GET or POST (default: /)")); 1320 printf (" %s\n", _("URL to GET or POST (default: /)"));
1314 printf (" %s\n", "-P, --post=STRING"); 1321 printf (" %s\n", "-P, --post=STRING");
1315 printf (" %s\n", _("URL encoded http POST data")); 1322 printf (" %s\n", _("URL encoded http POST data"));
1323 printf (" %s\n", "-j, --method=STRING (for example: HEAD, OPTIONS, TRACE, PUT, DELETE)");
1324 printf (" %s\n", _("Set HTTP method."));
1316 printf (" %s\n", "-N, --no-body"); 1325 printf (" %s\n", "-N, --no-body");
1317 printf (" %s\n", _("Don't wait for document body: stop reading after headers.")); 1326 printf (" %s\n", _("Don't wait for document body: stop reading after headers."));
1318 printf (" %s\n", _("(Note that this still does an HTTP GET or POST, not a HEAD.)")); 1327 printf (" %s\n", _("(Note that this still does an HTTP GET or POST, not a HEAD.)"));
@@ -1396,5 +1405,5 @@ print_usage (void)
1396 printf (" [-a auth] [-f <ok | warn | critcal | follow>] [-e <expect>]\n"); 1405 printf (" [-a auth] [-f <ok | warn | critcal | follow>] [-e <expect>]\n");
1397 printf (" [-s string] [-l] [-r <regex> | -R <case-insensitive regex>] [-P string]\n"); 1406 printf (" [-s string] [-l] [-r <regex> | -R <case-insensitive regex>] [-P string]\n");
1398 printf (" [-m <min_pg_size>:<max_pg_size>] [-4|-6] [-N] [-M <age>] [-A string]\n"); 1407 printf (" [-m <min_pg_size>:<max_pg_size>] [-4|-6] [-N] [-M <age>] [-A string]\n");
1399 printf (" [-k string] [-S] [-C <age>] [-T <content-type>]\n"); 1408 printf (" [-k string] [-S] [-C <age>] [-T <content-type>] [-j method]\n");
1400} 1409}
diff --git a/plugins/tests/check_http.t b/plugins/tests/check_http.t
index 6b932d9..d54932e 100755
--- a/plugins/tests/check_http.t
+++ b/plugins/tests/check_http.t
@@ -33,9 +33,7 @@ if ($pid) {
33 print "Please contact me at: <URL:", $d->url, ">\n"; 33 print "Please contact me at: <URL:", $d->url, ">\n";
34 while (my $c = $d->accept ) { 34 while (my $c = $d->accept ) {
35 while (my $r = $c->get_request) { 35 while (my $r = $c->get_request) {
36 if ($r->method eq "GET" and $r->url->path eq "/xyzzy") { 36 if ($r->method eq "GET" and $r->url->path =~ m^/statuscode/(\d+)^) {
37 $c->send_file_response("/etc/passwd");
38 } elsif ($r->method eq "GET" and $r->url->path =~ m^/statuscode/(\d+)^) {
39 $c->send_basic_header($1); 37 $c->send_basic_header($1);
40 $c->send_crlf; 38 $c->send_crlf;
41 } elsif ($r->method eq "GET" and $r->url->path =~ m^/file/(.*)^) { 39 } elsif ($r->method eq "GET" and $r->url->path =~ m^/file/(.*)^) {
@@ -47,6 +45,18 @@ if ($pid) {
47 $c->send_crlf; 45 $c->send_crlf;
48 sleep 1; 46 sleep 1;
49 $c->send_response("slow"); 47 $c->send_response("slow");
48 } elsif ($r->url->path eq "/method") {
49 if ($r->method eq "DELETE") {
50 $c->send_error(RC_METHOD_NOT_ALLOWED);
51 } elsif ($r->method eq "foo") {
52 $c->send_error(RC_NOT_IMPLEMENTED);
53 } else {
54 $c->send_status_line(200, $r->method);
55 }
56 } elsif ($r->url->path eq "/postdata") {
57 $c->send_basic_header;
58 $c->send_crlf;
59 $c->send_response($r->method.":".$r->content);
50 } else { 60 } else {
51 $c->send_error(RC_FORBIDDEN); 61 $c->send_error(RC_FORBIDDEN);
52 } 62 }
@@ -63,7 +73,7 @@ if ($ARGV[0] && $ARGV[0] eq "-d") {
63} 73}
64 74
65if (-x "./check_http") { 75if (-x "./check_http") {
66 plan tests => 19; 76 plan tests => 39;
67} else { 77} else {
68 plan skip_all => "No check_http compiled"; 78 plan skip_all => "No check_http compiled";
69} 79}
@@ -119,3 +129,54 @@ $result = NPTest->testCmd( $cmd );
119is( $result->return_code, 2, $cmd); 129is( $result->return_code, 2, $cmd);
120like( $result->output, '/^HTTP CRITICAL - Invalid HTTP response received from host on port (\d+): HTTP/1.1 203 Non-Authoritative Information/', "Output correct: ".$result->output ); 130like( $result->output, '/^HTTP CRITICAL - Invalid HTTP response received from host on port (\d+): HTTP/1.1 203 Non-Authoritative Information/', "Output correct: ".$result->output );
121 131
132$cmd = "$command -j HEAD -u /method";
133$result = NPTest->testCmd( $cmd );
134is( $result->return_code, 0, $cmd);
135like( $result->output, '/^HTTP OK HTTP/1.1 200 HEAD - 19 bytes in ([\d\.]+) seconds/', "Output correct: ".$result->output );
136
137$cmd = "$command -j POST -u /method";
138$result = NPTest->testCmd( $cmd );
139is( $result->return_code, 0, $cmd);
140like( $result->output, '/^HTTP OK HTTP/1.1 200 POST - 19 bytes in ([\d\.]+) seconds/', "Output correct: ".$result->output );
141
142$cmd = "$command -j GET -u /method";
143$result = NPTest->testCmd( $cmd );
144is( $result->return_code, 0, $cmd);
145like( $result->output, '/^HTTP OK HTTP/1.1 200 GET - 18 bytes in ([\d\.]+) seconds/', "Output correct: ".$result->output );
146
147$cmd = "$command -u /method";
148$result = NPTest->testCmd( $cmd );
149is( $result->return_code, 0, $cmd);
150like( $result->output, '/^HTTP OK HTTP/1.1 200 GET - 18 bytes in ([\d\.]+) seconds/', "Output correct: ".$result->output );
151
152$cmd = "$command -P foo -u /method";
153$result = NPTest->testCmd( $cmd );
154is( $result->return_code, 0, $cmd);
155like( $result->output, '/^HTTP OK HTTP/1.1 200 POST - 19 bytes in ([\d\.]+) seconds/', "Output correct: ".$result->output );
156
157$cmd = "$command -j DELETE -u /method";
158$result = NPTest->testCmd( $cmd );
159is( $result->return_code, 1, $cmd);
160like( $result->output, '/^HTTP WARNING: HTTP/1.1 405 Method Not Allowed/', "Output correct: ".$result->output );
161
162$cmd = "$command -j foo -u /method";
163$result = NPTest->testCmd( $cmd );
164is( $result->return_code, 2, $cmd);
165like( $result->output, '/^HTTP CRITICAL: HTTP/1.1 501 Not Implemented/', "Output correct: ".$result->output );
166
167$cmd = "$command -P stufftoinclude -u /postdata -s POST:stufftoinclude";
168$result = NPTest->testCmd( $cmd );
169is( $result->return_code, 0, $cmd);
170like( $result->output, '/^HTTP OK HTTP/1.1 200 OK - ([\d\.]+) second/', "Output correct: ".$result->output );
171
172$cmd = "$command -j PUT -P stufftoinclude -u /postdata -s PUT:stufftoinclude";
173$result = NPTest->testCmd( $cmd );
174is( $result->return_code, 0, $cmd);
175like( $result->output, '/^HTTP OK HTTP/1.1 200 OK - ([\d\.]+) second/', "Output correct: ".$result->output );
176
177# To confirm that the free doesn't segfault
178$cmd = "$command -P stufftoinclude -j PUT -u /postdata -s PUT:stufftoinclude";
179$result = NPTest->testCmd( $cmd );
180is( $result->return_code, 0, $cmd);
181like( $result->output, '/^HTTP OK HTTP/1.1 200 OK - ([\d\.]+) second/', "Output correct: ".$result->output );
182