diff options
-rw-r--r-- | plugins/check_http.c | 75 | ||||
-rw-r--r-- | plugins/utils.c | 12 | ||||
-rw-r--r-- | plugins/utils.h.in | 7 |
3 files changed, 47 insertions, 47 deletions
diff --git a/plugins/check_http.c b/plugins/check_http.c index 3ba406a..3fa34eb 100644 --- a/plugins/check_http.c +++ b/plugins/check_http.c | |||
@@ -31,7 +31,6 @@ | |||
31 | 31 | ||
32 | #include "config.h" | 32 | #include "config.h" |
33 | #include "common.h" | 33 | #include "common.h" |
34 | #include "version.h" | ||
35 | #include "netutils.h" | 34 | #include "netutils.h" |
36 | #include "utils.h" | 35 | #include "utils.h" |
37 | 36 | ||
@@ -160,6 +159,8 @@ int cflags = REG_NOSUB | REG_EXTENDED | REG_NEWLINE; | |||
160 | int errcode; | 159 | int errcode; |
161 | #endif | 160 | #endif |
162 | 161 | ||
162 | struct timeval tv; | ||
163 | |||
163 | #define server_type_check(server_type) \ | 164 | #define server_type_check(server_type) \ |
164 | (strcmp (server_type, "https") ? FALSE : TRUE) | 165 | (strcmp (server_type, "https") ? FALSE : TRUE) |
165 | 166 | ||
@@ -189,9 +190,9 @@ int server_url_length = 0; | |||
189 | int server_expect_yn = 0; | 190 | int server_expect_yn = 0; |
190 | char server_expect[MAX_INPUT_BUFFER] = HTTP_EXPECT; | 191 | char server_expect[MAX_INPUT_BUFFER] = HTTP_EXPECT; |
191 | char string_expect[MAX_INPUT_BUFFER] = ""; | 192 | char string_expect[MAX_INPUT_BUFFER] = ""; |
192 | int warning_time = 0; | 193 | double warning_time = 0; |
193 | int check_warning_time = FALSE; | 194 | int check_warning_time = FALSE; |
194 | int critical_time = 0; | 195 | double critical_time = 0; |
195 | int check_critical_time = FALSE; | 196 | int check_critical_time = FALSE; |
196 | char user_auth[MAX_INPUT_BUFFER] = ""; | 197 | char user_auth[MAX_INPUT_BUFFER] = ""; |
197 | int display_html = FALSE; | 198 | int display_html = FALSE; |
@@ -234,7 +235,7 @@ main (int argc, char **argv) | |||
234 | /* initialize alarm signal handling, set socket timeout, start timer */ | 235 | /* initialize alarm signal handling, set socket timeout, start timer */ |
235 | (void) signal (SIGALRM, socket_timeout_alarm_handler); | 236 | (void) signal (SIGALRM, socket_timeout_alarm_handler); |
236 | (void) alarm (socket_timeout); | 237 | (void) alarm (socket_timeout); |
237 | (void) time (&start_time); | 238 | gettimeofday (&tv, NULL); |
238 | 239 | ||
239 | #ifdef HAVE_SSL | 240 | #ifdef HAVE_SSL |
240 | if (use_ssl && check_cert == TRUE) { | 241 | if (use_ssl && check_cert == TRUE) { |
@@ -340,13 +341,13 @@ process_arguments (int argc, char **argv) | |||
340 | case 'c': /* critical time threshold */ | 341 | case 'c': /* critical time threshold */ |
341 | if (!is_intnonneg (optarg)) | 342 | if (!is_intnonneg (optarg)) |
342 | usage2 ("invalid critical threshold", optarg); | 343 | usage2 ("invalid critical threshold", optarg); |
343 | critical_time = atoi (optarg); | 344 | critical_time = strtod (optarg, NULL); |
344 | check_critical_time = TRUE; | 345 | check_critical_time = TRUE; |
345 | break; | 346 | break; |
346 | case 'w': /* warning time threshold */ | 347 | case 'w': /* warning time threshold */ |
347 | if (!is_intnonneg (optarg)) | 348 | if (!is_intnonneg (optarg)) |
348 | usage2 ("invalid warning threshold", optarg); | 349 | usage2 ("invalid warning threshold", optarg); |
349 | warning_time = atoi (optarg); | 350 | warning_time = strtod (optarg, NULL); |
350 | check_warning_time = TRUE; | 351 | check_warning_time = TRUE; |
351 | break; | 352 | break; |
352 | case 'L': /* show html link */ | 353 | case 'L': /* show html link */ |
@@ -363,7 +364,7 @@ process_arguments (int argc, char **argv) | |||
363 | if (specify_port == FALSE) | 364 | if (specify_port == FALSE) |
364 | server_port = HTTPS_PORT; | 365 | server_port = HTTPS_PORT; |
365 | break; | 366 | break; |
366 | case 'C': /* warning time threshold */ | 367 | case 'C': /* Check SSL cert validity */ |
367 | #ifdef HAVE_SSL | 368 | #ifdef HAVE_SSL |
368 | if (!is_intnonneg (optarg)) | 369 | if (!is_intnonneg (optarg)) |
369 | usage2 ("invalid certificate expiration period", optarg); | 370 | usage2 ("invalid certificate expiration period", optarg); |
@@ -389,10 +390,10 @@ process_arguments (int argc, char **argv) | |||
389 | break; | 390 | break; |
390 | /* Note: H, I, and u must be malloc'd or will fail on redirects */ | 391 | /* Note: H, I, and u must be malloc'd or will fail on redirects */ |
391 | case 'H': /* Host Name (virtual host) */ | 392 | case 'H': /* Host Name (virtual host) */ |
392 | host_name = strscpy (host_name, optarg); | 393 | host_name = strscpy (host_name, optarg); |
393 | break; | 394 | break; |
394 | case 'I': /* Server IP-address */ | 395 | case 'I': /* Server IP-address */ |
395 | server_address = strscpy (server_address, optarg); | 396 | server_address = strscpy (server_address, optarg); |
396 | break; | 397 | break; |
397 | case 'u': /* Host or server */ | 398 | case 'u': /* Host or server */ |
398 | server_url = strscpy (server_url, optarg); | 399 | server_url = strscpy (server_url, optarg); |
@@ -534,6 +535,7 @@ check_http (void) | |||
534 | char *pos = NULL; | 535 | char *pos = NULL; |
535 | char *x = NULL; | 536 | char *x = NULL; |
536 | char *orig_url = NULL; | 537 | char *orig_url = NULL; |
538 | double elapsed_time; | ||
537 | 539 | ||
538 | /* try to connect to the host at the given port number */ | 540 | /* try to connect to the host at the given port number */ |
539 | #ifdef HAVE_SSL | 541 | #ifdef HAVE_SSL |
@@ -657,10 +659,11 @@ check_http (void) | |||
657 | #endif | 659 | #endif |
658 | 660 | ||
659 | /* fetch the page */ | 661 | /* fetch the page */ |
660 | pagesize = (size_t) 0; | 662 | pagesize = (size_t) 1; |
663 | asprintf (&full_page, ""); | ||
661 | while ((i = my_recv ()) > 0) { | 664 | while ((i = my_recv ()) > 0) { |
662 | buffer[i] = '\0'; | 665 | buffer[i] = '\0'; |
663 | full_page = strscat (full_page, buffer); | 666 | asprintf (&full_page, "%s%s", full_page, buffer); |
664 | pagesize += i; | 667 | pagesize += i; |
665 | } | 668 | } |
666 | 669 | ||
@@ -821,10 +824,10 @@ check_http (void) | |||
821 | printf ("HTTP WARNING"); | 824 | printf ("HTTP WARNING"); |
822 | else if (onredirect == STATE_CRITICAL) | 825 | else if (onredirect == STATE_CRITICAL) |
823 | printf ("HTTP CRITICAL"); | 826 | printf ("HTTP CRITICAL"); |
824 | time (&end_time); | 827 | elapsed_time = delta_time (tv); |
825 | asprintf (&msg, ": %s - %d second response time %s%s|time=%d\n", | 828 | asprintf (&msg, ": %s - %6.2f second response time %s%s|time=%6.2f\n", |
826 | status_line, (int) (end_time - start_time), timestamp, | 829 | status_line, elapsed_time, timestamp, |
827 | (display_html ? "</A>" : ""), (int) (end_time - start_time)); | 830 | (display_html ? "</A>" : ""), elapsed_time); |
828 | terminate (onredirect, msg); | 831 | terminate (onredirect, msg); |
829 | } /* end if (strstr (status_line, "30[0-4]") */ | 832 | } /* end if (strstr (status_line, "30[0-4]") */ |
830 | 833 | ||
@@ -833,13 +836,13 @@ check_http (void) | |||
833 | 836 | ||
834 | 837 | ||
835 | /* check elapsed time */ | 838 | /* check elapsed time */ |
836 | time (&end_time); | 839 | elapsed_time = delta_time (tv); |
837 | asprintf (&msg, "HTTP problem: %s - %d second response time %s%s|time=%d\n", | 840 | asprintf (&msg, "HTTP problem: %s - %6.2f second response time %s%s|time=%6.2f\n", |
838 | status_line, (int) (end_time - start_time), timestamp, | 841 | status_line, elapsed_time, timestamp, |
839 | (display_html ? "</A>" : ""), (int) (end_time - start_time)); | 842 | (display_html ? "</A>" : ""), elapsed_time); |
840 | if (check_critical_time == TRUE && (end_time - start_time) > critical_time) | 843 | if (check_critical_time == TRUE && elapsed_time > critical_time) |
841 | terminate (STATE_CRITICAL, msg); | 844 | terminate (STATE_CRITICAL, msg); |
842 | if (check_warning_time == TRUE && (end_time - start_time) > warning_time) | 845 | if (check_warning_time == TRUE && elapsed_time > warning_time) |
843 | terminate (STATE_WARNING, msg); | 846 | terminate (STATE_WARNING, msg); |
844 | 847 | ||
845 | /* Page and Header content checks go here */ | 848 | /* Page and Header content checks go here */ |
@@ -847,14 +850,14 @@ check_http (void) | |||
847 | 850 | ||
848 | if (strlen (string_expect)) { | 851 | if (strlen (string_expect)) { |
849 | if (strstr (page, string_expect)) { | 852 | if (strstr (page, string_expect)) { |
850 | printf ("HTTP ok: %s - %d second response time %s%s|time=%d\n", | 853 | printf ("HTTP ok: %s - %6.2f second response time %s%s|time=%6.2f\n", |
851 | status_line, (int) (end_time - start_time), | 854 | status_line, elapsed_time, |
852 | timestamp, (display_html ? "</A>" : ""), (int) (end_time - start_time)); | 855 | timestamp, (display_html ? "</A>" : ""), elapsed_time); |
853 | exit (STATE_OK); | 856 | exit (STATE_OK); |
854 | } | 857 | } |
855 | else { | 858 | else { |
856 | printf ("HTTP CRITICAL: string not found%s|time=%d\n", | 859 | printf ("HTTP CRITICAL: string not found%s|time=%6.2f\n", |
857 | (display_html ? "</A>" : ""), (int) (end_time - start_time)); | 860 | (display_html ? "</A>" : ""), elapsed_time); |
858 | exit (STATE_CRITICAL); | 861 | exit (STATE_CRITICAL); |
859 | } | 862 | } |
860 | } | 863 | } |
@@ -862,15 +865,15 @@ check_http (void) | |||
862 | if (strlen (regexp)) { | 865 | if (strlen (regexp)) { |
863 | errcode = regexec (&preg, page, REGS, pmatch, 0); | 866 | errcode = regexec (&preg, page, REGS, pmatch, 0); |
864 | if (errcode == 0) { | 867 | if (errcode == 0) { |
865 | printf ("HTTP ok: %s - %d second response time %s%s|time=%d\n", | 868 | printf ("HTTP ok: %s - %6.2f second response time %s%s|time=%6.2f\n", |
866 | status_line, (int) (end_time - start_time), | 869 | status_line, elapsed_time, |
867 | timestamp, (display_html ? "</A>" : ""), (int) (end_time - start_time)); | 870 | timestamp, (display_html ? "</A>" : ""), elapsed_time); |
868 | exit (STATE_OK); | 871 | exit (STATE_OK); |
869 | } | 872 | } |
870 | else { | 873 | else { |
871 | if (errcode == REG_NOMATCH) { | 874 | if (errcode == REG_NOMATCH) { |
872 | printf ("HTTP CRITICAL: pattern not found%s|time=%d\n", | 875 | printf ("HTTP CRITICAL: pattern not found%s|time=%6.2f\n", |
873 | (display_html ? "</A>" : ""), (int) (end_time - start_time)); | 876 | (display_html ? "</A>" : ""), elapsed_time); |
874 | exit (STATE_CRITICAL); | 877 | exit (STATE_CRITICAL); |
875 | } | 878 | } |
876 | else { | 879 | else { |
@@ -883,9 +886,9 @@ check_http (void) | |||
883 | #endif | 886 | #endif |
884 | 887 | ||
885 | /* We only get here if all tests have been passed */ | 888 | /* We only get here if all tests have been passed */ |
886 | asprintf (&msg, "HTTP ok: %s - %d second response time %s%s|time=%d\n", | 889 | asprintf (&msg, "HTTP ok: %s - %6.2f second response time %s%s|time=%6.2f\n", |
887 | status_line, (int) (end_time - start_time), | 890 | status_line, (float)elapsed_time, |
888 | timestamp, (display_html ? "</A>" : ""), (int) (end_time - start_time)); | 891 | timestamp, (display_html ? "</A>" : ""), elapsed_time); |
889 | terminate (STATE_OK, msg); | 892 | terminate (STATE_OK, msg); |
890 | return STATE_UNKNOWN; | 893 | return STATE_UNKNOWN; |
891 | } | 894 | } |
@@ -915,7 +918,7 @@ int connect_SSL (void) | |||
915 | alarm (socket_timeout); | 918 | alarm (socket_timeout); |
916 | 919 | ||
917 | /* Save start time */ | 920 | /* Save start time */ |
918 | time (&start_time); | 921 | gettimeofday (&tv, NULL); |
919 | 922 | ||
920 | /* Make TCP connection */ | 923 | /* Make TCP connection */ |
921 | if (my_tcp_connect (server_address, server_port, &sd) == STATE_OK) { | 924 | if (my_tcp_connect (server_address, server_port, &sd) == STATE_OK) { |
diff --git a/plugins/utils.c b/plugins/utils.c index 05d3f79..0d1729e 100644 --- a/plugins/utils.c +++ b/plugins/utils.c | |||
@@ -317,14 +317,14 @@ is_option (char *str) | |||
317 | 317 | ||
318 | 318 | ||
319 | double | 319 | double |
320 | delta_time (struct timeval *tv) | 320 | delta_time (struct timeval tv) |
321 | { | 321 | { |
322 | struct timeval *pt; | 322 | struct timeval now; |
323 | struct timezone *tz; | 323 | struct timezone tz; |
324 | double et; | ||
324 | 325 | ||
325 | gettimeofday (pt, tz); | 326 | gettimeofday (&now, NULL); |
326 | 327 | return ((double)(now.tv_sec - tv.tv_sec) + (double)(now.tv_usec - tv.tv_usec) / (double)1000000); | |
327 | return (pt->tv_sec - tv->tv_sec + (pt->tv_usec - tv->tv_usec) / 1000000); | ||
328 | } | 328 | } |
329 | 329 | ||
330 | 330 | ||
diff --git a/plugins/utils.h.in b/plugins/utils.h.in index e910c41..5a3e120 100644 --- a/plugins/utils.h.in +++ b/plugins/utils.h.in | |||
@@ -52,17 +52,14 @@ struct timeval { | |||
52 | long tv_usec; /* microseconds */ | 52 | long tv_usec; /* microseconds */ |
53 | }; | 53 | }; |
54 | 54 | ||
55 | struct timezone { | ||
56 | int tz_minuteswest; /* minutes W of Greenwich */ | ||
57 | int tz_dsttime; /* type of dst correction */ | ||
58 | }; | ||
59 | |||
60 | #define gettimeofday (tvp,tz) {\ | 55 | #define gettimeofday (tvp,tz) {\ |
61 | tvp->tv_usec=0;\ | 56 | tvp->tv_usec=0;\ |
62 | tvp->tv_sec=(long)time();\ | 57 | tvp->tv_sec=(long)time();\ |
63 | } | 58 | } |
64 | #endif | 59 | #endif |
65 | 60 | ||
61 | double delta_time (struct timeval tv); | ||
62 | |||
66 | /* Handle strings safely */ | 63 | /* Handle strings safely */ |
67 | 64 | ||
68 | void strip (char *buffer); | 65 | void strip (char *buffer); |