[Nagiosplug-checkins] CVS: nagiosplug/plugins check_http.c,1.41,1.42
Karl DeBisschop
kdebisschop at users.sourceforge.net
Fri Aug 8 21:20:04 CEST 2003
- Previous message: [Nagiosplug-checkins] CVS: nagiosplug/plugins utils.c,1.29,1.30 utils.h,1.13,1.14
- Next message: [Nagiosplug-checkins] CVS: nagiosplug/plugins check_dig.c,1.15,1.16 check_http.c,1.42,1.43 check_load.c,1.9,1.10 check_mrtg.c,1.7,1.8 check_mrtgtraf.c,1.7,1.8 check_nwstat.c,1.10,1.11 check_overcr.c,1.5,1.6 check_ping.c,1.20,1.21 check_procs.c,1.17,1.18 check_real.c,1.9,1.10 utils.c,1.30,1.31 utils.h,1.14,1.15
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Update of /cvsroot/nagiosplug/nagiosplug/plugins
In directory sc8-pr-cvs1:/tmp/cvs-serv28535
Modified Files:
check_http.c
Log Message:
more pedantic compiler warns, change to microsecond output for perf data, add size to perf data
Index: check_http.c
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/check_http.c,v
retrieving revision 1.41
retrieving revision 1.42
diff -C2 -r1.41 -r1.42
*** check_http.c 9 Aug 2003 00:56:03 -0000 1.41
--- check_http.c 9 Aug 2003 04:19:41 -0000 1.42
***************
*** 41,54 ****
#include <err.h>
#include <rand.h>
! #endif
!
! #ifdef HAVE_OPENSSL_SSL_H
! #include <openssl/rsa.h>
! #include <openssl/crypto.h>
! #include <openssl/x509.h>
! #include <openssl/pem.h>
! #include <openssl/ssl.h>
! #include <openssl/err.h>
! #include <openssl/rand.h>
#endif
--- 41,54 ----
#include <err.h>
#include <rand.h>
! #else
! # ifdef HAVE_OPENSSL_SSL_H
! # include <openssl/rsa.h>
! # include <openssl/crypto.h>
! # include <openssl/x509.h>
! # include <openssl/pem.h>
! # include <openssl/ssl.h>
! # include <openssl/err.h>
! # include <openssl/rand.h>
! # endif
#endif
***************
*** 56,60 ****
int check_cert = FALSE;
int days_till_exp;
! char *randbuff = "";
SSL_CTX *ctx;
SSL *ssl;
--- 56,60 ----
int check_cert = FALSE;
int days_till_exp;
! char *randbuff;
SSL_CTX *ctx;
SSL *ssl;
***************
*** 85,96 ****
#define server_port_check(use_ssl) (use_ssl ? HTTPS_PORT : HTTP_PORT)
- /* per RFC 2396 */
-
- #define HDR_LOCATION "%*[Ll]%*[Oo]%*[Cc]%*[Aa]%*[Tt]%*[Ii]%*[Oo]%*[Nn]: "
- #define URI_HTTP "%[HTPShtps]://"
- #define URI_HOST "%[-.abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789]"
- #define URI_PORT ":%[0123456789]"
- #define URI_PATH "%[-_.!~*'();/?:@&=+$,%#abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789]"
-
#define HTTP_URL "/"
#define CRLF "\r\n"
--- 85,88 ----
***************
*** 101,107 ****
char server_port_text[6] = "";
char server_type[6] = "http";
! char *server_address = "";
! char *host_name = "";
! char *server_url = "";
int server_url_length;
int server_expect_yn = 0;
--- 93,99 ----
char server_port_text[6] = "";
char server_type[6] = "http";
! char *server_address;
! char *host_name;
! char *server_url;
int server_url_length;
int server_expect_yn = 0;
***************
*** 119,124 ****
int sd;
int min_page_len = 0;
! char *http_method = "GET";
! char *http_post_data = "";
char buffer[MAX_INPUT_BUFFER];
--- 111,116 ----
int sd;
int min_page_len = 0;
! char *http_method;
! char *http_post_data;
char buffer[MAX_INPUT_BUFFER];
***************
*** 137,141 ****
/* Set default URL. Must be malloced for subsequent realloc if --onredirect=follow */
! asprintf (&server_url, "%s", HTTP_URL);
server_url_length = strlen(server_url);
--- 129,133 ----
/* Set default URL. Must be malloced for subsequent realloc if --onredirect=follow */
! server_url = strdup(HTTP_URL);
server_url_length = strlen(server_url);
***************
*** 162,167 ****
if (use_ssl && check_cert == TRUE) {
if (connect_SSL () != OK)
! die (STATE_CRITICAL,
! _("HTTP CRITICAL - Could not make SSL connection\n"));
if ((server_cert = SSL_get_peer_certificate (ssl)) != NULL) {
result = check_certificate (&server_cert);
--- 154,158 ----
if (use_ssl && check_cert == TRUE) {
if (connect_SSL () != OK)
! die (STATE_CRITICAL, _("HTTP CRITICAL - Could not make SSL connection\n"));
if ((server_cert = SSL_get_peer_certificate (ssl)) != NULL) {
result = check_certificate (&server_cert);
***************
*** 314,327 ****
/* Note: H, I, and u must be malloc'd or will fail on redirects */
case 'H': /* Host Name (virtual host) */
! asprintf (&host_name, "%s", optarg);
break;
case 'I': /* Server IP-address */
! asprintf (&server_address, "%s", optarg);
break;
! case 'u': /* Host or server */
asprintf (&server_url, "%s", optarg);
server_url_length = strlen (server_url);
break;
! case 'p': /* Host or server */
if (!is_intnonneg (optarg))
usage2 (_("invalid port number"), optarg);
--- 305,318 ----
/* Note: H, I, and u must be malloc'd or will fail on redirects */
case 'H': /* Host Name (virtual host) */
! host_name = strdup (optarg);
break;
case 'I': /* Server IP-address */
! server_address = strdup(optarg);
break;
! case 'u': /* URL path */
asprintf (&server_url, "%s", optarg);
server_url_length = strlen (server_url);
break;
! case 'p': /* Server port */
if (!is_intnonneg (optarg))
usage2 (_("invalid port number"), optarg);
***************
*** 336,341 ****
break;
case 'P': /* HTTP POST data in URL encoded format */
! asprintf (&http_method, "%s", "POST");
! asprintf (&http_post_data, "%s", optarg);
break;
case 's': /* string or substring */
--- 327,333 ----
break;
case 'P': /* HTTP POST data in URL encoded format */
! if (http_method || http_post_data) break;
! http_method = strdup("POST");
! http_post_data = strdup(optarg);
break;
case 's': /* string or substring */
***************
*** 392,406 ****
c = optind;
! if (strcmp (server_address, "") == 0 && c < argc)
! asprintf (&server_address, "%s", argv[c++]);
! if (strcmp (host_name, "") == 0 && c < argc)
asprintf (&host_name, "%s", argv[c++]);
! if (strcmp (server_address ,"") == 0) {
! if (strcmp (host_name, "") == 0)
usage (_("check_http: you must specify a server address or host name\n"));
else
! asprintf (&server_address, "%s", host_name);
}
--- 384,398 ----
c = optind;
! if (server_address == NULL && c < argc)
! server_address = strdup (argv[c++]);
! if (host_name == NULL && c < argc)
asprintf (&host_name, "%s", argv[c++]);
! if (server_address == NULL) {
! if (host_name == NULL)
usage (_("check_http: you must specify a server address or host name\n"));
else
! server_address = strdup (host_name);
}
***************
*** 408,411 ****
--- 400,406 ----
socket_timeout = (int)critical_time + 1;
+ if (http_method == NULL)
+ http_method = strdup ("GET");
+
return TRUE;
}
***************
*** 456,474 ****
int
check_http (void)
{
! char *msg = NULL;
! char *status_line = "";
! char *header = NULL;
! char *page = "";
! char *auth = NULL;
int i = 0;
size_t pagesize = 0;
! char *full_page = "";
! char *buf = NULL;
! char *pos = "";
! char *x = NULL;
! char *orig_url = NULL;
double elapsed_time;
int page_len = 0;
--- 451,482 ----
+ /* per RFC 2396 */
+ #define HDR_LOCATION "%*[Ll]%*[Oo]%*[Cc]%*[Aa]%*[Tt]%*[Ii]%*[Oo]%*[Nn]: "
+ #define URI_HTTP "%[HTPShtps]://"
+ #define URI_HOST "%[-.abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789]"
+ #define URI_PORT ":%[0123456789]"
+ #define URI_PATH "%[-_.!~*'();/?:@&=+$,%#abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789]"
+ #define HD1 HDR_LOCATION URI_HTTP URI_HOST URI_PORT URI_PATH
+ #define HD2 HDR_LOCATION URI_HTTP URI_HOST URI_PATH
+ #define HD3 HDR_LOCATION URI_HTTP URI_HOST URI_PORT
+ #define HD4 HDR_LOCATION URI_HTTP URI_HOST
+ #define HD5 HDR_LOCATION URI_PATH
+
int
check_http (void)
{
! char *msg;
! char *status_line;
! char *header;
! char *page;
! char *auth;
int i = 0;
size_t pagesize = 0;
! char *full_page;
! char *buf;
! char *pos;
! char *x;
! char *orig_url;
! long microsec;
double elapsed_time;
int page_len = 0;
***************
*** 505,509 ****
/* optionally send the host header info (not clear if it's usable) */
! if (strcmp (host_name, ""))
asprintf (&buf, "%sHost: %s\r\n", buf, host_name);
--- 513,517 ----
/* optionally send the host header info (not clear if it's usable) */
! if (host_name)
asprintf (&buf, "%sHost: %s\r\n", buf, host_name);
***************
*** 513,517 ****
/* optionally send the authentication info */
! if (strcmp (user_auth, "")) {
auth = base64 (user_auth, strlen (user_auth));
asprintf (&buf, "%sAuthorization: Basic %s\r\n", buf, auth);
--- 521,525 ----
/* optionally send the authentication info */
! if (strlen(user_auth)) {
auth = base64 (user_auth, strlen (user_auth));
asprintf (&buf, "%sAuthorization: Basic %s\r\n", buf, auth);
***************
*** 519,523 ****
/* either send http POST data */
! if (strlen (http_post_data)) {
asprintf (&buf, "%sContent-Type: application/x-www-form-urlencoded\r\n", buf);
asprintf (&buf, "%sContent-Length: %i\r\n\r\n", buf, strlen (http_post_data));
--- 527,531 ----
/* either send http POST data */
! if (http_post_data) {
asprintf (&buf, "%sContent-Type: application/x-www-form-urlencoded\r\n", buf);
asprintf (&buf, "%sContent-Length: %i\r\n\r\n", buf, strlen (http_post_data));
***************
*** 544,547 ****
--- 552,556 ----
/* fetch the page */
+ full_page = strdup("");
while ((i = my_recv ()) > 0) {
buffer[i] = '\0';
***************
*** 664,690 ****
server_address = realloc (server_address, MAX_IPV4_HOSTLENGTH + 1);
if (server_address == NULL)
! die (STATE_UNKNOWN,
! _("HTTP UNKNOWN: could not allocate server_address"));
if (strcspn (pos, "\r\n") > (size_t)server_url_length) {
server_url = realloc (server_url, strcspn (pos, "\r\n"));
if (server_url == NULL)
! die (STATE_UNKNOWN,
! _("HTTP UNKNOWN: could not allocate server_url"));
server_url_length = strcspn (pos, "\r\n");
}
! if (sscanf (pos, HDR_LOCATION URI_HTTP URI_HOST URI_PORT URI_PATH, server_type, server_address, server_port_text, server_url) == 4) {
! asprintf (&host_name, "%s", server_address);
use_ssl = server_type_check (server_type);
server_port = atoi (server_port_text);
check_http ();
}
! else if (sscanf (pos, HDR_LOCATION URI_HTTP URI_HOST URI_PATH, server_type, server_address, server_url) == 3 ) {
! asprintf (&host_name, "%s", server_address);
use_ssl = server_type_check (server_type);
server_port = server_port_check (use_ssl);
check_http ();
}
! else if (sscanf (pos, HDR_LOCATION URI_HTTP URI_HOST URI_PORT, server_type, server_address, server_port_text) == 3) {
! asprintf (&host_name, "%s", server_address);
strcpy (server_url, "/");
use_ssl = server_type_check (server_type);
--- 673,703 ----
server_address = realloc (server_address, MAX_IPV4_HOSTLENGTH + 1);
if (server_address == NULL)
! die (STATE_UNKNOWN,_("ERROR: could not allocate server_address"));
if (strcspn (pos, "\r\n") > (size_t)server_url_length) {
server_url = realloc (server_url, strcspn (pos, "\r\n"));
if (server_url == NULL)
! die (STATE_UNKNOWN, _("ERROR: could not allocate server_url"));
server_url_length = strcspn (pos, "\r\n");
}
! /* HDR_LOCATION, URI_HTTP, URI_HOST, URI_PORT, URI_PATH */
! if (sscanf (pos, HD1, server_type, server_address, server_port_text, server_url) == 4) {
! if (host_name != NULL) free(host_name);
! host_name = strdup(server_address);
use_ssl = server_type_check (server_type);
server_port = atoi (server_port_text);
check_http ();
}
! /* HDR_LOCATION URI_HTTP URI_HOST URI_PATH */
! else if (sscanf (pos, HD2, server_type, server_address, server_url) == 3 ) {
! if (host_name != NULL) free(host_name);
! host_name = strdup(server_address);
use_ssl = server_type_check (server_type);
server_port = server_port_check (use_ssl);
check_http ();
}
! /* HDR_LOCATION URI_HTTP URI_HOST URI_PORT */
! else if(sscanf (pos, HD3, server_type, server_address, server_port_text) == 3) {
! if (host_name != NULL) free(host_name);
! host_name = strdup(server_address);
strcpy (server_url, "/");
use_ssl = server_type_check (server_type);
***************
*** 692,697 ****
check_http ();
}
! else if (sscanf (pos, HDR_LOCATION URI_HTTP URI_HOST, server_type, server_address) == 2) {
! asprintf (&host_name, "%s", server_address);
strcpy (server_url, "/");
use_ssl = server_type_check (server_type);
--- 705,712 ----
check_http ();
}
! /* HDR_LOCATION URI_HTTP URI_HOST */
! else if(sscanf (pos, HD4, server_type, server_address) == 2) {
! if (host_name != NULL) free(host_name);
! host_name = strdup(server_address);
strcpy (server_url, "/");
use_ssl = server_type_check (server_type);
***************
*** 699,703 ****
check_http ();
}
! else if (sscanf (pos, HDR_LOCATION URI_PATH, server_url) == 1) {
if ((server_url[0] != '/') && (x = strrchr(orig_url, '/'))) {
*x = '\0';
--- 714,719 ----
check_http ();
}
! /* HDR_LOCATION URI_PATH */
! else if (sscanf (pos, HD5, server_url) == 1) {
if ((server_url[0] != '/') && (x = strrchr(orig_url, '/'))) {
*x = '\0';
***************
*** 722,729 ****
else if (onredirect == STATE_CRITICAL)
printf (_("CRITICAL"));
! elapsed_time = delta_time (tv);
! asprintf (&msg, _(" - %s - %.3f second response time %s%s|time=%.3f\n"),
status_line, elapsed_time, timestamp,
! (display_html ? "</A>" : ""), elapsed_time);
die (onredirect, "%s", msg);
} /* end if (strstr (status_line, "30[0-4]") */
--- 738,746 ----
else if (onredirect == STATE_CRITICAL)
printf (_("CRITICAL"));
! microsec = deltime (tv);
! elapsed_time = (double)microsec / 1.0e6;
! asprintf (&msg, _(" - %s - %.3f second response time %s%s|time=%ldus size=%dB\n"),
status_line, elapsed_time, timestamp,
! (display_html ? "</A>" : ""), microsec, pagesize);
die (onredirect, "%s", msg);
} /* end if (strstr (status_line, "30[0-4]") */
***************
*** 734,741 ****
/* check elapsed time */
! elapsed_time = delta_time (tv);
! asprintf (&msg, _("HTTP problem: %s - %.3f second response time %s%s|time=%.3f\n"),
status_line, elapsed_time, timestamp,
! (display_html ? "</A>" : ""), elapsed_time);
if (check_critical_time == TRUE && elapsed_time > critical_time)
die (STATE_CRITICAL, "%s", msg);
--- 751,759 ----
/* check elapsed time */
! microsec = deltime (tv);
! elapsed_time = (double)microsec / 1.0e6;
! asprintf (&msg, _("HTTP problem: %s - %.3f second response time %s%s|time=%ldus size=%dB\n"),
status_line, elapsed_time, timestamp,
! (display_html ? "</A>" : ""), microsec, pagesize);
if (check_critical_time == TRUE && elapsed_time > critical_time)
die (STATE_CRITICAL, "%s", msg);
***************
*** 748,759 ****
if (strlen (string_expect)) {
if (strstr (page, string_expect)) {
! printf (_("HTTP OK %s - %.3f second response time %s%s|time=%.3f\n"),
status_line, elapsed_time,
! timestamp, (display_html ? "</A>" : ""), elapsed_time);
exit (STATE_OK);
}
else {
! printf (_("CRITICAL - string not found%s|time=%.3f\n"),
! (display_html ? "</A>" : ""), elapsed_time);
exit (STATE_CRITICAL);
}
--- 766,777 ----
if (strlen (string_expect)) {
if (strstr (page, string_expect)) {
! printf (_("HTTP OK %s - %.3f second response time %s%s|time=%ldus size=%dB\n"),
status_line, elapsed_time,
! timestamp, (display_html ? "</A>" : ""), microsec, pagesize);
exit (STATE_OK);
}
else {
! printf (_("CRITICAL - string not found%s|time=%ldus\n size=%dB"),
! (display_html ? "</A>" : ""), microsec, pagesize);
exit (STATE_CRITICAL);
}
***************
*** 763,775 ****
errcode = regexec (&preg, page, REGS, pmatch, 0);
if (errcode == 0) {
! printf (_("HTTP OK %s - %.3f second response time %s%s|time=%.3f\n"),
status_line, elapsed_time,
! timestamp, (display_html ? "</A>" : ""), elapsed_time);
exit (STATE_OK);
}
else {
if (errcode == REG_NOMATCH) {
! printf (_("CRITICAL - pattern not found%s|time=%.3f\n"),
! (display_html ? "</A>" : ""), elapsed_time);
exit (STATE_CRITICAL);
}
--- 781,793 ----
errcode = regexec (&preg, page, REGS, pmatch, 0);
if (errcode == 0) {
! printf (_("HTTP OK %s - %.3f second response time %s%s|time=%ldus size=%dB\n"),
status_line, elapsed_time,
! timestamp, (display_html ? "</A>" : ""), microsec, pagesize);
exit (STATE_OK);
}
else {
if (errcode == REG_NOMATCH) {
! printf (_("CRITICAL - pattern not found%s|time=%ldus size=%dB\n"),
! (display_html ? "</A>" : ""), microsec, pagesize);
exit (STATE_CRITICAL);
}
***************
*** 791,797 ****
}
/* We only get here if all tests have been passed */
! asprintf (&msg, _("HTTP OK %s - %.3f second response time %s%s|time=%.3f\n"),
! status_line, (float)elapsed_time,
! timestamp, (display_html ? "</A>" : ""), elapsed_time);
die (STATE_OK, "%s", msg);
return STATE_UNKNOWN;
--- 809,815 ----
}
/* We only get here if all tests have been passed */
! asprintf (&msg, _("HTTP OK %s - %.3f second response time %s%s|time=%ldus size=%dB\n"),
! status_line, elapsed_time,
! timestamp, (display_html ? "</A>" : ""), microsec, pagesize);
die (STATE_OK, "%s", msg);
return STATE_UNKNOWN;
- Previous message: [Nagiosplug-checkins] CVS: nagiosplug/plugins utils.c,1.29,1.30 utils.h,1.13,1.14
- Next message: [Nagiosplug-checkins] CVS: nagiosplug/plugins check_dig.c,1.15,1.16 check_http.c,1.42,1.43 check_load.c,1.9,1.10 check_mrtg.c,1.7,1.8 check_mrtgtraf.c,1.7,1.8 check_nwstat.c,1.10,1.11 check_overcr.c,1.5,1.6 check_ping.c,1.20,1.21 check_procs.c,1.17,1.18 check_real.c,1.9,1.10 utils.c,1.30,1.31 utils.h,1.14,1.15
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the Commits
mailing list