[Nagiosplug-checkins] CVS: nagiosplug/plugins check_http.c,1.7,1.8 utils.c,1.5,1.6 utils.h.in,1.3,1.4
Karl DeBisschop
kdebisschop at users.sourceforge.net
Wed Oct 16 14:33:02 CEST 2002
Update of /cvsroot/nagiosplug/nagiosplug/plugins
In directory usw-pr-cvs1:/tmp/cvs-serv29144/plugins
Modified Files:
check_http.c utils.c utils.h.in
Log Message:
millisecond timimg where supported
Index: check_http.c
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/check_http.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -r1.7 -r1.8
*** check_http.c 16 Oct 2002 10:14:53 -0000 1.7
--- check_http.c 16 Oct 2002 21:32:33 -0000 1.8
***************
*** 32,36 ****
#include "config.h"
#include "common.h"
- #include "version.h"
#include "netutils.h"
#include "utils.h"
--- 32,35 ----
***************
*** 161,164 ****
--- 160,165 ----
#endif
+ struct timeval tv;
+
#define server_type_check(server_type) \
(strcmp (server_type, "https") ? FALSE : TRUE)
***************
*** 190,196 ****
char server_expect[MAX_INPUT_BUFFER] = HTTP_EXPECT;
char string_expect[MAX_INPUT_BUFFER] = "";
! int warning_time = 0;
int check_warning_time = FALSE;
! int critical_time = 0;
int check_critical_time = FALSE;
char user_auth[MAX_INPUT_BUFFER] = "";
--- 191,197 ----
char server_expect[MAX_INPUT_BUFFER] = HTTP_EXPECT;
char string_expect[MAX_INPUT_BUFFER] = "";
! double warning_time = 0;
int check_warning_time = FALSE;
! double critical_time = 0;
int check_critical_time = FALSE;
char user_auth[MAX_INPUT_BUFFER] = "";
***************
*** 235,239 ****
(void) signal (SIGALRM, socket_timeout_alarm_handler);
(void) alarm (socket_timeout);
! (void) time (&start_time);
#ifdef HAVE_SSL
--- 236,240 ----
(void) signal (SIGALRM, socket_timeout_alarm_handler);
(void) alarm (socket_timeout);
! gettimeofday (&tv, NULL);
#ifdef HAVE_SSL
***************
*** 341,345 ****
if (!is_intnonneg (optarg))
usage2 ("invalid critical threshold", optarg);
! critical_time = atoi (optarg);
check_critical_time = TRUE;
break;
--- 342,346 ----
if (!is_intnonneg (optarg))
usage2 ("invalid critical threshold", optarg);
! critical_time = strtod (optarg, NULL);
check_critical_time = TRUE;
break;
***************
*** 347,351 ****
if (!is_intnonneg (optarg))
usage2 ("invalid warning threshold", optarg);
! warning_time = atoi (optarg);
check_warning_time = TRUE;
break;
--- 348,352 ----
if (!is_intnonneg (optarg))
usage2 ("invalid warning threshold", optarg);
! warning_time = strtod (optarg, NULL);
check_warning_time = TRUE;
break;
***************
*** 364,368 ****
server_port = HTTPS_PORT;
break;
! case 'C': /* warning time threshold */
#ifdef HAVE_SSL
if (!is_intnonneg (optarg))
--- 365,369 ----
server_port = HTTPS_PORT;
break;
! case 'C': /* Check SSL cert validity */
#ifdef HAVE_SSL
if (!is_intnonneg (optarg))
***************
*** 390,397 ****
/* Note: H, I, and u must be malloc'd or will fail on redirects */
case 'H': /* Host Name (virtual host) */
! host_name = strscpy (host_name, optarg);
break;
case 'I': /* Server IP-address */
! server_address = strscpy (server_address, optarg);
break;
case 'u': /* Host or server */
--- 391,398 ----
/* Note: H, I, and u must be malloc'd or will fail on redirects */
case 'H': /* Host Name (virtual host) */
! host_name = strscpy (host_name, optarg);
break;
case 'I': /* Server IP-address */
! server_address = strscpy (server_address, optarg);
break;
case 'u': /* Host or server */
***************
*** 535,538 ****
--- 536,540 ----
char *x = NULL;
char *orig_url = NULL;
+ double elapsed_time;
/* try to connect to the host at the given port number */
***************
*** 658,665 ****
/* fetch the page */
! pagesize = (size_t) 0;
while ((i = my_recv ()) > 0) {
! buffer[i] = '\0';
! full_page = strscat (full_page, buffer);
pagesize += i;
}
--- 660,668 ----
/* fetch the page */
! pagesize = (size_t) 1;
! asprintf (&full_page, "");
while ((i = my_recv ()) > 0) {
! buffer[i] = '\0';
! asprintf (&full_page, "%s%s", full_page, buffer);
pagesize += i;
}
***************
*** 822,829 ****
else if (onredirect == STATE_CRITICAL)
printf ("HTTP CRITICAL");
! time (&end_time);
! asprintf (&msg, ": %s - %d second response time %s%s|time=%d\n",
! status_line, (int) (end_time - start_time), timestamp,
! (display_html ? "</A>" : ""), (int) (end_time - start_time));
terminate (onredirect, msg);
} /* end if (strstr (status_line, "30[0-4]") */
--- 825,832 ----
else if (onredirect == STATE_CRITICAL)
printf ("HTTP CRITICAL");
! elapsed_time = delta_time (tv);
! asprintf (&msg, ": %s - %6.2f second response time %s%s|time=%6.2f\n",
! status_line, elapsed_time, timestamp,
! (display_html ? "</A>" : ""), elapsed_time);
terminate (onredirect, msg);
} /* end if (strstr (status_line, "30[0-4]") */
***************
*** 834,844 ****
/* check elapsed time */
! time (&end_time);
! asprintf (&msg, "HTTP problem: %s - %d second response time %s%s|time=%d\n",
! status_line, (int) (end_time - start_time), timestamp,
! (display_html ? "</A>" : ""), (int) (end_time - start_time));
! if (check_critical_time == TRUE && (end_time - start_time) > critical_time)
terminate (STATE_CRITICAL, msg);
! if (check_warning_time == TRUE && (end_time - start_time) > warning_time)
terminate (STATE_WARNING, msg);
--- 837,847 ----
/* check elapsed time */
! elapsed_time = delta_time (tv);
! asprintf (&msg, "HTTP problem: %s - %6.2f second response time %s%s|time=%6.2f\n",
! status_line, elapsed_time, timestamp,
! (display_html ? "</A>" : ""), elapsed_time);
! if (check_critical_time == TRUE && elapsed_time > critical_time)
terminate (STATE_CRITICAL, msg);
! if (check_warning_time == TRUE && elapsed_time > warning_time)
terminate (STATE_WARNING, msg);
***************
*** 848,859 ****
if (strlen (string_expect)) {
if (strstr (page, string_expect)) {
! printf ("HTTP ok: %s - %d second response time %s%s|time=%d\n",
! status_line, (int) (end_time - start_time),
! timestamp, (display_html ? "</A>" : ""), (int) (end_time - start_time));
exit (STATE_OK);
}
else {
! printf ("HTTP CRITICAL: string not found%s|time=%d\n",
! (display_html ? "</A>" : ""), (int) (end_time - start_time));
exit (STATE_CRITICAL);
}
--- 851,862 ----
if (strlen (string_expect)) {
if (strstr (page, string_expect)) {
! printf ("HTTP ok: %s - %6.2f second response time %s%s|time=%6.2f\n",
! status_line, elapsed_time,
! timestamp, (display_html ? "</A>" : ""), elapsed_time);
exit (STATE_OK);
}
else {
! printf ("HTTP CRITICAL: string not found%s|time=%6.2f\n",
! (display_html ? "</A>" : ""), elapsed_time);
exit (STATE_CRITICAL);
}
***************
*** 863,875 ****
errcode = regexec (&preg, page, REGS, pmatch, 0);
if (errcode == 0) {
! printf ("HTTP ok: %s - %d second response time %s%s|time=%d\n",
! status_line, (int) (end_time - start_time),
! timestamp, (display_html ? "</A>" : ""), (int) (end_time - start_time));
exit (STATE_OK);
}
else {
if (errcode == REG_NOMATCH) {
! printf ("HTTP CRITICAL: pattern not found%s|time=%d\n",
! (display_html ? "</A>" : ""), (int) (end_time - start_time));
exit (STATE_CRITICAL);
}
--- 866,878 ----
errcode = regexec (&preg, page, REGS, pmatch, 0);
if (errcode == 0) {
! printf ("HTTP ok: %s - %6.2f second response time %s%s|time=%6.2f\n",
! status_line, elapsed_time,
! timestamp, (display_html ? "</A>" : ""), elapsed_time);
exit (STATE_OK);
}
else {
if (errcode == REG_NOMATCH) {
! printf ("HTTP CRITICAL: pattern not found%s|time=%6.2f\n",
! (display_html ? "</A>" : ""), elapsed_time);
exit (STATE_CRITICAL);
}
***************
*** 884,890 ****
/* We only get here if all tests have been passed */
! asprintf (&msg, "HTTP ok: %s - %d second response time %s%s|time=%d\n",
! status_line, (int) (end_time - start_time),
! timestamp, (display_html ? "</A>" : ""), (int) (end_time - start_time));
terminate (STATE_OK, msg);
return STATE_UNKNOWN;
--- 887,893 ----
/* We only get here if all tests have been passed */
! asprintf (&msg, "HTTP ok: %s - %6.2f second response time %s%s|time=%6.2f\n",
! status_line, (float)elapsed_time,
! timestamp, (display_html ? "</A>" : ""), elapsed_time);
terminate (STATE_OK, msg);
return STATE_UNKNOWN;
***************
*** 916,920 ****
/* Save start time */
! time (&start_time);
/* Make TCP connection */
--- 919,923 ----
/* Save start time */
! gettimeofday (&tv, NULL);
/* Make TCP connection */
Index: utils.c
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/utils.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -r1.5 -r1.6
*** utils.c 16 Oct 2002 10:14:14 -0000 1.5
--- utils.c 16 Oct 2002 21:32:33 -0000 1.6
***************
*** 318,329 ****
double
! delta_time (struct timeval *tv)
{
! struct timeval *pt;
! struct timezone *tz;
! gettimeofday (pt, tz);
!
! return (pt->tv_sec - tv->tv_sec + (pt->tv_usec - tv->tv_usec) / 1000000);
}
--- 318,329 ----
double
! delta_time (struct timeval tv)
{
! struct timeval now;
! struct timezone tz;
! double et;
! gettimeofday (&now, NULL);
! return ((double)(now.tv_sec - tv.tv_sec) + (double)(now.tv_usec - tv.tv_usec) / (double)1000000);
}
Index: utils.h.in
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/utils.h.in,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -r1.3 -r1.4
*** utils.h.in 16 Oct 2002 04:56:10 -0000 1.3
--- utils.h.in 16 Oct 2002 21:32:33 -0000 1.4
***************
*** 53,61 ****
};
- struct timezone {
- int tz_minuteswest; /* minutes W of Greenwich */
- int tz_dsttime; /* type of dst correction */
- };
-
#define gettimeofday (tvp,tz) {\
tvp->tv_usec=0;\
--- 53,56 ----
***************
*** 63,66 ****
--- 58,63 ----
}
#endif
+
+ double delta_time (struct timeval tv);
/* Handle strings safely */
More information about the Commits
mailing list