summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: c4c897e)
raw | patch | inline | side by side (parent: c4c897e)
author | Ton Voon <tonvoon@users.sourceforge.net> | |
Sat, 8 Nov 2008 02:08:56 +0000 (02:08 +0000) | ||
committer | Ton Voon <tonvoon@users.sourceforge.net> | |
Sat, 8 Nov 2008 02:08:56 +0000 (02:08 +0000) |
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@2075 f882894a-f735-0410-b71e-b25c423dba1c
NEWS | patch | blob | history | |
plugins/check_http.c | patch | blob | history | |
plugins/tests/check_http.t | patch | blob | history |
index f4e662aa66923991c654fd7848a29f315c3a7fa6..01e8663a69753806d3cf51d25d812ee0846bf1bb 100644 (file)
--- a/NEWS
+++ b/NEWS
This file documents the major additions and syntax changes between releases.
1.4.14 ...
+ check_http has options to specify the HTTP method (#2155152)
check_users thresholds were not working excatly as documented (>= rather than >)
Updated tinderbox_build script to point to new tinderbox server
check_ifoperstatus -n flag now works as expected (sf.net #1569488)
diff --git a/plugins/check_http.c b/plugins/check_http.c
index 69ed2fa91031f0bf89eccd15734661e69cba45da..df5daf2d99448e31533046d464adf68d57d3bc96 100644 (file)
--- a/plugins/check_http.c
+++ b/plugins/check_http.c
{"nohtml", no_argument, 0, 'n'},
{"ssl", no_argument, 0, 'S'},
{"post", required_argument, 0, 'P'},
+ {"method", required_argument, 0, 'j'},
{"IP-address", required_argument, 0, 'I'},
{"url", required_argument, 0, 'u'},
{"port", required_argument, 0, 'p'},
}
while (1) {
- 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);
+ 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);
if (c == -1 || c == EOF)
break;
strncpy (user_auth, optarg, MAX_INPUT_BUFFER - 1);
user_auth[MAX_INPUT_BUFFER - 1] = 0;
break;
- case 'P': /* HTTP POST data in URL encoded format */
- if (http_method || http_post_data) break;
- http_method = strdup("POST");
- http_post_data = strdup (optarg);
+ case 'P': /* HTTP POST data in URL encoded format; ignored if settings already */
+ if (! http_post_data)
+ http_post_data = strdup (optarg);
+ if (! http_method)
+ http_method = strdup("POST");
+ break;
+ case 'j': /* Set HTTP method */
+ if (http_method)
+ free(http_method);
+ http_method = strdup (optarg);
break;
case 's': /* string or substring */
strncpy (string_expect, optarg, MAX_INPUT_BUFFER - 1);
asprintf (&buf, "%sAuthorization: Basic %s\r\n", buf, auth);
}
- /* either send http POST data */
+ /* either send http POST data (any data, not only POST)*/
if (http_post_data) {
if (http_content_type) {
asprintf (&buf, "%sContent-Type: %s\r\n", buf, http_content_type);
printf (" %s\n", _("URL to GET or POST (default: /)"));
printf (" %s\n", "-P, --post=STRING");
printf (" %s\n", _("URL encoded http POST data"));
+ printf (" %s\n", "-j, --method=STRING (for example: HEAD, OPTIONS, TRACE, PUT, DELETE)");
+ printf (" %s\n", _("Set HTTP method."));
printf (" %s\n", "-N, --no-body");
printf (" %s\n", _("Don't wait for document body: stop reading after headers."));
printf (" %s\n", _("(Note that this still does an HTTP GET or POST, not a HEAD.)"));
printf (" [-a auth] [-f <ok | warn | critcal | follow>] [-e <expect>]\n");
printf (" [-s string] [-l] [-r <regex> | -R <case-insensitive regex>] [-P string]\n");
printf (" [-m <min_pg_size>:<max_pg_size>] [-4|-6] [-N] [-M <age>] [-A string]\n");
- printf (" [-k string] [-S] [-C <age>] [-T <content-type>]\n");
+ printf (" [-k string] [-S] [-C <age>] [-T <content-type>] [-j method]\n");
}
index 6b932d9d68d390bf9d012064b3f1bca2acf30e67..d54932e681e9b840ede388acc24a4ef1675251d6 100755 (executable)
print "Please contact me at: <URL:", $d->url, ">\n";
while (my $c = $d->accept ) {
while (my $r = $c->get_request) {
- if ($r->method eq "GET" and $r->url->path eq "/xyzzy") {
- $c->send_file_response("/etc/passwd");
- } elsif ($r->method eq "GET" and $r->url->path =~ m^/statuscode/(\d+)^) {
+ if ($r->method eq "GET" and $r->url->path =~ m^/statuscode/(\d+)^) {
$c->send_basic_header($1);
$c->send_crlf;
} elsif ($r->method eq "GET" and $r->url->path =~ m^/file/(.*)^) {
$c->send_crlf;
sleep 1;
$c->send_response("slow");
+ } elsif ($r->url->path eq "/method") {
+ if ($r->method eq "DELETE") {
+ $c->send_error(RC_METHOD_NOT_ALLOWED);
+ } elsif ($r->method eq "foo") {
+ $c->send_error(RC_NOT_IMPLEMENTED);
+ } else {
+ $c->send_status_line(200, $r->method);
+ }
+ } elsif ($r->url->path eq "/postdata") {
+ $c->send_basic_header;
+ $c->send_crlf;
+ $c->send_response($r->method.":".$r->content);
} else {
$c->send_error(RC_FORBIDDEN);
}
}
if (-x "./check_http") {
- plan tests => 19;
+ plan tests => 39;
} else {
plan skip_all => "No check_http compiled";
}
is( $result->return_code, 2, $cmd);
like( $result->output, '/^HTTP CRITICAL - Invalid HTTP response received from host on port (\d+): HTTP/1.1 203 Non-Authoritative Information/', "Output correct: ".$result->output );
+$cmd = "$command -j HEAD -u /method";
+$result = NPTest->testCmd( $cmd );
+is( $result->return_code, 0, $cmd);
+like( $result->output, '/^HTTP OK HTTP/1.1 200 HEAD - 19 bytes in ([\d\.]+) seconds/', "Output correct: ".$result->output );
+
+$cmd = "$command -j POST -u /method";
+$result = NPTest->testCmd( $cmd );
+is( $result->return_code, 0, $cmd);
+like( $result->output, '/^HTTP OK HTTP/1.1 200 POST - 19 bytes in ([\d\.]+) seconds/', "Output correct: ".$result->output );
+
+$cmd = "$command -j GET -u /method";
+$result = NPTest->testCmd( $cmd );
+is( $result->return_code, 0, $cmd);
+like( $result->output, '/^HTTP OK HTTP/1.1 200 GET - 18 bytes in ([\d\.]+) seconds/', "Output correct: ".$result->output );
+
+$cmd = "$command -u /method";
+$result = NPTest->testCmd( $cmd );
+is( $result->return_code, 0, $cmd);
+like( $result->output, '/^HTTP OK HTTP/1.1 200 GET - 18 bytes in ([\d\.]+) seconds/', "Output correct: ".$result->output );
+
+$cmd = "$command -P foo -u /method";
+$result = NPTest->testCmd( $cmd );
+is( $result->return_code, 0, $cmd);
+like( $result->output, '/^HTTP OK HTTP/1.1 200 POST - 19 bytes in ([\d\.]+) seconds/', "Output correct: ".$result->output );
+
+$cmd = "$command -j DELETE -u /method";
+$result = NPTest->testCmd( $cmd );
+is( $result->return_code, 1, $cmd);
+like( $result->output, '/^HTTP WARNING: HTTP/1.1 405 Method Not Allowed/', "Output correct: ".$result->output );
+
+$cmd = "$command -j foo -u /method";
+$result = NPTest->testCmd( $cmd );
+is( $result->return_code, 2, $cmd);
+like( $result->output, '/^HTTP CRITICAL: HTTP/1.1 501 Not Implemented/', "Output correct: ".$result->output );
+
+$cmd = "$command -P stufftoinclude -u /postdata -s POST:stufftoinclude";
+$result = NPTest->testCmd( $cmd );
+is( $result->return_code, 0, $cmd);
+like( $result->output, '/^HTTP OK HTTP/1.1 200 OK - ([\d\.]+) second/', "Output correct: ".$result->output );
+
+$cmd = "$command -j PUT -P stufftoinclude -u /postdata -s PUT:stufftoinclude";
+$result = NPTest->testCmd( $cmd );
+is( $result->return_code, 0, $cmd);
+like( $result->output, '/^HTTP OK HTTP/1.1 200 OK - ([\d\.]+) second/', "Output correct: ".$result->output );
+
+# To confirm that the free doesn't segfault
+$cmd = "$command -P stufftoinclude -j PUT -u /postdata -s PUT:stufftoinclude";
+$result = NPTest->testCmd( $cmd );
+is( $result->return_code, 0, $cmd);
+like( $result->output, '/^HTTP OK HTTP/1.1 200 OK - ([\d\.]+) second/', "Output correct: ".$result->output );
+