diff --git a/plugins/check_http.c b/plugins/check_http.c
index 80b83679af0f9a01e0fb53123c0c97e105820692..6e76706277d702712a92bfa3e34656b9fcb29bf5 100644 (file)
--- a/plugins/check_http.c
+++ b/plugins/check_http.c
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ $Id$
+
******************************************************************************/
/* splint -I. -I../../plugins -I../../lib/ -I/usr/kerberos/include/ ../../plugins/check_http.c */
const char *progname = "check_http";
const char *revision = "$Revision$";
-const char *copyright = "1999-2001";
+const char *copyright = "1999-2004";
const char *email = "nagiosplug-devel@lists.sourceforge.net";
#include "common.h"
clean_revstring (revision), VERSION);
if (process_arguments (argc, argv) == ERROR)
- usage (_("check_http: could not parse arguments\n"));
+ usage4 (_("Could not parse arguments"));
if (strstr (timestamp, ":")) {
if (strstr (server_url, "?"))
}
if (display_html == TRUE)
- printf ("<A HREF=\"http://%s:%d%s\" target=\"_blank\">",
- host_name, server_port, server_url);
+ printf ("<A HREF=\"%s://%s:%d%s\" target=\"_blank\">",
+ use_ssl ? "https" : "http", host_name,
+ server_port, server_url);
/* initialize alarm signal handling, set socket timeout, start timer */
(void) signal (SIGALRM, socket_timeout_alarm_handler);
X509_free (server_cert);
}
else {
- printf (_("ERROR: Cannot retrieve server certificate.\n"));
+ printf (_("CRITICAL - Cannot retrieve server certificate.\n"));
result = STATE_CRITICAL;
}
SSL_shutdown (ssl);
#endif
return result;
}
-\f
+
/* process command-line arguments */
switch (c) {
case '?': /* usage */
- usage3 (_("unknown argument"), optopt);
+ usage2 (_("Unknown argument"), optarg);
break;
case 'h': /* help */
print_help ();
break;
case 't': /* timeout period */
if (!is_intnonneg (optarg))
- usage2 (_("timeout interval must be a non-negative integer"), optarg);
+ usage2 (_("Timeout interval must be a positive integer"), optarg);
else
socket_timeout = atoi (optarg);
break;
case 'c': /* critical time threshold */
if (!is_nonnegative (optarg))
- usage2 (_("invalid critical threshold"), optarg);
+ usage2 (_("Critical threshold must be integer"), optarg);
else {
critical_time = strtod (optarg, NULL);
check_critical_time = TRUE;
break;
case 'w': /* warning time threshold */
if (!is_nonnegative (optarg))
- usage2 (_("invalid warning threshold"), optarg);
+ usage2 (_("Warning threshold must be integer"), optarg);
else {
warning_time = strtod (optarg, NULL);
check_warning_time = TRUE;
break;
case 'S': /* use SSL */
#ifndef HAVE_SSL
- usage (_("check_http: invalid option - SSL is not available\n"));
+ usage4 (_("Invalid option - SSL is not available"));
#endif
use_ssl = TRUE;
if (specify_port == FALSE)
case 'C': /* Check SSL cert validity */
#ifdef HAVE_SSL
if (!is_intnonneg (optarg))
- usage2 (_("invalid certificate expiration period"), optarg);
+ usage2 (_("Invalid certificate expiration period"), optarg);
else {
days_till_exp = atoi (optarg);
check_cert = TRUE;
}
#else
- usage (_("check_http: invalid option - SSL is not available\n"));
+ usage4 (_("Invalid option - SSL is not available"));
#endif
break;
case 'f': /* onredirect */
/* Note: H, I, and u must be malloc'd or will fail on redirects */
case 'H': /* Host Name (virtual host) */
host_name = strdup (optarg);
+ if (strstr (optarg, ":"))
+ sscanf (optarg, "%*[^:]:%d", &server_port);
break;
case 'I': /* Server IP-address */
server_address = strdup (optarg);
break;
case 'p': /* Server port */
if (!is_intnonneg (optarg))
- usage2 (_("invalid port number"), optarg);
+ usage2 (_("Invalid port number"), optarg);
else {
server_port = atoi (optarg);
specify_port = TRUE;
case 'l': /* linespan */
case 'r': /* linespan */
case 'R': /* linespan */
- usage (_("check_http: call for regex which was not a compiled option\n"));
+ usage4 (_("Call for regex which was not a compiled option"));
break;
#else
case 'l': /* linespan */
#ifdef USE_IPV6
address_family = AF_INET6;
#else
- usage (_("IPv6 support not available\n"));
+ usage4 (_("IPv6 support not available"));
#endif
break;
case 'v': /* verbose */
if (server_address == NULL) {
if (host_name == NULL)
- usage (_("check_http: you must specify a server address or host name\n"));
+ usage4 (_("You must specify a server address or host name"));
else
server_address = strdup (host_name);
}
return TRUE;
}
-\f
+
/* written by lauri alanko */
buf[i] = '\0';
return buf;
}
-\f
-
static int
document_headers_done (char *full_page)
{
- const char *body, *s;
- const char *end;
+ const char *body;
for (body = full_page; *body; body++) {
if (!strncmp (body, "\n\n", 2) || !strncmp (body, "\n\r\n", 3))
}
+
static void
check_document_dates (const char *headers)
{
} else if (!document_date || !*document_date) {
die (STATE_CRITICAL, _("Document modification date unknown\n"));
} else {
- time_t sd = parse_time_string (server_date);
- time_t dd = parse_time_string (document_date);
+ time_t srv_data = parse_time_string (server_date);
+ time_t doc_data = parse_time_string (document_date);
- if (sd <= 0) {
+ if (srv_data <= 0) {
die (STATE_CRITICAL, _("CRITICAL - Server date \"%100s\" unparsable"), server_date);
- } else if (dd <= 0) {
+ } else if (doc_data <= 0) {
die (STATE_CRITICAL, _("CRITICAL - Document date \"%100s\" unparsable"), document_date);
- } else if (dd > sd + 30) {
- die (STATE_CRITICAL, _("CRITICAL - Document is %d seconds in the future\n"), dd - sd);
- } else if (dd < sd - maximum_age) {
- int n = (sd - dd);
+ } else if (doc_data > srv_data + 30) {
+ die (STATE_CRITICAL, _("CRITICAL - Document is %d seconds in the future\n"), (int)doc_data - (int)srv_data);
+ } else if (doc_data < srv_data - maximum_age) {
+ int n = (srv_data - doc_data);
if (n > (60 * 60 * 24 * 2))
die (STATE_CRITICAL,
_("CRITICAL - Last modified %.1f days ago\n"),
X509_free (server_cert);
}
else {
- printf (_("ERROR: Cannot retrieve server certificate.\n"));
+ printf (_("CRITICAL - Cannot retrieve server certificate.\n"));
return STATE_CRITICAL;
}
if ( sslerr == SSL_ERROR_SSL ) {
die (STATE_WARNING, _("Client Certificate Required\n"));
} else {
- die (STATE_CRITICAL, _("Error in recv()\n"));
+ die (STATE_CRITICAL, _("Error on receive\n"));
}
}
else {
#endif
- die (STATE_CRITICAL, _("Error in recv()\n"));
+ die (STATE_CRITICAL, _("Error on receive\n"));
#ifdef HAVE_SSL
}
#endif
page = full_page;
if (verbose)
- printf ("%s://%s:%d%s is %d characters\n", server_type, server_address, server_port, server_url, pagesize);
+ printf ("%s://%s:%d%s is %d characters\n",
+ use_ssl ? "https" : "http", server_address,
+ server_port, server_url, pagesize);
/* find status line and null-terminate it */
status_line = page;
microsec = deltime (tv);
elapsed_time = (double)microsec / 1.0e6;
asprintf (&msg,
- _("HTTP problem: %s - %.3f second response time %s%s|%s %s\n"),
+ _("HTTP WARNING: %s - %.3f second response time %s%s|%s %s\n"),
status_line, elapsed_time, timestamp,
(display_html ? "</A>" : ""),
perfd_time (elapsed_time), perfd_size (pagesize));
-
/* per RFC 2396 */
#define HDR_LOCATION "%*[Ll]%*[Oo]%*[Cc]%*[Aa]%*[Tt]%*[Ii]%*[Oo]%*[Nn]: "
#define URI_HTTP "%[HTPShtps]://"
addr = malloc (MAX_IPV4_HOSTLENGTH + 1);
if (addr == NULL)
- die (STATE_UNKNOWN, _("ERROR: could not allocate addr\n"));
+ die (STATE_UNKNOWN, _("Could not allocate addr\n"));
url = malloc (strcspn (pos, "\r\n"));
if (url == NULL)
- die (STATE_UNKNOWN, _("ERROR: could not allocate url\n"));
+ die (STATE_UNKNOWN, _("Could not allocate url\n"));
while (pos) {
url = realloc (url, strcspn (pos, "\r\n"));
if (url == NULL)
- die (STATE_UNKNOWN, _("ERROR: could not allocate url\n"));
+ die (STATE_UNKNOWN, _("could not allocate url\n"));
/* URI_HTTP, URI_HOST, URI_PORT, URI_PATH */
if (sscanf (pos, HD1, type, addr, port, url) == 4) {
}
#endif
+
+
#ifdef HAVE_SSL
int
check_certificate (X509 ** certificate)
return STATE_OK;
}
#endif
-\f
+
char *perfd_time (double elapsed_time)
}
+
char *perfd_size (int page_len)
{
return perfdata ("size", page_len, "B",
}
+
int
my_recv (void)
{
}
+
int
my_close (void)
{
-
-
-\f
void
print_help (void)
{
print_revision (progname, revision);
- printf (_("Copyright (c) 1999 Ethan Galstad <nagios@nagios.org>\n"));
- printf (_(COPYRIGHT), copyright, email);
+ printf ("Copyright (c) 1999 Ethan Galstad <nagios@nagios.org>\n");
+ printf (COPYRIGHT, copyright, email);
printf (_("\
This plugin tests the HTTP service on the specified host. It can test\n\
normal (http) and secure (https) servers, follow redirects, search for\n\
strings and regular expressions, check connection times, and report on\n\
-certificate expiration times.\n"));
+certificate expiration times.\n\n"));
print_usage ();
printf (_("\
-H, --hostname=ADDRESS\n\
Host name argument for servers using host headers (virtual host)\n\
+ Append a port to include it in the header (eg: example.com:5000)\n\
-I, --IP-address=ADDRESS\n\
IP address or name (use numeric address if possible to bypass DNS lookup).\n\
-p, --port=INTEGER\n\
-
void
print_usage (void)
{
- printf (_("\
-Usage: %s (-H <vhost> | -I <IP-address>) [-u <uri>] [-p <port>]\n\
- [-w <warn time>] [-c <critical time>] [-t <timeout>] [-L]\n\
- [-a auth] [-f <ok | warn | critcal | follow>] [-e <expect>]\n\
- [-s string] [-l] [-r <regex> | -R <case-insensitive regex>]\n\
- [-P string] [-m min_pg_size] [-4|-6] [-N] [-M <age>] [-A string]\n\
- [-k string]\n"), progname);
- printf (_(UT_HLP_VRS), progname, progname);
+ printf ("\
+Usage: %s -H <vhost> | -I <IP-address>) [-u <uri>] [-p <port>]\n\
+ [-w <warn time>] [-c <critical time>] [-t <timeout>] [-L]\n\
+ [-a auth] [-f <ok | warn | critcal | follow>] [-e <expect>]\n\
+ [-s string] [-l] [-r <regex> | -R <case-insensitive regex>]\n\
+ [-P string] [-m min_pg_size] [-4|-6] [-N] [-M <age>]\n\
+ [-A string] [-k string]\n", progname);
}