Imported Upstream version 1.4.8

This commit is contained in:
Jan Wagner 2013-11-26 23:53:44 +01:00
parent 6a280f6f24
commit 6dd54dd8e2
352 changed files with 42813 additions and 27251 deletions

View file

@ -5,7 +5,7 @@
* License: GPL
* Copyright (c) 1999-2006 nagios-plugins team
*
* Last Modified: $Date: 2006/10/26 20:51:24 $
* Last Modified: $Date: 2007/03/06 22:45:57 $
*
* Description:
*
@ -33,13 +33,13 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
$Id: check_http.c,v 1.96 2006/10/26 20:51:24 tonvoon Exp $
$Id: check_http.c,v 1.101 2007/03/06 22:45:57 tonvoon Exp $
******************************************************************************/
/* splint -I. -I../../plugins -I../../lib/ -I/usr/kerberos/include/ ../../plugins/check_http.c */
const char *progname = "check_http";
const char *revision = "$Revision: 1.96 $";
const char *revision = "$Revision: 1.101 $";
const char *copyright = "1999-2006";
const char *email = "nagiosplug-devel@lists.sourceforge.net";
@ -88,7 +88,6 @@ struct timeval tv;
#define HTTP_URL "/"
#define CRLF "\r\n"
char timestamp[17] = "";
int specify_port = FALSE;
int server_port = HTTP_PORT;
char server_port_text[6] = "";
@ -147,13 +146,6 @@ main (int argc, char **argv)
if (process_arguments (argc, argv) == ERROR)
usage4 (_("Could not parse arguments"));
if (strstr (timestamp, ":")) {
if (strstr (server_url, "?"))
asprintf (&server_url, "%s&%s", server_url, timestamp);
else
asprintf (&server_url, "%s?%s", server_url, timestamp);
}
if (display_html == TRUE)
printf ("<A HREF=\"%s://%s:%d%s\" target=\"_blank\">",
use_ssl ? "https" : "http", host_name,
@ -183,15 +175,16 @@ process_arguments (int argc, char **argv)
int option = 0;
static struct option longopts[] = {
STD_LONG_OPTS,
{"file",required_argument,0,'F'},
{"link", no_argument, 0, 'L'},
{"nohtml", no_argument, 0, 'n'},
{"ssl", no_argument, 0, 'S'},
{"verbose", no_argument, 0, 'v'},
{"post", required_argument, 0, 'P'},
{"IP-address", required_argument, 0, 'I'},
{"url", required_argument, 0, 'u'},
{"port", required_argument, 0, 'p'},
{"authorization", required_argument, 0, 'a'},
{"string", required_argument, 0, 's'},
{"expect", required_argument, 0, 'e'},
{"regex", required_argument, 0, 'r'},
{"ereg", required_argument, 0, 'r'},
{"eregi", required_argument, 0, 'R'},
@ -233,7 +226,7 @@ process_arguments (int argc, char **argv)
switch (c) {
case '?': /* usage */
usage2 (_("Unknown argument"), optarg);
usage5 ();
break;
case 'h': /* help */
print_help ();
@ -861,7 +854,7 @@ check_http (void)
/* return a CRITICAL status if we couldn't read any data */
if (pagesize == (size_t) 0)
die (STATE_CRITICAL, _("No data received %s\n"), timestamp);
die (STATE_CRITICAL, _("No data received from host\n"));
/* close the connection */
#ifdef HAVE_SSL
@ -967,8 +960,8 @@ check_http (void)
microsec = deltime (tv);
elapsed_time = (double)microsec / 1.0e6;
die (onredirect,
_(" - %s - %.3f second response time %s%s|%s %s\n"),
status_line, elapsed_time, timestamp,
_(" - %s - %.3f second response time %s|%s %s\n"),
status_line, elapsed_time,
(display_html ? "</A>" : ""),
perfd_time (elapsed_time), perfd_size (pagesize));
} /* end if (http_status >= 300) */
@ -983,8 +976,8 @@ check_http (void)
microsec = deltime (tv);
elapsed_time = (double)microsec / 1.0e6;
asprintf (&msg,
_("HTTP WARNING: %s - %.3f second response time %s%s|%s %s\n"),
status_line, elapsed_time, timestamp,
_("HTTP WARNING: %s - %.3f second response time %s|%s %s\n"),
status_line, elapsed_time,
(display_html ? "</A>" : ""),
perfd_time (elapsed_time), perfd_size (pagesize));
if (check_critical_time == TRUE && elapsed_time > critical_time)
@ -997,9 +990,9 @@ check_http (void)
if (strlen (string_expect)) {
if (strstr (page, string_expect)) {
printf (_("HTTP OK %s - %.3f second response time %s%s|%s %s\n"),
printf (_("HTTP OK %s - %.3f second response time %s|%s %s\n"),
status_line, elapsed_time,
timestamp, (display_html ? "</A>" : ""),
(display_html ? "</A>" : ""),
perfd_time (elapsed_time), perfd_size (pagesize));
exit (STATE_OK);
}
@ -1014,9 +1007,9 @@ check_http (void)
if (strlen (regexp)) {
errcode = regexec (&preg, page, REGS, pmatch, 0);
if ((errcode == 0 && invert_regex == 0) || (errcode == REG_NOMATCH && invert_regex == 1)) {
printf (_("HTTP OK %s - %.3f second response time %s%s|%s %s\n"),
printf (_("HTTP OK %s - %.3f second response time %s|%s %s\n"),
status_line, elapsed_time,
timestamp, (display_html ? "</A>" : ""),
(display_html ? "</A>" : ""),
perfd_time (elapsed_time), perfd_size (pagesize));
exit (STATE_OK);
}
@ -1025,7 +1018,7 @@ check_http (void)
msg = strdup(_("pattern not found"));
else
msg = strdup(_("pattern found"));
printf (_("%s - %s%s|%s %s\n"),
printf (("%s - %s%s|%s %s\n"),
_("CRITICAL"),
msg,
(display_html ? "</A>" : ""),
@ -1052,9 +1045,9 @@ check_http (void)
exit (STATE_WARNING);
}
/* We only get here if all tests have been passed */
asprintf (&msg, _("HTTP OK %s - %d bytes in %.3f seconds %s%s|%s %s\n"),
asprintf (&msg, _("HTTP OK %s - %d bytes in %.3f seconds %s|%s %s\n"),
status_line, page_len, elapsed_time,
timestamp, (display_html ? "</A>" : ""),
(display_html ? "</A>" : ""),
perfd_time (elapsed_time), perfd_size (page_len));
die (STATE_OK, "%s", msg);
return STATE_UNKNOWN;
@ -1263,21 +1256,21 @@ print_help (void)
#ifdef HAVE_SSL
printf (" %s\n", "-S, --ssl");
printf (" %s\n", _("Connect via SSL"));
printf (" %s\n", _("Connect via SSL. Port defaults to 443"));
printf (" %s\n", "-C, --certificate=INTEGER");
printf (" %s\n", _("Minimum number of days a certificate has to be valid."));
printf (" %s\n", _("Minimum number of days a certificate has to be valid. Port defaults to 443"));
printf (" %s\n", _("(when this option is used the url is not checked.)\n"));
#endif
printf (" %s\n", "-e, --expect=STRING");
printf (" %s\n", _("String to expect in first (status) line of server response (default: "));
printf ("%s\n", HTTP_EXPECT);
printf ("%s)\n", HTTP_EXPECT);
printf (" %s\n", _("If specified skips all other status line logic (ex: 3xx, 4xx, 5xx processing)"));
printf (" %s\n", "-s, --string=STRING");
printf (" %s\n", _("String to expect in the content"));
printf (" %s\n", "-u, --url=PATH");
printf (" %s\n", _("URL to GET or POST (default: /)"));
printf (" %s\n," "-P, --post=STRING");
printf (" %s\n", "-P, --post=STRING");
printf (" %s\n", _("URL encoded http POST data"));
printf (" %s\n", "-N, --no-body");
printf (" %s\n", _("Don't wait for document body: stop reading after headers."));
@ -1303,7 +1296,7 @@ print_help (void)
printf (" %s\n", _("String to be sent in http header as \"User Agent\""));
printf (" %s\n", "-k, --header=STRING");
printf (" %s\n", _(" Any other tags to be sent in http header. Use multiple times for additional headers"));
printf (" %s\n", "-L, --link=URL");
printf (" %s\n", "-L, --link");
printf (" %s\n", _("Wrap output in HTML link (obsoleted by urlize)"));
printf (" %s\n", "-f, --onredirect=<ok|warning|critical|follow>");
printf (" %s\n", _("How to handle redirected pages"));
@ -1329,13 +1322,13 @@ print_help (void)
printf (" %s\n", _("serve content (optionally within a specified time) or whether the X509 "));
printf (" %s\n", _("certificate is still valid for the specified number of days."));
printf (_("Examples:"));
printf (" %s\n\n", "CHECK CONTENT: check_http -w 5 -c 10 --ssl www.verisign.com");
printf (" %s\n\n", "CHECK CONTENT: check_http -w 5 -c 10 --ssl -H www.verisign.com");
printf (" %s\n", _("When the 'www.verisign.com' server returns its content within 5 seconds,"));
printf (" %s\n", _("a STATE_OK will be returned. When the server returns its content but exceeds"));
printf (" %s\n", _("the 5-second threshold, a STATE_WARNING will be returned. When an error occurs,"));
printf (" %s\n\n", _("a STATE_CRITICAL will be returned."));
printf (" %s\n\n", "CHECK CERTIFICATE: check_http www.verisign.com -C 14");
printf (" %s\n\n", "CHECK CERTIFICATE: check_http -H www.verisign.com -C 14");
printf (" %s\n", _("When the certificate of 'www.verisign.com' is valid for more than 14 days,"));
printf (" %s\n", _("a STATE_OK is returned. When the certificate is still valid, but for less than"));
printf (" %s\n", _("14 days, a STATE_WARNING is returned. A STATE_CRITICAL will be returned when"));