New upstream version 2.4.0
This commit is contained in:
parent
d5a5faa95b
commit
600e193ca4
102 changed files with 16219 additions and 31778 deletions
|
@ -1,7 +1,7 @@
|
|||
# Makefile.in generated by automake 1.16.3 from Makefile.am.
|
||||
# Makefile.in generated by automake 1.16.5 from Makefile.am.
|
||||
# @configure_input@
|
||||
|
||||
# Copyright (C) 1994-2020 Free Software Foundation, Inc.
|
||||
# Copyright (C) 1994-2021 Free Software Foundation, Inc.
|
||||
|
||||
# This Makefile.in is free software; the Free Software Foundation
|
||||
# gives unlimited permission to copy and/or distribute it,
|
||||
|
@ -182,8 +182,7 @@ am__aclocal_m4_deps = $(top_srcdir)/m4/libcurl.m4 \
|
|||
$(top_srcdir)/gl/m4/nocrash.m4 $(top_srcdir)/gl/m4/off_t.m4 \
|
||||
$(top_srcdir)/gl/m4/open-cloexec.m4 \
|
||||
$(top_srcdir)/gl/m4/open-slash.m4 $(top_srcdir)/gl/m4/open.m4 \
|
||||
$(top_srcdir)/gl/m4/pathmax.m4 $(top_srcdir)/gl/m4/pid_t.m4 \
|
||||
$(top_srcdir)/gl/m4/printf.m4 \
|
||||
$(top_srcdir)/gl/m4/pathmax.m4 $(top_srcdir)/gl/m4/printf.m4 \
|
||||
$(top_srcdir)/gl/m4/pthread_rwlock_rdlock.m4 \
|
||||
$(top_srcdir)/gl/m4/realloc.m4 \
|
||||
$(top_srcdir)/gl/m4/reallocarray.m4 \
|
||||
|
@ -196,7 +195,6 @@ am__aclocal_m4_deps = $(top_srcdir)/m4/libcurl.m4 \
|
|||
$(top_srcdir)/gl/m4/sockets.m4 $(top_srcdir)/gl/m4/socklen.m4 \
|
||||
$(top_srcdir)/gl/m4/sockpfaf.m4 $(top_srcdir)/gl/m4/ssize_t.m4 \
|
||||
$(top_srcdir)/gl/m4/stat-time.m4 $(top_srcdir)/gl/m4/stat.m4 \
|
||||
$(top_srcdir)/gl/m4/std-gnu11.m4 \
|
||||
$(top_srcdir)/gl/m4/stdalign.m4 \
|
||||
$(top_srcdir)/gl/m4/stddef_h.m4 $(top_srcdir)/gl/m4/stdint.m4 \
|
||||
$(top_srcdir)/gl/m4/stdint_h.m4 $(top_srcdir)/gl/m4/stdio_h.m4 \
|
||||
|
@ -214,7 +212,6 @@ am__aclocal_m4_deps = $(top_srcdir)/m4/libcurl.m4 \
|
|||
$(top_srcdir)/gl/m4/time_r.m4 $(top_srcdir)/gl/m4/timegm.m4 \
|
||||
$(top_srcdir)/gl/m4/ungetc.m4 $(top_srcdir)/gl/m4/unistd_h.m4 \
|
||||
$(top_srcdir)/gl/m4/unlocked-io.m4 \
|
||||
$(top_srcdir)/gl/m4/vararrays.m4 \
|
||||
$(top_srcdir)/gl/m4/vasnprintf.m4 \
|
||||
$(top_srcdir)/gl/m4/vasprintf.m4 \
|
||||
$(top_srcdir)/gl/m4/visibility.m4 \
|
||||
|
@ -520,8 +517,6 @@ am__define_uniq_tagged_files = \
|
|||
unique=`for i in $$list; do \
|
||||
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
|
||||
done | $(am__uniquify_input)`
|
||||
ETAGS = etags
|
||||
CTAGS = ctags
|
||||
am__tty_colors_dummy = \
|
||||
mgn= red= grn= lgn= blu= brg= std=; \
|
||||
am__color_tests=no
|
||||
|
@ -782,6 +777,8 @@ CFLAGS = @CFLAGS@
|
|||
CFLAG_VISIBILITY = @CFLAG_VISIBILITY@
|
||||
CPP = @CPP@
|
||||
CPPFLAGS = @CPPFLAGS@
|
||||
CSCOPE = @CSCOPE@
|
||||
CTAGS = @CTAGS@
|
||||
CYGPATH_W = @CYGPATH_W@
|
||||
DBILIBS = @DBILIBS@
|
||||
# gettext docs say to use AM_CPPFLAGS, but per module_CPPFLAGS override this
|
||||
|
@ -802,6 +799,7 @@ ENOLINK_VALUE = @ENOLINK_VALUE@
|
|||
EOVERFLOW_HIDDEN = @EOVERFLOW_HIDDEN@
|
||||
EOVERFLOW_VALUE = @EOVERFLOW_VALUE@
|
||||
ERRNO_H = @ERRNO_H@
|
||||
ETAGS = @ETAGS@
|
||||
EXEEXT = @EXEEXT@
|
||||
EXTRAS = @EXTRAS@
|
||||
EXTRAS_ROOT = @EXTRAS_ROOT@
|
||||
|
@ -2174,6 +2172,8 @@ install_sh = @install_sh@
|
|||
libdir = @libdir@
|
||||
libexecdir = @libexecdir@
|
||||
localedir = $(datadir)/locale
|
||||
localedir_c = @localedir_c@
|
||||
localedir_c_make = @localedir_c_make@
|
||||
localstatedir = @localstatedir@
|
||||
mandir = @mandir@
|
||||
mkdir_p = @mkdir_p@
|
||||
|
@ -2908,7 +2908,6 @@ recheck: all
|
|||
@am__EXEEXT_TRUE@ --log-file $$b.log --trs-file $$b.trs \
|
||||
@am__EXEEXT_TRUE@ $(am__common_driver_flags) $(AM_TEST_LOG_DRIVER_FLAGS) $(TEST_LOG_DRIVER_FLAGS) -- $(TEST_LOG_COMPILE) \
|
||||
@am__EXEEXT_TRUE@ "$$tst" $(AM_TESTS_FD_REDIRECT)
|
||||
|
||||
distdir: $(BUILT_SOURCES)
|
||||
$(MAKE) $(AM_MAKEFLAGS) distdir-am
|
||||
|
||||
|
|
|
@ -94,7 +94,7 @@ static int stderr_warning = 0; /* if a cmd issued output on stderr */
|
|||
static int exec_warning = 0; /* if a cmd exited non-zero */
|
||||
|
||||
int main (int argc, char **argv) {
|
||||
int result=STATE_UNKNOWN, packages_available=0, sec_count=0, i=0;
|
||||
int result=STATE_UNKNOWN, packages_available=0, sec_count=0;
|
||||
char **packages_list=NULL, **secpackages_list=NULL;
|
||||
|
||||
/* Parse extra opts if any */
|
||||
|
@ -142,10 +142,11 @@ int main (int argc, char **argv) {
|
|||
qsort(secpackages_list, sec_count, sizeof(char*), cmpstringp);
|
||||
qsort(packages_list, packages_available-sec_count, sizeof(char*), cmpstringp);
|
||||
|
||||
for(i = 0; i < sec_count; i++)
|
||||
for(int i = 0; i < sec_count; i++)
|
||||
printf("%s (security)\n", secpackages_list[i]);
|
||||
|
||||
if (only_critical == false) {
|
||||
for(i = 0; i < packages_available - sec_count; i++)
|
||||
for(int i = 0; i < packages_available - sec_count; i++)
|
||||
printf("%s\n", packages_list[i]);
|
||||
}
|
||||
}
|
||||
|
@ -251,7 +252,7 @@ int process_arguments (int argc, char **argv) {
|
|||
|
||||
/* run an apt-get upgrade */
|
||||
int run_upgrade(int *pkgcount, int *secpkgcount, char ***pkglist, char ***secpkglist){
|
||||
int i=0, result=STATE_UNKNOWN, regres=0, pc=0, spc=0;
|
||||
int result=STATE_UNKNOWN, regres=0, pc=0, spc=0;
|
||||
struct output chld_out, chld_err;
|
||||
regex_t ireg, ereg, sreg;
|
||||
char *cmdline=NULL, rerrbuf[64];
|
||||
|
@ -320,7 +321,7 @@ int run_upgrade(int *pkgcount, int *secpkgcount, char ***pkglist, char ***secpkg
|
|||
* we may need to switch to the --print-uris output format,
|
||||
* in which case the logic here will slightly change.
|
||||
*/
|
||||
for(i = 0; i < chld_out.lines; i++) {
|
||||
for(size_t i = 0; i < chld_out.lines; i++) {
|
||||
if(verbose){
|
||||
printf("%s\n", chld_out.line[i]);
|
||||
}
|
||||
|
@ -353,7 +354,7 @@ int run_upgrade(int *pkgcount, int *secpkgcount, char ***pkglist, char ***secpkg
|
|||
stderr_warning=1;
|
||||
result = max_state(result, STATE_WARNING);
|
||||
if(verbose){
|
||||
for(i = 0; i < chld_err.lines; i++) {
|
||||
for(size_t i = 0; i < chld_err.lines; i++) {
|
||||
fprintf(stderr, "%s\n", chld_err.line[i]);
|
||||
}
|
||||
}
|
||||
|
@ -367,7 +368,7 @@ int run_upgrade(int *pkgcount, int *secpkgcount, char ***pkglist, char ***secpkg
|
|||
|
||||
/* run an apt-get update (needs root) */
|
||||
int run_update(void){
|
||||
int i=0, result=STATE_UNKNOWN;
|
||||
int result=STATE_UNKNOWN;
|
||||
struct output chld_out, chld_err;
|
||||
char *cmdline;
|
||||
|
||||
|
@ -385,7 +386,7 @@ int run_update(void){
|
|||
}
|
||||
|
||||
if(verbose){
|
||||
for(i = 0; i < chld_out.lines; i++) {
|
||||
for(size_t i = 0; i < chld_out.lines; i++) {
|
||||
printf("%s\n", chld_out.line[i]);
|
||||
}
|
||||
}
|
||||
|
@ -395,7 +396,7 @@ int run_update(void){
|
|||
stderr_warning=1;
|
||||
result = max_state(result, STATE_WARNING);
|
||||
if(verbose){
|
||||
for(i = 0; i < chld_err.lines; i++) {
|
||||
for(size_t i = 0; i < chld_err.lines; i++) {
|
||||
fprintf(stderr, "%s\n", chld_err.line[i]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@ unsigned int services = 0;
|
|||
int skip_stdout = 0;
|
||||
int skip_stderr = 0;
|
||||
int warn_on_stderr = 0;
|
||||
bool unknown_timeout = FALSE;
|
||||
bool unknown_timeout = false;
|
||||
char *remotecmd = NULL;
|
||||
char **commargv = NULL;
|
||||
int commargc = 0;
|
||||
|
@ -58,8 +58,8 @@ char *hostname = NULL;
|
|||
char *outputfile = NULL;
|
||||
char *host_shortname = NULL;
|
||||
char **service;
|
||||
int passive = FALSE;
|
||||
int verbose = FALSE;
|
||||
bool passive = false;
|
||||
bool verbose = false;
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
|
@ -68,7 +68,6 @@ main (int argc, char **argv)
|
|||
char *status_text;
|
||||
int cresult;
|
||||
int result = STATE_UNKNOWN;
|
||||
int i;
|
||||
time_t local_time;
|
||||
FILE *fp = NULL;
|
||||
output chld_out, chld_err;
|
||||
|
@ -96,7 +95,7 @@ main (int argc, char **argv)
|
|||
/* run the command */
|
||||
if (verbose) {
|
||||
printf ("Command: %s\n", commargv[0]);
|
||||
for (i=1; i<commargc; i++)
|
||||
for (int i = 1; i < commargc; i++)
|
||||
printf ("Argument %i: %s\n", i, commargv[i]);
|
||||
}
|
||||
|
||||
|
@ -110,9 +109,9 @@ main (int argc, char **argv)
|
|||
}
|
||||
|
||||
if (verbose) {
|
||||
for(i = 0; i < chld_out.lines; i++)
|
||||
for(size_t i = 0; i < chld_out.lines; i++)
|
||||
printf("stdout: %s\n", chld_out.line[i]);
|
||||
for(i = 0; i < chld_err.lines; i++)
|
||||
for(size_t i = 0; i < chld_err.lines; i++)
|
||||
printf("stderr: %s\n", chld_err.line[i]);
|
||||
}
|
||||
|
||||
|
@ -122,7 +121,7 @@ main (int argc, char **argv)
|
|||
skip_stderr = chld_err.lines;
|
||||
|
||||
/* UNKNOWN or worse if (non-skipped) output found on stderr */
|
||||
if(chld_err.lines > skip_stderr) {
|
||||
if(chld_err.lines > (size_t)skip_stderr) {
|
||||
printf (_("Remote command execution failed: %s\n"),
|
||||
chld_err.line[skip_stderr]);
|
||||
if ( warn_on_stderr )
|
||||
|
@ -134,8 +133,8 @@ main (int argc, char **argv)
|
|||
/* this is simple if we're not supposed to be passive.
|
||||
* Wrap up quickly and keep the tricks below */
|
||||
if(!passive) {
|
||||
if (chld_out.lines > skip_stdout)
|
||||
for (i = skip_stdout; i < chld_out.lines; i++)
|
||||
if (chld_out.lines > (size_t)skip_stdout)
|
||||
for (size_t i = skip_stdout; i < chld_out.lines; i++)
|
||||
puts (chld_out.line[i]);
|
||||
else
|
||||
printf (_("%s - check_by_ssh: Remote command '%s' returned status %d\n"),
|
||||
|
@ -156,7 +155,7 @@ main (int argc, char **argv)
|
|||
|
||||
local_time = time (NULL);
|
||||
commands = 0;
|
||||
for(i = skip_stdout; i < chld_out.lines; i++) {
|
||||
for(size_t i = skip_stdout; i < chld_out.lines; i++) {
|
||||
status_text = chld_out.line[i++];
|
||||
if (i == chld_out.lines || strstr (chld_out.line[i], "STATUS CODE: ") == NULL)
|
||||
die (STATE_UNKNOWN, _("%s: Error parsing output\n"), progname);
|
||||
|
@ -235,7 +234,7 @@ process_arguments (int argc, char **argv)
|
|||
print_help ();
|
||||
exit (STATE_UNKNOWN);
|
||||
case 'v': /* help */
|
||||
verbose = TRUE;
|
||||
verbose = true;
|
||||
break;
|
||||
case 't': /* timeout period */
|
||||
if (!is_integer (optarg))
|
||||
|
@ -244,7 +243,7 @@ process_arguments (int argc, char **argv)
|
|||
timeout_interval = atoi (optarg);
|
||||
break;
|
||||
case 'U':
|
||||
unknown_timeout = TRUE;
|
||||
unknown_timeout = true;
|
||||
break;
|
||||
case 'H': /* host */
|
||||
hostname = optarg;
|
||||
|
@ -257,7 +256,7 @@ process_arguments (int argc, char **argv)
|
|||
break;
|
||||
case 'O': /* output file */
|
||||
outputfile = optarg;
|
||||
passive = TRUE;
|
||||
passive = true;
|
||||
break;
|
||||
case 's': /* description of service to check */
|
||||
p1 = optarg;
|
||||
|
|
|
@ -134,6 +134,7 @@ char regexp[MAX_RE_SIZE];
|
|||
int cflags = REG_NOSUB | REG_EXTENDED | REG_NEWLINE;
|
||||
int errcode;
|
||||
bool invert_regex = false;
|
||||
int state_regex = STATE_CRITICAL;
|
||||
|
||||
char *server_address = NULL;
|
||||
char *host_name = NULL;
|
||||
|
@ -223,6 +224,7 @@ curlhelp_ssl_library ssl_library = CURLHELP_SSL_LIBRARY_UNKNOWN;
|
|||
int curl_http_version = CURL_HTTP_VERSION_NONE;
|
||||
bool automatic_decompression = false;
|
||||
char *cookie_jar_file = NULL;
|
||||
bool haproxy_protocol = false;
|
||||
|
||||
bool process_arguments (int, char**);
|
||||
void handle_curl_option_return_code (CURLcode res, const char* option);
|
||||
|
@ -395,7 +397,7 @@ lookup_host (const char *host, char *buf, size_t buflen)
|
|||
char addrstr[100];
|
||||
size_t addrstr_len;
|
||||
int errcode;
|
||||
void *ptr;
|
||||
void *ptr = { 0 };
|
||||
size_t buflen_remaining = buflen - 1;
|
||||
|
||||
memset (&hints, 0, sizeof (hints));
|
||||
|
@ -520,6 +522,11 @@ check_http (void)
|
|||
handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_CONNECTTIMEOUT, socket_timeout), "CURLOPT_CONNECTTIMEOUT");
|
||||
handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_TIMEOUT, socket_timeout), "CURLOPT_TIMEOUT");
|
||||
|
||||
/* enable haproxy protocol */
|
||||
if (haproxy_protocol) {
|
||||
handle_curl_option_return_code(curl_easy_setopt(curl, CURLOPT_HAPROXYPROTOCOL, 1L), "CURLOPT_HAPROXYPROTOCOL");
|
||||
}
|
||||
|
||||
// fill dns resolve cache to make curl connect to the given server_address instead of the host_name, only required for ssl, because we use the host_name later on to make SNI happy
|
||||
if(use_ssl && host_name != NULL) {
|
||||
if ( (res=lookup_host (server_address, addrstr, DEFAULT_BUFFER_SIZE/2)) != 0) {
|
||||
|
@ -1127,7 +1134,7 @@ GOT_FIRST_CERT:
|
|||
strcpy(msg, tmp);
|
||||
|
||||
}
|
||||
result = STATE_CRITICAL;
|
||||
result = state_regex;
|
||||
} else {
|
||||
regerror (errcode, &preg, errbuf, MAX_INPUT_BUFFER);
|
||||
|
||||
|
@ -1186,16 +1193,16 @@ int
|
|||
uri_strcmp (const UriTextRangeA range, const char* s)
|
||||
{
|
||||
if (!range.first) return -1;
|
||||
if (range.afterLast - range.first < strlen (s)) return -1;
|
||||
return strncmp (s, range.first, min( range.afterLast - range.first, strlen (s)));
|
||||
if ( (size_t)(range.afterLast - range.first) < strlen (s) ) return -1;
|
||||
return strncmp (s, range.first, min( (size_t)(range.afterLast - range.first), strlen (s)));
|
||||
}
|
||||
|
||||
char*
|
||||
uri_string (const UriTextRangeA range, char* buf, size_t buflen)
|
||||
{
|
||||
if (!range.first) return "(null)";
|
||||
strncpy (buf, range.first, max (buflen-1, range.afterLast - range.first));
|
||||
buf[max (buflen-1, range.afterLast - range.first)] = '\0';
|
||||
strncpy (buf, range.first, max (buflen-1, (size_t)(range.afterLast - range.first)));
|
||||
buf[max (buflen-1, (size_t)(range.afterLast - range.first))] = '\0';
|
||||
buf[range.afterLast - range.first] = '\0';
|
||||
return buf;
|
||||
}
|
||||
|
@ -1384,7 +1391,9 @@ process_arguments (int argc, char **argv)
|
|||
CA_CERT_OPTION,
|
||||
HTTP_VERSION_OPTION,
|
||||
AUTOMATIC_DECOMPRESSION,
|
||||
COOKIE_JAR
|
||||
COOKIE_JAR,
|
||||
HAPROXY_PROTOCOL,
|
||||
STATE_REGEX
|
||||
};
|
||||
|
||||
int option = 0;
|
||||
|
@ -1423,6 +1432,7 @@ process_arguments (int argc, char **argv)
|
|||
{"content-type", required_argument, 0, 'T'},
|
||||
{"pagesize", required_argument, 0, 'm'},
|
||||
{"invert-regex", no_argument, NULL, INVERT_REGEX},
|
||||
{"state-regex", required_argument, 0, STATE_REGEX},
|
||||
{"use-ipv4", no_argument, 0, '4'},
|
||||
{"use-ipv6", no_argument, 0, '6'},
|
||||
{"extended-perfdata", no_argument, 0, 'E'},
|
||||
|
@ -1431,6 +1441,7 @@ process_arguments (int argc, char **argv)
|
|||
{"http-version", required_argument, 0, HTTP_VERSION_OPTION},
|
||||
{"enable-automatic-decompression", no_argument, 0, AUTOMATIC_DECOMPRESSION},
|
||||
{"cookie-jar", required_argument, 0, COOKIE_JAR},
|
||||
{"haproxy-protocol", no_argument, 0, HAPROXY_PROTOCOL},
|
||||
{0, 0, 0, 0}
|
||||
};
|
||||
|
||||
|
@ -1757,6 +1768,13 @@ process_arguments (int argc, char **argv)
|
|||
case INVERT_REGEX:
|
||||
invert_regex = true;
|
||||
break;
|
||||
case STATE_REGEX:
|
||||
if (!strcmp (optarg, "critical"))
|
||||
state_regex = STATE_CRITICAL;
|
||||
else if (!strcmp (optarg, "warning"))
|
||||
state_regex = STATE_WARNING;
|
||||
else usage2 (_("Invalid state-regex option"), optarg);
|
||||
break;
|
||||
case '4':
|
||||
address_family = AF_INET;
|
||||
break;
|
||||
|
@ -1841,6 +1859,9 @@ process_arguments (int argc, char **argv)
|
|||
case COOKIE_JAR:
|
||||
cookie_jar_file = optarg;
|
||||
break;
|
||||
case HAPROXY_PROTOCOL:
|
||||
haproxy_protocol = true;
|
||||
break;
|
||||
case '?':
|
||||
/* print short usage statement if args not parsable */
|
||||
usage5 ();
|
||||
|
@ -2011,7 +2032,7 @@ print_help (void)
|
|||
printf (" %s\n", "-u, --url=PATH");
|
||||
printf (" %s\n", _("URL to GET or POST (default: /)"));
|
||||
printf (" %s\n", "-P, --post=STRING");
|
||||
printf (" %s\n", _("URL encoded http POST data"));
|
||||
printf (" %s\n", _("URL decoded http POST data"));
|
||||
printf (" %s\n", "-j, --method=STRING (for example: HEAD, OPTIONS, TRACE, PUT, DELETE, CONNECT)");
|
||||
printf (" %s\n", _("Set HTTP method."));
|
||||
printf (" %s\n", "-N, --no-body");
|
||||
|
@ -2029,7 +2050,10 @@ print_help (void)
|
|||
printf (" %s\n", "-R, --eregi=STRING");
|
||||
printf (" %s\n", _("Search page for case-insensitive regex STRING"));
|
||||
printf (" %s\n", "--invert-regex");
|
||||
printf (" %s\n", _("Return CRITICAL if found, OK if not\n"));
|
||||
printf (" %s\n", _("Return STATE if found, OK if not (STATE is CRITICAL, per default)"));
|
||||
printf (" %s\n", _("can be changed with --state--regex)"));
|
||||
printf (" %s\n", "--regex-state=STATE");
|
||||
printf (" %s\n", _("Return STATE if regex is found, OK if not\n"));
|
||||
printf (" %s\n", "-a, --authorization=AUTH_PAIR");
|
||||
printf (" %s\n", _("Username:password on sites with basic authentication"));
|
||||
printf (" %s\n", "-b, --proxy-authorization=AUTH_PAIR");
|
||||
|
@ -2060,6 +2084,8 @@ print_help (void)
|
|||
printf (" %s\n", _("1.0 = HTTP/1.0, 1.1 = HTTP/1.1, 2.0 = HTTP/2 (HTTP/2 will fail without -S)"));
|
||||
printf (" %s\n", "--enable-automatic-decompression");
|
||||
printf (" %s\n", _("Enable automatic decompression of body (CURLOPT_ACCEPT_ENCODING)."));
|
||||
printf(" %s\n", "--haproxy-protocol");
|
||||
printf(" %s\n", _("Send HAProxy proxy protocol v1 header (CURLOPT_HAPROXYPROTOCOL)."));
|
||||
printf (" %s\n", "---cookie-jar=FILE");
|
||||
printf (" %s\n", _("Store cookies in the cookie jar and send them out when requested."));
|
||||
printf ("\n");
|
||||
|
@ -2144,7 +2170,7 @@ print_usage (void)
|
|||
printf (" [-b proxy_auth] [-f <ok|warning|critical|follow|sticky|stickyport|curl>]\n");
|
||||
printf (" [-e <expect>] [-d string] [-s string] [-l] [-r <regex> | -R <case-insensitive regex>]\n");
|
||||
printf (" [-P string] [-m <min_pg_size>:<max_pg_size>] [-4|-6] [-N] [-M <age>]\n");
|
||||
printf (" [-A string] [-k string] [-S <version>] [--sni]\n");
|
||||
printf (" [-A string] [-k string] [-S <version>] [--sni] [--haproxy-protocol]\n");
|
||||
printf (" [-T <content-type>] [-j method]\n");
|
||||
printf (" [--http-version=<version>] [--enable-automatic-decompression]\n");
|
||||
printf (" [--cookie-jar=<cookie jar file>\n");
|
||||
|
@ -2368,8 +2394,7 @@ remove_newlines (char *s)
|
|||
char *
|
||||
get_header_value (const struct phr_header* headers, const size_t nof_headers, const char* header)
|
||||
{
|
||||
int i;
|
||||
for( i = 0; i < nof_headers; i++ ) {
|
||||
for(size_t i = 0; i < nof_headers; i++ ) {
|
||||
if(headers[i].name != NULL && strncasecmp( header, headers[i].name, max( headers[i].name_len, 4 ) ) == 0 ) {
|
||||
return strndup( headers[i].value, headers[i].value_len );
|
||||
}
|
||||
|
@ -2471,7 +2496,7 @@ check_document_dates (const curlhelp_write_curlbuf *header_buf, char (*msg)[DEFA
|
|||
int
|
||||
get_content_length (const curlhelp_write_curlbuf* header_buf, const curlhelp_write_curlbuf* body_buf)
|
||||
{
|
||||
int content_length = 0;
|
||||
size_t content_length = 0;
|
||||
struct phr_header headers[255];
|
||||
size_t nof_headers = 255;
|
||||
size_t msglen;
|
||||
|
|
|
@ -141,7 +141,7 @@ main (int argc, char **argv)
|
|||
if (verbose > 2)
|
||||
printf ("Initializing DBI\n");
|
||||
|
||||
dbi_inst *instance_p;
|
||||
dbi_inst *instance_p = { 0 };
|
||||
|
||||
if (dbi_initialize_r(NULL, instance_p) < 0) {
|
||||
printf ("UNKNOWN - failed to initialize DBI; possibly you don't have any drivers installed.\n");
|
||||
|
|
|
@ -56,7 +56,7 @@ char *expected_address = NULL;
|
|||
char *dns_server = NULL;
|
||||
char *dig_args = "";
|
||||
char *query_transport = "";
|
||||
int verbose = FALSE;
|
||||
bool verbose = false;
|
||||
int server_port = DEFAULT_PORT;
|
||||
int number_tries = DEFAULT_TRIES;
|
||||
double warning_interval = UNDEFINED;
|
||||
|
@ -176,11 +176,11 @@ main (int argc, char **argv)
|
|||
state_text (result), elapsed_time,
|
||||
msg ? msg : _("Probably a non-existent host/domain"),
|
||||
fperfdata("time", elapsed_time, "s",
|
||||
(warning_interval>UNDEFINED?TRUE:FALSE),
|
||||
(warning_interval>UNDEFINED ? true:false),
|
||||
warning_interval,
|
||||
(critical_interval>UNDEFINED?TRUE:FALSE),
|
||||
(critical_interval>UNDEFINED ? true:false),
|
||||
critical_interval,
|
||||
TRUE, 0, FALSE, 0));
|
||||
true, 0, false, 0));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -270,7 +270,7 @@ process_arguments (int argc, char **argv)
|
|||
dig_args = strdup(optarg);
|
||||
break;
|
||||
case 'v': /* verbose */
|
||||
verbose = TRUE;
|
||||
verbose = true;
|
||||
break;
|
||||
case 'T':
|
||||
record_type = optarg;
|
||||
|
|
|
@ -46,7 +46,7 @@ const char *email = "devel@monitoring-plugins.org";
|
|||
#include <stdarg.h>
|
||||
#include "fsusage.h"
|
||||
#include "mountlist.h"
|
||||
#include "intprops.h" /* necessary for TYPE_MAXIMUM */
|
||||
#include <float.h>
|
||||
#if HAVE_LIMITS_H
|
||||
# include <limits.h>
|
||||
#endif
|
||||
|
@ -112,8 +112,7 @@ enum
|
|||
{
|
||||
SYNC_OPTION = CHAR_MAX + 1,
|
||||
NO_SYNC_OPTION,
|
||||
BLOCK_SIZE_OPTION,
|
||||
IGNORE_MISSING
|
||||
BLOCK_SIZE_OPTION
|
||||
};
|
||||
|
||||
#ifdef _AIX
|
||||
|
@ -135,12 +134,12 @@ char *exclude_device;
|
|||
char *units;
|
||||
uintmax_t mult = 1024 * 1024;
|
||||
int verbose = 0;
|
||||
int erronly = FALSE;
|
||||
int display_mntp = FALSE;
|
||||
int exact_match = FALSE;
|
||||
bool erronly = false;
|
||||
bool display_mntp = false;
|
||||
bool exact_match = false;
|
||||
bool ignore_missing = false;
|
||||
int freespace_ignore_reserved = FALSE;
|
||||
int display_inodes_perfdata = FALSE;
|
||||
bool freespace_ignore_reserved = false;
|
||||
bool display_inodes_perfdata = false;
|
||||
char *warn_freespace_units = NULL;
|
||||
char *crit_freespace_units = NULL;
|
||||
char *warn_freespace_percent = NULL;
|
||||
|
@ -153,7 +152,7 @@ char *warn_usedinodes_percent = NULL;
|
|||
char *crit_usedinodes_percent = NULL;
|
||||
char *warn_freeinodes_percent = NULL;
|
||||
char *crit_freeinodes_percent = NULL;
|
||||
int path_selected = FALSE;
|
||||
bool path_selected = false;
|
||||
bool path_ignored = false;
|
||||
char *group = NULL;
|
||||
struct stat *stat_buf;
|
||||
|
@ -205,7 +204,7 @@ main (int argc, char **argv)
|
|||
/* If a list of paths has not been selected, find entire
|
||||
mount list and create list of paths
|
||||
*/
|
||||
if (path_selected == FALSE && path_ignored == false) {
|
||||
if (path_selected == false && path_ignored == false) {
|
||||
for (me = mount_list; me; me = me->me_next) {
|
||||
if (! (path = np_find_parameter(path_select_list, me->me_mountdir))) {
|
||||
path = np_add_parameter(&path_select_list, me->me_mountdir);
|
||||
|
@ -326,7 +325,7 @@ main (int argc, char **argv)
|
|||
get_stats (path, &fsp);
|
||||
|
||||
if (verbose >= 3) {
|
||||
printf ("For %s, used_pct=%g free_pct=%g used_units=%lu free_units=%lu total_units=%lu used_inodes_pct=%g free_inodes_pct=%g fsp.fsu_blocksize=%lu mult=%lu\n",
|
||||
printf ("For %s, used_pct=%f free_pct=%f used_units=%lu free_units=%lu total_units=%lu used_inodes_pct=%f free_inodes_pct=%f fsp.fsu_blocksize=%lu mult=%lu\n",
|
||||
me->me_mountdir,
|
||||
path->dused_pct,
|
||||
path->dfree_pct,
|
||||
|
@ -396,10 +395,10 @@ main (int argc, char **argv)
|
|||
perfdata_uint64 (
|
||||
(!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir,
|
||||
path->dused_units * mult, "B",
|
||||
(warning_high_tide == UINT64_MAX ? FALSE : TRUE), warning_high_tide,
|
||||
(critical_high_tide == UINT64_MAX ? FALSE : TRUE), critical_high_tide,
|
||||
TRUE, 0,
|
||||
TRUE, path->dtotal_units * mult));
|
||||
(warning_high_tide == UINT64_MAX ? false : true), warning_high_tide,
|
||||
(critical_high_tide == UINT64_MAX ? false : true), critical_high_tide,
|
||||
true, 0,
|
||||
true, path->dtotal_units * mult));
|
||||
|
||||
if (display_inodes_perfdata) {
|
||||
/* *_high_tide must be reinitialized at each run */
|
||||
|
@ -418,10 +417,10 @@ main (int argc, char **argv)
|
|||
xasprintf (&perf, "%s %s", perf,
|
||||
perfdata_uint64 (perf_ilabel,
|
||||
path->inodes_used, "",
|
||||
(warning_high_tide != UINT64_MAX ? TRUE : FALSE), warning_high_tide,
|
||||
(critical_high_tide != UINT64_MAX ? TRUE : FALSE), critical_high_tide,
|
||||
TRUE, 0,
|
||||
TRUE, path->inodes_total));
|
||||
(warning_high_tide != UINT64_MAX ? true : false), warning_high_tide,
|
||||
(critical_high_tide != UINT64_MAX ? true : false), critical_high_tide,
|
||||
true, 0,
|
||||
true, path->inodes_total));
|
||||
}
|
||||
|
||||
if (disk_result==STATE_OK && erronly && !verbose)
|
||||
|
@ -432,7 +431,7 @@ main (int argc, char **argv)
|
|||
} else {
|
||||
xasprintf(&flag_header, "");
|
||||
}
|
||||
xasprintf (&output, "%s%s %s %llu%s (%.0f%%",
|
||||
xasprintf (&output, "%s%s %s %llu%s (%.1f%%",
|
||||
output, flag_header,
|
||||
(!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir,
|
||||
path->dfree_units,
|
||||
|
@ -452,7 +451,7 @@ main (int argc, char **argv)
|
|||
|
||||
if (strcmp(output, "") == 0 && ! erronly) {
|
||||
preamble = "";
|
||||
xasprintf (&output, " - No disks were found for provided parameters;");
|
||||
xasprintf (&output, " - No disks were found for provided parameters");
|
||||
}
|
||||
|
||||
printf ("DISK %s%s%s%s%s|%s\n", state_text (result), ((erronly && result==STATE_OK)) ? "" : preamble, output, (strcmp(ignored, "") == 0) ? "" : ignored_preamble, ignored, perf);
|
||||
|
@ -462,24 +461,8 @@ main (int argc, char **argv)
|
|||
|
||||
double calculate_percent(uintmax_t value, uintmax_t total) {
|
||||
double pct = -1;
|
||||
/* I don't understand the below, but it is taken from coreutils' df */
|
||||
/* Seems to be calculating pct, in the best possible way */
|
||||
if (value <= TYPE_MAXIMUM(uintmax_t) / 100
|
||||
&& total != 0) {
|
||||
uintmax_t u100 = value * 100;
|
||||
pct = u100 / total + (u100 % total != 0);
|
||||
} else {
|
||||
/* Possible rounding errors - see coreutils' df for more explanation */
|
||||
double u = value;
|
||||
double t = total;
|
||||
if (t) {
|
||||
long int lipct = pct = u * 100 / t;
|
||||
double ipct = lipct;
|
||||
|
||||
/* Like 'pct = ceil (dpct);', but without ceil - from coreutils again */
|
||||
if (ipct - 1 < pct && pct <= ipct + 1)
|
||||
pct = ipct + (ipct < pct);
|
||||
}
|
||||
if(value <= DBL_MAX && total != 0) {
|
||||
pct = (double)value / total * 100.0;
|
||||
}
|
||||
return pct;
|
||||
}
|
||||
|
@ -524,7 +507,7 @@ process_arguments (int argc, char **argv)
|
|||
{"ignore-ereg-partition", required_argument, 0, 'i'},
|
||||
{"ignore-eregi-path", required_argument, 0, 'I'},
|
||||
{"ignore-eregi-partition", required_argument, 0, 'I'},
|
||||
{"ignore-missing", no_argument, 0, IGNORE_MISSING},
|
||||
{"ignore-missing", no_argument, 0, 'n'},
|
||||
{"local", no_argument, 0, 'l'},
|
||||
{"stat-remote-fs", no_argument, 0, 'L'},
|
||||
{"iperfdata", no_argument, 0, 'P'},
|
||||
|
@ -550,7 +533,7 @@ process_arguments (int argc, char **argv)
|
|||
strcpy (argv[c], "-t");
|
||||
|
||||
while (1) {
|
||||
c = getopt_long (argc, argv, "+?VqhvefCt:c:w:K:W:u:p:x:X:N:mklLPg:R:r:i:I:MEA", longopts, &option);
|
||||
c = getopt_long (argc, argv, "+?VqhvefCt:c:w:K:W:u:p:x:X:N:mklLPg:R:r:i:I:MEAn", longopts, &option);
|
||||
|
||||
if (c == -1 || c == EOF)
|
||||
break;
|
||||
|
@ -567,6 +550,10 @@ process_arguments (int argc, char **argv)
|
|||
|
||||
/* See comments for 'c' */
|
||||
case 'w': /* warning threshold */
|
||||
if (!is_percentage_expression(optarg) && !is_numeric(optarg)) {
|
||||
die(STATE_UNKNOWN, "Argument for --warning invalid or missing: %s\n", optarg);
|
||||
}
|
||||
|
||||
if (strstr(optarg, "%")) {
|
||||
if (*optarg == '@') {
|
||||
warn_freespace_percent = optarg;
|
||||
|
@ -588,6 +575,10 @@ process_arguments (int argc, char **argv)
|
|||
force @ at the beginning of the range, so that it is backwards compatible
|
||||
*/
|
||||
case 'c': /* critical threshold */
|
||||
if (!is_percentage_expression(optarg) && !is_numeric(optarg)) {
|
||||
die(STATE_UNKNOWN, "Argument for --critical invalid or missing: %s\n", optarg);
|
||||
}
|
||||
|
||||
if (strstr(optarg, "%")) {
|
||||
if (*optarg == '@') {
|
||||
crit_freespace_percent = optarg;
|
||||
|
@ -710,7 +701,7 @@ process_arguments (int argc, char **argv)
|
|||
mount_list = read_file_system_list (0);
|
||||
np_set_best_match(se, mount_list, exact_match);
|
||||
|
||||
path_selected = TRUE;
|
||||
path_selected = true;
|
||||
break;
|
||||
case 'x': /* exclude path or partition */
|
||||
np_add_name(&dp_exclude_list, optarg);
|
||||
|
@ -734,18 +725,18 @@ process_arguments (int argc, char **argv)
|
|||
break;
|
||||
case 'q': /* TODO: this function should eventually go away (removed 2007-09-20) */
|
||||
/* verbose--; **replaced by line below**. -q was only a broken way of implementing -e */
|
||||
erronly = TRUE;
|
||||
erronly = true;
|
||||
break;
|
||||
case 'e':
|
||||
erronly = TRUE;
|
||||
erronly = true;
|
||||
break;
|
||||
case 'E':
|
||||
if (path_selected)
|
||||
die (STATE_UNKNOWN, "DISK %s: %s", _("UNKNOWN"), _("Must set -E before selecting paths\n"));
|
||||
exact_match = TRUE;
|
||||
exact_match = true;
|
||||
break;
|
||||
case 'f':
|
||||
freespace_ignore_reserved = TRUE;
|
||||
freespace_ignore_reserved = true;
|
||||
break;
|
||||
case 'g':
|
||||
if (path_selected)
|
||||
|
@ -792,7 +783,7 @@ process_arguments (int argc, char **argv)
|
|||
cflags = default_cflags;
|
||||
break;
|
||||
|
||||
case IGNORE_MISSING:
|
||||
case 'n':
|
||||
ignore_missing = true;
|
||||
break;
|
||||
case 'A':
|
||||
|
@ -817,7 +808,7 @@ process_arguments (int argc, char **argv)
|
|||
|
||||
for (me = mount_list; me; me = me->me_next) {
|
||||
if (np_regex_match_mount_entry(me, &re)) {
|
||||
fnd = TRUE;
|
||||
fnd = true;
|
||||
if (verbose >= 3)
|
||||
printf("%s %s matching expression %s\n", me->me_devname, me->me_mountdir, optarg);
|
||||
|
||||
|
@ -832,24 +823,24 @@ process_arguments (int argc, char **argv)
|
|||
|
||||
if (!fnd && ignore_missing == true) {
|
||||
path_ignored = true;
|
||||
/* path_selected = TRUE;*/
|
||||
path_selected = true;
|
||||
break;
|
||||
} else if (!fnd)
|
||||
die (STATE_UNKNOWN, "DISK %s: %s - %s\n",_("UNKNOWN"),
|
||||
_("Regular expression did not match any path or disk"), optarg);
|
||||
|
||||
fnd = FALSE;
|
||||
path_selected = TRUE;
|
||||
fnd = false;
|
||||
path_selected = true;
|
||||
np_set_best_match(path_select_list, mount_list, exact_match);
|
||||
cflags = default_cflags;
|
||||
|
||||
break;
|
||||
case 'M': /* display mountpoint */
|
||||
display_mntp = TRUE;
|
||||
display_mntp = true;
|
||||
break;
|
||||
case 'C':
|
||||
/* add all mount entries to path_select list if no partitions have been explicitly defined using -p */
|
||||
if (path_selected == FALSE) {
|
||||
if (path_selected == false) {
|
||||
struct parameter_list *path;
|
||||
for (me = mount_list; me; me = me->me_next) {
|
||||
if (! (path = np_find_parameter(path_select_list, me->me_mountdir)))
|
||||
|
@ -872,7 +863,7 @@ process_arguments (int argc, char **argv)
|
|||
warn_freeinodes_percent = NULL;
|
||||
crit_freeinodes_percent = NULL;
|
||||
|
||||
path_selected = FALSE;
|
||||
path_selected = false;
|
||||
group = NULL;
|
||||
break;
|
||||
case 'V': /* version */
|
||||
|
@ -896,7 +887,7 @@ process_arguments (int argc, char **argv)
|
|||
|
||||
if (argc > c) {
|
||||
se = np_add_parameter(&path_select_list, strdup(argv[c++]));
|
||||
path_selected = TRUE;
|
||||
path_selected = true;
|
||||
set_all_thresholds(se);
|
||||
}
|
||||
|
||||
|
@ -905,7 +896,7 @@ process_arguments (int argc, char **argv)
|
|||
mult = (uintmax_t)1024 * 1024;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
@ -1004,7 +995,7 @@ print_help (void)
|
|||
printf (" %s\n", _("Regular expression to ignore selected path/partition (case insensitive) (may be repeated)"));
|
||||
printf (" %s\n", "-i, --ignore-ereg-path=PATH, --ignore-ereg-partition=PARTITION");
|
||||
printf (" %s\n", _("Regular expression to ignore selected path or partition (may be repeated)"));
|
||||
printf (" %s\n", "--ignore-missing");
|
||||
printf (" %s\n", "-n, --ignore-missing");
|
||||
printf (" %s\n", _("Return OK if no filesystem matches, filesystem does not exist or is inaccessible."));
|
||||
printf (" %s\n", _("(Provide this option before -p / -r / --ereg-path if used)"));
|
||||
printf (UT_PLUG_TIMEOUT, DEFAULT_SOCKET_TIMEOUT);
|
||||
|
@ -1131,7 +1122,7 @@ get_stats (struct parameter_list *p, struct fs_usage *fsp) {
|
|||
}
|
||||
/* finally calculate percentages for either plain FS or summed up group */
|
||||
p->dused_pct = calculate_percent( p->used, p->used + p->available ); /* used + available can never be > uintmax */
|
||||
p->dfree_pct = 100 - p->dused_pct;
|
||||
p->dfree_pct = 100.0 - p->dused_pct;
|
||||
p->dused_inodes_percent = calculate_percent(p->inodes_total - p->inodes_free, p->inodes_total);
|
||||
p->dfree_inodes_percent = 100 - p->dused_inodes_percent;
|
||||
|
||||
|
|
|
@ -41,8 +41,8 @@ const char *email = "devel@monitoring-plugins.org";
|
|||
|
||||
int process_arguments (int, char **);
|
||||
int validate_arguments (void);
|
||||
int error_scan (char *, int *);
|
||||
int ip_match_cidr(const char *, const char *);
|
||||
int error_scan (char *, bool *);
|
||||
bool ip_match_cidr(const char *, const char *);
|
||||
unsigned long ip2long(const char *);
|
||||
void print_help (void);
|
||||
void print_usage (void);
|
||||
|
@ -51,13 +51,13 @@ void print_usage (void);
|
|||
char query_address[ADDRESS_LENGTH] = "";
|
||||
char dns_server[ADDRESS_LENGTH] = "";
|
||||
char ptr_server[ADDRESS_LENGTH] = "";
|
||||
int verbose = FALSE;
|
||||
bool verbose = false;
|
||||
char **expected_address = NULL;
|
||||
int expected_address_cnt = 0;
|
||||
int expect_nxdomain = FALSE;
|
||||
bool expect_nxdomain = false;
|
||||
|
||||
int expect_authority = FALSE;
|
||||
int all_match = FALSE;
|
||||
bool expect_authority = false;
|
||||
bool all_match = false;
|
||||
thresholds *time_thresholds = NULL;
|
||||
|
||||
static int
|
||||
|
@ -80,15 +80,14 @@ main (int argc, char **argv)
|
|||
int n_addresses = 0;
|
||||
char *msg = NULL;
|
||||
char *temp_buffer = NULL;
|
||||
int non_authoritative = FALSE;
|
||||
bool non_authoritative = false;
|
||||
int result = STATE_UNKNOWN;
|
||||
double elapsed_time;
|
||||
long microsec;
|
||||
struct timeval tv;
|
||||
int parse_address = FALSE; /* This flag scans for Address: but only after Name: */
|
||||
bool parse_address = false; /* This flag scans for Address: but only after Name: */
|
||||
output chld_out, chld_err;
|
||||
size_t i;
|
||||
int is_nxdomain = FALSE;
|
||||
bool is_nxdomain = false;
|
||||
|
||||
setlocale (LC_ALL, "");
|
||||
bindtextdomain (PACKAGE, LOCALEDIR);
|
||||
|
@ -122,7 +121,7 @@ main (int argc, char **argv)
|
|||
}
|
||||
|
||||
/* scan stdout */
|
||||
for(i = 0; i < chld_out.lines; i++) {
|
||||
for(size_t i = 0; i < chld_out.lines; i++) {
|
||||
if (addresses == NULL)
|
||||
addresses = malloc(sizeof(*addresses)*10);
|
||||
else if (!(n_addresses % 10))
|
||||
|
@ -164,8 +163,8 @@ main (int argc, char **argv)
|
|||
|
||||
/* the server is responding, we just got the host name... */
|
||||
if (strstr (chld_out.line[i], "Name:"))
|
||||
parse_address = TRUE;
|
||||
else if (parse_address == TRUE && (strstr (chld_out.line[i], "Address:") ||
|
||||
parse_address = true;
|
||||
else if (parse_address && (strstr (chld_out.line[i], "Address:") ||
|
||||
strstr (chld_out.line[i], "Addresses:"))) {
|
||||
temp_buffer = index (chld_out.line[i], ':');
|
||||
temp_buffer++;
|
||||
|
@ -184,7 +183,7 @@ main (int argc, char **argv)
|
|||
addresses[n_addresses++] = strdup(temp_buffer);
|
||||
}
|
||||
else if (strstr (chld_out.line[i], _("Non-authoritative answer:"))) {
|
||||
non_authoritative = TRUE;
|
||||
non_authoritative = true;
|
||||
}
|
||||
|
||||
|
||||
|
@ -197,7 +196,7 @@ main (int argc, char **argv)
|
|||
}
|
||||
|
||||
/* scan stderr */
|
||||
for(i = 0; i < chld_err.lines; i++) {
|
||||
for(size_t i = 0; i < chld_err.lines; i++) {
|
||||
if (verbose)
|
||||
puts(chld_err.line[i]);
|
||||
|
||||
|
@ -241,7 +240,7 @@ main (int argc, char **argv)
|
|||
unsigned long expect_match = (1 << expected_address_cnt) - 1;
|
||||
unsigned long addr_match = (1 << n_addresses) - 1;
|
||||
|
||||
for (i=0; i<expected_address_cnt; i++) {
|
||||
for (int i=0; i<expected_address_cnt; i++) {
|
||||
int j;
|
||||
/* check if we get a match on 'raw' ip or cidr */
|
||||
for (j=0; j<n_addresses; j++) {
|
||||
|
@ -298,21 +297,21 @@ main (int argc, char **argv)
|
|||
printf (_(". %s returns %s"), query_address, address);
|
||||
if ((time_thresholds->warning != NULL) && (time_thresholds->critical != NULL)) {
|
||||
printf ("|%s\n", fperfdata ("time", elapsed_time, "s",
|
||||
TRUE, time_thresholds->warning->end,
|
||||
TRUE, time_thresholds->critical->end,
|
||||
TRUE, 0, FALSE, 0));
|
||||
true, time_thresholds->warning->end,
|
||||
true, time_thresholds->critical->end,
|
||||
true, 0, false, 0));
|
||||
} else if ((time_thresholds->warning == NULL) && (time_thresholds->critical != NULL)) {
|
||||
printf ("|%s\n", fperfdata ("time", elapsed_time, "s",
|
||||
FALSE, 0,
|
||||
TRUE, time_thresholds->critical->end,
|
||||
TRUE, 0, FALSE, 0));
|
||||
false, 0,
|
||||
true, time_thresholds->critical->end,
|
||||
true, 0, false, 0));
|
||||
} else if ((time_thresholds->warning != NULL) && (time_thresholds->critical == NULL)) {
|
||||
printf ("|%s\n", fperfdata ("time", elapsed_time, "s",
|
||||
TRUE, time_thresholds->warning->end,
|
||||
FALSE, 0,
|
||||
TRUE, 0, FALSE, 0));
|
||||
true, time_thresholds->warning->end,
|
||||
false, 0,
|
||||
true, 0, false, 0));
|
||||
} else
|
||||
printf ("|%s\n", fperfdata ("time", elapsed_time, "s", FALSE, 0, FALSE, 0, TRUE, 0, FALSE, 0));
|
||||
printf ("|%s\n", fperfdata ("time", elapsed_time, "s", false, 0, false, 0, true, 0, false, 0));
|
||||
}
|
||||
else if (result == STATE_WARNING)
|
||||
printf (_("DNS WARNING - %s\n"),
|
||||
|
@ -327,15 +326,14 @@ main (int argc, char **argv)
|
|||
return result;
|
||||
}
|
||||
|
||||
int
|
||||
ip_match_cidr(const char *addr, const char *cidr_ro)
|
||||
{
|
||||
bool ip_match_cidr(const char *addr, const char *cidr_ro) {
|
||||
char *subnet, *mask_c, *cidr = strdup(cidr_ro);
|
||||
int mask;
|
||||
subnet = strtok(cidr, "/");
|
||||
mask_c = strtok(NULL, "\0");
|
||||
if (!subnet || !mask_c)
|
||||
return FALSE;
|
||||
if (!subnet || !mask_c) {
|
||||
return false;
|
||||
}
|
||||
mask = atoi(mask_c);
|
||||
|
||||
/* https://www.cryptobells.com/verifying-ips-in-a-subnet-in-php/ */
|
||||
|
@ -355,14 +353,14 @@ ip2long(const char* src) {
|
|||
}
|
||||
|
||||
int
|
||||
error_scan (char *input_buffer, int *is_nxdomain)
|
||||
error_scan (char *input_buffer, bool *is_nxdomain)
|
||||
{
|
||||
|
||||
const int nxdomain = strstr (input_buffer, "Non-existent") ||
|
||||
strstr (input_buffer, "** server can't find") ||
|
||||
strstr (input_buffer, "** Can't find") ||
|
||||
strstr (input_buffer, "NXDOMAIN");
|
||||
if (nxdomain) *is_nxdomain = TRUE;
|
||||
if (nxdomain) *is_nxdomain = true;
|
||||
|
||||
/* the DNS lookup timed out */
|
||||
if (strstr (input_buffer, _("Note: nslookup is deprecated and may be removed from future releases.")) ||
|
||||
|
@ -461,7 +459,7 @@ process_arguments (int argc, char **argv)
|
|||
print_revision (progname, NP_VERSION);
|
||||
exit (STATE_UNKNOWN);
|
||||
case 'v': /* version */
|
||||
verbose = TRUE;
|
||||
verbose = true;
|
||||
break;
|
||||
case 't': /* timeout period */
|
||||
timeout_interval = atoi (optarg);
|
||||
|
@ -508,13 +506,13 @@ process_arguments (int argc, char **argv)
|
|||
}
|
||||
break;
|
||||
case 'n': /* expect NXDOMAIN */
|
||||
expect_nxdomain = TRUE;
|
||||
expect_nxdomain = true;
|
||||
break;
|
||||
case 'A': /* expect authority */
|
||||
expect_authority = TRUE;
|
||||
expect_authority = true;
|
||||
break;
|
||||
case 'L': /* all must match */
|
||||
all_match = TRUE;
|
||||
all_match = true;
|
||||
break;
|
||||
case 'w':
|
||||
warning = optarg;
|
||||
|
|
|
@ -59,16 +59,16 @@ int packet_size = PACKET_SIZE;
|
|||
int packet_count = PACKET_COUNT;
|
||||
int target_timeout = 0;
|
||||
int packet_interval = 0;
|
||||
int verbose = FALSE;
|
||||
bool verbose = false;
|
||||
int cpl;
|
||||
int wpl;
|
||||
double crta;
|
||||
double wrta;
|
||||
int cpl_p = FALSE;
|
||||
int wpl_p = FALSE;
|
||||
bool alive_p = FALSE;
|
||||
int crta_p = FALSE;
|
||||
int wrta_p = FALSE;
|
||||
bool cpl_p = false;
|
||||
bool wpl_p = false;
|
||||
bool alive_p = false;
|
||||
bool crta_p = false;
|
||||
bool wrta_p = false;
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
|
@ -194,8 +194,8 @@ int textscan (char *buf) {
|
|||
_("FPING %s - %s (rta=%f ms)|%s\n"),
|
||||
state_text (STATE_OK), server_name,rta,
|
||||
/* No loss since we only waited for the first reply
|
||||
perfdata ("loss", (long int)loss, "%", wpl_p, wpl, cpl_p, cpl, TRUE, 0, TRUE, 100), */
|
||||
fperfdata ("rta", rta/1.0e3, "s", wrta_p, wrta/1.0e3, crta_p, crta/1.0e3, TRUE, 0, FALSE, 0));
|
||||
perfdata ("loss", (long int)loss, "%", wpl_p, wpl, cpl_p, cpl, true, 0, true, 100), */
|
||||
fperfdata ("rta", rta/1.0e3, "s", wrta_p, wrta/1.0e3, crta_p, crta/1.0e3, true, 0, false, 0));
|
||||
}
|
||||
|
||||
if (strstr (buf, "not found")) {
|
||||
|
@ -228,21 +228,21 @@ int textscan (char *buf) {
|
|||
rtastr = 1 + index (rtastr, '/');
|
||||
loss = strtod (losstr, NULL);
|
||||
rta = strtod (rtastr, NULL);
|
||||
if (cpl_p == TRUE && loss > cpl)
|
||||
if (cpl_p && loss > cpl)
|
||||
status = STATE_CRITICAL;
|
||||
else if (crta_p == TRUE && rta > crta)
|
||||
else if (crta_p && rta > crta)
|
||||
status = STATE_CRITICAL;
|
||||
else if (wpl_p == TRUE && loss > wpl)
|
||||
else if (wpl_p && loss > wpl)
|
||||
status = STATE_WARNING;
|
||||
else if (wrta_p == TRUE && rta > wrta)
|
||||
else if (wrta_p && rta > wrta)
|
||||
status = STATE_WARNING;
|
||||
else
|
||||
status = STATE_OK;
|
||||
die (status,
|
||||
_("FPING %s - %s (loss=%.0f%%, rta=%f ms)|%s %s\n"),
|
||||
state_text (status), server_name, loss, rta,
|
||||
perfdata ("loss", (long int)loss, "%", wpl_p, wpl, cpl_p, cpl, TRUE, 0, TRUE, 100),
|
||||
fperfdata ("rta", rta/1.0e3, "s", wrta_p, wrta/1.0e3, crta_p, crta/1.0e3, TRUE, 0, FALSE, 0));
|
||||
perfdata ("loss", (long int)loss, "%", wpl_p, wpl, cpl_p, cpl, true, 0, true, 100),
|
||||
fperfdata ("rta", rta/1.0e3, "s", wrta_p, wrta/1.0e3, crta_p, crta/1.0e3, true, 0, false, 0));
|
||||
|
||||
}
|
||||
else if(strstr (buf, "xmt/rcv/%loss") ) {
|
||||
|
@ -258,16 +258,16 @@ int textscan (char *buf) {
|
|||
loss = strtod (losstr, NULL);
|
||||
if (atoi(losstr) == 100)
|
||||
status = STATE_CRITICAL;
|
||||
else if (cpl_p == TRUE && loss > cpl)
|
||||
else if (cpl_p && loss > cpl)
|
||||
status = STATE_CRITICAL;
|
||||
else if (wpl_p == TRUE && loss > wpl)
|
||||
else if (wpl_p && loss > wpl)
|
||||
status = STATE_WARNING;
|
||||
else
|
||||
status = STATE_OK;
|
||||
/* loss=%.0f%%;%d;%d;0;100 */
|
||||
die (status, _("FPING %s - %s (loss=%.0f%% )|%s\n"),
|
||||
state_text (status), server_name, loss ,
|
||||
perfdata ("loss", (long int)loss, "%", wpl_p, wpl, cpl_p, cpl, TRUE, 0, TRUE, 100));
|
||||
perfdata ("loss", (long int)loss, "%", wpl_p, wpl, cpl_p, cpl, true, 0, true, 100));
|
||||
|
||||
}
|
||||
else {
|
||||
|
@ -329,7 +329,7 @@ process_arguments (int argc, char **argv)
|
|||
case '?': /* print short usage statement if args not parsable */
|
||||
usage5 ();
|
||||
case 'a': /* host alive mode */
|
||||
alive_p = TRUE;
|
||||
alive_p = true;
|
||||
break;
|
||||
case 'h': /* help */
|
||||
print_help ();
|
||||
|
@ -338,16 +338,16 @@ process_arguments (int argc, char **argv)
|
|||
print_revision (progname, NP_VERSION);
|
||||
exit (STATE_UNKNOWN);
|
||||
case 'v': /* verbose mode */
|
||||
verbose = TRUE;
|
||||
verbose = true;
|
||||
break;
|
||||
case 'H': /* hostname */
|
||||
if (is_host (optarg) == FALSE) {
|
||||
if (is_host (optarg) == false) {
|
||||
usage2 (_("Invalid hostname/address"), optarg);
|
||||
}
|
||||
server_name = strscpy (server_name, optarg);
|
||||
break;
|
||||
case 'S': /* sourceip */
|
||||
if (is_host (optarg) == FALSE) {
|
||||
if (is_host (optarg) == false) {
|
||||
usage2 (_("Invalid hostname/address"), optarg);
|
||||
}
|
||||
sourceip = strscpy (sourceip, optarg);
|
||||
|
@ -369,12 +369,12 @@ process_arguments (int argc, char **argv)
|
|||
get_threshold (optarg, rv);
|
||||
if (rv[RTA]) {
|
||||
crta = strtod (rv[RTA], NULL);
|
||||
crta_p = TRUE;
|
||||
crta_p = true;
|
||||
rv[RTA] = NULL;
|
||||
}
|
||||
if (rv[PL]) {
|
||||
cpl = atoi (rv[PL]);
|
||||
cpl_p = TRUE;
|
||||
cpl_p = true;
|
||||
rv[PL] = NULL;
|
||||
}
|
||||
break;
|
||||
|
@ -382,12 +382,12 @@ process_arguments (int argc, char **argv)
|
|||
get_threshold (optarg, rv);
|
||||
if (rv[RTA]) {
|
||||
wrta = strtod (rv[RTA], NULL);
|
||||
wrta_p = TRUE;
|
||||
wrta_p = true;
|
||||
rv[RTA] = NULL;
|
||||
}
|
||||
if (rv[PL]) {
|
||||
wpl = atoi (rv[PL]);
|
||||
wpl_p = TRUE;
|
||||
wpl_p = true;
|
||||
rv[PL] = NULL;
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -53,7 +53,7 @@ char *server_ip;
|
|||
char *game_type;
|
||||
int port = 0;
|
||||
|
||||
int verbose;
|
||||
bool verbose = false;
|
||||
|
||||
int qstat_game_players_max = -1;
|
||||
int qstat_game_players = -1;
|
||||
|
@ -90,7 +90,7 @@ main (int argc, char **argv)
|
|||
if (port)
|
||||
xasprintf (&command_line, "%s:%-d", command_line, port);
|
||||
|
||||
if (verbose > 0)
|
||||
if (verbose)
|
||||
printf ("%s\n", command_line);
|
||||
|
||||
/* run the command. historically, this plugin ignores output on stderr,
|
||||
|
@ -142,11 +142,11 @@ main (int argc, char **argv)
|
|||
ret[qstat_map_field],
|
||||
ret[qstat_ping_field],
|
||||
perfdata ("players", atol(ret[qstat_game_players]), "",
|
||||
FALSE, 0, FALSE, 0,
|
||||
TRUE, 0, TRUE, atol(ret[qstat_game_players_max])),
|
||||
false, 0, false, 0,
|
||||
true, 0, true, atol(ret[qstat_game_players_max])),
|
||||
fperfdata ("ping", strtod(ret[qstat_ping_field], NULL), "",
|
||||
FALSE, 0, FALSE, 0,
|
||||
TRUE, 0, FALSE, 0));
|
||||
false, 0, false, 0,
|
||||
true, 0, false, 0));
|
||||
}
|
||||
|
||||
return result;
|
||||
|
@ -201,7 +201,7 @@ process_arguments (int argc, char **argv)
|
|||
print_revision (progname, NP_VERSION);
|
||||
exit (STATE_UNKNOWN);
|
||||
case 'v': /* version */
|
||||
verbose = TRUE;
|
||||
verbose = true;
|
||||
break;
|
||||
case 't': /* timeout period */
|
||||
timeout_interval = atoi (optarg);
|
||||
|
|
|
@ -85,6 +85,7 @@ char errbuf[MAX_INPUT_BUFFER];
|
|||
int cflags = REG_NOSUB | REG_EXTENDED | REG_NEWLINE;
|
||||
int errcode;
|
||||
int invert_regex = 0;
|
||||
int state_regex = STATE_CRITICAL;
|
||||
|
||||
struct timeval tv;
|
||||
struct timeval tv_temp;
|
||||
|
@ -210,7 +211,8 @@ bool process_arguments (int argc, char **argv)
|
|||
INVERT_REGEX = CHAR_MAX + 1,
|
||||
SNI_OPTION,
|
||||
MAX_REDIRS_OPTION,
|
||||
CONTINUE_AFTER_CHECK_CERT
|
||||
CONTINUE_AFTER_CHECK_CERT,
|
||||
STATE_REGEX
|
||||
};
|
||||
|
||||
int option = 0;
|
||||
|
@ -246,6 +248,7 @@ bool process_arguments (int argc, char **argv)
|
|||
{"content-type", required_argument, 0, 'T'},
|
||||
{"pagesize", required_argument, 0, 'm'},
|
||||
{"invert-regex", no_argument, NULL, INVERT_REGEX},
|
||||
{"state-regex", required_argument, 0, STATE_REGEX},
|
||||
{"use-ipv4", no_argument, 0, '4'},
|
||||
{"use-ipv6", no_argument, 0, '6'},
|
||||
{"extended-perfdata", no_argument, 0, 'E'},
|
||||
|
@ -471,10 +474,9 @@ bool process_arguments (int argc, char **argv)
|
|||
free(http_method);
|
||||
http_method = strdup (optarg);
|
||||
char *tmp;
|
||||
if ((tmp = strstr(http_method, ":")) > 0) {
|
||||
tmp[0] = '\0';
|
||||
http_method = http_method;
|
||||
http_method_proxy = ++tmp;
|
||||
if ((tmp = strstr(http_method, ":")) != NULL) {
|
||||
tmp[0] = '\0'; // set the ":" in the middle to 0
|
||||
http_method_proxy = ++tmp; // this points to the second part
|
||||
}
|
||||
break;
|
||||
case 'd': /* string or substring */
|
||||
|
@ -512,6 +514,13 @@ bool process_arguments (int argc, char **argv)
|
|||
case INVERT_REGEX:
|
||||
invert_regex = 1;
|
||||
break;
|
||||
case STATE_REGEX:
|
||||
if (!strcmp (optarg, "critical"))
|
||||
state_regex = STATE_CRITICAL;
|
||||
else if (!strcmp (optarg, "warning"))
|
||||
state_regex = STATE_WARNING;
|
||||
else usage2 (_("Invalid state-regex option"), optarg);
|
||||
break;
|
||||
case '4':
|
||||
address_family = AF_INET;
|
||||
break;
|
||||
|
@ -1318,7 +1327,7 @@ check_http (void)
|
|||
xasprintf (&msg, _("%spattern not found, "), msg);
|
||||
else
|
||||
xasprintf (&msg, _("%spattern found, "), msg);
|
||||
result = STATE_CRITICAL;
|
||||
result = state_regex;
|
||||
}
|
||||
else {
|
||||
/* FIXME: Shouldn't that be UNKNOWN? */
|
||||
|
@ -1775,7 +1784,7 @@ print_help (void)
|
|||
printf (" %s\n", "-u, --url=PATH");
|
||||
printf (" %s\n", _("URL to GET or POST (default: /)"));
|
||||
printf (" %s\n", "-P, --post=STRING");
|
||||
printf (" %s\n", _("URL encoded http POST data"));
|
||||
printf (" %s\n", _("URL decoded http POST data"));
|
||||
printf (" %s\n", "-j, --method=STRING (for example: HEAD, OPTIONS, TRACE, PUT, DELETE, CONNECT, CONNECT:POST)");
|
||||
printf (" %s\n", _("Set HTTP method."));
|
||||
printf (" %s\n", "-N, --no-body");
|
||||
|
@ -1794,7 +1803,10 @@ print_help (void)
|
|||
printf (" %s\n", "-R, --eregi=STRING");
|
||||
printf (" %s\n", _("Search page for case-insensitive regex STRING"));
|
||||
printf (" %s\n", "--invert-regex");
|
||||
printf (" %s\n", _("Return CRITICAL if found, OK if not\n"));
|
||||
printf (" %s\n", _("Return STATE if found, OK if not (STATE is CRITICAL, per default)"));
|
||||
printf (" %s\n", _("can be changed with --state--regex)"));
|
||||
printf (" %s\n", "--regex-state=STATE");
|
||||
printf (" %s\n", _("Return STATE if regex is found, OK if not\n"));
|
||||
|
||||
printf (" %s\n", "-a, --authorization=AUTH_PAIR");
|
||||
printf (" %s\n", _("Username:password on sites with basic authentication"));
|
||||
|
|
|
@ -73,10 +73,6 @@ void print_usage (void);
|
|||
|
||||
#define NR_ATTRIBUTES 30
|
||||
|
||||
#ifndef TRUE
|
||||
#define TRUE 1
|
||||
#endif /* */
|
||||
|
||||
#define PREFAILURE 2
|
||||
#define ADVISORY 1
|
||||
#define OPERATIONAL 0
|
||||
|
@ -169,9 +165,9 @@ int smart_read_values (int, values_t *);
|
|||
int nagios (values_t *, thresholds_t *);
|
||||
void print_value (value_t *, threshold_t *);
|
||||
void print_values (values_t *, thresholds_t *);
|
||||
int smart_cmd_simple (int, enum SmartCommand, __u8, char);
|
||||
int smart_cmd_simple (int, enum SmartCommand, __u8, bool);
|
||||
int smart_read_thresholds (int, thresholds_t *);
|
||||
int verbose = FALSE;
|
||||
bool verbose = false;
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
|
@ -203,7 +199,7 @@ main (int argc, char *argv[])
|
|||
bindtextdomain (PACKAGE, LOCALEDIR);
|
||||
textdomain (PACKAGE);
|
||||
|
||||
while (1) {
|
||||
while (true) {
|
||||
|
||||
o = getopt_long (argc, argv, "+d:iq10nhVv", longopts, &longindex);
|
||||
|
||||
|
@ -229,7 +225,7 @@ main (int argc, char *argv[])
|
|||
fprintf (stderr, "%s\n", _("default and will be removed from future releases."));
|
||||
break;
|
||||
case 'v': /* verbose */
|
||||
verbose = TRUE;
|
||||
verbose = true;
|
||||
break;
|
||||
case 'h':
|
||||
print_help ();
|
||||
|
@ -258,7 +254,7 @@ main (int argc, char *argv[])
|
|||
return STATE_CRITICAL;
|
||||
}
|
||||
|
||||
if (smart_cmd_simple (fd, SMART_CMD_ENABLE, 0, FALSE)) {
|
||||
if (smart_cmd_simple (fd, SMART_CMD_ENABLE, 0, false)) {
|
||||
printf (_("CRITICAL - SMART_CMD_ENABLE\n"));
|
||||
return STATE_CRITICAL;
|
||||
}
|
||||
|
@ -447,9 +443,7 @@ print_values (values_t * p, thresholds_t * t)
|
|||
}
|
||||
|
||||
|
||||
int
|
||||
smart_cmd_simple (int fd, enum SmartCommand command, __u8 val0, char show_error)
|
||||
{
|
||||
int smart_cmd_simple (int fd, enum SmartCommand command, __u8 val0, bool show_error) {
|
||||
int e = STATE_UNKNOWN;
|
||||
#ifdef __linux__
|
||||
__u8 args[4];
|
||||
|
|
|
@ -71,9 +71,9 @@ thresholds *entries_thresholds = NULL;
|
|||
struct timeval tv;
|
||||
char* warn_entries = NULL;
|
||||
char* crit_entries = NULL;
|
||||
int starttls = FALSE;
|
||||
int ssl_on_connect = FALSE;
|
||||
int verbose = 0;
|
||||
bool starttls = false;
|
||||
bool ssl_on_connect = false;
|
||||
bool verbose = false;
|
||||
|
||||
/* for ldap tls */
|
||||
|
||||
|
@ -115,7 +115,7 @@ main (int argc, char *argv[])
|
|||
usage4 (_("Could not parse arguments"));
|
||||
|
||||
if (strstr(argv[0],"check_ldaps") && ! starttls && ! ssl_on_connect)
|
||||
starttls = TRUE;
|
||||
starttls = true;
|
||||
|
||||
/* initialize alarm signal handling */
|
||||
signal (SIGALRM, socket_timeout_alarm_handler);
|
||||
|
@ -253,11 +253,11 @@ main (int argc, char *argv[])
|
|||
fperfdata ("time", elapsed_time, "s",
|
||||
(int)warn_time, warn_time,
|
||||
(int)crit_time, crit_time,
|
||||
TRUE, 0, FALSE, 0),
|
||||
true, 0, false, 0),
|
||||
sperfdata ("entries", (double)num_entries, "",
|
||||
warn_entries,
|
||||
crit_entries,
|
||||
TRUE, 0.0, FALSE, 0.0));
|
||||
true, 0.0, false, 0.0));
|
||||
} else {
|
||||
printf (_("LDAP %s - %.3f seconds response time|%s\n"),
|
||||
state_text (status),
|
||||
|
@ -265,7 +265,7 @@ main (int argc, char *argv[])
|
|||
fperfdata ("time", elapsed_time, "s",
|
||||
(int)warn_time, warn_time,
|
||||
(int)crit_time, crit_time,
|
||||
TRUE, 0, FALSE, 0));
|
||||
true, 0, false, 0));
|
||||
}
|
||||
|
||||
return status;
|
||||
|
@ -313,7 +313,7 @@ process_arguments (int argc, char **argv)
|
|||
strcpy (argv[c], "-t");
|
||||
}
|
||||
|
||||
while (1) {
|
||||
while (true) {
|
||||
c = getopt_long (argc, argv, "hvV234TS6t:c:w:H:b:p:a:D:P:C:W:", longopts, &option);
|
||||
|
||||
if (c == -1 || c == EOF)
|
||||
|
@ -374,17 +374,17 @@ process_arguments (int argc, char **argv)
|
|||
address_family = AF_INET;
|
||||
break;
|
||||
case 'v':
|
||||
verbose++;
|
||||
verbose = true;
|
||||
break;
|
||||
case 'T':
|
||||
if (! ssl_on_connect)
|
||||
starttls = TRUE;
|
||||
starttls = true;
|
||||
else
|
||||
usage_va(_("%s cannot be combined with %s"), "-T/--starttls", "-S/--ssl");
|
||||
break;
|
||||
case 'S':
|
||||
if (! starttls) {
|
||||
ssl_on_connect = TRUE;
|
||||
ssl_on_connect = true;
|
||||
if (ld_port == -1)
|
||||
ld_port = LDAPS_PORT;
|
||||
} else
|
||||
|
|
|
@ -110,10 +110,6 @@ main (int argc, char **argv)
|
|||
double la[3] = { 0.0, 0.0, 0.0 }; /* NetBSD complains about uninitialized arrays */
|
||||
#ifndef HAVE_GETLOADAVG
|
||||
char input_buffer[MAX_INPUT_BUFFER];
|
||||
# ifdef HAVE_PROC_LOADAVG
|
||||
FILE *fp;
|
||||
char *str, *next;
|
||||
# endif
|
||||
#endif
|
||||
|
||||
setlocale (LC_ALL, "");
|
||||
|
@ -132,23 +128,6 @@ main (int argc, char **argv)
|
|||
if (result != 3)
|
||||
return STATE_UNKNOWN;
|
||||
#else
|
||||
# ifdef HAVE_PROC_LOADAVG
|
||||
fp = fopen (PROC_LOADAVG, "r");
|
||||
if (fp == NULL) {
|
||||
printf (_("Error opening %s\n"), PROC_LOADAVG);
|
||||
return STATE_UNKNOWN;
|
||||
}
|
||||
|
||||
while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, fp)) {
|
||||
str = (char *)input_buffer;
|
||||
for(i = 0; i < 3; i++) {
|
||||
la[i] = strtod(str, &next);
|
||||
str = next;
|
||||
}
|
||||
}
|
||||
|
||||
fclose (fp);
|
||||
# else
|
||||
child_process = spopen (PATH_TO_UPTIME);
|
||||
if (child_process == NULL) {
|
||||
printf (_("Error opening %s\n"), PATH_TO_UPTIME);
|
||||
|
@ -175,18 +154,13 @@ main (int argc, char **argv)
|
|||
printf (_("Error code %d returned in %s\n"), result, PATH_TO_UPTIME);
|
||||
return STATE_UNKNOWN;
|
||||
}
|
||||
# endif
|
||||
#endif
|
||||
|
||||
if ((la[0] < 0.0) || (la[1] < 0.0) || (la[2] < 0.0)) {
|
||||
#ifdef HAVE_GETLOADAVG
|
||||
printf (_("Error in getloadavg()\n"));
|
||||
#else
|
||||
# ifdef HAVE_PROC_LOADAVG
|
||||
printf (_("Error processing %s\n"), PROC_LOADAVG);
|
||||
# else
|
||||
printf (_("Error processing %s\n"), PATH_TO_UPTIME);
|
||||
# endif
|
||||
#endif
|
||||
return STATE_UNKNOWN;
|
||||
}
|
||||
|
|
|
@ -43,7 +43,7 @@ void print_usage (void);
|
|||
|
||||
char *log_file = NULL;
|
||||
int expire_minutes = 0;
|
||||
int use_average = TRUE;
|
||||
bool use_average = true;
|
||||
int variable_number = -1;
|
||||
unsigned long value_warning_threshold = 0L;
|
||||
unsigned long value_critical_threshold = 0L;
|
||||
|
@ -138,7 +138,7 @@ main (int argc, char **argv)
|
|||
}
|
||||
|
||||
/* else check the incoming/outgoing rates */
|
||||
if (use_average == TRUE)
|
||||
if (use_average)
|
||||
rate = average_value_rate;
|
||||
else
|
||||
rate = maximum_value_rate;
|
||||
|
@ -149,7 +149,7 @@ main (int argc, char **argv)
|
|||
result = STATE_WARNING;
|
||||
|
||||
printf("%s. %s = %lu %s|%s\n",
|
||||
(use_average == TRUE) ? _("Avg") : _("Max"),
|
||||
(use_average) ? _("Avg") : _("Max"),
|
||||
label, rate, units,
|
||||
perfdata(label, (long) rate, units,
|
||||
(int) value_warning_threshold, (long) value_warning_threshold,
|
||||
|
@ -211,9 +211,9 @@ process_arguments (int argc, char **argv)
|
|||
break;
|
||||
case 'a': /* port */
|
||||
if (!strcmp (optarg, "MAX"))
|
||||
use_average = FALSE;
|
||||
use_average = false;
|
||||
else
|
||||
use_average = TRUE;
|
||||
use_average = true;
|
||||
break;
|
||||
case 'v':
|
||||
variable_number = atoi (optarg);
|
||||
|
@ -258,11 +258,11 @@ process_arguments (int argc, char **argv)
|
|||
}
|
||||
|
||||
if (argc > c && strcmp (argv[c], "MAX") == 0) {
|
||||
use_average = FALSE;
|
||||
use_average = false;
|
||||
c++;
|
||||
}
|
||||
else if (argc > c && strcmp (argv[c], "AVG") == 0) {
|
||||
use_average = TRUE;
|
||||
use_average = true;
|
||||
c++;
|
||||
}
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@ void print_usage(void);
|
|||
|
||||
char *log_file = NULL;
|
||||
int expire_minutes = -1;
|
||||
int use_average = TRUE;
|
||||
bool use_average = true;
|
||||
unsigned long incoming_warning_threshold = 0L;
|
||||
unsigned long incoming_critical_threshold = 0L;
|
||||
unsigned long outgoing_warning_threshold = 0L;
|
||||
|
@ -137,7 +137,7 @@ main (int argc, char **argv)
|
|||
(int) ((current_time - timestamp) / 60));
|
||||
|
||||
/* else check the incoming/outgoing rates */
|
||||
if (use_average == TRUE) {
|
||||
if (use_average) {
|
||||
incoming_rate = average_incoming_rate;
|
||||
outgoing_rate = average_outgoing_rate;
|
||||
}
|
||||
|
@ -192,17 +192,17 @@ main (int argc, char **argv)
|
|||
}
|
||||
|
||||
xasprintf (&error_message, _("%s. In = %0.1f %s/s, %s. Out = %0.1f %s/s|%s %s\n"),
|
||||
(use_average == TRUE) ? _("Avg") : _("Max"), adjusted_incoming_rate,
|
||||
incoming_speed_rating, (use_average == TRUE) ? _("Avg") : _("Max"),
|
||||
(use_average) ? _("Avg") : _("Max"), adjusted_incoming_rate,
|
||||
incoming_speed_rating, (use_average) ? _("Avg") : _("Max"),
|
||||
adjusted_outgoing_rate, outgoing_speed_rating,
|
||||
fperfdata("in", adjusted_incoming_rate, incoming_speed_rating,
|
||||
(int)incoming_warning_threshold, incoming_warning_threshold,
|
||||
(int)incoming_critical_threshold, incoming_critical_threshold,
|
||||
TRUE, 0, FALSE, 0),
|
||||
true, 0, false, 0),
|
||||
fperfdata("out", adjusted_outgoing_rate, outgoing_speed_rating,
|
||||
(int)outgoing_warning_threshold, outgoing_warning_threshold,
|
||||
(int)outgoing_critical_threshold, outgoing_critical_threshold,
|
||||
TRUE, 0, FALSE, 0));
|
||||
true, 0, false, 0));
|
||||
|
||||
printf (_("Traffic %s - %s\n"), state_text(result), error_message);
|
||||
|
||||
|
@ -256,9 +256,9 @@ process_arguments (int argc, char **argv)
|
|||
break;
|
||||
case 'a': /* aggregation (AVE or MAX) */
|
||||
if (!strcmp (optarg, "MAX"))
|
||||
use_average = FALSE;
|
||||
use_average = false;
|
||||
else
|
||||
use_average = TRUE;
|
||||
use_average = true;
|
||||
break;
|
||||
case 'c': /* warning threshold */
|
||||
sscanf (optarg, "%lu,%lu", &incoming_critical_threshold,
|
||||
|
@ -289,11 +289,11 @@ process_arguments (int argc, char **argv)
|
|||
}
|
||||
|
||||
if (argc > c && strcmp (argv[c], "MAX") == 0) {
|
||||
use_average = FALSE;
|
||||
use_average = false;
|
||||
c++;
|
||||
}
|
||||
else if (argc > c && strcmp (argv[c], "AVG") == 0) {
|
||||
use_average = TRUE;
|
||||
use_average = true;
|
||||
c++;
|
||||
}
|
||||
|
||||
|
|
|
@ -113,7 +113,7 @@ main (int argc, char **argv)
|
|||
char slaveresult[SLAVERESULTSIZE] = { 0 };
|
||||
char* perf;
|
||||
|
||||
perf = strdup ("");
|
||||
perf = strdup ("");
|
||||
|
||||
setlocale (LC_ALL, "");
|
||||
bindtextdomain (PACKAGE, LOCALEDIR);
|
||||
|
@ -193,14 +193,14 @@ main (int argc, char **argv)
|
|||
for(i = 0; i < LENGTH_METRIC_UNIT; i++) {
|
||||
if (strcmp(row[0], metric_unit[i]) == 0) {
|
||||
xasprintf(&perf, "%s%s ", perf, perfdata(metric_unit[i],
|
||||
atol(row[1]), "", FALSE, 0, FALSE, 0, FALSE, 0, FALSE, 0));
|
||||
atol(row[1]), "", false, 0, false, 0, false, 0, false, 0));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
for(i = 0; i < LENGTH_METRIC_COUNTER; i++) {
|
||||
if (strcmp(row[0], metric_counter[i]) == 0) {
|
||||
xasprintf(&perf, "%s%s ", perf, perfdata(metric_counter[i],
|
||||
atol(row[1]), "c", FALSE, 0, FALSE, 0, FALSE, 0, FALSE, 0));
|
||||
atol(row[1]), "c", false, 0, false, 0, false, 0, false, 0));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
@ -322,10 +322,10 @@ main (int argc, char **argv)
|
|||
status = get_status(value, my_threshold);
|
||||
|
||||
xasprintf (&perf, "%s %s", perf, fperfdata ("seconds behind master", value, "s",
|
||||
TRUE, (double) warning_time,
|
||||
TRUE, (double) critical_time,
|
||||
FALSE, 0,
|
||||
FALSE, 0));
|
||||
true, (double) warning_time,
|
||||
true, (double) critical_time,
|
||||
false, 0,
|
||||
false, 0));
|
||||
|
||||
if (status == STATE_WARNING) {
|
||||
printf("SLOW_SLAVE %s: %s|%s\n", _("WARNING"), slaveresult, perf);
|
||||
|
|
|
@ -162,10 +162,10 @@ main (int argc, char **argv)
|
|||
}
|
||||
printf(_("'%s' returned %f | %s"), sql_query, value,
|
||||
fperfdata("result", value, "",
|
||||
my_thresholds->warning?TRUE:FALSE, my_thresholds->warning?my_thresholds->warning->end:0,
|
||||
my_thresholds->critical?TRUE:FALSE, my_thresholds->critical?my_thresholds->critical->end:0,
|
||||
FALSE, 0,
|
||||
FALSE, 0)
|
||||
my_thresholds->warning?true:false, my_thresholds->warning?my_thresholds->warning->end:0,
|
||||
my_thresholds->critical?true:false, my_thresholds->critical?my_thresholds->critical->end:0,
|
||||
false, 0,
|
||||
false, 0)
|
||||
);
|
||||
printf("\n");
|
||||
|
||||
|
|
|
@ -67,17 +67,17 @@ char *req_password=NULL;
|
|||
unsigned long lvalue_list[MAX_VALUE_LIST];
|
||||
unsigned long warning_value=0L;
|
||||
unsigned long critical_value=0L;
|
||||
int check_warning_value=FALSE;
|
||||
int check_critical_value=FALSE;
|
||||
bool check_warning_value=false;
|
||||
bool check_critical_value=false;
|
||||
enum checkvars vars_to_check = CHECK_NONE;
|
||||
int show_all=FALSE;
|
||||
bool show_all = false;
|
||||
|
||||
char recv_buffer[MAX_INPUT_BUFFER];
|
||||
|
||||
void fetch_data (const char* address, int port, const char* sendb);
|
||||
int process_arguments(int, char **);
|
||||
void preparelist(char *string);
|
||||
int strtoularray(unsigned long *array, char *string, const char *delim);
|
||||
bool strtoularray(unsigned long *array, char *string, const char *delim);
|
||||
void print_help(void);
|
||||
void print_usage(void);
|
||||
|
||||
|
@ -113,8 +113,8 @@ int main(int argc, char **argv){
|
|||
int uphours=0;
|
||||
int upminutes=0;
|
||||
|
||||
int isPercent = FALSE;
|
||||
int allRight = FALSE;
|
||||
bool isPercent = false;
|
||||
bool allRight = false;
|
||||
|
||||
setlocale (LC_ALL, "");
|
||||
bindtextdomain (PACKAGE, LOCALEDIR);
|
||||
|
@ -151,7 +151,7 @@ int main(int argc, char **argv){
|
|||
|
||||
if (value_list==NULL)
|
||||
output_message = strdup (_("missing -l parameters"));
|
||||
else if (strtoularray(lvalue_list,value_list,",")==FALSE)
|
||||
else if (! strtoularray(lvalue_list,value_list,","))
|
||||
output_message = strdup (_("wrong -l parameter."));
|
||||
else {
|
||||
/* -l parameters is present with only integers */
|
||||
|
@ -224,9 +224,9 @@ int main(int argc, char **argv){
|
|||
|
||||
xasprintf(&output_message,_("System Uptime - %u day(s) %u hour(s) %u minute(s) |uptime=%lu"),updays, uphours, upminutes, uptime);
|
||||
|
||||
if (check_critical_value==TRUE && uptime <= critical_value)
|
||||
if (check_critical_value && uptime <= critical_value)
|
||||
return_code=STATE_CRITICAL;
|
||||
else if (check_warning_value==TRUE && uptime <= warning_value)
|
||||
else if (check_warning_value && uptime <= warning_value)
|
||||
return_code=STATE_WARNING;
|
||||
else
|
||||
return_code=STATE_OK;
|
||||
|
@ -261,9 +261,9 @@ int main(int argc, char **argv){
|
|||
(total_disk_space - free_disk_space) / 1073741824, warning_used_space / 1073741824,
|
||||
critical_used_space / 1073741824, total_disk_space / 1073741824);
|
||||
|
||||
if(check_critical_value==TRUE && percent_used_space >= critical_value)
|
||||
if(check_critical_value && percent_used_space >= critical_value)
|
||||
return_code=STATE_CRITICAL;
|
||||
else if (check_warning_value==TRUE && percent_used_space >= warning_value)
|
||||
else if (check_warning_value && percent_used_space >= warning_value)
|
||||
return_code=STATE_WARNING;
|
||||
else
|
||||
return_code=STATE_OK;
|
||||
|
@ -285,7 +285,7 @@ int main(int argc, char **argv){
|
|||
else {
|
||||
preparelist(value_list); /* replace , between services with & to send the request */
|
||||
xasprintf(&send_buffer,"%s&%u&%s&%s", req_password,(vars_to_check==CHECK_SERVICESTATE)?5:6,
|
||||
(show_all==TRUE) ? "ShowAll" : "ShowFail",value_list);
|
||||
(show_all) ? "ShowAll" : "ShowFail",value_list);
|
||||
fetch_data (server_address, server_port, send_buffer);
|
||||
numstr = strtok(recv_buffer,"&");
|
||||
if (numstr == NULL)
|
||||
|
@ -321,9 +321,9 @@ int main(int argc, char **argv){
|
|||
warning_used_space / 1048567, critical_used_space / 1048567, mem_commitLimit / 1048567);
|
||||
|
||||
return_code=STATE_OK;
|
||||
if(check_critical_value==TRUE && percent_used_space >= critical_value)
|
||||
if(check_critical_value && percent_used_space >= critical_value)
|
||||
return_code=STATE_CRITICAL;
|
||||
else if (check_warning_value==TRUE && percent_used_space >= warning_value)
|
||||
else if (check_warning_value && percent_used_space >= warning_value)
|
||||
return_code=STATE_WARNING;
|
||||
|
||||
break;
|
||||
|
@ -371,7 +371,7 @@ int main(int argc, char **argv){
|
|||
else if (isPercent)
|
||||
{
|
||||
counter_unit = strdup ("%");
|
||||
allRight = TRUE;
|
||||
allRight = true;
|
||||
}
|
||||
|
||||
if ((counter_unit != NULL) && (!allRight))
|
||||
|
@ -391,7 +391,7 @@ int main(int argc, char **argv){
|
|||
if ((fmaxval == 0) && (maxval == errcvt))
|
||||
output_message = strdup (_("Maximum value contains non-numbers"));
|
||||
else
|
||||
allRight = TRUE; /* Everything is OK. */
|
||||
allRight = true; /* Everything is OK. */
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -418,9 +418,9 @@ int main(int argc, char **argv){
|
|||
|
||||
if (critical_value > warning_value)
|
||||
{ /* Normal thresholds */
|
||||
if (check_critical_value == TRUE && counter_value >= critical_value)
|
||||
if (check_critical_value && counter_value >= critical_value)
|
||||
return_code = STATE_CRITICAL;
|
||||
else if (check_warning_value == TRUE && counter_value >= warning_value)
|
||||
else if (check_warning_value && counter_value >= warning_value)
|
||||
return_code = STATE_WARNING;
|
||||
else
|
||||
return_code = STATE_OK;
|
||||
|
@ -428,9 +428,9 @@ int main(int argc, char **argv){
|
|||
else
|
||||
{ /* inverse thresholds */
|
||||
return_code = STATE_OK;
|
||||
if (check_critical_value == TRUE && counter_value <= critical_value)
|
||||
if (check_critical_value && counter_value <= critical_value)
|
||||
return_code = STATE_CRITICAL;
|
||||
else if (check_warning_value == TRUE && counter_value <= warning_value)
|
||||
else if (check_warning_value && counter_value <= warning_value)
|
||||
return_code = STATE_WARNING;
|
||||
}
|
||||
break;
|
||||
|
@ -448,17 +448,17 @@ int main(int argc, char **argv){
|
|||
output_message = strdup (description);
|
||||
|
||||
if (critical_value > warning_value) { /* Normal thresholds */
|
||||
if(check_critical_value==TRUE && age_in_minutes >= critical_value)
|
||||
if(check_critical_value && age_in_minutes >= critical_value)
|
||||
return_code=STATE_CRITICAL;
|
||||
else if (check_warning_value==TRUE && age_in_minutes >= warning_value)
|
||||
else if (check_warning_value && age_in_minutes >= warning_value)
|
||||
return_code=STATE_WARNING;
|
||||
else
|
||||
return_code=STATE_OK;
|
||||
}
|
||||
else { /* inverse thresholds */
|
||||
if(check_critical_value==TRUE && age_in_minutes <= critical_value)
|
||||
if(check_critical_value && age_in_minutes <= critical_value)
|
||||
return_code=STATE_CRITICAL;
|
||||
else if (check_warning_value==TRUE && age_in_minutes <= warning_value)
|
||||
else if (check_warning_value && age_in_minutes <= warning_value)
|
||||
return_code=STATE_WARNING;
|
||||
else
|
||||
return_code=STATE_OK;
|
||||
|
@ -600,15 +600,15 @@ int process_arguments(int argc, char **argv){
|
|||
break;
|
||||
case 'w': /* warning threshold */
|
||||
warning_value=strtoul(optarg,NULL,10);
|
||||
check_warning_value=TRUE;
|
||||
check_warning_value=true;
|
||||
break;
|
||||
case 'c': /* critical threshold */
|
||||
critical_value=strtoul(optarg,NULL,10);
|
||||
check_critical_value=TRUE;
|
||||
check_critical_value=true;
|
||||
break;
|
||||
case 'd': /* Display select for services */
|
||||
if (!strcmp(optarg,"SHOWALL"))
|
||||
show_all = TRUE;
|
||||
show_all = true;
|
||||
break;
|
||||
case 'u':
|
||||
socket_timeout_state=STATE_UNKNOWN;
|
||||
|
@ -646,7 +646,7 @@ void fetch_data (const char *address, int port, const char *sendb) {
|
|||
die (STATE_UNKNOWN, "NSClient - %s\n",recv_buffer);
|
||||
}
|
||||
|
||||
int strtoularray(unsigned long *array, char *string, const char *delim) {
|
||||
bool strtoularray(unsigned long *array, char *string, const char *delim) {
|
||||
/* split a <delim> delimited string into a long array */
|
||||
int idx=0;
|
||||
char *t1;
|
||||
|
@ -660,9 +660,9 @@ int strtoularray(unsigned long *array, char *string, const char *delim) {
|
|||
array[idx]=strtoul(t1,NULL,10);
|
||||
idx++;
|
||||
} else
|
||||
return FALSE;
|
||||
return false;
|
||||
}
|
||||
return TRUE;
|
||||
return true;
|
||||
}
|
||||
|
||||
void preparelist(char *string) {
|
||||
|
|
|
@ -40,10 +40,10 @@ const char *email = "devel@monitoring-plugins.org";
|
|||
|
||||
static char *server_address=NULL;
|
||||
static int verbose=0;
|
||||
static short do_offset=0;
|
||||
static bool do_offset = false;
|
||||
static char *owarn="60";
|
||||
static char *ocrit="120";
|
||||
static short do_jitter=0;
|
||||
static bool do_jitter = false;
|
||||
static char *jwarn="5000";
|
||||
static char *jcrit="10000";
|
||||
|
||||
|
@ -513,7 +513,8 @@ setup_control_request(ntp_control_message *p, uint8_t opcode, uint16_t seq){
|
|||
|
||||
/* XXX handle responses with the error bit set */
|
||||
double jitter_request(int *status){
|
||||
int conn=-1, i, npeers=0, num_candidates=0, syncsource_found=0;
|
||||
int conn=-1, i, npeers=0, num_candidates=0;
|
||||
bool syncsource_found = false;
|
||||
int run=0, min_peer_sel=PEER_INCLUDED, num_selected=0, num_valid=0;
|
||||
int peers_size=0, peer_offset=0;
|
||||
ntp_assoc_status_pair *peers=NULL;
|
||||
|
@ -570,7 +571,7 @@ double jitter_request(int *status){
|
|||
if (PEER_SEL(peers[i].status) >= PEER_INCLUDED){
|
||||
num_candidates++;
|
||||
if(PEER_SEL(peers[i].status) >= PEER_SYNCSOURCE){
|
||||
syncsource_found=1;
|
||||
syncsource_found = true;
|
||||
min_peer_sel=PEER_SYNCSOURCE;
|
||||
}
|
||||
}
|
||||
|
@ -699,23 +700,23 @@ int process_arguments(int argc, char **argv){
|
|||
verbose++;
|
||||
break;
|
||||
case 'w':
|
||||
do_offset=1;
|
||||
do_offset = true;
|
||||
owarn = optarg;
|
||||
break;
|
||||
case 'c':
|
||||
do_offset=1;
|
||||
do_offset = true;
|
||||
ocrit = optarg;
|
||||
break;
|
||||
case 'j':
|
||||
do_jitter=1;
|
||||
do_jitter = true;
|
||||
jwarn = optarg;
|
||||
break;
|
||||
case 'k':
|
||||
do_jitter=1;
|
||||
do_jitter = true;
|
||||
jcrit = optarg;
|
||||
break;
|
||||
case 'H':
|
||||
if(is_host(optarg) == FALSE)
|
||||
if(!is_host(optarg))
|
||||
usage2(_("Invalid hostname/address"), optarg);
|
||||
server_address = strdup(optarg);
|
||||
break;
|
||||
|
@ -749,9 +750,9 @@ int process_arguments(int argc, char **argv){
|
|||
char *perfd_offset (double offset)
|
||||
{
|
||||
return fperfdata ("offset", offset, "s",
|
||||
TRUE, offset_thresholds->warning->end,
|
||||
TRUE, offset_thresholds->critical->end,
|
||||
FALSE, 0, FALSE, 0);
|
||||
true, offset_thresholds->warning->end,
|
||||
true, offset_thresholds->critical->end,
|
||||
false, 0, false, 0);
|
||||
}
|
||||
|
||||
char *perfd_jitter (double jitter)
|
||||
|
@ -759,7 +760,7 @@ char *perfd_jitter (double jitter)
|
|||
return fperfdata ("jitter", jitter, "s",
|
||||
do_jitter, jitter_thresholds->warning->end,
|
||||
do_jitter, jitter_thresholds->critical->end,
|
||||
TRUE, 0, FALSE, 0);
|
||||
true, 0, false, 0);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]){
|
||||
|
|
|
@ -46,21 +46,20 @@ const char *email = "devel@monitoring-plugins.org";
|
|||
static char *server_address=NULL;
|
||||
static int port=123;
|
||||
static int verbose=0;
|
||||
static int quiet=0;
|
||||
static short do_offset=0;
|
||||
static bool quiet = false;
|
||||
static char *owarn="60";
|
||||
static char *ocrit="120";
|
||||
static short do_stratum=0;
|
||||
static bool do_stratum = false;
|
||||
static char *swarn="-1:16";
|
||||
static char *scrit="-1:16";
|
||||
static short do_jitter=0;
|
||||
static bool do_jitter = false;
|
||||
static char *jwarn="-1:5000";
|
||||
static char *jcrit="-1:10000";
|
||||
static short do_truechimers=0;
|
||||
static bool do_truechimers = false;
|
||||
static char *twarn="0:";
|
||||
static char *tcrit="0:";
|
||||
static int syncsource_found=0;
|
||||
static int li_alarm=0;
|
||||
static bool syncsource_found = false;
|
||||
static bool li_alarm = false;
|
||||
|
||||
int process_arguments (int, char **);
|
||||
thresholds *offset_thresholds = NULL;
|
||||
|
@ -254,7 +253,7 @@ int ntp_request(double *offset, int *offset_result, double *jitter, int *stratum
|
|||
die(STATE_CRITICAL, "NTP CRITICAL: Invalid packet received from NTP server\n");
|
||||
} while (!(req.op&OP_READSTAT && ntohs(req.seq) == 1));
|
||||
|
||||
if (LI(req.flags) == LI_ALARM) li_alarm = 1;
|
||||
if (LI(req.flags) == LI_ALARM) li_alarm = true;
|
||||
/* Each peer identifier is 4 bytes in the data section, which
|
||||
* we represent as a ntp_assoc_status_pair datatype.
|
||||
*/
|
||||
|
@ -276,7 +275,7 @@ int ntp_request(double *offset, int *offset_result, double *jitter, int *stratum
|
|||
if(PEER_SEL(peers[i].status) >= PEER_INCLUDED){
|
||||
num_candidates++;
|
||||
if(PEER_SEL(peers[i].status) >= PEER_SYNCSOURCE){
|
||||
syncsource_found=1;
|
||||
syncsource_found = true;
|
||||
min_peer_sel=PEER_SYNCSOURCE;
|
||||
}
|
||||
}
|
||||
|
@ -440,7 +439,7 @@ int process_arguments(int argc, char **argv){
|
|||
if (argc < 2)
|
||||
usage ("\n");
|
||||
|
||||
while (1) {
|
||||
while (true) {
|
||||
c = getopt_long (argc, argv, "Vhv46qw:c:W:C:j:k:m:n:t:H:p:", longopts, &option);
|
||||
if (c == -1 || c == EOF || c == 1)
|
||||
break;
|
||||
|
@ -458,42 +457,40 @@ int process_arguments(int argc, char **argv){
|
|||
verbose++;
|
||||
break;
|
||||
case 'q':
|
||||
quiet = 1;
|
||||
quiet = true;
|
||||
break;
|
||||
case 'w':
|
||||
do_offset=1;
|
||||
owarn = optarg;
|
||||
break;
|
||||
case 'c':
|
||||
do_offset=1;
|
||||
ocrit = optarg;
|
||||
break;
|
||||
case 'W':
|
||||
do_stratum=1;
|
||||
do_stratum = true;
|
||||
swarn = optarg;
|
||||
break;
|
||||
case 'C':
|
||||
do_stratum=1;
|
||||
do_stratum = true;
|
||||
scrit = optarg;
|
||||
break;
|
||||
case 'j':
|
||||
do_jitter=1;
|
||||
do_jitter = true;
|
||||
jwarn = optarg;
|
||||
break;
|
||||
case 'k':
|
||||
do_jitter=1;
|
||||
do_jitter = true;
|
||||
jcrit = optarg;
|
||||
break;
|
||||
case 'm':
|
||||
do_truechimers=1;
|
||||
do_truechimers = true;
|
||||
twarn = optarg;
|
||||
break;
|
||||
case 'n':
|
||||
do_truechimers=1;
|
||||
do_truechimers = true;
|
||||
tcrit = optarg;
|
||||
break;
|
||||
case 'H':
|
||||
if(is_host(optarg) == FALSE)
|
||||
if(!is_host(optarg))
|
||||
usage2(_("Invalid hostname/address"), optarg);
|
||||
server_address = strdup(optarg);
|
||||
break;
|
||||
|
@ -530,9 +527,9 @@ int process_arguments(int argc, char **argv){
|
|||
char *perfd_offset (double offset)
|
||||
{
|
||||
return fperfdata ("offset", offset, "s",
|
||||
TRUE, offset_thresholds->warning->end,
|
||||
TRUE, offset_thresholds->critical->end,
|
||||
FALSE, 0, FALSE, 0);
|
||||
true, offset_thresholds->warning->end,
|
||||
true, offset_thresholds->critical->end,
|
||||
false, 0, false, 0);
|
||||
}
|
||||
|
||||
char *perfd_jitter (double jitter)
|
||||
|
@ -540,7 +537,7 @@ char *perfd_jitter (double jitter)
|
|||
return fperfdata ("jitter", jitter, "",
|
||||
do_jitter, jitter_thresholds->warning->end,
|
||||
do_jitter, jitter_thresholds->critical->end,
|
||||
TRUE, 0, FALSE, 0);
|
||||
true, 0, false, 0);
|
||||
}
|
||||
|
||||
char *perfd_stratum (int stratum)
|
||||
|
@ -548,7 +545,7 @@ char *perfd_stratum (int stratum)
|
|||
return perfdata ("stratum", stratum, "",
|
||||
do_stratum, (int)stratum_thresholds->warning->end,
|
||||
do_stratum, (int)stratum_thresholds->critical->end,
|
||||
TRUE, 0, TRUE, 16);
|
||||
true, 0, true, 16);
|
||||
}
|
||||
|
||||
char *perfd_truechimers (int num_truechimers)
|
||||
|
@ -556,11 +553,11 @@ char *perfd_truechimers (int num_truechimers)
|
|||
return perfdata ("truechimers", num_truechimers, "",
|
||||
do_truechimers, (int)truechimer_thresholds->warning->end,
|
||||
do_truechimers, (int)truechimer_thresholds->critical->end,
|
||||
TRUE, 0, FALSE, 0);
|
||||
true, 0, false, 0);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]){
|
||||
int result, offset_result, stratum, num_truechimers, oresult, jresult, sresult, tresult;
|
||||
int result, offset_result, stratum, num_truechimers;
|
||||
double offset=0, jitter=0;
|
||||
char *result_line, *perfdata_line;
|
||||
|
||||
|
@ -590,25 +587,35 @@ int main(int argc, char *argv[]){
|
|||
|
||||
if(offset_result == STATE_UNKNOWN) {
|
||||
/* if there's no sync peer (this overrides ntp_request output): */
|
||||
result = (quiet == 1 ? STATE_UNKNOWN : STATE_CRITICAL);
|
||||
result = (quiet ? STATE_UNKNOWN : STATE_CRITICAL);
|
||||
} else {
|
||||
/* Be quiet if there's no candidates either */
|
||||
if (quiet == 1 && result == STATE_WARNING)
|
||||
if (quiet && result == STATE_WARNING)
|
||||
result = STATE_UNKNOWN;
|
||||
result = max_state_alt(result, get_status(fabs(offset), offset_thresholds));
|
||||
}
|
||||
oresult = result;
|
||||
|
||||
int oresult = result;
|
||||
|
||||
|
||||
int tresult = STATE_UNKNOWN;
|
||||
|
||||
if(do_truechimers) {
|
||||
tresult = get_status(num_truechimers, truechimer_thresholds);
|
||||
result = max_state_alt(result, tresult);
|
||||
}
|
||||
|
||||
|
||||
int sresult = STATE_UNKNOWN;
|
||||
|
||||
if(do_stratum) {
|
||||
sresult = get_status(stratum, stratum_thresholds);
|
||||
result = max_state_alt(result, sresult);
|
||||
}
|
||||
|
||||
|
||||
int jresult = STATE_UNKNOWN;
|
||||
|
||||
if(do_jitter) {
|
||||
jresult = get_status(jitter, jitter_thresholds);
|
||||
result = max_state_alt(result, jresult);
|
||||
|
|
|
@ -45,7 +45,7 @@ const char *email = "devel@monitoring-plugins.org";
|
|||
static char *server_address=NULL;
|
||||
static char *port="123";
|
||||
static int verbose=0;
|
||||
static int quiet=0;
|
||||
static bool quiet = false;
|
||||
static char *owarn="60";
|
||||
static char *ocrit="120";
|
||||
static int time_offset=0;
|
||||
|
@ -485,7 +485,7 @@ int process_arguments(int argc, char **argv){
|
|||
verbose++;
|
||||
break;
|
||||
case 'q':
|
||||
quiet = 1;
|
||||
quiet = true;
|
||||
break;
|
||||
case 'w':
|
||||
owarn = optarg;
|
||||
|
@ -494,7 +494,7 @@ int process_arguments(int argc, char **argv){
|
|||
ocrit = optarg;
|
||||
break;
|
||||
case 'H':
|
||||
if(is_host(optarg) == FALSE)
|
||||
if(!is_host(optarg))
|
||||
usage2(_("Invalid hostname/address"), optarg);
|
||||
server_address = strdup(optarg);
|
||||
break;
|
||||
|
@ -531,12 +531,11 @@ int process_arguments(int argc, char **argv){
|
|||
return 0;
|
||||
}
|
||||
|
||||
char *perfd_offset (double offset)
|
||||
{
|
||||
char *perfd_offset (double offset) {
|
||||
return fperfdata ("offset", offset, "s",
|
||||
TRUE, offset_thresholds->warning->end,
|
||||
TRUE, offset_thresholds->critical->end,
|
||||
FALSE, 0, FALSE, 0);
|
||||
true, offset_thresholds->warning->end,
|
||||
true, offset_thresholds->critical->end,
|
||||
false, 0, false, 0);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]){
|
||||
|
@ -566,7 +565,7 @@ int main(int argc, char *argv[]){
|
|||
|
||||
offset = offset_request(server_address, &offset_result);
|
||||
if (offset_result == STATE_UNKNOWN) {
|
||||
result = (quiet == 1 ? STATE_UNKNOWN : STATE_CRITICAL);
|
||||
result = ( (!quiet) ? STATE_UNKNOWN : STATE_CRITICAL);
|
||||
} else {
|
||||
result = get_status(fabs(offset), offset_thresholds);
|
||||
}
|
||||
|
|
|
@ -46,6 +46,7 @@ enum checkvar {
|
|||
VPF, /* check % free space on volume */
|
||||
VMF, /* check MB free space on volume */
|
||||
VMU, /* check MB used space on volume */
|
||||
VPU, /* check % used space on volume */
|
||||
VMP, /* check MB purgeable space on volume */
|
||||
VKF, /* check KB free space on volume */
|
||||
LTCH, /* check long-term cache hit percentage */
|
||||
|
@ -104,9 +105,9 @@ char *nss7_name=NULL;
|
|||
int server_port=PORT;
|
||||
unsigned long warning_value=0L;
|
||||
unsigned long critical_value=0L;
|
||||
int check_warning_value=FALSE;
|
||||
int check_critical_value=FALSE;
|
||||
int check_netware_version=FALSE;
|
||||
bool check_warning_value = false;
|
||||
bool check_critical_value = false;
|
||||
bool check_netware_version = false;
|
||||
enum checkvar vars_to_check = NONE;
|
||||
int sap_number=-1;
|
||||
|
||||
|
@ -146,6 +147,8 @@ main(int argc, char **argv) {
|
|||
unsigned long nss6_value=0L;
|
||||
unsigned long nss7_value=0L;
|
||||
unsigned long total_disk_space=0L;
|
||||
unsigned long used_disk_space=0L;
|
||||
unsigned long percent_used_disk_space=0L;
|
||||
unsigned long purgeable_disk_space=0L;
|
||||
unsigned long non_purgeable_disk_space=0L;
|
||||
unsigned long percent_free_space=0;
|
||||
|
@ -182,7 +185,7 @@ main(int argc, char **argv) {
|
|||
my_tcp_connect (server_address, server_port, &sd);
|
||||
|
||||
/* get OS version string */
|
||||
if (check_netware_version==TRUE) {
|
||||
if (check_netware_version) {
|
||||
send_buffer = strdup ("S19\r\n");
|
||||
result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
|
||||
if (result!=STATE_OK)
|
||||
|
@ -231,9 +234,9 @@ main(int argc, char **argv) {
|
|||
recv_buffer[strlen(recv_buffer)-1]=0;
|
||||
sprintf(uptime,_("Up %s,"),recv_buffer);
|
||||
|
||||
if (check_critical_value==TRUE && utilization >= critical_value)
|
||||
if (check_critical_value && utilization >= critical_value)
|
||||
result=STATE_CRITICAL;
|
||||
else if (check_warning_value==TRUE && utilization >= warning_value)
|
||||
else if (check_warning_value && utilization >= warning_value)
|
||||
result=STATE_WARNING;
|
||||
|
||||
xasprintf (&output_message,
|
||||
|
@ -259,9 +262,9 @@ main(int argc, char **argv) {
|
|||
return result;
|
||||
current_connections=strtoul(recv_buffer,NULL,10);
|
||||
|
||||
if (check_critical_value==TRUE && current_connections >= critical_value)
|
||||
if (check_critical_value && current_connections >= critical_value)
|
||||
result=STATE_CRITICAL;
|
||||
else if (check_warning_value==TRUE && current_connections >= warning_value)
|
||||
else if (check_warning_value && current_connections >= warning_value)
|
||||
result=STATE_WARNING;
|
||||
|
||||
xasprintf (&output_message,
|
||||
|
@ -284,9 +287,9 @@ main(int argc, char **argv) {
|
|||
return result;
|
||||
cache_hits=atoi(recv_buffer);
|
||||
|
||||
if (check_critical_value==TRUE && cache_hits <= critical_value)
|
||||
if (check_critical_value && cache_hits <= critical_value)
|
||||
result=STATE_CRITICAL;
|
||||
else if (check_warning_value==TRUE && cache_hits <= warning_value)
|
||||
else if (check_warning_value && cache_hits <= warning_value)
|
||||
result=STATE_WARNING;
|
||||
|
||||
xasprintf (&output_message,
|
||||
|
@ -306,9 +309,9 @@ main(int argc, char **argv) {
|
|||
return result;
|
||||
cache_buffers=strtoul(recv_buffer,NULL,10);
|
||||
|
||||
if (check_critical_value==TRUE && cache_buffers <= critical_value)
|
||||
if (check_critical_value && cache_buffers <= critical_value)
|
||||
result=STATE_CRITICAL;
|
||||
else if (check_warning_value==TRUE && cache_buffers <= warning_value)
|
||||
else if (check_warning_value && cache_buffers <= warning_value)
|
||||
result=STATE_WARNING;
|
||||
|
||||
xasprintf (&output_message,
|
||||
|
@ -331,9 +334,9 @@ main(int argc, char **argv) {
|
|||
return result;
|
||||
cache_buffers=strtoul(recv_buffer,NULL,10);
|
||||
|
||||
if (check_critical_value==TRUE && cache_buffers >= critical_value)
|
||||
if (check_critical_value && cache_buffers >= critical_value)
|
||||
result=STATE_CRITICAL;
|
||||
else if (check_warning_value==TRUE && cache_buffers >= warning_value)
|
||||
else if (check_warning_value && cache_buffers >= warning_value)
|
||||
result=STATE_WARNING;
|
||||
|
||||
xasprintf (&output_message,
|
||||
|
@ -356,9 +359,9 @@ main(int argc, char **argv) {
|
|||
return result;
|
||||
lru_time=strtoul(recv_buffer,NULL,10);
|
||||
|
||||
if (check_critical_value==TRUE && lru_time <= critical_value)
|
||||
if (check_critical_value && lru_time <= critical_value)
|
||||
result=STATE_CRITICAL;
|
||||
else if (check_warning_value==TRUE && lru_time <= warning_value)
|
||||
else if (check_warning_value && lru_time <= warning_value)
|
||||
result=STATE_WARNING;
|
||||
|
||||
xasprintf (&output_message,
|
||||
|
@ -383,9 +386,9 @@ main(int argc, char **argv) {
|
|||
result=STATE_CRITICAL;
|
||||
} else {
|
||||
free_disk_space=strtoul(recv_buffer,NULL,10);
|
||||
if (check_critical_value==TRUE && free_disk_space <= critical_value)
|
||||
if (check_critical_value && free_disk_space <= critical_value)
|
||||
result=STATE_CRITICAL;
|
||||
else if (check_warning_value==TRUE && free_disk_space <= warning_value)
|
||||
else if (check_warning_value && free_disk_space <= warning_value)
|
||||
result=STATE_WARNING;
|
||||
xasprintf (&output_message,
|
||||
_("%s%lu KB free on volume %s|KBFree%s=%lu;%lu;%lu;;"),
|
||||
|
@ -411,9 +414,9 @@ main(int argc, char **argv) {
|
|||
result=STATE_CRITICAL;
|
||||
} else {
|
||||
free_disk_space=strtoul(recv_buffer,NULL,10);
|
||||
if (check_critical_value==TRUE && free_disk_space <= critical_value)
|
||||
if (check_critical_value && free_disk_space <= critical_value)
|
||||
result=STATE_CRITICAL;
|
||||
else if (check_warning_value==TRUE && free_disk_space <= warning_value)
|
||||
else if (check_warning_value && free_disk_space <= warning_value)
|
||||
result=STATE_WARNING;
|
||||
xasprintf (&output_message,
|
||||
_("%s%lu MB free on volume %s|MBFree%s=%lu;%lu;%lu;;"),
|
||||
|
@ -438,9 +441,9 @@ main(int argc, char **argv) {
|
|||
result=STATE_CRITICAL;
|
||||
} else {
|
||||
free_disk_space=strtoul(recv_buffer,NULL,10);
|
||||
if (check_critical_value==TRUE && free_disk_space <= critical_value)
|
||||
if (check_critical_value && free_disk_space <= critical_value)
|
||||
result=STATE_CRITICAL;
|
||||
else if (check_warning_value==TRUE && free_disk_space <= warning_value)
|
||||
else if (check_warning_value && free_disk_space <= warning_value)
|
||||
result=STATE_WARNING;
|
||||
xasprintf (&output_message,
|
||||
_("%s%lu MB used on volume %s|MBUsed%s=%lu;%lu;%lu;;"),
|
||||
|
@ -452,7 +455,50 @@ main(int argc, char **argv) {
|
|||
warning_value,
|
||||
critical_value);
|
||||
}
|
||||
/* check % used space on volume */
|
||||
} else if (vars_to_check==VPU) {
|
||||
close(sd);
|
||||
my_tcp_connect (server_address, server_port, &sd);
|
||||
|
||||
asprintf (&send_buffer,"VMU%s\r\n",volume_name);
|
||||
result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
|
||||
|
||||
if (result!=STATE_OK)
|
||||
return result;
|
||||
|
||||
if (!strcmp(recv_buffer,"-1\n")) {
|
||||
asprintf (&output_message,_("CRITICAL - Volume '%s' does not exist!"),volume_name);
|
||||
result=STATE_CRITICAL;
|
||||
|
||||
} else {
|
||||
used_disk_space=strtoul(recv_buffer,NULL,10);
|
||||
close(sd);
|
||||
my_tcp_connect (server_address, server_port, &sd);
|
||||
/* get total volume in MB */
|
||||
asprintf (&send_buffer,"VMS%s\r\n",volume_name);
|
||||
result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
|
||||
if (result!=STATE_OK)
|
||||
return result;
|
||||
total_disk_space=strtoul(recv_buffer,NULL,10);
|
||||
/* calculate percent used on volume */
|
||||
percent_used_disk_space=(unsigned long)(((double)used_disk_space/(double)total_disk_space)*100.0);
|
||||
|
||||
if (check_critical_value && percent_used_disk_space >= critical_value)
|
||||
result=STATE_CRITICAL;
|
||||
else if (check_warning_value && percent_used_disk_space >= warning_value)
|
||||
result=STATE_WARNING;
|
||||
|
||||
asprintf (&output_message,_("%lu MB (%lu%%) used on volume %s - total %lu MB|Used space in percent on %s=%lu;%lu;%lu;0;100"),
|
||||
used_disk_space,
|
||||
percent_used_disk_space,
|
||||
volume_name,
|
||||
total_disk_space,
|
||||
volume_name,
|
||||
percent_used_disk_space,
|
||||
warning_value,
|
||||
critical_value
|
||||
);
|
||||
}
|
||||
|
||||
/* check % free space on volume */
|
||||
} else if (vars_to_check==VPF) {
|
||||
|
@ -485,9 +531,9 @@ main(int argc, char **argv) {
|
|||
|
||||
percent_free_space=(unsigned long)(((double)free_disk_space/(double)total_disk_space)*100.0);
|
||||
|
||||
if (check_critical_value==TRUE && percent_free_space <= critical_value)
|
||||
if (check_critical_value && percent_free_space <= critical_value)
|
||||
result=STATE_CRITICAL;
|
||||
else if (check_warning_value==TRUE && percent_free_space <= warning_value)
|
||||
else if (check_warning_value && percent_free_space <= warning_value)
|
||||
result=STATE_WARNING;
|
||||
free_disk_space/=1024;
|
||||
total_disk_space/=1024;
|
||||
|
@ -596,14 +642,14 @@ main(int argc, char **argv) {
|
|||
percent_used_packet_receive_buffers=(unsigned long)(((double)used_packet_receive_buffers/(double)max_packet_receive_buffers)*100.0);
|
||||
|
||||
if (vars_to_check==UPRB) {
|
||||
if (check_critical_value==TRUE && used_packet_receive_buffers >= critical_value)
|
||||
if (check_critical_value && used_packet_receive_buffers >= critical_value)
|
||||
result=STATE_CRITICAL;
|
||||
else if (check_warning_value==TRUE && used_packet_receive_buffers >= warning_value)
|
||||
else if (check_warning_value && used_packet_receive_buffers >= warning_value)
|
||||
result=STATE_WARNING;
|
||||
} else {
|
||||
if (check_critical_value==TRUE && percent_used_packet_receive_buffers >= critical_value)
|
||||
if (check_critical_value && percent_used_packet_receive_buffers >= critical_value)
|
||||
result=STATE_CRITICAL;
|
||||
else if (check_warning_value==TRUE && percent_used_packet_receive_buffers >= warning_value)
|
||||
else if (check_warning_value && percent_used_packet_receive_buffers >= warning_value)
|
||||
result=STATE_WARNING;
|
||||
}
|
||||
|
||||
|
@ -625,9 +671,9 @@ main(int argc, char **argv) {
|
|||
|
||||
sap_entries=atoi(recv_buffer);
|
||||
|
||||
if (check_critical_value==TRUE && sap_entries >= critical_value)
|
||||
if (check_critical_value && sap_entries >= critical_value)
|
||||
result=STATE_CRITICAL;
|
||||
else if (check_warning_value==TRUE && sap_entries >= warning_value)
|
||||
else if (check_warning_value && sap_entries >= warning_value)
|
||||
result=STATE_WARNING;
|
||||
|
||||
if (sap_number==-1)
|
||||
|
@ -651,9 +697,9 @@ main(int argc, char **argv) {
|
|||
result=STATE_CRITICAL;
|
||||
} else {
|
||||
purgeable_disk_space=strtoul(recv_buffer,NULL,10);
|
||||
if (check_critical_value==TRUE && purgeable_disk_space >= critical_value)
|
||||
if (check_critical_value && purgeable_disk_space >= critical_value)
|
||||
result=STATE_CRITICAL;
|
||||
else if (check_warning_value==TRUE && purgeable_disk_space >= warning_value)
|
||||
else if (check_warning_value && purgeable_disk_space >= warning_value)
|
||||
result=STATE_WARNING;
|
||||
xasprintf (&output_message,_("%s%lu KB purgeable on volume %s|Purge%s=%lu;%lu;%lu;;"),
|
||||
(result==STATE_OK)?"":_("Only "),
|
||||
|
@ -677,9 +723,9 @@ main(int argc, char **argv) {
|
|||
result=STATE_CRITICAL;
|
||||
} else {
|
||||
purgeable_disk_space=strtoul(recv_buffer,NULL,10);
|
||||
if (check_critical_value==TRUE && purgeable_disk_space >= critical_value)
|
||||
if (check_critical_value && purgeable_disk_space >= critical_value)
|
||||
result=STATE_CRITICAL;
|
||||
else if (check_warning_value==TRUE && purgeable_disk_space >= warning_value)
|
||||
else if (check_warning_value && purgeable_disk_space >= warning_value)
|
||||
result=STATE_WARNING;
|
||||
xasprintf (&output_message,_("%s%lu MB purgeable on volume %s|Purge%s=%lu;%lu;%lu;;"),
|
||||
(result==STATE_OK)?"":_("Only "),
|
||||
|
@ -722,9 +768,9 @@ main(int argc, char **argv) {
|
|||
|
||||
percent_purgeable_space=(unsigned long)(((double)purgeable_disk_space/(double)total_disk_space)*100.0);
|
||||
|
||||
if (check_critical_value==TRUE && percent_purgeable_space >= critical_value)
|
||||
if (check_critical_value && percent_purgeable_space >= critical_value)
|
||||
result=STATE_CRITICAL;
|
||||
else if (check_warning_value==TRUE && percent_purgeable_space >= warning_value)
|
||||
else if (check_warning_value && percent_purgeable_space >= warning_value)
|
||||
result=STATE_WARNING;
|
||||
purgeable_disk_space/=1024;
|
||||
xasprintf (&output_message,_("%lu MB (%lu%%) purgeable on volume %s|Purgeable%s=%lu;%lu;%lu;0;100"),
|
||||
|
@ -754,9 +800,9 @@ main(int argc, char **argv) {
|
|||
result=STATE_CRITICAL;
|
||||
} else {
|
||||
non_purgeable_disk_space=strtoul(recv_buffer,NULL,10);
|
||||
if (check_critical_value==TRUE && non_purgeable_disk_space >= critical_value)
|
||||
if (check_critical_value && non_purgeable_disk_space >= critical_value)
|
||||
result=STATE_CRITICAL;
|
||||
else if (check_warning_value==TRUE && non_purgeable_disk_space >= warning_value)
|
||||
else if (check_warning_value && non_purgeable_disk_space >= warning_value)
|
||||
result=STATE_WARNING;
|
||||
xasprintf (&output_message,_("%s%lu KB not yet purgeable on volume %s"),(result==STATE_OK)?"":_("Only "),non_purgeable_disk_space,volume_name);
|
||||
}
|
||||
|
@ -792,9 +838,9 @@ main(int argc, char **argv) {
|
|||
|
||||
percent_non_purgeable_space=(unsigned long)(((double)non_purgeable_disk_space/(double)total_disk_space)*100.0);
|
||||
|
||||
if (check_critical_value==TRUE && percent_non_purgeable_space >= critical_value)
|
||||
if (check_critical_value && percent_non_purgeable_space >= critical_value)
|
||||
result=STATE_CRITICAL;
|
||||
else if (check_warning_value==TRUE && percent_non_purgeable_space >= warning_value)
|
||||
else if (check_warning_value && percent_non_purgeable_space >= warning_value)
|
||||
result=STATE_WARNING;
|
||||
purgeable_disk_space/=1024;
|
||||
xasprintf (&output_message,_("%lu MB (%lu%%) not yet purgeable on volume %s"),non_purgeable_disk_space,percent_non_purgeable_space,volume_name);
|
||||
|
@ -813,9 +859,9 @@ main(int argc, char **argv) {
|
|||
|
||||
open_files=atoi(recv_buffer);
|
||||
|
||||
if (check_critical_value==TRUE && open_files >= critical_value)
|
||||
if (check_critical_value && open_files >= critical_value)
|
||||
result=STATE_CRITICAL;
|
||||
else if (check_warning_value==TRUE && open_files >= warning_value)
|
||||
else if (check_warning_value && open_files >= warning_value)
|
||||
result=STATE_WARNING;
|
||||
|
||||
xasprintf (&output_message,_("%lu open files|Openfiles=%lu;%lu;%lu;0,0"),
|
||||
|
@ -838,9 +884,9 @@ main(int argc, char **argv) {
|
|||
|
||||
abended_threads=atoi(recv_buffer);
|
||||
|
||||
if (check_critical_value==TRUE && abended_threads >= critical_value)
|
||||
if (check_critical_value && abended_threads >= critical_value)
|
||||
result=STATE_CRITICAL;
|
||||
else if (check_warning_value==TRUE && abended_threads >= warning_value)
|
||||
else if (check_warning_value && abended_threads >= warning_value)
|
||||
result=STATE_WARNING;
|
||||
|
||||
xasprintf (&output_message,_("%lu abended threads|Abends=%lu;%lu;%lu;;"),
|
||||
|
@ -872,9 +918,9 @@ main(int argc, char **argv) {
|
|||
|
||||
current_service_processes=atoi(recv_buffer);
|
||||
|
||||
if (check_critical_value==TRUE && current_service_processes >= critical_value)
|
||||
if (check_critical_value && current_service_processes >= critical_value)
|
||||
result=STATE_CRITICAL;
|
||||
else if (check_warning_value==TRUE && current_service_processes >= warning_value)
|
||||
else if (check_warning_value && current_service_processes >= warning_value)
|
||||
result=STATE_WARNING;
|
||||
|
||||
xasprintf (&output_message,
|
||||
|
@ -923,9 +969,9 @@ main(int argc, char **argv) {
|
|||
return result;
|
||||
lru_time=strtoul(recv_buffer,NULL,10);
|
||||
|
||||
if (check_critical_value==TRUE && lru_time <= critical_value)
|
||||
if (check_critical_value && lru_time <= critical_value)
|
||||
result=STATE_CRITICAL;
|
||||
else if (check_warning_value==TRUE && lru_time <= warning_value)
|
||||
else if (check_warning_value && lru_time <= warning_value)
|
||||
result=STATE_WARNING;
|
||||
xasprintf (&output_message,_("LRU sitting time = %lu seconds"),lru_time);
|
||||
|
||||
|
@ -942,9 +988,9 @@ main(int argc, char **argv) {
|
|||
return result;
|
||||
dirty_cache_buffers=atoi(recv_buffer);
|
||||
|
||||
if (check_critical_value==TRUE && dirty_cache_buffers <= critical_value)
|
||||
if (check_critical_value && dirty_cache_buffers <= critical_value)
|
||||
result=STATE_CRITICAL;
|
||||
else if (check_warning_value==TRUE && dirty_cache_buffers <= warning_value)
|
||||
else if (check_warning_value && dirty_cache_buffers <= warning_value)
|
||||
result=STATE_WARNING;
|
||||
xasprintf (&output_message,_("Dirty cache buffers = %lu%% of the total|DCB=%lu;%lu;%lu;0;100"),
|
||||
dirty_cache_buffers,
|
||||
|
@ -964,9 +1010,9 @@ main(int argc, char **argv) {
|
|||
return result;
|
||||
total_cache_buffers=atoi(recv_buffer);
|
||||
|
||||
if (check_critical_value==TRUE && total_cache_buffers <= critical_value)
|
||||
if (check_critical_value && total_cache_buffers <= critical_value)
|
||||
result=STATE_CRITICAL;
|
||||
else if (check_warning_value==TRUE && total_cache_buffers <= warning_value)
|
||||
else if (check_warning_value && total_cache_buffers <= warning_value)
|
||||
result=STATE_WARNING;
|
||||
xasprintf (&output_message,_("Total cache buffers = %lu%% of the original|TCB=%lu;%lu;%lu;0;100"),
|
||||
total_cache_buffers,
|
||||
|
@ -1034,9 +1080,9 @@ main(int argc, char **argv) {
|
|||
result=STATE_CRITICAL;
|
||||
} else {
|
||||
nrmp_value=strtoul(recv_buffer,NULL,10);
|
||||
if (check_critical_value==TRUE && nrmp_value <= critical_value)
|
||||
if (check_critical_value && nrmp_value <= critical_value)
|
||||
result=STATE_CRITICAL;
|
||||
else if (check_warning_value==TRUE && nrmp_value <= warning_value)
|
||||
else if (check_warning_value && nrmp_value <= warning_value)
|
||||
result=STATE_WARNING;
|
||||
xasprintf (&output_message,
|
||||
_("%s is %lu|%s=%lu;%lu;%lu;;"),
|
||||
|
@ -1060,9 +1106,9 @@ main(int argc, char **argv) {
|
|||
result=STATE_CRITICAL;
|
||||
} else {
|
||||
nrmm_value=strtoul(recv_buffer,NULL,10);
|
||||
if (check_critical_value==TRUE && nrmm_value <= critical_value)
|
||||
if (check_critical_value && nrmm_value <= critical_value)
|
||||
result=STATE_CRITICAL;
|
||||
else if (check_warning_value==TRUE && nrmm_value <= warning_value)
|
||||
else if (check_warning_value && nrmm_value <= warning_value)
|
||||
result=STATE_WARNING;
|
||||
xasprintf (&output_message,
|
||||
_("%s is %lu|%s=%lu;%lu;%lu;;"),
|
||||
|
@ -1086,9 +1132,9 @@ main(int argc, char **argv) {
|
|||
result=STATE_CRITICAL;
|
||||
} else {
|
||||
nrms_value=strtoul(recv_buffer,NULL,10);
|
||||
if (check_critical_value==TRUE && nrms_value >= critical_value)
|
||||
if (check_critical_value && nrms_value >= critical_value)
|
||||
result=STATE_CRITICAL;
|
||||
else if (check_warning_value==TRUE && nrms_value >= warning_value)
|
||||
else if (check_warning_value && nrms_value >= warning_value)
|
||||
result=STATE_WARNING;
|
||||
xasprintf (&output_message,
|
||||
_("%s is %lu|%s=%lu;%lu;%lu;;"),
|
||||
|
@ -1112,9 +1158,9 @@ main(int argc, char **argv) {
|
|||
result=STATE_CRITICAL;
|
||||
} else {
|
||||
nss1_value=strtoul(recv_buffer,NULL,10);
|
||||
if (check_critical_value==TRUE && nss1_value >= critical_value)
|
||||
if (check_critical_value && nss1_value >= critical_value)
|
||||
result=STATE_CRITICAL;
|
||||
else if (check_warning_value==TRUE && nss1_value >= warning_value)
|
||||
else if (check_warning_value && nss1_value >= warning_value)
|
||||
result=STATE_WARNING;
|
||||
xasprintf (&output_message,
|
||||
_("%s is %lu|%s=%lu;%lu;%lu;;"),
|
||||
|
@ -1138,9 +1184,9 @@ main(int argc, char **argv) {
|
|||
result=STATE_CRITICAL;
|
||||
} else {
|
||||
nss2_value=strtoul(recv_buffer,NULL,10);
|
||||
if (check_critical_value==TRUE && nss2_value >= critical_value)
|
||||
if (check_critical_value && nss2_value >= critical_value)
|
||||
result=STATE_CRITICAL;
|
||||
else if (check_warning_value==TRUE && nss2_value >= warning_value)
|
||||
else if (check_warning_value && nss2_value >= warning_value)
|
||||
result=STATE_WARNING;
|
||||
xasprintf (&output_message,
|
||||
_("%s is %lu|%s=%lu;%lu;%lu;;"),
|
||||
|
@ -1164,9 +1210,9 @@ main(int argc, char **argv) {
|
|||
result=STATE_CRITICAL;
|
||||
} else {
|
||||
nss3_value=strtoul(recv_buffer,NULL,10);
|
||||
if (check_critical_value==TRUE && nss3_value >= critical_value)
|
||||
if (check_critical_value && nss3_value >= critical_value)
|
||||
result=STATE_CRITICAL;
|
||||
else if (check_warning_value==TRUE && nss3_value >= warning_value)
|
||||
else if (check_warning_value && nss3_value >= warning_value)
|
||||
result=STATE_WARNING;
|
||||
xasprintf (&output_message,
|
||||
_("%s is %lu|%s=%lu;%lu;%lu;;"),
|
||||
|
@ -1190,9 +1236,9 @@ main(int argc, char **argv) {
|
|||
result=STATE_CRITICAL;
|
||||
} else {
|
||||
nss4_value=strtoul(recv_buffer,NULL,10);
|
||||
if (check_critical_value==TRUE && nss4_value >= critical_value)
|
||||
if (check_critical_value && nss4_value >= critical_value)
|
||||
result=STATE_CRITICAL;
|
||||
else if (check_warning_value==TRUE && nss4_value >= warning_value)
|
||||
else if (check_warning_value && nss4_value >= warning_value)
|
||||
result=STATE_WARNING;
|
||||
xasprintf (&output_message,
|
||||
_("%s is %lu|%s=%lu;%lu;%lu;;"),
|
||||
|
@ -1216,9 +1262,9 @@ main(int argc, char **argv) {
|
|||
result=STATE_CRITICAL;
|
||||
} else {
|
||||
nss5_value=strtoul(recv_buffer,NULL,10);
|
||||
if (check_critical_value==TRUE && nss5_value >= critical_value)
|
||||
if (check_critical_value && nss5_value >= critical_value)
|
||||
result=STATE_CRITICAL;
|
||||
else if (check_warning_value==TRUE && nss5_value >= warning_value)
|
||||
else if (check_warning_value && nss5_value >= warning_value)
|
||||
result=STATE_WARNING;
|
||||
xasprintf (&output_message,
|
||||
_("%s is %lu|%s=%lu;%lu;%lu;;"),
|
||||
|
@ -1242,9 +1288,9 @@ main(int argc, char **argv) {
|
|||
result=STATE_CRITICAL;
|
||||
} else {
|
||||
nss6_value=strtoul(recv_buffer,NULL,10);
|
||||
if (check_critical_value==TRUE && nss6_value >= critical_value)
|
||||
if (check_critical_value && nss6_value >= critical_value)
|
||||
result=STATE_CRITICAL;
|
||||
else if (check_warning_value==TRUE && nss6_value >= warning_value)
|
||||
else if (check_warning_value && nss6_value >= warning_value)
|
||||
result=STATE_WARNING;
|
||||
xasprintf (&output_message,
|
||||
_("%s is %lu|%s=%lu;%lu;%lu;;"),
|
||||
|
@ -1268,9 +1314,9 @@ main(int argc, char **argv) {
|
|||
result=STATE_CRITICAL;
|
||||
} else {
|
||||
nss7_value=strtoul(recv_buffer,NULL,10);
|
||||
if (check_critical_value==TRUE && nss7_value >= critical_value)
|
||||
if (check_critical_value && nss7_value >= critical_value)
|
||||
result=STATE_CRITICAL;
|
||||
else if (check_warning_value==TRUE && nss7_value >= warning_value)
|
||||
else if (check_warning_value && nss7_value >= warning_value)
|
||||
result=STATE_WARNING;
|
||||
xasprintf (&output_message,
|
||||
_("%s is %lu|%s=%lu;%lu;%lu;;"),
|
||||
|
@ -1362,7 +1408,7 @@ int process_arguments(int argc, char **argv) {
|
|||
server_address=optarg;
|
||||
break;
|
||||
case 'o': /* display nos version */
|
||||
check_netware_version=TRUE;
|
||||
check_netware_version = true;
|
||||
break;
|
||||
case 'p': /* port */
|
||||
if (is_intnonneg(optarg))
|
||||
|
@ -1450,6 +1496,12 @@ int process_arguments(int argc, char **argv) {
|
|||
if (!strcmp(volume_name,""))
|
||||
volume_name = strdup ("SYS");
|
||||
}
|
||||
else if (strncmp(optarg,"VPU",3)==0) {
|
||||
vars_to_check=VPU;
|
||||
volume_name = strdup (optarg+3);
|
||||
if (!strcmp(volume_name,""))
|
||||
volume_name = strdup ("SYS");
|
||||
}
|
||||
else if (strncmp(optarg,"VPP",3)==0) {
|
||||
vars_to_check=VPP;
|
||||
volume_name = strdup (optarg+3);
|
||||
|
@ -1569,11 +1621,11 @@ int process_arguments(int argc, char **argv) {
|
|||
break;
|
||||
case 'w': /* warning threshold */
|
||||
warning_value=strtoul(optarg,NULL,10);
|
||||
check_warning_value=TRUE;
|
||||
check_warning_value = true;
|
||||
break;
|
||||
case 'c': /* critical threshold */
|
||||
critical_value=strtoul(optarg,NULL,10);
|
||||
check_critical_value=TRUE;
|
||||
check_critical_value = true;
|
||||
break;
|
||||
case 't': /* timeout */
|
||||
socket_timeout=atoi(optarg);
|
||||
|
@ -1626,6 +1678,7 @@ void print_help(void)
|
|||
printf (" %s\n", _("OFILES = number of open files"));
|
||||
printf (" %s\n", _(" VMF<vol> = MB of free space on Volume <vol>"));
|
||||
printf (" %s\n", _(" VMU<vol> = MB used space on Volume <vol>"));
|
||||
printf (" %s\n", _(" VPU<vol> = percent used space on Volume <vol>"));
|
||||
printf (" %s\n", _(" VMP<vol> = MB of purgeable space on Volume <vol>"));
|
||||
printf (" %s\n", _(" VPF<vol> = percent free space on volume <vol>"));
|
||||
printf (" %s\n", _(" VKF<vol> = KB of free space on volume <vol>"));
|
||||
|
|
|
@ -56,15 +56,15 @@ char *server_address = NULL;
|
|||
int server_port = PORT;
|
||||
double warning_value = 0L;
|
||||
double critical_value = 0L;
|
||||
int check_warning_value = FALSE;
|
||||
int check_critical_value = FALSE;
|
||||
bool check_warning_value = false;
|
||||
bool check_critical_value = false;
|
||||
enum checkvar vars_to_check = NONE;
|
||||
int cmd_timeout = 1;
|
||||
|
||||
int netstat_port = 0;
|
||||
char *disk_name = NULL;
|
||||
char *process_name = NULL;
|
||||
char send_buffer[MAX_INPUT_BUFFER];
|
||||
char send_buffer[MAX_INPUT_BUFFER];
|
||||
|
||||
int process_arguments (int, char **);
|
||||
void print_usage (void);
|
||||
|
@ -77,7 +77,7 @@ main (int argc, char **argv)
|
|||
char recv_buffer[MAX_INPUT_BUFFER];
|
||||
char temp_buffer[MAX_INPUT_BUFFER];
|
||||
char *temp_ptr = NULL;
|
||||
int found_disk = FALSE;
|
||||
bool found_disk = false;
|
||||
unsigned long percent_used_disk_space = 100;
|
||||
double load;
|
||||
double load_1min;
|
||||
|
@ -155,9 +155,9 @@ main (int argc, char **argv)
|
|||
break;
|
||||
}
|
||||
|
||||
if (check_critical_value == TRUE && (load >= critical_value))
|
||||
if (check_critical_value && (load >= critical_value))
|
||||
result = STATE_CRITICAL;
|
||||
else if (check_warning_value == TRUE && (load >= warning_value))
|
||||
else if (check_warning_value && (load >= warning_value))
|
||||
result = STATE_WARNING;
|
||||
|
||||
die (result,
|
||||
|
@ -178,7 +178,7 @@ main (int argc, char **argv)
|
|||
temp_ptr = (char *) strtok (NULL, " ")) {
|
||||
|
||||
if (!strcmp (temp_ptr, disk_name)) {
|
||||
found_disk = TRUE;
|
||||
found_disk = true;
|
||||
temp_ptr = (char *) strtok (NULL, "%");
|
||||
if (temp_ptr == NULL)
|
||||
die (STATE_CRITICAL, _("Invalid response from server\n"));
|
||||
|
@ -191,14 +191,14 @@ main (int argc, char **argv)
|
|||
}
|
||||
|
||||
/* error if we couldn't find the info for the disk */
|
||||
if (found_disk == FALSE)
|
||||
if (!found_disk)
|
||||
die (STATE_CRITICAL,
|
||||
"CRITICAL - Disk '%s' non-existent or not mounted",
|
||||
disk_name);
|
||||
|
||||
if (check_critical_value == TRUE && (percent_used_disk_space >= critical_value))
|
||||
if (check_critical_value && (percent_used_disk_space >= critical_value))
|
||||
result = STATE_CRITICAL;
|
||||
else if (check_warning_value == TRUE && (percent_used_disk_space >= warning_value))
|
||||
else if (check_warning_value && (percent_used_disk_space >= warning_value))
|
||||
result = STATE_WARNING;
|
||||
|
||||
die (result, "Disk %s - %lu%% used on %s", state_text(result), percent_used_disk_space, disk_name);
|
||||
|
@ -212,9 +212,9 @@ main (int argc, char **argv)
|
|||
else
|
||||
port_connections = strtod (recv_buffer, NULL);
|
||||
|
||||
if (check_critical_value == TRUE && (port_connections >= critical_value))
|
||||
if (check_critical_value && (port_connections >= critical_value))
|
||||
result = STATE_CRITICAL;
|
||||
else if (check_warning_value == TRUE && (port_connections >= warning_value))
|
||||
else if (check_warning_value && (port_connections >= warning_value))
|
||||
result = STATE_WARNING;
|
||||
|
||||
die (result,
|
||||
|
@ -241,9 +241,9 @@ main (int argc, char **argv)
|
|||
else
|
||||
processes = strtod (temp_ptr, NULL);
|
||||
|
||||
if (check_critical_value == TRUE && (processes >= critical_value))
|
||||
if (check_critical_value && (processes >= critical_value))
|
||||
result = STATE_CRITICAL;
|
||||
else if (check_warning_value == TRUE && (processes >= warning_value))
|
||||
else if (check_warning_value && (processes >= warning_value))
|
||||
result = STATE_WARNING;
|
||||
|
||||
die (result,
|
||||
|
@ -262,9 +262,9 @@ main (int argc, char **argv)
|
|||
uptime_raw_hours = strtod (recv_buffer, NULL);
|
||||
uptime_raw_minutes = (unsigned long) (uptime_raw_hours * 60.0);
|
||||
|
||||
if (check_critical_value == TRUE && (uptime_raw_minutes <= critical_value))
|
||||
if (check_critical_value && (uptime_raw_minutes <= critical_value))
|
||||
result = STATE_CRITICAL;
|
||||
else if (check_warning_value == TRUE && (uptime_raw_minutes <= warning_value))
|
||||
else if (check_warning_value && (uptime_raw_minutes <= warning_value))
|
||||
result = STATE_WARNING;
|
||||
|
||||
uptime_days = uptime_raw_minutes / 1440;
|
||||
|
@ -388,11 +388,11 @@ process_arguments (int argc, char **argv)
|
|||
break;
|
||||
case 'w': /* warning threshold */
|
||||
warning_value = strtoul (optarg, NULL, 10);
|
||||
check_warning_value = TRUE;
|
||||
check_warning_value = true;
|
||||
break;
|
||||
case 'c': /* critical threshold */
|
||||
critical_value = strtoul (optarg, NULL, 10);
|
||||
check_critical_value = TRUE;
|
||||
check_critical_value = true;
|
||||
break;
|
||||
case 't': /* timeout */
|
||||
socket_timeout = atoi (optarg);
|
||||
|
|
|
@ -69,7 +69,7 @@ int process_arguments (int, char **);
|
|||
int validate_arguments (void);
|
||||
void print_usage (void);
|
||||
void print_help (void);
|
||||
int is_pg_logname (char *);
|
||||
bool is_pg_logname (char *);
|
||||
int do_query (PGconn *, char *);
|
||||
|
||||
char *pghost = NULL; /* host name of the backend server */
|
||||
|
@ -252,7 +252,7 @@ main (int argc, char **argv)
|
|||
printf (_(" %s - database %s (%f sec.)|%s\n"),
|
||||
state_text(status), dbName, elapsed_time,
|
||||
fperfdata("time", elapsed_time, "s",
|
||||
!!(twarn > 0.0), twarn, !!(tcrit > 0.0), tcrit, TRUE, 0, FALSE,0));
|
||||
!!(twarn > 0.0), twarn, !!(tcrit > 0.0), tcrit, true, 0, false,0));
|
||||
|
||||
if (pgquery)
|
||||
query_status = do_query (conn, pgquery);
|
||||
|
@ -393,7 +393,7 @@ process_arguments (int argc, char **argv)
|
|||
|
||||
<para>&PROTO_validate_arguments;</para>
|
||||
|
||||
<para>Given a database name, this function returns TRUE if the string
|
||||
<para>Given a database name, this function returns true if the string
|
||||
is a valid PostgreSQL database name, and returns false if it is
|
||||
not.</para>
|
||||
|
||||
|
@ -424,7 +424,7 @@ function prototype
|
|||
|
||||
<para>&PROTO_is_pg_logname;</para>
|
||||
|
||||
<para>Given a username, this function returns TRUE if the string is a
|
||||
<para>Given a username, this function returns true if the string is a
|
||||
valid PostgreSQL username, and returns false if it is not. Valid PostgreSQL
|
||||
usernames are less than &NAMEDATALEN; characters long and consist of
|
||||
letters, numbers, dashes, and underscores, plus possibly some other
|
||||
|
@ -439,12 +439,10 @@ should be added.</para>
|
|||
|
||||
|
||||
|
||||
int
|
||||
is_pg_logname (char *username)
|
||||
{
|
||||
bool is_pg_logname (char *username) {
|
||||
if (strlen (username) > NAMEDATALEN - 1)
|
||||
return (FALSE);
|
||||
return (TRUE);
|
||||
return (false);
|
||||
return (true);
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
|
|
|
@ -55,7 +55,7 @@ int error_scan (char buf[MAX_INPUT_BUFFER], const char *addr);
|
|||
void print_usage (void);
|
||||
void print_help (void);
|
||||
|
||||
int display_html = FALSE;
|
||||
bool display_html = false;
|
||||
int wpl = UNKNOWN_PACKET_LOSS;
|
||||
int cpl = UNKNOWN_PACKET_LOSS;
|
||||
float wrta = UNKNOWN_TRIP_TIME;
|
||||
|
@ -153,7 +153,7 @@ main (int argc, char **argv)
|
|||
if (n_addresses > 1 && this_result != STATE_UNKNOWN)
|
||||
die (STATE_OK, "%s is alive\n", addresses[i]);
|
||||
|
||||
if (display_html == TRUE)
|
||||
if (display_html == true)
|
||||
printf ("<A HREF='%s/traceroute.cgi?%s'>", CGIURL, addresses[i]);
|
||||
if (pl == 100)
|
||||
printf (_("PING %s - %sPacket loss = %d%%"), state_text (this_result), warn_text,
|
||||
|
@ -161,22 +161,22 @@ main (int argc, char **argv)
|
|||
else
|
||||
printf (_("PING %s - %sPacket loss = %d%%, RTA = %2.2f ms"),
|
||||
state_text (this_result), warn_text, pl, rta);
|
||||
if (display_html == TRUE)
|
||||
if (display_html == true)
|
||||
printf ("</A>");
|
||||
|
||||
/* Print performance data */
|
||||
if (pl != 100) {
|
||||
printf("|%s", fperfdata ("rta", (double) rta, "ms",
|
||||
wrta>0?TRUE:FALSE, wrta,
|
||||
crta>0?TRUE:FALSE, crta,
|
||||
TRUE, 0, FALSE, 0));
|
||||
wrta>0?true:false, wrta,
|
||||
crta>0?true:false, crta,
|
||||
true, 0, false, 0));
|
||||
} else {
|
||||
printf("| rta=U;%f;%f;;", wrta, crta);
|
||||
}
|
||||
printf(" %s\n", perfdata ("pl", (long) pl, "%",
|
||||
wpl>0?TRUE:FALSE, wpl,
|
||||
cpl>0?TRUE:FALSE, cpl,
|
||||
TRUE, 0, FALSE, 0));
|
||||
wpl>0?true:false, wpl,
|
||||
cpl>0?true:false, cpl,
|
||||
true, 0, false, 0));
|
||||
|
||||
if (verbose >= 2)
|
||||
printf ("%f:%d%% %f:%d%%\n", wrta, wpl, crta, cpl);
|
||||
|
@ -278,10 +278,10 @@ process_arguments (int argc, char **argv)
|
|||
usage2 (_("<max_packets> (%s) must be a non-negative number\n"), optarg);
|
||||
break;
|
||||
case 'n': /* no HTML */
|
||||
display_html = FALSE;
|
||||
display_html = false;
|
||||
break;
|
||||
case 'L': /* show HTML */
|
||||
display_html = TRUE;
|
||||
display_html = true;
|
||||
break;
|
||||
case 'c':
|
||||
get_threshold (optarg, &crta, &cpl);
|
||||
|
@ -297,7 +297,7 @@ process_arguments (int argc, char **argv)
|
|||
return validate_arguments ();
|
||||
|
||||
if (addresses[0] == NULL) {
|
||||
if (is_host (argv[c]) == FALSE) {
|
||||
if (!is_host (argv[c])) {
|
||||
usage2 (_("Invalid hostname/address"), argv[c]);
|
||||
} else {
|
||||
addresses[0] = argv[c++];
|
||||
|
@ -308,7 +308,7 @@ process_arguments (int argc, char **argv)
|
|||
}
|
||||
|
||||
if (wpl == UNKNOWN_PACKET_LOSS) {
|
||||
if (is_intpercent (argv[c]) == FALSE) {
|
||||
if (!is_intpercent (argv[c])) {
|
||||
printf (_("<wpl> (%s) must be an integer percentage\n"), argv[c]);
|
||||
return ERROR;
|
||||
} else {
|
||||
|
@ -319,7 +319,7 @@ process_arguments (int argc, char **argv)
|
|||
}
|
||||
|
||||
if (cpl == UNKNOWN_PACKET_LOSS) {
|
||||
if (is_intpercent (argv[c]) == FALSE) {
|
||||
if (!is_intpercent (argv[c])) {
|
||||
printf (_("<cpl> (%s) must be an integer percentage\n"), argv[c]);
|
||||
return ERROR;
|
||||
} else {
|
||||
|
@ -420,7 +420,7 @@ validate_arguments ()
|
|||
timeout_interval = (int)max_seconds;
|
||||
|
||||
for (i=0; i<n_addresses; i++) {
|
||||
if (is_host(addresses[i]) == FALSE)
|
||||
if (!is_host(addresses[i]))
|
||||
usage2 (_("Invalid hostname/address"), addresses[i]);
|
||||
}
|
||||
|
||||
|
|
|
@ -14,6 +14,9 @@
|
|||
* defaults to number of processes. Search filters can be applied to limit
|
||||
* the processes to check.
|
||||
*
|
||||
* The parent process, check_procs itself and any child process of
|
||||
* check_procs (ps) are excluded from any checks to prevent false positives.
|
||||
*
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -153,7 +156,7 @@ main (int argc, char **argv)
|
|||
int expected_cols = PS_COLS - 1;
|
||||
int warn = 0; /* number of processes in warn state */
|
||||
int crit = 0; /* number of processes in crit state */
|
||||
int i = 0, j = 0;
|
||||
int i = 0;
|
||||
int result = STATE_UNKNOWN;
|
||||
int ret = 0;
|
||||
output chld_out, chld_err;
|
||||
|
@ -207,7 +210,7 @@ main (int argc, char **argv)
|
|||
}
|
||||
|
||||
/* flush first line: j starts at 1 */
|
||||
for (j = 1; j < chld_out.lines; j++) {
|
||||
for (size_t j = 1; j < chld_out.lines; j++) {
|
||||
input_line = chld_out.line[j];
|
||||
|
||||
if (verbose >= 3)
|
||||
|
@ -255,6 +258,13 @@ main (int argc, char **argv)
|
|||
continue;
|
||||
}
|
||||
|
||||
/* Ignore our own children */
|
||||
if (procppid == mypid) {
|
||||
if (verbose >= 3)
|
||||
printf("not considering - is our child\n");
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Ignore excluded processes by name */
|
||||
if(options & EXCLUDE_PROGS) {
|
||||
int found = 0;
|
||||
|
@ -728,18 +738,23 @@ convert_to_seconds(char *etime) {
|
|||
void
|
||||
print_help (void)
|
||||
{
|
||||
print_revision (progname, NP_VERSION);
|
||||
print_revision (progname, NP_VERSION);
|
||||
|
||||
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 ("%s\n", _("Checks all processes and generates WARNING or CRITICAL states if the specified"));
|
||||
printf ("%s\n", _("Checks all processes and generates WARNING or CRITICAL states if the specified"));
|
||||
printf ("%s\n", _("metric is outside the required threshold ranges. The metric defaults to number"));
|
||||
printf ("%s\n", _("of processes. Search filters can be applied to limit the processes to check."));
|
||||
|
||||
printf ("\n\n");
|
||||
|
||||
print_usage ();
|
||||
printf ("%s\n", _("The parent process, check_procs itself and any child process of check_procs (ps)"));
|
||||
printf ("%s\n", _("are excluded from any checks to prevent false positives."));
|
||||
|
||||
printf ("\n\n");
|
||||
|
||||
print_usage ();
|
||||
|
||||
printf (UT_HELP_VRSN);
|
||||
printf (UT_EXTRA_OPTS);
|
||||
|
@ -755,11 +770,11 @@ print_help (void)
|
|||
printf (" %s\n", _("CPU - percentage CPU"));
|
||||
/* only linux etime is support currently */
|
||||
#if defined( __linux__ )
|
||||
printf (" %s\n", _("ELAPSED - time elapsed in seconds"));
|
||||
printf (" %s\n", _("ELAPSED - time elapsed in seconds"));
|
||||
#endif /* defined(__linux__) */
|
||||
printf (UT_PLUG_TIMEOUT, DEFAULT_SOCKET_TIMEOUT);
|
||||
printf (UT_PLUG_TIMEOUT, DEFAULT_SOCKET_TIMEOUT);
|
||||
|
||||
printf (" %s\n", "-v, --verbose");
|
||||
printf (" %s\n", "-v, --verbose");
|
||||
printf (" %s\n", _("Extra information. Up to 3 verbosity levels"));
|
||||
|
||||
printf (" %s\n", "-T, --traditional");
|
||||
|
@ -777,7 +792,7 @@ print_help (void)
|
|||
printf (" %s\n", _("Only scan for processes with VSZ higher than indicated."));
|
||||
printf (" %s\n", "-r, --rss=RSS");
|
||||
printf (" %s\n", _("Only scan for processes with RSS higher than indicated."));
|
||||
printf (" %s\n", "-P, --pcpu=PCPU");
|
||||
printf (" %s\n", "-P, --pcpu=PCPU");
|
||||
printf (" %s\n", _("Only scan for processes with PCPU higher than indicated."));
|
||||
printf (" %s\n", "-u, --user=USER");
|
||||
printf (" %s\n", _("Only scan for processes with user name or ID indicated."));
|
||||
|
@ -792,19 +807,19 @@ print_help (void)
|
|||
printf (" %s\n", "-k, --no-kthreads");
|
||||
printf (" %s\n", _("Only scan for non kernel threads (works on Linux only)."));
|
||||
|
||||
printf(_("\n\
|
||||
printf(_("\n\
|
||||
RANGEs are specified 'min:max' or 'min:' or ':max' (or 'max'). If\n\
|
||||
specified 'max:min', a warning status will be generated if the\n\
|
||||
count is inside the specified range\n\n"));
|
||||
|
||||
printf(_("\
|
||||
printf(_("\
|
||||
This plugin checks the number of currently running processes and\n\
|
||||
generates WARNING or CRITICAL states if the process count is outside\n\
|
||||
the specified threshold ranges. The process count can be filtered by\n\
|
||||
process owner, parent process PID, current state (e.g., 'Z'), or may\n\
|
||||
be the total number of running processes\n\n"));
|
||||
|
||||
printf ("%s\n", _("Examples:"));
|
||||
printf ("%s\n", _("Examples:"));
|
||||
printf (" %s\n", "check_procs -w 2:2 -c 2:1024 -C portsentry");
|
||||
printf (" %s\n", _("Warning if not two processes with command name portsentry."));
|
||||
printf (" %s\n\n", _("Critical if < 2 or > 1024 processes"));
|
||||
|
@ -821,14 +836,14 @@ be the total number of running processes\n\n"));
|
|||
printf (" %s\n", "check_procs -w 10 -c 20 --metric=CPU");
|
||||
printf (" %s\n", _("Alert if CPU of any processes over 10\% or 20\%"));
|
||||
|
||||
printf (UT_SUPPORT);
|
||||
printf (UT_SUPPORT);
|
||||
}
|
||||
|
||||
void
|
||||
print_usage (void)
|
||||
{
|
||||
printf ("%s\n", _("Usage:"));
|
||||
printf ("%s -w <range> -c <range> [-m metric] [-s state] [-p ppid]\n", progname);
|
||||
printf ("%s -w <range> -c <range> [-m metric] [-s state] [-p ppid]\n", progname);
|
||||
printf (" [-u user] [-r rss] [-z vsz] [-P %%cpu] [-a argument-array]\n");
|
||||
printf (" [-C command] [-X process_to_exclude] [-k] [-t timeout] [-v]\n");
|
||||
}
|
||||
|
|
|
@ -93,7 +93,7 @@ char *expect = NULL;
|
|||
char *config_file = NULL;
|
||||
unsigned short port = PW_AUTH_UDP_PORT;
|
||||
int retries = 1;
|
||||
int verbose = FALSE;
|
||||
bool verbose = false;
|
||||
|
||||
/******************************************************************************
|
||||
|
||||
|
@ -272,10 +272,10 @@ process_arguments (int argc, char **argv)
|
|||
print_revision (progname, NP_VERSION);
|
||||
exit (STATE_UNKNOWN);
|
||||
case 'v': /* verbose mode */
|
||||
verbose = TRUE;
|
||||
verbose = true;
|
||||
break;
|
||||
case 'H': /* hostname */
|
||||
if (is_host (optarg) == FALSE) {
|
||||
if (!is_host (optarg)) {
|
||||
usage2 (_("Invalid hostname/address"), optarg);
|
||||
}
|
||||
server = optarg;
|
||||
|
|
|
@ -54,10 +54,10 @@ char *host_name;
|
|||
char *server_url = NULL;
|
||||
char *server_expect;
|
||||
int warning_time = 0;
|
||||
int check_warning_time = FALSE;
|
||||
bool check_warning_time = false;
|
||||
int critical_time = 0;
|
||||
int check_critical_time = FALSE;
|
||||
int verbose = FALSE;
|
||||
bool check_critical_time = false;
|
||||
bool verbose = false;
|
||||
|
||||
|
||||
|
||||
|
@ -238,9 +238,9 @@ main (int argc, char **argv)
|
|||
/* Return results */
|
||||
if (result == STATE_OK) {
|
||||
|
||||
if (check_critical_time == TRUE
|
||||
if (check_critical_time
|
||||
&& (end_time - start_time) > critical_time) result = STATE_CRITICAL;
|
||||
else if (check_warning_time == TRUE
|
||||
else if (check_warning_time
|
||||
&& (end_time - start_time) > warning_time) result =
|
||||
STATE_WARNING;
|
||||
|
||||
|
@ -331,7 +331,7 @@ process_arguments (int argc, char **argv)
|
|||
case 'w': /* warning time threshold */
|
||||
if (is_intnonneg (optarg)) {
|
||||
warning_time = atoi (optarg);
|
||||
check_warning_time = TRUE;
|
||||
check_warning_time = true;
|
||||
}
|
||||
else {
|
||||
usage4 (_("Warning time must be a positive integer"));
|
||||
|
@ -340,14 +340,14 @@ process_arguments (int argc, char **argv)
|
|||
case 'c': /* critical time threshold */
|
||||
if (is_intnonneg (optarg)) {
|
||||
critical_time = atoi (optarg);
|
||||
check_critical_time = TRUE;
|
||||
check_critical_time = true;
|
||||
}
|
||||
else {
|
||||
usage4 (_("Critical time must be a positive integer"));
|
||||
}
|
||||
break;
|
||||
case 'v': /* verbose */
|
||||
verbose = TRUE;
|
||||
verbose = true;
|
||||
break;
|
||||
case 't': /* timeout */
|
||||
if (is_intnonneg (optarg)) {
|
||||
|
|
|
@ -40,7 +40,7 @@ const char *email = "devel@monitoring-plugins.org";
|
|||
#include <ctype.h>
|
||||
|
||||
#ifdef HAVE_SSL
|
||||
int check_cert = FALSE;
|
||||
bool check_cert = false;
|
||||
int days_till_exp_warn, days_till_exp_crit;
|
||||
# define my_recv(buf, len) (((use_starttls || use_ssl) && ssl_established) ? np_net_ssl_read(buf, len) : read(sd, buf, len))
|
||||
# define my_send(buf, len) (((use_starttls || use_ssl) && ssl_established) ? np_net_ssl_write(buf, len) : send(sd, buf, len, 0))
|
||||
|
@ -100,17 +100,17 @@ char *authtype = NULL;
|
|||
char *authuser = NULL;
|
||||
char *authpass = NULL;
|
||||
double warning_time = 0;
|
||||
int check_warning_time = FALSE;
|
||||
bool check_warning_time = false;
|
||||
double critical_time = 0;
|
||||
int check_critical_time = FALSE;
|
||||
bool check_critical_time = false;
|
||||
int verbose = 0;
|
||||
int use_ssl = FALSE;
|
||||
int use_starttls = FALSE;
|
||||
int use_sni = FALSE;
|
||||
short use_proxy_prefix = FALSE;
|
||||
short use_ehlo = FALSE;
|
||||
short use_lhlo = FALSE;
|
||||
short ssl_established = 0;
|
||||
bool use_ssl = false;
|
||||
bool use_starttls = false;
|
||||
bool use_sni = false;
|
||||
bool use_proxy_prefix = false;
|
||||
bool use_ehlo = false;
|
||||
bool use_lhlo = false;
|
||||
bool ssl_established = false;
|
||||
char *localhostname = NULL;
|
||||
int sd;
|
||||
char buffer[MAX_INPUT_BUFFER];
|
||||
|
@ -118,13 +118,13 @@ enum {
|
|||
TCP_PROTOCOL = 1,
|
||||
UDP_PROTOCOL = 2,
|
||||
};
|
||||
int ignore_send_quit_failure = FALSE;
|
||||
bool ignore_send_quit_failure = false;
|
||||
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
short supports_tls=FALSE;
|
||||
bool supports_tls = false;
|
||||
int n = 0;
|
||||
double elapsed_time;
|
||||
long microsec;
|
||||
|
@ -230,7 +230,7 @@ main (int argc, char **argv)
|
|||
} else if(use_ehlo || use_lhlo){
|
||||
if(strstr(buffer, "250 STARTTLS") != NULL ||
|
||||
strstr(buffer, "250-STARTTLS") != NULL){
|
||||
supports_tls=TRUE;
|
||||
supports_tls=true;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -466,7 +466,7 @@ main (int argc, char **argv)
|
|||
fperfdata ("time", elapsed_time, "s",
|
||||
(int)check_warning_time, warning_time,
|
||||
(int)check_critical_time, critical_time,
|
||||
TRUE, 0, FALSE, 0));
|
||||
true, 0, false, 0));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -480,6 +480,8 @@ process_arguments (int argc, char **argv)
|
|||
int c;
|
||||
char* temp;
|
||||
|
||||
bool implicit_tls = false;
|
||||
|
||||
enum {
|
||||
SNI_OPTION
|
||||
};
|
||||
|
@ -560,7 +562,7 @@ process_arguments (int argc, char **argv)
|
|||
break;
|
||||
case 'A':
|
||||
authtype = optarg;
|
||||
use_ehlo = TRUE;
|
||||
use_ehlo = true;
|
||||
break;
|
||||
case 'U':
|
||||
authuser = optarg;
|
||||
|
@ -600,7 +602,7 @@ process_arguments (int argc, char **argv)
|
|||
usage4 (_("Critical time must be a positive"));
|
||||
else {
|
||||
critical_time = strtod (optarg, NULL);
|
||||
check_critical_time = TRUE;
|
||||
check_critical_time = true;
|
||||
}
|
||||
break;
|
||||
case 'w': /* warning time threshold */
|
||||
|
@ -608,14 +610,14 @@ process_arguments (int argc, char **argv)
|
|||
usage4 (_("Warning time must be a positive"));
|
||||
else {
|
||||
warning_time = strtod (optarg, NULL);
|
||||
check_warning_time = TRUE;
|
||||
check_warning_time = true;
|
||||
}
|
||||
break;
|
||||
case 'v': /* verbose */
|
||||
verbose++;
|
||||
break;
|
||||
case 'q':
|
||||
ignore_send_quit_failure++; /* ignore problem sending QUIT */
|
||||
ignore_send_quit_failure = true; /* ignore problem sending QUIT */
|
||||
break;
|
||||
case 't': /* timeout */
|
||||
if (is_intnonneg (optarg)) {
|
||||
|
@ -645,33 +647,35 @@ process_arguments (int argc, char **argv)
|
|||
usage2 ("Invalid certificate expiration period", optarg);
|
||||
days_till_exp_warn = atoi (optarg);
|
||||
}
|
||||
check_cert = TRUE;
|
||||
ignore_send_quit_failure = TRUE;
|
||||
check_cert = true;
|
||||
ignore_send_quit_failure = true;
|
||||
#else
|
||||
usage (_("SSL support not available - install OpenSSL and recompile"));
|
||||
#endif
|
||||
implicit_tls = true;
|
||||
// fallthrough
|
||||
case 's':
|
||||
/* ssl */
|
||||
use_ssl = TRUE;
|
||||
use_ssl = true;
|
||||
server_port = SMTPS_PORT;
|
||||
break;
|
||||
case 'S':
|
||||
/* starttls */
|
||||
use_starttls = TRUE;
|
||||
use_ehlo = TRUE;
|
||||
use_starttls = true;
|
||||
use_ehlo = true;
|
||||
break;
|
||||
case SNI_OPTION:
|
||||
#ifdef HAVE_SSL
|
||||
use_sni = TRUE;
|
||||
use_sni = true;
|
||||
#else
|
||||
usage (_("SSL support not available - install OpenSSL and recompile"));
|
||||
#endif
|
||||
break;
|
||||
case 'r':
|
||||
use_proxy_prefix = TRUE;
|
||||
use_proxy_prefix = true;
|
||||
break;
|
||||
case 'L':
|
||||
use_lhlo = TRUE;
|
||||
use_lhlo = true;
|
||||
break;
|
||||
case '4':
|
||||
address_family = AF_INET;
|
||||
|
@ -717,7 +721,12 @@ process_arguments (int argc, char **argv)
|
|||
from_arg = strdup(" ");
|
||||
|
||||
if (use_starttls && use_ssl) {
|
||||
usage4 (_("Set either -s/--ssl/--tls or -S/--starttls"));
|
||||
if (implicit_tls) {
|
||||
use_ssl = false;
|
||||
server_port = SMTP_PORT;
|
||||
} else {
|
||||
usage4 (_("Set either -s/--ssl/--tls or -S/--starttls"));
|
||||
}
|
||||
}
|
||||
|
||||
if (server_port_option != 0) {
|
||||
|
|
|
@ -131,11 +131,11 @@ size_t nlabels = 0;
|
|||
size_t labels_size = OID_COUNT_STEP;
|
||||
size_t nunits = 0;
|
||||
size_t unitv_size = OID_COUNT_STEP;
|
||||
int numoids = 0;
|
||||
size_t numoids = 0;
|
||||
int numauthpriv = 0;
|
||||
int numcontext = 0;
|
||||
int verbose = 0;
|
||||
int usesnmpgetnext = FALSE;
|
||||
bool usesnmpgetnext = false;
|
||||
char *warning_thresholds = NULL;
|
||||
char *critical_thresholds = NULL;
|
||||
thresholds **thlds;
|
||||
|
@ -148,7 +148,7 @@ size_t eval_size = OID_COUNT_STEP;
|
|||
char *delimiter;
|
||||
char *output_delim;
|
||||
char *miblist = NULL;
|
||||
int needmibs = FALSE;
|
||||
bool needmibs = false;
|
||||
int calculate_rate = 0;
|
||||
double offset = 0.0;
|
||||
int rate_multiplier = 1;
|
||||
|
@ -187,7 +187,8 @@ static char *fix_snmp_range(char *th)
|
|||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
int i, len, line, total_oids;
|
||||
int len, total_oids;
|
||||
size_t line;
|
||||
unsigned int bk_count = 0, dq_count = 0;
|
||||
int iresult = STATE_UNKNOWN;
|
||||
int result = STATE_UNKNOWN;
|
||||
|
@ -253,14 +254,16 @@ main (int argc, char **argv)
|
|||
if(calculate_rate) {
|
||||
if (!strcmp(label, "SNMP"))
|
||||
label = strdup("SNMP RATE");
|
||||
i=0;
|
||||
|
||||
size_t i = 0;
|
||||
|
||||
previous_state = np_state_read();
|
||||
if(previous_state!=NULL) {
|
||||
/* Split colon separated values */
|
||||
previous_string = strdup((char *) previous_state->data);
|
||||
while((ap = strsep(&previous_string, ":")) != NULL) {
|
||||
if(verbose>2)
|
||||
printf("State for %d=%s\n", i, ap);
|
||||
printf("State for %zd=%s\n", i, ap);
|
||||
while (i >= previous_size) {
|
||||
previous_size += OID_COUNT_STEP;
|
||||
previous_value = realloc(previous_value, previous_size * sizeof(*previous_value));
|
||||
|
@ -273,7 +276,7 @@ main (int argc, char **argv)
|
|||
/* Populate the thresholds */
|
||||
th_warn=warning_thresholds;
|
||||
th_crit=critical_thresholds;
|
||||
for (i=0; i<numoids; i++) {
|
||||
for (size_t i = 0; i < numoids; i++) {
|
||||
char *w = th_warn ? strndup(th_warn, strcspn(th_warn, ",")) : NULL;
|
||||
char *c = th_crit ? strndup(th_crit, strcspn(th_crit, ",")) : NULL;
|
||||
/* translate "2:1" to "@1:2" for backwards compatibility */
|
||||
|
@ -302,7 +305,7 @@ main (int argc, char **argv)
|
|||
}
|
||||
|
||||
/* Create the command array to execute */
|
||||
if(usesnmpgetnext == TRUE) {
|
||||
if(usesnmpgetnext) {
|
||||
snmpcmd = strdup (PATH_TO_SNMPGETNEXT);
|
||||
}else{
|
||||
snmpcmd = strdup (PATH_TO_SNMPGET);
|
||||
|
@ -333,11 +336,11 @@ main (int argc, char **argv)
|
|||
}
|
||||
|
||||
|
||||
for (i = 0; i < numcontext; i++) {
|
||||
for (int i = 0; i < numcontext; i++) {
|
||||
command_line[index++] = contextargs[i];
|
||||
}
|
||||
|
||||
for (i = 0; i < numauthpriv; i++) {
|
||||
for (int i = 0; i < numauthpriv; i++) {
|
||||
command_line[index++] = authpriv[i];
|
||||
}
|
||||
|
||||
|
@ -348,7 +351,7 @@ main (int argc, char **argv)
|
|||
server_address,
|
||||
port);
|
||||
|
||||
for (i = 0; i < numoids; i++) {
|
||||
for (size_t i = 0; i < numoids; i++) {
|
||||
command_line[index++] = oids[i];
|
||||
xasprintf(&cl_hidden_auth, "%s %s", cl_hidden_auth, oids[i]);
|
||||
}
|
||||
|
@ -382,7 +385,7 @@ main (int argc, char **argv)
|
|||
if (external_error) {
|
||||
if (chld_err.lines > 0) {
|
||||
printf (_("External command error: %s\n"), chld_err.line[0]);
|
||||
for (i = 1; i < chld_err.lines; i++) {
|
||||
for (size_t i = 1; i < chld_err.lines; i++) {
|
||||
printf ("%s\n", chld_err.line[i]);
|
||||
}
|
||||
} else {
|
||||
|
@ -392,12 +395,14 @@ main (int argc, char **argv)
|
|||
}
|
||||
|
||||
if (verbose) {
|
||||
for (i = 0; i < chld_out.lines; i++) {
|
||||
for (size_t i = 0; i < chld_out.lines; i++) {
|
||||
printf ("%s\n", chld_out.line[i]);
|
||||
}
|
||||
}
|
||||
|
||||
for (line=0, i=0; line < chld_out.lines && i < numoids ; line++, i++) {
|
||||
line = 0;
|
||||
total_oids = 0;
|
||||
for (size_t i = 0; line < chld_out.lines && i < numoids ; line++, i++, total_oids++) {
|
||||
if(calculate_rate)
|
||||
conv = "%.10g";
|
||||
else
|
||||
|
@ -410,7 +415,7 @@ main (int argc, char **argv)
|
|||
break;
|
||||
|
||||
if (verbose > 2) {
|
||||
printf("Processing oid %i (line %i)\n oidname: %s\n response: %s\n", i+1, line+1, oidname, response);
|
||||
printf("Processing oid %zi (line %zi)\n oidname: %s\n response: %s\n", i+1, line+1, oidname, response);
|
||||
}
|
||||
|
||||
/* Clean up type array - Sol10 does not necessarily zero it out */
|
||||
|
@ -634,7 +639,6 @@ main (int argc, char **argv)
|
|||
strncat(perfstr, " ", sizeof(perfstr)-strlen(perfstr)-1);
|
||||
}
|
||||
}
|
||||
total_oids=i;
|
||||
|
||||
/* Save state data, as all data collected now */
|
||||
if(calculate_rate) {
|
||||
|
@ -644,7 +648,7 @@ main (int argc, char **argv)
|
|||
die(STATE_UNKNOWN, _("Cannot malloc"));
|
||||
|
||||
current_length=0;
|
||||
for(i=0; i<total_oids; i++) {
|
||||
for(int i = 0; i < total_oids; i++) {
|
||||
xasprintf(&temp_string,"%.0f",response_value[i]);
|
||||
if(temp_string==NULL)
|
||||
die(STATE_UNKNOWN,_("Cannot asprintf()"));
|
||||
|
@ -687,7 +691,7 @@ process_arguments (int argc, char **argv)
|
|||
{
|
||||
char *ptr;
|
||||
int c = 1;
|
||||
int j = 0, jj = 0, ii = 0;
|
||||
size_t j = 0, jj = 0;
|
||||
|
||||
int option = 0;
|
||||
static struct option longopts[] = {
|
||||
|
@ -777,7 +781,7 @@ process_arguments (int argc, char **argv)
|
|||
miblist = optarg;
|
||||
break;
|
||||
case 'n': /* usesnmpgetnext */
|
||||
usesnmpgetnext = TRUE;
|
||||
usesnmpgetnext = true;
|
||||
break;
|
||||
case 'P': /* SNMP protocol version */
|
||||
proto = optarg;
|
||||
|
@ -831,7 +835,7 @@ process_arguments (int argc, char **argv)
|
|||
* so we have a mib variable, rather than just an SNMP OID,
|
||||
* so we have to actually read the mib files
|
||||
*/
|
||||
needmibs = TRUE;
|
||||
needmibs = true;
|
||||
}
|
||||
for (ptr = strtok(optarg, ", "); ptr != NULL; ptr = strtok(NULL, ", "), j++) {
|
||||
while (j >= oids_size) {
|
||||
|
@ -843,7 +847,6 @@ process_arguments (int argc, char **argv)
|
|||
numoids = j;
|
||||
if (c == 'E' || c == 'e') {
|
||||
jj++;
|
||||
ii++;
|
||||
while (j+1 >= eval_size) {
|
||||
eval_size += OID_COUNT_STEP;
|
||||
eval_method = realloc(eval_method, eval_size * sizeof(*eval_method));
|
||||
|
@ -870,7 +873,6 @@ process_arguments (int argc, char **argv)
|
|||
memset(eval_method + eval_size - OID_COUNT_STEP, 0, 8);
|
||||
}
|
||||
eval_method[jj++] = CRIT_STRING;
|
||||
ii++;
|
||||
break;
|
||||
case 'R': /* regex */
|
||||
cflags = REG_ICASE;
|
||||
|
@ -891,7 +893,6 @@ process_arguments (int argc, char **argv)
|
|||
memset(eval_method + eval_size - OID_COUNT_STEP, 0, 8);
|
||||
}
|
||||
eval_method[jj++] = CRIT_REGEX;
|
||||
ii++;
|
||||
break;
|
||||
|
||||
/* Format */
|
||||
|
@ -1034,7 +1035,7 @@ validate_arguments ()
|
|||
{
|
||||
/* check whether to load locally installed MIBS (CPU/disk intensive) */
|
||||
if (miblist == NULL) {
|
||||
if ( needmibs == TRUE ) {
|
||||
if (needmibs) {
|
||||
miblist = strdup (DEFAULT_MIBLIST);
|
||||
}else{
|
||||
miblist = ""; /* don't read any mib files for numeric oids */
|
||||
|
|
|
@ -1,39 +1,39 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
*
|
||||
* Monitoring check_ssh plugin
|
||||
*
|
||||
*
|
||||
* License: GPL
|
||||
* Copyright (c) 2000-2007 Monitoring Plugins Development Team
|
||||
*
|
||||
*
|
||||
* Description:
|
||||
*
|
||||
*
|
||||
* This file contains the check_ssh plugin
|
||||
*
|
||||
*
|
||||
* Try to connect to an SSH server at specified server and port
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
const char *progname = "check_ssh";
|
||||
const char *copyright = "2000-2007";
|
||||
const char *email = "devel@monitoring-plugins.org";
|
||||
|
||||
#include "common.h"
|
||||
#include "netutils.h"
|
||||
#include "./common.h"
|
||||
#include "./netutils.h"
|
||||
#include "utils.h"
|
||||
|
||||
#ifndef MSG_DONTWAIT
|
||||
|
@ -47,7 +47,7 @@ int port = -1;
|
|||
char *server_name = NULL;
|
||||
char *remote_version = NULL;
|
||||
char *remote_protocol = NULL;
|
||||
int verbose = FALSE;
|
||||
bool verbose = false;
|
||||
|
||||
int process_arguments (int, char **);
|
||||
int validate_arguments (void);
|
||||
|
@ -57,7 +57,6 @@ void print_usage (void);
|
|||
int ssh_connect (char *haddr, int hport, char *remote_version, char *remote_protocol);
|
||||
|
||||
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
|
@ -106,7 +105,7 @@ process_arguments (int argc, char **argv)
|
|||
{"timeout", required_argument, 0, 't'},
|
||||
{"verbose", no_argument, 0, 'v'},
|
||||
{"remote-version", required_argument, 0, 'r'},
|
||||
{"remote-protcol", required_argument, 0, 'P'},
|
||||
{"remote-protocol", required_argument, 0, 'P'},
|
||||
{0, 0, 0, 0}
|
||||
};
|
||||
|
||||
|
@ -133,7 +132,7 @@ process_arguments (int argc, char **argv)
|
|||
print_help ();
|
||||
exit (STATE_UNKNOWN);
|
||||
case 'v': /* verbose */
|
||||
verbose = TRUE;
|
||||
verbose = true;
|
||||
break;
|
||||
case 't': /* timeout period */
|
||||
if (!is_integer (optarg))
|
||||
|
@ -158,7 +157,7 @@ process_arguments (int argc, char **argv)
|
|||
remote_protocol = optarg;
|
||||
break;
|
||||
case 'H': /* host */
|
||||
if (is_host (optarg) == FALSE)
|
||||
if (!is_host (optarg))
|
||||
usage2 (_("Invalid hostname/address"), optarg);
|
||||
server_name = optarg;
|
||||
break;
|
||||
|
@ -215,7 +214,9 @@ ssh_connect (char *haddr, int hport, char *remote_version, char *remote_protocol
|
|||
{
|
||||
int sd;
|
||||
int result;
|
||||
char *output = NULL;
|
||||
int len = 0;
|
||||
ssize_t recv_ret = 0;
|
||||
char *version_control_string = NULL;
|
||||
char *buffer = NULL;
|
||||
char *ssh_proto = NULL;
|
||||
char *ssh_server = NULL;
|
||||
|
@ -230,52 +231,126 @@ ssh_connect (char *haddr, int hport, char *remote_version, char *remote_protocol
|
|||
if (result != STATE_OK)
|
||||
return result;
|
||||
|
||||
output = (char *) malloc (BUFF_SZ + 1);
|
||||
memset (output, 0, BUFF_SZ + 1);
|
||||
recv (sd, output, BUFF_SZ, 0);
|
||||
if (strncmp (output, "SSH", 3)) {
|
||||
printf (_("Server answer: %s"), output);
|
||||
char *output = (char *) calloc (BUFF_SZ + 1, sizeof(char));
|
||||
|
||||
unsigned int iteration = 0;
|
||||
ssize_t byte_offset = 0;
|
||||
|
||||
while ((version_control_string == NULL) && (recv_ret = recv(sd, output+byte_offset, BUFF_SZ - byte_offset, 0) > 0)) {
|
||||
|
||||
if (strchr(output, '\n')) { /* we've got at least one full line, start parsing*/
|
||||
byte_offset = 0;
|
||||
|
||||
char *index = NULL;
|
||||
while ((index = strchr(output+byte_offset, '\n')) != NULL) {
|
||||
/*Partition the buffer so that this line is a separate string,
|
||||
* by replacing the newline with NUL*/
|
||||
output[(index - output)] = '\0';
|
||||
len = strlen(output + byte_offset);
|
||||
|
||||
if ((len >= 4) && (strncmp (output+byte_offset, "SSH-", 4) == 0)) {
|
||||
/*if the string starts with SSH-, this _should_ be a valid version control string*/
|
||||
version_control_string = output+byte_offset;
|
||||
break;
|
||||
}
|
||||
|
||||
/*the start of the next line (if one exists) will be after the current one (+ NUL)*/
|
||||
byte_offset += (len + 1);
|
||||
}
|
||||
|
||||
if(version_control_string == NULL) {
|
||||
/* move unconsumed data to beginning of buffer, null rest */
|
||||
memmove((void *)output, (void *)output+byte_offset+1, BUFF_SZ - len+1);
|
||||
memset(output+byte_offset+1, 0, BUFF_SZ-byte_offset+1);
|
||||
|
||||
/*start reading from end of current line chunk on next recv*/
|
||||
byte_offset = strlen(output);
|
||||
}
|
||||
} else {
|
||||
byte_offset += recv_ret;
|
||||
}
|
||||
}
|
||||
|
||||
if (recv_ret < 0) {
|
||||
printf("SSH CRITICAL - %s", strerror(errno));
|
||||
exit(STATE_CRITICAL);
|
||||
}
|
||||
|
||||
if (version_control_string == NULL) {
|
||||
printf("SSH CRITICAL - No version control string received");
|
||||
exit(STATE_CRITICAL);
|
||||
}
|
||||
/*
|
||||
* "When the connection has been established, both sides MUST send an
|
||||
* identification string. This identification string MUST be
|
||||
*
|
||||
* SSH-protoversion-softwareversion SP comments CR LF"
|
||||
* - RFC 4253:4.2
|
||||
*/
|
||||
strip (version_control_string);
|
||||
if (verbose)
|
||||
printf ("%s\n", version_control_string);
|
||||
ssh_proto = version_control_string + 4;
|
||||
|
||||
/*
|
||||
* We assume the protoversion is of the form Major.Minor, although
|
||||
* this is not _strictly_ required. See
|
||||
*
|
||||
* "Both the 'protoversion' and 'softwareversion' strings MUST consist of
|
||||
* printable US-ASCII characters, with the exception of whitespace
|
||||
* characters and the minus sign (-)"
|
||||
* - RFC 4253:4.2
|
||||
* and,
|
||||
*
|
||||
* "As stated earlier, the 'protoversion' specified for this protocol is
|
||||
* "2.0". Earlier versions of this protocol have not been formally
|
||||
* documented, but it is widely known that they use 'protoversion' of
|
||||
* "1.x" (e.g., "1.5" or "1.3")."
|
||||
* - RFC 4253:5
|
||||
*/
|
||||
ssh_server = ssh_proto + strspn (ssh_proto, "0123456789.") + 1; /* (+1 for the '-' separating protoversion from softwareversion) */
|
||||
|
||||
/* If there's a space in the version string, whatever's after the space is a comment
|
||||
* (which is NOT part of the server name/version)*/
|
||||
char *tmp = strchr(ssh_server, ' ');
|
||||
if (tmp) {
|
||||
ssh_server[tmp - ssh_server] = '\0';
|
||||
}
|
||||
if (strlen(ssh_proto) == 0 || strlen(ssh_server) == 0) {
|
||||
printf(_("SSH CRITICAL - Invalid protocol version control string %s\n"), version_control_string);
|
||||
exit (STATE_CRITICAL);
|
||||
}
|
||||
ssh_proto[strspn (ssh_proto, "0123456789. ")] = 0;
|
||||
|
||||
xasprintf (&buffer, "SSH-%s-check_ssh_%s\r\n", ssh_proto, rev_no);
|
||||
send (sd, buffer, strlen (buffer), MSG_DONTWAIT);
|
||||
if (verbose)
|
||||
printf ("%s\n", buffer);
|
||||
|
||||
if (remote_version && strcmp(remote_version, ssh_server)) {
|
||||
printf
|
||||
(_("SSH CRITICAL - %s (protocol %s) version mismatch, expected '%s'\n"),
|
||||
ssh_server, ssh_proto, remote_version);
|
||||
close(sd);
|
||||
exit (STATE_CRITICAL);
|
||||
}
|
||||
else {
|
||||
strip (output);
|
||||
if (verbose)
|
||||
printf ("%s\n", output);
|
||||
ssh_proto = output + 4;
|
||||
ssh_server = ssh_proto + strspn (ssh_proto, "-0123456789. ");
|
||||
ssh_proto[strspn (ssh_proto, "0123456789. ")] = 0;
|
||||
|
||||
xasprintf (&buffer, "SSH-%s-check_ssh_%s\r\n", ssh_proto, rev_no);
|
||||
send (sd, buffer, strlen (buffer), MSG_DONTWAIT);
|
||||
if (verbose)
|
||||
printf ("%s\n", buffer);
|
||||
|
||||
if (remote_version && strcmp(remote_version, ssh_server)) {
|
||||
printf
|
||||
(_("SSH CRITICAL - %s (protocol %s) version mismatch, expected '%s'\n"),
|
||||
ssh_server, ssh_proto, remote_version);
|
||||
close(sd);
|
||||
exit (STATE_CRITICAL);
|
||||
}
|
||||
|
||||
if (remote_protocol && strcmp(remote_protocol, ssh_proto)) {
|
||||
printf
|
||||
(_("SSH CRITICAL - %s (protocol %s) protocol version mismatch, expected '%s'\n"),
|
||||
ssh_server, ssh_proto, remote_protocol);
|
||||
close(sd);
|
||||
exit (STATE_CRITICAL);
|
||||
}
|
||||
|
||||
elapsed_time = (double)deltime(tv) / 1.0e6;
|
||||
|
||||
if (remote_protocol && strcmp(remote_protocol, ssh_proto)) {
|
||||
printf
|
||||
(_("SSH OK - %s (protocol %s) | %s\n"),
|
||||
ssh_server, ssh_proto, fperfdata("time", elapsed_time, "s",
|
||||
FALSE, 0, FALSE, 0, TRUE, 0, TRUE, (int)socket_timeout));
|
||||
(_("SSH CRITICAL - %s (protocol %s) protocol version mismatch, expected '%s' | %s\n"),
|
||||
ssh_server, ssh_proto, remote_protocol, fperfdata("time", elapsed_time, "s",
|
||||
false, 0, false, 0, true, 0, true, (int)socket_timeout));
|
||||
close(sd);
|
||||
exit (STATE_OK);
|
||||
exit (STATE_CRITICAL);
|
||||
}
|
||||
elapsed_time = (double)deltime(tv) / 1.0e6;
|
||||
|
||||
printf
|
||||
(_("SSH OK - %s (protocol %s) | %s\n"),
|
||||
ssh_server, ssh_proto, fperfdata("time", elapsed_time, "s",
|
||||
false, 0, false, 0, true, 0, true, (int)socket_timeout));
|
||||
close(sd);
|
||||
exit (STATE_OK);
|
||||
}
|
||||
|
||||
|
||||
|
@ -293,7 +368,7 @@ print_help (void)
|
|||
|
||||
printf ("%s\n", _("Try to connect to an SSH server at specified server and port"));
|
||||
|
||||
printf ("\n\n");
|
||||
printf ("\n\n");
|
||||
|
||||
print_usage ();
|
||||
|
||||
|
@ -307,10 +382,10 @@ print_help (void)
|
|||
printf (UT_CONN_TIMEOUT, DEFAULT_SOCKET_TIMEOUT);
|
||||
|
||||
printf (" %s\n", "-r, --remote-version=STRING");
|
||||
printf (" %s\n", _("Alert if string doesn't match expected server version (ex: OpenSSH_3.9p1)"));
|
||||
printf (" %s\n", _("Alert if string doesn't match expected server version (ex: OpenSSH_3.9p1)"));
|
||||
|
||||
printf (" %s\n", "-P, --remote-protocol=STRING");
|
||||
printf (" %s\n", _("Alert if protocol doesn't match expected protocol version (ex: 2.0)"));
|
||||
printf (" %s\n", _("Alert if protocol doesn't match expected protocol version (ex: 2.0)"));
|
||||
|
||||
printf (UT_VERBOSE);
|
||||
|
||||
|
@ -322,7 +397,7 @@ print_help (void)
|
|||
void
|
||||
print_usage (void)
|
||||
{
|
||||
printf ("%s\n", _("Usage:"));
|
||||
printf ("%s\n", _("Usage:"));
|
||||
printf ("%s [-4|-6] [-t <timeout>] [-r <remote version>] [-p <port>] <host>\n", progname);
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
*
|
||||
* License: GPL
|
||||
* Copyright (c) 2000 Karl DeBisschop (kdebisschop@users.sourceforge.net)
|
||||
* Copyright (c) 2000-2007 Monitoring Plugins Development Team
|
||||
* Copyright (c) 2000-2024 Monitoring Plugins Development Team
|
||||
*
|
||||
* Description:
|
||||
*
|
||||
|
@ -28,7 +28,7 @@
|
|||
*****************************************************************************/
|
||||
|
||||
const char *progname = "check_swap";
|
||||
const char *copyright = "2000-2007";
|
||||
const char *copyright = "2000-2024";
|
||||
const char *email = "devel@monitoring-plugins.org";
|
||||
|
||||
#include "common.h"
|
||||
|
@ -52,9 +52,9 @@ const char *email = "devel@monitoring-plugins.org";
|
|||
#endif
|
||||
|
||||
typedef struct {
|
||||
int is_percentage;
|
||||
bool is_percentage;
|
||||
uint64_t value;
|
||||
} threshold_t;
|
||||
} threshold;
|
||||
|
||||
int check_swap (float free_swap_mb, float total_swap_mb);
|
||||
int process_arguments (int argc, char **argv);
|
||||
|
@ -62,10 +62,10 @@ int validate_arguments (void);
|
|||
void print_usage (void);
|
||||
void print_help (void);
|
||||
|
||||
threshold_t warn;
|
||||
threshold_t crit;
|
||||
threshold warn;
|
||||
threshold crit;
|
||||
int verbose;
|
||||
int allswaps;
|
||||
bool allswaps = false;
|
||||
int no_swap_state = STATE_CRITICAL;
|
||||
|
||||
int
|
||||
|
@ -383,10 +383,10 @@ main (int argc, char **argv)
|
|||
if (crit.is_percentage) crit_print = crit.value * (total_swap_mb *1024 *1024/100);
|
||||
|
||||
puts (perfdata_uint64 ("swap", free_swap_mb *1024 *1024, "B",
|
||||
TRUE, warn_print,
|
||||
TRUE, crit_print,
|
||||
TRUE, 0,
|
||||
TRUE, (long) total_swap_mb * 1024 * 1024));
|
||||
true, warn_print,
|
||||
true, crit_print,
|
||||
true, 0,
|
||||
true, (long) total_swap_mb * 1024 * 1024));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -399,28 +399,30 @@ check_swap(float free_swap_mb, float total_swap_mb)
|
|||
if (!total_swap_mb) return no_swap_state;
|
||||
|
||||
uint64_t free_swap = free_swap_mb * (1024 * 1024); /* Convert back to bytes as warn and crit specified in bytes */
|
||||
|
||||
if (!crit.is_percentage && crit.value >= free_swap) return STATE_CRITICAL;
|
||||
if (!warn.is_percentage && warn.value >= free_swap) return STATE_WARNING;
|
||||
|
||||
|
||||
uint64_t usage_percentage = ((total_swap_mb - free_swap_mb) / total_swap_mb) * 100;
|
||||
|
||||
if (crit.is_percentage &&
|
||||
crit.value != 0 &&
|
||||
usage_percentage >= (100 - crit.value))
|
||||
{
|
||||
return STATE_CRITICAL;
|
||||
}
|
||||
if (warn.value || crit.value) { /* Thresholds defined */
|
||||
if (!crit.is_percentage && crit.value >= free_swap) return STATE_CRITICAL;
|
||||
if (!warn.is_percentage && warn.value >= free_swap) return STATE_WARNING;
|
||||
|
||||
if (warn.is_percentage &&
|
||||
warn.value != 0 &&
|
||||
usage_percentage >= (100 - warn.value))
|
||||
{
|
||||
return STATE_WARNING;
|
||||
}
|
||||
if (crit.is_percentage &&
|
||||
crit.value != 0 &&
|
||||
usage_percentage >= (100 - crit.value))
|
||||
{
|
||||
return STATE_CRITICAL;
|
||||
}
|
||||
|
||||
return STATE_OK;
|
||||
if (warn.is_percentage &&
|
||||
warn.value != 0 &&
|
||||
usage_percentage >= (100 - warn.value))
|
||||
{
|
||||
return STATE_WARNING;
|
||||
}
|
||||
|
||||
return STATE_OK;
|
||||
} else { /* Without thresholds */
|
||||
return STATE_OK;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -443,9 +445,6 @@ process_arguments (int argc, char **argv)
|
|||
{0, 0, 0, 0}
|
||||
};
|
||||
|
||||
if (argc < 2)
|
||||
return ERROR;
|
||||
|
||||
while (1) {
|
||||
c = getopt_long (argc, argv, "+?Vvhac:w:n:", longopts, &option);
|
||||
|
||||
|
@ -465,7 +464,7 @@ process_arguments (int argc, char **argv)
|
|||
|
||||
if (optarg[length - 1] == '%') {
|
||||
/* It's percentage */
|
||||
warn.is_percentage = 1;
|
||||
warn.is_percentage = true;
|
||||
optarg[length - 1] = '\0';
|
||||
if (is_uint64(optarg, &warn.value)) {
|
||||
if (warn.value > 100) {
|
||||
|
@ -475,7 +474,7 @@ process_arguments (int argc, char **argv)
|
|||
break;
|
||||
} else {
|
||||
/* It's Bytes */
|
||||
warn.is_percentage = 0;
|
||||
warn.is_percentage = false;
|
||||
if (is_uint64(optarg, &warn.value)) {
|
||||
break;
|
||||
} else {
|
||||
|
@ -495,7 +494,7 @@ process_arguments (int argc, char **argv)
|
|||
|
||||
if (optarg[length - 1] == '%') {
|
||||
/* It's percentage */
|
||||
crit.is_percentage = 1;
|
||||
crit.is_percentage = true;
|
||||
optarg[length - 1] = '\0';
|
||||
if (is_uint64(optarg, &crit.value)) {
|
||||
if (crit.value> 100) {
|
||||
|
@ -505,7 +504,7 @@ process_arguments (int argc, char **argv)
|
|||
break;
|
||||
} else {
|
||||
/* It's Bytes */
|
||||
crit.is_percentage = 0;
|
||||
crit.is_percentage = false;
|
||||
if (is_uint64(optarg, &crit.value)) {
|
||||
break;
|
||||
} else {
|
||||
|
@ -514,7 +513,7 @@ process_arguments (int argc, char **argv)
|
|||
}
|
||||
}
|
||||
case 'a': /* all swap */
|
||||
allswaps = TRUE;
|
||||
allswaps = true;
|
||||
break;
|
||||
case 'n':
|
||||
if ((no_swap_state = mp_translate_state(optarg)) == ERROR) {
|
||||
|
@ -547,10 +546,7 @@ process_arguments (int argc, char **argv)
|
|||
int
|
||||
validate_arguments (void)
|
||||
{
|
||||
if (warn.value == 0 && crit.value == 0) {
|
||||
return ERROR;
|
||||
}
|
||||
else if ((warn.is_percentage == crit.is_percentage) && (warn.value < crit.value)) {
|
||||
if ((warn.is_percentage == crit.is_percentage) && (warn.value < crit.value)) {
|
||||
/* This is NOT triggered if warn and crit are different units, e.g warn is percentage
|
||||
* and crit is absolute. We cannot determine the condition at this point since we
|
||||
* dont know the value of total swap yet
|
||||
|
@ -595,6 +591,7 @@ print_help (void)
|
|||
printf ("\n");
|
||||
printf ("%s\n", _("Notes:"));
|
||||
printf (" %s\n", _("Both INTEGER and PERCENT thresholds can be specified, they are all checked."));
|
||||
printf (" %s\n", _("Without thresholds, the plugin shows free swap space and performance data, but always returns OK."));
|
||||
printf (" %s\n", _("On AIX, if -a is specified, uses lsps -a, otherwise uses lsps -s."));
|
||||
|
||||
printf (UT_SUPPORT);
|
||||
|
@ -605,6 +602,6 @@ void
|
|||
print_usage (void)
|
||||
{
|
||||
printf ("%s\n", _("Usage:"));
|
||||
printf (" %s [-av] -w <percent_free>%% -c <percent_free>%%\n",progname);
|
||||
printf (" -w <bytes_free> -c <bytes_free> [-n <state>]\n");
|
||||
printf (" %s [-av] [-w <percent_free>%%] [-c <percent_free>%%]\n",progname);
|
||||
printf (" [-w <bytes_free>] [-c <bytes_free>] [-n <state>]\n");
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ const char *email = "devel@monitoring-plugins.org";
|
|||
#include <sys/select.h>
|
||||
|
||||
#ifdef HAVE_SSL
|
||||
static int check_cert = FALSE;
|
||||
static bool check_cert = false;
|
||||
static int days_till_exp_warn, days_till_exp_crit;
|
||||
# define my_recv(buf, len) ((flags & FLAG_SSL) ? np_net_ssl_read(buf, len) : read(sd, buf, len))
|
||||
# define my_send(buf, len) ((flags & FLAG_SSL) ? np_net_ssl_write(buf, len) : send(sd, buf, len, 0))
|
||||
|
@ -65,12 +65,12 @@ static int READ_TIMEOUT = 2;
|
|||
|
||||
static int server_port = 0;
|
||||
static char *server_address = NULL;
|
||||
static int host_specified = FALSE;
|
||||
static bool host_specified = false;
|
||||
static char *server_send = NULL;
|
||||
static char *server_quit = NULL;
|
||||
static char **server_expect;
|
||||
static size_t server_expect_count = 0;
|
||||
static size_t maxbytes = 0;
|
||||
static ssize_t maxbytes = 0;
|
||||
static char **warn_codes = NULL;
|
||||
static size_t warn_codes_count = 0;
|
||||
static char **crit_codes = NULL;
|
||||
|
@ -88,7 +88,7 @@ static int match_flags = NP_MATCH_EXACT;
|
|||
|
||||
#ifdef HAVE_SSL
|
||||
static char *sni = NULL;
|
||||
static int sni_specified = FALSE;
|
||||
static bool sni_specified = false;
|
||||
#endif
|
||||
|
||||
#define FLAG_SSL 0x01
|
||||
|
@ -102,11 +102,9 @@ int
|
|||
main (int argc, char **argv)
|
||||
{
|
||||
int result = STATE_UNKNOWN;
|
||||
int i;
|
||||
char *status = NULL;
|
||||
struct timeval tv;
|
||||
struct timeval timeout;
|
||||
size_t len;
|
||||
int match = -1;
|
||||
fd_set rfds;
|
||||
|
||||
|
@ -121,10 +119,10 @@ main (int argc, char **argv)
|
|||
if(progname != NULL) progname++;
|
||||
else progname = argv[0];
|
||||
|
||||
len = strlen(progname);
|
||||
if(len > 6 && !memcmp(progname, "check_", 6)) {
|
||||
size_t prog_name_len = strlen(progname);
|
||||
if(prog_name_len > 6 && !memcmp(progname, "check_", 6)) {
|
||||
SERVICE = strdup(progname + 6);
|
||||
for(i = 0; i < len - 6; i++)
|
||||
for(size_t i = 0; i < prog_name_len - 6; i++)
|
||||
SERVICE[i] = toupper(SERVICE[i]);
|
||||
}
|
||||
|
||||
|
@ -247,7 +245,7 @@ main (int argc, char **argv)
|
|||
#ifdef HAVE_SSL
|
||||
if (flags & FLAG_SSL){
|
||||
result = np_net_ssl_init_with_hostname(sd, (sni_specified ? sni : NULL));
|
||||
if (result == STATE_OK && check_cert == TRUE) {
|
||||
if (result == STATE_OK && check_cert) {
|
||||
result = np_net_ssl_check_cert(days_till_exp_warn, days_till_exp_crit);
|
||||
}
|
||||
}
|
||||
|
@ -275,19 +273,21 @@ main (int argc, char **argv)
|
|||
printf("Quit string: %s\n", server_quit);
|
||||
}
|
||||
printf("server_expect_count: %d\n", (int)server_expect_count);
|
||||
for(i = 0; i < server_expect_count; i++)
|
||||
printf("\t%d: %s\n", i, server_expect[i]);
|
||||
for(size_t i = 0; i < server_expect_count; i++)
|
||||
printf("\t%zd: %s\n", i, server_expect[i]);
|
||||
}
|
||||
|
||||
/* if(len) later on, we know we have a non-NULL response */
|
||||
len = 0;
|
||||
ssize_t len = 0;
|
||||
|
||||
if (server_expect_count) {
|
||||
ssize_t received = 0;
|
||||
|
||||
/* watch for the expect string */
|
||||
while ((i = my_recv(buffer, sizeof(buffer))) > 0) {
|
||||
status = realloc(status, len + i + 1);
|
||||
memcpy(&status[len], buffer, i);
|
||||
len += i;
|
||||
while ((received = my_recv(buffer, sizeof(buffer))) > 0) {
|
||||
status = realloc(status, len + received + 1);
|
||||
memcpy(&status[len], buffer, received);
|
||||
len += received;
|
||||
status[len] = '\0';
|
||||
|
||||
/* stop reading if user-forced */
|
||||
|
@ -307,6 +307,7 @@ main (int argc, char **argv)
|
|||
if(select(sd + 1, &rfds, NULL, NULL, &timeout) <= 0)
|
||||
break;
|
||||
}
|
||||
|
||||
if (match == NP_MATCH_RETRY)
|
||||
match = NP_MATCH_FAILURE;
|
||||
|
||||
|
@ -378,18 +379,18 @@ main (int argc, char **argv)
|
|||
if(match == NP_MATCH_FAILURE)
|
||||
printf ("|%s",
|
||||
fperfdata ("time", elapsed_time, "s",
|
||||
(flags & FLAG_TIME_WARN ? TRUE : FALSE), 0,
|
||||
(flags & FLAG_TIME_CRIT ? TRUE : FALSE), 0,
|
||||
TRUE, 0,
|
||||
TRUE, socket_timeout)
|
||||
(flags & FLAG_TIME_WARN ? true : false), 0,
|
||||
(flags & FLAG_TIME_CRIT ? true : false), 0,
|
||||
true, 0,
|
||||
true, socket_timeout)
|
||||
);
|
||||
else
|
||||
printf("|%s",
|
||||
fperfdata ("time", elapsed_time, "s",
|
||||
(flags & FLAG_TIME_WARN ? TRUE : FALSE), warning_time,
|
||||
(flags & FLAG_TIME_CRIT ? TRUE : FALSE), critical_time,
|
||||
TRUE, 0,
|
||||
TRUE, socket_timeout)
|
||||
(flags & FLAG_TIME_WARN ? true : false), warning_time,
|
||||
(flags & FLAG_TIME_CRIT ? true : false), critical_time,
|
||||
true, 0,
|
||||
true, socket_timeout)
|
||||
);
|
||||
|
||||
putchar('\n');
|
||||
|
@ -399,11 +400,9 @@ main (int argc, char **argv)
|
|||
|
||||
|
||||
/* process command-line arguments */
|
||||
static int
|
||||
process_arguments (int argc, char **argv)
|
||||
{
|
||||
static int process_arguments (int argc, char **argv) {
|
||||
int c;
|
||||
int escape = 0;
|
||||
bool escape = false;
|
||||
char *temp;
|
||||
|
||||
enum {
|
||||
|
@ -492,7 +491,7 @@ process_arguments (int argc, char **argv)
|
|||
#endif
|
||||
break;
|
||||
case 'H': /* hostname */
|
||||
host_specified = TRUE;
|
||||
host_specified = true;
|
||||
server_address = optarg;
|
||||
break;
|
||||
case 'c': /* critical */
|
||||
|
@ -527,7 +526,7 @@ process_arguments (int argc, char **argv)
|
|||
server_port = atoi (optarg);
|
||||
break;
|
||||
case 'E':
|
||||
escape = 1;
|
||||
escape = true;
|
||||
break;
|
||||
case 's':
|
||||
if (escape)
|
||||
|
@ -601,7 +600,7 @@ process_arguments (int argc, char **argv)
|
|||
usage2 (_("Invalid certificate expiration period"), optarg);
|
||||
days_till_exp_warn = atoi (optarg);
|
||||
}
|
||||
check_cert = TRUE;
|
||||
check_cert = true;
|
||||
flags |= FLAG_SSL;
|
||||
break;
|
||||
# endif /* USE_OPENSSL */
|
||||
|
@ -617,7 +616,7 @@ process_arguments (int argc, char **argv)
|
|||
case SNI_OPTION:
|
||||
#ifdef HAVE_SSL
|
||||
flags |= FLAG_SSL;
|
||||
sni_specified = TRUE;
|
||||
sni_specified = true;
|
||||
sni = optarg;
|
||||
#else
|
||||
die (STATE_UNKNOWN, _("Invalid option - SSL is not available"));
|
||||
|
@ -630,15 +629,15 @@ process_arguments (int argc, char **argv)
|
|||
}
|
||||
|
||||
c = optind;
|
||||
if(host_specified == FALSE && c < argc)
|
||||
if(!host_specified && c < argc)
|
||||
server_address = strdup (argv[c++]);
|
||||
|
||||
if (server_address == NULL)
|
||||
usage4 (_("You must provide a server address"));
|
||||
else if (server_address[0] != '/' && is_host (server_address) == FALSE)
|
||||
else if (server_address[0] != '/' && !is_host(server_address))
|
||||
die (STATE_CRITICAL, "%s %s - %s: %s\n", SERVICE, state_text(STATE_CRITICAL), _("Invalid hostname, address or socket"), server_address);
|
||||
|
||||
return TRUE;
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -45,16 +45,16 @@ enum {
|
|||
uint32_t raw_server_time;
|
||||
unsigned long server_time, diff_time;
|
||||
int warning_time = 0;
|
||||
int check_warning_time = FALSE;
|
||||
bool check_warning_time = false;
|
||||
int critical_time = 0;
|
||||
int check_critical_time = FALSE;
|
||||
bool check_critical_time = false;
|
||||
unsigned long warning_diff = 0;
|
||||
int check_warning_diff = FALSE;
|
||||
bool check_warning_diff = false;
|
||||
unsigned long critical_diff = 0;
|
||||
int check_critical_diff = FALSE;
|
||||
bool check_critical_diff = false;
|
||||
int server_port = TIME_PORT;
|
||||
char *server_address = NULL;
|
||||
int use_udp = FALSE;
|
||||
bool use_udp = false;
|
||||
|
||||
int process_arguments (int, char **);
|
||||
void print_help (void);
|
||||
|
@ -92,9 +92,9 @@ main (int argc, char **argv)
|
|||
}
|
||||
|
||||
if (result != STATE_OK) {
|
||||
if (check_critical_time == TRUE)
|
||||
if (check_critical_time)
|
||||
result = STATE_CRITICAL;
|
||||
else if (check_warning_time == TRUE)
|
||||
else if (check_warning_time)
|
||||
result = STATE_WARNING;
|
||||
else
|
||||
result = STATE_UNKNOWN;
|
||||
|
@ -105,9 +105,9 @@ main (int argc, char **argv)
|
|||
|
||||
if (use_udp) {
|
||||
if (send (sd, "", 0, 0) < 0) {
|
||||
if (check_critical_time == TRUE)
|
||||
if (check_critical_time)
|
||||
result = STATE_CRITICAL;
|
||||
else if (check_warning_time == TRUE)
|
||||
else if (check_warning_time)
|
||||
result = STATE_WARNING;
|
||||
else
|
||||
result = STATE_UNKNOWN;
|
||||
|
@ -129,9 +129,9 @@ main (int argc, char **argv)
|
|||
|
||||
/* return a WARNING status if we couldn't read any data */
|
||||
if (result <= 0) {
|
||||
if (check_critical_time == TRUE)
|
||||
if (check_critical_time)
|
||||
result = STATE_CRITICAL;
|
||||
else if (check_warning_time == TRUE)
|
||||
else if (check_warning_time)
|
||||
result = STATE_WARNING;
|
||||
else
|
||||
result = STATE_UNKNOWN;
|
||||
|
@ -143,9 +143,9 @@ main (int argc, char **argv)
|
|||
result = STATE_OK;
|
||||
|
||||
conntime = (end_time - start_time);
|
||||
if (check_critical_time == TRUE && conntime > critical_time)
|
||||
if (check_critical_time&& conntime > critical_time)
|
||||
result = STATE_CRITICAL;
|
||||
else if (check_warning_time == TRUE && conntime > warning_time)
|
||||
else if (check_warning_time && conntime > warning_time)
|
||||
result = STATE_WARNING;
|
||||
|
||||
if (result != STATE_OK)
|
||||
|
@ -154,7 +154,7 @@ main (int argc, char **argv)
|
|||
perfdata ("time", (long)conntime, "s",
|
||||
check_warning_time, (long)warning_time,
|
||||
check_critical_time, (long)critical_time,
|
||||
TRUE, 0, FALSE, 0));
|
||||
true, 0, false, 0));
|
||||
|
||||
server_time = ntohl (raw_server_time) - UNIX_EPOCH;
|
||||
if (server_time > (unsigned long)end_time)
|
||||
|
@ -162,9 +162,9 @@ main (int argc, char **argv)
|
|||
else
|
||||
diff_time = (unsigned long)end_time - server_time;
|
||||
|
||||
if (check_critical_diff == TRUE && diff_time > critical_diff)
|
||||
if (check_critical_diff&& diff_time > critical_diff)
|
||||
result = STATE_CRITICAL;
|
||||
else if (check_warning_diff == TRUE && diff_time > warning_diff)
|
||||
else if (check_warning_diff&& diff_time > warning_diff)
|
||||
result = STATE_WARNING;
|
||||
|
||||
printf (_("TIME %s - %lu second time difference|%s %s\n"),
|
||||
|
@ -172,11 +172,11 @@ main (int argc, char **argv)
|
|||
perfdata ("time", (long)conntime, "s",
|
||||
check_warning_time, (long)warning_time,
|
||||
check_critical_time, (long)critical_time,
|
||||
TRUE, 0, FALSE, 0),
|
||||
true, 0, false, 0),
|
||||
perfdata ("offset", diff_time, "s",
|
||||
check_warning_diff, warning_diff,
|
||||
check_critical_diff, critical_diff,
|
||||
TRUE, 0, FALSE, 0));
|
||||
true, 0, false, 0));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -219,7 +219,7 @@ process_arguments (int argc, char **argv)
|
|||
strcpy (argv[c], "-C");
|
||||
}
|
||||
|
||||
while (1) {
|
||||
while (true) {
|
||||
c = getopt_long (argc, argv, "hVH:w:c:W:C:p:t:u", longopts,
|
||||
&option);
|
||||
|
||||
|
@ -236,19 +236,19 @@ process_arguments (int argc, char **argv)
|
|||
print_revision (progname, NP_VERSION);
|
||||
exit (STATE_UNKNOWN);
|
||||
case 'H': /* hostname */
|
||||
if (is_host (optarg) == FALSE)
|
||||
if (!is_host (optarg))
|
||||
usage2 (_("Invalid hostname/address"), optarg);
|
||||
server_address = optarg;
|
||||
break;
|
||||
case 'w': /* warning-variance */
|
||||
if (is_intnonneg (optarg)) {
|
||||
warning_diff = strtoul (optarg, NULL, 10);
|
||||
check_warning_diff = TRUE;
|
||||
check_warning_diff = true;
|
||||
}
|
||||
else if (strspn (optarg, "0123456789:,") > 0) {
|
||||
if (sscanf (optarg, "%lu%*[:,]%d", &warning_diff, &warning_time) == 2) {
|
||||
check_warning_diff = TRUE;
|
||||
check_warning_time = TRUE;
|
||||
check_warning_diff = true;
|
||||
check_warning_time = true;
|
||||
}
|
||||
else {
|
||||
usage4 (_("Warning thresholds must be a positive integer"));
|
||||
|
@ -261,13 +261,13 @@ process_arguments (int argc, char **argv)
|
|||
case 'c': /* critical-variance */
|
||||
if (is_intnonneg (optarg)) {
|
||||
critical_diff = strtoul (optarg, NULL, 10);
|
||||
check_critical_diff = TRUE;
|
||||
check_critical_diff = true;
|
||||
}
|
||||
else if (strspn (optarg, "0123456789:,") > 0) {
|
||||
if (sscanf (optarg, "%lu%*[:,]%d", &critical_diff, &critical_time) ==
|
||||
2) {
|
||||
check_critical_diff = TRUE;
|
||||
check_critical_time = TRUE;
|
||||
check_critical_diff = true;
|
||||
check_critical_time = true;
|
||||
}
|
||||
else {
|
||||
usage4 (_("Critical thresholds must be a positive integer"));
|
||||
|
@ -282,14 +282,14 @@ process_arguments (int argc, char **argv)
|
|||
usage4 (_("Warning threshold must be a positive integer"));
|
||||
else
|
||||
warning_time = atoi (optarg);
|
||||
check_warning_time = TRUE;
|
||||
check_warning_time = true;
|
||||
break;
|
||||
case 'C': /* critical-connect */
|
||||
if (!is_intnonneg (optarg))
|
||||
usage4 (_("Critical threshold must be a positive integer"));
|
||||
else
|
||||
critical_time = atoi (optarg);
|
||||
check_critical_time = TRUE;
|
||||
check_critical_time = true;
|
||||
break;
|
||||
case 'p': /* port */
|
||||
if (!is_intnonneg (optarg))
|
||||
|
@ -304,14 +304,14 @@ process_arguments (int argc, char **argv)
|
|||
socket_timeout = atoi (optarg);
|
||||
break;
|
||||
case 'u': /* udp */
|
||||
use_udp = TRUE;
|
||||
use_udp = true;
|
||||
}
|
||||
}
|
||||
|
||||
c = optind;
|
||||
if (server_address == NULL) {
|
||||
if (argc > c) {
|
||||
if (is_host (argv[c]) == FALSE)
|
||||
if (!is_host (argv[c]))
|
||||
usage2 (_("Invalid hostname/address"), optarg);
|
||||
server_address = argv[c];
|
||||
}
|
||||
|
|
1091
plugins/check_ups.c
1091
plugins/check_ups.c
File diff suppressed because it is too large
Load diff
|
@ -179,7 +179,7 @@ main (int argc, char **argv)
|
|||
printf (_("USERS %s - %d users currently logged in |%s\n"),
|
||||
state_text(result), users,
|
||||
sperfdata_int("users", users, "", warning_range,
|
||||
critical_range, TRUE, 0, FALSE, 0));
|
||||
critical_range, true, 0, false, 0));
|
||||
}
|
||||
|
||||
return result;
|
||||
|
@ -202,7 +202,7 @@ process_arguments (int argc, char **argv)
|
|||
if (argc < 2)
|
||||
usage ("\n");
|
||||
|
||||
while (1) {
|
||||
while (true) {
|
||||
c = getopt_long (argc, argv, "+hVvc:w:", longopts, &option);
|
||||
|
||||
if (c == -1 || c == EOF || c == 1)
|
||||
|
@ -227,18 +227,23 @@ process_arguments (int argc, char **argv)
|
|||
}
|
||||
|
||||
c = optind;
|
||||
|
||||
if (warning_range == NULL && argc > c)
|
||||
warning_range = argv[c++];
|
||||
|
||||
if (critical_range == NULL && argc > c)
|
||||
critical_range = argv[c++];
|
||||
|
||||
/* this will abort in case of invalid ranges */
|
||||
set_thresholds (&thlds, warning_range, critical_range);
|
||||
|
||||
if (thlds->warning->end < 0)
|
||||
usage4 (_("Warning threshold must be a positive integer"));
|
||||
if (thlds->critical->end < 0)
|
||||
usage4 (_("Critical threshold must be a positive integer"));
|
||||
if (!thlds->warning) {
|
||||
usage4 (_("Warning threshold must be a valid range expression"));
|
||||
}
|
||||
|
||||
if (!thlds->critical) {
|
||||
usage4 (_("Critical threshold must be a valid range expression"));
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
@ -261,10 +266,10 @@ print_help (void)
|
|||
printf (UT_HELP_VRSN);
|
||||
printf (UT_EXTRA_OPTS);
|
||||
|
||||
printf (" %s\n", "-w, --warning=INTEGER");
|
||||
printf (" %s\n", _("Set WARNING status if more than INTEGER users are logged in"));
|
||||
printf (" %s\n", "-c, --critical=INTEGER");
|
||||
printf (" %s\n", _("Set CRITICAL status if more than INTEGER users are logged in"));
|
||||
printf (" %s\n", "-w, --warning=RANGE_EXPRESSION");
|
||||
printf (" %s\n", _("Set WARNING status if number of logged in users violates RANGE_EXPRESSION"));
|
||||
printf (" %s\n", "-c, --critical=RANGE_EXPRESSION");
|
||||
printf (" %s\n", _("Set CRITICAL status if number of logged in users violates RANGE_EXPRESSION"));
|
||||
|
||||
printf (UT_SUPPORT);
|
||||
}
|
||||
|
|
|
@ -184,14 +184,6 @@ enum {
|
|||
ERROR = -1
|
||||
};
|
||||
|
||||
/* AIX seems to have this defined somewhere else */
|
||||
#ifndef FALSE
|
||||
enum {
|
||||
FALSE,
|
||||
TRUE
|
||||
};
|
||||
#endif
|
||||
|
||||
enum {
|
||||
STATE_OK,
|
||||
STATE_WARNING,
|
||||
|
|
|
@ -47,7 +47,7 @@ static const char **process_arguments (int, char **);
|
|||
void validate_arguments (char **);
|
||||
void print_help (void);
|
||||
void print_usage (void);
|
||||
int subst_text = FALSE;
|
||||
bool subst_text = false;
|
||||
|
||||
static int state[4] = {
|
||||
STATE_OK,
|
||||
|
@ -63,7 +63,6 @@ main (int argc, char **argv)
|
|||
char *sub;
|
||||
char **command_line;
|
||||
output chld_out, chld_err;
|
||||
int i;
|
||||
|
||||
setlocale (LC_ALL, "");
|
||||
bindtextdomain (PACKAGE, LOCALEDIR);
|
||||
|
@ -86,7 +85,7 @@ main (int argc, char **argv)
|
|||
result = cmd_run_array (command_line, &chld_out, &chld_err, 0);
|
||||
}
|
||||
if (chld_err.lines > 0) {
|
||||
for (i = 0; i < chld_err.lines; i++) {
|
||||
for (size_t i = 0; i < chld_err.lines; i++) {
|
||||
fprintf (stderr, "%s\n", chld_err.line[i]);
|
||||
}
|
||||
}
|
||||
|
@ -95,7 +94,7 @@ main (int argc, char **argv)
|
|||
if (chld_out.lines == 0)
|
||||
die (max_state_alt (result, STATE_UNKNOWN), _("No data returned from command\n"));
|
||||
|
||||
for (i = 0; i < chld_out.lines; i++) {
|
||||
for (size_t i = 0; i < chld_out.lines; i++) {
|
||||
if (subst_text && result >= 0 && result <= 4 && result != state[result]) {
|
||||
/* Loop over each match found */
|
||||
while ((sub = strstr (chld_out.line[i], state_text (result)))) {
|
||||
|
@ -122,7 +121,7 @@ static const char **
|
|||
process_arguments (int argc, char **argv)
|
||||
{
|
||||
int c;
|
||||
int permute = TRUE;
|
||||
bool permute = true;
|
||||
|
||||
int option = 0;
|
||||
static struct option longopts[] = {
|
||||
|
@ -168,26 +167,26 @@ process_arguments (int argc, char **argv)
|
|||
case 'o': /* replacement for OK */
|
||||
if ((state[STATE_OK] = mp_translate_state(optarg)) == ERROR)
|
||||
usage4 (_("Ok must be a valid state name (OK, WARNING, CRITICAL, UNKNOWN) or integer (0-3)."));
|
||||
permute = FALSE;
|
||||
permute = false;
|
||||
break;
|
||||
|
||||
case 'w': /* replacement for WARNING */
|
||||
if ((state[STATE_WARNING] = mp_translate_state(optarg)) == ERROR)
|
||||
usage4 (_("Warning must be a valid state name (OK, WARNING, CRITICAL, UNKNOWN) or integer (0-3)."));
|
||||
permute = FALSE;
|
||||
permute = false;
|
||||
break;
|
||||
case 'c': /* replacement for CRITICAL */
|
||||
if ((state[STATE_CRITICAL] = mp_translate_state(optarg)) == ERROR)
|
||||
usage4 (_("Critical must be a valid state name (OK, WARNING, CRITICAL, UNKNOWN) or integer (0-3)."));
|
||||
permute = FALSE;
|
||||
permute = false;
|
||||
break;
|
||||
case 'u': /* replacement for UNKNOWN */
|
||||
if ((state[STATE_UNKNOWN] = mp_translate_state(optarg)) == ERROR)
|
||||
usage4 (_("Unknown must be a valid state name (OK, WARNING, CRITICAL, UNKNOWN) or integer (0-3)."));
|
||||
permute = FALSE;
|
||||
permute = false;
|
||||
break;
|
||||
case 's': /* Substitute status text */
|
||||
subst_text = TRUE;
|
||||
subst_text = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -221,8 +220,10 @@ print_help (void)
|
|||
|
||||
printf (COPYRIGHT, copyright, email);
|
||||
|
||||
printf ("%s\n", _("Negates the status of a plugin (returns OK for CRITICAL and vice-versa)."));
|
||||
printf ("%s\n", _("Additional switches can be used to control which state becomes what."));
|
||||
printf ("%s\n", _("Negates only the return code of a plugin (returns OK for CRITICAL and vice-versa) by default."));
|
||||
printf ("%s\n", _("Additional switches can be used to control:\n"));
|
||||
printf ("\t - which state becomes what\n");
|
||||
printf ("\t - changing the plugin output text to match the return code");
|
||||
|
||||
printf ("\n\n");
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ unsigned int socket_timeout = DEFAULT_SOCKET_TIMEOUT;
|
|||
unsigned int socket_timeout_state = STATE_CRITICAL;
|
||||
|
||||
int econn_refuse_state = STATE_CRITICAL;
|
||||
int was_refused = FALSE;
|
||||
bool was_refused = false;
|
||||
#if USE_IPV6
|
||||
int address_family = AF_UNSPEC;
|
||||
#else
|
||||
|
@ -215,14 +215,14 @@ np_net_connect (const char *host_name, int port, int *sd, int proto)
|
|||
result = connect (*sd, r->ai_addr, r->ai_addrlen);
|
||||
|
||||
if (result == 0) {
|
||||
was_refused = FALSE;
|
||||
was_refused = false;
|
||||
break;
|
||||
}
|
||||
|
||||
if (result < 0) {
|
||||
switch (errno) {
|
||||
case ECONNREFUSED:
|
||||
was_refused = TRUE;
|
||||
was_refused = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -246,7 +246,7 @@ np_net_connect (const char *host_name, int port, int *sd, int proto)
|
|||
}
|
||||
result = connect(*sd, (struct sockaddr *)&su, sizeof(su));
|
||||
if (result < 0 && errno == ECONNREFUSED)
|
||||
was_refused = TRUE;
|
||||
was_refused = true;
|
||||
}
|
||||
|
||||
if (result == 0)
|
||||
|
@ -326,13 +326,11 @@ send_request (int sd, int proto, const char *send_buffer, char *recv_buffer, int
|
|||
}
|
||||
|
||||
|
||||
int
|
||||
is_host (const char *address)
|
||||
{
|
||||
bool is_host (const char *address) {
|
||||
if (is_addr (address) || is_hostname (address))
|
||||
return (TRUE);
|
||||
return (true);
|
||||
|
||||
return (FALSE);
|
||||
return (false);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -342,20 +340,18 @@ host_or_die(const char *str)
|
|||
usage_va(_("Invalid hostname/address - %s"), str);
|
||||
}
|
||||
|
||||
int
|
||||
is_addr (const char *address)
|
||||
{
|
||||
bool is_addr (const char *address) {
|
||||
#ifdef USE_IPV6
|
||||
if (address_family == AF_INET && is_inet_addr (address))
|
||||
return TRUE;
|
||||
return true;
|
||||
else if (address_family == AF_INET6 && is_inet6_addr (address))
|
||||
return TRUE;
|
||||
return true;
|
||||
#else
|
||||
if (is_inet_addr (address))
|
||||
return (TRUE);
|
||||
return (true);
|
||||
#endif
|
||||
|
||||
return (FALSE);
|
||||
return (false);
|
||||
}
|
||||
|
||||
int
|
||||
|
@ -370,10 +366,10 @@ dns_lookup (const char *in, struct sockaddr_storage *ss, int family)
|
|||
|
||||
retval = getaddrinfo (in, NULL, &hints, &res);
|
||||
if (retval != 0)
|
||||
return FALSE;
|
||||
return false;
|
||||
|
||||
if (ss != NULL)
|
||||
memcpy (ss, res->ai_addr, res->ai_addrlen);
|
||||
freeaddrinfo (res);
|
||||
return TRUE;
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -73,8 +73,8 @@ int send_request (int sd, int proto, const char *send_buffer, char *recv_buffer,
|
|||
|
||||
|
||||
/* "is_*" wrapper macros and functions */
|
||||
int is_host (const char *);
|
||||
int is_addr (const char *);
|
||||
bool is_host (const char *);
|
||||
bool is_addr (const char *);
|
||||
int dns_lookup (const char *, struct sockaddr_storage *, int);
|
||||
void host_or_die(const char *str);
|
||||
#define resolve_host_or_addr(addr, family) dns_lookup(addr, NULL, family)
|
||||
|
@ -89,7 +89,7 @@ void host_or_die(const char *str);
|
|||
extern unsigned int socket_timeout;
|
||||
extern unsigned int socket_timeout_state;
|
||||
extern int econn_refuse_state;
|
||||
extern int was_refused;
|
||||
extern bool was_refused;
|
||||
extern int address_family;
|
||||
|
||||
void socket_timeout_alarm_handler (int) __attribute__((noreturn));
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# Makefile.in generated by automake 1.16.3 from Makefile.am.
|
||||
# Makefile.in generated by automake 1.16.5 from Makefile.am.
|
||||
# @configure_input@
|
||||
|
||||
# Copyright (C) 1994-2020 Free Software Foundation, Inc.
|
||||
# Copyright (C) 1994-2021 Free Software Foundation, Inc.
|
||||
|
||||
# This Makefile.in is free software; the Free Software Foundation
|
||||
# gives unlimited permission to copy and/or distribute it,
|
||||
|
@ -164,8 +164,7 @@ am__aclocal_m4_deps = $(top_srcdir)/m4/libcurl.m4 \
|
|||
$(top_srcdir)/gl/m4/nocrash.m4 $(top_srcdir)/gl/m4/off_t.m4 \
|
||||
$(top_srcdir)/gl/m4/open-cloexec.m4 \
|
||||
$(top_srcdir)/gl/m4/open-slash.m4 $(top_srcdir)/gl/m4/open.m4 \
|
||||
$(top_srcdir)/gl/m4/pathmax.m4 $(top_srcdir)/gl/m4/pid_t.m4 \
|
||||
$(top_srcdir)/gl/m4/printf.m4 \
|
||||
$(top_srcdir)/gl/m4/pathmax.m4 $(top_srcdir)/gl/m4/printf.m4 \
|
||||
$(top_srcdir)/gl/m4/pthread_rwlock_rdlock.m4 \
|
||||
$(top_srcdir)/gl/m4/realloc.m4 \
|
||||
$(top_srcdir)/gl/m4/reallocarray.m4 \
|
||||
|
@ -178,7 +177,6 @@ am__aclocal_m4_deps = $(top_srcdir)/m4/libcurl.m4 \
|
|||
$(top_srcdir)/gl/m4/sockets.m4 $(top_srcdir)/gl/m4/socklen.m4 \
|
||||
$(top_srcdir)/gl/m4/sockpfaf.m4 $(top_srcdir)/gl/m4/ssize_t.m4 \
|
||||
$(top_srcdir)/gl/m4/stat-time.m4 $(top_srcdir)/gl/m4/stat.m4 \
|
||||
$(top_srcdir)/gl/m4/std-gnu11.m4 \
|
||||
$(top_srcdir)/gl/m4/stdalign.m4 \
|
||||
$(top_srcdir)/gl/m4/stddef_h.m4 $(top_srcdir)/gl/m4/stdint.m4 \
|
||||
$(top_srcdir)/gl/m4/stdint_h.m4 $(top_srcdir)/gl/m4/stdio_h.m4 \
|
||||
|
@ -196,7 +194,6 @@ am__aclocal_m4_deps = $(top_srcdir)/m4/libcurl.m4 \
|
|||
$(top_srcdir)/gl/m4/time_r.m4 $(top_srcdir)/gl/m4/timegm.m4 \
|
||||
$(top_srcdir)/gl/m4/ungetc.m4 $(top_srcdir)/gl/m4/unistd_h.m4 \
|
||||
$(top_srcdir)/gl/m4/unlocked-io.m4 \
|
||||
$(top_srcdir)/gl/m4/vararrays.m4 \
|
||||
$(top_srcdir)/gl/m4/vasnprintf.m4 \
|
||||
$(top_srcdir)/gl/m4/vasprintf.m4 \
|
||||
$(top_srcdir)/gl/m4/visibility.m4 \
|
||||
|
@ -286,8 +283,6 @@ am__define_uniq_tagged_files = \
|
|||
unique=`for i in $$list; do \
|
||||
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
|
||||
done | $(am__uniquify_input)`
|
||||
ETAGS = etags
|
||||
CTAGS = ctags
|
||||
am__DIST_COMMON = $(srcdir)/Makefile.in \
|
||||
$(top_srcdir)/build-aux/depcomp \
|
||||
$(top_srcdir)/build-aux/mkinstalldirs
|
||||
|
@ -318,6 +313,8 @@ CFLAGS = @CFLAGS@
|
|||
CFLAG_VISIBILITY = @CFLAG_VISIBILITY@
|
||||
CPP = @CPP@
|
||||
CPPFLAGS = @CPPFLAGS@
|
||||
CSCOPE = @CSCOPE@
|
||||
CTAGS = @CTAGS@
|
||||
CYGPATH_W = @CYGPATH_W@
|
||||
DBILIBS = @DBILIBS@
|
||||
DEFS = @DEFS@
|
||||
|
@ -337,6 +334,7 @@ ENOLINK_VALUE = @ENOLINK_VALUE@
|
|||
EOVERFLOW_HIDDEN = @EOVERFLOW_HIDDEN@
|
||||
EOVERFLOW_VALUE = @EOVERFLOW_VALUE@
|
||||
ERRNO_H = @ERRNO_H@
|
||||
ETAGS = @ETAGS@
|
||||
EXEEXT = @EXEEXT@
|
||||
EXTRAS = @EXTRAS@
|
||||
EXTRAS_ROOT = @EXTRAS_ROOT@
|
||||
|
@ -1708,6 +1706,8 @@ install_sh = @install_sh@
|
|||
libdir = @libdir@
|
||||
libexecdir = @libexecdir@
|
||||
localedir = @localedir@
|
||||
localedir_c = @localedir_c@
|
||||
localedir_c_make = @localedir_c_make@
|
||||
localstatedir = @localstatedir@
|
||||
mandir = @mandir@
|
||||
mkdir_p = @mkdir_p@
|
||||
|
@ -1863,7 +1863,6 @@ cscopelist-am: $(am__tagged_files)
|
|||
|
||||
distclean-tags:
|
||||
-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
|
||||
|
||||
distdir: $(BUILT_SOURCES)
|
||||
$(MAKE) $(AM_MAKEFLAGS) distdir-am
|
||||
|
||||
|
|
|
@ -105,7 +105,7 @@ spopen (const char *cmdstring)
|
|||
#endif
|
||||
|
||||
env[0] = strdup("LC_ALL=C");
|
||||
env[1] = '\0';
|
||||
env[1] = NULL;
|
||||
|
||||
/* if no command was passed, return with no error */
|
||||
if (cmdstring == NULL)
|
||||
|
|
|
@ -115,7 +115,7 @@ np_runcmd_open(const char *cmdstring, int *pfd, int *pfderr)
|
|||
if(!np_pids) NP_RUNCMD_INIT;
|
||||
|
||||
env[0] = strdup("LC_ALL=C");
|
||||
env[1] = '\0';
|
||||
env[1] = NULL;
|
||||
|
||||
/* make copy of command string so strtok() doesn't silently modify it */
|
||||
/* (the calling program may want to access it later) */
|
||||
|
@ -240,13 +240,12 @@ np_runcmd_close(int fd)
|
|||
void
|
||||
runcmd_timeout_alarm_handler (int signo)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
if (signo == SIGALRM)
|
||||
puts(_("CRITICAL - Plugin timed out while executing system call"));
|
||||
|
||||
long maxfd = mp_open_max();
|
||||
if(np_pids) for(i = 0; i < maxfd; i++) {
|
||||
if(np_pids) for(long int i = 0; i < maxfd; i++) {
|
||||
if(np_pids[i] != 0) kill(np_pids[i], SIGKILL);
|
||||
}
|
||||
|
||||
|
|
|
@ -205,9 +205,9 @@ SKIP: {
|
|||
like ( $res->output, '/time_connect=[\d\.]+/', 'Extended Performance Data Output OK' );
|
||||
like ( $res->output, '/time_ssl=[\d\.]+/', 'Extended Performance Data SSL Output OK' );
|
||||
|
||||
$res = NPTest->testCmd( "./$plugin -H www.mozilla.com -u /firefox -f curl" );
|
||||
$res = NPTest->testCmd( "./$plugin -H monitoring-plugins.org -u /download.html -f follow" );
|
||||
is( $res->return_code, 0, "Redirection based on location is okay");
|
||||
|
||||
$res = NPTest->testCmd( "./$plugin -H www.mozilla.com --extended-perfdata" );
|
||||
$res = NPTest->testCmd( "./$plugin -H monitoring-plugins.org --extended-perfdata" );
|
||||
like ( $res->output, '/time_connect=[\d\.]+/', 'Extended Performance Data Output OK' );
|
||||
}
|
||||
|
|
|
@ -23,11 +23,11 @@ my $mountpoint2_valid = getTestParameter( "NP_MOUNTPOINT2_VALID", "Path to anoth
|
|||
if ($mountpoint_valid eq "" or $mountpoint2_valid eq "") {
|
||||
plan skip_all => "Need 2 mountpoints to test";
|
||||
} else {
|
||||
plan tests => 88;
|
||||
plan tests => 94;
|
||||
}
|
||||
|
||||
$result = NPTest->testCmd(
|
||||
"./check_disk -w 1% -c 1% -p $mountpoint_valid -w 1% -c 1% -p $mountpoint2_valid"
|
||||
$result = NPTest->testCmd(
|
||||
"./check_disk -w 1% -c 1% -p $mountpoint_valid -w 1% -c 1% -p $mountpoint2_valid"
|
||||
);
|
||||
cmp_ok( $result->return_code, "==", 0, "Checking two mountpoints (must have at least 1% free in space and inodes)");
|
||||
my $c = 0;
|
||||
|
@ -44,7 +44,7 @@ my @perf_data = sort(split(/ /, $result->perf_output));
|
|||
# Calculate avg_free free on mountpoint1 and mountpoint2
|
||||
# because if you check in the middle, you should get different errors
|
||||
$_ = $result->output;
|
||||
my ($free_on_mp1, $free_on_mp2) = (m/\((\d+)%.*\((\d+)%/);
|
||||
my ($free_on_mp1, $free_on_mp2) = (m/\((\d+\.\d+)%.*\((\d+\.\d+)%/);
|
||||
die "Cannot parse output: $_" unless ($free_on_mp1 && $free_on_mp2);
|
||||
my $avg_free = ceil(($free_on_mp1+$free_on_mp2)/2);
|
||||
my ($more_free, $less_free);
|
||||
|
@ -103,8 +103,8 @@ is ($crit_percth_data, int((1-10/100)*$total_percth_data), "Wrong critical in pe
|
|||
|
||||
|
||||
# Check when order of mount points are reversed, that perf data remains same
|
||||
$result = NPTest->testCmd(
|
||||
"./check_disk -w 1% -c 1% -p $mountpoint2_valid -w 1% -c 1% -p $mountpoint_valid"
|
||||
$result = NPTest->testCmd(
|
||||
"./check_disk -w 1% -c 1% -p $mountpoint2_valid -w 1% -c 1% -p $mountpoint_valid"
|
||||
);
|
||||
@_ = sort(split(/ /, $result->perf_output));
|
||||
is_deeply( \@perf_data, \@_, "perf data for both filesystems same when reversed");
|
||||
|
@ -119,8 +119,12 @@ like ( $result->only_output, qr/$more_free/, "Have disk name in text");
|
|||
|
||||
$result = NPTest->testCmd( "./check_disk -w 1 -c 1 -p $more_free -p $less_free" );
|
||||
cmp_ok( $result->return_code, '==', 0, "At least 1 MB available on $more_free and $less_free");
|
||||
|
||||
$_ = $result->output;
|
||||
|
||||
my ($free_mb_on_mp1, $free_mb_on_mp2) = (m/(\d+)MiB .* (\d+)MiB /g);
|
||||
die "Cannot parse output: $_" unless ($free_mb_on_mp1 && $free_mb_on_mp2);
|
||||
|
||||
my $free_mb_on_all = $free_mb_on_mp1 + $free_mb_on_mp2;
|
||||
|
||||
|
||||
|
@ -134,8 +138,8 @@ cmp_ok( $result->return_code, '==', 0, "Old syntax okay" );
|
|||
$result = NPTest->testCmd( "./check_disk -w 1% -c 1% -p $more_free" );
|
||||
cmp_ok( $result->return_code, "==", 0, "At least 1% free" );
|
||||
|
||||
$result = NPTest->testCmd(
|
||||
"./check_disk -w 1% -c 1% -p $more_free -w 100% -c 100% -p $less_free"
|
||||
$result = NPTest->testCmd(
|
||||
"./check_disk -w 1% -c 1% -p $more_free -w 100% -c 100% -p $less_free"
|
||||
);
|
||||
cmp_ok( $result->return_code, "==", 2, "Get critical on less_free mountpoint $less_free" );
|
||||
like( $result->output, $failureOutput, "Right output" );
|
||||
|
@ -151,14 +155,14 @@ $result = NPTest->testCmd(
|
|||
);
|
||||
cmp_ok( $result->return_code, '==', 0, "Get ok on more_free mountpoint, when checking avg_free");
|
||||
|
||||
$result = NPTest->testCmd(
|
||||
"./check_disk -w $avg_free% -c 0% -p $less_free -w $avg_free% -c $avg_free% -p $more_free"
|
||||
$result = NPTest->testCmd(
|
||||
"./check_disk -w $avg_free% -c 0% -p $less_free -w $avg_free% -c $avg_free% -p $more_free"
|
||||
);
|
||||
cmp_ok( $result->return_code, "==", 1, "Combining above two tests, get warning");
|
||||
my $all_disks = $result->output;
|
||||
|
||||
$result = NPTest->testCmd(
|
||||
"./check_disk -e -w $avg_free% -c 0% -p $less_free -w $avg_free% -c $avg_free% -p $more_free"
|
||||
"./check_disk -e -w $avg_free% -c 0% -p $less_free -w $avg_free% -c $avg_free% -p $more_free"
|
||||
);
|
||||
isnt( $result->output, $all_disks, "-e gives different output");
|
||||
|
||||
|
@ -240,7 +244,7 @@ TODO: {
|
|||
cmp_ok( $result->return_code, '==', 3, "Invalid command line options" );
|
||||
}
|
||||
|
||||
$result = NPTest->testCmd(
|
||||
$result = NPTest->testCmd(
|
||||
"./check_disk -p $mountpoint_valid -w 10% -c 15%"
|
||||
);
|
||||
cmp_ok( $result->return_code, "==", 3, "Invalid options: -p must come after thresholds" );
|
||||
|
@ -311,8 +315,8 @@ $result = NPTest->testCmd( "./check_disk -w 0% -c 0% -C -w 0% -c 0% -p $mountpoi
|
|||
like( $result->output, '/;.*;\|/', "-C selects partitions if -p is not given");
|
||||
|
||||
# grouping: exit crit if the sum of free megs on mp1+mp2 is less than warn/crit
|
||||
$result = NPTest->testCmd( "./check_disk -w ". ($free_mb_on_all + 1) ." -c ". ($free_mb_on_all + 1) ."-g group -p $mountpoint_valid -p $mountpoint2_valid" );
|
||||
cmp_ok( $result->return_code, '==', 2, "grouping: exit crit if the sum of free megs on mp1+mp2 is less than warn/crit");
|
||||
$result = NPTest->testCmd( "./check_disk -w ". ($free_mb_on_all + 1) ." -c ". ($free_mb_on_all + 1) ." -g group -p $mountpoint_valid -p $mountpoint2_valid" );
|
||||
cmp_ok( $result->return_code, '==', 2, "grouping: exit crit if the sum of free megs on mp1+mp2 is less than warn/crit\nInstead received: " . $result->output);
|
||||
|
||||
# grouping: exit warning if the sum of free megs on mp1+mp2 is between -w and -c
|
||||
$result = NPTest->testCmd( "./check_disk -w ". ($free_mb_on_all + 1) ." -c ". ($free_mb_on_all - 1) ." -g group -p $mountpoint_valid -p $mountpoint2_valid" );
|
||||
|
@ -322,7 +326,7 @@ cmp_ok( $result->return_code, '==', 1, "grouping: exit warning if the sum of fre
|
|||
$result = NPTest->testCmd( "./check_disk -w ". ($free_mb_on_all - 1) ." -c ". ($free_mb_on_all - 1) ." -g group -p $mountpoint_valid -p $mountpoint2_valid" );
|
||||
cmp_ok( $result->return_code, '==', 0, "grouping: exit ok if the sum of free megs on mp1+mp2 is more than warn/crit");
|
||||
|
||||
# grouping: exit unknown if group name is given after -p
|
||||
# grouping: exit unknown if group name is given after -p
|
||||
$result = NPTest->testCmd( "./check_disk -w ". ($free_mb_on_all - 1) ." -c ". ($free_mb_on_all - 1) ." -p $mountpoint_valid -g group -p $mountpoint2_valid" );
|
||||
cmp_ok( $result->return_code, '==', 3, "Invalid options: -p must come after groupname");
|
||||
|
||||
|
@ -355,17 +359,17 @@ like( $result->output, qr/$mountpoint2_valid/,"ignore: output data does have $mo
|
|||
# ignore-missing: exit okay, when fs is not accessible
|
||||
$result = NPTest->testCmd( "./check_disk --ignore-missing -w 0% -c 0% -p /bob");
|
||||
cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay for not existing filesystem /bob");
|
||||
like( $result->output, '/^DISK OK - No disks were found for provided parameters; - ignored paths: /bob;.*$/', 'Output OK');
|
||||
like( $result->output, '/^DISK OK - No disks were found for provided parameters - ignored paths: /bob;.*$/', 'Output OK');
|
||||
|
||||
# ignore-missing: exit okay, when regex does not match
|
||||
$result = NPTest->testCmd( "./check_disk --ignore-missing -w 0% -c 0% -r /bob");
|
||||
cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay for regular expression not matching");
|
||||
like( $result->output, '/^DISK OK - No disks were found for provided parameters;.*$/', 'Output OK');
|
||||
like( $result->output, '/^DISK OK - No disks were found for provided parameters.*$/', 'Output OK');
|
||||
|
||||
# ignore-missing: exit okay, when fs with exact match (-E) is not found
|
||||
$result = NPTest->testCmd( "./check_disk --ignore-missing -w 0% -c 0% -E -p /etc");
|
||||
cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay when exact match does not find fs");
|
||||
like( $result->output, '/^DISK OK - No disks were found for provided parameters; - ignored paths: /etc;.*$/', 'Output OK');
|
||||
like( $result->output, '/^DISK OK - No disks were found for provided parameters - ignored paths: /etc;.*$/', 'Output OK');
|
||||
|
||||
# ignore-missing: exit okay, when checking one existing fs and one non-existing fs (regex)
|
||||
$result = NPTest->testCmd( "./check_disk --ignore-missing -w 0% -c 0% -r '/bob' -r '^/\$'");
|
||||
|
@ -375,4 +379,19 @@ like( $result->output, '/^DISK OK - free space: \/ .*$/', 'Output OK');
|
|||
# ignore-missing: exit okay, when checking one existing fs and one non-existing fs (path)
|
||||
$result = NPTest->testCmd( "./check_disk --ignore-missing -w 0% -c 0% -p '/bob' -p '/'");
|
||||
cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay for regular expression not matching");
|
||||
like( $result->output, '/^DISK OK - free space: / .*; - ignored paths: /bob;.*$/', 'Output OK');
|
||||
like( $result->output, '/^DISK OK - free space: / .*; - ignored paths: /bob;.*$/', 'Output OK');
|
||||
|
||||
# ignore-missing: exit okay, when checking one non-existing fs (path) and one ignored
|
||||
$result = NPTest->testCmd( "./check_disk -n -w 0% -c 0% -r /dummy -i /dummy2");
|
||||
cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay for regular expression not matching");
|
||||
like( $result->output, '/^DISK OK - No disks were found for provided parameters\|$/', 'Output OK');
|
||||
|
||||
# ignore-missing: exit okay, when regex match does not find anything
|
||||
$result = NPTest->testCmd( "./check_disk -n -e -l -w 10% -c 5% -W 10% -K 5% -r /dummy");
|
||||
cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay for regular expression not matching");
|
||||
like( $result->output, '/^DISK OK\|$/', 'Output OK');
|
||||
|
||||
# ignore-missing: exit okay, when regex match does not find anything
|
||||
$result = NPTest->testCmd( "./check_disk -n -l -w 10% -c 5% -W 10% -K 5% -r /dummy");
|
||||
cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay for regular expression not matching");
|
||||
like( $result->output, '/^DISK OK - No disks were found for provided parameters\|$/', 'Output OK');
|
||||
|
|
|
@ -166,10 +166,10 @@ SKIP: {
|
|||
like ( $res->output, '/time_connect=[\d\.]+/', 'Extended Performance Data Output OK' );
|
||||
like ( $res->output, '/time_ssl=[\d\.]+/', 'Extended Performance Data SSL Output OK' );
|
||||
|
||||
$res = NPTest->testCmd( "./$plugin -H www.mozilla.com -u /firefox -f follow" );
|
||||
$res = NPTest->testCmd( "./$plugin -H monitoring-plugins.org -u /download.html -f follow" );
|
||||
is( $res->return_code, 0, "Redirection based on location is okay");
|
||||
|
||||
$res = NPTest->testCmd( "./$plugin -H www.mozilla.com --extended-perfdata" );
|
||||
$res = NPTest->testCmd( "./$plugin -H monitoring-plugins.org --extended-perfdata" );
|
||||
like ( $res->output, '/time_connect=[\d\.]+/', 'Extended Performance Data Output OK' );
|
||||
}
|
||||
|
||||
|
|
|
@ -8,34 +8,116 @@ use strict;
|
|||
use Test::More;
|
||||
use NPTest;
|
||||
|
||||
my $res;
|
||||
|
||||
# Required parameters
|
||||
my $ssh_host = getTestParameter("NP_SSH_HOST", "A host providing SSH service", "localhost");
|
||||
my $host_nonresponsive = getTestParameter("NP_HOST_NONRESPONSIVE", "The hostname of system not responsive to network requests", "10.0.0.1" );
|
||||
my $hostname_invalid = getTestParameter("NP_HOSTNAME_INVALID", "An invalid (not known to DNS) hostname", "nosuchhost" );
|
||||
my $ssh_host = getTestParameter("NP_SSH_HOST",
|
||||
"A host providing SSH service",
|
||||
"localhost");
|
||||
|
||||
my $host_nonresponsive = getTestParameter("NP_HOST_NONRESPONSIVE",
|
||||
"The hostname of system not responsive to network requests",
|
||||
"10.0.0.1" );
|
||||
|
||||
my $hostname_invalid = getTestParameter("NP_HOSTNAME_INVALID",
|
||||
"An invalid (not known to DNS) hostname",
|
||||
"nosuchhost" );
|
||||
|
||||
|
||||
plan skip_all => "SSH_HOST must be defined" unless $ssh_host;
|
||||
plan tests => 6;
|
||||
plan tests => 14 + 6;
|
||||
|
||||
SKIP: {
|
||||
skip "SSH_HOST must be defined", 6 unless $ssh_host;
|
||||
my $result = NPTest->testCmd(
|
||||
"./check_ssh -H $ssh_host"
|
||||
);
|
||||
cmp_ok($result->return_code, '==', 0, "Exit with return code 0 (OK)");
|
||||
like($result->output, '/^SSH OK - /', "Status text if command returned none (OK)");
|
||||
|
||||
|
||||
my $result = NPTest->testCmd(
|
||||
"./check_ssh -H $ssh_host"
|
||||
);
|
||||
cmp_ok($result->return_code, '==', 0, "Exit with return code 0 (OK)");
|
||||
like($result->output, '/^SSH OK - /', "Status text if command returned none (OK)");
|
||||
|
||||
|
||||
$result = NPTest->testCmd(
|
||||
"./check_ssh -H $host_nonresponsive -t 2"
|
||||
);
|
||||
cmp_ok($result->return_code, '==', 2, "Exit with return code 0 (OK)");
|
||||
like($result->output, '/^CRITICAL - Socket timeout after 2 seconds/', "Status text if command returned none (OK)");
|
||||
$result = NPTest->testCmd(
|
||||
"./check_ssh -H $host_nonresponsive -t 2"
|
||||
);
|
||||
cmp_ok($result->return_code, '==', 2, "Exit with return code 0 (OK)");
|
||||
like($result->output, '/^CRITICAL - Socket timeout after 2 seconds/', "Status text if command returned none (OK)");
|
||||
|
||||
|
||||
|
||||
$result = NPTest->testCmd(
|
||||
"./check_ssh -H $hostname_invalid -t 2"
|
||||
);
|
||||
cmp_ok($result->return_code, '==', 3, "Exit with return code 0 (OK)");
|
||||
like($result->output, '/^check_ssh: Invalid hostname/', "Status text if command returned none (OK)");
|
||||
$result = NPTest->testCmd(
|
||||
"./check_ssh -H $hostname_invalid -t 2"
|
||||
);
|
||||
cmp_ok($result->return_code, '==', 3, "Exit with return code 0 (OK)");
|
||||
like($result->output, '/^check_ssh: Invalid hostname/', "Status text if command returned none (OK)");
|
||||
|
||||
|
||||
}
|
||||
SKIP: {
|
||||
|
||||
skip "No netcat available", 14 unless (system("which nc > /dev/null") == 0);
|
||||
|
||||
# netcat on linux (on debian) will just keep the socket open if not advised otherwise
|
||||
# therefore we add -q to close it after two seconds after receiving the EOF from input
|
||||
my $nc_flags = "-l 5003 -N";
|
||||
#A valid protocol version control string has the form
|
||||
# SSH-protoversion-softwareversion SP comments CR LF
|
||||
#
|
||||
# where `comments` is optional, protoversion is the SSH protocol version and
|
||||
# softwareversion is an arbitrary string representing the server software version
|
||||
open(NC, "echo 'SSH-2.0-nagiosplug.ssh.0.1' | nc ${nc_flags}|");
|
||||
sleep 0.1;
|
||||
$res = NPTest->testCmd( "./check_ssh -H localhost -p 5003" );
|
||||
cmp_ok( $res->return_code, '==', 0, "Got SSH protocol version control string");
|
||||
like( $res->output, '/^SSH OK - nagiosplug.ssh.0.1 \(protocol 2.0\)/', "Output OK");
|
||||
close NC;
|
||||
|
||||
open(NC, "echo 'SSH-2.0-3.2.9.1' | nc ${nc_flags}|");
|
||||
sleep 0.1;
|
||||
$res = NPTest->testCmd( "./check_ssh -H localhost -p 5003" );
|
||||
cmp_ok( $res->return_code, "==", 0, "Got SSH protocol version control string with non-alpha softwareversion string");
|
||||
like( $res->output, '/^SSH OK - 3.2.9.1 \(protocol 2.0\)/', "Output OK for non-alpha softwareversion string");
|
||||
close NC;
|
||||
|
||||
open(NC, "echo 'SSH-2.0-nagiosplug.ssh.0.1 this is a comment' | nc ${nc_flags} |");
|
||||
sleep 0.1;
|
||||
$res = NPTest->testCmd( "./check_ssh -H localhost -p 5003 -r nagiosplug.ssh.0.1" );
|
||||
cmp_ok( $res->return_code, '==', 0, "Got SSH protocol version control string, and parsed comment appropriately");
|
||||
like( $res->output, '/^SSH OK - nagiosplug.ssh.0.1 \(protocol 2.0\)/', "Output OK");
|
||||
close NC;
|
||||
|
||||
open(NC, "echo 'SSH-' | nc ${nc_flags}|");
|
||||
sleep 0.1;
|
||||
$res = NPTest->testCmd( "./check_ssh -H localhost -p 5003" );
|
||||
cmp_ok( $res->return_code, '==', 2, "Got invalid SSH protocol version control string");
|
||||
like( $res->output, '/^SSH CRITICAL/', "Output OK");
|
||||
close NC;
|
||||
|
||||
open(NC, "echo '' | nc ${nc_flags}|");
|
||||
sleep 0.1;
|
||||
$res = NPTest->testCmd( "./check_ssh -H localhost -p 5003" );
|
||||
cmp_ok( $res->return_code, '==', 2, "No version control string received");
|
||||
like( $res->output, '/^SSH CRITICAL - No version control string received/', "Output OK");
|
||||
close NC;
|
||||
|
||||
open(NC, "echo 'Not a version control string' | nc ${nc_flags}|");
|
||||
sleep 0.1;
|
||||
$res = NPTest->testCmd( "./check_ssh -H localhost -p 5003" );
|
||||
cmp_ok( $res->return_code, '==', 2, "No version control string received");
|
||||
like( $res->output, '/^SSH CRITICAL - No version control string received/', "Output OK");
|
||||
close NC;
|
||||
|
||||
|
||||
#RFC 4253 permits servers to send any number of data lines prior to sending the protocol version control string
|
||||
open(NC, "{ echo 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'; sleep 0.5;
|
||||
echo 'BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB'; sleep 0.5;
|
||||
echo 'CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC'; sleep 0.2;
|
||||
echo 'DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD'; sleep 0.3;
|
||||
printf 'EEEEEEEEEEEEEEEEEE'; sleep 0.2;
|
||||
printf 'EEEEEEEEEEEEEEEEEE\n'; sleep 0.2;
|
||||
echo 'Some\nPrepended\nData\nLines\n'; sleep 0.2;
|
||||
echo 'SSH-2.0-nagiosplug.ssh.0.2';} | nc ${nc_flags}|");
|
||||
sleep 0.1;
|
||||
$res = NPTest->testCmd( "./check_ssh -H localhost -p 5003" );
|
||||
cmp_ok( $res->return_code, '==', 0, "Got delayed SSH protocol version control string");
|
||||
like( $res->output, '/^SSH OK - nagiosplug.ssh.0.2 \(protocol 2.0\)/', "Output OK");
|
||||
close NC;
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
#
|
||||
|
||||
use strict;
|
||||
use Test::More tests => 8;
|
||||
use Test::More tests => 14;
|
||||
use NPTest;
|
||||
|
||||
my $successOutput = '/^SWAP OK - [0-9]+\% free \([0-9]+MB out of [0-9]+MB\)/';
|
||||
|
@ -14,6 +14,10 @@ my $warnOutput = '/^SWAP WARNING - [0-9]+\% free \([0-9]+MB out of [0-9]+MB\)
|
|||
|
||||
my $result;
|
||||
|
||||
$result = NPTest->testCmd( "./check_swap" ); # Always OK
|
||||
cmp_ok( $result->return_code, "==", 0, "Always OK" );
|
||||
like( $result->output, $successOutput, "Right output" );
|
||||
|
||||
$result = NPTest->testCmd( "./check_swap -w 1048576 -c 1048576" ); # 1 MB free
|
||||
cmp_ok( $result->return_code, "==", 0, "At least 1MB free" );
|
||||
like( $result->output, $successOutput, "Right output" );
|
||||
|
@ -29,3 +33,11 @@ like( $result->output, $failureOutput, "Right output" );
|
|||
$result = NPTest->testCmd( "./check_swap -w 100% -c 1%" ); # 100% (always warn)
|
||||
cmp_ok( $result->return_code, "==", 1, 'Get warning because not 100% free' );
|
||||
like( $result->output, $warnOutput, "Right output" );
|
||||
|
||||
$result = NPTest->testCmd( "./check_swap -w 100%" ); # 100% (single threshold, always warn)
|
||||
cmp_ok( $result->return_code, "==", 1, 'Get warning because not 100% free' );
|
||||
like( $result->output, $warnOutput, "Right output" );
|
||||
|
||||
$result = NPTest->testCmd( "./check_swap -c 100%" ); # 100% (single threshold, always critical)
|
||||
cmp_ok( $result->return_code, "==", 2, 'Get critical because not 100% free' );
|
||||
like( $result->output, $failureOutput, "Right output" );
|
||||
|
|
|
@ -13,10 +13,11 @@ use Test;
|
|||
use NPTest;
|
||||
|
||||
use vars qw($tests);
|
||||
BEGIN {$tests = 8; plan tests => $tests}
|
||||
BEGIN {$tests = 12; plan tests => $tests}
|
||||
|
||||
my $successOutput = '/^USERS OK - [0-9]+ users currently logged in/';
|
||||
my $failureOutput = '/^USERS CRITICAL - [0-9]+ users currently logged in/';
|
||||
my $wrongOptionOutput = '/Usage:/';
|
||||
|
||||
my $t;
|
||||
|
||||
|
@ -24,6 +25,8 @@ $t += checkCmd( "./check_users 1000 1000", 0, $successOutput );
|
|||
$t += checkCmd( "./check_users 0 0", 2, $failureOutput );
|
||||
$t += checkCmd( "./check_users -w 0:1000 -c 0:1000", 0, $successOutput );
|
||||
$t += checkCmd( "./check_users -w 0:0 -c 0:0", 2, $failureOutput );
|
||||
$t += checkCmd( "./check_users -w 0:1000", 3, $wrongOptionOutput);
|
||||
$t += checkCmd( "./check_users", 3, $wrongOptionOutput);
|
||||
|
||||
exit(0) if defined($Test::Harness::VERSION);
|
||||
exit($tests - $t);
|
||||
|
|
164
plugins/utils.c
164
plugins/utils.c
|
@ -23,13 +23,15 @@
|
|||
*****************************************************************************/
|
||||
|
||||
#include "common.h"
|
||||
#include "utils.h"
|
||||
#include "./utils.h"
|
||||
#include "utils_base.h"
|
||||
#include <stdarg.h>
|
||||
#include <limits.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <arpa/inet.h>
|
||||
|
||||
extern void print_usage (void);
|
||||
|
@ -147,98 +149,107 @@ print_revision (const char *command_name, const char *revision)
|
|||
command_name, revision, PACKAGE, VERSION);
|
||||
}
|
||||
|
||||
int
|
||||
is_numeric (char *number)
|
||||
{
|
||||
bool is_numeric (char *number) {
|
||||
char tmp[1];
|
||||
float x;
|
||||
|
||||
if (!number)
|
||||
return FALSE;
|
||||
return false;
|
||||
else if (sscanf (number, "%f%c", &x, tmp) == 1)
|
||||
return TRUE;
|
||||
return true;
|
||||
else
|
||||
return FALSE;
|
||||
return false;
|
||||
}
|
||||
|
||||
int
|
||||
is_positive (char *number)
|
||||
{
|
||||
bool is_positive (char *number) {
|
||||
if (is_numeric (number) && atof (number) > 0.0)
|
||||
return TRUE;
|
||||
return true;
|
||||
else
|
||||
return FALSE;
|
||||
return false;
|
||||
}
|
||||
|
||||
int
|
||||
is_negative (char *number)
|
||||
{
|
||||
bool is_negative (char *number) {
|
||||
if (is_numeric (number) && atof (number) < 0.0)
|
||||
return TRUE;
|
||||
return true;
|
||||
else
|
||||
return FALSE;
|
||||
return false;
|
||||
}
|
||||
|
||||
int
|
||||
is_nonnegative (char *number)
|
||||
{
|
||||
bool is_nonnegative (char *number) {
|
||||
if (is_numeric (number) && atof (number) >= 0.0)
|
||||
return TRUE;
|
||||
return true;
|
||||
else
|
||||
return FALSE;
|
||||
return false;
|
||||
}
|
||||
|
||||
int
|
||||
is_percentage (char *number)
|
||||
{
|
||||
bool is_percentage (char *number) {
|
||||
int x;
|
||||
if (is_numeric (number) && (x = atof (number)) >= 0 && x <= 100)
|
||||
return TRUE;
|
||||
return true;
|
||||
else
|
||||
return FALSE;
|
||||
return false;
|
||||
}
|
||||
|
||||
int
|
||||
is_integer (char *number)
|
||||
{
|
||||
bool is_percentage_expression (const char str[]) {
|
||||
if (!str) {
|
||||
return false;
|
||||
}
|
||||
|
||||
size_t len = strlen(str);
|
||||
|
||||
if (str[len-1] != '%') {
|
||||
return false;
|
||||
}
|
||||
|
||||
char *foo = calloc(sizeof(char), len + 1);
|
||||
|
||||
if (!foo) {
|
||||
die (STATE_UNKNOWN, _("calloc failed \n"));
|
||||
}
|
||||
|
||||
strcpy(foo, str);
|
||||
foo[len-1] = '\0';
|
||||
|
||||
bool result = is_numeric(foo);
|
||||
|
||||
free(foo);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
bool is_integer (char *number) {
|
||||
long int n;
|
||||
|
||||
if (!number || (strspn (number, "-0123456789 ") != strlen (number)))
|
||||
return FALSE;
|
||||
return false;
|
||||
|
||||
n = strtol (number, NULL, 10);
|
||||
|
||||
if (errno != ERANGE && n >= INT_MIN && n <= INT_MAX)
|
||||
return TRUE;
|
||||
return true;
|
||||
else
|
||||
return FALSE;
|
||||
return false;
|
||||
}
|
||||
|
||||
int
|
||||
is_intpos (char *number)
|
||||
{
|
||||
bool is_intpos (char *number) {
|
||||
if (is_integer (number) && atoi (number) > 0)
|
||||
return TRUE;
|
||||
return true;
|
||||
else
|
||||
return FALSE;
|
||||
return false;
|
||||
}
|
||||
|
||||
int
|
||||
is_intneg (char *number)
|
||||
{
|
||||
bool is_intneg (char *number) {
|
||||
if (is_integer (number) && atoi (number) < 0)
|
||||
return TRUE;
|
||||
return true;
|
||||
else
|
||||
return FALSE;
|
||||
return false;
|
||||
}
|
||||
|
||||
int
|
||||
is_intnonneg (char *number)
|
||||
{
|
||||
bool is_intnonneg (char *number) {
|
||||
if (is_integer (number) && atoi (number) >= 0)
|
||||
return TRUE;
|
||||
return true;
|
||||
else
|
||||
return FALSE;
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -246,19 +257,27 @@ is_intnonneg (char *number)
|
|||
* On success the number will be written to the _target_ address, if _target_ is not set
|
||||
* to NULL.
|
||||
*/
|
||||
int is_int64(char *number, int64_t *target) {
|
||||
bool is_int64(char *number, int64_t *target) {
|
||||
errno = 0;
|
||||
uint64_t tmp = strtoll(number, NULL, 10);
|
||||
char *endptr = { 0 };
|
||||
|
||||
int64_t tmp = strtoll(number, &endptr, 10);
|
||||
if (errno != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (*endptr == '\0') {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (tmp < INT64_MIN || tmp > INT64_MAX) {
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (target != NULL) {
|
||||
*target = tmp;
|
||||
}
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -266,40 +285,45 @@ int is_int64(char *number, int64_t *target) {
|
|||
* On success the number will be written to the _target_ address, if _target_ is not set
|
||||
* to NULL.
|
||||
*/
|
||||
int is_uint64(char *number, uint64_t *target) {
|
||||
bool is_uint64(char *number, uint64_t *target) {
|
||||
errno = 0;
|
||||
uint64_t tmp = strtoll(number, NULL, 10);
|
||||
char *endptr = { 0 };
|
||||
unsigned long long tmp = strtoull(number, &endptr, 10);
|
||||
|
||||
if (errno != 0) {
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
if (tmp < 0 || tmp > UINT64_MAX) {
|
||||
return 0;
|
||||
|
||||
if (*endptr != '\0') {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (tmp > UINT64_MAX) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (target != NULL) {
|
||||
*target = tmp;
|
||||
*target = (uint64_t)tmp;
|
||||
}
|
||||
return 1;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int
|
||||
is_intpercent (char *number)
|
||||
{
|
||||
bool is_intpercent (char *number) {
|
||||
int i;
|
||||
if (is_integer (number) && (i = atoi (number)) >= 0 && i <= 100)
|
||||
return TRUE;
|
||||
return true;
|
||||
else
|
||||
return FALSE;
|
||||
return false;
|
||||
}
|
||||
|
||||
int
|
||||
is_option (char *str)
|
||||
{
|
||||
bool is_option (char *str) {
|
||||
if (!str)
|
||||
return FALSE;
|
||||
return false;
|
||||
else if (strspn (str, "-") == 1 || strspn (str, "-") == 2)
|
||||
return TRUE;
|
||||
return true;
|
||||
else
|
||||
return FALSE;
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef NEED_GETTIMEOFDAY
|
||||
|
|
|
@ -16,6 +16,8 @@ suite of plugins. */
|
|||
/* now some functions etc are being defined in ../lib/utils_base.c */
|
||||
#include "utils_base.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
|
||||
#ifdef NP_EXTRA_OPTS
|
||||
/* Include extra-opts functions if compiled in */
|
||||
|
@ -34,21 +36,22 @@ extern time_t start_time, end_time;
|
|||
|
||||
/* Test input types */
|
||||
|
||||
int is_integer (char *);
|
||||
int is_intpos (char *);
|
||||
int is_intneg (char *);
|
||||
int is_intnonneg (char *);
|
||||
int is_intpercent (char *);
|
||||
int is_uint64(char *number, uint64_t *target);
|
||||
int is_int64(char *number, int64_t *target);
|
||||
bool is_integer (char *);
|
||||
bool is_intpos (char *);
|
||||
bool is_intneg (char *);
|
||||
bool is_intnonneg (char *);
|
||||
bool is_intpercent (char *);
|
||||
bool is_uint64(char *number, uint64_t *target);
|
||||
bool is_int64(char *number, int64_t *target);
|
||||
|
||||
int is_numeric (char *);
|
||||
int is_positive (char *);
|
||||
int is_negative (char *);
|
||||
int is_nonnegative (char *);
|
||||
int is_percentage (char *);
|
||||
bool is_numeric (char *);
|
||||
bool is_positive (char *);
|
||||
bool is_negative (char *);
|
||||
bool is_nonnegative (char *);
|
||||
bool is_percentage (char *);
|
||||
bool is_percentage_expression (const char[]);
|
||||
|
||||
int is_option (char *);
|
||||
bool is_option (char *);
|
||||
|
||||
/* Generalized timer that will do milliseconds if available */
|
||||
#ifndef HAVE_STRUCT_TIMEVAL
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue