summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: f235579)
raw | patch | inline | side by side (parent: f235579)
author | Ton Voon <tonvoon@users.sourceforge.net> | |
Wed, 5 Apr 2006 07:58:29 +0000 (07:58 +0000) | ||
committer | Ton Voon <tonvoon@users.sourceforge.net> | |
Wed, 5 Apr 2006 07:58:29 +0000 (07:58 +0000) |
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1367 f882894a-f735-0410-b71e-b25c423dba1c
plugins/check_http.c | patch | blob | history | |
plugins/t/check_http.t | patch | blob | history |
diff --git a/plugins/check_http.c b/plugins/check_http.c
index 58cf83cf236ae8cdf3f11c9579e500c64d3892ca..e25e5db24715a01d352528ff39f32ebbed19a7bb 100644 (file)
--- a/plugins/check_http.c
+++ b/plugins/check_http.c
int check_critical_time = FALSE;
char user_auth[MAX_INPUT_BUFFER] = "";
int display_html = FALSE;
-char *http_opt_headers;
+char **http_opt_headers;
+int http_opt_headers_count = 0;
int onredirect = STATE_OK;
int use_ssl = FALSE;
int verbose = FALSE;
asprintf (&user_agent, "User-Agent: %s", optarg);
break;
case 'k': /* Additional headers */
- asprintf (&http_opt_headers, "%s", optarg);
+ if (http_opt_headers_count == 0)
+ http_opt_headers = malloc (sizeof (char *) * (++http_opt_headers_count));
+ else
+ http_opt_headers = realloc (http_opt_headers, sizeof (char *) * (++http_opt_headers_count));
+ http_opt_headers[http_opt_headers_count - 1] = optarg;
+ //asprintf (&http_opt_headers, "%s", optarg);
break;
case 'L': /* show html link */
display_html = TRUE;
asprintf (&buf, "%sHost: %s\r\n", buf, host_name);
/* optionally send any other header tag */
- if (http_opt_headers) {
- for ((pos = strtok(http_opt_headers, INPUT_DELIMITER)); pos; (pos = strtok(NULL, INPUT_DELIMITER)))
- asprintf (&buf, "%s%s\r\n", buf, pos);
+ if (http_opt_headers_count) {
+ for (i = 0; i < http_opt_headers_count ; i++) {
+ for ((pos = strtok(http_opt_headers[i], INPUT_DELIMITER)); pos; (pos = strtok(NULL, INPUT_DELIMITER)))
+ asprintf (&buf, "%s%s\r\n", buf, pos);
+ }
+ free(http_opt_headers);
}
/* optionally send the authentication info */
-A, --useragent=STRING\n\
String to be sent in http header as \"User Agent\"\n\
-k, --header=STRING\n\
- Any other tags to be sent in http header, separated by semicolon\n\
+ Any other tags to be sent in http header. Use multiple times for additional headers\n\
-L, --link=URL\n\
Wrap output in HTML link (obsoleted by urlize)\n\
-f, --onredirect=<ok|warning|critical|follow>\n\
diff --git a/plugins/t/check_http.t b/plugins/t/check_http.t
index 408906d97d4610b05fed0fb0a03b583601de8942..3154151f9b8b941bb3695e42f73838d5fcb4eb42 100644 (file)
--- a/plugins/t/check_http.t
+++ b/plugins/t/check_http.t
use Test::More;
use NPTest;
-plan tests => 12;
+plan tests => 14;
my $successOutput = '/OK.*HTTP.*second/';
cmp_ok( $res->return_code, '==', 0, "Webserver $host_tcp_http responded" );
like( $res->output, $successOutput, "Output OK" );
+$res = NPTest->testCmd(
+ "./check_http $host_tcp_http -wt 300 -ct 600 -v -v -v -k 'bob:there;fred:here'"
+ );
+like( $res->output, '/bob:there\r\nfred:here\r\n/', "Got headers, delimited with ';'" );
+
+$res = NPTest->testCmd(
+ "./check_http $host_tcp_http -wt 300 -ct 600 -v -v -v -k 'bob:there;fred:here' -k 'carl:frown'"
+ );
+like( $res->output, '/bob:there\r\nfred:here\r\ncarl:frown\r\n/', "Got headers with multiple -k options" );
+
$res = NPTest->testCmd(
"./check_http $host_nonresponsive -wt 1 -ct 2"
);