summaryrefslogtreecommitdiffstats
path: root/plugins/check_http.c
diff options
context:
space:
mode:
authorChristopher Odenbach <odenbach@uni-paderborn.de>2015-09-15 12:52:18 (GMT)
committerSven Nierlein <sven@nierlein.de>2016-11-11 08:33:37 (GMT)
commit2233b7aa7545ff1e66264611270473b44e6ffdf5 (patch)
tree728da4f1fdcbccf9f7f6dd38cbace6f026f06e81 /plugins/check_http.c
parentb9f54f85f9bcc57e38cd6814682f2b43f7dc5965 (diff)
downloadmonitoring-plugins-2233b7aa7545ff1e66264611270473b44e6ffdf5.tar.gz
patch to support the concept of virtual ports
Diffstat (limited to 'plugins/check_http.c')
-rw-r--r--plugins/check_http.c38
1 files changed, 30 insertions, 8 deletions
diff --git a/plugins/check_http.c b/plugins/check_http.c
index 2038f4a..2ce7e21 100644
--- a/plugins/check_http.c
+++ b/plugins/check_http.c
@@ -91,10 +91,12 @@ struct timeval tv_temp;
91 91
92int specify_port = FALSE; 92int specify_port = FALSE;
93int server_port = HTTP_PORT; 93int server_port = HTTP_PORT;
94int virtual_port = 0;
94char server_port_text[6] = ""; 95char server_port_text[6] = "";
95char server_type[6] = "http"; 96char server_type[6] = "http";
96char *server_address; 97char *server_address;
97char *host_name; 98char *host_name;
99int host_name_length;
98char *server_url; 100char *server_url;
99char *user_agent; 101char *user_agent;
100int server_url_length; 102int server_url_length;
@@ -391,11 +393,25 @@ process_arguments (int argc, char **argv)
391 case 'H': /* Host Name (virtual host) */ 393 case 'H': /* Host Name (virtual host) */
392 host_name = strdup (optarg); 394 host_name = strdup (optarg);
393 if (host_name[0] == '[') { 395 if (host_name[0] == '[') {
394 if ((p = strstr (host_name, "]:")) != NULL) /* [IPv6]:port */ 396 if ((p = strstr (host_name, "]:")) != NULL) { /* [IPv6]:port */
395 server_port = atoi (p + 2); 397 virtual_port = atoi (p + 2);
398 /* cut off the port */
399 host_name_length = strlen (host_name) - strlen (p) - 1;
400 free (host_name);
401 host_name = strndup (optarg, host_name_length);
402 if (specify_port == FALSE)
403 server_port = virtual_port;
404 }
396 } else if ((p = strchr (host_name, ':')) != NULL 405 } else if ((p = strchr (host_name, ':')) != NULL
397 && strchr (++p, ':') == NULL) /* IPv4:port or host:port */ 406 && strchr (++p, ':') == NULL) { /* IPv4:port or host:port */
398 server_port = atoi (p); 407 virtual_port = atoi (p);
408 /* cut off the port */
409 host_name_length = strlen (host_name) - strlen (p) - 1;
410 free (host_name);
411 host_name = strndup (optarg, host_name_length);
412 if (specify_port == FALSE)
413 server_port = virtual_port;
414 }
399 break; 415 break;
400 case 'I': /* Server IP-address */ 416 case 'I': /* Server IP-address */
401 server_address = strdup (optarg); 417 server_address = strdup (optarg);
@@ -550,9 +566,12 @@ process_arguments (int argc, char **argv)
550 if (http_method == NULL) 566 if (http_method == NULL)
551 http_method = strdup ("GET"); 567 http_method = strdup ("GET");
552 568
553 if (client_cert && !client_privkey) 569 if (client_cert && !client_privkey)
554 usage4 (_("If you use a client certificate you must also specify a private key file")); 570 usage4 (_("If you use a client certificate you must also specify a private key file"));
555 571
572 if (virtual_port == 0)
573 virtual_port = server_port;
574
556 return TRUE; 575 return TRUE;
557} 576}
558 577
@@ -958,13 +977,13 @@ check_http (void)
958 * 14.23). Some server applications/configurations cause trouble if the 977 * 14.23). Some server applications/configurations cause trouble if the
959 * (default) port is explicitly specified in the "Host:" header line. 978 * (default) port is explicitly specified in the "Host:" header line.
960 */ 979 */
961 if ((use_ssl == FALSE && server_port == HTTP_PORT) || 980 if ((use_ssl == FALSE && virtual_port == HTTP_PORT) ||
962 (use_ssl == TRUE && server_port == HTTPS_PORT) || 981 (use_ssl == TRUE && virtual_port == HTTPS_PORT) ||
963 (server_address != NULL && strcmp(http_method, "CONNECT") == 0 982 (server_address != NULL && strcmp(http_method, "CONNECT") == 0
964 && host_name != NULL && use_ssl == TRUE)) 983 && host_name != NULL && use_ssl == TRUE))
965 xasprintf (&buf, "%sHost: %s\r\n", buf, host_name); 984 xasprintf (&buf, "%sHost: %s\r\n", buf, host_name);
966 else 985 else
967 xasprintf (&buf, "%sHost: %s:%d\r\n", buf, host_name, server_port); 986 xasprintf (&buf, "%sHost: %s:%d\r\n", buf, host_name, virtual_port);
968 } 987 }
969 } 988 }
970 989
@@ -1421,6 +1440,9 @@ redir (char *pos, char *status_line)
1421 MAX_PORT, server_type, server_address, server_port, server_url, 1440 MAX_PORT, server_type, server_address, server_port, server_url,
1422 display_html ? "</A>" : ""); 1441 display_html ? "</A>" : "");
1423 1442
1443 /* reset virtual port */
1444 virtual_port = server_port;
1445
1424 if (verbose) 1446 if (verbose)
1425 printf (_("Redirection to %s://%s:%d%s\n"), server_type, 1447 printf (_("Redirection to %s://%s:%d%s\n"), server_type,
1426 host_name ? host_name : server_address, server_port, server_url); 1448 host_name ? host_name : server_address, server_port, server_url);