From f8e826df7fc403362563023328cb18e3cc7767db Mon Sep 17 00:00:00 2001 From: Ton Voon Date: Fri, 19 Nov 2004 00:12:55 +0000 Subject: Options for User Agent string and extra headers (Ibere Tizio) git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@904 f882894a-f735-0410-b71e-b25c423dba1c diff --git a/plugins/check_http.c b/plugins/check_http.c index 2281786..80b8367 100644 --- a/plugins/check_http.c +++ b/plugins/check_http.c @@ -26,6 +26,8 @@ const char *email = "nagiosplug-devel@lists.sourceforge.net"; #include "netutils.h" #include "utils.h" +#define INPUT_DELIMITER ";" + #define HTTP_EXPECT "HTTP/1." enum { MAX_IPV4_HOSTLENGTH = 255, @@ -104,6 +106,7 @@ double critical_time = 0; int check_critical_time = FALSE; char user_auth[MAX_INPUT_BUFFER] = ""; int display_html = FALSE; +char *http_opt_headers; int onredirect = STATE_OK; int use_ssl = FALSE; int verbose = FALSE; @@ -211,6 +214,8 @@ process_arguments (int argc, char **argv) {"linespan", no_argument, 0, 'l'}, {"onredirect", required_argument, 0, 'f'}, {"certificate", required_argument, 0, 'C'}, + {"useragent", required_argument, 0, 'A'}, + {"header", required_argument, 0, 'k'}, {"no-body", no_argument, 0, 'N'}, {"max-age", required_argument, 0, 'M'}, {"content-type", required_argument, 0, 'T'}, @@ -237,7 +242,7 @@ process_arguments (int argc, char **argv) } while (1) { - c = getopt_long (argc, argv, "Vvh46t:c:w: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:T:I:a:e:p:s:R:r:u:f:C:nlLSm:M:N", longopts, &option); if (c == -1 || c == EOF) break; @@ -275,6 +280,12 @@ process_arguments (int argc, char **argv) check_warning_time = TRUE; } break; + case 'A': /* User Agent String */ + asprintf (&user_agent, "User-Agent: %s", optarg); + break; + case 'k': /* Additional headers */ + asprintf (&http_opt_headers, "%s", optarg); + break; case 'L': /* show html link */ display_html = TRUE; break; @@ -741,6 +752,12 @@ check_http (void) if (host_name) 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); + } + /* optionally send the authentication info */ if (strlen(user_auth)) { auth = base64 (user_auth, strlen (user_auth)); @@ -1410,6 +1427,10 @@ certificate expiration times.\n")); printf (_("\ -a, --authorization=AUTH_PAIR\n\ Username:password on sites with basic authentication\n\ + -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\ -L, --link=URL\n\ Wrap output in HTML link (obsoleted by urlize)\n\ -f, --onredirect=\n\ @@ -1466,6 +1487,7 @@ Usage: %s (-H | -I ) [-u ] [-p ]\n\ [-w ] [-c ] [-t ] [-L]\n\ [-a auth] [-f ] [-e ]\n\ [-s string] [-l] [-r | -R ]\n\ - [-P string] [-m min_pg_size] [-4|-6] [-N] [-M ]\n"), progname); + [-P string] [-m min_pg_size] [-4|-6] [-N] [-M ] [-A string]\n\ + [-k string]\n"), progname); printf (_(UT_HLP_VRS), progname, progname); } -- cgit v0.10-9-g596f