X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=plugins%2Fcheck_http.c;h=4734d75c5c43b4fde66490986f89046399424786;hb=11b35b92e3195d230bef359f6a0679ae4414716b;hp=cf86d469a91ff7c09c7d0eb6f27ab47dd2caa44e;hpb=cbd684fa0ba4447dcdc3b6d5f9699aca7b5c9047;p=nagiosplug.git diff --git a/plugins/check_http.c b/plugins/check_http.c index cf86d46..4734d75 100644 --- a/plugins/check_http.c +++ b/plugins/check_http.c @@ -296,7 +296,6 @@ process_arguments (int argc, char **argv) { int c = 1; -#ifdef HAVE_GETOPT_H int option_index = 0; static struct option long_options[] = { STD_LONG_OPTS, @@ -317,7 +316,6 @@ process_arguments (int argc, char **argv) {"min", required_argument, 0, 'm'}, {0, 0, 0, 0} }; -#endif if (argc < 2) return ERROR; @@ -335,14 +333,8 @@ process_arguments (int argc, char **argv) strcpy (argv[c], "-n"); } -#define OPTCHARS "Vvht:c:w:H:P:I:a:e:p:s:R:r:u:f:C:nlLSm:" - 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; @@ -789,21 +781,21 @@ check_http (void) 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 ? "" : "")); 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 ? "" : ""), elapsed_time); terminate (onredirect, msg); @@ -815,7 +807,7 @@ check_http (void) /* 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 ? "" : ""), elapsed_time); if (check_critical_time == TRUE && elapsed_time > critical_time) @@ -828,13 +820,13 @@ check_http (void) 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 ? "" : ""), 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 ? "" : ""), elapsed_time); exit (STATE_CRITICAL); } @@ -843,20 +835,20 @@ check_http (void) 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 ? "" : ""), 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 ? "" : ""), 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); } } @@ -871,7 +863,7 @@ check_http (void) 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 ? "" : ""), elapsed_time); terminate (STATE_OK, msg); @@ -895,7 +887,7 @@ int connect_SSL (void) 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; } @@ -919,7 +911,7 @@ int connect_SSL (void) ERR_print_errors_fp (stderr); } else { - printf ("ERROR: Cannot initiate SSL handshake.\n"); + printf ("CRITICAL - Cannot initiate SSL handshake.\n"); } SSL_free (ssl); } @@ -947,7 +939,7 @@ check_certificate (X509 ** certificate) /* 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 { @@ -959,7 +951,7 @@ check_certificate (X509 ** certificate) } 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 { @@ -988,20 +980,20 @@ check_certificate (X509 ** certificate) 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; } @@ -1068,12 +1060,7 @@ void 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); }