summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTon Voon <tonvoon@users.sourceforge.net>2004-11-19 00:12:55 (GMT)
committerTon Voon <tonvoon@users.sourceforge.net>2004-11-19 00:12:55 (GMT)
commitf8e826df7fc403362563023328cb18e3cc7767db (patch)
treea711908929ddbef4f1a0e6a78560c9cc8ebbba55
parent26b9e9c56457a0a94f0646802982c7818d53a431 (diff)
downloadmonitoring-plugins-f8e826df7fc403362563023328cb18e3cc7767db.tar.gz
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
-rw-r--r--plugins/check_http.c26
1 files changed, 24 insertions, 2 deletions
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";
26#include "netutils.h" 26#include "netutils.h"
27#include "utils.h" 27#include "utils.h"
28 28
29#define INPUT_DELIMITER ";"
30
29#define HTTP_EXPECT "HTTP/1." 31#define HTTP_EXPECT "HTTP/1."
30enum { 32enum {
31 MAX_IPV4_HOSTLENGTH = 255, 33 MAX_IPV4_HOSTLENGTH = 255,
@@ -104,6 +106,7 @@ double critical_time = 0;
104int check_critical_time = FALSE; 106int check_critical_time = FALSE;
105char user_auth[MAX_INPUT_BUFFER] = ""; 107char user_auth[MAX_INPUT_BUFFER] = "";
106int display_html = FALSE; 108int display_html = FALSE;
109char *http_opt_headers;
107int onredirect = STATE_OK; 110int onredirect = STATE_OK;
108int use_ssl = FALSE; 111int use_ssl = FALSE;
109int verbose = FALSE; 112int verbose = FALSE;
@@ -211,6 +214,8 @@ process_arguments (int argc, char **argv)
211 {"linespan", no_argument, 0, 'l'}, 214 {"linespan", no_argument, 0, 'l'},
212 {"onredirect", required_argument, 0, 'f'}, 215 {"onredirect", required_argument, 0, 'f'},
213 {"certificate", required_argument, 0, 'C'}, 216 {"certificate", required_argument, 0, 'C'},
217 {"useragent", required_argument, 0, 'A'},
218 {"header", required_argument, 0, 'k'},
214 {"no-body", no_argument, 0, 'N'}, 219 {"no-body", no_argument, 0, 'N'},
215 {"max-age", required_argument, 0, 'M'}, 220 {"max-age", required_argument, 0, 'M'},
216 {"content-type", required_argument, 0, 'T'}, 221 {"content-type", required_argument, 0, 'T'},
@@ -237,7 +242,7 @@ process_arguments (int argc, char **argv)
237 } 242 }
238 243
239 while (1) { 244 while (1) {
240 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); 245 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);
241 if (c == -1 || c == EOF) 246 if (c == -1 || c == EOF)
242 break; 247 break;
243 248
@@ -275,6 +280,12 @@ process_arguments (int argc, char **argv)
275 check_warning_time = TRUE; 280 check_warning_time = TRUE;
276 } 281 }
277 break; 282 break;
283 case 'A': /* User Agent String */
284 asprintf (&user_agent, "User-Agent: %s", optarg);
285 break;
286 case 'k': /* Additional headers */
287 asprintf (&http_opt_headers, "%s", optarg);
288 break;
278 case 'L': /* show html link */ 289 case 'L': /* show html link */
279 display_html = TRUE; 290 display_html = TRUE;
280 break; 291 break;
@@ -741,6 +752,12 @@ check_http (void)
741 if (host_name) 752 if (host_name)
742 asprintf (&buf, "%sHost: %s\r\n", buf, host_name); 753 asprintf (&buf, "%sHost: %s\r\n", buf, host_name);
743 754
755 /* optionally send any other header tag */
756 if (http_opt_headers) {
757 for ((pos = strtok(http_opt_headers, INPUT_DELIMITER)); pos; (pos = strtok(NULL, INPUT_DELIMITER)))
758 asprintf (&buf, "%s%s\r\n", buf, pos);
759 }
760
744 /* optionally send the authentication info */ 761 /* optionally send the authentication info */
745 if (strlen(user_auth)) { 762 if (strlen(user_auth)) {
746 auth = base64 (user_auth, strlen (user_auth)); 763 auth = base64 (user_auth, strlen (user_auth));
@@ -1410,6 +1427,10 @@ certificate expiration times.\n"));
1410 printf (_("\ 1427 printf (_("\
1411 -a, --authorization=AUTH_PAIR\n\ 1428 -a, --authorization=AUTH_PAIR\n\
1412 Username:password on sites with basic authentication\n\ 1429 Username:password on sites with basic authentication\n\
1430 -A, --useragent=STRING\n\
1431 String to be sent in http header as \"User Agent\"\n\
1432 -k, --header=STRING\n\
1433 Any other tags to be sent in http header, separated by semicolon\n\
1413 -L, --link=URL\n\ 1434 -L, --link=URL\n\
1414 Wrap output in HTML link (obsoleted by urlize)\n\ 1435 Wrap output in HTML link (obsoleted by urlize)\n\
1415 -f, --onredirect=<ok|warning|critical|follow>\n\ 1436 -f, --onredirect=<ok|warning|critical|follow>\n\
@@ -1466,6 +1487,7 @@ Usage: %s (-H <vhost> | -I <IP-address>) [-u <uri>] [-p <port>]\n\
1466 [-w <warn time>] [-c <critical time>] [-t <timeout>] [-L]\n\ 1487 [-w <warn time>] [-c <critical time>] [-t <timeout>] [-L]\n\
1467 [-a auth] [-f <ok | warn | critcal | follow>] [-e <expect>]\n\ 1488 [-a auth] [-f <ok | warn | critcal | follow>] [-e <expect>]\n\
1468 [-s string] [-l] [-r <regex> | -R <case-insensitive regex>]\n\ 1489 [-s string] [-l] [-r <regex> | -R <case-insensitive regex>]\n\
1469 [-P string] [-m min_pg_size] [-4|-6] [-N] [-M <age>]\n"), progname); 1490 [-P string] [-m min_pg_size] [-4|-6] [-N] [-M <age>] [-A string]\n\
1491 [-k string]\n"), progname);
1470 printf (_(UT_HLP_VRS), progname, progname); 1492 printf (_(UT_HLP_VRS), progname, progname);
1471} 1493}