summaryrefslogtreecommitdiffstats
path: root/plugins/check_http.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/check_http.c')
-rw-r--r--plugins/check_http.c58
1 files changed, 42 insertions, 16 deletions
diff --git a/plugins/check_http.c b/plugins/check_http.c
index 2038f4a1..e5ef7cc4 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
@@ -922,8 +941,8 @@ check_http (void)
922 elapsed_time_ssl = (double)microsec_ssl / 1.0e6; 941 elapsed_time_ssl = (double)microsec_ssl / 1.0e6;
923 if (check_cert == TRUE) { 942 if (check_cert == TRUE) {
924 result = np_net_ssl_check_cert(days_till_exp_warn, days_till_exp_crit); 943 result = np_net_ssl_check_cert(days_till_exp_warn, days_till_exp_crit);
925 np_net_ssl_cleanup();
926 if (sd) close(sd); 944 if (sd) close(sd);
945 np_net_ssl_cleanup();
927 return result; 946 return result;
928 } 947 }
929 } 948 }
@@ -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
@@ -1022,6 +1041,10 @@ check_http (void)
1022 microsec_firstbyte = deltime (tv_temp); 1041 microsec_firstbyte = deltime (tv_temp);
1023 elapsed_time_firstbyte = (double)microsec_firstbyte / 1.0e6; 1042 elapsed_time_firstbyte = (double)microsec_firstbyte / 1.0e6;
1024 } 1043 }
1044 while (pos = memchr(buffer, '\0', i)) {
1045 /* replace nul character with a blank */
1046 *pos = ' ';
1047 }
1025 buffer[i] = '\0'; 1048 buffer[i] = '\0';
1026 xasprintf (&full_page_new, "%s%s", full_page, buffer); 1049 xasprintf (&full_page_new, "%s%s", full_page, buffer);
1027 free (full_page); 1050 free (full_page);
@@ -1063,10 +1086,10 @@ check_http (void)
1063 die (STATE_CRITICAL, _("HTTP CRITICAL - No data received from host\n")); 1086 die (STATE_CRITICAL, _("HTTP CRITICAL - No data received from host\n"));
1064 1087
1065 /* close the connection */ 1088 /* close the connection */
1089 if (sd) close(sd);
1066#ifdef HAVE_SSL 1090#ifdef HAVE_SSL
1067 np_net_ssl_cleanup(); 1091 np_net_ssl_cleanup();
1068#endif 1092#endif
1069 if (sd) close(sd);
1070 1093
1071 /* Save check time */ 1094 /* Save check time */
1072 microsec = deltime (tv); 1095 microsec = deltime (tv);
@@ -1421,6 +1444,9 @@ redir (char *pos, char *status_line)
1421 MAX_PORT, server_type, server_address, server_port, server_url, 1444 MAX_PORT, server_type, server_address, server_port, server_url,
1422 display_html ? "</A>" : ""); 1445 display_html ? "</A>" : "");
1423 1446
1447 /* reset virtual port */
1448 virtual_port = server_port;
1449
1424 if (verbose) 1450 if (verbose)
1425 printf (_("Redirection to %s://%s:%d%s\n"), server_type, 1451 printf (_("Redirection to %s://%s:%d%s\n"), server_type,
1426 host_name ? host_name : server_address, server_port, server_url); 1452 host_name ? host_name : server_address, server_port, server_url);
@@ -1453,32 +1479,32 @@ char *perfd_time (double elapsed_time)
1453 return fperfdata ("time", elapsed_time, "s", 1479 return fperfdata ("time", elapsed_time, "s",
1454 thlds->warning?TRUE:FALSE, thlds->warning?thlds->warning->end:0, 1480 thlds->warning?TRUE:FALSE, thlds->warning?thlds->warning->end:0,
1455 thlds->critical?TRUE:FALSE, thlds->critical?thlds->critical->end:0, 1481 thlds->critical?TRUE:FALSE, thlds->critical?thlds->critical->end:0,
1456 TRUE, 0, FALSE, 0); 1482 TRUE, 0, TRUE, socket_timeout);
1457} 1483}
1458 1484
1459char *perfd_time_connect (double elapsed_time_connect) 1485char *perfd_time_connect (double elapsed_time_connect)
1460{ 1486{
1461 return fperfdata ("time_connect", elapsed_time_connect, "s", FALSE, 0, FALSE, 0, FALSE, 0, FALSE, 0); 1487 return fperfdata ("time_connect", elapsed_time_connect, "s", FALSE, 0, FALSE, 0, FALSE, 0, TRUE, socket_timeout);
1462} 1488}
1463 1489
1464char *perfd_time_ssl (double elapsed_time_ssl) 1490char *perfd_time_ssl (double elapsed_time_ssl)
1465{ 1491{
1466 return fperfdata ("time_ssl", elapsed_time_ssl, "s", FALSE, 0, FALSE, 0, FALSE, 0, FALSE, 0); 1492 return fperfdata ("time_ssl", elapsed_time_ssl, "s", FALSE, 0, FALSE, 0, FALSE, 0, TRUE, socket_timeout);
1467} 1493}
1468 1494
1469char *perfd_time_headers (double elapsed_time_headers) 1495char *perfd_time_headers (double elapsed_time_headers)
1470{ 1496{
1471 return fperfdata ("time_headers", elapsed_time_headers, "s", FALSE, 0, FALSE, 0, FALSE, 0, FALSE, 0); 1497 return fperfdata ("time_headers", elapsed_time_headers, "s", FALSE, 0, FALSE, 0, FALSE, 0, TRUE, socket_timeout);
1472} 1498}
1473 1499
1474char *perfd_time_firstbyte (double elapsed_time_firstbyte) 1500char *perfd_time_firstbyte (double elapsed_time_firstbyte)
1475{ 1501{
1476 return fperfdata ("time_firstbyte", elapsed_time_firstbyte, "s", FALSE, 0, FALSE, 0, FALSE, 0, FALSE, 0); 1502 return fperfdata ("time_firstbyte", elapsed_time_firstbyte, "s", FALSE, 0, FALSE, 0, FALSE, 0, TRUE, socket_timeout);
1477} 1503}
1478 1504
1479char *perfd_time_transfer (double elapsed_time_transfer) 1505char *perfd_time_transfer (double elapsed_time_transfer)
1480{ 1506{
1481 return fperfdata ("time_transfer", elapsed_time_transfer, "s", FALSE, 0, FALSE, 0, FALSE, 0, FALSE, 0); 1507 return fperfdata ("time_transfer", elapsed_time_transfer, "s", FALSE, 0, FALSE, 0, FALSE, 0, TRUE, socket_timeout);
1482} 1508}
1483 1509
1484char *perfd_size (int page_len) 1510char *perfd_size (int page_len)