diff --git a/plugins/check_http.c b/plugins/check_http.c
index 7cdd5e01c170dc27b6c086b4b34bbebd28e4a041..4734d75c5c43b4fde66490986f89046399424786 100644 (file)
--- a/plugins/check_http.c
+++ b/plugins/check_http.c
certificate expiration times.\n"
#define OPTIONS "\
-\(-H <vhost> | -I <IP-address>) [-u <uri>] [-p <port>]\n\
+(-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]"
+ [-P string] [-m min_pg_size]"
#define LONGOPTIONS "\
-H, --hostname=ADDRESS\n\
Wrap output in HTML link (obsoleted by urlize)\n\
-f, --onredirect=<ok|warning|critical|follow>\n\
How to handle redirected pages\n%s%s\
+-m, --min=INTEGER\n\
+ Minimum page size required (bytes)\n\
-v, --verbose\n\
Show details for command-line debugging (do not use with nagios server)\n\
-h, --help\n\
#ifdef HAVE_SSL
int check_cert = FALSE;
int days_till_exp;
-unsigned char *randbuff;
+char *randbuff = "";
SSL_CTX *ctx;
SSL *ssl;
X509 *server_cert;
char server_type[6] = "http";
char *server_address = "";
char *host_name = "";
-char *server_url = HTTP_URL;
-int server_url_length = 1;
+char *server_url = "";
+int server_url_length;
int server_expect_yn = 0;
char server_expect[MAX_INPUT_BUFFER] = HTTP_EXPECT;
char string_expect[MAX_INPUT_BUFFER] = "";
int use_ssl = FALSE;
int verbose = FALSE;
int sd;
+int min_page_len = 0;
char *http_method = "GET";
char *http_post_data = "";
char buffer[MAX_INPUT_BUFFER];
{
int result = STATE_UNKNOWN;
+ /* Set default URL. Must be malloced for subsequent realloc if --onredirect=follow */
+ asprintf (&server_url, "%s", HTTP_URL);
+ server_url_length = strlen(server_url);
+
if (process_arguments (argc, argv) == ERROR)
usage ("check_http: could not parse arguments\n");
{
int c = 1;
-#ifdef HAVE_GETOPT_H
int option_index = 0;
static struct option long_options[] = {
STD_LONG_OPTS,
{"linespan", no_argument, 0, 'l'},
{"onredirect", required_argument, 0, 'f'},
{"certificate", required_argument, 0, 'C'},
+ {"min", required_argument, 0, 'm'},
{0, 0, 0, 0}
};
-#endif
if (argc < 2)
return ERROR;
strcpy (argv[c], "-n");
}
-#define OPTCHARS "Vvht:c:w:H:P:I:a:e:p:s:R:r:u:f:C:nlLS"
-
while (1) {
-#ifdef HAVE_GETOPT_H
- c = getopt_long (argc, argv, OPTCHARS, long_options, &option_index);
-#else
- c = getopt (argc, argv, OPTCHARS);
-#endif
+ c = getopt_long (argc, argv, "Vvht:c:w:H:P:I:a:e:p:s:R:r:u:f:C:nlLSm:", long_options, &option_index);
if (c == -1 || c == EOF)
break;
case 'v': /* verbose */
verbose = TRUE;
break;
+ case 'm': /* min_page_length */
+ min_page_len = atoi (optarg);
+ break;
}
}
char *x = NULL;
char *orig_url = NULL;
double elapsed_time;
+ int page_len = 0;
#ifdef HAVE_SSL
int sslerr;
#endif
pos += (size_t) strcspn (pos, "\r\n");
pos += (size_t) strspn (pos, "\r\n");
} /* end while (pos) */
- printf ("HTTP UNKNOWN: Could not find redirect location - %s%s",
+ printf ("UNKNOWN - Could not find redirect location - %s%s",
status_line, (display_html ? "</A>" : ""));
exit (STATE_UNKNOWN);
} /* end if (onredirect == STATE_DEPENDENT) */
else if (onredirect == STATE_UNKNOWN)
- printf ("HTTP UNKNOWN");
+ printf ("UNKNOWN");
else if (onredirect == STATE_OK)
- printf ("HTTP ok");
+ printf ("OK");
else if (onredirect == STATE_WARNING)
- printf ("HTTP WARNING");
+ printf ("WARNING");
else if (onredirect == STATE_CRITICAL)
- printf ("HTTP CRITICAL");
+ printf ("CRITICAL");
elapsed_time = delta_time (tv);
- asprintf (&msg, ": %s - %7.3f second response time %s%s|time=%7.3f\n",
+ asprintf (&msg, " - %s - %.3f second response time %s%s|time=%.3f\n",
status_line, elapsed_time, timestamp,
(display_html ? "</A>" : ""), elapsed_time);
terminate (onredirect, msg);
/* check elapsed time */
elapsed_time = delta_time (tv);
- asprintf (&msg, "HTTP problem: %s - %7.3f second response time %s%s|time=%7.3f\n",
+ 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)
if (strlen (string_expect)) {
if (strstr (page, string_expect)) {
- printf ("HTTP ok: %s - %7.3f second response time %s%s|time=%7.3f\n",
+ 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 ("HTTP CRITICAL: string not found%s|time=%7.3f\n",
+ printf ("CRITICAL - string not found%s|time=%.3f\n",
(display_html ? "</A>" : ""), elapsed_time);
exit (STATE_CRITICAL);
}
if (strlen (regexp)) {
errcode = regexec (&preg, page, REGS, pmatch, 0);
if (errcode == 0) {
- printf ("HTTP ok: %s - %7.3f second response time %s%s|time=%7.3f\n",
+ 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 ("HTTP CRITICAL: pattern not found%s|time=%7.3f\n",
+ printf ("CRITICAL - pattern not found%s|time=%.3f\n",
(display_html ? "</A>" : ""), elapsed_time);
exit (STATE_CRITICAL);
}
else {
regerror (errcode, &preg, errbuf, MAX_INPUT_BUFFER);
- printf ("Execute Error: %s\n", errbuf);
+ printf ("CRITICAL - Execute Error: %s\n", errbuf);
exit (STATE_CRITICAL);
}
}
}
#endif
+ /* make sure the page is of an appropriate size */
+ page_len = strlen (page);
+ if ((min_page_len > 0) && (page_len < min_page_len)) {
+ printf ("HTTP WARNING: page size too small%s|size=%i\n",
+ (display_html ? "</A>" : ""), page_len );
+ exit (STATE_WARNING);
+ }
/* We only get here if all tests have been passed */
- asprintf (&msg, "HTTP ok: %s - %7.3f second response time %s%s|time=%7.3f\n",
+ 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);
terminate (STATE_OK, msg);
{
SSL_METHOD *meth;
- asprintf (&randbuff, "%s", "qwertyuiopasdfghjkl");
+ asprintf (&randbuff, "%s", "qwertyuiopasdfghjklqwertyuiopasdfghjkl");
RAND_seed (randbuff, strlen (randbuff));
+ if (verbose)
+ printf("SSL seeding: %s\n", (RAND_status()==1 ? "OK" : "Failed") );
+
/* Initialize SSL context */
SSLeay_add_ssl_algorithms ();
meth = SSLv23_client_method ();
SSL_load_error_strings ();
if ((ctx = SSL_CTX_new (meth)) == NULL) {
- printf ("ERROR: Cannot create SSL context.\n");
+ printf ("CRITICAL - Cannot create SSL context.\n");
return STATE_CRITICAL;
}
ERR_print_errors_fp (stderr);
}
else {
- printf ("ERROR: Cannot initiate SSL handshake.\n");
+ printf ("CRITICAL - Cannot initiate SSL handshake.\n");
}
SSL_free (ssl);
}
/* Generate tm structure to process timestamp */
if (tm->type == V_ASN1_UTCTIME) {
if (tm->length < 10) {
- printf ("ERROR: Wrong time format in certificate.\n");
+ printf ("CRITICAL - Wrong time format in certificate.\n");
return STATE_CRITICAL;
}
else {
}
else {
if (tm->length < 12) {
- printf ("ERROR: Wrong time format in certificate.\n");
+ printf ("CRITICAL - Wrong time format in certificate.\n");
return STATE_CRITICAL;
}
else {
stamp.tm_mday, stamp.tm_year + 1900, stamp.tm_hour, stamp.tm_min);
if (days_left > 0 && days_left <= days_till_exp) {
- printf ("Certificate expires in %d day(s) (%s).\n", days_left, timestamp);
+ printf ("WARNING - Certificate expires in %d day(s) (%s).\n", days_left, timestamp);
return STATE_WARNING;
}
if (days_left < 0) {
- printf ("Certificate expired on %s.\n", timestamp);
+ printf ("CRITICAL - Certificate expired on %s.\n", timestamp);
return STATE_CRITICAL;
}
if (days_left == 0) {
- printf ("Certificate expires today (%s).\n", timestamp);
+ printf ("WARNING - Certificate expires today (%s).\n", timestamp);
return STATE_WARNING;
}
- printf ("Certificate will expire on %s.\n", timestamp);
+ printf ("OK - Certificate will expire on %s.\n", timestamp);
return STATE_OK;
}
print_usage (void)
{
printf ("Usage:\n" " %s %s\n"
-#ifdef HAVE_GETOPT_H
" %s (-h | --help) for detailed help\n"
" %s (-V | --version) for version information\n",
-#else
- " %s -h for detailed help\n"
- " %s -V for version information\n",
-#endif
progname, OPTIONS, progname, progname);
}