diff options
Diffstat (limited to 'plugins/check_http.c')
-rw-r--r-- | plugins/check_http.c | 92 |
1 files changed, 83 insertions, 9 deletions
diff --git a/plugins/check_http.c b/plugins/check_http.c index 110875d..ce26ff4 100644 --- a/plugins/check_http.c +++ b/plugins/check_http.c | |||
@@ -3,7 +3,7 @@ | |||
3 | * Nagios check_http plugin | 3 | * Nagios check_http plugin |
4 | * | 4 | * |
5 | * License: GPL | 5 | * License: GPL |
6 | * Copyright (c) 1999-2008 Nagios Plugins Development Team | 6 | * Copyright (c) 1999-2013 Nagios Plugins Development Team |
7 | * | 7 | * |
8 | * Description: | 8 | * Description: |
9 | * | 9 | * |
@@ -34,7 +34,7 @@ | |||
34 | /* splint -I. -I../../plugins -I../../lib/ -I/usr/kerberos/include/ ../../plugins/check_http.c */ | 34 | /* splint -I. -I../../plugins -I../../lib/ -I/usr/kerberos/include/ ../../plugins/check_http.c */ |
35 | 35 | ||
36 | const char *progname = "check_http"; | 36 | const char *progname = "check_http"; |
37 | const char *copyright = "1999-2011"; | 37 | const char *copyright = "1999-2013"; |
38 | const char *email = "nagiosplug-devel@lists.sourceforge.net"; | 38 | const char *email = "nagiosplug-devel@lists.sourceforge.net"; |
39 | 39 | ||
40 | #include "common.h" | 40 | #include "common.h" |
@@ -84,6 +84,7 @@ int errcode; | |||
84 | int invert_regex = 0; | 84 | int invert_regex = 0; |
85 | 85 | ||
86 | struct timeval tv; | 86 | struct timeval tv; |
87 | struct timeval tv_temp; | ||
87 | 88 | ||
88 | #define HTTP_URL "/" | 89 | #define HTTP_URL "/" |
89 | #define CRLF "\r\n" | 90 | #define CRLF "\r\n" |
@@ -114,6 +115,7 @@ int followsticky = STICKY_NONE; | |||
114 | int use_ssl = FALSE; | 115 | int use_ssl = FALSE; |
115 | int use_sni = FALSE; | 116 | int use_sni = FALSE; |
116 | int verbose = FALSE; | 117 | int verbose = FALSE; |
118 | int show_extended_perfdata = FALSE; | ||
117 | int sd; | 119 | int sd; |
118 | int min_page_len = 0; | 120 | int min_page_len = 0; |
119 | int max_page_len = 0; | 121 | int max_page_len = 0; |
@@ -130,6 +132,11 @@ void redir (char *pos, char *status_line); | |||
130 | int server_type_check(const char *type); | 132 | int server_type_check(const char *type); |
131 | int server_port_check(int ssl_flag); | 133 | int server_port_check(int ssl_flag); |
132 | char *perfd_time (double microsec); | 134 | char *perfd_time (double microsec); |
135 | char *perfd_time_connect (double microsec); | ||
136 | char *perfd_time_ssl (double microsec); | ||
137 | char *perfd_time_firstbyte (double microsec); | ||
138 | char *perfd_time_headers (double microsec); | ||
139 | char *perfd_time_transfer (double microsec); | ||
133 | char *perfd_size (int page_len); | 140 | char *perfd_size (int page_len); |
134 | void print_help (void); | 141 | void print_help (void); |
135 | void print_usage (void); | 142 | void print_usage (void); |
@@ -215,6 +222,7 @@ process_arguments (int argc, char **argv) | |||
215 | {"invert-regex", no_argument, NULL, INVERT_REGEX}, | 222 | {"invert-regex", no_argument, NULL, INVERT_REGEX}, |
216 | {"use-ipv4", no_argument, 0, '4'}, | 223 | {"use-ipv4", no_argument, 0, '4'}, |
217 | {"use-ipv6", no_argument, 0, '6'}, | 224 | {"use-ipv6", no_argument, 0, '6'}, |
225 | {"extended-perfdata", no_argument, 0, 'E'}, | ||
218 | {0, 0, 0, 0} | 226 | {0, 0, 0, 0} |
219 | }; | 227 | }; |
220 | 228 | ||
@@ -235,7 +243,7 @@ process_arguments (int argc, char **argv) | |||
235 | } | 243 | } |
236 | 244 | ||
237 | while (1) { | 245 | while (1) { |
238 | c = getopt_long (argc, argv, "Vvh46t:c:w:A:k:H:P:j:T:I:a:b:e:p:s:R:r:u:f:C:nlLS::m:M:N", longopts, &option); | 246 | c = getopt_long (argc, argv, "Vvh46t:c:w:A:k:H:P:j:T:I:a:b:e:p:s:R:r:u:f:C:nlLS::m:M:N:E", longopts, &option); |
239 | if (c == -1 || c == EOF) | 247 | if (c == -1 || c == EOF) |
240 | break; | 248 | break; |
241 | 249 | ||
@@ -470,6 +478,9 @@ process_arguments (int argc, char **argv) | |||
470 | } | 478 | } |
471 | } | 479 | } |
472 | break; | 480 | break; |
481 | case 'E': /* show extended perfdata */ | ||
482 | show_extended_perfdata = TRUE; | ||
483 | break; | ||
473 | } | 484 | } |
474 | } | 485 | } |
475 | 486 | ||
@@ -811,17 +822,33 @@ check_http (void) | |||
811 | char *pos; | 822 | char *pos; |
812 | long microsec; | 823 | long microsec; |
813 | double elapsed_time; | 824 | double elapsed_time; |
825 | long microsec_connect; | ||
826 | double elapsed_time_connect; | ||
827 | long microsec_ssl; | ||
828 | double elapsed_time_ssl; | ||
829 | long microsec_firstbyte; | ||
830 | double elapsed_time_firstbyte; | ||
831 | long microsec_headers; | ||
832 | double elapsed_time_headers; | ||
833 | long microsec_transfer; | ||
834 | double elapsed_time_transfer; | ||
814 | int page_len = 0; | 835 | int page_len = 0; |
815 | int result = STATE_OK; | 836 | int result = STATE_OK; |
816 | 837 | ||
817 | /* try to connect to the host at the given port number */ | 838 | /* try to connect to the host at the given port number */ |
839 | gettimeofday (&tv_temp, NULL); | ||
818 | if (my_tcp_connect (server_address, server_port, &sd) != STATE_OK) | 840 | if (my_tcp_connect (server_address, server_port, &sd) != STATE_OK) |
819 | die (STATE_CRITICAL, _("HTTP CRITICAL - Unable to open TCP socket\n")); | 841 | die (STATE_CRITICAL, _("HTTP CRITICAL - Unable to open TCP socket\n")); |
842 | microsec_connect = deltime (tv_temp); | ||
820 | #ifdef HAVE_SSL | 843 | #ifdef HAVE_SSL |
844 | elapsed_time_connect = (double)microsec_connect / 1.0e6; | ||
821 | if (use_ssl == TRUE) { | 845 | if (use_ssl == TRUE) { |
846 | gettimeofday (&tv_temp, NULL); | ||
822 | result = np_net_ssl_init_with_hostname_and_version(sd, (use_sni ? host_name : NULL), ssl_version); | 847 | result = np_net_ssl_init_with_hostname_and_version(sd, (use_sni ? host_name : NULL), ssl_version); |
823 | if (result != STATE_OK) | 848 | if (result != STATE_OK) |
824 | return result; | 849 | return result; |
850 | microsec_ssl = deltime (tv_temp); | ||
851 | elapsed_time_ssl = (double)microsec_ssl / 1.0e6; | ||
825 | if (check_cert == TRUE) { | 852 | if (check_cert == TRUE) { |
826 | result = np_net_ssl_check_cert(days_till_exp_warn, days_till_exp_crit); | 853 | result = np_net_ssl_check_cert(days_till_exp_warn, days_till_exp_crit); |
827 | np_net_ssl_cleanup(); | 854 | np_net_ssl_cleanup(); |
@@ -889,11 +916,19 @@ check_http (void) | |||
889 | } | 916 | } |
890 | 917 | ||
891 | if (verbose) printf ("%s\n", buf); | 918 | if (verbose) printf ("%s\n", buf); |
919 | gettimeofday (&tv_temp, NULL); | ||
892 | my_send (buf, strlen (buf)); | 920 | my_send (buf, strlen (buf)); |
921 | microsec_headers = deltime (tv_temp); | ||
922 | elapsed_time_headers = (double)microsec_headers / 1.0e6; | ||
893 | 923 | ||
894 | /* fetch the page */ | 924 | /* fetch the page */ |
895 | full_page = strdup(""); | 925 | full_page = strdup(""); |
926 | gettimeofday (&tv_temp, NULL); | ||
896 | while ((i = my_recv (buffer, MAX_INPUT_BUFFER-1)) > 0) { | 927 | while ((i = my_recv (buffer, MAX_INPUT_BUFFER-1)) > 0) { |
928 | if ((i >= 1) && (elapsed_time_firstbyte <= 0.000001)) { | ||
929 | microsec_firstbyte = deltime (tv_temp); | ||
930 | elapsed_time_firstbyte = (double)microsec_firstbyte / 1.0e6; | ||
931 | } | ||
897 | buffer[i] = '\0'; | 932 | buffer[i] = '\0'; |
898 | xasprintf (&full_page_new, "%s%s", full_page, buffer); | 933 | xasprintf (&full_page_new, "%s%s", full_page, buffer); |
899 | free (full_page); | 934 | free (full_page); |
@@ -905,6 +940,8 @@ check_http (void) | |||
905 | break; | 940 | break; |
906 | } | 941 | } |
907 | } | 942 | } |
943 | microsec_transfer = deltime (tv_temp); | ||
944 | elapsed_time_transfer = (double)microsec_transfer / 1.0e6; | ||
908 | 945 | ||
909 | if (i < 0 && errno != ECONNRESET) { | 946 | if (i < 0 && errno != ECONNRESET) { |
910 | #ifdef HAVE_SSL | 947 | #ifdef HAVE_SSL |
@@ -1106,12 +1143,26 @@ check_http (void) | |||
1106 | msg[strlen(msg)-3] = '\0'; | 1143 | msg[strlen(msg)-3] = '\0'; |
1107 | 1144 | ||
1108 | /* check elapsed time */ | 1145 | /* check elapsed time */ |
1109 | xasprintf (&msg, | 1146 | if (show_extended_perfdata) |
1110 | _("%s - %d bytes in %.3f second response time %s|%s %s"), | 1147 | xasprintf (&msg, |
1111 | msg, page_len, elapsed_time, | 1148 | _("%s - %d bytes in %.3f second response time %s|%s %s %s %s %s %s %s"), |
1112 | (display_html ? "</A>" : ""), | 1149 | msg, page_len, elapsed_time, |
1113 | perfd_time (elapsed_time), perfd_size (page_len)); | 1150 | (display_html ? "</A>" : ""), |
1114 | 1151 | perfd_time (elapsed_time), | |
1152 | perfd_size (page_len), | ||
1153 | perfd_time_connect (elapsed_time_connect), | ||
1154 | perfd_time_ssl (elapsed_time_ssl), | ||
1155 | perfd_time_headers (elapsed_time_headers), | ||
1156 | perfd_time_firstbyte (elapsed_time_firstbyte), | ||
1157 | perfd_time_transfer (elapsed_time_transfer)); | ||
1158 | else | ||
1159 | xasprintf (&msg, | ||
1160 | _("%s - %d bytes in %.3f second response time %s|%s %s"), | ||
1161 | msg, page_len, elapsed_time, | ||
1162 | (display_html ? "</A>" : ""), | ||
1163 | perfd_time (elapsed_time), | ||
1164 | perfd_size (page_len)); | ||
1165 | |||
1115 | result = max_state_alt(get_status(elapsed_time, thlds), result); | 1166 | result = max_state_alt(get_status(elapsed_time, thlds), result); |
1116 | 1167 | ||
1117 | die (result, "HTTP %s: %s\n", state_text(result), msg); | 1168 | die (result, "HTTP %s: %s\n", state_text(result), msg); |
@@ -1299,7 +1350,30 @@ char *perfd_time (double elapsed_time) | |||
1299 | TRUE, 0, FALSE, 0); | 1350 | TRUE, 0, FALSE, 0); |
1300 | } | 1351 | } |
1301 | 1352 | ||
1353 | char *perfd_time_connect (double elapsed_time_connect) | ||
1354 | { | ||
1355 | return fperfdata ("time_connect", elapsed_time_connect, "s", FALSE, 0, FALSE, 0, FALSE, 0, FALSE, 0); | ||
1356 | } | ||
1357 | |||
1358 | char *perfd_time_ssl (double elapsed_time_ssl) | ||
1359 | { | ||
1360 | return fperfdata ("time_ssl", elapsed_time_ssl, "s", FALSE, 0, FALSE, 0, FALSE, 0, FALSE, 0); | ||
1361 | } | ||
1302 | 1362 | ||
1363 | char *perfd_time_headers (double elapsed_time_headers) | ||
1364 | { | ||
1365 | return fperfdata ("time_headers", elapsed_time_headers, "s", FALSE, 0, FALSE, 0, FALSE, 0, FALSE, 0); | ||
1366 | } | ||
1367 | |||
1368 | char *perfd_time_firstbyte (double elapsed_time_firstbyte) | ||
1369 | { | ||
1370 | return fperfdata ("time_firstbyte", elapsed_time_firstbyte, "s", FALSE, 0, FALSE, 0, FALSE, 0, FALSE, 0); | ||
1371 | } | ||
1372 | |||
1373 | char *perfd_time_transfer (double elapsed_time_transfer) | ||
1374 | { | ||
1375 | return fperfdata ("time_transfer", elapsed_time_transfer, "s", FALSE, 0, FALSE, 0, FALSE, 0, FALSE, 0); | ||
1376 | } | ||
1303 | 1377 | ||
1304 | char *perfd_size (int page_len) | 1378 | char *perfd_size (int page_len) |
1305 | { | 1379 | { |