[Nagiosplug-devel] check_http Content-Type

Shawn Wills shawn at greymetalprimer.com
Thu Feb 19 11:38:19 CET 2004


I found the need to be able to specify the Content-Type header in 
check_http.

I've attached patches to check_http.c in the event that someone else might 
find this useful (and also to see if I did this the "right" way).
-------------- next part --------------
--- nagios-plugins-1.4.0alpha1/plugins/check_http.c	Mon Feb 16 15:36:43 2004
+++ nagios-plugins-1.4.0alpha1a/plugins/check_http.c	Thu Feb 19 11:17:06 2004
@@ -1156,7 +1156,7 @@
  -P, --post=STRING\n\
    URL encoded http POST data\n\
  -T, --content-type=STRING\n\
-   HTTP Content-Type\n"), HTTP_EXPECT);
+   specify Content-Type header media type\n"), HTTP_EXPECT);
 
 #ifdef HAVE_REGEX_H
 	printf (_("\
-------------- next part --------------
--- nagios-plugins-1.3.1/plugins/check_http.c	Mon Jun 30 04:56:08 2003
+++ nagios-plugins-1.3.1a/plugins/check_http.c	Thu Feb 19 11:15:47 2004
@@ -63,6 +63,8 @@
    Port number (default: %d)\n\
  -P, --post=STRING\n\
    URL encoded http POST data\n\
+ -T, --content-type=STRING\n\
+   specify Content-Type header media type\n\
  -w, --warning=INTEGER\n\
    Response time to result in warning status (seconds)\n\
  -c, --critical=INTEGER\n\
@@ -220,6 +222,7 @@
 int sd;
 char *http_method = "GET";
 char *http_post_data = "";
+char *http_content_type = "";
 char buffer[MAX_INPUT_BUFFER];
 
 void print_usage (void);
@@ -311,6 +314,7 @@
  		{"linespan", no_argument, 0, 'l'},
 		{"onredirect", required_argument, 0, 'f'},
 		{"certificate", required_argument, 0, 'C'},
+		{"content-type", required_argument, 0, 'T'},
 		{0, 0, 0, 0}
 	};
 #endif
@@ -331,7 +335,7 @@
 			strcpy (argv[c], "-n");
 	}
 
-#define OPTCHARS "Vvht:c:w:H:P:I:a:e:p:s:R:r:u:f:C:nlLS"
+#define OPTCHARS "Vvht:c:w:H:P:I:a:e:p:s:R:r:u:f:C:T:nlLS"
 
 	while (1) {
 #ifdef HAVE_GETOPT_H
@@ -443,6 +447,9 @@
 			server_expect[MAX_INPUT_BUFFER - 1] = 0;
 			server_expect_yn = 1;
 			break;
+		case 'T': /* Content-type */
+			asprintf (&http_content_type, "%s", optarg);
+			break;
 #ifndef HAVE_REGEX_H
  		case 'l': /* linespan */
  		case 'r': /* linespan */
@@ -597,7 +604,12 @@
 
 	/* either send http POST data */
 	if (strlen (http_post_data)) {
-		asprintf (&buf, "%sContent-Type: application/x-www-form-urlencoded\r\n", buf);
+		if (strlen (http_content_type)) {
+			asprintf (&buf, "%sContent-Type: %s\r\n", buf, http_content_type);
+		}
+		else {
+			asprintf (&buf, "%sContent-Type: application/x-www-form-urlencoded\r\n", buf);
+		}
 		asprintf (&buf, "%sContent-Length: %i\r\n\r\n", buf, strlen (http_post_data));
 		asprintf (&buf, "%s%s%s", buf, http_post_data, CRLF);
 	}


More information about the Devel mailing list