diff options
Diffstat (limited to 'plugins')
55 files changed, 2013 insertions, 1640 deletions
diff --git a/plugins/check_apt.c b/plugins/check_apt.c index fa982ae3..5c0f6e28 100644 --- a/plugins/check_apt.c +++ b/plugins/check_apt.c | |||
@@ -94,7 +94,7 @@ static int stderr_warning = 0; /* if a cmd issued output on stderr */ | |||
94 | static int exec_warning = 0; /* if a cmd exited non-zero */ | 94 | static int exec_warning = 0; /* if a cmd exited non-zero */ |
95 | 95 | ||
96 | int main (int argc, char **argv) { | 96 | int main (int argc, char **argv) { |
97 | int result=STATE_UNKNOWN, packages_available=0, sec_count=0, i=0; | 97 | int result=STATE_UNKNOWN, packages_available=0, sec_count=0; |
98 | char **packages_list=NULL, **secpackages_list=NULL; | 98 | char **packages_list=NULL, **secpackages_list=NULL; |
99 | 99 | ||
100 | /* Parse extra opts if any */ | 100 | /* Parse extra opts if any */ |
@@ -142,10 +142,11 @@ int main (int argc, char **argv) { | |||
142 | qsort(secpackages_list, sec_count, sizeof(char*), cmpstringp); | 142 | qsort(secpackages_list, sec_count, sizeof(char*), cmpstringp); |
143 | qsort(packages_list, packages_available-sec_count, sizeof(char*), cmpstringp); | 143 | qsort(packages_list, packages_available-sec_count, sizeof(char*), cmpstringp); |
144 | 144 | ||
145 | for(i = 0; i < sec_count; i++) | 145 | for(int i = 0; i < sec_count; i++) |
146 | printf("%s (security)\n", secpackages_list[i]); | 146 | printf("%s (security)\n", secpackages_list[i]); |
147 | |||
147 | if (only_critical == false) { | 148 | if (only_critical == false) { |
148 | for(i = 0; i < packages_available - sec_count; i++) | 149 | for(int i = 0; i < packages_available - sec_count; i++) |
149 | printf("%s\n", packages_list[i]); | 150 | printf("%s\n", packages_list[i]); |
150 | } | 151 | } |
151 | } | 152 | } |
@@ -251,7 +252,7 @@ int process_arguments (int argc, char **argv) { | |||
251 | 252 | ||
252 | /* run an apt-get upgrade */ | 253 | /* run an apt-get upgrade */ |
253 | int run_upgrade(int *pkgcount, int *secpkgcount, char ***pkglist, char ***secpkglist){ | 254 | int run_upgrade(int *pkgcount, int *secpkgcount, char ***pkglist, char ***secpkglist){ |
254 | int i=0, result=STATE_UNKNOWN, regres=0, pc=0, spc=0; | 255 | int result=STATE_UNKNOWN, regres=0, pc=0, spc=0; |
255 | struct output chld_out, chld_err; | 256 | struct output chld_out, chld_err; |
256 | regex_t ireg, ereg, sreg; | 257 | regex_t ireg, ereg, sreg; |
257 | char *cmdline=NULL, rerrbuf[64]; | 258 | char *cmdline=NULL, rerrbuf[64]; |
@@ -320,7 +321,7 @@ int run_upgrade(int *pkgcount, int *secpkgcount, char ***pkglist, char ***secpkg | |||
320 | * we may need to switch to the --print-uris output format, | 321 | * we may need to switch to the --print-uris output format, |
321 | * in which case the logic here will slightly change. | 322 | * in which case the logic here will slightly change. |
322 | */ | 323 | */ |
323 | for(i = 0; i < chld_out.lines; i++) { | 324 | for(size_t i = 0; i < chld_out.lines; i++) { |
324 | if(verbose){ | 325 | if(verbose){ |
325 | printf("%s\n", chld_out.line[i]); | 326 | printf("%s\n", chld_out.line[i]); |
326 | } | 327 | } |
@@ -353,7 +354,7 @@ int run_upgrade(int *pkgcount, int *secpkgcount, char ***pkglist, char ***secpkg | |||
353 | stderr_warning=1; | 354 | stderr_warning=1; |
354 | result = max_state(result, STATE_WARNING); | 355 | result = max_state(result, STATE_WARNING); |
355 | if(verbose){ | 356 | if(verbose){ |
356 | for(i = 0; i < chld_err.lines; i++) { | 357 | for(size_t i = 0; i < chld_err.lines; i++) { |
357 | fprintf(stderr, "%s\n", chld_err.line[i]); | 358 | fprintf(stderr, "%s\n", chld_err.line[i]); |
358 | } | 359 | } |
359 | } | 360 | } |
@@ -367,7 +368,7 @@ int run_upgrade(int *pkgcount, int *secpkgcount, char ***pkglist, char ***secpkg | |||
367 | 368 | ||
368 | /* run an apt-get update (needs root) */ | 369 | /* run an apt-get update (needs root) */ |
369 | int run_update(void){ | 370 | int run_update(void){ |
370 | int i=0, result=STATE_UNKNOWN; | 371 | int result=STATE_UNKNOWN; |
371 | struct output chld_out, chld_err; | 372 | struct output chld_out, chld_err; |
372 | char *cmdline; | 373 | char *cmdline; |
373 | 374 | ||
@@ -385,7 +386,7 @@ int run_update(void){ | |||
385 | } | 386 | } |
386 | 387 | ||
387 | if(verbose){ | 388 | if(verbose){ |
388 | for(i = 0; i < chld_out.lines; i++) { | 389 | for(size_t i = 0; i < chld_out.lines; i++) { |
389 | printf("%s\n", chld_out.line[i]); | 390 | printf("%s\n", chld_out.line[i]); |
390 | } | 391 | } |
391 | } | 392 | } |
@@ -395,7 +396,7 @@ int run_update(void){ | |||
395 | stderr_warning=1; | 396 | stderr_warning=1; |
396 | result = max_state(result, STATE_WARNING); | 397 | result = max_state(result, STATE_WARNING); |
397 | if(verbose){ | 398 | if(verbose){ |
398 | for(i = 0; i < chld_err.lines; i++) { | 399 | for(size_t i = 0; i < chld_err.lines; i++) { |
399 | fprintf(stderr, "%s\n", chld_err.line[i]); | 400 | fprintf(stderr, "%s\n", chld_err.line[i]); |
400 | } | 401 | } |
401 | } | 402 | } |
diff --git a/plugins/check_by_ssh.c b/plugins/check_by_ssh.c index 1ad547ed..2a23b397 100644 --- a/plugins/check_by_ssh.c +++ b/plugins/check_by_ssh.c | |||
@@ -50,7 +50,7 @@ unsigned int services = 0; | |||
50 | int skip_stdout = 0; | 50 | int skip_stdout = 0; |
51 | int skip_stderr = 0; | 51 | int skip_stderr = 0; |
52 | int warn_on_stderr = 0; | 52 | int warn_on_stderr = 0; |
53 | bool unknown_timeout = FALSE; | 53 | bool unknown_timeout = false; |
54 | char *remotecmd = NULL; | 54 | char *remotecmd = NULL; |
55 | char **commargv = NULL; | 55 | char **commargv = NULL; |
56 | int commargc = 0; | 56 | int commargc = 0; |
@@ -58,8 +58,8 @@ char *hostname = NULL; | |||
58 | char *outputfile = NULL; | 58 | char *outputfile = NULL; |
59 | char *host_shortname = NULL; | 59 | char *host_shortname = NULL; |
60 | char **service; | 60 | char **service; |
61 | int passive = FALSE; | 61 | bool passive = false; |
62 | int verbose = FALSE; | 62 | bool verbose = false; |
63 | 63 | ||
64 | int | 64 | int |
65 | main (int argc, char **argv) | 65 | main (int argc, char **argv) |
@@ -68,7 +68,6 @@ main (int argc, char **argv) | |||
68 | char *status_text; | 68 | char *status_text; |
69 | int cresult; | 69 | int cresult; |
70 | int result = STATE_UNKNOWN; | 70 | int result = STATE_UNKNOWN; |
71 | int i; | ||
72 | time_t local_time; | 71 | time_t local_time; |
73 | FILE *fp = NULL; | 72 | FILE *fp = NULL; |
74 | output chld_out, chld_err; | 73 | output chld_out, chld_err; |
@@ -96,7 +95,7 @@ main (int argc, char **argv) | |||
96 | /* run the command */ | 95 | /* run the command */ |
97 | if (verbose) { | 96 | if (verbose) { |
98 | printf ("Command: %s\n", commargv[0]); | 97 | printf ("Command: %s\n", commargv[0]); |
99 | for (i=1; i<commargc; i++) | 98 | for (int i = 1; i < commargc; i++) |
100 | printf ("Argument %i: %s\n", i, commargv[i]); | 99 | printf ("Argument %i: %s\n", i, commargv[i]); |
101 | } | 100 | } |
102 | 101 | ||
@@ -110,9 +109,9 @@ main (int argc, char **argv) | |||
110 | } | 109 | } |
111 | 110 | ||
112 | if (verbose) { | 111 | if (verbose) { |
113 | for(i = 0; i < chld_out.lines; i++) | 112 | for(size_t i = 0; i < chld_out.lines; i++) |
114 | printf("stdout: %s\n", chld_out.line[i]); | 113 | printf("stdout: %s\n", chld_out.line[i]); |
115 | for(i = 0; i < chld_err.lines; i++) | 114 | for(size_t i = 0; i < chld_err.lines; i++) |
116 | printf("stderr: %s\n", chld_err.line[i]); | 115 | printf("stderr: %s\n", chld_err.line[i]); |
117 | } | 116 | } |
118 | 117 | ||
@@ -122,7 +121,7 @@ main (int argc, char **argv) | |||
122 | skip_stderr = chld_err.lines; | 121 | skip_stderr = chld_err.lines; |
123 | 122 | ||
124 | /* UNKNOWN or worse if (non-skipped) output found on stderr */ | 123 | /* UNKNOWN or worse if (non-skipped) output found on stderr */ |
125 | if(chld_err.lines > skip_stderr) { | 124 | if(chld_err.lines > (size_t)skip_stderr) { |
126 | printf (_("Remote command execution failed: %s\n"), | 125 | printf (_("Remote command execution failed: %s\n"), |
127 | chld_err.line[skip_stderr]); | 126 | chld_err.line[skip_stderr]); |
128 | if ( warn_on_stderr ) | 127 | if ( warn_on_stderr ) |
@@ -134,8 +133,8 @@ main (int argc, char **argv) | |||
134 | /* this is simple if we're not supposed to be passive. | 133 | /* this is simple if we're not supposed to be passive. |
135 | * Wrap up quickly and keep the tricks below */ | 134 | * Wrap up quickly and keep the tricks below */ |
136 | if(!passive) { | 135 | if(!passive) { |
137 | if (chld_out.lines > skip_stdout) | 136 | if (chld_out.lines > (size_t)skip_stdout) |
138 | for (i = skip_stdout; i < chld_out.lines; i++) | 137 | for (size_t i = skip_stdout; i < chld_out.lines; i++) |
139 | puts (chld_out.line[i]); | 138 | puts (chld_out.line[i]); |
140 | else | 139 | else |
141 | printf (_("%s - check_by_ssh: Remote command '%s' returned status %d\n"), | 140 | printf (_("%s - check_by_ssh: Remote command '%s' returned status %d\n"), |
@@ -156,7 +155,7 @@ main (int argc, char **argv) | |||
156 | 155 | ||
157 | local_time = time (NULL); | 156 | local_time = time (NULL); |
158 | commands = 0; | 157 | commands = 0; |
159 | for(i = skip_stdout; i < chld_out.lines; i++) { | 158 | for(size_t i = skip_stdout; i < chld_out.lines; i++) { |
160 | status_text = chld_out.line[i++]; | 159 | status_text = chld_out.line[i++]; |
161 | if (i == chld_out.lines || strstr (chld_out.line[i], "STATUS CODE: ") == NULL) | 160 | if (i == chld_out.lines || strstr (chld_out.line[i], "STATUS CODE: ") == NULL) |
162 | die (STATE_UNKNOWN, _("%s: Error parsing output\n"), progname); | 161 | die (STATE_UNKNOWN, _("%s: Error parsing output\n"), progname); |
@@ -235,7 +234,7 @@ process_arguments (int argc, char **argv) | |||
235 | print_help (); | 234 | print_help (); |
236 | exit (STATE_UNKNOWN); | 235 | exit (STATE_UNKNOWN); |
237 | case 'v': /* help */ | 236 | case 'v': /* help */ |
238 | verbose = TRUE; | 237 | verbose = true; |
239 | break; | 238 | break; |
240 | case 't': /* timeout period */ | 239 | case 't': /* timeout period */ |
241 | if (!is_integer (optarg)) | 240 | if (!is_integer (optarg)) |
@@ -244,7 +243,7 @@ process_arguments (int argc, char **argv) | |||
244 | timeout_interval = atoi (optarg); | 243 | timeout_interval = atoi (optarg); |
245 | break; | 244 | break; |
246 | case 'U': | 245 | case 'U': |
247 | unknown_timeout = TRUE; | 246 | unknown_timeout = true; |
248 | break; | 247 | break; |
249 | case 'H': /* host */ | 248 | case 'H': /* host */ |
250 | hostname = optarg; | 249 | hostname = optarg; |
@@ -257,7 +256,7 @@ process_arguments (int argc, char **argv) | |||
257 | break; | 256 | break; |
258 | case 'O': /* output file */ | 257 | case 'O': /* output file */ |
259 | outputfile = optarg; | 258 | outputfile = optarg; |
260 | passive = TRUE; | 259 | passive = true; |
261 | break; | 260 | break; |
262 | case 's': /* description of service to check */ | 261 | case 's': /* description of service to check */ |
263 | p1 = optarg; | 262 | p1 = optarg; |
diff --git a/plugins/check_curl.c b/plugins/check_curl.c index d0871c48..d3bddacd 100644 --- a/plugins/check_curl.c +++ b/plugins/check_curl.c | |||
@@ -134,6 +134,7 @@ char regexp[MAX_RE_SIZE]; | |||
134 | int cflags = REG_NOSUB | REG_EXTENDED | REG_NEWLINE; | 134 | int cflags = REG_NOSUB | REG_EXTENDED | REG_NEWLINE; |
135 | int errcode; | 135 | int errcode; |
136 | bool invert_regex = false; | 136 | bool invert_regex = false; |
137 | int state_regex = STATE_CRITICAL; | ||
137 | 138 | ||
138 | char *server_address = NULL; | 139 | char *server_address = NULL; |
139 | char *host_name = NULL; | 140 | char *host_name = NULL; |
@@ -213,6 +214,7 @@ char *client_privkey = NULL; | |||
213 | char *ca_cert = NULL; | 214 | char *ca_cert = NULL; |
214 | bool verify_peer_and_host = false; | 215 | bool verify_peer_and_host = false; |
215 | bool is_openssl_callback = false; | 216 | bool is_openssl_callback = false; |
217 | bool add_sslctx_verify_fun = false; | ||
216 | #if defined(HAVE_SSL) && defined(USE_OPENSSL) | 218 | #if defined(HAVE_SSL) && defined(USE_OPENSSL) |
217 | X509 *cert = NULL; | 219 | X509 *cert = NULL; |
218 | #endif /* defined(HAVE_SSL) && defined(USE_OPENSSL) */ | 220 | #endif /* defined(HAVE_SSL) && defined(USE_OPENSSL) */ |
@@ -223,6 +225,7 @@ curlhelp_ssl_library ssl_library = CURLHELP_SSL_LIBRARY_UNKNOWN; | |||
223 | int curl_http_version = CURL_HTTP_VERSION_NONE; | 225 | int curl_http_version = CURL_HTTP_VERSION_NONE; |
224 | bool automatic_decompression = false; | 226 | bool automatic_decompression = false; |
225 | char *cookie_jar_file = NULL; | 227 | char *cookie_jar_file = NULL; |
228 | bool haproxy_protocol = false; | ||
226 | 229 | ||
227 | bool process_arguments (int, char**); | 230 | bool process_arguments (int, char**); |
228 | void handle_curl_option_return_code (CURLcode res, const char* option); | 231 | void handle_curl_option_return_code (CURLcode res, const char* option); |
@@ -239,10 +242,10 @@ void print_help (void); | |||
239 | void print_usage (void); | 242 | void print_usage (void); |
240 | void print_curl_version (void); | 243 | void print_curl_version (void); |
241 | int curlhelp_initwritebuffer (curlhelp_write_curlbuf*); | 244 | int curlhelp_initwritebuffer (curlhelp_write_curlbuf*); |
242 | int curlhelp_buffer_write_callback (void*, size_t , size_t , void*); | 245 | size_t curlhelp_buffer_write_callback(void*, size_t , size_t , void*); |
243 | void curlhelp_freewritebuffer (curlhelp_write_curlbuf*); | 246 | void curlhelp_freewritebuffer (curlhelp_write_curlbuf*); |
244 | int curlhelp_initreadbuffer (curlhelp_read_curlbuf *, const char *, size_t); | 247 | int curlhelp_initreadbuffer (curlhelp_read_curlbuf *, const char *, size_t); |
245 | int curlhelp_buffer_read_callback (void *, size_t , size_t , void *); | 248 | size_t curlhelp_buffer_read_callback(void *, size_t , size_t , void *); |
246 | void curlhelp_freereadbuffer (curlhelp_read_curlbuf *); | 249 | void curlhelp_freereadbuffer (curlhelp_read_curlbuf *); |
247 | curlhelp_ssl_library curlhelp_get_ssl_library (); | 250 | curlhelp_ssl_library curlhelp_get_ssl_library (); |
248 | const char* curlhelp_get_ssl_library_string (curlhelp_ssl_library); | 251 | const char* curlhelp_get_ssl_library_string (curlhelp_ssl_library); |
@@ -297,7 +300,7 @@ main (int argc, char **argv) | |||
297 | 300 | ||
298 | int verify_callback(int preverify_ok, X509_STORE_CTX *x509_ctx) | 301 | int verify_callback(int preverify_ok, X509_STORE_CTX *x509_ctx) |
299 | { | 302 | { |
300 | (void) preverify_ok; | 303 | (void) preverify_ok; |
301 | /* TODO: we get all certificates of the chain, so which ones | 304 | /* TODO: we get all certificates of the chain, so which ones |
302 | * should we test? | 305 | * should we test? |
303 | * TODO: is the last certificate always the server certificate? | 306 | * TODO: is the last certificate always the server certificate? |
@@ -322,9 +325,18 @@ int verify_callback(int preverify_ok, X509_STORE_CTX *x509_ctx) | |||
322 | 325 | ||
323 | CURLcode sslctxfun(CURL *curl, SSL_CTX *sslctx, void *parm) | 326 | CURLcode sslctxfun(CURL *curl, SSL_CTX *sslctx, void *parm) |
324 | { | 327 | { |
325 | (void) curl; // ignore unused parameter | 328 | (void) curl; // ignore unused parameter |
326 | (void) parm; // ignore unused parameter | 329 | (void) parm; // ignore unused parameter |
327 | SSL_CTX_set_verify(sslctx, SSL_VERIFY_PEER, verify_callback); | 330 | if(add_sslctx_verify_fun) { |
331 | SSL_CTX_set_verify(sslctx, SSL_VERIFY_PEER, verify_callback); | ||
332 | } | ||
333 | |||
334 | // workaround for issue: | ||
335 | // OpenSSL SSL_read: error:0A000126:SSL routines::unexpected eof while reading, errno 0 | ||
336 | // see discussion https://github.com/openssl/openssl/discussions/22690 | ||
337 | #ifdef SSL_OP_IGNORE_UNEXPECTED_EOF | ||
338 | SSL_CTX_set_options(sslctx, SSL_OP_IGNORE_UNEXPECTED_EOF); | ||
339 | #endif | ||
328 | 340 | ||
329 | return CURLE_OK; | 341 | return CURLE_OK; |
330 | } | 342 | } |
@@ -395,7 +407,7 @@ lookup_host (const char *host, char *buf, size_t buflen) | |||
395 | char addrstr[100]; | 407 | char addrstr[100]; |
396 | size_t addrstr_len; | 408 | size_t addrstr_len; |
397 | int errcode; | 409 | int errcode; |
398 | void *ptr; | 410 | void *ptr = { 0 }; |
399 | size_t buflen_remaining = buflen - 1; | 411 | size_t buflen_remaining = buflen - 1; |
400 | 412 | ||
401 | memset (&hints, 0, sizeof (hints)); | 413 | memset (&hints, 0, sizeof (hints)); |
@@ -466,6 +478,7 @@ int | |||
466 | check_http (void) | 478 | check_http (void) |
467 | { | 479 | { |
468 | int result = STATE_OK; | 480 | int result = STATE_OK; |
481 | int result_ssl = STATE_OK; | ||
469 | int page_len = 0; | 482 | int page_len = 0; |
470 | int i; | 483 | int i; |
471 | char *force_host_header = NULL; | 484 | char *force_host_header = NULL; |
@@ -485,7 +498,7 @@ check_http (void) | |||
485 | 498 | ||
486 | /* register cleanup function to shut down libcurl properly */ | 499 | /* register cleanup function to shut down libcurl properly */ |
487 | atexit (cleanup); | 500 | atexit (cleanup); |
488 | 501 | ||
489 | if (verbose >= 1) | 502 | if (verbose >= 1) |
490 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_VERBOSE, 1), "CURLOPT_VERBOSE"); | 503 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_VERBOSE, 1), "CURLOPT_VERBOSE"); |
491 | 504 | ||
@@ -520,6 +533,11 @@ check_http (void) | |||
520 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_CONNECTTIMEOUT, socket_timeout), "CURLOPT_CONNECTTIMEOUT"); | 533 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_CONNECTTIMEOUT, socket_timeout), "CURLOPT_CONNECTTIMEOUT"); |
521 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_TIMEOUT, socket_timeout), "CURLOPT_TIMEOUT"); | 534 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_TIMEOUT, socket_timeout), "CURLOPT_TIMEOUT"); |
522 | 535 | ||
536 | /* enable haproxy protocol */ | ||
537 | if (haproxy_protocol) { | ||
538 | handle_curl_option_return_code(curl_easy_setopt(curl, CURLOPT_HAPROXYPROTOCOL, 1L), "CURLOPT_HAPROXYPROTOCOL"); | ||
539 | } | ||
540 | |||
523 | // 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 | 541 | // 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 |
524 | if(use_ssl && host_name != NULL) { | 542 | if(use_ssl && host_name != NULL) { |
525 | if ( (res=lookup_host (server_address, addrstr, DEFAULT_BUFFER_SIZE/2)) != 0) { | 543 | if ( (res=lookup_host (server_address, addrstr, DEFAULT_BUFFER_SIZE/2)) != 0) { |
@@ -670,9 +688,8 @@ check_http (void) | |||
670 | * OpenSSL-style libraries only!) */ | 688 | * OpenSSL-style libraries only!) */ |
671 | #ifdef USE_OPENSSL | 689 | #ifdef USE_OPENSSL |
672 | /* libcurl and monitoring plugins built with OpenSSL, good */ | 690 | /* libcurl and monitoring plugins built with OpenSSL, good */ |
673 | handle_curl_option_return_code (curl_easy_setopt(curl, CURLOPT_SSL_CTX_FUNCTION, sslctxfun), "CURLOPT_SSL_CTX_FUNCTION"); | 691 | add_sslctx_verify_fun = true; |
674 | is_openssl_callback = true; | 692 | is_openssl_callback = true; |
675 | #else /* USE_OPENSSL */ | ||
676 | #endif /* USE_OPENSSL */ | 693 | #endif /* USE_OPENSSL */ |
677 | /* libcurl is built with OpenSSL, monitoring plugins, so falling | 694 | /* libcurl is built with OpenSSL, monitoring plugins, so falling |
678 | * back to manually extracting certificate information */ | 695 | * back to manually extracting certificate information */ |
@@ -705,12 +722,18 @@ check_http (void) | |||
705 | #else /* LIBCURL_VERSION_NUM >= MAKE_LIBCURL_VERSION(7, 19, 1) */ | 722 | #else /* LIBCURL_VERSION_NUM >= MAKE_LIBCURL_VERSION(7, 19, 1) */ |
706 | /* old libcurl, our only hope is OpenSSL, otherwise we are out of luck */ | 723 | /* old libcurl, our only hope is OpenSSL, otherwise we are out of luck */ |
707 | if (ssl_library == CURLHELP_SSL_LIBRARY_OPENSSL || ssl_library == CURLHELP_SSL_LIBRARY_LIBRESSL) | 724 | if (ssl_library == CURLHELP_SSL_LIBRARY_OPENSSL || ssl_library == CURLHELP_SSL_LIBRARY_LIBRESSL) |
708 | handle_curl_option_return_code (curl_easy_setopt(curl, CURLOPT_SSL_CTX_FUNCTION, sslctxfun), "CURLOPT_SSL_CTX_FUNCTION"); | 725 | add_sslctx_verify_fun = true; |
709 | else | 726 | else |
710 | die (STATE_CRITICAL, "HTTP CRITICAL - Cannot retrieve certificates (no CURLOPT_SSL_CTX_FUNCTION, no OpenSSL library or libcurl too old and has no CURLOPT_CERTINFO)\n"); | 727 | die (STATE_CRITICAL, "HTTP CRITICAL - Cannot retrieve certificates (no CURLOPT_SSL_CTX_FUNCTION, no OpenSSL library or libcurl too old and has no CURLOPT_CERTINFO)\n"); |
711 | #endif /* LIBCURL_VERSION_NUM >= MAKE_LIBCURL_VERSION(7, 19, 1) */ | 728 | #endif /* LIBCURL_VERSION_NUM >= MAKE_LIBCURL_VERSION(7, 19, 1) */ |
712 | } | 729 | } |
713 | 730 | ||
731 | #if LIBCURL_VERSION_NUM >= MAKE_LIBCURL_VERSION(7, 10, 6) /* required for CURLOPT_SSL_CTX_FUNCTION */ | ||
732 | // ssl ctx function is not available with all ssl backends | ||
733 | if (curl_easy_setopt(curl, CURLOPT_SSL_CTX_FUNCTION, NULL) != CURLE_UNKNOWN_OPTION) | ||
734 | handle_curl_option_return_code (curl_easy_setopt(curl, CURLOPT_SSL_CTX_FUNCTION, sslctxfun), "CURLOPT_SSL_CTX_FUNCTION"); | ||
735 | #endif | ||
736 | |||
714 | #endif /* LIBCURL_FEATURE_SSL */ | 737 | #endif /* LIBCURL_FEATURE_SSL */ |
715 | 738 | ||
716 | /* set default or user-given user agent identification */ | 739 | /* set default or user-given user agent identification */ |
@@ -805,7 +828,7 @@ check_http (void) | |||
805 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_INFILESIZE, (curl_off_t)strlen (http_post_data)), "CURLOPT_INFILESIZE"); | 828 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_INFILESIZE, (curl_off_t)strlen (http_post_data)), "CURLOPT_INFILESIZE"); |
806 | } | 829 | } |
807 | } | 830 | } |
808 | 831 | ||
809 | /* cookie handling */ | 832 | /* cookie handling */ |
810 | if (cookie_jar_file != NULL) { | 833 | if (cookie_jar_file != NULL) { |
811 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_COOKIEJAR, cookie_jar_file), "CURLOPT_COOKIEJAR"); | 834 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_COOKIEJAR, cookie_jar_file), "CURLOPT_COOKIEJAR"); |
@@ -845,9 +868,9 @@ check_http (void) | |||
845 | /* check certificate with OpenSSL functions, curl has been built against OpenSSL | 868 | /* check certificate with OpenSSL functions, curl has been built against OpenSSL |
846 | * and we actually have OpenSSL in the monitoring tools | 869 | * and we actually have OpenSSL in the monitoring tools |
847 | */ | 870 | */ |
848 | result = np_net_ssl_check_certificate(cert, days_till_exp_warn, days_till_exp_crit); | 871 | result_ssl = np_net_ssl_check_certificate(cert, days_till_exp_warn, days_till_exp_crit); |
849 | if (!continue_after_check_cert) { | 872 | if (!continue_after_check_cert) { |
850 | return result; | 873 | return result_ssl; |
851 | } | 874 | } |
852 | #else /* USE_OPENSSL */ | 875 | #else /* USE_OPENSSL */ |
853 | die (STATE_CRITICAL, "HTTP CRITICAL - Cannot retrieve certificates - OpenSSL callback used and not linked against OpenSSL\n"); | 876 | die (STATE_CRITICAL, "HTTP CRITICAL - Cannot retrieve certificates - OpenSSL callback used and not linked against OpenSSL\n"); |
@@ -891,17 +914,17 @@ GOT_FIRST_CERT: | |||
891 | die (STATE_CRITICAL, "HTTP CRITICAL - %s\n", msg); | 914 | die (STATE_CRITICAL, "HTTP CRITICAL - %s\n", msg); |
892 | } | 915 | } |
893 | BIO_free (cert_BIO); | 916 | BIO_free (cert_BIO); |
894 | result = np_net_ssl_check_certificate(cert, days_till_exp_warn, days_till_exp_crit); | 917 | result_ssl = np_net_ssl_check_certificate(cert, days_till_exp_warn, days_till_exp_crit); |
895 | if (!continue_after_check_cert) { | 918 | if (!continue_after_check_cert) { |
896 | return result; | 919 | return result_ssl; |
897 | } | 920 | } |
898 | #else /* USE_OPENSSL */ | 921 | #else /* USE_OPENSSL */ |
899 | /* We assume we don't have OpenSSL and np_net_ssl_check_certificate at our disposal, | 922 | /* We assume we don't have OpenSSL and np_net_ssl_check_certificate at our disposal, |
900 | * so we use the libcurl CURLINFO data | 923 | * so we use the libcurl CURLINFO data |
901 | */ | 924 | */ |
902 | result = net_noopenssl_check_certificate(&cert_ptr, days_till_exp_warn, days_till_exp_crit); | 925 | result_ssl = net_noopenssl_check_certificate(&cert_ptr, days_till_exp_warn, days_till_exp_crit); |
903 | if (!continue_after_check_cert) { | 926 | if (!continue_after_check_cert) { |
904 | return result; | 927 | return result_ssl; |
905 | } | 928 | } |
906 | #endif /* USE_OPENSSL */ | 929 | #endif /* USE_OPENSSL */ |
907 | } else { | 930 | } else { |
@@ -1127,7 +1150,7 @@ GOT_FIRST_CERT: | |||
1127 | strcpy(msg, tmp); | 1150 | strcpy(msg, tmp); |
1128 | 1151 | ||
1129 | } | 1152 | } |
1130 | result = STATE_CRITICAL; | 1153 | result = state_regex; |
1131 | } else { | 1154 | } else { |
1132 | regerror (errcode, &preg, errbuf, MAX_INPUT_BUFFER); | 1155 | regerror (errcode, &preg, errbuf, MAX_INPUT_BUFFER); |
1133 | 1156 | ||
@@ -1167,9 +1190,9 @@ GOT_FIRST_CERT: | |||
1167 | else | 1190 | else |
1168 | msg[strlen(msg)-3] = '\0'; | 1191 | msg[strlen(msg)-3] = '\0'; |
1169 | } | 1192 | } |
1170 | 1193 | ||
1171 | /* TODO: separate _() msg and status code: die (result, "HTTP %s: %s\n", state_text(result), msg); */ | 1194 | /* TODO: separate _() msg and status code: die (result, "HTTP %s: %s\n", state_text(result), msg); */ |
1172 | die (result, "HTTP %s: %s %d %s%s%s - %d bytes in %.3f second response time %s|%s\n%s%s", | 1195 | die (max_state_alt(result, result_ssl), "HTTP %s: %s %d %s%s%s - %d bytes in %.3f second response time %s|%s\n%s%s", |
1173 | state_text(result), string_statuscode (status_line.http_major, status_line.http_minor), | 1196 | state_text(result), string_statuscode (status_line.http_major, status_line.http_minor), |
1174 | status_line.http_code, status_line.msg, | 1197 | status_line.http_code, status_line.msg, |
1175 | strlen(msg) > 0 ? " - " : "", | 1198 | strlen(msg) > 0 ? " - " : "", |
@@ -1179,23 +1202,23 @@ GOT_FIRST_CERT: | |||
1179 | (show_body ? body_buf.buf : ""), | 1202 | (show_body ? body_buf.buf : ""), |
1180 | (show_body ? "\n" : "") ); | 1203 | (show_body ? "\n" : "") ); |
1181 | 1204 | ||
1182 | return result; | 1205 | return max_state_alt(result, result_ssl); |
1183 | } | 1206 | } |
1184 | 1207 | ||
1185 | int | 1208 | int |
1186 | uri_strcmp (const UriTextRangeA range, const char* s) | 1209 | uri_strcmp (const UriTextRangeA range, const char* s) |
1187 | { | 1210 | { |
1188 | if (!range.first) return -1; | 1211 | if (!range.first) return -1; |
1189 | if (range.afterLast - range.first < strlen (s)) return -1; | 1212 | if ( (size_t)(range.afterLast - range.first) < strlen (s) ) return -1; |
1190 | return strncmp (s, range.first, min( range.afterLast - range.first, strlen (s))); | 1213 | return strncmp (s, range.first, min( (size_t)(range.afterLast - range.first), strlen (s))); |
1191 | } | 1214 | } |
1192 | 1215 | ||
1193 | char* | 1216 | char* |
1194 | uri_string (const UriTextRangeA range, char* buf, size_t buflen) | 1217 | uri_string (const UriTextRangeA range, char* buf, size_t buflen) |
1195 | { | 1218 | { |
1196 | if (!range.first) return "(null)"; | 1219 | if (!range.first) return "(null)"; |
1197 | strncpy (buf, range.first, max (buflen-1, range.afterLast - range.first)); | 1220 | strncpy (buf, range.first, max (buflen-1, (size_t)(range.afterLast - range.first))); |
1198 | buf[max (buflen-1, range.afterLast - range.first)] = '\0'; | 1221 | buf[max (buflen-1, (size_t)(range.afterLast - range.first))] = '\0'; |
1199 | buf[range.afterLast - range.first] = '\0'; | 1222 | buf[range.afterLast - range.first] = '\0'; |
1200 | return buf; | 1223 | return buf; |
1201 | } | 1224 | } |
@@ -1218,6 +1241,10 @@ redir (curlhelp_write_curlbuf* header_buf) | |||
1218 | &status_line.http_major, &status_line.http_minor, &status_line.http_code, &status_line.msg, &msglen, | 1241 | &status_line.http_major, &status_line.http_minor, &status_line.http_code, &status_line.msg, &msglen, |
1219 | headers, &nof_headers, 0); | 1242 | headers, &nof_headers, 0); |
1220 | 1243 | ||
1244 | if (res == -1) { | ||
1245 | die (STATE_UNKNOWN, _("HTTP UNKNOWN - Failed to parse Response\n")); | ||
1246 | } | ||
1247 | |||
1221 | location = get_header_value (headers, nof_headers, "location"); | 1248 | location = get_header_value (headers, nof_headers, "location"); |
1222 | 1249 | ||
1223 | if (verbose >= 2) | 1250 | if (verbose >= 2) |
@@ -1274,10 +1301,12 @@ redir (curlhelp_write_curlbuf* header_buf) | |||
1274 | } | 1301 | } |
1275 | } | 1302 | } |
1276 | 1303 | ||
1277 | if (!uri_strcmp (uri.scheme, "https")) | 1304 | if (uri.scheme.first) { |
1278 | use_ssl = true; | 1305 | if (!uri_strcmp (uri.scheme, "https")) |
1279 | else | 1306 | use_ssl = true; |
1280 | use_ssl = false; | 1307 | else |
1308 | use_ssl = false; | ||
1309 | } | ||
1281 | 1310 | ||
1282 | /* we do a sloppy test here only, because uriparser would have failed | 1311 | /* we do a sloppy test here only, because uriparser would have failed |
1283 | * above, if the port would be invalid, we just check for MAX_PORT | 1312 | * above, if the port would be invalid, we just check for MAX_PORT |
@@ -1295,10 +1324,13 @@ redir (curlhelp_write_curlbuf* header_buf) | |||
1295 | MAX_PORT, location, display_html ? "</A>" : ""); | 1324 | MAX_PORT, location, display_html ? "</A>" : ""); |
1296 | 1325 | ||
1297 | /* by RFC 7231 relative URLs in Location should be taken relative to | 1326 | /* by RFC 7231 relative URLs in Location should be taken relative to |
1298 | * the original URL, so wy try to form a new absolute URL here | 1327 | * the original URL, so we try to form a new absolute URL here |
1299 | */ | 1328 | */ |
1300 | if (!uri.scheme.first && !uri.hostText.first) { | 1329 | if (!uri.scheme.first && !uri.hostText.first) { |
1301 | new_host = strdup (host_name ? host_name : server_address); | 1330 | new_host = strdup (host_name ? host_name : server_address); |
1331 | new_port = server_port; | ||
1332 | if(use_ssl) | ||
1333 | uri_string (uri.scheme, "https", DEFAULT_BUFFER_SIZE); | ||
1302 | } else { | 1334 | } else { |
1303 | new_host = strdup (uri_string (uri.hostText, buf, DEFAULT_BUFFER_SIZE)); | 1335 | new_host = strdup (uri_string (uri.hostText, buf, DEFAULT_BUFFER_SIZE)); |
1304 | } | 1336 | } |
@@ -1380,7 +1412,9 @@ process_arguments (int argc, char **argv) | |||
1380 | CA_CERT_OPTION, | 1412 | CA_CERT_OPTION, |
1381 | HTTP_VERSION_OPTION, | 1413 | HTTP_VERSION_OPTION, |
1382 | AUTOMATIC_DECOMPRESSION, | 1414 | AUTOMATIC_DECOMPRESSION, |
1383 | COOKIE_JAR | 1415 | COOKIE_JAR, |
1416 | HAPROXY_PROTOCOL, | ||
1417 | STATE_REGEX | ||
1384 | }; | 1418 | }; |
1385 | 1419 | ||
1386 | int option = 0; | 1420 | int option = 0; |
@@ -1419,6 +1453,7 @@ process_arguments (int argc, char **argv) | |||
1419 | {"content-type", required_argument, 0, 'T'}, | 1453 | {"content-type", required_argument, 0, 'T'}, |
1420 | {"pagesize", required_argument, 0, 'm'}, | 1454 | {"pagesize", required_argument, 0, 'm'}, |
1421 | {"invert-regex", no_argument, NULL, INVERT_REGEX}, | 1455 | {"invert-regex", no_argument, NULL, INVERT_REGEX}, |
1456 | {"state-regex", required_argument, 0, STATE_REGEX}, | ||
1422 | {"use-ipv4", no_argument, 0, '4'}, | 1457 | {"use-ipv4", no_argument, 0, '4'}, |
1423 | {"use-ipv6", no_argument, 0, '6'}, | 1458 | {"use-ipv6", no_argument, 0, '6'}, |
1424 | {"extended-perfdata", no_argument, 0, 'E'}, | 1459 | {"extended-perfdata", no_argument, 0, 'E'}, |
@@ -1427,6 +1462,7 @@ process_arguments (int argc, char **argv) | |||
1427 | {"http-version", required_argument, 0, HTTP_VERSION_OPTION}, | 1462 | {"http-version", required_argument, 0, HTTP_VERSION_OPTION}, |
1428 | {"enable-automatic-decompression", no_argument, 0, AUTOMATIC_DECOMPRESSION}, | 1463 | {"enable-automatic-decompression", no_argument, 0, AUTOMATIC_DECOMPRESSION}, |
1429 | {"cookie-jar", required_argument, 0, COOKIE_JAR}, | 1464 | {"cookie-jar", required_argument, 0, COOKIE_JAR}, |
1465 | {"haproxy-protocol", no_argument, 0, HAPROXY_PROTOCOL}, | ||
1430 | {0, 0, 0, 0} | 1466 | {0, 0, 0, 0} |
1431 | }; | 1467 | }; |
1432 | 1468 | ||
@@ -1694,7 +1730,7 @@ process_arguments (int argc, char **argv) | |||
1694 | else { | 1730 | else { |
1695 | max_depth = atoi (optarg); | 1731 | max_depth = atoi (optarg); |
1696 | } | 1732 | } |
1697 | break; | 1733 | break; |
1698 | case 'f': /* onredirect */ | 1734 | case 'f': /* onredirect */ |
1699 | if (!strcmp (optarg, "ok")) | 1735 | if (!strcmp (optarg, "ok")) |
1700 | onredirect = STATE_OK; | 1736 | onredirect = STATE_OK; |
@@ -1753,6 +1789,13 @@ process_arguments (int argc, char **argv) | |||
1753 | case INVERT_REGEX: | 1789 | case INVERT_REGEX: |
1754 | invert_regex = true; | 1790 | invert_regex = true; |
1755 | break; | 1791 | break; |
1792 | case STATE_REGEX: | ||
1793 | if (!strcasecmp (optarg, "critical")) | ||
1794 | state_regex = STATE_CRITICAL; | ||
1795 | else if (!strcasecmp (optarg, "warning")) | ||
1796 | state_regex = STATE_WARNING; | ||
1797 | else usage2 (_("Invalid state-regex option"), optarg); | ||
1798 | break; | ||
1756 | case '4': | 1799 | case '4': |
1757 | address_family = AF_INET; | 1800 | address_family = AF_INET; |
1758 | break; | 1801 | break; |
@@ -1837,6 +1880,9 @@ process_arguments (int argc, char **argv) | |||
1837 | case COOKIE_JAR: | 1880 | case COOKIE_JAR: |
1838 | cookie_jar_file = optarg; | 1881 | cookie_jar_file = optarg; |
1839 | break; | 1882 | break; |
1883 | case HAPROXY_PROTOCOL: | ||
1884 | haproxy_protocol = true; | ||
1885 | break; | ||
1840 | case '?': | 1886 | case '?': |
1841 | /* print short usage statement if args not parsable */ | 1887 | /* print short usage statement if args not parsable */ |
1842 | usage5 (); | 1888 | usage5 (); |
@@ -1977,8 +2023,11 @@ print_help (void) | |||
1977 | printf (" %s\n", _("Note: SNI is not supported in libcurl before 7.18.1")); | 2023 | printf (" %s\n", _("Note: SNI is not supported in libcurl before 7.18.1")); |
1978 | #endif | 2024 | #endif |
1979 | printf (" %s\n", "-C, --certificate=INTEGER[,INTEGER]"); | 2025 | printf (" %s\n", "-C, --certificate=INTEGER[,INTEGER]"); |
1980 | printf (" %s\n", _("Minimum number of days a certificate has to be valid. Port defaults to 443")); | 2026 | printf (" %s\n", _("Minimum number of days a certificate has to be valid. Port defaults to 443.")); |
1981 | printf (" %s\n", _("(when this option is used the URL is not checked by default. You can use")); | 2027 | printf (" %s\n", _("A STATE_WARNING is returned if the certificate has a validity less than the")); |
2028 | printf (" %s\n", _("first agument's value. If there is a second argument and the certificate's")); | ||
2029 | printf (" %s\n", _("validity is less than its value, a STATE_CRITICAL is returned.")); | ||
2030 | printf (" %s\n", _("(When this option is used the URL is not checked by default. You can use")); | ||
1982 | printf (" %s\n", _(" --continue-after-certificate to override this behavior)")); | 2031 | printf (" %s\n", _(" --continue-after-certificate to override this behavior)")); |
1983 | printf (" %s\n", "--continue-after-certificate"); | 2032 | printf (" %s\n", "--continue-after-certificate"); |
1984 | printf (" %s\n", _("Allows the HTTP check to continue after performing the certificate check.")); | 2033 | printf (" %s\n", _("Allows the HTTP check to continue after performing the certificate check.")); |
@@ -2007,7 +2056,7 @@ print_help (void) | |||
2007 | printf (" %s\n", "-u, --url=PATH"); | 2056 | printf (" %s\n", "-u, --url=PATH"); |
2008 | printf (" %s\n", _("URL to GET or POST (default: /)")); | 2057 | printf (" %s\n", _("URL to GET or POST (default: /)")); |
2009 | printf (" %s\n", "-P, --post=STRING"); | 2058 | printf (" %s\n", "-P, --post=STRING"); |
2010 | printf (" %s\n", _("URL encoded http POST data")); | 2059 | printf (" %s\n", _("URL decoded http POST data")); |
2011 | printf (" %s\n", "-j, --method=STRING (for example: HEAD, OPTIONS, TRACE, PUT, DELETE, CONNECT)"); | 2060 | printf (" %s\n", "-j, --method=STRING (for example: HEAD, OPTIONS, TRACE, PUT, DELETE, CONNECT)"); |
2012 | printf (" %s\n", _("Set HTTP method.")); | 2061 | printf (" %s\n", _("Set HTTP method.")); |
2013 | printf (" %s\n", "-N, --no-body"); | 2062 | printf (" %s\n", "-N, --no-body"); |
@@ -2025,7 +2074,10 @@ print_help (void) | |||
2025 | printf (" %s\n", "-R, --eregi=STRING"); | 2074 | printf (" %s\n", "-R, --eregi=STRING"); |
2026 | printf (" %s\n", _("Search page for case-insensitive regex STRING")); | 2075 | printf (" %s\n", _("Search page for case-insensitive regex STRING")); |
2027 | printf (" %s\n", "--invert-regex"); | 2076 | printf (" %s\n", "--invert-regex"); |
2028 | printf (" %s\n", _("Return CRITICAL if found, OK if not\n")); | 2077 | printf (" %s\n", _("Return STATE if found, OK if not (STATE is CRITICAL, per default)")); |
2078 | printf (" %s\n", _("can be changed with --state--regex)")); | ||
2079 | printf (" %s\n", "--state-regex=STATE"); | ||
2080 | printf (" %s\n", _("Return STATE if regex is found, OK if not. STATE can be one of \"critical\",\"warning\"")); | ||
2029 | printf (" %s\n", "-a, --authorization=AUTH_PAIR"); | 2081 | printf (" %s\n", "-a, --authorization=AUTH_PAIR"); |
2030 | printf (" %s\n", _("Username:password on sites with basic authentication")); | 2082 | printf (" %s\n", _("Username:password on sites with basic authentication")); |
2031 | printf (" %s\n", "-b, --proxy-authorization=AUTH_PAIR"); | 2083 | printf (" %s\n", "-b, --proxy-authorization=AUTH_PAIR"); |
@@ -2056,7 +2108,9 @@ print_help (void) | |||
2056 | printf (" %s\n", _("1.0 = HTTP/1.0, 1.1 = HTTP/1.1, 2.0 = HTTP/2 (HTTP/2 will fail without -S)")); | 2108 | printf (" %s\n", _("1.0 = HTTP/1.0, 1.1 = HTTP/1.1, 2.0 = HTTP/2 (HTTP/2 will fail without -S)")); |
2057 | printf (" %s\n", "--enable-automatic-decompression"); | 2109 | printf (" %s\n", "--enable-automatic-decompression"); |
2058 | printf (" %s\n", _("Enable automatic decompression of body (CURLOPT_ACCEPT_ENCODING).")); | 2110 | printf (" %s\n", _("Enable automatic decompression of body (CURLOPT_ACCEPT_ENCODING).")); |
2059 | printf (" %s\n", "---cookie-jar=FILE"); | 2111 | printf(" %s\n", "--haproxy-protocol"); |
2112 | printf(" %s\n", _("Send HAProxy proxy protocol v1 header (CURLOPT_HAPROXYPROTOCOL).")); | ||
2113 | printf (" %s\n", "--cookie-jar=FILE"); | ||
2060 | printf (" %s\n", _("Store cookies in the cookie jar and send them out when requested.")); | 2114 | printf (" %s\n", _("Store cookies in the cookie jar and send them out when requested.")); |
2061 | printf ("\n"); | 2115 | printf ("\n"); |
2062 | 2116 | ||
@@ -2140,7 +2194,7 @@ print_usage (void) | |||
2140 | printf (" [-b proxy_auth] [-f <ok|warning|critical|follow|sticky|stickyport|curl>]\n"); | 2194 | printf (" [-b proxy_auth] [-f <ok|warning|critical|follow|sticky|stickyport|curl>]\n"); |
2141 | printf (" [-e <expect>] [-d string] [-s string] [-l] [-r <regex> | -R <case-insensitive regex>]\n"); | 2195 | printf (" [-e <expect>] [-d string] [-s string] [-l] [-r <regex> | -R <case-insensitive regex>]\n"); |
2142 | printf (" [-P string] [-m <min_pg_size>:<max_pg_size>] [-4|-6] [-N] [-M <age>]\n"); | 2196 | printf (" [-P string] [-m <min_pg_size>:<max_pg_size>] [-4|-6] [-N] [-M <age>]\n"); |
2143 | printf (" [-A string] [-k string] [-S <version>] [--sni]\n"); | 2197 | printf (" [-A string] [-k string] [-S <version>] [--sni] [--haproxy-protocol]\n"); |
2144 | printf (" [-T <content-type>] [-j method]\n"); | 2198 | printf (" [-T <content-type>] [-j method]\n"); |
2145 | printf (" [--http-version=<version>] [--enable-automatic-decompression]\n"); | 2199 | printf (" [--http-version=<version>] [--enable-automatic-decompression]\n"); |
2146 | printf (" [--cookie-jar=<cookie jar file>\n"); | 2200 | printf (" [--cookie-jar=<cookie jar file>\n"); |
@@ -2151,8 +2205,6 @@ print_usage (void) | |||
2151 | printf ("%s\n", _("In the first form, make an HTTP request.")); | 2205 | printf ("%s\n", _("In the first form, make an HTTP request.")); |
2152 | printf ("%s\n\n", _("In the second form, connect to the server and check the TLS certificate.")); | 2206 | printf ("%s\n\n", _("In the second form, connect to the server and check the TLS certificate.")); |
2153 | #endif | 2207 | #endif |
2154 | printf ("%s\n", _("WARNING: check_curl is experimental. Please use")); | ||
2155 | printf ("%s\n\n", _("check_http if you need a stable version.")); | ||
2156 | } | 2208 | } |
2157 | 2209 | ||
2158 | void | 2210 | void |
@@ -2171,8 +2223,7 @@ curlhelp_initwritebuffer (curlhelp_write_curlbuf *buf) | |||
2171 | return 0; | 2223 | return 0; |
2172 | } | 2224 | } |
2173 | 2225 | ||
2174 | int | 2226 | size_t curlhelp_buffer_write_callback (void *buffer, size_t size, size_t nmemb, void *stream) |
2175 | curlhelp_buffer_write_callback (void *buffer, size_t size, size_t nmemb, void *stream) | ||
2176 | { | 2227 | { |
2177 | curlhelp_write_curlbuf *buf = (curlhelp_write_curlbuf *)stream; | 2228 | curlhelp_write_curlbuf *buf = (curlhelp_write_curlbuf *)stream; |
2178 | 2229 | ||
@@ -2192,8 +2243,7 @@ curlhelp_buffer_write_callback (void *buffer, size_t size, size_t nmemb, void *s | |||
2192 | return (int)(size * nmemb); | 2243 | return (int)(size * nmemb); |
2193 | } | 2244 | } |
2194 | 2245 | ||
2195 | int | 2246 | size_t curlhelp_buffer_read_callback(void *buffer, size_t size, size_t nmemb, void *stream) |
2196 | curlhelp_buffer_read_callback (void *buffer, size_t size, size_t nmemb, void *stream) | ||
2197 | { | 2247 | { |
2198 | curlhelp_read_curlbuf *buf = (curlhelp_read_curlbuf *)stream; | 2248 | curlhelp_read_curlbuf *buf = (curlhelp_read_curlbuf *)stream; |
2199 | 2249 | ||
@@ -2366,8 +2416,7 @@ remove_newlines (char *s) | |||
2366 | char * | 2416 | char * |
2367 | get_header_value (const struct phr_header* headers, const size_t nof_headers, const char* header) | 2417 | get_header_value (const struct phr_header* headers, const size_t nof_headers, const char* header) |
2368 | { | 2418 | { |
2369 | int i; | 2419 | for(size_t i = 0; i < nof_headers; i++ ) { |
2370 | for( i = 0; i < nof_headers; i++ ) { | ||
2371 | if(headers[i].name != NULL && strncasecmp( header, headers[i].name, max( headers[i].name_len, 4 ) ) == 0 ) { | 2420 | if(headers[i].name != NULL && strncasecmp( header, headers[i].name, max( headers[i].name_len, 4 ) ) == 0 ) { |
2372 | return strndup( headers[i].value, headers[i].value_len ); | 2421 | return strndup( headers[i].value, headers[i].value_len ); |
2373 | } | 2422 | } |
@@ -2390,6 +2439,10 @@ check_document_dates (const curlhelp_write_curlbuf *header_buf, char (*msg)[DEFA | |||
2390 | &status_line.http_major, &status_line.http_minor, &status_line.http_code, &status_line.msg, &msglen, | 2439 | &status_line.http_major, &status_line.http_minor, &status_line.http_code, &status_line.msg, &msglen, |
2391 | headers, &nof_headers, 0); | 2440 | headers, &nof_headers, 0); |
2392 | 2441 | ||
2442 | if (res == -1) { | ||
2443 | die (STATE_UNKNOWN, _("HTTP UNKNOWN - Failed to parse Response\n")); | ||
2444 | } | ||
2445 | |||
2393 | server_date = get_header_value (headers, nof_headers, "date"); | 2446 | server_date = get_header_value (headers, nof_headers, "date"); |
2394 | document_date = get_header_value (headers, nof_headers, "last-modified"); | 2447 | document_date = get_header_value (headers, nof_headers, "last-modified"); |
2395 | 2448 | ||
@@ -2465,9 +2518,7 @@ check_document_dates (const curlhelp_write_curlbuf *header_buf, char (*msg)[DEFA | |||
2465 | int | 2518 | int |
2466 | get_content_length (const curlhelp_write_curlbuf* header_buf, const curlhelp_write_curlbuf* body_buf) | 2519 | get_content_length (const curlhelp_write_curlbuf* header_buf, const curlhelp_write_curlbuf* body_buf) |
2467 | { | 2520 | { |
2468 | const char *s; | 2521 | size_t content_length = 0; |
2469 | int content_length = 0; | ||
2470 | char *copy; | ||
2471 | struct phr_header headers[255]; | 2522 | struct phr_header headers[255]; |
2472 | size_t nof_headers = 255; | 2523 | size_t nof_headers = 255; |
2473 | size_t msglen; | 2524 | size_t msglen; |
@@ -2478,6 +2529,10 @@ get_content_length (const curlhelp_write_curlbuf* header_buf, const curlhelp_wri | |||
2478 | &status_line.http_major, &status_line.http_minor, &status_line.http_code, &status_line.msg, &msglen, | 2529 | &status_line.http_major, &status_line.http_minor, &status_line.http_code, &status_line.msg, &msglen, |
2479 | headers, &nof_headers, 0); | 2530 | headers, &nof_headers, 0); |
2480 | 2531 | ||
2532 | if (res == -1) { | ||
2533 | die (STATE_UNKNOWN, _("HTTP UNKNOWN - Failed to parse Response\n")); | ||
2534 | } | ||
2535 | |||
2481 | content_length_s = get_header_value (headers, nof_headers, "content-length"); | 2536 | content_length_s = get_header_value (headers, nof_headers, "content-length"); |
2482 | if (!content_length_s) { | 2537 | if (!content_length_s) { |
2483 | return header_buf->buflen + body_buf->buflen; | 2538 | return header_buf->buflen + body_buf->buflen; |
diff --git a/plugins/check_dbi.c b/plugins/check_dbi.c index c24ca248..29c85206 100644 --- a/plugins/check_dbi.c +++ b/plugins/check_dbi.c | |||
@@ -141,7 +141,7 @@ main (int argc, char **argv) | |||
141 | if (verbose > 2) | 141 | if (verbose > 2) |
142 | printf ("Initializing DBI\n"); | 142 | printf ("Initializing DBI\n"); |
143 | 143 | ||
144 | dbi_inst *instance_p; | 144 | dbi_inst *instance_p = { 0 }; |
145 | 145 | ||
146 | if (dbi_initialize_r(NULL, instance_p) < 0) { | 146 | if (dbi_initialize_r(NULL, instance_p) < 0) { |
147 | printf ("UNKNOWN - failed to initialize DBI; possibly you don't have any drivers installed.\n"); | 147 | printf ("UNKNOWN - failed to initialize DBI; possibly you don't have any drivers installed.\n"); |
diff --git a/plugins/check_dig.c b/plugins/check_dig.c index 5d85ae26..be7a6101 100644 --- a/plugins/check_dig.c +++ b/plugins/check_dig.c | |||
@@ -56,7 +56,7 @@ char *expected_address = NULL; | |||
56 | char *dns_server = NULL; | 56 | char *dns_server = NULL; |
57 | char *dig_args = ""; | 57 | char *dig_args = ""; |
58 | char *query_transport = ""; | 58 | char *query_transport = ""; |
59 | int verbose = FALSE; | 59 | bool verbose = false; |
60 | int server_port = DEFAULT_PORT; | 60 | int server_port = DEFAULT_PORT; |
61 | int number_tries = DEFAULT_TRIES; | 61 | int number_tries = DEFAULT_TRIES; |
62 | double warning_interval = UNDEFINED; | 62 | double warning_interval = UNDEFINED; |
@@ -176,11 +176,11 @@ main (int argc, char **argv) | |||
176 | state_text (result), elapsed_time, | 176 | state_text (result), elapsed_time, |
177 | msg ? msg : _("Probably a non-existent host/domain"), | 177 | msg ? msg : _("Probably a non-existent host/domain"), |
178 | fperfdata("time", elapsed_time, "s", | 178 | fperfdata("time", elapsed_time, "s", |
179 | (warning_interval>UNDEFINED?TRUE:FALSE), | 179 | (warning_interval>UNDEFINED ? true:false), |
180 | warning_interval, | 180 | warning_interval, |
181 | (critical_interval>UNDEFINED?TRUE:FALSE), | 181 | (critical_interval>UNDEFINED ? true:false), |
182 | critical_interval, | 182 | critical_interval, |
183 | TRUE, 0, FALSE, 0)); | 183 | true, 0, false, 0)); |
184 | return result; | 184 | return result; |
185 | } | 185 | } |
186 | 186 | ||
@@ -270,7 +270,7 @@ process_arguments (int argc, char **argv) | |||
270 | dig_args = strdup(optarg); | 270 | dig_args = strdup(optarg); |
271 | break; | 271 | break; |
272 | case 'v': /* verbose */ | 272 | case 'v': /* verbose */ |
273 | verbose = TRUE; | 273 | verbose = true; |
274 | break; | 274 | break; |
275 | case 'T': | 275 | case 'T': |
276 | record_type = optarg; | 276 | record_type = optarg; |
diff --git a/plugins/check_disk.c b/plugins/check_disk.c index 05e55022..b3dd301c 100644 --- a/plugins/check_disk.c +++ b/plugins/check_disk.c | |||
@@ -46,7 +46,7 @@ const char *email = "devel@monitoring-plugins.org"; | |||
46 | #include <stdarg.h> | 46 | #include <stdarg.h> |
47 | #include "fsusage.h" | 47 | #include "fsusage.h" |
48 | #include "mountlist.h" | 48 | #include "mountlist.h" |
49 | #include "intprops.h" /* necessary for TYPE_MAXIMUM */ | 49 | #include <float.h> |
50 | #if HAVE_LIMITS_H | 50 | #if HAVE_LIMITS_H |
51 | # include <limits.h> | 51 | # include <limits.h> |
52 | #endif | 52 | #endif |
@@ -93,11 +93,11 @@ static int stat_remote_fs = 0; | |||
93 | 93 | ||
94 | /* Linked list of filesystem types to omit. | 94 | /* Linked list of filesystem types to omit. |
95 | If the list is empty, don't exclude any types. */ | 95 | If the list is empty, don't exclude any types. */ |
96 | static struct name_list *fs_exclude_list; | 96 | static struct regex_list *fs_exclude_list = NULL; |
97 | 97 | ||
98 | /* Linked list of filesystem types to check. | 98 | /* Linked list of filesystem types to check. |
99 | If the list is empty, include all types. */ | 99 | If the list is empty, include all types. */ |
100 | static struct name_list *fs_include_list; | 100 | static struct regex_list *fs_include_list; |
101 | 101 | ||
102 | static struct name_list *dp_exclude_list; | 102 | static struct name_list *dp_exclude_list; |
103 | 103 | ||
@@ -112,52 +112,48 @@ enum | |||
112 | { | 112 | { |
113 | SYNC_OPTION = CHAR_MAX + 1, | 113 | SYNC_OPTION = CHAR_MAX + 1, |
114 | NO_SYNC_OPTION, | 114 | NO_SYNC_OPTION, |
115 | BLOCK_SIZE_OPTION, | 115 | BLOCK_SIZE_OPTION |
116 | IGNORE_MISSING | ||
117 | }; | 116 | }; |
118 | 117 | ||
119 | #ifdef _AIX | 118 | #ifdef _AIX |
120 | #pragma alloca | 119 | #pragma alloca |
121 | #endif | 120 | #endif |
122 | 121 | ||
123 | int process_arguments (int, char **); | 122 | static int process_arguments (int, char **); |
124 | void print_path (const char *mypath); | 123 | static void set_all_thresholds (struct parameter_list *path); |
125 | void set_all_thresholds (struct parameter_list *path); | 124 | static void print_help (void); |
126 | int validate_arguments (uintmax_t, uintmax_t, double, double, double, double, char *); | ||
127 | void print_help (void); | ||
128 | void print_usage (void); | 125 | void print_usage (void); |
129 | double calculate_percent(uintmax_t, uintmax_t); | 126 | static double calculate_percent(uintmax_t, uintmax_t); |
130 | bool stat_path (struct parameter_list *p); | 127 | static bool stat_path (struct parameter_list *p); |
131 | void get_stats (struct parameter_list *p, struct fs_usage *fsp); | 128 | static void get_stats (struct parameter_list *p, struct fs_usage *fsp); |
132 | void get_path_stats (struct parameter_list *p, struct fs_usage *fsp); | 129 | static void get_path_stats (struct parameter_list *p, struct fs_usage *fsp); |
133 | 130 | ||
134 | char *exclude_device; | 131 | static char *units; |
135 | char *units; | 132 | static uintmax_t mult = 1024 * 1024; |
136 | uintmax_t mult = 1024 * 1024; | 133 | static int verbose = 0; |
137 | int verbose = 0; | 134 | static bool erronly = false; |
138 | int erronly = FALSE; | 135 | static bool display_mntp = false; |
139 | int display_mntp = FALSE; | 136 | static bool exact_match = false; |
140 | int exact_match = FALSE; | 137 | static bool ignore_missing = false; |
141 | bool ignore_missing = false; | 138 | static bool freespace_ignore_reserved = false; |
142 | int freespace_ignore_reserved = FALSE; | 139 | static bool display_inodes_perfdata = false; |
143 | int display_inodes_perfdata = FALSE; | 140 | static char *warn_freespace_units = NULL; |
144 | char *warn_freespace_units = NULL; | 141 | static char *crit_freespace_units = NULL; |
145 | char *crit_freespace_units = NULL; | 142 | static char *warn_freespace_percent = NULL; |
146 | char *warn_freespace_percent = NULL; | 143 | static char *crit_freespace_percent = NULL; |
147 | char *crit_freespace_percent = NULL; | 144 | static char *warn_usedspace_units = NULL; |
148 | char *warn_usedspace_units = NULL; | 145 | static char *crit_usedspace_units = NULL; |
149 | char *crit_usedspace_units = NULL; | 146 | static char *warn_usedspace_percent = NULL; |
150 | char *warn_usedspace_percent = NULL; | 147 | static char *crit_usedspace_percent = NULL; |
151 | char *crit_usedspace_percent = NULL; | 148 | static char *warn_usedinodes_percent = NULL; |
152 | char *warn_usedinodes_percent = NULL; | 149 | static char *crit_usedinodes_percent = NULL; |
153 | char *crit_usedinodes_percent = NULL; | 150 | static char *warn_freeinodes_percent = NULL; |
154 | char *warn_freeinodes_percent = NULL; | 151 | static char *crit_freeinodes_percent = NULL; |
155 | char *crit_freeinodes_percent = NULL; | 152 | static bool path_selected = false; |
156 | int path_selected = FALSE; | 153 | static bool path_ignored = false; |
157 | bool path_ignored = false; | 154 | static char *group = NULL; |
158 | char *group = NULL; | 155 | static struct stat *stat_buf; |
159 | struct stat *stat_buf; | 156 | static struct name_list *seen = NULL; |
160 | struct name_list *seen = NULL; | ||
161 | 157 | ||
162 | 158 | ||
163 | int | 159 | int |
@@ -205,7 +201,7 @@ main (int argc, char **argv) | |||
205 | /* If a list of paths has not been selected, find entire | 201 | /* If a list of paths has not been selected, find entire |
206 | mount list and create list of paths | 202 | mount list and create list of paths |
207 | */ | 203 | */ |
208 | if (path_selected == FALSE && path_ignored == false) { | 204 | if (path_selected == false && path_ignored == false) { |
209 | for (me = mount_list; me; me = me->me_next) { | 205 | for (me = mount_list; me; me = me->me_next) { |
210 | if (! (path = np_find_parameter(path_select_list, me->me_mountdir))) { | 206 | if (! (path = np_find_parameter(path_select_list, me->me_mountdir))) { |
211 | path = np_add_parameter(&path_select_list, me->me_mountdir); | 207 | path = np_add_parameter(&path_select_list, me->me_mountdir); |
@@ -300,7 +296,7 @@ main (int argc, char **argv) | |||
300 | } else if (me->me_dummy && !show_all_fs) { | 296 | } else if (me->me_dummy && !show_all_fs) { |
301 | continue; | 297 | continue; |
302 | /* Skip excluded fstypes */ | 298 | /* Skip excluded fstypes */ |
303 | } else if (fs_exclude_list && np_find_name (fs_exclude_list, me->me_type)) { | 299 | } else if (fs_exclude_list && np_find_regmatch (fs_exclude_list, me->me_type)) { |
304 | continue; | 300 | continue; |
305 | /* Skip excluded fs's */ | 301 | /* Skip excluded fs's */ |
306 | } else if (dp_exclude_list && | 302 | } else if (dp_exclude_list && |
@@ -308,7 +304,7 @@ main (int argc, char **argv) | |||
308 | np_find_name (dp_exclude_list, me->me_mountdir))) { | 304 | np_find_name (dp_exclude_list, me->me_mountdir))) { |
309 | continue; | 305 | continue; |
310 | /* Skip not included fstypes */ | 306 | /* Skip not included fstypes */ |
311 | } else if (fs_include_list && !np_find_name (fs_include_list, me->me_type)) { | 307 | } else if (fs_include_list && !np_find_regmatch(fs_include_list, me->me_type)) { |
312 | continue; | 308 | continue; |
313 | } | 309 | } |
314 | } | 310 | } |
@@ -326,7 +322,7 @@ main (int argc, char **argv) | |||
326 | get_stats (path, &fsp); | 322 | get_stats (path, &fsp); |
327 | 323 | ||
328 | if (verbose >= 3) { | 324 | if (verbose >= 3) { |
329 | 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", | 325 | 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", |
330 | me->me_mountdir, | 326 | me->me_mountdir, |
331 | path->dused_pct, | 327 | path->dused_pct, |
332 | path->dfree_pct, | 328 | path->dfree_pct, |
@@ -396,10 +392,10 @@ main (int argc, char **argv) | |||
396 | perfdata_uint64 ( | 392 | perfdata_uint64 ( |
397 | (!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir, | 393 | (!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir, |
398 | path->dused_units * mult, "B", | 394 | path->dused_units * mult, "B", |
399 | (warning_high_tide == UINT64_MAX ? FALSE : TRUE), warning_high_tide, | 395 | (warning_high_tide == UINT64_MAX ? false : true), warning_high_tide, |
400 | (critical_high_tide == UINT64_MAX ? FALSE : TRUE), critical_high_tide, | 396 | (critical_high_tide == UINT64_MAX ? false : true), critical_high_tide, |
401 | TRUE, 0, | 397 | true, 0, |
402 | TRUE, path->dtotal_units * mult)); | 398 | true, path->dtotal_units * mult)); |
403 | 399 | ||
404 | if (display_inodes_perfdata) { | 400 | if (display_inodes_perfdata) { |
405 | /* *_high_tide must be reinitialized at each run */ | 401 | /* *_high_tide must be reinitialized at each run */ |
@@ -418,10 +414,10 @@ main (int argc, char **argv) | |||
418 | xasprintf (&perf, "%s %s", perf, | 414 | xasprintf (&perf, "%s %s", perf, |
419 | perfdata_uint64 (perf_ilabel, | 415 | perfdata_uint64 (perf_ilabel, |
420 | path->inodes_used, "", | 416 | path->inodes_used, "", |
421 | (warning_high_tide != UINT64_MAX ? TRUE : FALSE), warning_high_tide, | 417 | (warning_high_tide != UINT64_MAX ? true : false), warning_high_tide, |
422 | (critical_high_tide != UINT64_MAX ? TRUE : FALSE), critical_high_tide, | 418 | (critical_high_tide != UINT64_MAX ? true : false), critical_high_tide, |
423 | TRUE, 0, | 419 | true, 0, |
424 | TRUE, path->inodes_total)); | 420 | true, path->inodes_total)); |
425 | } | 421 | } |
426 | 422 | ||
427 | if (disk_result==STATE_OK && erronly && !verbose) | 423 | if (disk_result==STATE_OK && erronly && !verbose) |
@@ -432,7 +428,7 @@ main (int argc, char **argv) | |||
432 | } else { | 428 | } else { |
433 | xasprintf(&flag_header, ""); | 429 | xasprintf(&flag_header, ""); |
434 | } | 430 | } |
435 | xasprintf (&output, "%s%s %s %llu%s (%.0f%%", | 431 | xasprintf (&output, "%s%s %s %llu%s (%.1f%%", |
436 | output, flag_header, | 432 | output, flag_header, |
437 | (!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir, | 433 | (!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir, |
438 | path->dfree_units, | 434 | path->dfree_units, |
@@ -452,7 +448,7 @@ main (int argc, char **argv) | |||
452 | 448 | ||
453 | if (strcmp(output, "") == 0 && ! erronly) { | 449 | if (strcmp(output, "") == 0 && ! erronly) { |
454 | preamble = ""; | 450 | preamble = ""; |
455 | xasprintf (&output, " - No disks were found for provided parameters;"); | 451 | xasprintf (&output, " - No disks were found for provided parameters"); |
456 | } | 452 | } |
457 | 453 | ||
458 | 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); | 454 | 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 +458,8 @@ main (int argc, char **argv) | |||
462 | 458 | ||
463 | double calculate_percent(uintmax_t value, uintmax_t total) { | 459 | double calculate_percent(uintmax_t value, uintmax_t total) { |
464 | double pct = -1; | 460 | double pct = -1; |
465 | /* I don't understand the below, but it is taken from coreutils' df */ | 461 | if(value <= DBL_MAX && total != 0) { |
466 | /* Seems to be calculating pct, in the best possible way */ | 462 | pct = (double)value / total * 100.0; |
467 | if (value <= TYPE_MAXIMUM(uintmax_t) / 100 | ||
468 | && total != 0) { | ||
469 | uintmax_t u100 = value * 100; | ||
470 | pct = u100 / total + (u100 % total != 0); | ||
471 | } else { | ||
472 | /* Possible rounding errors - see coreutils' df for more explanation */ | ||
473 | double u = value; | ||
474 | double t = total; | ||
475 | if (t) { | ||
476 | long int lipct = pct = u * 100 / t; | ||
477 | double ipct = lipct; | ||
478 | |||
479 | /* Like 'pct = ceil (dpct);', but without ceil - from coreutils again */ | ||
480 | if (ipct - 1 < pct && pct <= ipct + 1) | ||
481 | pct = ipct + (ipct < pct); | ||
482 | } | ||
483 | } | 463 | } |
484 | return pct; | 464 | return pct; |
485 | } | 465 | } |
@@ -524,7 +504,7 @@ process_arguments (int argc, char **argv) | |||
524 | {"ignore-ereg-partition", required_argument, 0, 'i'}, | 504 | {"ignore-ereg-partition", required_argument, 0, 'i'}, |
525 | {"ignore-eregi-path", required_argument, 0, 'I'}, | 505 | {"ignore-eregi-path", required_argument, 0, 'I'}, |
526 | {"ignore-eregi-partition", required_argument, 0, 'I'}, | 506 | {"ignore-eregi-partition", required_argument, 0, 'I'}, |
527 | {"ignore-missing", no_argument, 0, IGNORE_MISSING}, | 507 | {"ignore-missing", no_argument, 0, 'n'}, |
528 | {"local", no_argument, 0, 'l'}, | 508 | {"local", no_argument, 0, 'l'}, |
529 | {"stat-remote-fs", no_argument, 0, 'L'}, | 509 | {"stat-remote-fs", no_argument, 0, 'L'}, |
530 | {"iperfdata", no_argument, 0, 'P'}, | 510 | {"iperfdata", no_argument, 0, 'P'}, |
@@ -543,14 +523,14 @@ process_arguments (int argc, char **argv) | |||
543 | if (argc < 2) | 523 | if (argc < 2) |
544 | return ERROR; | 524 | return ERROR; |
545 | 525 | ||
546 | np_add_name(&fs_exclude_list, "iso9660"); | 526 | np_add_regex(&fs_exclude_list, "iso9660", REG_EXTENDED); |
547 | 527 | ||
548 | for (c = 1; c < argc; c++) | 528 | for (c = 1; c < argc; c++) |
549 | if (strcmp ("-to", argv[c]) == 0) | 529 | if (strcmp ("-to", argv[c]) == 0) |
550 | strcpy (argv[c], "-t"); | 530 | strcpy (argv[c], "-t"); |
551 | 531 | ||
552 | while (1) { | 532 | while (1) { |
553 | c = getopt_long (argc, argv, "+?VqhvefCt:c:w:K:W:u:p:x:X:N:mklLPg:R:r:i:I:MEA", longopts, &option); | 533 | c = getopt_long (argc, argv, "+?VqhvefCt:c:w:K:W:u:p:x:X:N:mklLPg:R:r:i:I:MEAn", longopts, &option); |
554 | 534 | ||
555 | if (c == -1 || c == EOF) | 535 | if (c == -1 || c == EOF) |
556 | break; | 536 | break; |
@@ -567,6 +547,10 @@ process_arguments (int argc, char **argv) | |||
567 | 547 | ||
568 | /* See comments for 'c' */ | 548 | /* See comments for 'c' */ |
569 | case 'w': /* warning threshold */ | 549 | case 'w': /* warning threshold */ |
550 | if (!is_percentage_expression(optarg) && !is_numeric(optarg)) { | ||
551 | die(STATE_UNKNOWN, "Argument for --warning invalid or missing: %s\n", optarg); | ||
552 | } | ||
553 | |||
570 | if (strstr(optarg, "%")) { | 554 | if (strstr(optarg, "%")) { |
571 | if (*optarg == '@') { | 555 | if (*optarg == '@') { |
572 | warn_freespace_percent = optarg; | 556 | warn_freespace_percent = optarg; |
@@ -588,6 +572,10 @@ process_arguments (int argc, char **argv) | |||
588 | force @ at the beginning of the range, so that it is backwards compatible | 572 | force @ at the beginning of the range, so that it is backwards compatible |
589 | */ | 573 | */ |
590 | case 'c': /* critical threshold */ | 574 | case 'c': /* critical threshold */ |
575 | if (!is_percentage_expression(optarg) && !is_numeric(optarg)) { | ||
576 | die(STATE_UNKNOWN, "Argument for --critical invalid or missing: %s\n", optarg); | ||
577 | } | ||
578 | |||
591 | if (strstr(optarg, "%")) { | 579 | if (strstr(optarg, "%")) { |
592 | if (*optarg == '@') { | 580 | if (*optarg == '@') { |
593 | crit_freespace_percent = optarg; | 581 | crit_freespace_percent = optarg; |
@@ -710,34 +698,42 @@ process_arguments (int argc, char **argv) | |||
710 | mount_list = read_file_system_list (0); | 698 | mount_list = read_file_system_list (0); |
711 | np_set_best_match(se, mount_list, exact_match); | 699 | np_set_best_match(se, mount_list, exact_match); |
712 | 700 | ||
713 | path_selected = TRUE; | 701 | path_selected = true; |
714 | break; | 702 | break; |
715 | case 'x': /* exclude path or partition */ | 703 | case 'x': /* exclude path or partition */ |
716 | np_add_name(&dp_exclude_list, optarg); | 704 | np_add_name(&dp_exclude_list, optarg); |
717 | break; | 705 | break; |
718 | case 'X': /* exclude file system type */ | 706 | case 'X': /* exclude file system type */ |
719 | np_add_name(&fs_exclude_list, optarg); | 707 | err = np_add_regex(&fs_exclude_list, optarg, REG_EXTENDED); |
708 | if (err != 0) { | ||
709 | regerror (err, &fs_exclude_list->regex, errbuf, MAX_INPUT_BUFFER); | ||
710 | die (STATE_UNKNOWN, "DISK %s: %s - %s\n",_("UNKNOWN"), _("Could not compile regular expression"), errbuf); | ||
711 | } | ||
720 | break; | 712 | break; |
721 | case 'N': /* include file system type */ | 713 | case 'N': /* include file system type */ |
722 | np_add_name(&fs_include_list, optarg); | 714 | err = np_add_regex(&fs_include_list, optarg, REG_EXTENDED); |
715 | if (err != 0) { | ||
716 | regerror (err, &fs_exclude_list->regex, errbuf, MAX_INPUT_BUFFER); | ||
717 | die (STATE_UNKNOWN, "DISK %s: %s - %s\n",_("UNKNOWN"), _("Could not compile regular expression"), errbuf); | ||
718 | } | ||
723 | break; | 719 | break; |
724 | case 'v': /* verbose */ | 720 | case 'v': /* verbose */ |
725 | verbose++; | 721 | verbose++; |
726 | break; | 722 | break; |
727 | case 'q': /* TODO: this function should eventually go away (removed 2007-09-20) */ | 723 | case 'q': /* TODO: this function should eventually go away (removed 2007-09-20) */ |
728 | /* verbose--; **replaced by line below**. -q was only a broken way of implementing -e */ | 724 | /* verbose--; **replaced by line below**. -q was only a broken way of implementing -e */ |
729 | erronly = TRUE; | 725 | erronly = true; |
730 | break; | 726 | break; |
731 | case 'e': | 727 | case 'e': |
732 | erronly = TRUE; | 728 | erronly = true; |
733 | break; | 729 | break; |
734 | case 'E': | 730 | case 'E': |
735 | if (path_selected) | 731 | if (path_selected) |
736 | die (STATE_UNKNOWN, "DISK %s: %s", _("UNKNOWN"), _("Must set -E before selecting paths\n")); | 732 | die (STATE_UNKNOWN, "DISK %s: %s", _("UNKNOWN"), _("Must set -E before selecting paths\n")); |
737 | exact_match = TRUE; | 733 | exact_match = true; |
738 | break; | 734 | break; |
739 | case 'f': | 735 | case 'f': |
740 | freespace_ignore_reserved = TRUE; | 736 | freespace_ignore_reserved = true; |
741 | break; | 737 | break; |
742 | case 'g': | 738 | case 'g': |
743 | if (path_selected) | 739 | if (path_selected) |
@@ -784,7 +780,7 @@ process_arguments (int argc, char **argv) | |||
784 | cflags = default_cflags; | 780 | cflags = default_cflags; |
785 | break; | 781 | break; |
786 | 782 | ||
787 | case IGNORE_MISSING: | 783 | case 'n': |
788 | ignore_missing = true; | 784 | ignore_missing = true; |
789 | break; | 785 | break; |
790 | case 'A': | 786 | case 'A': |
@@ -798,7 +794,7 @@ process_arguments (int argc, char **argv) | |||
798 | crit_freespace_percent || warn_usedspace_units || crit_usedspace_units || | 794 | crit_freespace_percent || warn_usedspace_units || crit_usedspace_units || |
799 | warn_usedspace_percent || crit_usedspace_percent || warn_usedinodes_percent || | 795 | warn_usedspace_percent || crit_usedspace_percent || warn_usedinodes_percent || |
800 | crit_usedinodes_percent || warn_freeinodes_percent || crit_freeinodes_percent )) { | 796 | crit_usedinodes_percent || warn_freeinodes_percent || crit_freeinodes_percent )) { |
801 | die (STATE_UNKNOWN, "DISK %s: %s", _("UNKNOWN"), _("Must set a threshold value before using -r/-R\n")); | 797 | die (STATE_UNKNOWN, "DISK %s: %s", _("UNKNOWN"), _("Must set a threshold value before using -r/-R/-A (--ereg-path/--eregi-path/--all)\n")); |
802 | } | 798 | } |
803 | 799 | ||
804 | err = regcomp(&re, optarg, cflags); | 800 | err = regcomp(&re, optarg, cflags); |
@@ -809,7 +805,7 @@ process_arguments (int argc, char **argv) | |||
809 | 805 | ||
810 | for (me = mount_list; me; me = me->me_next) { | 806 | for (me = mount_list; me; me = me->me_next) { |
811 | if (np_regex_match_mount_entry(me, &re)) { | 807 | if (np_regex_match_mount_entry(me, &re)) { |
812 | fnd = TRUE; | 808 | fnd = true; |
813 | if (verbose >= 3) | 809 | if (verbose >= 3) |
814 | printf("%s %s matching expression %s\n", me->me_devname, me->me_mountdir, optarg); | 810 | printf("%s %s matching expression %s\n", me->me_devname, me->me_mountdir, optarg); |
815 | 811 | ||
@@ -824,24 +820,24 @@ process_arguments (int argc, char **argv) | |||
824 | 820 | ||
825 | if (!fnd && ignore_missing == true) { | 821 | if (!fnd && ignore_missing == true) { |
826 | path_ignored = true; | 822 | path_ignored = true; |
827 | /* path_selected = TRUE;*/ | 823 | path_selected = true; |
828 | break; | 824 | break; |
829 | } else if (!fnd) | 825 | } else if (!fnd) |
830 | die (STATE_UNKNOWN, "DISK %s: %s - %s\n",_("UNKNOWN"), | 826 | die (STATE_UNKNOWN, "DISK %s: %s - %s\n",_("UNKNOWN"), |
831 | _("Regular expression did not match any path or disk"), optarg); | 827 | _("Regular expression did not match any path or disk"), optarg); |
832 | 828 | ||
833 | fnd = FALSE; | 829 | fnd = false; |
834 | path_selected = TRUE; | 830 | path_selected = true; |
835 | np_set_best_match(path_select_list, mount_list, exact_match); | 831 | np_set_best_match(path_select_list, mount_list, exact_match); |
836 | cflags = default_cflags; | 832 | cflags = default_cflags; |
837 | 833 | ||
838 | break; | 834 | break; |
839 | case 'M': /* display mountpoint */ | 835 | case 'M': /* display mountpoint */ |
840 | display_mntp = TRUE; | 836 | display_mntp = true; |
841 | break; | 837 | break; |
842 | case 'C': | 838 | case 'C': |
843 | /* add all mount entries to path_select list if no partitions have been explicitly defined using -p */ | 839 | /* add all mount entries to path_select list if no partitions have been explicitly defined using -p */ |
844 | if (path_selected == FALSE) { | 840 | if (path_selected == false) { |
845 | struct parameter_list *path; | 841 | struct parameter_list *path; |
846 | for (me = mount_list; me; me = me->me_next) { | 842 | for (me = mount_list; me; me = me->me_next) { |
847 | if (! (path = np_find_parameter(path_select_list, me->me_mountdir))) | 843 | if (! (path = np_find_parameter(path_select_list, me->me_mountdir))) |
@@ -864,7 +860,7 @@ process_arguments (int argc, char **argv) | |||
864 | warn_freeinodes_percent = NULL; | 860 | warn_freeinodes_percent = NULL; |
865 | crit_freeinodes_percent = NULL; | 861 | crit_freeinodes_percent = NULL; |
866 | 862 | ||
867 | path_selected = FALSE; | 863 | path_selected = false; |
868 | group = NULL; | 864 | group = NULL; |
869 | break; | 865 | break; |
870 | case 'V': /* version */ | 866 | case 'V': /* version */ |
@@ -888,7 +884,7 @@ process_arguments (int argc, char **argv) | |||
888 | 884 | ||
889 | if (argc > c) { | 885 | if (argc > c) { |
890 | se = np_add_parameter(&path_select_list, strdup(argv[c++])); | 886 | se = np_add_parameter(&path_select_list, strdup(argv[c++])); |
891 | path_selected = TRUE; | 887 | path_selected = true; |
892 | set_all_thresholds(se); | 888 | set_all_thresholds(se); |
893 | } | 889 | } |
894 | 890 | ||
@@ -897,21 +893,9 @@ process_arguments (int argc, char **argv) | |||
897 | mult = (uintmax_t)1024 * 1024; | 893 | mult = (uintmax_t)1024 * 1024; |
898 | } | 894 | } |
899 | 895 | ||
900 | return TRUE; | 896 | return true; |
901 | } | ||
902 | |||
903 | |||
904 | |||
905 | void | ||
906 | print_path (const char *mypath) | ||
907 | { | ||
908 | if (mypath == NULL) | ||
909 | printf ("\n"); | ||
910 | else | ||
911 | printf (_(" for %s\n"), mypath); | ||
912 | } | 897 | } |
913 | 898 | ||
914 | |||
915 | void | 899 | void |
916 | set_all_thresholds (struct parameter_list *path) | 900 | set_all_thresholds (struct parameter_list *path) |
917 | { | 901 | { |
@@ -996,25 +980,33 @@ print_help (void) | |||
996 | printf (" %s\n", _("Regular expression to ignore selected path/partition (case insensitive) (may be repeated)")); | 980 | printf (" %s\n", _("Regular expression to ignore selected path/partition (case insensitive) (may be repeated)")); |
997 | printf (" %s\n", "-i, --ignore-ereg-path=PATH, --ignore-ereg-partition=PARTITION"); | 981 | printf (" %s\n", "-i, --ignore-ereg-path=PATH, --ignore-ereg-partition=PARTITION"); |
998 | printf (" %s\n", _("Regular expression to ignore selected path or partition (may be repeated)")); | 982 | printf (" %s\n", _("Regular expression to ignore selected path or partition (may be repeated)")); |
999 | printf (" %s\n", "--ignore-missing"); | 983 | printf (" %s\n", "-n, --ignore-missing"); |
1000 | printf (" %s\n", _("Return OK if no filesystem matches, filesystem does not exist or is inaccessible.")); | 984 | printf (" %s\n", _("Return OK if no filesystem matches, filesystem does not exist or is inaccessible.")); |
1001 | printf (" %s\n", _("(Provide this option before -p / -r / --ereg-path if used)")); | 985 | printf (" %s\n", _("(Provide this option before -p / -r / --ereg-path if used)")); |
1002 | printf (UT_PLUG_TIMEOUT, DEFAULT_SOCKET_TIMEOUT); | 986 | printf (UT_PLUG_TIMEOUT, DEFAULT_SOCKET_TIMEOUT); |
1003 | printf (" %s\n", "-u, --units=STRING"); | 987 | printf (" %s\n", "-u, --units=STRING"); |
1004 | printf (" %s\n", _("Choose bytes, kB, MB, GB, TB (default: MB)")); | 988 | printf (" %s\n", _("Choose bytes, kB, MB, GB, TB (default: MB)")); |
1005 | printf (UT_VERBOSE); | 989 | printf (UT_VERBOSE); |
1006 | printf (" %s\n", "-X, --exclude-type=TYPE"); | 990 | printf (" %s\n", "-X, --exclude-type=TYPE_REGEX"); |
1007 | printf (" %s\n", _("Ignore all filesystems of indicated type (may be repeated)")); | 991 | printf (" %s\n", _("Ignore all filesystems of types matching given regex(7) (may be repeated)")); |
1008 | printf (" %s\n", "-N, --include-type=TYPE"); | 992 | printf (" %s\n", "-N, --include-type=TYPE_REGEX"); |
1009 | printf (" %s\n", _("Check only filesystems of indicated type (may be repeated)")); | 993 | printf (" %s\n", _("Check only filesystems where the type matches this given regex(7) (may be repeated)")); |
994 | |||
995 | printf ("\n"); | ||
996 | printf ("%s\n", _("General usage hints:")); | ||
997 | printf (" %s\n", _("- Arguments are positional! \"-w 5 -c 1 -p /foo -w6 -c2 -p /bar\" is not the same as")); | ||
998 | printf (" %s\n", _("\"-w 5 -c 1 -p /bar w6 -c2 -p /foo\".")); | ||
999 | printf (" %s\n", _("- The syntax is broadly: \"{thresholds a} {paths a} -C {thresholds b} {thresholds b} ...\"")); | ||
1000 | |||
1001 | |||
1010 | 1002 | ||
1011 | printf ("\n"); | 1003 | printf ("\n"); |
1012 | printf ("%s\n", _("Examples:")); | 1004 | printf ("%s\n", _("Examples:")); |
1013 | printf (" %s\n", "check_disk -w 10% -c 5% -p /tmp -p /var -C -w 100000 -c 50000 -p /"); | 1005 | printf (" %s\n", "check_disk -w 10% -c 5% -p /tmp -p /var -C -w 100000 -c 50000 -p /"); |
1014 | printf (" %s\n", _("Checks /tmp and /var at 10% and 5%, and / at 100MB and 50MB")); | 1006 | printf (" %s\n\n", _("Checks /tmp and /var at 10% and 5%, and / at 100MB and 50MB")); |
1015 | printf (" %s\n", "check_disk -w 100 -c 50 -C -w 1000 -c 500 -g sidDATA -r '^/oracle/SID/data.*$'"); | 1007 | printf (" %s\n", "check_disk -w 100 -c 50 -C -w 1000 -c 500 -g sidDATA -r '^/oracle/SID/data.*$'"); |
1016 | printf (" %s\n", _("Checks all filesystems not matching -r at 100M and 50M. The fs matching the -r regex")); | 1008 | printf (" %s\n", _("Checks all filesystems not matching -r at 100M and 50M. The fs matching the -r regex")); |
1017 | printf (" %s\n", _("are grouped which means the freespace thresholds are applied to all disks together")); | 1009 | printf (" %s\n\n", _("are grouped which means the freespace thresholds are applied to all disks together")); |
1018 | printf (" %s\n", "check_disk -w 100 -c 50 -C -w 1000 -c 500 -p /foo -C -w 5% -c 3% -p /bar"); | 1010 | printf (" %s\n", "check_disk -w 100 -c 50 -C -w 1000 -c 500 -p /foo -C -w 5% -c 3% -p /bar"); |
1019 | printf (" %s\n", _("Checks /foo for 1000M/500M and /bar for 5/3%. All remaining volumes use 100M/50M")); | 1011 | printf (" %s\n", _("Checks /foo for 1000M/500M and /bar for 5/3%. All remaining volumes use 100M/50M")); |
1020 | 1012 | ||
@@ -1027,9 +1019,9 @@ void | |||
1027 | print_usage (void) | 1019 | print_usage (void) |
1028 | { | 1020 | { |
1029 | printf ("%s\n", _("Usage:")); | 1021 | printf ("%s\n", _("Usage:")); |
1030 | printf (" %s {-w absolute_limit |-w percentage_limit% | -W inode_percentage_limit } {-c absolute_limit|-c percentage_limit% | -K inode_percentage_limit } {-p path | -x device}\n", progname); | 1022 | printf (" %s {-w absolute_limit |-w percentage_limit%% | -W inode_percentage_limit } {-c absolute_limit|-c percentage_limit%% | -K inode_percentage_limit } {-p path | -x device}\n", progname); |
1031 | printf ("[-C] [-E] [-e] [-f] [-g group ] [-k] [-l] [-M] [-m] [-R path ] [-r path ]\n"); | 1023 | printf ("[-C] [-E] [-e] [-f] [-g group ] [-k] [-l] [-M] [-m] [-R path ] [-r path ]\n"); |
1032 | printf ("[-t timeout] [-u unit] [-v] [-X type] [-N type]\n"); | 1024 | printf ("[-t timeout] [-u unit] [-v] [-X type_regex] [-N type]\n"); |
1033 | } | 1025 | } |
1034 | 1026 | ||
1035 | bool | 1027 | bool |
@@ -1115,7 +1107,7 @@ get_stats (struct parameter_list *p, struct fs_usage *fsp) { | |||
1115 | } | 1107 | } |
1116 | /* finally calculate percentages for either plain FS or summed up group */ | 1108 | /* finally calculate percentages for either plain FS or summed up group */ |
1117 | p->dused_pct = calculate_percent( p->used, p->used + p->available ); /* used + available can never be > uintmax */ | 1109 | p->dused_pct = calculate_percent( p->used, p->used + p->available ); /* used + available can never be > uintmax */ |
1118 | p->dfree_pct = 100 - p->dused_pct; | 1110 | p->dfree_pct = 100.0 - p->dused_pct; |
1119 | p->dused_inodes_percent = calculate_percent(p->inodes_total - p->inodes_free, p->inodes_total); | 1111 | p->dused_inodes_percent = calculate_percent(p->inodes_total - p->inodes_free, p->inodes_total); |
1120 | p->dfree_inodes_percent = 100 - p->dused_inodes_percent; | 1112 | p->dfree_inodes_percent = 100 - p->dused_inodes_percent; |
1121 | 1113 | ||
diff --git a/plugins/check_dns.c b/plugins/check_dns.c index 7ffce98b..468bc958 100644 --- a/plugins/check_dns.c +++ b/plugins/check_dns.c | |||
@@ -41,8 +41,8 @@ const char *email = "devel@monitoring-plugins.org"; | |||
41 | 41 | ||
42 | int process_arguments (int, char **); | 42 | int process_arguments (int, char **); |
43 | int validate_arguments (void); | 43 | int validate_arguments (void); |
44 | int error_scan (char *, int *); | 44 | int error_scan (char *, bool *); |
45 | int ip_match_cidr(const char *, const char *); | 45 | bool ip_match_cidr(const char *, const char *); |
46 | unsigned long ip2long(const char *); | 46 | unsigned long ip2long(const char *); |
47 | void print_help (void); | 47 | void print_help (void); |
48 | void print_usage (void); | 48 | void print_usage (void); |
@@ -51,13 +51,13 @@ void print_usage (void); | |||
51 | char query_address[ADDRESS_LENGTH] = ""; | 51 | char query_address[ADDRESS_LENGTH] = ""; |
52 | char dns_server[ADDRESS_LENGTH] = ""; | 52 | char dns_server[ADDRESS_LENGTH] = ""; |
53 | char ptr_server[ADDRESS_LENGTH] = ""; | 53 | char ptr_server[ADDRESS_LENGTH] = ""; |
54 | int verbose = FALSE; | 54 | bool verbose = false; |
55 | char **expected_address = NULL; | 55 | char **expected_address = NULL; |
56 | int expected_address_cnt = 0; | 56 | int expected_address_cnt = 0; |
57 | int expect_nxdomain = FALSE; | 57 | bool expect_nxdomain = false; |
58 | 58 | ||
59 | int expect_authority = FALSE; | 59 | bool expect_authority = false; |
60 | int all_match = FALSE; | 60 | bool all_match = false; |
61 | thresholds *time_thresholds = NULL; | 61 | thresholds *time_thresholds = NULL; |
62 | 62 | ||
63 | static int | 63 | static int |
@@ -80,15 +80,14 @@ main (int argc, char **argv) | |||
80 | int n_addresses = 0; | 80 | int n_addresses = 0; |
81 | char *msg = NULL; | 81 | char *msg = NULL; |
82 | char *temp_buffer = NULL; | 82 | char *temp_buffer = NULL; |
83 | int non_authoritative = FALSE; | 83 | bool non_authoritative = false; |
84 | int result = STATE_UNKNOWN; | 84 | int result = STATE_UNKNOWN; |
85 | double elapsed_time; | 85 | double elapsed_time; |
86 | long microsec; | 86 | long microsec; |
87 | struct timeval tv; | 87 | struct timeval tv; |
88 | int parse_address = FALSE; /* This flag scans for Address: but only after Name: */ | 88 | bool parse_address = false; /* This flag scans for Address: but only after Name: */ |
89 | output chld_out, chld_err; | 89 | output chld_out, chld_err; |
90 | size_t i; | 90 | bool is_nxdomain = false; |
91 | int is_nxdomain = FALSE; | ||
92 | 91 | ||
93 | setlocale (LC_ALL, ""); | 92 | setlocale (LC_ALL, ""); |
94 | bindtextdomain (PACKAGE, LOCALEDIR); | 93 | bindtextdomain (PACKAGE, LOCALEDIR); |
@@ -122,7 +121,7 @@ main (int argc, char **argv) | |||
122 | } | 121 | } |
123 | 122 | ||
124 | /* scan stdout */ | 123 | /* scan stdout */ |
125 | for(i = 0; i < chld_out.lines; i++) { | 124 | for(size_t i = 0; i < chld_out.lines; i++) { |
126 | if (addresses == NULL) | 125 | if (addresses == NULL) |
127 | addresses = malloc(sizeof(*addresses)*10); | 126 | addresses = malloc(sizeof(*addresses)*10); |
128 | else if (!(n_addresses % 10)) | 127 | else if (!(n_addresses % 10)) |
@@ -164,8 +163,8 @@ main (int argc, char **argv) | |||
164 | 163 | ||
165 | /* the server is responding, we just got the host name... */ | 164 | /* the server is responding, we just got the host name... */ |
166 | if (strstr (chld_out.line[i], "Name:")) | 165 | if (strstr (chld_out.line[i], "Name:")) |
167 | parse_address = TRUE; | 166 | parse_address = true; |
168 | else if (parse_address == TRUE && (strstr (chld_out.line[i], "Address:") || | 167 | else if (parse_address && (strstr (chld_out.line[i], "Address:") || |
169 | strstr (chld_out.line[i], "Addresses:"))) { | 168 | strstr (chld_out.line[i], "Addresses:"))) { |
170 | temp_buffer = index (chld_out.line[i], ':'); | 169 | temp_buffer = index (chld_out.line[i], ':'); |
171 | temp_buffer++; | 170 | temp_buffer++; |
@@ -184,7 +183,7 @@ main (int argc, char **argv) | |||
184 | addresses[n_addresses++] = strdup(temp_buffer); | 183 | addresses[n_addresses++] = strdup(temp_buffer); |
185 | } | 184 | } |
186 | else if (strstr (chld_out.line[i], _("Non-authoritative answer:"))) { | 185 | else if (strstr (chld_out.line[i], _("Non-authoritative answer:"))) { |
187 | non_authoritative = TRUE; | 186 | non_authoritative = true; |
188 | } | 187 | } |
189 | 188 | ||
190 | 189 | ||
@@ -197,7 +196,7 @@ main (int argc, char **argv) | |||
197 | } | 196 | } |
198 | 197 | ||
199 | /* scan stderr */ | 198 | /* scan stderr */ |
200 | for(i = 0; i < chld_err.lines; i++) { | 199 | for(size_t i = 0; i < chld_err.lines; i++) { |
201 | if (verbose) | 200 | if (verbose) |
202 | puts(chld_err.line[i]); | 201 | puts(chld_err.line[i]); |
203 | 202 | ||
@@ -241,7 +240,7 @@ main (int argc, char **argv) | |||
241 | unsigned long expect_match = (1 << expected_address_cnt) - 1; | 240 | unsigned long expect_match = (1 << expected_address_cnt) - 1; |
242 | unsigned long addr_match = (1 << n_addresses) - 1; | 241 | unsigned long addr_match = (1 << n_addresses) - 1; |
243 | 242 | ||
244 | for (i=0; i<expected_address_cnt; i++) { | 243 | for (int i=0; i<expected_address_cnt; i++) { |
245 | int j; | 244 | int j; |
246 | /* check if we get a match on 'raw' ip or cidr */ | 245 | /* check if we get a match on 'raw' ip or cidr */ |
247 | for (j=0; j<n_addresses; j++) { | 246 | for (j=0; j<n_addresses; j++) { |
@@ -298,21 +297,21 @@ main (int argc, char **argv) | |||
298 | printf (_(". %s returns %s"), query_address, address); | 297 | printf (_(". %s returns %s"), query_address, address); |
299 | if ((time_thresholds->warning != NULL) && (time_thresholds->critical != NULL)) { | 298 | if ((time_thresholds->warning != NULL) && (time_thresholds->critical != NULL)) { |
300 | printf ("|%s\n", fperfdata ("time", elapsed_time, "s", | 299 | printf ("|%s\n", fperfdata ("time", elapsed_time, "s", |
301 | TRUE, time_thresholds->warning->end, | 300 | true, time_thresholds->warning->end, |
302 | TRUE, time_thresholds->critical->end, | 301 | true, time_thresholds->critical->end, |
303 | TRUE, 0, FALSE, 0)); | 302 | true, 0, false, 0)); |
304 | } else if ((time_thresholds->warning == NULL) && (time_thresholds->critical != NULL)) { | 303 | } else if ((time_thresholds->warning == NULL) && (time_thresholds->critical != NULL)) { |
305 | printf ("|%s\n", fperfdata ("time", elapsed_time, "s", | 304 | printf ("|%s\n", fperfdata ("time", elapsed_time, "s", |
306 | FALSE, 0, | 305 | false, 0, |
307 | TRUE, time_thresholds->critical->end, | 306 | true, time_thresholds->critical->end, |
308 | TRUE, 0, FALSE, 0)); | 307 | true, 0, false, 0)); |
309 | } else if ((time_thresholds->warning != NULL) && (time_thresholds->critical == NULL)) { | 308 | } else if ((time_thresholds->warning != NULL) && (time_thresholds->critical == NULL)) { |
310 | printf ("|%s\n", fperfdata ("time", elapsed_time, "s", | 309 | printf ("|%s\n", fperfdata ("time", elapsed_time, "s", |
311 | TRUE, time_thresholds->warning->end, | 310 | true, time_thresholds->warning->end, |
312 | FALSE, 0, | 311 | false, 0, |
313 | TRUE, 0, FALSE, 0)); | 312 | true, 0, false, 0)); |
314 | } else | 313 | } else |
315 | printf ("|%s\n", fperfdata ("time", elapsed_time, "s", FALSE, 0, FALSE, 0, TRUE, 0, FALSE, 0)); | 314 | printf ("|%s\n", fperfdata ("time", elapsed_time, "s", false, 0, false, 0, true, 0, false, 0)); |
316 | } | 315 | } |
317 | else if (result == STATE_WARNING) | 316 | else if (result == STATE_WARNING) |
318 | printf (_("DNS WARNING - %s\n"), | 317 | printf (_("DNS WARNING - %s\n"), |
@@ -327,15 +326,14 @@ main (int argc, char **argv) | |||
327 | return result; | 326 | return result; |
328 | } | 327 | } |
329 | 328 | ||
330 | int | 329 | bool ip_match_cidr(const char *addr, const char *cidr_ro) { |
331 | ip_match_cidr(const char *addr, const char *cidr_ro) | ||
332 | { | ||
333 | char *subnet, *mask_c, *cidr = strdup(cidr_ro); | 330 | char *subnet, *mask_c, *cidr = strdup(cidr_ro); |
334 | int mask; | 331 | int mask; |
335 | subnet = strtok(cidr, "/"); | 332 | subnet = strtok(cidr, "/"); |
336 | mask_c = strtok(NULL, "\0"); | 333 | mask_c = strtok(NULL, "\0"); |
337 | if (!subnet || !mask_c) | 334 | if (!subnet || !mask_c) { |
338 | return FALSE; | 335 | return false; |
336 | } | ||
339 | mask = atoi(mask_c); | 337 | mask = atoi(mask_c); |
340 | 338 | ||
341 | /* https://www.cryptobells.com/verifying-ips-in-a-subnet-in-php/ */ | 339 | /* https://www.cryptobells.com/verifying-ips-in-a-subnet-in-php/ */ |
@@ -355,14 +353,14 @@ ip2long(const char* src) { | |||
355 | } | 353 | } |
356 | 354 | ||
357 | int | 355 | int |
358 | error_scan (char *input_buffer, int *is_nxdomain) | 356 | error_scan (char *input_buffer, bool *is_nxdomain) |
359 | { | 357 | { |
360 | 358 | ||
361 | const int nxdomain = strstr (input_buffer, "Non-existent") || | 359 | const int nxdomain = strstr (input_buffer, "Non-existent") || |
362 | strstr (input_buffer, "** server can't find") || | 360 | strstr (input_buffer, "** server can't find") || |
363 | strstr (input_buffer, "** Can't find") || | 361 | strstr (input_buffer, "** Can't find") || |
364 | strstr (input_buffer, "NXDOMAIN"); | 362 | strstr (input_buffer, "NXDOMAIN"); |
365 | if (nxdomain) *is_nxdomain = TRUE; | 363 | if (nxdomain) *is_nxdomain = true; |
366 | 364 | ||
367 | /* the DNS lookup timed out */ | 365 | /* the DNS lookup timed out */ |
368 | if (strstr (input_buffer, _("Note: nslookup is deprecated and may be removed from future releases.")) || | 366 | 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) | |||
461 | print_revision (progname, NP_VERSION); | 459 | print_revision (progname, NP_VERSION); |
462 | exit (STATE_UNKNOWN); | 460 | exit (STATE_UNKNOWN); |
463 | case 'v': /* version */ | 461 | case 'v': /* version */ |
464 | verbose = TRUE; | 462 | verbose = true; |
465 | break; | 463 | break; |
466 | case 't': /* timeout period */ | 464 | case 't': /* timeout period */ |
467 | timeout_interval = atoi (optarg); | 465 | timeout_interval = atoi (optarg); |
@@ -508,13 +506,13 @@ process_arguments (int argc, char **argv) | |||
508 | } | 506 | } |
509 | break; | 507 | break; |
510 | case 'n': /* expect NXDOMAIN */ | 508 | case 'n': /* expect NXDOMAIN */ |
511 | expect_nxdomain = TRUE; | 509 | expect_nxdomain = true; |
512 | break; | 510 | break; |
513 | case 'A': /* expect authority */ | 511 | case 'A': /* expect authority */ |
514 | expect_authority = TRUE; | 512 | expect_authority = true; |
515 | break; | 513 | break; |
516 | case 'L': /* all must match */ | 514 | case 'L': /* all must match */ |
517 | all_match = TRUE; | 515 | all_match = true; |
518 | break; | 516 | break; |
519 | case 'w': | 517 | case 'w': |
520 | warning = optarg; | 518 | warning = optarg; |
diff --git a/plugins/check_fping.c b/plugins/check_fping.c index 23a9e990..70d6f9fc 100644 --- a/plugins/check_fping.c +++ b/plugins/check_fping.c | |||
@@ -59,16 +59,16 @@ int packet_size = PACKET_SIZE; | |||
59 | int packet_count = PACKET_COUNT; | 59 | int packet_count = PACKET_COUNT; |
60 | int target_timeout = 0; | 60 | int target_timeout = 0; |
61 | int packet_interval = 0; | 61 | int packet_interval = 0; |
62 | int verbose = FALSE; | 62 | bool verbose = false; |
63 | int cpl; | 63 | int cpl; |
64 | int wpl; | 64 | int wpl; |
65 | double crta; | 65 | double crta; |
66 | double wrta; | 66 | double wrta; |
67 | int cpl_p = FALSE; | 67 | bool cpl_p = false; |
68 | int wpl_p = FALSE; | 68 | bool wpl_p = false; |
69 | bool alive_p = FALSE; | 69 | bool alive_p = false; |
70 | int crta_p = FALSE; | 70 | bool crta_p = false; |
71 | int wrta_p = FALSE; | 71 | bool wrta_p = false; |
72 | 72 | ||
73 | int | 73 | int |
74 | main (int argc, char **argv) | 74 | main (int argc, char **argv) |
@@ -194,8 +194,8 @@ int textscan (char *buf) { | |||
194 | _("FPING %s - %s (rta=%f ms)|%s\n"), | 194 | _("FPING %s - %s (rta=%f ms)|%s\n"), |
195 | state_text (STATE_OK), server_name,rta, | 195 | state_text (STATE_OK), server_name,rta, |
196 | /* No loss since we only waited for the first reply | 196 | /* No loss since we only waited for the first reply |
197 | perfdata ("loss", (long int)loss, "%", wpl_p, wpl, cpl_p, cpl, TRUE, 0, TRUE, 100), */ | 197 | perfdata ("loss", (long int)loss, "%", wpl_p, wpl, cpl_p, cpl, true, 0, true, 100), */ |
198 | fperfdata ("rta", rta/1.0e3, "s", wrta_p, wrta/1.0e3, crta_p, crta/1.0e3, TRUE, 0, FALSE, 0)); | 198 | fperfdata ("rta", rta/1.0e3, "s", wrta_p, wrta/1.0e3, crta_p, crta/1.0e3, true, 0, false, 0)); |
199 | } | 199 | } |
200 | 200 | ||
201 | if (strstr (buf, "not found")) { | 201 | if (strstr (buf, "not found")) { |
@@ -228,21 +228,21 @@ int textscan (char *buf) { | |||
228 | rtastr = 1 + index (rtastr, '/'); | 228 | rtastr = 1 + index (rtastr, '/'); |
229 | loss = strtod (losstr, NULL); | 229 | loss = strtod (losstr, NULL); |
230 | rta = strtod (rtastr, NULL); | 230 | rta = strtod (rtastr, NULL); |
231 | if (cpl_p == TRUE && loss > cpl) | 231 | if (cpl_p && loss > cpl) |
232 | status = STATE_CRITICAL; | 232 | status = STATE_CRITICAL; |
233 | else if (crta_p == TRUE && rta > crta) | 233 | else if (crta_p && rta > crta) |
234 | status = STATE_CRITICAL; | 234 | status = STATE_CRITICAL; |
235 | else if (wpl_p == TRUE && loss > wpl) | 235 | else if (wpl_p && loss > wpl) |
236 | status = STATE_WARNING; | 236 | status = STATE_WARNING; |
237 | else if (wrta_p == TRUE && rta > wrta) | 237 | else if (wrta_p && rta > wrta) |
238 | status = STATE_WARNING; | 238 | status = STATE_WARNING; |
239 | else | 239 | else |
240 | status = STATE_OK; | 240 | status = STATE_OK; |
241 | die (status, | 241 | die (status, |
242 | _("FPING %s - %s (loss=%.0f%%, rta=%f ms)|%s %s\n"), | 242 | _("FPING %s - %s (loss=%.0f%%, rta=%f ms)|%s %s\n"), |
243 | state_text (status), server_name, loss, rta, | 243 | state_text (status), server_name, loss, rta, |
244 | perfdata ("loss", (long int)loss, "%", wpl_p, wpl, cpl_p, cpl, TRUE, 0, TRUE, 100), | 244 | perfdata ("loss", (long int)loss, "%", wpl_p, wpl, cpl_p, cpl, true, 0, true, 100), |
245 | fperfdata ("rta", rta/1.0e3, "s", wrta_p, wrta/1.0e3, crta_p, crta/1.0e3, TRUE, 0, FALSE, 0)); | 245 | fperfdata ("rta", rta/1.0e3, "s", wrta_p, wrta/1.0e3, crta_p, crta/1.0e3, true, 0, false, 0)); |
246 | 246 | ||
247 | } | 247 | } |
248 | else if(strstr (buf, "xmt/rcv/%loss") ) { | 248 | else if(strstr (buf, "xmt/rcv/%loss") ) { |
@@ -258,16 +258,16 @@ int textscan (char *buf) { | |||
258 | loss = strtod (losstr, NULL); | 258 | loss = strtod (losstr, NULL); |
259 | if (atoi(losstr) == 100) | 259 | if (atoi(losstr) == 100) |
260 | status = STATE_CRITICAL; | 260 | status = STATE_CRITICAL; |
261 | else if (cpl_p == TRUE && loss > cpl) | 261 | else if (cpl_p && loss > cpl) |
262 | status = STATE_CRITICAL; | 262 | status = STATE_CRITICAL; |
263 | else if (wpl_p == TRUE && loss > wpl) | 263 | else if (wpl_p && loss > wpl) |
264 | status = STATE_WARNING; | 264 | status = STATE_WARNING; |
265 | else | 265 | else |
266 | status = STATE_OK; | 266 | status = STATE_OK; |
267 | /* loss=%.0f%%;%d;%d;0;100 */ | 267 | /* loss=%.0f%%;%d;%d;0;100 */ |
268 | die (status, _("FPING %s - %s (loss=%.0f%% )|%s\n"), | 268 | die (status, _("FPING %s - %s (loss=%.0f%% )|%s\n"), |
269 | state_text (status), server_name, loss , | 269 | state_text (status), server_name, loss , |
270 | perfdata ("loss", (long int)loss, "%", wpl_p, wpl, cpl_p, cpl, TRUE, 0, TRUE, 100)); | 270 | perfdata ("loss", (long int)loss, "%", wpl_p, wpl, cpl_p, cpl, true, 0, true, 100)); |
271 | 271 | ||
272 | } | 272 | } |
273 | else { | 273 | else { |
@@ -329,7 +329,7 @@ process_arguments (int argc, char **argv) | |||
329 | case '?': /* print short usage statement if args not parsable */ | 329 | case '?': /* print short usage statement if args not parsable */ |
330 | usage5 (); | 330 | usage5 (); |
331 | case 'a': /* host alive mode */ | 331 | case 'a': /* host alive mode */ |
332 | alive_p = TRUE; | 332 | alive_p = true; |
333 | break; | 333 | break; |
334 | case 'h': /* help */ | 334 | case 'h': /* help */ |
335 | print_help (); | 335 | print_help (); |
@@ -338,16 +338,16 @@ process_arguments (int argc, char **argv) | |||
338 | print_revision (progname, NP_VERSION); | 338 | print_revision (progname, NP_VERSION); |
339 | exit (STATE_UNKNOWN); | 339 | exit (STATE_UNKNOWN); |
340 | case 'v': /* verbose mode */ | 340 | case 'v': /* verbose mode */ |
341 | verbose = TRUE; | 341 | verbose = true; |
342 | break; | 342 | break; |
343 | case 'H': /* hostname */ | 343 | case 'H': /* hostname */ |
344 | if (is_host (optarg) == FALSE) { | 344 | if (is_host (optarg) == false) { |
345 | usage2 (_("Invalid hostname/address"), optarg); | 345 | usage2 (_("Invalid hostname/address"), optarg); |
346 | } | 346 | } |
347 | server_name = strscpy (server_name, optarg); | 347 | server_name = strscpy (server_name, optarg); |
348 | break; | 348 | break; |
349 | case 'S': /* sourceip */ | 349 | case 'S': /* sourceip */ |
350 | if (is_host (optarg) == FALSE) { | 350 | if (is_host (optarg) == false) { |
351 | usage2 (_("Invalid hostname/address"), optarg); | 351 | usage2 (_("Invalid hostname/address"), optarg); |
352 | } | 352 | } |
353 | sourceip = strscpy (sourceip, optarg); | 353 | sourceip = strscpy (sourceip, optarg); |
@@ -369,12 +369,12 @@ process_arguments (int argc, char **argv) | |||
369 | get_threshold (optarg, rv); | 369 | get_threshold (optarg, rv); |
370 | if (rv[RTA]) { | 370 | if (rv[RTA]) { |
371 | crta = strtod (rv[RTA], NULL); | 371 | crta = strtod (rv[RTA], NULL); |
372 | crta_p = TRUE; | 372 | crta_p = true; |
373 | rv[RTA] = NULL; | 373 | rv[RTA] = NULL; |
374 | } | 374 | } |
375 | if (rv[PL]) { | 375 | if (rv[PL]) { |
376 | cpl = atoi (rv[PL]); | 376 | cpl = atoi (rv[PL]); |
377 | cpl_p = TRUE; | 377 | cpl_p = true; |
378 | rv[PL] = NULL; | 378 | rv[PL] = NULL; |
379 | } | 379 | } |
380 | break; | 380 | break; |
@@ -382,12 +382,12 @@ process_arguments (int argc, char **argv) | |||
382 | get_threshold (optarg, rv); | 382 | get_threshold (optarg, rv); |
383 | if (rv[RTA]) { | 383 | if (rv[RTA]) { |
384 | wrta = strtod (rv[RTA], NULL); | 384 | wrta = strtod (rv[RTA], NULL); |
385 | wrta_p = TRUE; | 385 | wrta_p = true; |
386 | rv[RTA] = NULL; | 386 | rv[RTA] = NULL; |
387 | } | 387 | } |
388 | if (rv[PL]) { | 388 | if (rv[PL]) { |
389 | wpl = atoi (rv[PL]); | 389 | wpl = atoi (rv[PL]); |
390 | wpl_p = TRUE; | 390 | wpl_p = true; |
391 | rv[PL] = NULL; | 391 | rv[PL] = NULL; |
392 | } | 392 | } |
393 | break; | 393 | break; |
diff --git a/plugins/check_game.c b/plugins/check_game.c index a534b69b..ca126973 100644 --- a/plugins/check_game.c +++ b/plugins/check_game.c | |||
@@ -53,7 +53,7 @@ char *server_ip; | |||
53 | char *game_type; | 53 | char *game_type; |
54 | int port = 0; | 54 | int port = 0; |
55 | 55 | ||
56 | int verbose; | 56 | bool verbose = false; |
57 | 57 | ||
58 | int qstat_game_players_max = -1; | 58 | int qstat_game_players_max = -1; |
59 | int qstat_game_players = -1; | 59 | int qstat_game_players = -1; |
@@ -90,7 +90,7 @@ main (int argc, char **argv) | |||
90 | if (port) | 90 | if (port) |
91 | xasprintf (&command_line, "%s:%-d", command_line, port); | 91 | xasprintf (&command_line, "%s:%-d", command_line, port); |
92 | 92 | ||
93 | if (verbose > 0) | 93 | if (verbose) |
94 | printf ("%s\n", command_line); | 94 | printf ("%s\n", command_line); |
95 | 95 | ||
96 | /* run the command. historically, this plugin ignores output on stderr, | 96 | /* run the command. historically, this plugin ignores output on stderr, |
@@ -142,11 +142,11 @@ main (int argc, char **argv) | |||
142 | ret[qstat_map_field], | 142 | ret[qstat_map_field], |
143 | ret[qstat_ping_field], | 143 | ret[qstat_ping_field], |
144 | perfdata ("players", atol(ret[qstat_game_players]), "", | 144 | perfdata ("players", atol(ret[qstat_game_players]), "", |
145 | FALSE, 0, FALSE, 0, | 145 | false, 0, false, 0, |
146 | TRUE, 0, TRUE, atol(ret[qstat_game_players_max])), | 146 | true, 0, true, atol(ret[qstat_game_players_max])), |
147 | fperfdata ("ping", strtod(ret[qstat_ping_field], NULL), "", | 147 | fperfdata ("ping", strtod(ret[qstat_ping_field], NULL), "", |
148 | FALSE, 0, FALSE, 0, | 148 | false, 0, false, 0, |
149 | TRUE, 0, FALSE, 0)); | 149 | true, 0, false, 0)); |
150 | } | 150 | } |
151 | 151 | ||
152 | return result; | 152 | return result; |
@@ -201,7 +201,7 @@ process_arguments (int argc, char **argv) | |||
201 | print_revision (progname, NP_VERSION); | 201 | print_revision (progname, NP_VERSION); |
202 | exit (STATE_UNKNOWN); | 202 | exit (STATE_UNKNOWN); |
203 | case 'v': /* version */ | 203 | case 'v': /* version */ |
204 | verbose = TRUE; | 204 | verbose = true; |
205 | break; | 205 | break; |
206 | case 't': /* timeout period */ | 206 | case 't': /* timeout period */ |
207 | timeout_interval = atoi (optarg); | 207 | timeout_interval = atoi (optarg); |
diff --git a/plugins/check_http.c b/plugins/check_http.c index 718c8ee7..cdf768c9 100644 --- a/plugins/check_http.c +++ b/plugins/check_http.c | |||
@@ -85,6 +85,7 @@ char errbuf[MAX_INPUT_BUFFER]; | |||
85 | int cflags = REG_NOSUB | REG_EXTENDED | REG_NEWLINE; | 85 | int cflags = REG_NOSUB | REG_EXTENDED | REG_NEWLINE; |
86 | int errcode; | 86 | int errcode; |
87 | int invert_regex = 0; | 87 | int invert_regex = 0; |
88 | int state_regex = STATE_CRITICAL; | ||
88 | 89 | ||
89 | struct timeval tv; | 90 | struct timeval tv; |
90 | struct timeval tv_temp; | 91 | struct timeval tv_temp; |
@@ -210,7 +211,8 @@ bool process_arguments (int argc, char **argv) | |||
210 | INVERT_REGEX = CHAR_MAX + 1, | 211 | INVERT_REGEX = CHAR_MAX + 1, |
211 | SNI_OPTION, | 212 | SNI_OPTION, |
212 | MAX_REDIRS_OPTION, | 213 | MAX_REDIRS_OPTION, |
213 | CONTINUE_AFTER_CHECK_CERT | 214 | CONTINUE_AFTER_CHECK_CERT, |
215 | STATE_REGEX | ||
214 | }; | 216 | }; |
215 | 217 | ||
216 | int option = 0; | 218 | int option = 0; |
@@ -246,6 +248,7 @@ bool process_arguments (int argc, char **argv) | |||
246 | {"content-type", required_argument, 0, 'T'}, | 248 | {"content-type", required_argument, 0, 'T'}, |
247 | {"pagesize", required_argument, 0, 'm'}, | 249 | {"pagesize", required_argument, 0, 'm'}, |
248 | {"invert-regex", no_argument, NULL, INVERT_REGEX}, | 250 | {"invert-regex", no_argument, NULL, INVERT_REGEX}, |
251 | {"state-regex", required_argument, 0, STATE_REGEX}, | ||
249 | {"use-ipv4", no_argument, 0, '4'}, | 252 | {"use-ipv4", no_argument, 0, '4'}, |
250 | {"use-ipv6", no_argument, 0, '6'}, | 253 | {"use-ipv6", no_argument, 0, '6'}, |
251 | {"extended-perfdata", no_argument, 0, 'E'}, | 254 | {"extended-perfdata", no_argument, 0, 'E'}, |
@@ -471,10 +474,9 @@ bool process_arguments (int argc, char **argv) | |||
471 | free(http_method); | 474 | free(http_method); |
472 | http_method = strdup (optarg); | 475 | http_method = strdup (optarg); |
473 | char *tmp; | 476 | char *tmp; |
474 | if ((tmp = strstr(http_method, ":")) > 0) { | 477 | if ((tmp = strstr(http_method, ":")) != NULL) { |
475 | tmp[0] = '\0'; | 478 | tmp[0] = '\0'; // set the ":" in the middle to 0 |
476 | http_method = http_method; | 479 | http_method_proxy = ++tmp; // this points to the second part |
477 | http_method_proxy = ++tmp; | ||
478 | } | 480 | } |
479 | break; | 481 | break; |
480 | case 'd': /* string or substring */ | 482 | case 'd': /* string or substring */ |
@@ -512,6 +514,13 @@ bool process_arguments (int argc, char **argv) | |||
512 | case INVERT_REGEX: | 514 | case INVERT_REGEX: |
513 | invert_regex = 1; | 515 | invert_regex = 1; |
514 | break; | 516 | break; |
517 | case STATE_REGEX: | ||
518 | if (!strcmp (optarg, "critical")) | ||
519 | state_regex = STATE_CRITICAL; | ||
520 | else if (!strcmp (optarg, "warning")) | ||
521 | state_regex = STATE_WARNING; | ||
522 | else usage2 (_("Invalid state-regex option"), optarg); | ||
523 | break; | ||
515 | case '4': | 524 | case '4': |
516 | address_family = AF_INET; | 525 | address_family = AF_INET; |
517 | break; | 526 | break; |
@@ -1094,7 +1103,7 @@ check_http (void) | |||
1094 | microsec_firstbyte = deltime (tv_temp); | 1103 | microsec_firstbyte = deltime (tv_temp); |
1095 | elapsed_time_firstbyte = (double)microsec_firstbyte / 1.0e6; | 1104 | elapsed_time_firstbyte = (double)microsec_firstbyte / 1.0e6; |
1096 | } | 1105 | } |
1097 | while (pos = memchr(buffer, '\0', i)) { | 1106 | while ((pos = memchr(buffer, '\0', i))) { |
1098 | /* replace nul character with a blank */ | 1107 | /* replace nul character with a blank */ |
1099 | *pos = ' '; | 1108 | *pos = ' '; |
1100 | } | 1109 | } |
@@ -1318,7 +1327,7 @@ check_http (void) | |||
1318 | xasprintf (&msg, _("%spattern not found, "), msg); | 1327 | xasprintf (&msg, _("%spattern not found, "), msg); |
1319 | else | 1328 | else |
1320 | xasprintf (&msg, _("%spattern found, "), msg); | 1329 | xasprintf (&msg, _("%spattern found, "), msg); |
1321 | result = STATE_CRITICAL; | 1330 | result = state_regex; |
1322 | } | 1331 | } |
1323 | else { | 1332 | else { |
1324 | /* FIXME: Shouldn't that be UNKNOWN? */ | 1333 | /* FIXME: Shouldn't that be UNKNOWN? */ |
@@ -1775,7 +1784,7 @@ print_help (void) | |||
1775 | printf (" %s\n", "-u, --url=PATH"); | 1784 | printf (" %s\n", "-u, --url=PATH"); |
1776 | printf (" %s\n", _("URL to GET or POST (default: /)")); | 1785 | printf (" %s\n", _("URL to GET or POST (default: /)")); |
1777 | printf (" %s\n", "-P, --post=STRING"); | 1786 | printf (" %s\n", "-P, --post=STRING"); |
1778 | printf (" %s\n", _("URL encoded http POST data")); | 1787 | printf (" %s\n", _("URL decoded http POST data")); |
1779 | printf (" %s\n", "-j, --method=STRING (for example: HEAD, OPTIONS, TRACE, PUT, DELETE, CONNECT, CONNECT:POST)"); | 1788 | printf (" %s\n", "-j, --method=STRING (for example: HEAD, OPTIONS, TRACE, PUT, DELETE, CONNECT, CONNECT:POST)"); |
1780 | printf (" %s\n", _("Set HTTP method.")); | 1789 | printf (" %s\n", _("Set HTTP method.")); |
1781 | printf (" %s\n", "-N, --no-body"); | 1790 | printf (" %s\n", "-N, --no-body"); |
@@ -1794,7 +1803,10 @@ print_help (void) | |||
1794 | printf (" %s\n", "-R, --eregi=STRING"); | 1803 | printf (" %s\n", "-R, --eregi=STRING"); |
1795 | printf (" %s\n", _("Search page for case-insensitive regex STRING")); | 1804 | printf (" %s\n", _("Search page for case-insensitive regex STRING")); |
1796 | printf (" %s\n", "--invert-regex"); | 1805 | printf (" %s\n", "--invert-regex"); |
1797 | printf (" %s\n", _("Return CRITICAL if found, OK if not\n")); | 1806 | printf (" %s\n", _("Return STATE if found, OK if not (STATE is CRITICAL, per default)")); |
1807 | printf (" %s\n", _("can be changed with --state--regex)")); | ||
1808 | printf (" %s\n", "--regex-state=STATE"); | ||
1809 | printf (" %s\n", _("Return STATE if regex is found, OK if not\n")); | ||
1798 | 1810 | ||
1799 | printf (" %s\n", "-a, --authorization=AUTH_PAIR"); | 1811 | printf (" %s\n", "-a, --authorization=AUTH_PAIR"); |
1800 | printf (" %s\n", _("Username:password on sites with basic authentication")); | 1812 | printf (" %s\n", _("Username:password on sites with basic authentication")); |
diff --git a/plugins/check_ide_smart.c b/plugins/check_ide_smart.c index 0160d98b..3872e341 100644 --- a/plugins/check_ide_smart.c +++ b/plugins/check_ide_smart.c | |||
@@ -73,10 +73,6 @@ void print_usage (void); | |||
73 | 73 | ||
74 | #define NR_ATTRIBUTES 30 | 74 | #define NR_ATTRIBUTES 30 |
75 | 75 | ||
76 | #ifndef TRUE | ||
77 | #define TRUE 1 | ||
78 | #endif /* */ | ||
79 | |||
80 | #define PREFAILURE 2 | 76 | #define PREFAILURE 2 |
81 | #define ADVISORY 1 | 77 | #define ADVISORY 1 |
82 | #define OPERATIONAL 0 | 78 | #define OPERATIONAL 0 |
@@ -169,9 +165,9 @@ int smart_read_values (int, values_t *); | |||
169 | int nagios (values_t *, thresholds_t *); | 165 | int nagios (values_t *, thresholds_t *); |
170 | void print_value (value_t *, threshold_t *); | 166 | void print_value (value_t *, threshold_t *); |
171 | void print_values (values_t *, thresholds_t *); | 167 | void print_values (values_t *, thresholds_t *); |
172 | int smart_cmd_simple (int, enum SmartCommand, __u8, char); | 168 | int smart_cmd_simple (int, enum SmartCommand, __u8, bool); |
173 | int smart_read_thresholds (int, thresholds_t *); | 169 | int smart_read_thresholds (int, thresholds_t *); |
174 | int verbose = FALSE; | 170 | bool verbose = false; |
175 | 171 | ||
176 | int | 172 | int |
177 | main (int argc, char *argv[]) | 173 | main (int argc, char *argv[]) |
@@ -203,7 +199,7 @@ main (int argc, char *argv[]) | |||
203 | bindtextdomain (PACKAGE, LOCALEDIR); | 199 | bindtextdomain (PACKAGE, LOCALEDIR); |
204 | textdomain (PACKAGE); | 200 | textdomain (PACKAGE); |
205 | 201 | ||
206 | while (1) { | 202 | while (true) { |
207 | 203 | ||
208 | o = getopt_long (argc, argv, "+d:iq10nhVv", longopts, &longindex); | 204 | o = getopt_long (argc, argv, "+d:iq10nhVv", longopts, &longindex); |
209 | 205 | ||
@@ -229,7 +225,7 @@ main (int argc, char *argv[]) | |||
229 | fprintf (stderr, "%s\n", _("default and will be removed from future releases.")); | 225 | fprintf (stderr, "%s\n", _("default and will be removed from future releases.")); |
230 | break; | 226 | break; |
231 | case 'v': /* verbose */ | 227 | case 'v': /* verbose */ |
232 | verbose = TRUE; | 228 | verbose = true; |
233 | break; | 229 | break; |
234 | case 'h': | 230 | case 'h': |
235 | print_help (); | 231 | print_help (); |
@@ -258,7 +254,7 @@ main (int argc, char *argv[]) | |||
258 | return STATE_CRITICAL; | 254 | return STATE_CRITICAL; |
259 | } | 255 | } |
260 | 256 | ||
261 | if (smart_cmd_simple (fd, SMART_CMD_ENABLE, 0, FALSE)) { | 257 | if (smart_cmd_simple (fd, SMART_CMD_ENABLE, 0, false)) { |
262 | printf (_("CRITICAL - SMART_CMD_ENABLE\n")); | 258 | printf (_("CRITICAL - SMART_CMD_ENABLE\n")); |
263 | return STATE_CRITICAL; | 259 | return STATE_CRITICAL; |
264 | } | 260 | } |
@@ -447,9 +443,7 @@ print_values (values_t * p, thresholds_t * t) | |||
447 | } | 443 | } |
448 | 444 | ||
449 | 445 | ||
450 | int | 446 | int smart_cmd_simple (int fd, enum SmartCommand command, __u8 val0, bool show_error) { |
451 | smart_cmd_simple (int fd, enum SmartCommand command, __u8 val0, char show_error) | ||
452 | { | ||
453 | int e = STATE_UNKNOWN; | 447 | int e = STATE_UNKNOWN; |
454 | #ifdef __linux__ | 448 | #ifdef __linux__ |
455 | __u8 args[4]; | 449 | __u8 args[4]; |
diff --git a/plugins/check_ldap.c b/plugins/check_ldap.c index a1bfe1be..868ffc1e 100644 --- a/plugins/check_ldap.c +++ b/plugins/check_ldap.c | |||
@@ -71,9 +71,9 @@ thresholds *entries_thresholds = NULL; | |||
71 | struct timeval tv; | 71 | struct timeval tv; |
72 | char* warn_entries = NULL; | 72 | char* warn_entries = NULL; |
73 | char* crit_entries = NULL; | 73 | char* crit_entries = NULL; |
74 | int starttls = FALSE; | 74 | bool starttls = false; |
75 | int ssl_on_connect = FALSE; | 75 | bool ssl_on_connect = false; |
76 | int verbose = 0; | 76 | bool verbose = false; |
77 | 77 | ||
78 | /* for ldap tls */ | 78 | /* for ldap tls */ |
79 | 79 | ||
@@ -97,9 +97,6 @@ main (int argc, char *argv[]) | |||
97 | int tls; | 97 | int tls; |
98 | int version=3; | 98 | int version=3; |
99 | 99 | ||
100 | /* for entry counting */ | ||
101 | |||
102 | LDAPMessage *next_entry; | ||
103 | int status_entries = STATE_OK; | 100 | int status_entries = STATE_OK; |
104 | int num_entries = 0; | 101 | int num_entries = 0; |
105 | 102 | ||
@@ -118,7 +115,7 @@ main (int argc, char *argv[]) | |||
118 | usage4 (_("Could not parse arguments")); | 115 | usage4 (_("Could not parse arguments")); |
119 | 116 | ||
120 | if (strstr(argv[0],"check_ldaps") && ! starttls && ! ssl_on_connect) | 117 | if (strstr(argv[0],"check_ldaps") && ! starttls && ! ssl_on_connect) |
121 | starttls = TRUE; | 118 | starttls = true; |
122 | 119 | ||
123 | /* initialize alarm signal handling */ | 120 | /* initialize alarm signal handling */ |
124 | signal (SIGALRM, socket_timeout_alarm_handler); | 121 | signal (SIGALRM, socket_timeout_alarm_handler); |
@@ -256,11 +253,11 @@ main (int argc, char *argv[]) | |||
256 | fperfdata ("time", elapsed_time, "s", | 253 | fperfdata ("time", elapsed_time, "s", |
257 | (int)warn_time, warn_time, | 254 | (int)warn_time, warn_time, |
258 | (int)crit_time, crit_time, | 255 | (int)crit_time, crit_time, |
259 | TRUE, 0, FALSE, 0), | 256 | true, 0, false, 0), |
260 | sperfdata ("entries", (double)num_entries, "", | 257 | sperfdata ("entries", (double)num_entries, "", |
261 | warn_entries, | 258 | warn_entries, |
262 | crit_entries, | 259 | crit_entries, |
263 | TRUE, 0.0, FALSE, 0.0)); | 260 | true, 0.0, false, 0.0)); |
264 | } else { | 261 | } else { |
265 | printf (_("LDAP %s - %.3f seconds response time|%s\n"), | 262 | printf (_("LDAP %s - %.3f seconds response time|%s\n"), |
266 | state_text (status), | 263 | state_text (status), |
@@ -268,7 +265,7 @@ main (int argc, char *argv[]) | |||
268 | fperfdata ("time", elapsed_time, "s", | 265 | fperfdata ("time", elapsed_time, "s", |
269 | (int)warn_time, warn_time, | 266 | (int)warn_time, warn_time, |
270 | (int)crit_time, crit_time, | 267 | (int)crit_time, crit_time, |
271 | TRUE, 0, FALSE, 0)); | 268 | true, 0, false, 0)); |
272 | } | 269 | } |
273 | 270 | ||
274 | return status; | 271 | return status; |
@@ -316,7 +313,7 @@ process_arguments (int argc, char **argv) | |||
316 | strcpy (argv[c], "-t"); | 313 | strcpy (argv[c], "-t"); |
317 | } | 314 | } |
318 | 315 | ||
319 | while (1) { | 316 | while (true) { |
320 | c = getopt_long (argc, argv, "hvV234TS6t:c:w:H:b:p:a:D:P:C:W:", longopts, &option); | 317 | c = getopt_long (argc, argv, "hvV234TS6t:c:w:H:b:p:a:D:P:C:W:", longopts, &option); |
321 | 318 | ||
322 | if (c == -1 || c == EOF) | 319 | if (c == -1 || c == EOF) |
@@ -377,17 +374,17 @@ process_arguments (int argc, char **argv) | |||
377 | address_family = AF_INET; | 374 | address_family = AF_INET; |
378 | break; | 375 | break; |
379 | case 'v': | 376 | case 'v': |
380 | verbose++; | 377 | verbose = true; |
381 | break; | 378 | break; |
382 | case 'T': | 379 | case 'T': |
383 | if (! ssl_on_connect) | 380 | if (! ssl_on_connect) |
384 | starttls = TRUE; | 381 | starttls = true; |
385 | else | 382 | else |
386 | usage_va(_("%s cannot be combined with %s"), "-T/--starttls", "-S/--ssl"); | 383 | usage_va(_("%s cannot be combined with %s"), "-T/--starttls", "-S/--ssl"); |
387 | break; | 384 | break; |
388 | case 'S': | 385 | case 'S': |
389 | if (! starttls) { | 386 | if (! starttls) { |
390 | ssl_on_connect = TRUE; | 387 | ssl_on_connect = true; |
391 | if (ld_port == -1) | 388 | if (ld_port == -1) |
392 | ld_port = LDAPS_PORT; | 389 | ld_port = LDAPS_PORT; |
393 | } else | 390 | } else |
diff --git a/plugins/check_load.c b/plugins/check_load.c index 313df8ad..1431d130 100644 --- a/plugins/check_load.c +++ b/plugins/check_load.c | |||
@@ -110,10 +110,6 @@ main (int argc, char **argv) | |||
110 | double la[3] = { 0.0, 0.0, 0.0 }; /* NetBSD complains about uninitialized arrays */ | 110 | double la[3] = { 0.0, 0.0, 0.0 }; /* NetBSD complains about uninitialized arrays */ |
111 | #ifndef HAVE_GETLOADAVG | 111 | #ifndef HAVE_GETLOADAVG |
112 | char input_buffer[MAX_INPUT_BUFFER]; | 112 | char input_buffer[MAX_INPUT_BUFFER]; |
113 | # ifdef HAVE_PROC_LOADAVG | ||
114 | FILE *fp; | ||
115 | char *str, *next; | ||
116 | # endif | ||
117 | #endif | 113 | #endif |
118 | 114 | ||
119 | setlocale (LC_ALL, ""); | 115 | setlocale (LC_ALL, ""); |
@@ -132,23 +128,6 @@ main (int argc, char **argv) | |||
132 | if (result != 3) | 128 | if (result != 3) |
133 | return STATE_UNKNOWN; | 129 | return STATE_UNKNOWN; |
134 | #else | 130 | #else |
135 | # ifdef HAVE_PROC_LOADAVG | ||
136 | fp = fopen (PROC_LOADAVG, "r"); | ||
137 | if (fp == NULL) { | ||
138 | printf (_("Error opening %s\n"), PROC_LOADAVG); | ||
139 | return STATE_UNKNOWN; | ||
140 | } | ||
141 | |||
142 | while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, fp)) { | ||
143 | str = (char *)input_buffer; | ||
144 | for(i = 0; i < 3; i++) { | ||
145 | la[i] = strtod(str, &next); | ||
146 | str = next; | ||
147 | } | ||
148 | } | ||
149 | |||
150 | fclose (fp); | ||
151 | # else | ||
152 | child_process = spopen (PATH_TO_UPTIME); | 131 | child_process = spopen (PATH_TO_UPTIME); |
153 | if (child_process == NULL) { | 132 | if (child_process == NULL) { |
154 | printf (_("Error opening %s\n"), PATH_TO_UPTIME); | 133 | printf (_("Error opening %s\n"), PATH_TO_UPTIME); |
@@ -175,18 +154,13 @@ main (int argc, char **argv) | |||
175 | printf (_("Error code %d returned in %s\n"), result, PATH_TO_UPTIME); | 154 | printf (_("Error code %d returned in %s\n"), result, PATH_TO_UPTIME); |
176 | return STATE_UNKNOWN; | 155 | return STATE_UNKNOWN; |
177 | } | 156 | } |
178 | # endif | ||
179 | #endif | 157 | #endif |
180 | 158 | ||
181 | if ((la[0] < 0.0) || (la[1] < 0.0) || (la[2] < 0.0)) { | 159 | if ((la[0] < 0.0) || (la[1] < 0.0) || (la[2] < 0.0)) { |
182 | #ifdef HAVE_GETLOADAVG | 160 | #ifdef HAVE_GETLOADAVG |
183 | printf (_("Error in getloadavg()\n")); | 161 | printf (_("Error in getloadavg()\n")); |
184 | #else | 162 | #else |
185 | # ifdef HAVE_PROC_LOADAVG | ||
186 | printf (_("Error processing %s\n"), PROC_LOADAVG); | ||
187 | # else | ||
188 | printf (_("Error processing %s\n"), PATH_TO_UPTIME); | 163 | printf (_("Error processing %s\n"), PATH_TO_UPTIME); |
189 | # endif | ||
190 | #endif | 164 | #endif |
191 | return STATE_UNKNOWN; | 165 | return STATE_UNKNOWN; |
192 | } | 166 | } |
diff --git a/plugins/check_mrtg.c b/plugins/check_mrtg.c index 1fda5492..826b77e9 100644 --- a/plugins/check_mrtg.c +++ b/plugins/check_mrtg.c | |||
@@ -43,7 +43,7 @@ void print_usage (void); | |||
43 | 43 | ||
44 | char *log_file = NULL; | 44 | char *log_file = NULL; |
45 | int expire_minutes = 0; | 45 | int expire_minutes = 0; |
46 | int use_average = TRUE; | 46 | bool use_average = true; |
47 | int variable_number = -1; | 47 | int variable_number = -1; |
48 | unsigned long value_warning_threshold = 0L; | 48 | unsigned long value_warning_threshold = 0L; |
49 | unsigned long value_critical_threshold = 0L; | 49 | unsigned long value_critical_threshold = 0L; |
@@ -138,7 +138,7 @@ main (int argc, char **argv) | |||
138 | } | 138 | } |
139 | 139 | ||
140 | /* else check the incoming/outgoing rates */ | 140 | /* else check the incoming/outgoing rates */ |
141 | if (use_average == TRUE) | 141 | if (use_average) |
142 | rate = average_value_rate; | 142 | rate = average_value_rate; |
143 | else | 143 | else |
144 | rate = maximum_value_rate; | 144 | rate = maximum_value_rate; |
@@ -149,7 +149,7 @@ main (int argc, char **argv) | |||
149 | result = STATE_WARNING; | 149 | result = STATE_WARNING; |
150 | 150 | ||
151 | printf("%s. %s = %lu %s|%s\n", | 151 | printf("%s. %s = %lu %s|%s\n", |
152 | (use_average == TRUE) ? _("Avg") : _("Max"), | 152 | (use_average) ? _("Avg") : _("Max"), |
153 | label, rate, units, | 153 | label, rate, units, |
154 | perfdata(label, (long) rate, units, | 154 | perfdata(label, (long) rate, units, |
155 | (int) value_warning_threshold, (long) value_warning_threshold, | 155 | (int) value_warning_threshold, (long) value_warning_threshold, |
@@ -211,9 +211,9 @@ process_arguments (int argc, char **argv) | |||
211 | break; | 211 | break; |
212 | case 'a': /* port */ | 212 | case 'a': /* port */ |
213 | if (!strcmp (optarg, "MAX")) | 213 | if (!strcmp (optarg, "MAX")) |
214 | use_average = FALSE; | 214 | use_average = false; |
215 | else | 215 | else |
216 | use_average = TRUE; | 216 | use_average = true; |
217 | break; | 217 | break; |
218 | case 'v': | 218 | case 'v': |
219 | variable_number = atoi (optarg); | 219 | variable_number = atoi (optarg); |
@@ -258,11 +258,11 @@ process_arguments (int argc, char **argv) | |||
258 | } | 258 | } |
259 | 259 | ||
260 | if (argc > c && strcmp (argv[c], "MAX") == 0) { | 260 | if (argc > c && strcmp (argv[c], "MAX") == 0) { |
261 | use_average = FALSE; | 261 | use_average = false; |
262 | c++; | 262 | c++; |
263 | } | 263 | } |
264 | else if (argc > c && strcmp (argv[c], "AVG") == 0) { | 264 | else if (argc > c && strcmp (argv[c], "AVG") == 0) { |
265 | use_average = TRUE; | 265 | use_average = true; |
266 | c++; | 266 | c++; |
267 | } | 267 | } |
268 | 268 | ||
diff --git a/plugins/check_mrtgtraf.c b/plugins/check_mrtgtraf.c index eb66f622..bd25d47d 100644 --- a/plugins/check_mrtgtraf.c +++ b/plugins/check_mrtgtraf.c | |||
@@ -43,7 +43,7 @@ void print_usage(void); | |||
43 | 43 | ||
44 | char *log_file = NULL; | 44 | char *log_file = NULL; |
45 | int expire_minutes = -1; | 45 | int expire_minutes = -1; |
46 | int use_average = TRUE; | 46 | bool use_average = true; |
47 | unsigned long incoming_warning_threshold = 0L; | 47 | unsigned long incoming_warning_threshold = 0L; |
48 | unsigned long incoming_critical_threshold = 0L; | 48 | unsigned long incoming_critical_threshold = 0L; |
49 | unsigned long outgoing_warning_threshold = 0L; | 49 | unsigned long outgoing_warning_threshold = 0L; |
@@ -137,7 +137,7 @@ main (int argc, char **argv) | |||
137 | (int) ((current_time - timestamp) / 60)); | 137 | (int) ((current_time - timestamp) / 60)); |
138 | 138 | ||
139 | /* else check the incoming/outgoing rates */ | 139 | /* else check the incoming/outgoing rates */ |
140 | if (use_average == TRUE) { | 140 | if (use_average) { |
141 | incoming_rate = average_incoming_rate; | 141 | incoming_rate = average_incoming_rate; |
142 | outgoing_rate = average_outgoing_rate; | 142 | outgoing_rate = average_outgoing_rate; |
143 | } | 143 | } |
@@ -192,17 +192,17 @@ main (int argc, char **argv) | |||
192 | } | 192 | } |
193 | 193 | ||
194 | xasprintf (&error_message, _("%s. In = %0.1f %s/s, %s. Out = %0.1f %s/s|%s %s\n"), | 194 | xasprintf (&error_message, _("%s. In = %0.1f %s/s, %s. Out = %0.1f %s/s|%s %s\n"), |
195 | (use_average == TRUE) ? _("Avg") : _("Max"), adjusted_incoming_rate, | 195 | (use_average) ? _("Avg") : _("Max"), adjusted_incoming_rate, |
196 | incoming_speed_rating, (use_average == TRUE) ? _("Avg") : _("Max"), | 196 | incoming_speed_rating, (use_average) ? _("Avg") : _("Max"), |
197 | adjusted_outgoing_rate, outgoing_speed_rating, | 197 | adjusted_outgoing_rate, outgoing_speed_rating, |
198 | fperfdata("in", adjusted_incoming_rate, incoming_speed_rating, | 198 | fperfdata("in", adjusted_incoming_rate, incoming_speed_rating, |
199 | (int)incoming_warning_threshold, incoming_warning_threshold, | 199 | (int)incoming_warning_threshold, incoming_warning_threshold, |
200 | (int)incoming_critical_threshold, incoming_critical_threshold, | 200 | (int)incoming_critical_threshold, incoming_critical_threshold, |
201 | TRUE, 0, FALSE, 0), | 201 | true, 0, false, 0), |
202 | fperfdata("out", adjusted_outgoing_rate, outgoing_speed_rating, | 202 | fperfdata("out", adjusted_outgoing_rate, outgoing_speed_rating, |
203 | (int)outgoing_warning_threshold, outgoing_warning_threshold, | 203 | (int)outgoing_warning_threshold, outgoing_warning_threshold, |
204 | (int)outgoing_critical_threshold, outgoing_critical_threshold, | 204 | (int)outgoing_critical_threshold, outgoing_critical_threshold, |
205 | TRUE, 0, FALSE, 0)); | 205 | true, 0, false, 0)); |
206 | 206 | ||
207 | printf (_("Traffic %s - %s\n"), state_text(result), error_message); | 207 | printf (_("Traffic %s - %s\n"), state_text(result), error_message); |
208 | 208 | ||
@@ -256,9 +256,9 @@ process_arguments (int argc, char **argv) | |||
256 | break; | 256 | break; |
257 | case 'a': /* aggregation (AVE or MAX) */ | 257 | case 'a': /* aggregation (AVE or MAX) */ |
258 | if (!strcmp (optarg, "MAX")) | 258 | if (!strcmp (optarg, "MAX")) |
259 | use_average = FALSE; | 259 | use_average = false; |
260 | else | 260 | else |
261 | use_average = TRUE; | 261 | use_average = true; |
262 | break; | 262 | break; |
263 | case 'c': /* warning threshold */ | 263 | case 'c': /* warning threshold */ |
264 | sscanf (optarg, "%lu,%lu", &incoming_critical_threshold, | 264 | sscanf (optarg, "%lu,%lu", &incoming_critical_threshold, |
@@ -289,11 +289,11 @@ process_arguments (int argc, char **argv) | |||
289 | } | 289 | } |
290 | 290 | ||
291 | if (argc > c && strcmp (argv[c], "MAX") == 0) { | 291 | if (argc > c && strcmp (argv[c], "MAX") == 0) { |
292 | use_average = FALSE; | 292 | use_average = false; |
293 | c++; | 293 | c++; |
294 | } | 294 | } |
295 | else if (argc > c && strcmp (argv[c], "AVG") == 0) { | 295 | else if (argc > c && strcmp (argv[c], "AVG") == 0) { |
296 | use_average = TRUE; | 296 | use_average = true; |
297 | c++; | 297 | c++; |
298 | } | 298 | } |
299 | 299 | ||
diff --git a/plugins/check_mysql.c b/plugins/check_mysql.c index 7d855544..15ec04c0 100644 --- a/plugins/check_mysql.c +++ b/plugins/check_mysql.c | |||
@@ -59,8 +59,8 @@ bool ssl = false; | |||
59 | char *opt_file = NULL; | 59 | char *opt_file = NULL; |
60 | char *opt_group = NULL; | 60 | char *opt_group = NULL; |
61 | unsigned int db_port = MYSQL_PORT; | 61 | unsigned int db_port = MYSQL_PORT; |
62 | int check_slave = 0, warn_sec = 0, crit_sec = 0; | 62 | bool check_slave = false; |
63 | int ignore_auth = 0; | 63 | bool ignore_auth = false; |
64 | int verbose = 0; | 64 | int verbose = 0; |
65 | 65 | ||
66 | static double warning_time = 0; | 66 | static double warning_time = 0; |
@@ -113,7 +113,7 @@ main (int argc, char **argv) | |||
113 | char slaveresult[SLAVERESULTSIZE] = { 0 }; | 113 | char slaveresult[SLAVERESULTSIZE] = { 0 }; |
114 | char* perf; | 114 | char* perf; |
115 | 115 | ||
116 | perf = strdup (""); | 116 | perf = strdup (""); |
117 | 117 | ||
118 | setlocale (LC_ALL, ""); | 118 | setlocale (LC_ALL, ""); |
119 | bindtextdomain (PACKAGE, LOCALEDIR); | 119 | bindtextdomain (PACKAGE, LOCALEDIR); |
@@ -193,14 +193,14 @@ main (int argc, char **argv) | |||
193 | for(i = 0; i < LENGTH_METRIC_UNIT; i++) { | 193 | for(i = 0; i < LENGTH_METRIC_UNIT; i++) { |
194 | if (strcmp(row[0], metric_unit[i]) == 0) { | 194 | if (strcmp(row[0], metric_unit[i]) == 0) { |
195 | xasprintf(&perf, "%s%s ", perf, perfdata(metric_unit[i], | 195 | xasprintf(&perf, "%s%s ", perf, perfdata(metric_unit[i], |
196 | atol(row[1]), "", FALSE, 0, FALSE, 0, FALSE, 0, FALSE, 0)); | 196 | atol(row[1]), "", false, 0, false, 0, false, 0, false, 0)); |
197 | continue; | 197 | continue; |
198 | } | 198 | } |
199 | } | 199 | } |
200 | for(i = 0; i < LENGTH_METRIC_COUNTER; i++) { | 200 | for(i = 0; i < LENGTH_METRIC_COUNTER; i++) { |
201 | if (strcmp(row[0], metric_counter[i]) == 0) { | 201 | if (strcmp(row[0], metric_counter[i]) == 0) { |
202 | xasprintf(&perf, "%s%s ", perf, perfdata(metric_counter[i], | 202 | xasprintf(&perf, "%s%s ", perf, perfdata(metric_counter[i], |
203 | atol(row[1]), "c", FALSE, 0, FALSE, 0, FALSE, 0, FALSE, 0)); | 203 | atol(row[1]), "c", false, 0, false, 0, false, 0, false, 0)); |
204 | continue; | 204 | continue; |
205 | } | 205 | } |
206 | } | 206 | } |
@@ -322,10 +322,10 @@ main (int argc, char **argv) | |||
322 | status = get_status(value, my_threshold); | 322 | status = get_status(value, my_threshold); |
323 | 323 | ||
324 | xasprintf (&perf, "%s %s", perf, fperfdata ("seconds behind master", value, "s", | 324 | xasprintf (&perf, "%s %s", perf, fperfdata ("seconds behind master", value, "s", |
325 | TRUE, (double) warning_time, | 325 | true, (double) warning_time, |
326 | TRUE, (double) critical_time, | 326 | true, (double) critical_time, |
327 | FALSE, 0, | 327 | false, 0, |
328 | FALSE, 0)); | 328 | false, 0)); |
329 | 329 | ||
330 | if (status == STATE_WARNING) { | 330 | if (status == STATE_WARNING) { |
331 | printf("SLOW_SLAVE %s: %s|%s\n", _("WARNING"), slaveresult, perf); | 331 | printf("SLOW_SLAVE %s: %s|%s\n", _("WARNING"), slaveresult, perf); |
@@ -456,10 +456,10 @@ process_arguments (int argc, char **argv) | |||
456 | db_port = atoi (optarg); | 456 | db_port = atoi (optarg); |
457 | break; | 457 | break; |
458 | case 'S': | 458 | case 'S': |
459 | check_slave = 1; /* check-slave */ | 459 | check_slave = true; /* check-slave */ |
460 | break; | 460 | break; |
461 | case 'n': | 461 | case 'n': |
462 | ignore_auth = 1; /* ignore-auth */ | 462 | ignore_auth = true; /* ignore-auth */ |
463 | break; | 463 | break; |
464 | case 'w': | 464 | case 'w': |
465 | warning = optarg; | 465 | warning = optarg; |
diff --git a/plugins/check_mysql_query.c b/plugins/check_mysql_query.c index ac2fb15d..842b7a2f 100644 --- a/plugins/check_mysql_query.c +++ b/plugins/check_mysql_query.c | |||
@@ -162,10 +162,10 @@ main (int argc, char **argv) | |||
162 | } | 162 | } |
163 | printf(_("'%s' returned %f | %s"), sql_query, value, | 163 | printf(_("'%s' returned %f | %s"), sql_query, value, |
164 | fperfdata("result", value, "", | 164 | fperfdata("result", value, "", |
165 | my_thresholds->warning?TRUE:FALSE, my_thresholds->warning?my_thresholds->warning->end:0, | 165 | my_thresholds->warning?true:false, my_thresholds->warning?my_thresholds->warning->end:0, |
166 | my_thresholds->critical?TRUE:FALSE, my_thresholds->critical?my_thresholds->critical->end:0, | 166 | my_thresholds->critical?true:false, my_thresholds->critical?my_thresholds->critical->end:0, |
167 | FALSE, 0, | 167 | false, 0, |
168 | FALSE, 0) | 168 | false, 0) |
169 | ); | 169 | ); |
170 | printf("\n"); | 170 | printf("\n"); |
171 | 171 | ||
diff --git a/plugins/check_nt.c b/plugins/check_nt.c index d73d83ce..19c050de 100644 --- a/plugins/check_nt.c +++ b/plugins/check_nt.c | |||
@@ -67,17 +67,17 @@ char *req_password=NULL; | |||
67 | unsigned long lvalue_list[MAX_VALUE_LIST]; | 67 | unsigned long lvalue_list[MAX_VALUE_LIST]; |
68 | unsigned long warning_value=0L; | 68 | unsigned long warning_value=0L; |
69 | unsigned long critical_value=0L; | 69 | unsigned long critical_value=0L; |
70 | int check_warning_value=FALSE; | 70 | bool check_warning_value=false; |
71 | int check_critical_value=FALSE; | 71 | bool check_critical_value=false; |
72 | enum checkvars vars_to_check = CHECK_NONE; | 72 | enum checkvars vars_to_check = CHECK_NONE; |
73 | int show_all=FALSE; | 73 | bool show_all = false; |
74 | 74 | ||
75 | char recv_buffer[MAX_INPUT_BUFFER]; | 75 | char recv_buffer[MAX_INPUT_BUFFER]; |
76 | 76 | ||
77 | void fetch_data (const char* address, int port, const char* sendb); | 77 | void fetch_data (const char* address, int port, const char* sendb); |
78 | int process_arguments(int, char **); | 78 | int process_arguments(int, char **); |
79 | void preparelist(char *string); | 79 | void preparelist(char *string); |
80 | int strtoularray(unsigned long *array, char *string, const char *delim); | 80 | bool strtoularray(unsigned long *array, char *string, const char *delim); |
81 | void print_help(void); | 81 | void print_help(void); |
82 | void print_usage(void); | 82 | void print_usage(void); |
83 | 83 | ||
@@ -113,8 +113,8 @@ int main(int argc, char **argv){ | |||
113 | int uphours=0; | 113 | int uphours=0; |
114 | int upminutes=0; | 114 | int upminutes=0; |
115 | 115 | ||
116 | int isPercent = FALSE; | 116 | bool isPercent = false; |
117 | int allRight = FALSE; | 117 | bool allRight = false; |
118 | 118 | ||
119 | setlocale (LC_ALL, ""); | 119 | setlocale (LC_ALL, ""); |
120 | bindtextdomain (PACKAGE, LOCALEDIR); | 120 | bindtextdomain (PACKAGE, LOCALEDIR); |
@@ -151,7 +151,7 @@ int main(int argc, char **argv){ | |||
151 | 151 | ||
152 | if (value_list==NULL) | 152 | if (value_list==NULL) |
153 | output_message = strdup (_("missing -l parameters")); | 153 | output_message = strdup (_("missing -l parameters")); |
154 | else if (strtoularray(lvalue_list,value_list,",")==FALSE) | 154 | else if (! strtoularray(lvalue_list,value_list,",")) |
155 | output_message = strdup (_("wrong -l parameter.")); | 155 | output_message = strdup (_("wrong -l parameter.")); |
156 | else { | 156 | else { |
157 | /* -l parameters is present with only integers */ | 157 | /* -l parameters is present with only integers */ |
@@ -224,9 +224,9 @@ int main(int argc, char **argv){ | |||
224 | 224 | ||
225 | xasprintf(&output_message,_("System Uptime - %u day(s) %u hour(s) %u minute(s) |uptime=%lu"),updays, uphours, upminutes, uptime); | 225 | xasprintf(&output_message,_("System Uptime - %u day(s) %u hour(s) %u minute(s) |uptime=%lu"),updays, uphours, upminutes, uptime); |
226 | 226 | ||
227 | if (check_critical_value==TRUE && uptime <= critical_value) | 227 | if (check_critical_value && uptime <= critical_value) |
228 | return_code=STATE_CRITICAL; | 228 | return_code=STATE_CRITICAL; |
229 | else if (check_warning_value==TRUE && uptime <= warning_value) | 229 | else if (check_warning_value && uptime <= warning_value) |
230 | return_code=STATE_WARNING; | 230 | return_code=STATE_WARNING; |
231 | else | 231 | else |
232 | return_code=STATE_OK; | 232 | return_code=STATE_OK; |
@@ -261,9 +261,9 @@ int main(int argc, char **argv){ | |||
261 | (total_disk_space - free_disk_space) / 1073741824, warning_used_space / 1073741824, | 261 | (total_disk_space - free_disk_space) / 1073741824, warning_used_space / 1073741824, |
262 | critical_used_space / 1073741824, total_disk_space / 1073741824); | 262 | critical_used_space / 1073741824, total_disk_space / 1073741824); |
263 | 263 | ||
264 | if(check_critical_value==TRUE && percent_used_space >= critical_value) | 264 | if(check_critical_value && percent_used_space >= critical_value) |
265 | return_code=STATE_CRITICAL; | 265 | return_code=STATE_CRITICAL; |
266 | else if (check_warning_value==TRUE && percent_used_space >= warning_value) | 266 | else if (check_warning_value && percent_used_space >= warning_value) |
267 | return_code=STATE_WARNING; | 267 | return_code=STATE_WARNING; |
268 | else | 268 | else |
269 | return_code=STATE_OK; | 269 | return_code=STATE_OK; |
@@ -285,7 +285,7 @@ int main(int argc, char **argv){ | |||
285 | else { | 285 | else { |
286 | preparelist(value_list); /* replace , between services with & to send the request */ | 286 | preparelist(value_list); /* replace , between services with & to send the request */ |
287 | xasprintf(&send_buffer,"%s&%u&%s&%s", req_password,(vars_to_check==CHECK_SERVICESTATE)?5:6, | 287 | xasprintf(&send_buffer,"%s&%u&%s&%s", req_password,(vars_to_check==CHECK_SERVICESTATE)?5:6, |
288 | (show_all==TRUE) ? "ShowAll" : "ShowFail",value_list); | 288 | (show_all) ? "ShowAll" : "ShowFail",value_list); |
289 | fetch_data (server_address, server_port, send_buffer); | 289 | fetch_data (server_address, server_port, send_buffer); |
290 | numstr = strtok(recv_buffer,"&"); | 290 | numstr = strtok(recv_buffer,"&"); |
291 | if (numstr == NULL) | 291 | if (numstr == NULL) |
@@ -321,9 +321,9 @@ int main(int argc, char **argv){ | |||
321 | warning_used_space / 1048567, critical_used_space / 1048567, mem_commitLimit / 1048567); | 321 | warning_used_space / 1048567, critical_used_space / 1048567, mem_commitLimit / 1048567); |
322 | 322 | ||
323 | return_code=STATE_OK; | 323 | return_code=STATE_OK; |
324 | if(check_critical_value==TRUE && percent_used_space >= critical_value) | 324 | if(check_critical_value && percent_used_space >= critical_value) |
325 | return_code=STATE_CRITICAL; | 325 | return_code=STATE_CRITICAL; |
326 | else if (check_warning_value==TRUE && percent_used_space >= warning_value) | 326 | else if (check_warning_value && percent_used_space >= warning_value) |
327 | return_code=STATE_WARNING; | 327 | return_code=STATE_WARNING; |
328 | 328 | ||
329 | break; | 329 | break; |
@@ -371,7 +371,7 @@ int main(int argc, char **argv){ | |||
371 | else if (isPercent) | 371 | else if (isPercent) |
372 | { | 372 | { |
373 | counter_unit = strdup ("%"); | 373 | counter_unit = strdup ("%"); |
374 | allRight = TRUE; | 374 | allRight = true; |
375 | } | 375 | } |
376 | 376 | ||
377 | if ((counter_unit != NULL) && (!allRight)) | 377 | if ((counter_unit != NULL) && (!allRight)) |
@@ -391,7 +391,7 @@ int main(int argc, char **argv){ | |||
391 | if ((fmaxval == 0) && (maxval == errcvt)) | 391 | if ((fmaxval == 0) && (maxval == errcvt)) |
392 | output_message = strdup (_("Maximum value contains non-numbers")); | 392 | output_message = strdup (_("Maximum value contains non-numbers")); |
393 | else | 393 | else |
394 | allRight = TRUE; /* Everything is OK. */ | 394 | allRight = true; /* Everything is OK. */ |
395 | 395 | ||
396 | } | 396 | } |
397 | } | 397 | } |
@@ -418,9 +418,9 @@ int main(int argc, char **argv){ | |||
418 | 418 | ||
419 | if (critical_value > warning_value) | 419 | if (critical_value > warning_value) |
420 | { /* Normal thresholds */ | 420 | { /* Normal thresholds */ |
421 | if (check_critical_value == TRUE && counter_value >= critical_value) | 421 | if (check_critical_value && counter_value >= critical_value) |
422 | return_code = STATE_CRITICAL; | 422 | return_code = STATE_CRITICAL; |
423 | else if (check_warning_value == TRUE && counter_value >= warning_value) | 423 | else if (check_warning_value && counter_value >= warning_value) |
424 | return_code = STATE_WARNING; | 424 | return_code = STATE_WARNING; |
425 | else | 425 | else |
426 | return_code = STATE_OK; | 426 | return_code = STATE_OK; |
@@ -428,9 +428,9 @@ int main(int argc, char **argv){ | |||
428 | else | 428 | else |
429 | { /* inverse thresholds */ | 429 | { /* inverse thresholds */ |
430 | return_code = STATE_OK; | 430 | return_code = STATE_OK; |
431 | if (check_critical_value == TRUE && counter_value <= critical_value) | 431 | if (check_critical_value && counter_value <= critical_value) |
432 | return_code = STATE_CRITICAL; | 432 | return_code = STATE_CRITICAL; |
433 | else if (check_warning_value == TRUE && counter_value <= warning_value) | 433 | else if (check_warning_value && counter_value <= warning_value) |
434 | return_code = STATE_WARNING; | 434 | return_code = STATE_WARNING; |
435 | } | 435 | } |
436 | break; | 436 | break; |
@@ -448,17 +448,17 @@ int main(int argc, char **argv){ | |||
448 | output_message = strdup (description); | 448 | output_message = strdup (description); |
449 | 449 | ||
450 | if (critical_value > warning_value) { /* Normal thresholds */ | 450 | if (critical_value > warning_value) { /* Normal thresholds */ |
451 | if(check_critical_value==TRUE && age_in_minutes >= critical_value) | 451 | if(check_critical_value && age_in_minutes >= critical_value) |
452 | return_code=STATE_CRITICAL; | 452 | return_code=STATE_CRITICAL; |
453 | else if (check_warning_value==TRUE && age_in_minutes >= warning_value) | 453 | else if (check_warning_value && age_in_minutes >= warning_value) |
454 | return_code=STATE_WARNING; | 454 | return_code=STATE_WARNING; |
455 | else | 455 | else |
456 | return_code=STATE_OK; | 456 | return_code=STATE_OK; |
457 | } | 457 | } |
458 | else { /* inverse thresholds */ | 458 | else { /* inverse thresholds */ |
459 | if(check_critical_value==TRUE && age_in_minutes <= critical_value) | 459 | if(check_critical_value && age_in_minutes <= critical_value) |
460 | return_code=STATE_CRITICAL; | 460 | return_code=STATE_CRITICAL; |
461 | else if (check_warning_value==TRUE && age_in_minutes <= warning_value) | 461 | else if (check_warning_value && age_in_minutes <= warning_value) |
462 | return_code=STATE_WARNING; | 462 | return_code=STATE_WARNING; |
463 | else | 463 | else |
464 | return_code=STATE_OK; | 464 | return_code=STATE_OK; |
@@ -600,15 +600,15 @@ int process_arguments(int argc, char **argv){ | |||
600 | break; | 600 | break; |
601 | case 'w': /* warning threshold */ | 601 | case 'w': /* warning threshold */ |
602 | warning_value=strtoul(optarg,NULL,10); | 602 | warning_value=strtoul(optarg,NULL,10); |
603 | check_warning_value=TRUE; | 603 | check_warning_value=true; |
604 | break; | 604 | break; |
605 | case 'c': /* critical threshold */ | 605 | case 'c': /* critical threshold */ |
606 | critical_value=strtoul(optarg,NULL,10); | 606 | critical_value=strtoul(optarg,NULL,10); |
607 | check_critical_value=TRUE; | 607 | check_critical_value=true; |
608 | break; | 608 | break; |
609 | case 'd': /* Display select for services */ | 609 | case 'd': /* Display select for services */ |
610 | if (!strcmp(optarg,"SHOWALL")) | 610 | if (!strcmp(optarg,"SHOWALL")) |
611 | show_all = TRUE; | 611 | show_all = true; |
612 | break; | 612 | break; |
613 | case 'u': | 613 | case 'u': |
614 | socket_timeout_state=STATE_UNKNOWN; | 614 | socket_timeout_state=STATE_UNKNOWN; |
@@ -646,7 +646,7 @@ void fetch_data (const char *address, int port, const char *sendb) { | |||
646 | die (STATE_UNKNOWN, "NSClient - %s\n",recv_buffer); | 646 | die (STATE_UNKNOWN, "NSClient - %s\n",recv_buffer); |
647 | } | 647 | } |
648 | 648 | ||
649 | int strtoularray(unsigned long *array, char *string, const char *delim) { | 649 | bool strtoularray(unsigned long *array, char *string, const char *delim) { |
650 | /* split a <delim> delimited string into a long array */ | 650 | /* split a <delim> delimited string into a long array */ |
651 | int idx=0; | 651 | int idx=0; |
652 | char *t1; | 652 | char *t1; |
@@ -660,9 +660,9 @@ int strtoularray(unsigned long *array, char *string, const char *delim) { | |||
660 | array[idx]=strtoul(t1,NULL,10); | 660 | array[idx]=strtoul(t1,NULL,10); |
661 | idx++; | 661 | idx++; |
662 | } else | 662 | } else |
663 | return FALSE; | 663 | return false; |
664 | } | 664 | } |
665 | return TRUE; | 665 | return true; |
666 | } | 666 | } |
667 | 667 | ||
668 | void preparelist(char *string) { | 668 | void preparelist(char *string) { |
diff --git a/plugins/check_ntp.c b/plugins/check_ntp.c index 36146505..61b2d699 100644 --- a/plugins/check_ntp.c +++ b/plugins/check_ntp.c | |||
@@ -40,10 +40,10 @@ const char *email = "devel@monitoring-plugins.org"; | |||
40 | 40 | ||
41 | static char *server_address=NULL; | 41 | static char *server_address=NULL; |
42 | static int verbose=0; | 42 | static int verbose=0; |
43 | static short do_offset=0; | 43 | static bool do_offset = false; |
44 | static char *owarn="60"; | 44 | static char *owarn="60"; |
45 | static char *ocrit="120"; | 45 | static char *ocrit="120"; |
46 | static short do_jitter=0; | 46 | static bool do_jitter = false; |
47 | static char *jwarn="5000"; | 47 | static char *jwarn="5000"; |
48 | static char *jcrit="10000"; | 48 | static char *jcrit="10000"; |
49 | 49 | ||
@@ -486,7 +486,7 @@ double offset_request(const char *host, int *status){ | |||
486 | } | 486 | } |
487 | 487 | ||
488 | /* cleanup */ | 488 | /* cleanup */ |
489 | /* FIXME: Not closing the socket to avoid re-use of the local port | 489 | /* FIXME: Not closing the socket to avoid reuse of the local port |
490 | * which can cause old NTP packets to be read instead of NTP control | 490 | * which can cause old NTP packets to be read instead of NTP control |
491 | * packets in jitter_request(). THERE MUST BE ANOTHER WAY... | 491 | * packets in jitter_request(). THERE MUST BE ANOTHER WAY... |
492 | * for(j=0; j<num_hosts; j++){ close(socklist[j]); } */ | 492 | * for(j=0; j<num_hosts; j++){ close(socklist[j]); } */ |
@@ -513,7 +513,8 @@ setup_control_request(ntp_control_message *p, uint8_t opcode, uint16_t seq){ | |||
513 | 513 | ||
514 | /* XXX handle responses with the error bit set */ | 514 | /* XXX handle responses with the error bit set */ |
515 | double jitter_request(int *status){ | 515 | double jitter_request(int *status){ |
516 | int conn=-1, i, npeers=0, num_candidates=0, syncsource_found=0; | 516 | int conn=-1, i, npeers=0, num_candidates=0; |
517 | bool syncsource_found = false; | ||
517 | int run=0, min_peer_sel=PEER_INCLUDED, num_selected=0, num_valid=0; | 518 | int run=0, min_peer_sel=PEER_INCLUDED, num_selected=0, num_valid=0; |
518 | int peers_size=0, peer_offset=0; | 519 | int peers_size=0, peer_offset=0; |
519 | ntp_assoc_status_pair *peers=NULL; | 520 | ntp_assoc_status_pair *peers=NULL; |
@@ -570,7 +571,7 @@ double jitter_request(int *status){ | |||
570 | if (PEER_SEL(peers[i].status) >= PEER_INCLUDED){ | 571 | if (PEER_SEL(peers[i].status) >= PEER_INCLUDED){ |
571 | num_candidates++; | 572 | num_candidates++; |
572 | if(PEER_SEL(peers[i].status) >= PEER_SYNCSOURCE){ | 573 | if(PEER_SEL(peers[i].status) >= PEER_SYNCSOURCE){ |
573 | syncsource_found=1; | 574 | syncsource_found = true; |
574 | min_peer_sel=PEER_SYNCSOURCE; | 575 | min_peer_sel=PEER_SYNCSOURCE; |
575 | } | 576 | } |
576 | } | 577 | } |
@@ -699,23 +700,23 @@ int process_arguments(int argc, char **argv){ | |||
699 | verbose++; | 700 | verbose++; |
700 | break; | 701 | break; |
701 | case 'w': | 702 | case 'w': |
702 | do_offset=1; | 703 | do_offset = true; |
703 | owarn = optarg; | 704 | owarn = optarg; |
704 | break; | 705 | break; |
705 | case 'c': | 706 | case 'c': |
706 | do_offset=1; | 707 | do_offset = true; |
707 | ocrit = optarg; | 708 | ocrit = optarg; |
708 | break; | 709 | break; |
709 | case 'j': | 710 | case 'j': |
710 | do_jitter=1; | 711 | do_jitter = true; |
711 | jwarn = optarg; | 712 | jwarn = optarg; |
712 | break; | 713 | break; |
713 | case 'k': | 714 | case 'k': |
714 | do_jitter=1; | 715 | do_jitter = true; |
715 | jcrit = optarg; | 716 | jcrit = optarg; |
716 | break; | 717 | break; |
717 | case 'H': | 718 | case 'H': |
718 | if(is_host(optarg) == FALSE) | 719 | if(!is_host(optarg)) |
719 | usage2(_("Invalid hostname/address"), optarg); | 720 | usage2(_("Invalid hostname/address"), optarg); |
720 | server_address = strdup(optarg); | 721 | server_address = strdup(optarg); |
721 | break; | 722 | break; |
@@ -749,9 +750,9 @@ int process_arguments(int argc, char **argv){ | |||
749 | char *perfd_offset (double offset) | 750 | char *perfd_offset (double offset) |
750 | { | 751 | { |
751 | return fperfdata ("offset", offset, "s", | 752 | return fperfdata ("offset", offset, "s", |
752 | TRUE, offset_thresholds->warning->end, | 753 | true, offset_thresholds->warning->end, |
753 | TRUE, offset_thresholds->critical->end, | 754 | true, offset_thresholds->critical->end, |
754 | FALSE, 0, FALSE, 0); | 755 | false, 0, false, 0); |
755 | } | 756 | } |
756 | 757 | ||
757 | char *perfd_jitter (double jitter) | 758 | char *perfd_jitter (double jitter) |
@@ -759,7 +760,7 @@ char *perfd_jitter (double jitter) | |||
759 | return fperfdata ("jitter", jitter, "s", | 760 | return fperfdata ("jitter", jitter, "s", |
760 | do_jitter, jitter_thresholds->warning->end, | 761 | do_jitter, jitter_thresholds->warning->end, |
761 | do_jitter, jitter_thresholds->critical->end, | 762 | do_jitter, jitter_thresholds->critical->end, |
762 | TRUE, 0, FALSE, 0); | 763 | true, 0, false, 0); |
763 | } | 764 | } |
764 | 765 | ||
765 | int main(int argc, char *argv[]){ | 766 | int main(int argc, char *argv[]){ |
diff --git a/plugins/check_ntp_peer.c b/plugins/check_ntp_peer.c index 49cb1008..464a9e10 100644 --- a/plugins/check_ntp_peer.c +++ b/plugins/check_ntp_peer.c | |||
@@ -46,21 +46,20 @@ const char *email = "devel@monitoring-plugins.org"; | |||
46 | static char *server_address=NULL; | 46 | static char *server_address=NULL; |
47 | static int port=123; | 47 | static int port=123; |
48 | static int verbose=0; | 48 | static int verbose=0; |
49 | static int quiet=0; | 49 | static bool quiet = false; |
50 | static short do_offset=0; | ||
51 | static char *owarn="60"; | 50 | static char *owarn="60"; |
52 | static char *ocrit="120"; | 51 | static char *ocrit="120"; |
53 | static short do_stratum=0; | 52 | static bool do_stratum = false; |
54 | static char *swarn="-1:16"; | 53 | static char *swarn="-1:16"; |
55 | static char *scrit="-1:16"; | 54 | static char *scrit="-1:16"; |
56 | static short do_jitter=0; | 55 | static bool do_jitter = false; |
57 | static char *jwarn="-1:5000"; | 56 | static char *jwarn="-1:5000"; |
58 | static char *jcrit="-1:10000"; | 57 | static char *jcrit="-1:10000"; |
59 | static short do_truechimers=0; | 58 | static bool do_truechimers = false; |
60 | static char *twarn="0:"; | 59 | static char *twarn="0:"; |
61 | static char *tcrit="0:"; | 60 | static char *tcrit="0:"; |
62 | static int syncsource_found=0; | 61 | static bool syncsource_found = false; |
63 | static int li_alarm=0; | 62 | static bool li_alarm = false; |
64 | 63 | ||
65 | int process_arguments (int, char **); | 64 | int process_arguments (int, char **); |
66 | thresholds *offset_thresholds = NULL; | 65 | thresholds *offset_thresholds = NULL; |
@@ -254,7 +253,7 @@ int ntp_request(double *offset, int *offset_result, double *jitter, int *stratum | |||
254 | die(STATE_CRITICAL, "NTP CRITICAL: Invalid packet received from NTP server\n"); | 253 | die(STATE_CRITICAL, "NTP CRITICAL: Invalid packet received from NTP server\n"); |
255 | } while (!(req.op&OP_READSTAT && ntohs(req.seq) == 1)); | 254 | } while (!(req.op&OP_READSTAT && ntohs(req.seq) == 1)); |
256 | 255 | ||
257 | if (LI(req.flags) == LI_ALARM) li_alarm = 1; | 256 | if (LI(req.flags) == LI_ALARM) li_alarm = true; |
258 | /* Each peer identifier is 4 bytes in the data section, which | 257 | /* Each peer identifier is 4 bytes in the data section, which |
259 | * we represent as a ntp_assoc_status_pair datatype. | 258 | * we represent as a ntp_assoc_status_pair datatype. |
260 | */ | 259 | */ |
@@ -276,7 +275,7 @@ int ntp_request(double *offset, int *offset_result, double *jitter, int *stratum | |||
276 | if(PEER_SEL(peers[i].status) >= PEER_INCLUDED){ | 275 | if(PEER_SEL(peers[i].status) >= PEER_INCLUDED){ |
277 | num_candidates++; | 276 | num_candidates++; |
278 | if(PEER_SEL(peers[i].status) >= PEER_SYNCSOURCE){ | 277 | if(PEER_SEL(peers[i].status) >= PEER_SYNCSOURCE){ |
279 | syncsource_found=1; | 278 | syncsource_found = true; |
280 | min_peer_sel=PEER_SYNCSOURCE; | 279 | min_peer_sel=PEER_SYNCSOURCE; |
281 | } | 280 | } |
282 | } | 281 | } |
@@ -440,7 +439,7 @@ int process_arguments(int argc, char **argv){ | |||
440 | if (argc < 2) | 439 | if (argc < 2) |
441 | usage ("\n"); | 440 | usage ("\n"); |
442 | 441 | ||
443 | while (1) { | 442 | while (true) { |
444 | c = getopt_long (argc, argv, "Vhv46qw:c:W:C:j:k:m:n:t:H:p:", longopts, &option); | 443 | c = getopt_long (argc, argv, "Vhv46qw:c:W:C:j:k:m:n:t:H:p:", longopts, &option); |
445 | if (c == -1 || c == EOF || c == 1) | 444 | if (c == -1 || c == EOF || c == 1) |
446 | break; | 445 | break; |
@@ -458,42 +457,40 @@ int process_arguments(int argc, char **argv){ | |||
458 | verbose++; | 457 | verbose++; |
459 | break; | 458 | break; |
460 | case 'q': | 459 | case 'q': |
461 | quiet = 1; | 460 | quiet = true; |
462 | break; | 461 | break; |
463 | case 'w': | 462 | case 'w': |
464 | do_offset=1; | ||
465 | owarn = optarg; | 463 | owarn = optarg; |
466 | break; | 464 | break; |
467 | case 'c': | 465 | case 'c': |
468 | do_offset=1; | ||
469 | ocrit = optarg; | 466 | ocrit = optarg; |
470 | break; | 467 | break; |
471 | case 'W': | 468 | case 'W': |
472 | do_stratum=1; | 469 | do_stratum = true; |
473 | swarn = optarg; | 470 | swarn = optarg; |
474 | break; | 471 | break; |
475 | case 'C': | 472 | case 'C': |
476 | do_stratum=1; | 473 | do_stratum = true; |
477 | scrit = optarg; | 474 | scrit = optarg; |
478 | break; | 475 | break; |
479 | case 'j': | 476 | case 'j': |
480 | do_jitter=1; | 477 | do_jitter = true; |
481 | jwarn = optarg; | 478 | jwarn = optarg; |
482 | break; | 479 | break; |
483 | case 'k': | 480 | case 'k': |
484 | do_jitter=1; | 481 | do_jitter = true; |
485 | jcrit = optarg; | 482 | jcrit = optarg; |
486 | break; | 483 | break; |
487 | case 'm': | 484 | case 'm': |
488 | do_truechimers=1; | 485 | do_truechimers = true; |
489 | twarn = optarg; | 486 | twarn = optarg; |
490 | break; | 487 | break; |
491 | case 'n': | 488 | case 'n': |
492 | do_truechimers=1; | 489 | do_truechimers = true; |
493 | tcrit = optarg; | 490 | tcrit = optarg; |
494 | break; | 491 | break; |
495 | case 'H': | 492 | case 'H': |
496 | if(is_host(optarg) == FALSE) | 493 | if(!is_host(optarg)) |
497 | usage2(_("Invalid hostname/address"), optarg); | 494 | usage2(_("Invalid hostname/address"), optarg); |
498 | server_address = strdup(optarg); | 495 | server_address = strdup(optarg); |
499 | break; | 496 | break; |
@@ -530,9 +527,9 @@ int process_arguments(int argc, char **argv){ | |||
530 | char *perfd_offset (double offset) | 527 | char *perfd_offset (double offset) |
531 | { | 528 | { |
532 | return fperfdata ("offset", offset, "s", | 529 | return fperfdata ("offset", offset, "s", |
533 | TRUE, offset_thresholds->warning->end, | 530 | true, offset_thresholds->warning->end, |
534 | TRUE, offset_thresholds->critical->end, | 531 | true, offset_thresholds->critical->end, |
535 | FALSE, 0, FALSE, 0); | 532 | false, 0, false, 0); |
536 | } | 533 | } |
537 | 534 | ||
538 | char *perfd_jitter (double jitter) | 535 | char *perfd_jitter (double jitter) |
@@ -540,7 +537,7 @@ char *perfd_jitter (double jitter) | |||
540 | return fperfdata ("jitter", jitter, "", | 537 | return fperfdata ("jitter", jitter, "", |
541 | do_jitter, jitter_thresholds->warning->end, | 538 | do_jitter, jitter_thresholds->warning->end, |
542 | do_jitter, jitter_thresholds->critical->end, | 539 | do_jitter, jitter_thresholds->critical->end, |
543 | TRUE, 0, FALSE, 0); | 540 | true, 0, false, 0); |
544 | } | 541 | } |
545 | 542 | ||
546 | char *perfd_stratum (int stratum) | 543 | char *perfd_stratum (int stratum) |
@@ -548,7 +545,7 @@ char *perfd_stratum (int stratum) | |||
548 | return perfdata ("stratum", stratum, "", | 545 | return perfdata ("stratum", stratum, "", |
549 | do_stratum, (int)stratum_thresholds->warning->end, | 546 | do_stratum, (int)stratum_thresholds->warning->end, |
550 | do_stratum, (int)stratum_thresholds->critical->end, | 547 | do_stratum, (int)stratum_thresholds->critical->end, |
551 | TRUE, 0, TRUE, 16); | 548 | true, 0, true, 16); |
552 | } | 549 | } |
553 | 550 | ||
554 | char *perfd_truechimers (int num_truechimers) | 551 | char *perfd_truechimers (int num_truechimers) |
@@ -556,11 +553,11 @@ char *perfd_truechimers (int num_truechimers) | |||
556 | return perfdata ("truechimers", num_truechimers, "", | 553 | return perfdata ("truechimers", num_truechimers, "", |
557 | do_truechimers, (int)truechimer_thresholds->warning->end, | 554 | do_truechimers, (int)truechimer_thresholds->warning->end, |
558 | do_truechimers, (int)truechimer_thresholds->critical->end, | 555 | do_truechimers, (int)truechimer_thresholds->critical->end, |
559 | TRUE, 0, FALSE, 0); | 556 | true, 0, false, 0); |
560 | } | 557 | } |
561 | 558 | ||
562 | int main(int argc, char *argv[]){ | 559 | int main(int argc, char *argv[]){ |
563 | int result, offset_result, stratum, num_truechimers, oresult, jresult, sresult, tresult; | 560 | int result, offset_result, stratum, num_truechimers; |
564 | double offset=0, jitter=0; | 561 | double offset=0, jitter=0; |
565 | char *result_line, *perfdata_line; | 562 | char *result_line, *perfdata_line; |
566 | 563 | ||
@@ -590,25 +587,35 @@ int main(int argc, char *argv[]){ | |||
590 | 587 | ||
591 | if(offset_result == STATE_UNKNOWN) { | 588 | if(offset_result == STATE_UNKNOWN) { |
592 | /* if there's no sync peer (this overrides ntp_request output): */ | 589 | /* if there's no sync peer (this overrides ntp_request output): */ |
593 | result = (quiet == 1 ? STATE_UNKNOWN : STATE_CRITICAL); | 590 | result = (quiet ? STATE_UNKNOWN : STATE_CRITICAL); |
594 | } else { | 591 | } else { |
595 | /* Be quiet if there's no candidates either */ | 592 | /* Be quiet if there's no candidates either */ |
596 | if (quiet == 1 && result == STATE_WARNING) | 593 | if (quiet && result == STATE_WARNING) |
597 | result = STATE_UNKNOWN; | 594 | result = STATE_UNKNOWN; |
598 | result = max_state_alt(result, get_status(fabs(offset), offset_thresholds)); | 595 | result = max_state_alt(result, get_status(fabs(offset), offset_thresholds)); |
599 | } | 596 | } |
600 | oresult = result; | 597 | |
598 | int oresult = result; | ||
599 | |||
600 | |||
601 | int tresult = STATE_UNKNOWN; | ||
601 | 602 | ||
602 | if(do_truechimers) { | 603 | if(do_truechimers) { |
603 | tresult = get_status(num_truechimers, truechimer_thresholds); | 604 | tresult = get_status(num_truechimers, truechimer_thresholds); |
604 | result = max_state_alt(result, tresult); | 605 | result = max_state_alt(result, tresult); |
605 | } | 606 | } |
606 | 607 | ||
608 | |||
609 | int sresult = STATE_UNKNOWN; | ||
610 | |||
607 | if(do_stratum) { | 611 | if(do_stratum) { |
608 | sresult = get_status(stratum, stratum_thresholds); | 612 | sresult = get_status(stratum, stratum_thresholds); |
609 | result = max_state_alt(result, sresult); | 613 | result = max_state_alt(result, sresult); |
610 | } | 614 | } |
611 | 615 | ||
616 | |||
617 | int jresult = STATE_UNKNOWN; | ||
618 | |||
612 | if(do_jitter) { | 619 | if(do_jitter) { |
613 | jresult = get_status(jitter, jitter_thresholds); | 620 | jresult = get_status(jitter, jitter_thresholds); |
614 | result = max_state_alt(result, jresult); | 621 | result = max_state_alt(result, jresult); |
diff --git a/plugins/check_ntp_time.c b/plugins/check_ntp_time.c index 46cc604f..b2e16556 100644 --- a/plugins/check_ntp_time.c +++ b/plugins/check_ntp_time.c | |||
@@ -45,7 +45,7 @@ const char *email = "devel@monitoring-plugins.org"; | |||
45 | static char *server_address=NULL; | 45 | static char *server_address=NULL; |
46 | static char *port="123"; | 46 | static char *port="123"; |
47 | static int verbose=0; | 47 | static int verbose=0; |
48 | static int quiet=0; | 48 | static bool quiet = false; |
49 | static char *owarn="60"; | 49 | static char *owarn="60"; |
50 | static char *ocrit="120"; | 50 | static char *ocrit="120"; |
51 | static int time_offset=0; | 51 | static int time_offset=0; |
@@ -485,7 +485,7 @@ int process_arguments(int argc, char **argv){ | |||
485 | verbose++; | 485 | verbose++; |
486 | break; | 486 | break; |
487 | case 'q': | 487 | case 'q': |
488 | quiet = 1; | 488 | quiet = true; |
489 | break; | 489 | break; |
490 | case 'w': | 490 | case 'w': |
491 | owarn = optarg; | 491 | owarn = optarg; |
@@ -494,7 +494,7 @@ int process_arguments(int argc, char **argv){ | |||
494 | ocrit = optarg; | 494 | ocrit = optarg; |
495 | break; | 495 | break; |
496 | case 'H': | 496 | case 'H': |
497 | if(is_host(optarg) == FALSE) | 497 | if(!is_host(optarg)) |
498 | usage2(_("Invalid hostname/address"), optarg); | 498 | usage2(_("Invalid hostname/address"), optarg); |
499 | server_address = strdup(optarg); | 499 | server_address = strdup(optarg); |
500 | break; | 500 | break; |
@@ -531,12 +531,11 @@ int process_arguments(int argc, char **argv){ | |||
531 | return 0; | 531 | return 0; |
532 | } | 532 | } |
533 | 533 | ||
534 | char *perfd_offset (double offset) | 534 | char *perfd_offset (double offset) { |
535 | { | ||
536 | return fperfdata ("offset", offset, "s", | 535 | return fperfdata ("offset", offset, "s", |
537 | TRUE, offset_thresholds->warning->end, | 536 | true, offset_thresholds->warning->end, |
538 | TRUE, offset_thresholds->critical->end, | 537 | true, offset_thresholds->critical->end, |
539 | FALSE, 0, FALSE, 0); | 538 | false, 0, false, 0); |
540 | } | 539 | } |
541 | 540 | ||
542 | int main(int argc, char *argv[]){ | 541 | int main(int argc, char *argv[]){ |
@@ -566,7 +565,7 @@ int main(int argc, char *argv[]){ | |||
566 | 565 | ||
567 | offset = offset_request(server_address, &offset_result); | 566 | offset = offset_request(server_address, &offset_result); |
568 | if (offset_result == STATE_UNKNOWN) { | 567 | if (offset_result == STATE_UNKNOWN) { |
569 | result = (quiet == 1 ? STATE_UNKNOWN : STATE_CRITICAL); | 568 | result = ( (!quiet) ? STATE_UNKNOWN : STATE_CRITICAL); |
570 | } else { | 569 | } else { |
571 | result = get_status(fabs(offset), offset_thresholds); | 570 | result = get_status(fabs(offset), offset_thresholds); |
572 | } | 571 | } |
diff --git a/plugins/check_nwstat.c b/plugins/check_nwstat.c index 3c9d23e2..10c493b6 100644 --- a/plugins/check_nwstat.c +++ b/plugins/check_nwstat.c | |||
@@ -46,6 +46,7 @@ enum checkvar { | |||
46 | VPF, /* check % free space on volume */ | 46 | VPF, /* check % free space on volume */ |
47 | VMF, /* check MB free space on volume */ | 47 | VMF, /* check MB free space on volume */ |
48 | VMU, /* check MB used space on volume */ | 48 | VMU, /* check MB used space on volume */ |
49 | VPU, /* check % used space on volume */ | ||
49 | VMP, /* check MB purgeable space on volume */ | 50 | VMP, /* check MB purgeable space on volume */ |
50 | VKF, /* check KB free space on volume */ | 51 | VKF, /* check KB free space on volume */ |
51 | LTCH, /* check long-term cache hit percentage */ | 52 | LTCH, /* check long-term cache hit percentage */ |
@@ -104,9 +105,9 @@ char *nss7_name=NULL; | |||
104 | int server_port=PORT; | 105 | int server_port=PORT; |
105 | unsigned long warning_value=0L; | 106 | unsigned long warning_value=0L; |
106 | unsigned long critical_value=0L; | 107 | unsigned long critical_value=0L; |
107 | int check_warning_value=FALSE; | 108 | bool check_warning_value = false; |
108 | int check_critical_value=FALSE; | 109 | bool check_critical_value = false; |
109 | int check_netware_version=FALSE; | 110 | bool check_netware_version = false; |
110 | enum checkvar vars_to_check = NONE; | 111 | enum checkvar vars_to_check = NONE; |
111 | int sap_number=-1; | 112 | int sap_number=-1; |
112 | 113 | ||
@@ -146,6 +147,8 @@ main(int argc, char **argv) { | |||
146 | unsigned long nss6_value=0L; | 147 | unsigned long nss6_value=0L; |
147 | unsigned long nss7_value=0L; | 148 | unsigned long nss7_value=0L; |
148 | unsigned long total_disk_space=0L; | 149 | unsigned long total_disk_space=0L; |
150 | unsigned long used_disk_space=0L; | ||
151 | unsigned long percent_used_disk_space=0L; | ||
149 | unsigned long purgeable_disk_space=0L; | 152 | unsigned long purgeable_disk_space=0L; |
150 | unsigned long non_purgeable_disk_space=0L; | 153 | unsigned long non_purgeable_disk_space=0L; |
151 | unsigned long percent_free_space=0; | 154 | unsigned long percent_free_space=0; |
@@ -182,7 +185,7 @@ main(int argc, char **argv) { | |||
182 | my_tcp_connect (server_address, server_port, &sd); | 185 | my_tcp_connect (server_address, server_port, &sd); |
183 | 186 | ||
184 | /* get OS version string */ | 187 | /* get OS version string */ |
185 | if (check_netware_version==TRUE) { | 188 | if (check_netware_version) { |
186 | send_buffer = strdup ("S19\r\n"); | 189 | send_buffer = strdup ("S19\r\n"); |
187 | result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer)); | 190 | result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer)); |
188 | if (result!=STATE_OK) | 191 | if (result!=STATE_OK) |
@@ -231,9 +234,9 @@ main(int argc, char **argv) { | |||
231 | recv_buffer[strlen(recv_buffer)-1]=0; | 234 | recv_buffer[strlen(recv_buffer)-1]=0; |
232 | sprintf(uptime,_("Up %s,"),recv_buffer); | 235 | sprintf(uptime,_("Up %s,"),recv_buffer); |
233 | 236 | ||
234 | if (check_critical_value==TRUE && utilization >= critical_value) | 237 | if (check_critical_value && utilization >= critical_value) |
235 | result=STATE_CRITICAL; | 238 | result=STATE_CRITICAL; |
236 | else if (check_warning_value==TRUE && utilization >= warning_value) | 239 | else if (check_warning_value && utilization >= warning_value) |
237 | result=STATE_WARNING; | 240 | result=STATE_WARNING; |
238 | 241 | ||
239 | xasprintf (&output_message, | 242 | xasprintf (&output_message, |
@@ -259,9 +262,9 @@ main(int argc, char **argv) { | |||
259 | return result; | 262 | return result; |
260 | current_connections=strtoul(recv_buffer,NULL,10); | 263 | current_connections=strtoul(recv_buffer,NULL,10); |
261 | 264 | ||
262 | if (check_critical_value==TRUE && current_connections >= critical_value) | 265 | if (check_critical_value && current_connections >= critical_value) |
263 | result=STATE_CRITICAL; | 266 | result=STATE_CRITICAL; |
264 | else if (check_warning_value==TRUE && current_connections >= warning_value) | 267 | else if (check_warning_value && current_connections >= warning_value) |
265 | result=STATE_WARNING; | 268 | result=STATE_WARNING; |
266 | 269 | ||
267 | xasprintf (&output_message, | 270 | xasprintf (&output_message, |
@@ -284,9 +287,9 @@ main(int argc, char **argv) { | |||
284 | return result; | 287 | return result; |
285 | cache_hits=atoi(recv_buffer); | 288 | cache_hits=atoi(recv_buffer); |
286 | 289 | ||
287 | if (check_critical_value==TRUE && cache_hits <= critical_value) | 290 | if (check_critical_value && cache_hits <= critical_value) |
288 | result=STATE_CRITICAL; | 291 | result=STATE_CRITICAL; |
289 | else if (check_warning_value==TRUE && cache_hits <= warning_value) | 292 | else if (check_warning_value && cache_hits <= warning_value) |
290 | result=STATE_WARNING; | 293 | result=STATE_WARNING; |
291 | 294 | ||
292 | xasprintf (&output_message, | 295 | xasprintf (&output_message, |
@@ -306,9 +309,9 @@ main(int argc, char **argv) { | |||
306 | return result; | 309 | return result; |
307 | cache_buffers=strtoul(recv_buffer,NULL,10); | 310 | cache_buffers=strtoul(recv_buffer,NULL,10); |
308 | 311 | ||
309 | if (check_critical_value==TRUE && cache_buffers <= critical_value) | 312 | if (check_critical_value && cache_buffers <= critical_value) |
310 | result=STATE_CRITICAL; | 313 | result=STATE_CRITICAL; |
311 | else if (check_warning_value==TRUE && cache_buffers <= warning_value) | 314 | else if (check_warning_value && cache_buffers <= warning_value) |
312 | result=STATE_WARNING; | 315 | result=STATE_WARNING; |
313 | 316 | ||
314 | xasprintf (&output_message, | 317 | xasprintf (&output_message, |
@@ -331,9 +334,9 @@ main(int argc, char **argv) { | |||
331 | return result; | 334 | return result; |
332 | cache_buffers=strtoul(recv_buffer,NULL,10); | 335 | cache_buffers=strtoul(recv_buffer,NULL,10); |
333 | 336 | ||
334 | if (check_critical_value==TRUE && cache_buffers >= critical_value) | 337 | if (check_critical_value && cache_buffers >= critical_value) |
335 | result=STATE_CRITICAL; | 338 | result=STATE_CRITICAL; |
336 | else if (check_warning_value==TRUE && cache_buffers >= warning_value) | 339 | else if (check_warning_value && cache_buffers >= warning_value) |
337 | result=STATE_WARNING; | 340 | result=STATE_WARNING; |
338 | 341 | ||
339 | xasprintf (&output_message, | 342 | xasprintf (&output_message, |
@@ -356,9 +359,9 @@ main(int argc, char **argv) { | |||
356 | return result; | 359 | return result; |
357 | lru_time=strtoul(recv_buffer,NULL,10); | 360 | lru_time=strtoul(recv_buffer,NULL,10); |
358 | 361 | ||
359 | if (check_critical_value==TRUE && lru_time <= critical_value) | 362 | if (check_critical_value && lru_time <= critical_value) |
360 | result=STATE_CRITICAL; | 363 | result=STATE_CRITICAL; |
361 | else if (check_warning_value==TRUE && lru_time <= warning_value) | 364 | else if (check_warning_value && lru_time <= warning_value) |
362 | result=STATE_WARNING; | 365 | result=STATE_WARNING; |
363 | 366 | ||
364 | xasprintf (&output_message, | 367 | xasprintf (&output_message, |
@@ -383,9 +386,9 @@ main(int argc, char **argv) { | |||
383 | result=STATE_CRITICAL; | 386 | result=STATE_CRITICAL; |
384 | } else { | 387 | } else { |
385 | free_disk_space=strtoul(recv_buffer,NULL,10); | 388 | free_disk_space=strtoul(recv_buffer,NULL,10); |
386 | if (check_critical_value==TRUE && free_disk_space <= critical_value) | 389 | if (check_critical_value && free_disk_space <= critical_value) |
387 | result=STATE_CRITICAL; | 390 | result=STATE_CRITICAL; |
388 | else if (check_warning_value==TRUE && free_disk_space <= warning_value) | 391 | else if (check_warning_value && free_disk_space <= warning_value) |
389 | result=STATE_WARNING; | 392 | result=STATE_WARNING; |
390 | xasprintf (&output_message, | 393 | xasprintf (&output_message, |
391 | _("%s%lu KB free on volume %s|KBFree%s=%lu;%lu;%lu;;"), | 394 | _("%s%lu KB free on volume %s|KBFree%s=%lu;%lu;%lu;;"), |
@@ -411,9 +414,9 @@ main(int argc, char **argv) { | |||
411 | result=STATE_CRITICAL; | 414 | result=STATE_CRITICAL; |
412 | } else { | 415 | } else { |
413 | free_disk_space=strtoul(recv_buffer,NULL,10); | 416 | free_disk_space=strtoul(recv_buffer,NULL,10); |
414 | if (check_critical_value==TRUE && free_disk_space <= critical_value) | 417 | if (check_critical_value && free_disk_space <= critical_value) |
415 | result=STATE_CRITICAL; | 418 | result=STATE_CRITICAL; |
416 | else if (check_warning_value==TRUE && free_disk_space <= warning_value) | 419 | else if (check_warning_value && free_disk_space <= warning_value) |
417 | result=STATE_WARNING; | 420 | result=STATE_WARNING; |
418 | xasprintf (&output_message, | 421 | xasprintf (&output_message, |
419 | _("%s%lu MB free on volume %s|MBFree%s=%lu;%lu;%lu;;"), | 422 | _("%s%lu MB free on volume %s|MBFree%s=%lu;%lu;%lu;;"), |
@@ -438,9 +441,9 @@ main(int argc, char **argv) { | |||
438 | result=STATE_CRITICAL; | 441 | result=STATE_CRITICAL; |
439 | } else { | 442 | } else { |
440 | free_disk_space=strtoul(recv_buffer,NULL,10); | 443 | free_disk_space=strtoul(recv_buffer,NULL,10); |
441 | if (check_critical_value==TRUE && free_disk_space <= critical_value) | 444 | if (check_critical_value && free_disk_space <= critical_value) |
442 | result=STATE_CRITICAL; | 445 | result=STATE_CRITICAL; |
443 | else if (check_warning_value==TRUE && free_disk_space <= warning_value) | 446 | else if (check_warning_value && free_disk_space <= warning_value) |
444 | result=STATE_WARNING; | 447 | result=STATE_WARNING; |
445 | xasprintf (&output_message, | 448 | xasprintf (&output_message, |
446 | _("%s%lu MB used on volume %s|MBUsed%s=%lu;%lu;%lu;;"), | 449 | _("%s%lu MB used on volume %s|MBUsed%s=%lu;%lu;%lu;;"), |
@@ -452,7 +455,50 @@ main(int argc, char **argv) { | |||
452 | warning_value, | 455 | warning_value, |
453 | critical_value); | 456 | critical_value); |
454 | } | 457 | } |
458 | /* check % used space on volume */ | ||
459 | } else if (vars_to_check==VPU) { | ||
460 | close(sd); | ||
461 | my_tcp_connect (server_address, server_port, &sd); | ||
462 | |||
463 | asprintf (&send_buffer,"VMU%s\r\n",volume_name); | ||
464 | result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer)); | ||
465 | |||
466 | if (result!=STATE_OK) | ||
467 | return result; | ||
468 | |||
469 | if (!strcmp(recv_buffer,"-1\n")) { | ||
470 | asprintf (&output_message,_("CRITICAL - Volume '%s' does not exist!"),volume_name); | ||
471 | result=STATE_CRITICAL; | ||
472 | |||
473 | } else { | ||
474 | used_disk_space=strtoul(recv_buffer,NULL,10); | ||
475 | close(sd); | ||
476 | my_tcp_connect (server_address, server_port, &sd); | ||
477 | /* get total volume in MB */ | ||
478 | asprintf (&send_buffer,"VMS%s\r\n",volume_name); | ||
479 | result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer)); | ||
480 | if (result!=STATE_OK) | ||
481 | return result; | ||
482 | total_disk_space=strtoul(recv_buffer,NULL,10); | ||
483 | /* calculate percent used on volume */ | ||
484 | percent_used_disk_space=(unsigned long)(((double)used_disk_space/(double)total_disk_space)*100.0); | ||
455 | 485 | ||
486 | if (check_critical_value && percent_used_disk_space >= critical_value) | ||
487 | result=STATE_CRITICAL; | ||
488 | else if (check_warning_value && percent_used_disk_space >= warning_value) | ||
489 | result=STATE_WARNING; | ||
490 | |||
491 | asprintf (&output_message,_("%lu MB (%lu%%) used on volume %s - total %lu MB|Used space in percent on %s=%lu;%lu;%lu;0;100"), | ||
492 | used_disk_space, | ||
493 | percent_used_disk_space, | ||
494 | volume_name, | ||
495 | total_disk_space, | ||
496 | volume_name, | ||
497 | percent_used_disk_space, | ||
498 | warning_value, | ||
499 | critical_value | ||
500 | ); | ||
501 | } | ||
456 | 502 | ||
457 | /* check % free space on volume */ | 503 | /* check % free space on volume */ |
458 | } else if (vars_to_check==VPF) { | 504 | } else if (vars_to_check==VPF) { |
@@ -485,9 +531,9 @@ main(int argc, char **argv) { | |||
485 | 531 | ||
486 | percent_free_space=(unsigned long)(((double)free_disk_space/(double)total_disk_space)*100.0); | 532 | percent_free_space=(unsigned long)(((double)free_disk_space/(double)total_disk_space)*100.0); |
487 | 533 | ||
488 | if (check_critical_value==TRUE && percent_free_space <= critical_value) | 534 | if (check_critical_value && percent_free_space <= critical_value) |
489 | result=STATE_CRITICAL; | 535 | result=STATE_CRITICAL; |
490 | else if (check_warning_value==TRUE && percent_free_space <= warning_value) | 536 | else if (check_warning_value && percent_free_space <= warning_value) |
491 | result=STATE_WARNING; | 537 | result=STATE_WARNING; |
492 | free_disk_space/=1024; | 538 | free_disk_space/=1024; |
493 | total_disk_space/=1024; | 539 | total_disk_space/=1024; |
@@ -596,14 +642,14 @@ main(int argc, char **argv) { | |||
596 | percent_used_packet_receive_buffers=(unsigned long)(((double)used_packet_receive_buffers/(double)max_packet_receive_buffers)*100.0); | 642 | percent_used_packet_receive_buffers=(unsigned long)(((double)used_packet_receive_buffers/(double)max_packet_receive_buffers)*100.0); |
597 | 643 | ||
598 | if (vars_to_check==UPRB) { | 644 | if (vars_to_check==UPRB) { |
599 | if (check_critical_value==TRUE && used_packet_receive_buffers >= critical_value) | 645 | if (check_critical_value && used_packet_receive_buffers >= critical_value) |
600 | result=STATE_CRITICAL; | 646 | result=STATE_CRITICAL; |
601 | else if (check_warning_value==TRUE && used_packet_receive_buffers >= warning_value) | 647 | else if (check_warning_value && used_packet_receive_buffers >= warning_value) |
602 | result=STATE_WARNING; | 648 | result=STATE_WARNING; |
603 | } else { | 649 | } else { |
604 | if (check_critical_value==TRUE && percent_used_packet_receive_buffers >= critical_value) | 650 | if (check_critical_value && percent_used_packet_receive_buffers >= critical_value) |
605 | result=STATE_CRITICAL; | 651 | result=STATE_CRITICAL; |
606 | else if (check_warning_value==TRUE && percent_used_packet_receive_buffers >= warning_value) | 652 | else if (check_warning_value && percent_used_packet_receive_buffers >= warning_value) |
607 | result=STATE_WARNING; | 653 | result=STATE_WARNING; |
608 | } | 654 | } |
609 | 655 | ||
@@ -625,9 +671,9 @@ main(int argc, char **argv) { | |||
625 | 671 | ||
626 | sap_entries=atoi(recv_buffer); | 672 | sap_entries=atoi(recv_buffer); |
627 | 673 | ||
628 | if (check_critical_value==TRUE && sap_entries >= critical_value) | 674 | if (check_critical_value && sap_entries >= critical_value) |
629 | result=STATE_CRITICAL; | 675 | result=STATE_CRITICAL; |
630 | else if (check_warning_value==TRUE && sap_entries >= warning_value) | 676 | else if (check_warning_value && sap_entries >= warning_value) |
631 | result=STATE_WARNING; | 677 | result=STATE_WARNING; |
632 | 678 | ||
633 | if (sap_number==-1) | 679 | if (sap_number==-1) |
@@ -651,9 +697,9 @@ main(int argc, char **argv) { | |||
651 | result=STATE_CRITICAL; | 697 | result=STATE_CRITICAL; |
652 | } else { | 698 | } else { |
653 | purgeable_disk_space=strtoul(recv_buffer,NULL,10); | 699 | purgeable_disk_space=strtoul(recv_buffer,NULL,10); |
654 | if (check_critical_value==TRUE && purgeable_disk_space >= critical_value) | 700 | if (check_critical_value && purgeable_disk_space >= critical_value) |
655 | result=STATE_CRITICAL; | 701 | result=STATE_CRITICAL; |
656 | else if (check_warning_value==TRUE && purgeable_disk_space >= warning_value) | 702 | else if (check_warning_value && purgeable_disk_space >= warning_value) |
657 | result=STATE_WARNING; | 703 | result=STATE_WARNING; |
658 | xasprintf (&output_message,_("%s%lu KB purgeable on volume %s|Purge%s=%lu;%lu;%lu;;"), | 704 | xasprintf (&output_message,_("%s%lu KB purgeable on volume %s|Purge%s=%lu;%lu;%lu;;"), |
659 | (result==STATE_OK)?"":_("Only "), | 705 | (result==STATE_OK)?"":_("Only "), |
@@ -677,9 +723,9 @@ main(int argc, char **argv) { | |||
677 | result=STATE_CRITICAL; | 723 | result=STATE_CRITICAL; |
678 | } else { | 724 | } else { |
679 | purgeable_disk_space=strtoul(recv_buffer,NULL,10); | 725 | purgeable_disk_space=strtoul(recv_buffer,NULL,10); |
680 | if (check_critical_value==TRUE && purgeable_disk_space >= critical_value) | 726 | if (check_critical_value && purgeable_disk_space >= critical_value) |
681 | result=STATE_CRITICAL; | 727 | result=STATE_CRITICAL; |
682 | else if (check_warning_value==TRUE && purgeable_disk_space >= warning_value) | 728 | else if (check_warning_value && purgeable_disk_space >= warning_value) |
683 | result=STATE_WARNING; | 729 | result=STATE_WARNING; |
684 | xasprintf (&output_message,_("%s%lu MB purgeable on volume %s|Purge%s=%lu;%lu;%lu;;"), | 730 | xasprintf (&output_message,_("%s%lu MB purgeable on volume %s|Purge%s=%lu;%lu;%lu;;"), |
685 | (result==STATE_OK)?"":_("Only "), | 731 | (result==STATE_OK)?"":_("Only "), |
@@ -722,9 +768,9 @@ main(int argc, char **argv) { | |||
722 | 768 | ||
723 | percent_purgeable_space=(unsigned long)(((double)purgeable_disk_space/(double)total_disk_space)*100.0); | 769 | percent_purgeable_space=(unsigned long)(((double)purgeable_disk_space/(double)total_disk_space)*100.0); |
724 | 770 | ||
725 | if (check_critical_value==TRUE && percent_purgeable_space >= critical_value) | 771 | if (check_critical_value && percent_purgeable_space >= critical_value) |
726 | result=STATE_CRITICAL; | 772 | result=STATE_CRITICAL; |
727 | else if (check_warning_value==TRUE && percent_purgeable_space >= warning_value) | 773 | else if (check_warning_value && percent_purgeable_space >= warning_value) |
728 | result=STATE_WARNING; | 774 | result=STATE_WARNING; |
729 | purgeable_disk_space/=1024; | 775 | purgeable_disk_space/=1024; |
730 | xasprintf (&output_message,_("%lu MB (%lu%%) purgeable on volume %s|Purgeable%s=%lu;%lu;%lu;0;100"), | 776 | 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) { | |||
754 | result=STATE_CRITICAL; | 800 | result=STATE_CRITICAL; |
755 | } else { | 801 | } else { |
756 | non_purgeable_disk_space=strtoul(recv_buffer,NULL,10); | 802 | non_purgeable_disk_space=strtoul(recv_buffer,NULL,10); |
757 | if (check_critical_value==TRUE && non_purgeable_disk_space >= critical_value) | 803 | if (check_critical_value && non_purgeable_disk_space >= critical_value) |
758 | result=STATE_CRITICAL; | 804 | result=STATE_CRITICAL; |
759 | else if (check_warning_value==TRUE && non_purgeable_disk_space >= warning_value) | 805 | else if (check_warning_value && non_purgeable_disk_space >= warning_value) |
760 | result=STATE_WARNING; | 806 | result=STATE_WARNING; |
761 | xasprintf (&output_message,_("%s%lu KB not yet purgeable on volume %s"),(result==STATE_OK)?"":_("Only "),non_purgeable_disk_space,volume_name); | 807 | xasprintf (&output_message,_("%s%lu KB not yet purgeable on volume %s"),(result==STATE_OK)?"":_("Only "),non_purgeable_disk_space,volume_name); |
762 | } | 808 | } |
@@ -792,9 +838,9 @@ main(int argc, char **argv) { | |||
792 | 838 | ||
793 | percent_non_purgeable_space=(unsigned long)(((double)non_purgeable_disk_space/(double)total_disk_space)*100.0); | 839 | percent_non_purgeable_space=(unsigned long)(((double)non_purgeable_disk_space/(double)total_disk_space)*100.0); |
794 | 840 | ||
795 | if (check_critical_value==TRUE && percent_non_purgeable_space >= critical_value) | 841 | if (check_critical_value && percent_non_purgeable_space >= critical_value) |
796 | result=STATE_CRITICAL; | 842 | result=STATE_CRITICAL; |
797 | else if (check_warning_value==TRUE && percent_non_purgeable_space >= warning_value) | 843 | else if (check_warning_value && percent_non_purgeable_space >= warning_value) |
798 | result=STATE_WARNING; | 844 | result=STATE_WARNING; |
799 | purgeable_disk_space/=1024; | 845 | purgeable_disk_space/=1024; |
800 | xasprintf (&output_message,_("%lu MB (%lu%%) not yet purgeable on volume %s"),non_purgeable_disk_space,percent_non_purgeable_space,volume_name); | 846 | 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) { | |||
813 | 859 | ||
814 | open_files=atoi(recv_buffer); | 860 | open_files=atoi(recv_buffer); |
815 | 861 | ||
816 | if (check_critical_value==TRUE && open_files >= critical_value) | 862 | if (check_critical_value && open_files >= critical_value) |
817 | result=STATE_CRITICAL; | 863 | result=STATE_CRITICAL; |
818 | else if (check_warning_value==TRUE && open_files >= warning_value) | 864 | else if (check_warning_value && open_files >= warning_value) |
819 | result=STATE_WARNING; | 865 | result=STATE_WARNING; |
820 | 866 | ||
821 | xasprintf (&output_message,_("%lu open files|Openfiles=%lu;%lu;%lu;0,0"), | 867 | xasprintf (&output_message,_("%lu open files|Openfiles=%lu;%lu;%lu;0,0"), |
@@ -838,9 +884,9 @@ main(int argc, char **argv) { | |||
838 | 884 | ||
839 | abended_threads=atoi(recv_buffer); | 885 | abended_threads=atoi(recv_buffer); |
840 | 886 | ||
841 | if (check_critical_value==TRUE && abended_threads >= critical_value) | 887 | if (check_critical_value && abended_threads >= critical_value) |
842 | result=STATE_CRITICAL; | 888 | result=STATE_CRITICAL; |
843 | else if (check_warning_value==TRUE && abended_threads >= warning_value) | 889 | else if (check_warning_value && abended_threads >= warning_value) |
844 | result=STATE_WARNING; | 890 | result=STATE_WARNING; |
845 | 891 | ||
846 | xasprintf (&output_message,_("%lu abended threads|Abends=%lu;%lu;%lu;;"), | 892 | xasprintf (&output_message,_("%lu abended threads|Abends=%lu;%lu;%lu;;"), |
@@ -872,9 +918,9 @@ main(int argc, char **argv) { | |||
872 | 918 | ||
873 | current_service_processes=atoi(recv_buffer); | 919 | current_service_processes=atoi(recv_buffer); |
874 | 920 | ||
875 | if (check_critical_value==TRUE && current_service_processes >= critical_value) | 921 | if (check_critical_value && current_service_processes >= critical_value) |
876 | result=STATE_CRITICAL; | 922 | result=STATE_CRITICAL; |
877 | else if (check_warning_value==TRUE && current_service_processes >= warning_value) | 923 | else if (check_warning_value && current_service_processes >= warning_value) |
878 | result=STATE_WARNING; | 924 | result=STATE_WARNING; |
879 | 925 | ||
880 | xasprintf (&output_message, | 926 | xasprintf (&output_message, |
@@ -923,9 +969,9 @@ main(int argc, char **argv) { | |||
923 | return result; | 969 | return result; |
924 | lru_time=strtoul(recv_buffer,NULL,10); | 970 | lru_time=strtoul(recv_buffer,NULL,10); |
925 | 971 | ||
926 | if (check_critical_value==TRUE && lru_time <= critical_value) | 972 | if (check_critical_value && lru_time <= critical_value) |
927 | result=STATE_CRITICAL; | 973 | result=STATE_CRITICAL; |
928 | else if (check_warning_value==TRUE && lru_time <= warning_value) | 974 | else if (check_warning_value && lru_time <= warning_value) |
929 | result=STATE_WARNING; | 975 | result=STATE_WARNING; |
930 | xasprintf (&output_message,_("LRU sitting time = %lu seconds"),lru_time); | 976 | xasprintf (&output_message,_("LRU sitting time = %lu seconds"),lru_time); |
931 | 977 | ||
@@ -942,9 +988,9 @@ main(int argc, char **argv) { | |||
942 | return result; | 988 | return result; |
943 | dirty_cache_buffers=atoi(recv_buffer); | 989 | dirty_cache_buffers=atoi(recv_buffer); |
944 | 990 | ||
945 | if (check_critical_value==TRUE && dirty_cache_buffers <= critical_value) | 991 | if (check_critical_value && dirty_cache_buffers <= critical_value) |
946 | result=STATE_CRITICAL; | 992 | result=STATE_CRITICAL; |
947 | else if (check_warning_value==TRUE && dirty_cache_buffers <= warning_value) | 993 | else if (check_warning_value && dirty_cache_buffers <= warning_value) |
948 | result=STATE_WARNING; | 994 | result=STATE_WARNING; |
949 | xasprintf (&output_message,_("Dirty cache buffers = %lu%% of the total|DCB=%lu;%lu;%lu;0;100"), | 995 | xasprintf (&output_message,_("Dirty cache buffers = %lu%% of the total|DCB=%lu;%lu;%lu;0;100"), |
950 | dirty_cache_buffers, | 996 | dirty_cache_buffers, |
@@ -964,9 +1010,9 @@ main(int argc, char **argv) { | |||
964 | return result; | 1010 | return result; |
965 | total_cache_buffers=atoi(recv_buffer); | 1011 | total_cache_buffers=atoi(recv_buffer); |
966 | 1012 | ||
967 | if (check_critical_value==TRUE && total_cache_buffers <= critical_value) | 1013 | if (check_critical_value && total_cache_buffers <= critical_value) |
968 | result=STATE_CRITICAL; | 1014 | result=STATE_CRITICAL; |
969 | else if (check_warning_value==TRUE && total_cache_buffers <= warning_value) | 1015 | else if (check_warning_value && total_cache_buffers <= warning_value) |
970 | result=STATE_WARNING; | 1016 | result=STATE_WARNING; |
971 | xasprintf (&output_message,_("Total cache buffers = %lu%% of the original|TCB=%lu;%lu;%lu;0;100"), | 1017 | xasprintf (&output_message,_("Total cache buffers = %lu%% of the original|TCB=%lu;%lu;%lu;0;100"), |
972 | total_cache_buffers, | 1018 | total_cache_buffers, |
@@ -1034,9 +1080,9 @@ main(int argc, char **argv) { | |||
1034 | result=STATE_CRITICAL; | 1080 | result=STATE_CRITICAL; |
1035 | } else { | 1081 | } else { |
1036 | nrmp_value=strtoul(recv_buffer,NULL,10); | 1082 | nrmp_value=strtoul(recv_buffer,NULL,10); |
1037 | if (check_critical_value==TRUE && nrmp_value <= critical_value) | 1083 | if (check_critical_value && nrmp_value <= critical_value) |
1038 | result=STATE_CRITICAL; | 1084 | result=STATE_CRITICAL; |
1039 | else if (check_warning_value==TRUE && nrmp_value <= warning_value) | 1085 | else if (check_warning_value && nrmp_value <= warning_value) |
1040 | result=STATE_WARNING; | 1086 | result=STATE_WARNING; |
1041 | xasprintf (&output_message, | 1087 | xasprintf (&output_message, |
1042 | _("%s is %lu|%s=%lu;%lu;%lu;;"), | 1088 | _("%s is %lu|%s=%lu;%lu;%lu;;"), |
@@ -1060,9 +1106,9 @@ main(int argc, char **argv) { | |||
1060 | result=STATE_CRITICAL; | 1106 | result=STATE_CRITICAL; |
1061 | } else { | 1107 | } else { |
1062 | nrmm_value=strtoul(recv_buffer,NULL,10); | 1108 | nrmm_value=strtoul(recv_buffer,NULL,10); |
1063 | if (check_critical_value==TRUE && nrmm_value <= critical_value) | 1109 | if (check_critical_value && nrmm_value <= critical_value) |
1064 | result=STATE_CRITICAL; | 1110 | result=STATE_CRITICAL; |
1065 | else if (check_warning_value==TRUE && nrmm_value <= warning_value) | 1111 | else if (check_warning_value && nrmm_value <= warning_value) |
1066 | result=STATE_WARNING; | 1112 | result=STATE_WARNING; |
1067 | xasprintf (&output_message, | 1113 | xasprintf (&output_message, |
1068 | _("%s is %lu|%s=%lu;%lu;%lu;;"), | 1114 | _("%s is %lu|%s=%lu;%lu;%lu;;"), |
@@ -1086,9 +1132,9 @@ main(int argc, char **argv) { | |||
1086 | result=STATE_CRITICAL; | 1132 | result=STATE_CRITICAL; |
1087 | } else { | 1133 | } else { |
1088 | nrms_value=strtoul(recv_buffer,NULL,10); | 1134 | nrms_value=strtoul(recv_buffer,NULL,10); |
1089 | if (check_critical_value==TRUE && nrms_value >= critical_value) | 1135 | if (check_critical_value && nrms_value >= critical_value) |
1090 | result=STATE_CRITICAL; | 1136 | result=STATE_CRITICAL; |
1091 | else if (check_warning_value==TRUE && nrms_value >= warning_value) | 1137 | else if (check_warning_value && nrms_value >= warning_value) |
1092 | result=STATE_WARNING; | 1138 | result=STATE_WARNING; |
1093 | xasprintf (&output_message, | 1139 | xasprintf (&output_message, |
1094 | _("%s is %lu|%s=%lu;%lu;%lu;;"), | 1140 | _("%s is %lu|%s=%lu;%lu;%lu;;"), |
@@ -1112,9 +1158,9 @@ main(int argc, char **argv) { | |||
1112 | result=STATE_CRITICAL; | 1158 | result=STATE_CRITICAL; |
1113 | } else { | 1159 | } else { |
1114 | nss1_value=strtoul(recv_buffer,NULL,10); | 1160 | nss1_value=strtoul(recv_buffer,NULL,10); |
1115 | if (check_critical_value==TRUE && nss1_value >= critical_value) | 1161 | if (check_critical_value && nss1_value >= critical_value) |
1116 | result=STATE_CRITICAL; | 1162 | result=STATE_CRITICAL; |
1117 | else if (check_warning_value==TRUE && nss1_value >= warning_value) | 1163 | else if (check_warning_value && nss1_value >= warning_value) |
1118 | result=STATE_WARNING; | 1164 | result=STATE_WARNING; |
1119 | xasprintf (&output_message, | 1165 | xasprintf (&output_message, |
1120 | _("%s is %lu|%s=%lu;%lu;%lu;;"), | 1166 | _("%s is %lu|%s=%lu;%lu;%lu;;"), |
@@ -1138,9 +1184,9 @@ main(int argc, char **argv) { | |||
1138 | result=STATE_CRITICAL; | 1184 | result=STATE_CRITICAL; |
1139 | } else { | 1185 | } else { |
1140 | nss2_value=strtoul(recv_buffer,NULL,10); | 1186 | nss2_value=strtoul(recv_buffer,NULL,10); |
1141 | if (check_critical_value==TRUE && nss2_value >= critical_value) | 1187 | if (check_critical_value && nss2_value >= critical_value) |
1142 | result=STATE_CRITICAL; | 1188 | result=STATE_CRITICAL; |
1143 | else if (check_warning_value==TRUE && nss2_value >= warning_value) | 1189 | else if (check_warning_value && nss2_value >= warning_value) |
1144 | result=STATE_WARNING; | 1190 | result=STATE_WARNING; |
1145 | xasprintf (&output_message, | 1191 | xasprintf (&output_message, |
1146 | _("%s is %lu|%s=%lu;%lu;%lu;;"), | 1192 | _("%s is %lu|%s=%lu;%lu;%lu;;"), |
@@ -1164,9 +1210,9 @@ main(int argc, char **argv) { | |||
1164 | result=STATE_CRITICAL; | 1210 | result=STATE_CRITICAL; |
1165 | } else { | 1211 | } else { |
1166 | nss3_value=strtoul(recv_buffer,NULL,10); | 1212 | nss3_value=strtoul(recv_buffer,NULL,10); |
1167 | if (check_critical_value==TRUE && nss3_value >= critical_value) | 1213 | if (check_critical_value && nss3_value >= critical_value) |
1168 | result=STATE_CRITICAL; | 1214 | result=STATE_CRITICAL; |
1169 | else if (check_warning_value==TRUE && nss3_value >= warning_value) | 1215 | else if (check_warning_value && nss3_value >= warning_value) |
1170 | result=STATE_WARNING; | 1216 | result=STATE_WARNING; |
1171 | xasprintf (&output_message, | 1217 | xasprintf (&output_message, |
1172 | _("%s is %lu|%s=%lu;%lu;%lu;;"), | 1218 | _("%s is %lu|%s=%lu;%lu;%lu;;"), |
@@ -1190,9 +1236,9 @@ main(int argc, char **argv) { | |||
1190 | result=STATE_CRITICAL; | 1236 | result=STATE_CRITICAL; |
1191 | } else { | 1237 | } else { |
1192 | nss4_value=strtoul(recv_buffer,NULL,10); | 1238 | nss4_value=strtoul(recv_buffer,NULL,10); |
1193 | if (check_critical_value==TRUE && nss4_value >= critical_value) | 1239 | if (check_critical_value && nss4_value >= critical_value) |
1194 | result=STATE_CRITICAL; | 1240 | result=STATE_CRITICAL; |
1195 | else if (check_warning_value==TRUE && nss4_value >= warning_value) | 1241 | else if (check_warning_value && nss4_value >= warning_value) |
1196 | result=STATE_WARNING; | 1242 | result=STATE_WARNING; |
1197 | xasprintf (&output_message, | 1243 | xasprintf (&output_message, |
1198 | _("%s is %lu|%s=%lu;%lu;%lu;;"), | 1244 | _("%s is %lu|%s=%lu;%lu;%lu;;"), |
@@ -1216,9 +1262,9 @@ main(int argc, char **argv) { | |||
1216 | result=STATE_CRITICAL; | 1262 | result=STATE_CRITICAL; |
1217 | } else { | 1263 | } else { |
1218 | nss5_value=strtoul(recv_buffer,NULL,10); | 1264 | nss5_value=strtoul(recv_buffer,NULL,10); |
1219 | if (check_critical_value==TRUE && nss5_value >= critical_value) | 1265 | if (check_critical_value && nss5_value >= critical_value) |
1220 | result=STATE_CRITICAL; | 1266 | result=STATE_CRITICAL; |
1221 | else if (check_warning_value==TRUE && nss5_value >= warning_value) | 1267 | else if (check_warning_value && nss5_value >= warning_value) |
1222 | result=STATE_WARNING; | 1268 | result=STATE_WARNING; |
1223 | xasprintf (&output_message, | 1269 | xasprintf (&output_message, |
1224 | _("%s is %lu|%s=%lu;%lu;%lu;;"), | 1270 | _("%s is %lu|%s=%lu;%lu;%lu;;"), |
@@ -1242,9 +1288,9 @@ main(int argc, char **argv) { | |||
1242 | result=STATE_CRITICAL; | 1288 | result=STATE_CRITICAL; |
1243 | } else { | 1289 | } else { |
1244 | nss6_value=strtoul(recv_buffer,NULL,10); | 1290 | nss6_value=strtoul(recv_buffer,NULL,10); |
1245 | if (check_critical_value==TRUE && nss6_value >= critical_value) | 1291 | if (check_critical_value && nss6_value >= critical_value) |
1246 | result=STATE_CRITICAL; | 1292 | result=STATE_CRITICAL; |
1247 | else if (check_warning_value==TRUE && nss6_value >= warning_value) | 1293 | else if (check_warning_value && nss6_value >= warning_value) |
1248 | result=STATE_WARNING; | 1294 | result=STATE_WARNING; |
1249 | xasprintf (&output_message, | 1295 | xasprintf (&output_message, |
1250 | _("%s is %lu|%s=%lu;%lu;%lu;;"), | 1296 | _("%s is %lu|%s=%lu;%lu;%lu;;"), |
@@ -1268,9 +1314,9 @@ main(int argc, char **argv) { | |||
1268 | result=STATE_CRITICAL; | 1314 | result=STATE_CRITICAL; |
1269 | } else { | 1315 | } else { |
1270 | nss7_value=strtoul(recv_buffer,NULL,10); | 1316 | nss7_value=strtoul(recv_buffer,NULL,10); |
1271 | if (check_critical_value==TRUE && nss7_value >= critical_value) | 1317 | if (check_critical_value && nss7_value >= critical_value) |
1272 | result=STATE_CRITICAL; | 1318 | result=STATE_CRITICAL; |
1273 | else if (check_warning_value==TRUE && nss7_value >= warning_value) | 1319 | else if (check_warning_value && nss7_value >= warning_value) |
1274 | result=STATE_WARNING; | 1320 | result=STATE_WARNING; |
1275 | xasprintf (&output_message, | 1321 | xasprintf (&output_message, |
1276 | _("%s is %lu|%s=%lu;%lu;%lu;;"), | 1322 | _("%s is %lu|%s=%lu;%lu;%lu;;"), |
@@ -1362,7 +1408,7 @@ int process_arguments(int argc, char **argv) { | |||
1362 | server_address=optarg; | 1408 | server_address=optarg; |
1363 | break; | 1409 | break; |
1364 | case 'o': /* display nos version */ | 1410 | case 'o': /* display nos version */ |
1365 | check_netware_version=TRUE; | 1411 | check_netware_version = true; |
1366 | break; | 1412 | break; |
1367 | case 'p': /* port */ | 1413 | case 'p': /* port */ |
1368 | if (is_intnonneg(optarg)) | 1414 | if (is_intnonneg(optarg)) |
@@ -1450,6 +1496,12 @@ int process_arguments(int argc, char **argv) { | |||
1450 | if (!strcmp(volume_name,"")) | 1496 | if (!strcmp(volume_name,"")) |
1451 | volume_name = strdup ("SYS"); | 1497 | volume_name = strdup ("SYS"); |
1452 | } | 1498 | } |
1499 | else if (strncmp(optarg,"VPU",3)==0) { | ||
1500 | vars_to_check=VPU; | ||
1501 | volume_name = strdup (optarg+3); | ||
1502 | if (!strcmp(volume_name,"")) | ||
1503 | volume_name = strdup ("SYS"); | ||
1504 | } | ||
1453 | else if (strncmp(optarg,"VPP",3)==0) { | 1505 | else if (strncmp(optarg,"VPP",3)==0) { |
1454 | vars_to_check=VPP; | 1506 | vars_to_check=VPP; |
1455 | volume_name = strdup (optarg+3); | 1507 | volume_name = strdup (optarg+3); |
@@ -1569,11 +1621,11 @@ int process_arguments(int argc, char **argv) { | |||
1569 | break; | 1621 | break; |
1570 | case 'w': /* warning threshold */ | 1622 | case 'w': /* warning threshold */ |
1571 | warning_value=strtoul(optarg,NULL,10); | 1623 | warning_value=strtoul(optarg,NULL,10); |
1572 | check_warning_value=TRUE; | 1624 | check_warning_value = true; |
1573 | break; | 1625 | break; |
1574 | case 'c': /* critical threshold */ | 1626 | case 'c': /* critical threshold */ |
1575 | critical_value=strtoul(optarg,NULL,10); | 1627 | critical_value=strtoul(optarg,NULL,10); |
1576 | check_critical_value=TRUE; | 1628 | check_critical_value = true; |
1577 | break; | 1629 | break; |
1578 | case 't': /* timeout */ | 1630 | case 't': /* timeout */ |
1579 | socket_timeout=atoi(optarg); | 1631 | socket_timeout=atoi(optarg); |
@@ -1626,6 +1678,7 @@ void print_help(void) | |||
1626 | printf (" %s\n", _("OFILES = number of open files")); | 1678 | printf (" %s\n", _("OFILES = number of open files")); |
1627 | printf (" %s\n", _(" VMF<vol> = MB of free space on Volume <vol>")); | 1679 | printf (" %s\n", _(" VMF<vol> = MB of free space on Volume <vol>")); |
1628 | printf (" %s\n", _(" VMU<vol> = MB used space on Volume <vol>")); | 1680 | printf (" %s\n", _(" VMU<vol> = MB used space on Volume <vol>")); |
1681 | printf (" %s\n", _(" VPU<vol> = percent used space on Volume <vol>")); | ||
1629 | printf (" %s\n", _(" VMP<vol> = MB of purgeable space on Volume <vol>")); | 1682 | printf (" %s\n", _(" VMP<vol> = MB of purgeable space on Volume <vol>")); |
1630 | printf (" %s\n", _(" VPF<vol> = percent free space on volume <vol>")); | 1683 | printf (" %s\n", _(" VPF<vol> = percent free space on volume <vol>")); |
1631 | printf (" %s\n", _(" VKF<vol> = KB of free space on volume <vol>")); | 1684 | printf (" %s\n", _(" VKF<vol> = KB of free space on volume <vol>")); |
diff --git a/plugins/check_overcr.c b/plugins/check_overcr.c index 9a4d25fa..5165c828 100644 --- a/plugins/check_overcr.c +++ b/plugins/check_overcr.c | |||
@@ -56,15 +56,15 @@ char *server_address = NULL; | |||
56 | int server_port = PORT; | 56 | int server_port = PORT; |
57 | double warning_value = 0L; | 57 | double warning_value = 0L; |
58 | double critical_value = 0L; | 58 | double critical_value = 0L; |
59 | int check_warning_value = FALSE; | 59 | bool check_warning_value = false; |
60 | int check_critical_value = FALSE; | 60 | bool check_critical_value = false; |
61 | enum checkvar vars_to_check = NONE; | 61 | enum checkvar vars_to_check = NONE; |
62 | int cmd_timeout = 1; | 62 | int cmd_timeout = 1; |
63 | 63 | ||
64 | int netstat_port = 0; | 64 | int netstat_port = 0; |
65 | char *disk_name = NULL; | 65 | char *disk_name = NULL; |
66 | char *process_name = NULL; | 66 | char *process_name = NULL; |
67 | char send_buffer[MAX_INPUT_BUFFER]; | 67 | char send_buffer[MAX_INPUT_BUFFER]; |
68 | 68 | ||
69 | int process_arguments (int, char **); | 69 | int process_arguments (int, char **); |
70 | void print_usage (void); | 70 | void print_usage (void); |
@@ -77,7 +77,7 @@ main (int argc, char **argv) | |||
77 | char recv_buffer[MAX_INPUT_BUFFER]; | 77 | char recv_buffer[MAX_INPUT_BUFFER]; |
78 | char temp_buffer[MAX_INPUT_BUFFER]; | 78 | char temp_buffer[MAX_INPUT_BUFFER]; |
79 | char *temp_ptr = NULL; | 79 | char *temp_ptr = NULL; |
80 | int found_disk = FALSE; | 80 | bool found_disk = false; |
81 | unsigned long percent_used_disk_space = 100; | 81 | unsigned long percent_used_disk_space = 100; |
82 | double load; | 82 | double load; |
83 | double load_1min; | 83 | double load_1min; |
@@ -155,9 +155,9 @@ main (int argc, char **argv) | |||
155 | break; | 155 | break; |
156 | } | 156 | } |
157 | 157 | ||
158 | if (check_critical_value == TRUE && (load >= critical_value)) | 158 | if (check_critical_value && (load >= critical_value)) |
159 | result = STATE_CRITICAL; | 159 | result = STATE_CRITICAL; |
160 | else if (check_warning_value == TRUE && (load >= warning_value)) | 160 | else if (check_warning_value && (load >= warning_value)) |
161 | result = STATE_WARNING; | 161 | result = STATE_WARNING; |
162 | 162 | ||
163 | die (result, | 163 | die (result, |
@@ -178,7 +178,7 @@ main (int argc, char **argv) | |||
178 | temp_ptr = (char *) strtok (NULL, " ")) { | 178 | temp_ptr = (char *) strtok (NULL, " ")) { |
179 | 179 | ||
180 | if (!strcmp (temp_ptr, disk_name)) { | 180 | if (!strcmp (temp_ptr, disk_name)) { |
181 | found_disk = TRUE; | 181 | found_disk = true; |
182 | temp_ptr = (char *) strtok (NULL, "%"); | 182 | temp_ptr = (char *) strtok (NULL, "%"); |
183 | if (temp_ptr == NULL) | 183 | if (temp_ptr == NULL) |
184 | die (STATE_CRITICAL, _("Invalid response from server\n")); | 184 | die (STATE_CRITICAL, _("Invalid response from server\n")); |
@@ -191,14 +191,14 @@ main (int argc, char **argv) | |||
191 | } | 191 | } |
192 | 192 | ||
193 | /* error if we couldn't find the info for the disk */ | 193 | /* error if we couldn't find the info for the disk */ |
194 | if (found_disk == FALSE) | 194 | if (!found_disk) |
195 | die (STATE_CRITICAL, | 195 | die (STATE_CRITICAL, |
196 | "CRITICAL - Disk '%s' non-existent or not mounted", | 196 | "CRITICAL - Disk '%s' non-existent or not mounted", |
197 | disk_name); | 197 | disk_name); |
198 | 198 | ||
199 | if (check_critical_value == TRUE && (percent_used_disk_space >= critical_value)) | 199 | if (check_critical_value && (percent_used_disk_space >= critical_value)) |
200 | result = STATE_CRITICAL; | 200 | result = STATE_CRITICAL; |
201 | else if (check_warning_value == TRUE && (percent_used_disk_space >= warning_value)) | 201 | else if (check_warning_value && (percent_used_disk_space >= warning_value)) |
202 | result = STATE_WARNING; | 202 | result = STATE_WARNING; |
203 | 203 | ||
204 | die (result, "Disk %s - %lu%% used on %s", state_text(result), percent_used_disk_space, disk_name); | 204 | 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) | |||
212 | else | 212 | else |
213 | port_connections = strtod (recv_buffer, NULL); | 213 | port_connections = strtod (recv_buffer, NULL); |
214 | 214 | ||
215 | if (check_critical_value == TRUE && (port_connections >= critical_value)) | 215 | if (check_critical_value && (port_connections >= critical_value)) |
216 | result = STATE_CRITICAL; | 216 | result = STATE_CRITICAL; |
217 | else if (check_warning_value == TRUE && (port_connections >= warning_value)) | 217 | else if (check_warning_value && (port_connections >= warning_value)) |
218 | result = STATE_WARNING; | 218 | result = STATE_WARNING; |
219 | 219 | ||
220 | die (result, | 220 | die (result, |
@@ -241,9 +241,9 @@ main (int argc, char **argv) | |||
241 | else | 241 | else |
242 | processes = strtod (temp_ptr, NULL); | 242 | processes = strtod (temp_ptr, NULL); |
243 | 243 | ||
244 | if (check_critical_value == TRUE && (processes >= critical_value)) | 244 | if (check_critical_value && (processes >= critical_value)) |
245 | result = STATE_CRITICAL; | 245 | result = STATE_CRITICAL; |
246 | else if (check_warning_value == TRUE && (processes >= warning_value)) | 246 | else if (check_warning_value && (processes >= warning_value)) |
247 | result = STATE_WARNING; | 247 | result = STATE_WARNING; |
248 | 248 | ||
249 | die (result, | 249 | die (result, |
@@ -262,9 +262,9 @@ main (int argc, char **argv) | |||
262 | uptime_raw_hours = strtod (recv_buffer, NULL); | 262 | uptime_raw_hours = strtod (recv_buffer, NULL); |
263 | uptime_raw_minutes = (unsigned long) (uptime_raw_hours * 60.0); | 263 | uptime_raw_minutes = (unsigned long) (uptime_raw_hours * 60.0); |
264 | 264 | ||
265 | if (check_critical_value == TRUE && (uptime_raw_minutes <= critical_value)) | 265 | if (check_critical_value && (uptime_raw_minutes <= critical_value)) |
266 | result = STATE_CRITICAL; | 266 | result = STATE_CRITICAL; |
267 | else if (check_warning_value == TRUE && (uptime_raw_minutes <= warning_value)) | 267 | else if (check_warning_value && (uptime_raw_minutes <= warning_value)) |
268 | result = STATE_WARNING; | 268 | result = STATE_WARNING; |
269 | 269 | ||
270 | uptime_days = uptime_raw_minutes / 1440; | 270 | uptime_days = uptime_raw_minutes / 1440; |
@@ -388,11 +388,11 @@ process_arguments (int argc, char **argv) | |||
388 | break; | 388 | break; |
389 | case 'w': /* warning threshold */ | 389 | case 'w': /* warning threshold */ |
390 | warning_value = strtoul (optarg, NULL, 10); | 390 | warning_value = strtoul (optarg, NULL, 10); |
391 | check_warning_value = TRUE; | 391 | check_warning_value = true; |
392 | break; | 392 | break; |
393 | case 'c': /* critical threshold */ | 393 | case 'c': /* critical threshold */ |
394 | critical_value = strtoul (optarg, NULL, 10); | 394 | critical_value = strtoul (optarg, NULL, 10); |
395 | check_critical_value = TRUE; | 395 | check_critical_value = true; |
396 | break; | 396 | break; |
397 | case 't': /* timeout */ | 397 | case 't': /* timeout */ |
398 | socket_timeout = atoi (optarg); | 398 | socket_timeout = atoi (optarg); |
diff --git a/plugins/check_pgsql.c b/plugins/check_pgsql.c index 61990335..94d589e1 100644 --- a/plugins/check_pgsql.c +++ b/plugins/check_pgsql.c | |||
@@ -69,7 +69,7 @@ int process_arguments (int, char **); | |||
69 | int validate_arguments (void); | 69 | int validate_arguments (void); |
70 | void print_usage (void); | 70 | void print_usage (void); |
71 | void print_help (void); | 71 | void print_help (void); |
72 | int is_pg_logname (char *); | 72 | bool is_pg_logname (char *); |
73 | int do_query (PGconn *, char *); | 73 | int do_query (PGconn *, char *); |
74 | 74 | ||
75 | char *pghost = NULL; /* host name of the backend server */ | 75 | char *pghost = NULL; /* host name of the backend server */ |
@@ -252,7 +252,7 @@ main (int argc, char **argv) | |||
252 | printf (_(" %s - database %s (%f sec.)|%s\n"), | 252 | printf (_(" %s - database %s (%f sec.)|%s\n"), |
253 | state_text(status), dbName, elapsed_time, | 253 | state_text(status), dbName, elapsed_time, |
254 | fperfdata("time", elapsed_time, "s", | 254 | fperfdata("time", elapsed_time, "s", |
255 | !!(twarn > 0.0), twarn, !!(tcrit > 0.0), tcrit, TRUE, 0, FALSE,0)); | 255 | !!(twarn > 0.0), twarn, !!(tcrit > 0.0), tcrit, true, 0, false,0)); |
256 | 256 | ||
257 | if (pgquery) | 257 | if (pgquery) |
258 | query_status = do_query (conn, pgquery); | 258 | query_status = do_query (conn, pgquery); |
@@ -393,7 +393,7 @@ process_arguments (int argc, char **argv) | |||
393 | 393 | ||
394 | <para>&PROTO_validate_arguments;</para> | 394 | <para>&PROTO_validate_arguments;</para> |
395 | 395 | ||
396 | <para>Given a database name, this function returns TRUE if the string | 396 | <para>Given a database name, this function returns true if the string |
397 | is a valid PostgreSQL database name, and returns false if it is | 397 | is a valid PostgreSQL database name, and returns false if it is |
398 | not.</para> | 398 | not.</para> |
399 | 399 | ||
@@ -424,7 +424,7 @@ function prototype | |||
424 | 424 | ||
425 | <para>&PROTO_is_pg_logname;</para> | 425 | <para>&PROTO_is_pg_logname;</para> |
426 | 426 | ||
427 | <para>Given a username, this function returns TRUE if the string is a | 427 | <para>Given a username, this function returns true if the string is a |
428 | valid PostgreSQL username, and returns false if it is not. Valid PostgreSQL | 428 | valid PostgreSQL username, and returns false if it is not. Valid PostgreSQL |
429 | usernames are less than &NAMEDATALEN; characters long and consist of | 429 | usernames are less than &NAMEDATALEN; characters long and consist of |
430 | letters, numbers, dashes, and underscores, plus possibly some other | 430 | letters, numbers, dashes, and underscores, plus possibly some other |
@@ -439,12 +439,10 @@ should be added.</para> | |||
439 | 439 | ||
440 | 440 | ||
441 | 441 | ||
442 | int | 442 | bool is_pg_logname (char *username) { |
443 | is_pg_logname (char *username) | ||
444 | { | ||
445 | if (strlen (username) > NAMEDATALEN - 1) | 443 | if (strlen (username) > NAMEDATALEN - 1) |
446 | return (FALSE); | 444 | return (false); |
447 | return (TRUE); | 445 | return (true); |
448 | } | 446 | } |
449 | 447 | ||
450 | /****************************************************************************** | 448 | /****************************************************************************** |
diff --git a/plugins/check_ping.c b/plugins/check_ping.c index 741f732e..6e162e6a 100644 --- a/plugins/check_ping.c +++ b/plugins/check_ping.c | |||
@@ -55,7 +55,7 @@ int error_scan (char buf[MAX_INPUT_BUFFER], const char *addr); | |||
55 | void print_usage (void); | 55 | void print_usage (void); |
56 | void print_help (void); | 56 | void print_help (void); |
57 | 57 | ||
58 | int display_html = FALSE; | 58 | bool display_html = false; |
59 | int wpl = UNKNOWN_PACKET_LOSS; | 59 | int wpl = UNKNOWN_PACKET_LOSS; |
60 | int cpl = UNKNOWN_PACKET_LOSS; | 60 | int cpl = UNKNOWN_PACKET_LOSS; |
61 | float wrta = UNKNOWN_TRIP_TIME; | 61 | float wrta = UNKNOWN_TRIP_TIME; |
@@ -153,7 +153,7 @@ main (int argc, char **argv) | |||
153 | if (n_addresses > 1 && this_result != STATE_UNKNOWN) | 153 | if (n_addresses > 1 && this_result != STATE_UNKNOWN) |
154 | die (STATE_OK, "%s is alive\n", addresses[i]); | 154 | die (STATE_OK, "%s is alive\n", addresses[i]); |
155 | 155 | ||
156 | if (display_html == TRUE) | 156 | if (display_html == true) |
157 | printf ("<A HREF='%s/traceroute.cgi?%s'>", CGIURL, addresses[i]); | 157 | printf ("<A HREF='%s/traceroute.cgi?%s'>", CGIURL, addresses[i]); |
158 | if (pl == 100) | 158 | if (pl == 100) |
159 | printf (_("PING %s - %sPacket loss = %d%%"), state_text (this_result), warn_text, | 159 | printf (_("PING %s - %sPacket loss = %d%%"), state_text (this_result), warn_text, |
@@ -161,22 +161,22 @@ main (int argc, char **argv) | |||
161 | else | 161 | else |
162 | printf (_("PING %s - %sPacket loss = %d%%, RTA = %2.2f ms"), | 162 | printf (_("PING %s - %sPacket loss = %d%%, RTA = %2.2f ms"), |
163 | state_text (this_result), warn_text, pl, rta); | 163 | state_text (this_result), warn_text, pl, rta); |
164 | if (display_html == TRUE) | 164 | if (display_html == true) |
165 | printf ("</A>"); | 165 | printf ("</A>"); |
166 | 166 | ||
167 | /* Print performance data */ | 167 | /* Print performance data */ |
168 | if (pl != 100) { | 168 | if (pl != 100) { |
169 | printf("|%s", fperfdata ("rta", (double) rta, "ms", | 169 | printf("|%s", fperfdata ("rta", (double) rta, "ms", |
170 | wrta>0?TRUE:FALSE, wrta, | 170 | wrta>0?true:false, wrta, |
171 | crta>0?TRUE:FALSE, crta, | 171 | crta>0?true:false, crta, |
172 | TRUE, 0, FALSE, 0)); | 172 | true, 0, false, 0)); |
173 | } else { | 173 | } else { |
174 | printf("| rta=U;%f;%f;;", wrta, crta); | 174 | printf("| rta=U;%f;%f;;", wrta, crta); |
175 | } | 175 | } |
176 | printf(" %s\n", perfdata ("pl", (long) pl, "%", | 176 | printf(" %s\n", perfdata ("pl", (long) pl, "%", |
177 | wpl>0?TRUE:FALSE, wpl, | 177 | wpl>0?true:false, wpl, |
178 | cpl>0?TRUE:FALSE, cpl, | 178 | cpl>0?true:false, cpl, |
179 | TRUE, 0, FALSE, 0)); | 179 | true, 0, false, 0)); |
180 | 180 | ||
181 | if (verbose >= 2) | 181 | if (verbose >= 2) |
182 | printf ("%f:%d%% %f:%d%%\n", wrta, wpl, crta, cpl); | 182 | printf ("%f:%d%% %f:%d%%\n", wrta, wpl, crta, cpl); |
@@ -278,10 +278,10 @@ process_arguments (int argc, char **argv) | |||
278 | usage2 (_("<max_packets> (%s) must be a non-negative number\n"), optarg); | 278 | usage2 (_("<max_packets> (%s) must be a non-negative number\n"), optarg); |
279 | break; | 279 | break; |
280 | case 'n': /* no HTML */ | 280 | case 'n': /* no HTML */ |
281 | display_html = FALSE; | 281 | display_html = false; |
282 | break; | 282 | break; |
283 | case 'L': /* show HTML */ | 283 | case 'L': /* show HTML */ |
284 | display_html = TRUE; | 284 | display_html = true; |
285 | break; | 285 | break; |
286 | case 'c': | 286 | case 'c': |
287 | get_threshold (optarg, &crta, &cpl); | 287 | get_threshold (optarg, &crta, &cpl); |
@@ -297,7 +297,7 @@ process_arguments (int argc, char **argv) | |||
297 | return validate_arguments (); | 297 | return validate_arguments (); |
298 | 298 | ||
299 | if (addresses[0] == NULL) { | 299 | if (addresses[0] == NULL) { |
300 | if (is_host (argv[c]) == FALSE) { | 300 | if (!is_host (argv[c])) { |
301 | usage2 (_("Invalid hostname/address"), argv[c]); | 301 | usage2 (_("Invalid hostname/address"), argv[c]); |
302 | } else { | 302 | } else { |
303 | addresses[0] = argv[c++]; | 303 | addresses[0] = argv[c++]; |
@@ -308,7 +308,7 @@ process_arguments (int argc, char **argv) | |||
308 | } | 308 | } |
309 | 309 | ||
310 | if (wpl == UNKNOWN_PACKET_LOSS) { | 310 | if (wpl == UNKNOWN_PACKET_LOSS) { |
311 | if (is_intpercent (argv[c]) == FALSE) { | 311 | if (!is_intpercent (argv[c])) { |
312 | printf (_("<wpl> (%s) must be an integer percentage\n"), argv[c]); | 312 | printf (_("<wpl> (%s) must be an integer percentage\n"), argv[c]); |
313 | return ERROR; | 313 | return ERROR; |
314 | } else { | 314 | } else { |
@@ -319,7 +319,7 @@ process_arguments (int argc, char **argv) | |||
319 | } | 319 | } |
320 | 320 | ||
321 | if (cpl == UNKNOWN_PACKET_LOSS) { | 321 | if (cpl == UNKNOWN_PACKET_LOSS) { |
322 | if (is_intpercent (argv[c]) == FALSE) { | 322 | if (!is_intpercent (argv[c])) { |
323 | printf (_("<cpl> (%s) must be an integer percentage\n"), argv[c]); | 323 | printf (_("<cpl> (%s) must be an integer percentage\n"), argv[c]); |
324 | return ERROR; | 324 | return ERROR; |
325 | } else { | 325 | } else { |
@@ -420,7 +420,7 @@ validate_arguments () | |||
420 | timeout_interval = (int)max_seconds; | 420 | timeout_interval = (int)max_seconds; |
421 | 421 | ||
422 | for (i=0; i<n_addresses; i++) { | 422 | for (i=0; i<n_addresses; i++) { |
423 | if (is_host(addresses[i]) == FALSE) | 423 | if (!is_host(addresses[i])) |
424 | usage2 (_("Invalid hostname/address"), addresses[i]); | 424 | usage2 (_("Invalid hostname/address"), addresses[i]); |
425 | } | 425 | } |
426 | 426 | ||
diff --git a/plugins/check_procs.c b/plugins/check_procs.c index c17c6996..1fcbd981 100644 --- a/plugins/check_procs.c +++ b/plugins/check_procs.c | |||
@@ -14,6 +14,9 @@ | |||
14 | * defaults to number of processes. Search filters can be applied to limit | 14 | * defaults to number of processes. Search filters can be applied to limit |
15 | * the processes to check. | 15 | * the processes to check. |
16 | * | 16 | * |
17 | * The parent process, check_procs itself and any child process of | ||
18 | * check_procs (ps) are excluded from any checks to prevent false positives. | ||
19 | * | ||
17 | * | 20 | * |
18 | * This program is free software: you can redistribute it and/or modify | 21 | * This program is free software: you can redistribute it and/or modify |
19 | * it under the terms of the GNU General Public License as published by | 22 | * it under the terms of the GNU General Public License as published by |
@@ -153,7 +156,7 @@ main (int argc, char **argv) | |||
153 | int expected_cols = PS_COLS - 1; | 156 | int expected_cols = PS_COLS - 1; |
154 | int warn = 0; /* number of processes in warn state */ | 157 | int warn = 0; /* number of processes in warn state */ |
155 | int crit = 0; /* number of processes in crit state */ | 158 | int crit = 0; /* number of processes in crit state */ |
156 | int i = 0, j = 0; | 159 | int i = 0; |
157 | int result = STATE_UNKNOWN; | 160 | int result = STATE_UNKNOWN; |
158 | int ret = 0; | 161 | int ret = 0; |
159 | output chld_out, chld_err; | 162 | output chld_out, chld_err; |
@@ -207,7 +210,7 @@ main (int argc, char **argv) | |||
207 | } | 210 | } |
208 | 211 | ||
209 | /* flush first line: j starts at 1 */ | 212 | /* flush first line: j starts at 1 */ |
210 | for (j = 1; j < chld_out.lines; j++) { | 213 | for (size_t j = 1; j < chld_out.lines; j++) { |
211 | input_line = chld_out.line[j]; | 214 | input_line = chld_out.line[j]; |
212 | 215 | ||
213 | if (verbose >= 3) | 216 | if (verbose >= 3) |
@@ -241,8 +244,9 @@ main (int argc, char **argv) | |||
241 | 244 | ||
242 | /* Ignore self */ | 245 | /* Ignore self */ |
243 | if ((usepid && mypid == procpid) || | 246 | if ((usepid && mypid == procpid) || |
244 | (!usepid && ((ret = stat_exe(procpid, &statbuf) != -1) && statbuf.st_dev == mydev && statbuf.st_ino == myino) || | 247 | ( ((!usepid) && ((ret = stat_exe(procpid, &statbuf) != -1) && statbuf.st_dev == mydev && statbuf.st_ino == myino)) || |
245 | (ret == -1 && errno == ENOENT))) { | 248 | (ret == -1 && errno == ENOENT)) |
249 | ) { | ||
246 | if (verbose >= 3) | 250 | if (verbose >= 3) |
247 | printf("not considering - is myself or gone\n"); | 251 | printf("not considering - is myself or gone\n"); |
248 | continue; | 252 | continue; |
@@ -254,6 +258,13 @@ main (int argc, char **argv) | |||
254 | continue; | 258 | continue; |
255 | } | 259 | } |
256 | 260 | ||
261 | /* Ignore our own children */ | ||
262 | if (procppid == mypid) { | ||
263 | if (verbose >= 3) | ||
264 | printf("not considering - is our child\n"); | ||
265 | continue; | ||
266 | } | ||
267 | |||
257 | /* Ignore excluded processes by name */ | 268 | /* Ignore excluded processes by name */ |
258 | if(options & EXCLUDE_PROGS) { | 269 | if(options & EXCLUDE_PROGS) { |
259 | int found = 0; | 270 | int found = 0; |
@@ -727,18 +738,23 @@ convert_to_seconds(char *etime) { | |||
727 | void | 738 | void |
728 | print_help (void) | 739 | print_help (void) |
729 | { | 740 | { |
730 | print_revision (progname, NP_VERSION); | 741 | print_revision (progname, NP_VERSION); |
731 | 742 | ||
732 | printf ("Copyright (c) 1999 Ethan Galstad <nagios@nagios.org>\n"); | 743 | printf ("Copyright (c) 1999 Ethan Galstad <nagios@nagios.org>\n"); |
733 | printf (COPYRIGHT, copyright, email); | 744 | printf (COPYRIGHT, copyright, email); |
734 | 745 | ||
735 | printf ("%s\n", _("Checks all processes and generates WARNING or CRITICAL states if the specified")); | 746 | printf ("%s\n", _("Checks all processes and generates WARNING or CRITICAL states if the specified")); |
736 | printf ("%s\n", _("metric is outside the required threshold ranges. The metric defaults to number")); | 747 | printf ("%s\n", _("metric is outside the required threshold ranges. The metric defaults to number")); |
737 | printf ("%s\n", _("of processes. Search filters can be applied to limit the processes to check.")); | 748 | printf ("%s\n", _("of processes. Search filters can be applied to limit the processes to check.")); |
738 | 749 | ||
739 | printf ("\n\n"); | 750 | printf ("\n\n"); |
740 | 751 | ||
741 | print_usage (); | 752 | printf ("%s\n", _("The parent process, check_procs itself and any child process of check_procs (ps)")); |
753 | printf ("%s\n", _("are excluded from any checks to prevent false positives.")); | ||
754 | |||
755 | printf ("\n\n"); | ||
756 | |||
757 | print_usage (); | ||
742 | 758 | ||
743 | printf (UT_HELP_VRSN); | 759 | printf (UT_HELP_VRSN); |
744 | printf (UT_EXTRA_OPTS); | 760 | printf (UT_EXTRA_OPTS); |
@@ -754,11 +770,11 @@ print_help (void) | |||
754 | printf (" %s\n", _("CPU - percentage CPU")); | 770 | printf (" %s\n", _("CPU - percentage CPU")); |
755 | /* only linux etime is support currently */ | 771 | /* only linux etime is support currently */ |
756 | #if defined( __linux__ ) | 772 | #if defined( __linux__ ) |
757 | printf (" %s\n", _("ELAPSED - time elapsed in seconds")); | 773 | printf (" %s\n", _("ELAPSED - time elapsed in seconds")); |
758 | #endif /* defined(__linux__) */ | 774 | #endif /* defined(__linux__) */ |
759 | printf (UT_PLUG_TIMEOUT, DEFAULT_SOCKET_TIMEOUT); | 775 | printf (UT_PLUG_TIMEOUT, DEFAULT_SOCKET_TIMEOUT); |
760 | 776 | ||
761 | printf (" %s\n", "-v, --verbose"); | 777 | printf (" %s\n", "-v, --verbose"); |
762 | printf (" %s\n", _("Extra information. Up to 3 verbosity levels")); | 778 | printf (" %s\n", _("Extra information. Up to 3 verbosity levels")); |
763 | 779 | ||
764 | printf (" %s\n", "-T, --traditional"); | 780 | printf (" %s\n", "-T, --traditional"); |
@@ -776,7 +792,7 @@ print_help (void) | |||
776 | printf (" %s\n", _("Only scan for processes with VSZ higher than indicated.")); | 792 | printf (" %s\n", _("Only scan for processes with VSZ higher than indicated.")); |
777 | printf (" %s\n", "-r, --rss=RSS"); | 793 | printf (" %s\n", "-r, --rss=RSS"); |
778 | printf (" %s\n", _("Only scan for processes with RSS higher than indicated.")); | 794 | printf (" %s\n", _("Only scan for processes with RSS higher than indicated.")); |
779 | printf (" %s\n", "-P, --pcpu=PCPU"); | 795 | printf (" %s\n", "-P, --pcpu=PCPU"); |
780 | printf (" %s\n", _("Only scan for processes with PCPU higher than indicated.")); | 796 | printf (" %s\n", _("Only scan for processes with PCPU higher than indicated.")); |
781 | printf (" %s\n", "-u, --user=USER"); | 797 | printf (" %s\n", "-u, --user=USER"); |
782 | printf (" %s\n", _("Only scan for processes with user name or ID indicated.")); | 798 | printf (" %s\n", _("Only scan for processes with user name or ID indicated.")); |
@@ -791,19 +807,19 @@ print_help (void) | |||
791 | printf (" %s\n", "-k, --no-kthreads"); | 807 | printf (" %s\n", "-k, --no-kthreads"); |
792 | printf (" %s\n", _("Only scan for non kernel threads (works on Linux only).")); | 808 | printf (" %s\n", _("Only scan for non kernel threads (works on Linux only).")); |
793 | 809 | ||
794 | printf(_("\n\ | 810 | printf(_("\n\ |
795 | RANGEs are specified 'min:max' or 'min:' or ':max' (or 'max'). If\n\ | 811 | RANGEs are specified 'min:max' or 'min:' or ':max' (or 'max'). If\n\ |
796 | specified 'max:min', a warning status will be generated if the\n\ | 812 | specified 'max:min', a warning status will be generated if the\n\ |
797 | count is inside the specified range\n\n")); | 813 | count is inside the specified range\n\n")); |
798 | 814 | ||
799 | printf(_("\ | 815 | printf(_("\ |
800 | This plugin checks the number of currently running processes and\n\ | 816 | This plugin checks the number of currently running processes and\n\ |
801 | generates WARNING or CRITICAL states if the process count is outside\n\ | 817 | generates WARNING or CRITICAL states if the process count is outside\n\ |
802 | the specified threshold ranges. The process count can be filtered by\n\ | 818 | the specified threshold ranges. The process count can be filtered by\n\ |
803 | process owner, parent process PID, current state (e.g., 'Z'), or may\n\ | 819 | process owner, parent process PID, current state (e.g., 'Z'), or may\n\ |
804 | be the total number of running processes\n\n")); | 820 | be the total number of running processes\n\n")); |
805 | 821 | ||
806 | printf ("%s\n", _("Examples:")); | 822 | printf ("%s\n", _("Examples:")); |
807 | printf (" %s\n", "check_procs -w 2:2 -c 2:1024 -C portsentry"); | 823 | printf (" %s\n", "check_procs -w 2:2 -c 2:1024 -C portsentry"); |
808 | printf (" %s\n", _("Warning if not two processes with command name portsentry.")); | 824 | printf (" %s\n", _("Warning if not two processes with command name portsentry.")); |
809 | printf (" %s\n\n", _("Critical if < 2 or > 1024 processes")); | 825 | printf (" %s\n\n", _("Critical if < 2 or > 1024 processes")); |
@@ -820,14 +836,14 @@ be the total number of running processes\n\n")); | |||
820 | printf (" %s\n", "check_procs -w 10 -c 20 --metric=CPU"); | 836 | printf (" %s\n", "check_procs -w 10 -c 20 --metric=CPU"); |
821 | printf (" %s\n", _("Alert if CPU of any processes over 10\% or 20\%")); | 837 | printf (" %s\n", _("Alert if CPU of any processes over 10\% or 20\%")); |
822 | 838 | ||
823 | printf (UT_SUPPORT); | 839 | printf (UT_SUPPORT); |
824 | } | 840 | } |
825 | 841 | ||
826 | void | 842 | void |
827 | print_usage (void) | 843 | print_usage (void) |
828 | { | 844 | { |
829 | printf ("%s\n", _("Usage:")); | 845 | printf ("%s\n", _("Usage:")); |
830 | printf ("%s -w <range> -c <range> [-m metric] [-s state] [-p ppid]\n", progname); | 846 | printf ("%s -w <range> -c <range> [-m metric] [-s state] [-p ppid]\n", progname); |
831 | printf (" [-u user] [-r rss] [-z vsz] [-P %%cpu] [-a argument-array]\n"); | 847 | printf (" [-u user] [-r rss] [-z vsz] [-P %%cpu] [-a argument-array]\n"); |
832 | printf (" [-C command] [-X process_to_exclude] [-k] [-t timeout] [-v]\n"); | 848 | printf (" [-C command] [-X process_to_exclude] [-k] [-t timeout] [-v]\n"); |
833 | } | 849 | } |
diff --git a/plugins/check_radius.c b/plugins/check_radius.c index b1b4938c..6b32710a 100644 --- a/plugins/check_radius.c +++ b/plugins/check_radius.c | |||
@@ -93,7 +93,7 @@ char *expect = NULL; | |||
93 | char *config_file = NULL; | 93 | char *config_file = NULL; |
94 | unsigned short port = PW_AUTH_UDP_PORT; | 94 | unsigned short port = PW_AUTH_UDP_PORT; |
95 | int retries = 1; | 95 | int retries = 1; |
96 | int verbose = FALSE; | 96 | bool verbose = false; |
97 | 97 | ||
98 | /****************************************************************************** | 98 | /****************************************************************************** |
99 | 99 | ||
@@ -272,10 +272,10 @@ process_arguments (int argc, char **argv) | |||
272 | print_revision (progname, NP_VERSION); | 272 | print_revision (progname, NP_VERSION); |
273 | exit (STATE_UNKNOWN); | 273 | exit (STATE_UNKNOWN); |
274 | case 'v': /* verbose mode */ | 274 | case 'v': /* verbose mode */ |
275 | verbose = TRUE; | 275 | verbose = true; |
276 | break; | 276 | break; |
277 | case 'H': /* hostname */ | 277 | case 'H': /* hostname */ |
278 | if (is_host (optarg) == FALSE) { | 278 | if (!is_host (optarg)) { |
279 | usage2 (_("Invalid hostname/address"), optarg); | 279 | usage2 (_("Invalid hostname/address"), optarg); |
280 | } | 280 | } |
281 | server = optarg; | 281 | server = optarg; |
diff --git a/plugins/check_real.c b/plugins/check_real.c index fbdb70f3..15e035b6 100644 --- a/plugins/check_real.c +++ b/plugins/check_real.c | |||
@@ -54,10 +54,10 @@ char *host_name; | |||
54 | char *server_url = NULL; | 54 | char *server_url = NULL; |
55 | char *server_expect; | 55 | char *server_expect; |
56 | int warning_time = 0; | 56 | int warning_time = 0; |
57 | int check_warning_time = FALSE; | 57 | bool check_warning_time = false; |
58 | int critical_time = 0; | 58 | int critical_time = 0; |
59 | int check_critical_time = FALSE; | 59 | bool check_critical_time = false; |
60 | int verbose = FALSE; | 60 | bool verbose = false; |
61 | 61 | ||
62 | 62 | ||
63 | 63 | ||
@@ -238,9 +238,9 @@ main (int argc, char **argv) | |||
238 | /* Return results */ | 238 | /* Return results */ |
239 | if (result == STATE_OK) { | 239 | if (result == STATE_OK) { |
240 | 240 | ||
241 | if (check_critical_time == TRUE | 241 | if (check_critical_time |
242 | && (end_time - start_time) > critical_time) result = STATE_CRITICAL; | 242 | && (end_time - start_time) > critical_time) result = STATE_CRITICAL; |
243 | else if (check_warning_time == TRUE | 243 | else if (check_warning_time |
244 | && (end_time - start_time) > warning_time) result = | 244 | && (end_time - start_time) > warning_time) result = |
245 | STATE_WARNING; | 245 | STATE_WARNING; |
246 | 246 | ||
@@ -331,7 +331,7 @@ process_arguments (int argc, char **argv) | |||
331 | case 'w': /* warning time threshold */ | 331 | case 'w': /* warning time threshold */ |
332 | if (is_intnonneg (optarg)) { | 332 | if (is_intnonneg (optarg)) { |
333 | warning_time = atoi (optarg); | 333 | warning_time = atoi (optarg); |
334 | check_warning_time = TRUE; | 334 | check_warning_time = true; |
335 | } | 335 | } |
336 | else { | 336 | else { |
337 | usage4 (_("Warning time must be a positive integer")); | 337 | usage4 (_("Warning time must be a positive integer")); |
@@ -340,14 +340,14 @@ process_arguments (int argc, char **argv) | |||
340 | case 'c': /* critical time threshold */ | 340 | case 'c': /* critical time threshold */ |
341 | if (is_intnonneg (optarg)) { | 341 | if (is_intnonneg (optarg)) { |
342 | critical_time = atoi (optarg); | 342 | critical_time = atoi (optarg); |
343 | check_critical_time = TRUE; | 343 | check_critical_time = true; |
344 | } | 344 | } |
345 | else { | 345 | else { |
346 | usage4 (_("Critical time must be a positive integer")); | 346 | usage4 (_("Critical time must be a positive integer")); |
347 | } | 347 | } |
348 | break; | 348 | break; |
349 | case 'v': /* verbose */ | 349 | case 'v': /* verbose */ |
350 | verbose = TRUE; | 350 | verbose = true; |
351 | break; | 351 | break; |
352 | case 't': /* timeout */ | 352 | case 't': /* timeout */ |
353 | if (is_intnonneg (optarg)) { | 353 | if (is_intnonneg (optarg)) { |
diff --git a/plugins/check_smtp.c b/plugins/check_smtp.c index fc0ae2c4..986c3e18 100644 --- a/plugins/check_smtp.c +++ b/plugins/check_smtp.c | |||
@@ -40,7 +40,7 @@ const char *email = "devel@monitoring-plugins.org"; | |||
40 | #include <ctype.h> | 40 | #include <ctype.h> |
41 | 41 | ||
42 | #ifdef HAVE_SSL | 42 | #ifdef HAVE_SSL |
43 | int check_cert = FALSE; | 43 | bool check_cert = false; |
44 | int days_till_exp_warn, days_till_exp_crit; | 44 | int days_till_exp_warn, days_till_exp_crit; |
45 | # define my_recv(buf, len) (((use_starttls || use_ssl) && ssl_established) ? np_net_ssl_read(buf, len) : read(sd, buf, len)) | 45 | # define my_recv(buf, len) (((use_starttls || use_ssl) && ssl_established) ? np_net_ssl_read(buf, len) : read(sd, buf, len)) |
46 | # define my_send(buf, len) (((use_starttls || use_ssl) && ssl_established) ? np_net_ssl_write(buf, len) : send(sd, buf, len, 0)) | 46 | # 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; | |||
100 | char *authuser = NULL; | 100 | char *authuser = NULL; |
101 | char *authpass = NULL; | 101 | char *authpass = NULL; |
102 | double warning_time = 0; | 102 | double warning_time = 0; |
103 | int check_warning_time = FALSE; | 103 | bool check_warning_time = false; |
104 | double critical_time = 0; | 104 | double critical_time = 0; |
105 | int check_critical_time = FALSE; | 105 | bool check_critical_time = false; |
106 | int verbose = 0; | 106 | int verbose = 0; |
107 | int use_ssl = FALSE; | 107 | bool use_ssl = false; |
108 | int use_starttls = FALSE; | 108 | bool use_starttls = false; |
109 | int use_sni = FALSE; | 109 | bool use_sni = false; |
110 | short use_proxy_prefix = FALSE; | 110 | bool use_proxy_prefix = false; |
111 | short use_ehlo = FALSE; | 111 | bool use_ehlo = false; |
112 | short use_lhlo = FALSE; | 112 | bool use_lhlo = false; |
113 | short ssl_established = 0; | 113 | bool ssl_established = false; |
114 | char *localhostname = NULL; | 114 | char *localhostname = NULL; |
115 | int sd; | 115 | int sd; |
116 | char buffer[MAX_INPUT_BUFFER]; | 116 | char buffer[MAX_INPUT_BUFFER]; |
@@ -118,13 +118,13 @@ enum { | |||
118 | TCP_PROTOCOL = 1, | 118 | TCP_PROTOCOL = 1, |
119 | UDP_PROTOCOL = 2, | 119 | UDP_PROTOCOL = 2, |
120 | }; | 120 | }; |
121 | int ignore_send_quit_failure = FALSE; | 121 | bool ignore_send_quit_failure = false; |
122 | 122 | ||
123 | 123 | ||
124 | int | 124 | int |
125 | main (int argc, char **argv) | 125 | main (int argc, char **argv) |
126 | { | 126 | { |
127 | short supports_tls=FALSE; | 127 | bool supports_tls = false; |
128 | int n = 0; | 128 | int n = 0; |
129 | double elapsed_time; | 129 | double elapsed_time; |
130 | long microsec; | 130 | long microsec; |
@@ -230,7 +230,7 @@ main (int argc, char **argv) | |||
230 | } else if(use_ehlo || use_lhlo){ | 230 | } else if(use_ehlo || use_lhlo){ |
231 | if(strstr(buffer, "250 STARTTLS") != NULL || | 231 | if(strstr(buffer, "250 STARTTLS") != NULL || |
232 | strstr(buffer, "250-STARTTLS") != NULL){ | 232 | strstr(buffer, "250-STARTTLS") != NULL){ |
233 | supports_tls=TRUE; | 233 | supports_tls=true; |
234 | } | 234 | } |
235 | } | 235 | } |
236 | 236 | ||
@@ -466,7 +466,7 @@ main (int argc, char **argv) | |||
466 | fperfdata ("time", elapsed_time, "s", | 466 | fperfdata ("time", elapsed_time, "s", |
467 | (int)check_warning_time, warning_time, | 467 | (int)check_warning_time, warning_time, |
468 | (int)check_critical_time, critical_time, | 468 | (int)check_critical_time, critical_time, |
469 | TRUE, 0, FALSE, 0)); | 469 | true, 0, false, 0)); |
470 | 470 | ||
471 | return result; | 471 | return result; |
472 | } | 472 | } |
@@ -480,6 +480,8 @@ process_arguments (int argc, char **argv) | |||
480 | int c; | 480 | int c; |
481 | char* temp; | 481 | char* temp; |
482 | 482 | ||
483 | bool implicit_tls = false; | ||
484 | |||
483 | enum { | 485 | enum { |
484 | SNI_OPTION | 486 | SNI_OPTION |
485 | }; | 487 | }; |
@@ -560,7 +562,7 @@ process_arguments (int argc, char **argv) | |||
560 | break; | 562 | break; |
561 | case 'A': | 563 | case 'A': |
562 | authtype = optarg; | 564 | authtype = optarg; |
563 | use_ehlo = TRUE; | 565 | use_ehlo = true; |
564 | break; | 566 | break; |
565 | case 'U': | 567 | case 'U': |
566 | authuser = optarg; | 568 | authuser = optarg; |
@@ -600,7 +602,7 @@ process_arguments (int argc, char **argv) | |||
600 | usage4 (_("Critical time must be a positive")); | 602 | usage4 (_("Critical time must be a positive")); |
601 | else { | 603 | else { |
602 | critical_time = strtod (optarg, NULL); | 604 | critical_time = strtod (optarg, NULL); |
603 | check_critical_time = TRUE; | 605 | check_critical_time = true; |
604 | } | 606 | } |
605 | break; | 607 | break; |
606 | case 'w': /* warning time threshold */ | 608 | case 'w': /* warning time threshold */ |
@@ -608,14 +610,14 @@ process_arguments (int argc, char **argv) | |||
608 | usage4 (_("Warning time must be a positive")); | 610 | usage4 (_("Warning time must be a positive")); |
609 | else { | 611 | else { |
610 | warning_time = strtod (optarg, NULL); | 612 | warning_time = strtod (optarg, NULL); |
611 | check_warning_time = TRUE; | 613 | check_warning_time = true; |
612 | } | 614 | } |
613 | break; | 615 | break; |
614 | case 'v': /* verbose */ | 616 | case 'v': /* verbose */ |
615 | verbose++; | 617 | verbose++; |
616 | break; | 618 | break; |
617 | case 'q': | 619 | case 'q': |
618 | ignore_send_quit_failure++; /* ignore problem sending QUIT */ | 620 | ignore_send_quit_failure = true; /* ignore problem sending QUIT */ |
619 | break; | 621 | break; |
620 | case 't': /* timeout */ | 622 | case 't': /* timeout */ |
621 | if (is_intnonneg (optarg)) { | 623 | if (is_intnonneg (optarg)) { |
@@ -645,33 +647,35 @@ process_arguments (int argc, char **argv) | |||
645 | usage2 ("Invalid certificate expiration period", optarg); | 647 | usage2 ("Invalid certificate expiration period", optarg); |
646 | days_till_exp_warn = atoi (optarg); | 648 | days_till_exp_warn = atoi (optarg); |
647 | } | 649 | } |
648 | check_cert = TRUE; | 650 | check_cert = true; |
649 | ignore_send_quit_failure = TRUE; | 651 | ignore_send_quit_failure = true; |
650 | #else | 652 | #else |
651 | usage (_("SSL support not available - install OpenSSL and recompile")); | 653 | usage (_("SSL support not available - install OpenSSL and recompile")); |
652 | #endif | 654 | #endif |
655 | implicit_tls = true; | ||
656 | // fallthrough | ||
653 | case 's': | 657 | case 's': |
654 | /* ssl */ | 658 | /* ssl */ |
655 | use_ssl = TRUE; | 659 | use_ssl = true; |
656 | server_port = SMTPS_PORT; | 660 | server_port = SMTPS_PORT; |
657 | break; | 661 | break; |
658 | case 'S': | 662 | case 'S': |
659 | /* starttls */ | 663 | /* starttls */ |
660 | use_starttls = TRUE; | 664 | use_starttls = true; |
661 | use_ehlo = TRUE; | 665 | use_ehlo = true; |
662 | break; | 666 | break; |
663 | case SNI_OPTION: | 667 | case SNI_OPTION: |
664 | #ifdef HAVE_SSL | 668 | #ifdef HAVE_SSL |
665 | use_sni = TRUE; | 669 | use_sni = true; |
666 | #else | 670 | #else |
667 | usage (_("SSL support not available - install OpenSSL and recompile")); | 671 | usage (_("SSL support not available - install OpenSSL and recompile")); |
668 | #endif | 672 | #endif |
669 | break; | 673 | break; |
670 | case 'r': | 674 | case 'r': |
671 | use_proxy_prefix = TRUE; | 675 | use_proxy_prefix = true; |
672 | break; | 676 | break; |
673 | case 'L': | 677 | case 'L': |
674 | use_lhlo = TRUE; | 678 | use_lhlo = true; |
675 | break; | 679 | break; |
676 | case '4': | 680 | case '4': |
677 | address_family = AF_INET; | 681 | address_family = AF_INET; |
@@ -717,7 +721,12 @@ process_arguments (int argc, char **argv) | |||
717 | from_arg = strdup(" "); | 721 | from_arg = strdup(" "); |
718 | 722 | ||
719 | if (use_starttls && use_ssl) { | 723 | if (use_starttls && use_ssl) { |
720 | usage4 (_("Set either -s/--ssl/--tls or -S/--starttls")); | 724 | if (implicit_tls) { |
725 | use_ssl = false; | ||
726 | server_port = SMTP_PORT; | ||
727 | } else { | ||
728 | usage4 (_("Set either -s/--ssl/--tls or -S/--starttls")); | ||
729 | } | ||
721 | } | 730 | } |
722 | 731 | ||
723 | if (server_port_option != 0) { | 732 | if (server_port_option != 0) { |
diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c index 56a586ad..90a04027 100644 --- a/plugins/check_snmp.c +++ b/plugins/check_snmp.c | |||
@@ -55,8 +55,6 @@ const char *email = "devel@monitoring-plugins.org"; | |||
55 | #define CRIT_STRING 2 | 55 | #define CRIT_STRING 2 |
56 | #define CRIT_REGEX 4 | 56 | #define CRIT_REGEX 4 |
57 | #define WARN_PRESENT 8 | 57 | #define WARN_PRESENT 8 |
58 | #define WARN_STRING 16 | ||
59 | #define WARN_REGEX 32 | ||
60 | 58 | ||
61 | #define OID_COUNT_STEP 8 | 59 | #define OID_COUNT_STEP 8 |
62 | 60 | ||
@@ -86,82 +84,82 @@ const char *email = "devel@monitoring-plugins.org"; | |||
86 | 84 | ||
87 | 85 | ||
88 | 86 | ||
89 | int process_arguments (int, char **); | 87 | static int process_arguments (int, char **); |
90 | int validate_arguments (void); | 88 | static int validate_arguments (void); |
91 | char *thisarg (char *str); | 89 | static char *thisarg (char *str); |
92 | char *nextarg (char *str); | 90 | static char *nextarg (char *str); |
93 | void print_usage (void); | 91 | void print_usage (void); |
94 | void print_help (void); | 92 | static void print_help (void); |
95 | char *multiply (char *str); | 93 | static char *multiply (char *str); |
96 | 94 | ||
97 | #include "regex.h" | 95 | #include "regex.h" |
98 | char regex_expect[MAX_INPUT_BUFFER] = ""; | 96 | static char regex_expect[MAX_INPUT_BUFFER] = ""; |
99 | regex_t preg; | 97 | static regex_t preg; |
100 | regmatch_t pmatch[10]; | 98 | static regmatch_t pmatch[10]; |
101 | char errbuf[MAX_INPUT_BUFFER] = ""; | 99 | static char errbuf[MAX_INPUT_BUFFER] = ""; |
102 | char perfstr[MAX_INPUT_BUFFER] = "| "; | 100 | static char perfstr[MAX_INPUT_BUFFER] = "| "; |
103 | int cflags = REG_EXTENDED | REG_NOSUB | REG_NEWLINE; | 101 | static int cflags = REG_EXTENDED | REG_NOSUB | REG_NEWLINE; |
104 | int eflags = 0; | 102 | static int eflags = 0; |
105 | int errcode, excode; | 103 | static int errcode, excode; |
106 | 104 | ||
107 | char *server_address = NULL; | 105 | static char *server_address = NULL; |
108 | char *community = NULL; | 106 | static char *community = NULL; |
109 | char **contextargs = NULL; | 107 | static char **contextargs = NULL; |
110 | char *context = NULL; | 108 | static char *context = NULL; |
111 | char **authpriv = NULL; | 109 | static char **authpriv = NULL; |
112 | char *proto = NULL; | 110 | static char *proto = NULL; |
113 | char *seclevel = NULL; | 111 | static char *seclevel = NULL; |
114 | char *secname = NULL; | 112 | static char *secname = NULL; |
115 | char *authproto = NULL; | 113 | static char *authproto = NULL; |
116 | char *privproto = NULL; | 114 | static char *privproto = NULL; |
117 | char *authpasswd = NULL; | 115 | static char *authpasswd = NULL; |
118 | char *privpasswd = NULL; | 116 | static char *privpasswd = NULL; |
119 | int nulloid = STATE_UNKNOWN; | 117 | static int nulloid = STATE_UNKNOWN; |
120 | char **oids = NULL; | 118 | static char **oids = NULL; |
121 | size_t oids_size = 0; | 119 | static size_t oids_size = 0; |
122 | char *label; | 120 | static char *label; |
123 | char *units; | 121 | static char *units; |
124 | char *port; | 122 | static char *port; |
125 | char *snmpcmd; | 123 | static char *snmpcmd; |
126 | char string_value[MAX_INPUT_BUFFER] = ""; | 124 | static char string_value[MAX_INPUT_BUFFER] = ""; |
127 | int invert_search=0; | 125 | static int invert_search=0; |
128 | char **labels = NULL; | 126 | static char **labels = NULL; |
129 | char **unitv = NULL; | 127 | static char **unitv = NULL; |
130 | size_t nlabels = 0; | 128 | static size_t nlabels = 0; |
131 | size_t labels_size = OID_COUNT_STEP; | 129 | static size_t labels_size = OID_COUNT_STEP; |
132 | size_t nunits = 0; | 130 | static size_t nunits = 0; |
133 | size_t unitv_size = OID_COUNT_STEP; | 131 | static size_t unitv_size = OID_COUNT_STEP; |
134 | int numoids = 0; | 132 | static size_t numoids = 0; |
135 | int numauthpriv = 0; | 133 | static int numauthpriv = 0; |
136 | int numcontext = 0; | 134 | static int numcontext = 0; |
137 | int verbose = 0; | 135 | static int verbose = 0; |
138 | int usesnmpgetnext = FALSE; | 136 | static bool usesnmpgetnext = false; |
139 | char *warning_thresholds = NULL; | 137 | static char *warning_thresholds = NULL; |
140 | char *critical_thresholds = NULL; | 138 | static char *critical_thresholds = NULL; |
141 | thresholds **thlds; | 139 | static thresholds **thlds; |
142 | size_t thlds_size = OID_COUNT_STEP; | 140 | static size_t thlds_size = OID_COUNT_STEP; |
143 | double *response_value; | 141 | static double *response_value; |
144 | size_t response_size = OID_COUNT_STEP; | 142 | static size_t response_size = OID_COUNT_STEP; |
145 | int retries = 0; | 143 | static int retries = 0; |
146 | int *eval_method; | 144 | static int *eval_method; |
147 | size_t eval_size = OID_COUNT_STEP; | 145 | static size_t eval_size = OID_COUNT_STEP; |
148 | char *delimiter; | 146 | static char *delimiter; |
149 | char *output_delim; | 147 | static char *output_delim; |
150 | char *miblist = NULL; | 148 | static char *miblist = NULL; |
151 | int needmibs = FALSE; | 149 | static bool needmibs = false; |
152 | int calculate_rate = 0; | 150 | static int calculate_rate = 0; |
153 | double offset = 0.0; | 151 | static double offset = 0.0; |
154 | int rate_multiplier = 1; | 152 | static int rate_multiplier = 1; |
155 | state_data *previous_state; | 153 | static state_data *previous_state; |
156 | double *previous_value; | 154 | static double *previous_value; |
157 | size_t previous_size = OID_COUNT_STEP; | 155 | static size_t previous_size = OID_COUNT_STEP; |
158 | int perf_labels = 1; | 156 | static int perf_labels = 1; |
159 | char* ip_version = ""; | 157 | static char* ip_version = ""; |
160 | double multiplier = 1.0; | 158 | static double multiplier = 1.0; |
161 | char *fmtstr = ""; | 159 | static char *fmtstr = ""; |
162 | bool fmtstr_set = false; | 160 | static bool fmtstr_set = false; |
163 | char buffer[DEFAULT_BUFFER_SIZE]; | 161 | static char buffer[DEFAULT_BUFFER_SIZE]; |
164 | bool ignore_mib_parsing_errors = false; | 162 | static bool ignore_mib_parsing_errors = false; |
165 | 163 | ||
166 | static char *fix_snmp_range(char *th) | 164 | static char *fix_snmp_range(char *th) |
167 | { | 165 | { |
@@ -187,7 +185,8 @@ static char *fix_snmp_range(char *th) | |||
187 | int | 185 | int |
188 | main (int argc, char **argv) | 186 | main (int argc, char **argv) |
189 | { | 187 | { |
190 | int i, len, line, total_oids; | 188 | int len, total_oids; |
189 | size_t line; | ||
191 | unsigned int bk_count = 0, dq_count = 0; | 190 | unsigned int bk_count = 0, dq_count = 0; |
192 | int iresult = STATE_UNKNOWN; | 191 | int iresult = STATE_UNKNOWN; |
193 | int result = STATE_UNKNOWN; | 192 | int result = STATE_UNKNOWN; |
@@ -253,14 +252,16 @@ main (int argc, char **argv) | |||
253 | if(calculate_rate) { | 252 | if(calculate_rate) { |
254 | if (!strcmp(label, "SNMP")) | 253 | if (!strcmp(label, "SNMP")) |
255 | label = strdup("SNMP RATE"); | 254 | label = strdup("SNMP RATE"); |
256 | i=0; | 255 | |
256 | size_t i = 0; | ||
257 | |||
257 | previous_state = np_state_read(); | 258 | previous_state = np_state_read(); |
258 | if(previous_state!=NULL) { | 259 | if(previous_state!=NULL) { |
259 | /* Split colon separated values */ | 260 | /* Split colon separated values */ |
260 | previous_string = strdup((char *) previous_state->data); | 261 | previous_string = strdup((char *) previous_state->data); |
261 | while((ap = strsep(&previous_string, ":")) != NULL) { | 262 | while((ap = strsep(&previous_string, ":")) != NULL) { |
262 | if(verbose>2) | 263 | if(verbose>2) |
263 | printf("State for %d=%s\n", i, ap); | 264 | printf("State for %zd=%s\n", i, ap); |
264 | while (i >= previous_size) { | 265 | while (i >= previous_size) { |
265 | previous_size += OID_COUNT_STEP; | 266 | previous_size += OID_COUNT_STEP; |
266 | previous_value = realloc(previous_value, previous_size * sizeof(*previous_value)); | 267 | previous_value = realloc(previous_value, previous_size * sizeof(*previous_value)); |
@@ -273,7 +274,7 @@ main (int argc, char **argv) | |||
273 | /* Populate the thresholds */ | 274 | /* Populate the thresholds */ |
274 | th_warn=warning_thresholds; | 275 | th_warn=warning_thresholds; |
275 | th_crit=critical_thresholds; | 276 | th_crit=critical_thresholds; |
276 | for (i=0; i<numoids; i++) { | 277 | for (size_t i = 0; i < numoids; i++) { |
277 | char *w = th_warn ? strndup(th_warn, strcspn(th_warn, ",")) : NULL; | 278 | char *w = th_warn ? strndup(th_warn, strcspn(th_warn, ",")) : NULL; |
278 | char *c = th_crit ? strndup(th_crit, strcspn(th_crit, ",")) : NULL; | 279 | char *c = th_crit ? strndup(th_crit, strcspn(th_crit, ",")) : NULL; |
279 | /* translate "2:1" to "@1:2" for backwards compatibility */ | 280 | /* translate "2:1" to "@1:2" for backwards compatibility */ |
@@ -302,7 +303,7 @@ main (int argc, char **argv) | |||
302 | } | 303 | } |
303 | 304 | ||
304 | /* Create the command array to execute */ | 305 | /* Create the command array to execute */ |
305 | if(usesnmpgetnext == TRUE) { | 306 | if(usesnmpgetnext) { |
306 | snmpcmd = strdup (PATH_TO_SNMPGETNEXT); | 307 | snmpcmd = strdup (PATH_TO_SNMPGETNEXT); |
307 | }else{ | 308 | }else{ |
308 | snmpcmd = strdup (PATH_TO_SNMPGET); | 309 | snmpcmd = strdup (PATH_TO_SNMPGET); |
@@ -333,11 +334,11 @@ main (int argc, char **argv) | |||
333 | } | 334 | } |
334 | 335 | ||
335 | 336 | ||
336 | for (i = 0; i < numcontext; i++) { | 337 | for (int i = 0; i < numcontext; i++) { |
337 | command_line[index++] = contextargs[i]; | 338 | command_line[index++] = contextargs[i]; |
338 | } | 339 | } |
339 | 340 | ||
340 | for (i = 0; i < numauthpriv; i++) { | 341 | for (int i = 0; i < numauthpriv; i++) { |
341 | command_line[index++] = authpriv[i]; | 342 | command_line[index++] = authpriv[i]; |
342 | } | 343 | } |
343 | 344 | ||
@@ -348,7 +349,7 @@ main (int argc, char **argv) | |||
348 | server_address, | 349 | server_address, |
349 | port); | 350 | port); |
350 | 351 | ||
351 | for (i = 0; i < numoids; i++) { | 352 | for (size_t i = 0; i < numoids; i++) { |
352 | command_line[index++] = oids[i]; | 353 | command_line[index++] = oids[i]; |
353 | xasprintf(&cl_hidden_auth, "%s %s", cl_hidden_auth, oids[i]); | 354 | xasprintf(&cl_hidden_auth, "%s %s", cl_hidden_auth, oids[i]); |
354 | } | 355 | } |
@@ -382,7 +383,7 @@ main (int argc, char **argv) | |||
382 | if (external_error) { | 383 | if (external_error) { |
383 | if (chld_err.lines > 0) { | 384 | if (chld_err.lines > 0) { |
384 | printf (_("External command error: %s\n"), chld_err.line[0]); | 385 | printf (_("External command error: %s\n"), chld_err.line[0]); |
385 | for (i = 1; i < chld_err.lines; i++) { | 386 | for (size_t i = 1; i < chld_err.lines; i++) { |
386 | printf ("%s\n", chld_err.line[i]); | 387 | printf ("%s\n", chld_err.line[i]); |
387 | } | 388 | } |
388 | } else { | 389 | } else { |
@@ -392,12 +393,14 @@ main (int argc, char **argv) | |||
392 | } | 393 | } |
393 | 394 | ||
394 | if (verbose) { | 395 | if (verbose) { |
395 | for (i = 0; i < chld_out.lines; i++) { | 396 | for (size_t i = 0; i < chld_out.lines; i++) { |
396 | printf ("%s\n", chld_out.line[i]); | 397 | printf ("%s\n", chld_out.line[i]); |
397 | } | 398 | } |
398 | } | 399 | } |
399 | 400 | ||
400 | for (line=0, i=0; line < chld_out.lines && i < numoids ; line++, i++) { | 401 | line = 0; |
402 | total_oids = 0; | ||
403 | for (size_t i = 0; line < chld_out.lines && i < numoids ; line++, i++, total_oids++) { | ||
401 | if(calculate_rate) | 404 | if(calculate_rate) |
402 | conv = "%.10g"; | 405 | conv = "%.10g"; |
403 | else | 406 | else |
@@ -410,7 +413,7 @@ main (int argc, char **argv) | |||
410 | break; | 413 | break; |
411 | 414 | ||
412 | if (verbose > 2) { | 415 | if (verbose > 2) { |
413 | printf("Processing oid %i (line %i)\n oidname: %s\n response: %s\n", i+1, line+1, oidname, response); | 416 | printf("Processing oid %zi (line %zi)\n oidname: %s\n response: %s\n", i+1, line+1, oidname, response); |
414 | } | 417 | } |
415 | 418 | ||
416 | /* Clean up type array - Sol10 does not necessarily zero it out */ | 419 | /* Clean up type array - Sol10 does not necessarily zero it out */ |
@@ -634,7 +637,6 @@ main (int argc, char **argv) | |||
634 | strncat(perfstr, " ", sizeof(perfstr)-strlen(perfstr)-1); | 637 | strncat(perfstr, " ", sizeof(perfstr)-strlen(perfstr)-1); |
635 | } | 638 | } |
636 | } | 639 | } |
637 | total_oids=i; | ||
638 | 640 | ||
639 | /* Save state data, as all data collected now */ | 641 | /* Save state data, as all data collected now */ |
640 | if(calculate_rate) { | 642 | if(calculate_rate) { |
@@ -644,7 +646,7 @@ main (int argc, char **argv) | |||
644 | die(STATE_UNKNOWN, _("Cannot malloc")); | 646 | die(STATE_UNKNOWN, _("Cannot malloc")); |
645 | 647 | ||
646 | current_length=0; | 648 | current_length=0; |
647 | for(i=0; i<total_oids; i++) { | 649 | for(int i = 0; i < total_oids; i++) { |
648 | xasprintf(&temp_string,"%.0f",response_value[i]); | 650 | xasprintf(&temp_string,"%.0f",response_value[i]); |
649 | if(temp_string==NULL) | 651 | if(temp_string==NULL) |
650 | die(STATE_UNKNOWN,_("Cannot asprintf()")); | 652 | die(STATE_UNKNOWN,_("Cannot asprintf()")); |
@@ -687,7 +689,7 @@ process_arguments (int argc, char **argv) | |||
687 | { | 689 | { |
688 | char *ptr; | 690 | char *ptr; |
689 | int c = 1; | 691 | int c = 1; |
690 | int j = 0, jj = 0, ii = 0; | 692 | size_t j = 0, jj = 0; |
691 | 693 | ||
692 | int option = 0; | 694 | int option = 0; |
693 | static struct option longopts[] = { | 695 | static struct option longopts[] = { |
@@ -777,7 +779,7 @@ process_arguments (int argc, char **argv) | |||
777 | miblist = optarg; | 779 | miblist = optarg; |
778 | break; | 780 | break; |
779 | case 'n': /* usesnmpgetnext */ | 781 | case 'n': /* usesnmpgetnext */ |
780 | usesnmpgetnext = TRUE; | 782 | usesnmpgetnext = true; |
781 | break; | 783 | break; |
782 | case 'P': /* SNMP protocol version */ | 784 | case 'P': /* SNMP protocol version */ |
783 | proto = optarg; | 785 | proto = optarg; |
@@ -831,7 +833,7 @@ process_arguments (int argc, char **argv) | |||
831 | * so we have a mib variable, rather than just an SNMP OID, | 833 | * so we have a mib variable, rather than just an SNMP OID, |
832 | * so we have to actually read the mib files | 834 | * so we have to actually read the mib files |
833 | */ | 835 | */ |
834 | needmibs = TRUE; | 836 | needmibs = true; |
835 | } | 837 | } |
836 | for (ptr = strtok(optarg, ", "); ptr != NULL; ptr = strtok(NULL, ", "), j++) { | 838 | for (ptr = strtok(optarg, ", "); ptr != NULL; ptr = strtok(NULL, ", "), j++) { |
837 | while (j >= oids_size) { | 839 | while (j >= oids_size) { |
@@ -843,7 +845,6 @@ process_arguments (int argc, char **argv) | |||
843 | numoids = j; | 845 | numoids = j; |
844 | if (c == 'E' || c == 'e') { | 846 | if (c == 'E' || c == 'e') { |
845 | jj++; | 847 | jj++; |
846 | ii++; | ||
847 | while (j+1 >= eval_size) { | 848 | while (j+1 >= eval_size) { |
848 | eval_size += OID_COUNT_STEP; | 849 | eval_size += OID_COUNT_STEP; |
849 | eval_method = realloc(eval_method, eval_size * sizeof(*eval_method)); | 850 | eval_method = realloc(eval_method, eval_size * sizeof(*eval_method)); |
@@ -870,7 +871,6 @@ process_arguments (int argc, char **argv) | |||
870 | memset(eval_method + eval_size - OID_COUNT_STEP, 0, 8); | 871 | memset(eval_method + eval_size - OID_COUNT_STEP, 0, 8); |
871 | } | 872 | } |
872 | eval_method[jj++] = CRIT_STRING; | 873 | eval_method[jj++] = CRIT_STRING; |
873 | ii++; | ||
874 | break; | 874 | break; |
875 | case 'R': /* regex */ | 875 | case 'R': /* regex */ |
876 | cflags = REG_ICASE; | 876 | cflags = REG_ICASE; |
@@ -891,7 +891,6 @@ process_arguments (int argc, char **argv) | |||
891 | memset(eval_method + eval_size - OID_COUNT_STEP, 0, 8); | 891 | memset(eval_method + eval_size - OID_COUNT_STEP, 0, 8); |
892 | } | 892 | } |
893 | eval_method[jj++] = CRIT_REGEX; | 893 | eval_method[jj++] = CRIT_REGEX; |
894 | ii++; | ||
895 | break; | 894 | break; |
896 | 895 | ||
897 | /* Format */ | 896 | /* Format */ |
@@ -1029,12 +1028,12 @@ selected.</para> | |||
1029 | 1028 | ||
1030 | 1029 | ||
1031 | 1030 | ||
1032 | int | 1031 | static int |
1033 | validate_arguments () | 1032 | validate_arguments () |
1034 | { | 1033 | { |
1035 | /* check whether to load locally installed MIBS (CPU/disk intensive) */ | 1034 | /* check whether to load locally installed MIBS (CPU/disk intensive) */ |
1036 | if (miblist == NULL) { | 1035 | if (miblist == NULL) { |
1037 | if ( needmibs == TRUE ) { | 1036 | if (needmibs) { |
1038 | miblist = strdup (DEFAULT_MIBLIST); | 1037 | miblist = strdup (DEFAULT_MIBLIST); |
1039 | }else{ | 1038 | }else{ |
1040 | miblist = ""; /* don't read any mib files for numeric oids */ | 1039 | miblist = ""; /* don't read any mib files for numeric oids */ |
@@ -1138,7 +1137,7 @@ validate_arguments () | |||
1138 | /* trim leading whitespace | 1137 | /* trim leading whitespace |
1139 | if there is a leading quote, make sure it balances */ | 1138 | if there is a leading quote, make sure it balances */ |
1140 | 1139 | ||
1141 | char * | 1140 | static char * |
1142 | thisarg (char *str) | 1141 | thisarg (char *str) |
1143 | { | 1142 | { |
1144 | str += strspn (str, " \t\r\n"); /* trim any leading whitespace */ | 1143 | str += strspn (str, " \t\r\n"); /* trim any leading whitespace */ |
@@ -1155,7 +1154,7 @@ thisarg (char *str) | |||
1155 | set the trailing quote to '\x0' | 1154 | set the trailing quote to '\x0' |
1156 | if the string continues, advance beyond the comma */ | 1155 | if the string continues, advance beyond the comma */ |
1157 | 1156 | ||
1158 | char * | 1157 | static char * |
1159 | nextarg (char *str) | 1158 | nextarg (char *str) |
1160 | { | 1159 | { |
1161 | if (str[0] == '\'') { | 1160 | if (str[0] == '\'') { |
@@ -1187,7 +1186,7 @@ nextarg (char *str) | |||
1187 | 1186 | ||
1188 | 1187 | ||
1189 | /* multiply result (values 0 < n < 1 work as divider) */ | 1188 | /* multiply result (values 0 < n < 1 work as divider) */ |
1190 | char * | 1189 | static char * |
1191 | multiply (char *str) | 1190 | multiply (char *str) |
1192 | { | 1191 | { |
1193 | char *endptr; | 1192 | char *endptr; |
@@ -1224,7 +1223,7 @@ multiply (char *str) | |||
1224 | } | 1223 | } |
1225 | 1224 | ||
1226 | 1225 | ||
1227 | void | 1226 | static void |
1228 | print_help (void) | 1227 | print_help (void) |
1229 | { | 1228 | { |
1230 | print_revision (progname, NP_VERSION); | 1229 | print_revision (progname, NP_VERSION); |
@@ -1252,10 +1251,12 @@ print_help (void) | |||
1252 | printf (" %s\n", _("SNMPv3 context")); | 1251 | printf (" %s\n", _("SNMPv3 context")); |
1253 | printf (" %s\n", "-L, --seclevel=[noAuthNoPriv|authNoPriv|authPriv]"); | 1252 | printf (" %s\n", "-L, --seclevel=[noAuthNoPriv|authNoPriv|authPriv]"); |
1254 | printf (" %s\n", _("SNMPv3 securityLevel")); | 1253 | printf (" %s\n", _("SNMPv3 securityLevel")); |
1255 | printf (" %s\n", "-a, --authproto=[MD5|SHA]"); | 1254 | printf (" %s\n", "-a, --authproto=AUTHENTICATION_PROTOCOL"); |
1256 | printf (" %s\n", _("SNMPv3 auth proto")); | 1255 | printf (" %s\n", _("SNMPv3 authentication protocol (default MD5), available options depend on the specific version of the net-snmp tools")); |
1257 | printf (" %s\n", "-x, --privproto=[DES|AES]"); | 1256 | printf (" %s\n", _("if < 5.8 SHA (1) and MD5 should be available, if >= 5.8 additionally SHA-224, SHA-256, SHA-384 and SHA-512")); |
1258 | printf (" %s\n", _("SNMPv3 priv proto (default DES)")); | 1257 | printf (" %s\n", "-x, --privproto=PRIVACY_PROTOCOL"); |
1258 | printf (" %s\n", _("SNMPv3 privacy protocol (default DES), available options depend on the specific version of the net-snmp tools")); | ||
1259 | printf (" %s\n", _("if < 5.8 DES and AES should be available, if >= 5.8 additionally AES-192 and AES-256")); | ||
1259 | 1260 | ||
1260 | /* Authentication Tokens*/ | 1261 | /* Authentication Tokens*/ |
1261 | printf (" %s\n", "-C, --community=STRING"); | 1262 | printf (" %s\n", "-C, --community=STRING"); |
diff --git a/plugins/check_ssh.c b/plugins/check_ssh.c index 8ccbd5a7..34ef37b7 100644 --- a/plugins/check_ssh.c +++ b/plugins/check_ssh.c | |||
@@ -1,39 +1,39 @@ | |||
1 | /***************************************************************************** | 1 | /***************************************************************************** |
2 | * | 2 | * |
3 | * Monitoring check_ssh plugin | 3 | * Monitoring check_ssh plugin |
4 | * | 4 | * |
5 | * License: GPL | 5 | * License: GPL |
6 | * Copyright (c) 2000-2007 Monitoring Plugins Development Team | 6 | * Copyright (c) 2000-2007 Monitoring Plugins Development Team |
7 | * | 7 | * |
8 | * Description: | 8 | * Description: |
9 | * | 9 | * |
10 | * This file contains the check_ssh plugin | 10 | * This file contains the check_ssh plugin |
11 | * | 11 | * |
12 | * Try to connect to an SSH server at specified server and port | 12 | * Try to connect to an SSH server at specified server and port |
13 | * | 13 | * |
14 | * | 14 | * |
15 | * This program is free software: you can redistribute it and/or modify | 15 | * This program is free software: you can redistribute it and/or modify |
16 | * it under the terms of the GNU General Public License as published by | 16 | * it under the terms of the GNU General Public License as published by |
17 | * the Free Software Foundation, either version 3 of the License, or | 17 | * the Free Software Foundation, either version 3 of the License, or |
18 | * (at your option) any later version. | 18 | * (at your option) any later version. |
19 | * | 19 | * |
20 | * This program is distributed in the hope that it will be useful, | 20 | * This program is distributed in the hope that it will be useful, |
21 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 21 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
22 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 22 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
23 | * GNU General Public License for more details. | 23 | * GNU General Public License for more details. |
24 | * | 24 | * |
25 | * You should have received a copy of the GNU General Public License | 25 | * You should have received a copy of the GNU General Public License |
26 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 26 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
27 | * | 27 | * |
28 | * | 28 | * |
29 | *****************************************************************************/ | 29 | *****************************************************************************/ |
30 | 30 | ||
31 | const char *progname = "check_ssh"; | 31 | const char *progname = "check_ssh"; |
32 | const char *copyright = "2000-2007"; | 32 | const char *copyright = "2000-2007"; |
33 | const char *email = "devel@monitoring-plugins.org"; | 33 | const char *email = "devel@monitoring-plugins.org"; |
34 | 34 | ||
35 | #include "common.h" | 35 | #include "./common.h" |
36 | #include "netutils.h" | 36 | #include "./netutils.h" |
37 | #include "utils.h" | 37 | #include "utils.h" |
38 | 38 | ||
39 | #ifndef MSG_DONTWAIT | 39 | #ifndef MSG_DONTWAIT |
@@ -47,7 +47,7 @@ int port = -1; | |||
47 | char *server_name = NULL; | 47 | char *server_name = NULL; |
48 | char *remote_version = NULL; | 48 | char *remote_version = NULL; |
49 | char *remote_protocol = NULL; | 49 | char *remote_protocol = NULL; |
50 | int verbose = FALSE; | 50 | bool verbose = false; |
51 | 51 | ||
52 | int process_arguments (int, char **); | 52 | int process_arguments (int, char **); |
53 | int validate_arguments (void); | 53 | int validate_arguments (void); |
@@ -57,7 +57,6 @@ void print_usage (void); | |||
57 | int ssh_connect (char *haddr, int hport, char *remote_version, char *remote_protocol); | 57 | int ssh_connect (char *haddr, int hport, char *remote_version, char *remote_protocol); |
58 | 58 | ||
59 | 59 | ||
60 | |||
61 | int | 60 | int |
62 | main (int argc, char **argv) | 61 | main (int argc, char **argv) |
63 | { | 62 | { |
@@ -106,7 +105,7 @@ process_arguments (int argc, char **argv) | |||
106 | {"timeout", required_argument, 0, 't'}, | 105 | {"timeout", required_argument, 0, 't'}, |
107 | {"verbose", no_argument, 0, 'v'}, | 106 | {"verbose", no_argument, 0, 'v'}, |
108 | {"remote-version", required_argument, 0, 'r'}, | 107 | {"remote-version", required_argument, 0, 'r'}, |
109 | {"remote-protcol", required_argument, 0, 'P'}, | 108 | {"remote-protocol", required_argument, 0, 'P'}, |
110 | {0, 0, 0, 0} | 109 | {0, 0, 0, 0} |
111 | }; | 110 | }; |
112 | 111 | ||
@@ -133,7 +132,7 @@ process_arguments (int argc, char **argv) | |||
133 | print_help (); | 132 | print_help (); |
134 | exit (STATE_UNKNOWN); | 133 | exit (STATE_UNKNOWN); |
135 | case 'v': /* verbose */ | 134 | case 'v': /* verbose */ |
136 | verbose = TRUE; | 135 | verbose = true; |
137 | break; | 136 | break; |
138 | case 't': /* timeout period */ | 137 | case 't': /* timeout period */ |
139 | if (!is_integer (optarg)) | 138 | if (!is_integer (optarg)) |
@@ -158,7 +157,7 @@ process_arguments (int argc, char **argv) | |||
158 | remote_protocol = optarg; | 157 | remote_protocol = optarg; |
159 | break; | 158 | break; |
160 | case 'H': /* host */ | 159 | case 'H': /* host */ |
161 | if (is_host (optarg) == FALSE) | 160 | if (!is_host (optarg)) |
162 | usage2 (_("Invalid hostname/address"), optarg); | 161 | usage2 (_("Invalid hostname/address"), optarg); |
163 | server_name = optarg; | 162 | server_name = optarg; |
164 | break; | 163 | break; |
@@ -215,7 +214,9 @@ ssh_connect (char *haddr, int hport, char *remote_version, char *remote_protocol | |||
215 | { | 214 | { |
216 | int sd; | 215 | int sd; |
217 | int result; | 216 | int result; |
218 | char *output = NULL; | 217 | int len = 0; |
218 | ssize_t recv_ret = 0; | ||
219 | char *version_control_string = NULL; | ||
219 | char *buffer = NULL; | 220 | char *buffer = NULL; |
220 | char *ssh_proto = NULL; | 221 | char *ssh_proto = NULL; |
221 | char *ssh_server = NULL; | 222 | char *ssh_server = NULL; |
@@ -230,52 +231,126 @@ ssh_connect (char *haddr, int hport, char *remote_version, char *remote_protocol | |||
230 | if (result != STATE_OK) | 231 | if (result != STATE_OK) |
231 | return result; | 232 | return result; |
232 | 233 | ||
233 | output = (char *) malloc (BUFF_SZ + 1); | 234 | char *output = (char *) calloc (BUFF_SZ + 1, sizeof(char)); |
234 | memset (output, 0, BUFF_SZ + 1); | 235 | |
235 | recv (sd, output, BUFF_SZ, 0); | 236 | unsigned int iteration = 0; |
236 | if (strncmp (output, "SSH", 3)) { | 237 | ssize_t byte_offset = 0; |
237 | printf (_("Server answer: %s"), output); | 238 | |
238 | close(sd); | 239 | while ((version_control_string == NULL) && (recv_ret = recv(sd, output+byte_offset, BUFF_SZ - byte_offset, 0) > 0)) { |
240 | |||
241 | if (strchr(output, '\n')) { /* we've got at least one full line, start parsing*/ | ||
242 | byte_offset = 0; | ||
243 | |||
244 | char *index = NULL; | ||
245 | while ((index = strchr(output+byte_offset, '\n')) != NULL) { | ||
246 | /*Partition the buffer so that this line is a separate string, | ||
247 | * by replacing the newline with NUL*/ | ||
248 | output[(index - output)] = '\0'; | ||
249 | len = strlen(output + byte_offset); | ||
250 | |||
251 | if ((len >= 4) && (strncmp (output+byte_offset, "SSH-", 4) == 0)) { | ||
252 | /*if the string starts with SSH-, this _should_ be a valid version control string*/ | ||
253 | version_control_string = output+byte_offset; | ||
254 | break; | ||
255 | } | ||
256 | |||
257 | /*the start of the next line (if one exists) will be after the current one (+ NUL)*/ | ||
258 | byte_offset += (len + 1); | ||
259 | } | ||
260 | |||
261 | if(version_control_string == NULL) { | ||
262 | /* move unconsumed data to beginning of buffer, null rest */ | ||
263 | memmove((void *)output, (void *)output+byte_offset+1, BUFF_SZ - len+1); | ||
264 | memset(output+byte_offset+1, 0, BUFF_SZ-byte_offset+1); | ||
265 | |||
266 | /*start reading from end of current line chunk on next recv*/ | ||
267 | byte_offset = strlen(output); | ||
268 | } | ||
269 | } else { | ||
270 | byte_offset += recv_ret; | ||
271 | } | ||
272 | } | ||
273 | |||
274 | if (recv_ret < 0) { | ||
275 | printf("SSH CRITICAL - %s", strerror(errno)); | ||
276 | exit(STATE_CRITICAL); | ||
277 | } | ||
278 | |||
279 | if (version_control_string == NULL) { | ||
280 | printf("SSH CRITICAL - No version control string received"); | ||
281 | exit(STATE_CRITICAL); | ||
282 | } | ||
283 | /* | ||
284 | * "When the connection has been established, both sides MUST send an | ||
285 | * identification string. This identification string MUST be | ||
286 | * | ||
287 | * SSH-protoversion-softwareversion SP comments CR LF" | ||
288 | * - RFC 4253:4.2 | ||
289 | */ | ||
290 | strip (version_control_string); | ||
291 | if (verbose) | ||
292 | printf ("%s\n", version_control_string); | ||
293 | ssh_proto = version_control_string + 4; | ||
294 | |||
295 | /* | ||
296 | * We assume the protoversion is of the form Major.Minor, although | ||
297 | * this is not _strictly_ required. See | ||
298 | * | ||
299 | * "Both the 'protoversion' and 'softwareversion' strings MUST consist of | ||
300 | * printable US-ASCII characters, with the exception of whitespace | ||
301 | * characters and the minus sign (-)" | ||
302 | * - RFC 4253:4.2 | ||
303 | * and, | ||
304 | * | ||
305 | * "As stated earlier, the 'protoversion' specified for this protocol is | ||
306 | * "2.0". Earlier versions of this protocol have not been formally | ||
307 | * documented, but it is widely known that they use 'protoversion' of | ||
308 | * "1.x" (e.g., "1.5" or "1.3")." | ||
309 | * - RFC 4253:5 | ||
310 | */ | ||
311 | ssh_server = ssh_proto + strspn (ssh_proto, "0123456789.") + 1; /* (+1 for the '-' separating protoversion from softwareversion) */ | ||
312 | |||
313 | /* If there's a space in the version string, whatever's after the space is a comment | ||
314 | * (which is NOT part of the server name/version)*/ | ||
315 | char *tmp = strchr(ssh_server, ' '); | ||
316 | if (tmp) { | ||
317 | ssh_server[tmp - ssh_server] = '\0'; | ||
318 | } | ||
319 | if (strlen(ssh_proto) == 0 || strlen(ssh_server) == 0) { | ||
320 | printf(_("SSH CRITICAL - Invalid protocol version control string %s\n"), version_control_string); | ||
239 | exit (STATE_CRITICAL); | 321 | exit (STATE_CRITICAL); |
240 | } | 322 | } |
241 | else { | 323 | ssh_proto[strspn (ssh_proto, "0123456789. ")] = 0; |
242 | strip (output); | ||
243 | if (verbose) | ||
244 | printf ("%s\n", output); | ||
245 | ssh_proto = output + 4; | ||
246 | ssh_server = ssh_proto + strspn (ssh_proto, "-0123456789. "); | ||
247 | ssh_proto[strspn (ssh_proto, "0123456789. ")] = 0; | ||
248 | |||
249 | xasprintf (&buffer, "SSH-%s-check_ssh_%s\r\n", ssh_proto, rev_no); | ||
250 | send (sd, buffer, strlen (buffer), MSG_DONTWAIT); | ||
251 | if (verbose) | ||
252 | printf ("%s\n", buffer); | ||
253 | |||
254 | if (remote_version && strcmp(remote_version, ssh_server)) { | ||
255 | printf | ||
256 | (_("SSH CRITICAL - %s (protocol %s) version mismatch, expected '%s'\n"), | ||
257 | ssh_server, ssh_proto, remote_version); | ||
258 | close(sd); | ||
259 | exit (STATE_CRITICAL); | ||
260 | } | ||
261 | 324 | ||
262 | if (remote_protocol && strcmp(remote_protocol, ssh_proto)) { | 325 | xasprintf (&buffer, "SSH-%s-check_ssh_%s\r\n", ssh_proto, rev_no); |
263 | printf | 326 | send (sd, buffer, strlen (buffer), MSG_DONTWAIT); |
264 | (_("SSH CRITICAL - %s (protocol %s) protocol version mismatch, expected '%s'\n"), | 327 | if (verbose) |
265 | ssh_server, ssh_proto, remote_protocol); | 328 | printf ("%s\n", buffer); |
266 | close(sd); | ||
267 | exit (STATE_CRITICAL); | ||
268 | } | ||
269 | 329 | ||
270 | elapsed_time = (double)deltime(tv) / 1.0e6; | 330 | if (remote_version && strcmp(remote_version, ssh_server)) { |
331 | printf | ||
332 | (_("SSH CRITICAL - %s (protocol %s) version mismatch, expected '%s'\n"), | ||
333 | ssh_server, ssh_proto, remote_version); | ||
334 | close(sd); | ||
335 | exit (STATE_CRITICAL); | ||
336 | } | ||
271 | 337 | ||
338 | if (remote_protocol && strcmp(remote_protocol, ssh_proto)) { | ||
272 | printf | 339 | printf |
273 | (_("SSH OK - %s (protocol %s) | %s\n"), | 340 | (_("SSH CRITICAL - %s (protocol %s) protocol version mismatch, expected '%s' | %s\n"), |
274 | ssh_server, ssh_proto, fperfdata("time", elapsed_time, "s", | 341 | ssh_server, ssh_proto, remote_protocol, fperfdata("time", elapsed_time, "s", |
275 | FALSE, 0, FALSE, 0, TRUE, 0, TRUE, (int)socket_timeout)); | 342 | false, 0, false, 0, true, 0, true, (int)socket_timeout)); |
276 | close(sd); | 343 | close(sd); |
277 | exit (STATE_OK); | 344 | exit (STATE_CRITICAL); |
278 | } | 345 | } |
346 | elapsed_time = (double)deltime(tv) / 1.0e6; | ||
347 | |||
348 | printf | ||
349 | (_("SSH OK - %s (protocol %s) | %s\n"), | ||
350 | ssh_server, ssh_proto, fperfdata("time", elapsed_time, "s", | ||
351 | false, 0, false, 0, true, 0, true, (int)socket_timeout)); | ||
352 | close(sd); | ||
353 | exit (STATE_OK); | ||
279 | } | 354 | } |
280 | 355 | ||
281 | 356 | ||
@@ -293,7 +368,7 @@ print_help (void) | |||
293 | 368 | ||
294 | printf ("%s\n", _("Try to connect to an SSH server at specified server and port")); | 369 | printf ("%s\n", _("Try to connect to an SSH server at specified server and port")); |
295 | 370 | ||
296 | printf ("\n\n"); | 371 | printf ("\n\n"); |
297 | 372 | ||
298 | print_usage (); | 373 | print_usage (); |
299 | 374 | ||
@@ -307,10 +382,10 @@ print_help (void) | |||
307 | printf (UT_CONN_TIMEOUT, DEFAULT_SOCKET_TIMEOUT); | 382 | printf (UT_CONN_TIMEOUT, DEFAULT_SOCKET_TIMEOUT); |
308 | 383 | ||
309 | printf (" %s\n", "-r, --remote-version=STRING"); | 384 | printf (" %s\n", "-r, --remote-version=STRING"); |
310 | printf (" %s\n", _("Alert if string doesn't match expected server version (ex: OpenSSH_3.9p1)")); | 385 | printf (" %s\n", _("Alert if string doesn't match expected server version (ex: OpenSSH_3.9p1)")); |
311 | 386 | ||
312 | printf (" %s\n", "-P, --remote-protocol=STRING"); | 387 | printf (" %s\n", "-P, --remote-protocol=STRING"); |
313 | printf (" %s\n", _("Alert if protocol doesn't match expected protocol version (ex: 2.0)")); | 388 | printf (" %s\n", _("Alert if protocol doesn't match expected protocol version (ex: 2.0)")); |
314 | 389 | ||
315 | printf (UT_VERBOSE); | 390 | printf (UT_VERBOSE); |
316 | 391 | ||
@@ -322,7 +397,7 @@ print_help (void) | |||
322 | void | 397 | void |
323 | print_usage (void) | 398 | print_usage (void) |
324 | { | 399 | { |
325 | printf ("%s\n", _("Usage:")); | 400 | printf ("%s\n", _("Usage:")); |
326 | printf ("%s [-4|-6] [-t <timeout>] [-r <remote version>] [-p <port>] <host>\n", progname); | 401 | printf ("%s [-4|-6] [-t <timeout>] [-r <remote version>] [-p <port>] <host>\n", progname); |
327 | } | 402 | } |
328 | 403 | ||
diff --git a/plugins/check_swap.c b/plugins/check_swap.c index cd965e31..e7ee785d 100644 --- a/plugins/check_swap.c +++ b/plugins/check_swap.c | |||
@@ -4,7 +4,7 @@ | |||
4 | * | 4 | * |
5 | * License: GPL | 5 | * License: GPL |
6 | * Copyright (c) 2000 Karl DeBisschop (kdebisschop@users.sourceforge.net) | 6 | * Copyright (c) 2000 Karl DeBisschop (kdebisschop@users.sourceforge.net) |
7 | * Copyright (c) 2000-2007 Monitoring Plugins Development Team | 7 | * Copyright (c) 2000-2024 Monitoring Plugins Development Team |
8 | * | 8 | * |
9 | * Description: | 9 | * Description: |
10 | * | 10 | * |
@@ -28,7 +28,7 @@ | |||
28 | *****************************************************************************/ | 28 | *****************************************************************************/ |
29 | 29 | ||
30 | const char *progname = "check_swap"; | 30 | const char *progname = "check_swap"; |
31 | const char *copyright = "2000-2007"; | 31 | const char *copyright = "2000-2024"; |
32 | const char *email = "devel@monitoring-plugins.org"; | 32 | const char *email = "devel@monitoring-plugins.org"; |
33 | 33 | ||
34 | #include "common.h" | 34 | #include "common.h" |
@@ -52,9 +52,9 @@ const char *email = "devel@monitoring-plugins.org"; | |||
52 | #endif | 52 | #endif |
53 | 53 | ||
54 | typedef struct { | 54 | typedef struct { |
55 | int is_percentage; | 55 | bool is_percentage; |
56 | uint64_t value; | 56 | uint64_t value; |
57 | } threshold_t; | 57 | } threshold; |
58 | 58 | ||
59 | int check_swap (float free_swap_mb, float total_swap_mb); | 59 | int check_swap (float free_swap_mb, float total_swap_mb); |
60 | int process_arguments (int argc, char **argv); | 60 | int process_arguments (int argc, char **argv); |
@@ -62,10 +62,10 @@ int validate_arguments (void); | |||
62 | void print_usage (void); | 62 | void print_usage (void); |
63 | void print_help (void); | 63 | void print_help (void); |
64 | 64 | ||
65 | threshold_t warn; | 65 | threshold warn; |
66 | threshold_t crit; | 66 | threshold crit; |
67 | int verbose; | 67 | int verbose; |
68 | int allswaps; | 68 | bool allswaps = false; |
69 | int no_swap_state = STATE_CRITICAL; | 69 | int no_swap_state = STATE_CRITICAL; |
70 | 70 | ||
71 | int | 71 | int |
@@ -383,10 +383,10 @@ main (int argc, char **argv) | |||
383 | if (crit.is_percentage) crit_print = crit.value * (total_swap_mb *1024 *1024/100); | 383 | if (crit.is_percentage) crit_print = crit.value * (total_swap_mb *1024 *1024/100); |
384 | 384 | ||
385 | puts (perfdata_uint64 ("swap", free_swap_mb *1024 *1024, "B", | 385 | puts (perfdata_uint64 ("swap", free_swap_mb *1024 *1024, "B", |
386 | TRUE, warn_print, | 386 | true, warn_print, |
387 | TRUE, crit_print, | 387 | true, crit_print, |
388 | TRUE, 0, | 388 | true, 0, |
389 | TRUE, (long) total_swap_mb * 1024 * 1024)); | 389 | true, (long) total_swap_mb * 1024 * 1024)); |
390 | 390 | ||
391 | return result; | 391 | return result; |
392 | } | 392 | } |
@@ -399,28 +399,30 @@ check_swap(float free_swap_mb, float total_swap_mb) | |||
399 | if (!total_swap_mb) return no_swap_state; | 399 | if (!total_swap_mb) return no_swap_state; |
400 | 400 | ||
401 | uint64_t free_swap = free_swap_mb * (1024 * 1024); /* Convert back to bytes as warn and crit specified in bytes */ | 401 | uint64_t free_swap = free_swap_mb * (1024 * 1024); /* Convert back to bytes as warn and crit specified in bytes */ |
402 | |||
403 | if (!crit.is_percentage && crit.value >= free_swap) return STATE_CRITICAL; | ||
404 | if (!warn.is_percentage && warn.value >= free_swap) return STATE_WARNING; | ||
405 | |||
406 | |||
407 | uint64_t usage_percentage = ((total_swap_mb - free_swap_mb) / total_swap_mb) * 100; | 402 | uint64_t usage_percentage = ((total_swap_mb - free_swap_mb) / total_swap_mb) * 100; |
408 | 403 | ||
409 | if (crit.is_percentage && | 404 | if (warn.value || crit.value) { /* Thresholds defined */ |
410 | crit.value != 0 && | 405 | if (!crit.is_percentage && crit.value >= free_swap) return STATE_CRITICAL; |
411 | usage_percentage >= (100 - crit.value)) | 406 | if (!warn.is_percentage && warn.value >= free_swap) return STATE_WARNING; |
412 | { | 407 | |
413 | return STATE_CRITICAL; | 408 | if (crit.is_percentage && |
414 | } | 409 | crit.value != 0 && |
415 | 410 | usage_percentage >= (100 - crit.value)) | |
416 | if (warn.is_percentage && | 411 | { |
417 | warn.value != 0 && | 412 | return STATE_CRITICAL; |
418 | usage_percentage >= (100 - warn.value)) | 413 | } |
419 | { | 414 | |
420 | return STATE_WARNING; | 415 | if (warn.is_percentage && |
421 | } | 416 | warn.value != 0 && |
422 | 417 | usage_percentage >= (100 - warn.value)) | |
423 | return STATE_OK; | 418 | { |
419 | return STATE_WARNING; | ||
420 | } | ||
421 | |||
422 | return STATE_OK; | ||
423 | } else { /* Without thresholds */ | ||
424 | return STATE_OK; | ||
425 | } | ||
424 | } | 426 | } |
425 | 427 | ||
426 | 428 | ||
@@ -443,9 +445,6 @@ process_arguments (int argc, char **argv) | |||
443 | {0, 0, 0, 0} | 445 | {0, 0, 0, 0} |
444 | }; | 446 | }; |
445 | 447 | ||
446 | if (argc < 2) | ||
447 | return ERROR; | ||
448 | |||
449 | while (1) { | 448 | while (1) { |
450 | c = getopt_long (argc, argv, "+?Vvhac:w:n:", longopts, &option); | 449 | c = getopt_long (argc, argv, "+?Vvhac:w:n:", longopts, &option); |
451 | 450 | ||
@@ -465,7 +464,7 @@ process_arguments (int argc, char **argv) | |||
465 | 464 | ||
466 | if (optarg[length - 1] == '%') { | 465 | if (optarg[length - 1] == '%') { |
467 | /* It's percentage */ | 466 | /* It's percentage */ |
468 | warn.is_percentage = 1; | 467 | warn.is_percentage = true; |
469 | optarg[length - 1] = '\0'; | 468 | optarg[length - 1] = '\0'; |
470 | if (is_uint64(optarg, &warn.value)) { | 469 | if (is_uint64(optarg, &warn.value)) { |
471 | if (warn.value > 100) { | 470 | if (warn.value > 100) { |
@@ -475,7 +474,7 @@ process_arguments (int argc, char **argv) | |||
475 | break; | 474 | break; |
476 | } else { | 475 | } else { |
477 | /* It's Bytes */ | 476 | /* It's Bytes */ |
478 | warn.is_percentage = 0; | 477 | warn.is_percentage = false; |
479 | if (is_uint64(optarg, &warn.value)) { | 478 | if (is_uint64(optarg, &warn.value)) { |
480 | break; | 479 | break; |
481 | } else { | 480 | } else { |
@@ -495,7 +494,7 @@ process_arguments (int argc, char **argv) | |||
495 | 494 | ||
496 | if (optarg[length - 1] == '%') { | 495 | if (optarg[length - 1] == '%') { |
497 | /* It's percentage */ | 496 | /* It's percentage */ |
498 | crit.is_percentage = 1; | 497 | crit.is_percentage = true; |
499 | optarg[length - 1] = '\0'; | 498 | optarg[length - 1] = '\0'; |
500 | if (is_uint64(optarg, &crit.value)) { | 499 | if (is_uint64(optarg, &crit.value)) { |
501 | if (crit.value> 100) { | 500 | if (crit.value> 100) { |
@@ -505,7 +504,7 @@ process_arguments (int argc, char **argv) | |||
505 | break; | 504 | break; |
506 | } else { | 505 | } else { |
507 | /* It's Bytes */ | 506 | /* It's Bytes */ |
508 | crit.is_percentage = 0; | 507 | crit.is_percentage = false; |
509 | if (is_uint64(optarg, &crit.value)) { | 508 | if (is_uint64(optarg, &crit.value)) { |
510 | break; | 509 | break; |
511 | } else { | 510 | } else { |
@@ -514,7 +513,7 @@ process_arguments (int argc, char **argv) | |||
514 | } | 513 | } |
515 | } | 514 | } |
516 | case 'a': /* all swap */ | 515 | case 'a': /* all swap */ |
517 | allswaps = TRUE; | 516 | allswaps = true; |
518 | break; | 517 | break; |
519 | case 'n': | 518 | case 'n': |
520 | if ((no_swap_state = mp_translate_state(optarg)) == ERROR) { | 519 | if ((no_swap_state = mp_translate_state(optarg)) == ERROR) { |
@@ -547,10 +546,7 @@ process_arguments (int argc, char **argv) | |||
547 | int | 546 | int |
548 | validate_arguments (void) | 547 | validate_arguments (void) |
549 | { | 548 | { |
550 | if (warn.value == 0 && crit.value == 0) { | 549 | if ((warn.is_percentage == crit.is_percentage) && (warn.value < crit.value)) { |
551 | return ERROR; | ||
552 | } | ||
553 | else if ((warn.is_percentage == crit.is_percentage) && (warn.value < crit.value)) { | ||
554 | /* This is NOT triggered if warn and crit are different units, e.g warn is percentage | 550 | /* This is NOT triggered if warn and crit are different units, e.g warn is percentage |
555 | * and crit is absolute. We cannot determine the condition at this point since we | 551 | * and crit is absolute. We cannot determine the condition at this point since we |
556 | * dont know the value of total swap yet | 552 | * dont know the value of total swap yet |
@@ -595,6 +591,7 @@ print_help (void) | |||
595 | printf ("\n"); | 591 | printf ("\n"); |
596 | printf ("%s\n", _("Notes:")); | 592 | printf ("%s\n", _("Notes:")); |
597 | printf (" %s\n", _("Both INTEGER and PERCENT thresholds can be specified, they are all checked.")); | 593 | printf (" %s\n", _("Both INTEGER and PERCENT thresholds can be specified, they are all checked.")); |
594 | printf (" %s\n", _("Without thresholds, the plugin shows free swap space and performance data, but always returns OK.")); | ||
598 | printf (" %s\n", _("On AIX, if -a is specified, uses lsps -a, otherwise uses lsps -s.")); | 595 | printf (" %s\n", _("On AIX, if -a is specified, uses lsps -a, otherwise uses lsps -s.")); |
599 | 596 | ||
600 | printf (UT_SUPPORT); | 597 | printf (UT_SUPPORT); |
@@ -605,6 +602,6 @@ void | |||
605 | print_usage (void) | 602 | print_usage (void) |
606 | { | 603 | { |
607 | printf ("%s\n", _("Usage:")); | 604 | printf ("%s\n", _("Usage:")); |
608 | printf (" %s [-av] -w <percent_free>%% -c <percent_free>%%\n",progname); | 605 | printf (" %s [-av] [-w <percent_free>%%] [-c <percent_free>%%]\n",progname); |
609 | printf (" -w <bytes_free> -c <bytes_free> [-n <state>]\n"); | 606 | printf (" [-w <bytes_free>] [-c <bytes_free>] [-n <state>]\n"); |
610 | } | 607 | } |
diff --git a/plugins/check_tcp.c b/plugins/check_tcp.c index 1d307cf3..01dd35eb 100644 --- a/plugins/check_tcp.c +++ b/plugins/check_tcp.c | |||
@@ -41,7 +41,7 @@ const char *email = "devel@monitoring-plugins.org"; | |||
41 | #include <sys/select.h> | 41 | #include <sys/select.h> |
42 | 42 | ||
43 | #ifdef HAVE_SSL | 43 | #ifdef HAVE_SSL |
44 | static int check_cert = FALSE; | 44 | static bool check_cert = false; |
45 | static int days_till_exp_warn, days_till_exp_crit; | 45 | static int days_till_exp_warn, days_till_exp_crit; |
46 | # define my_recv(buf, len) ((flags & FLAG_SSL) ? np_net_ssl_read(buf, len) : read(sd, buf, len)) | 46 | # define my_recv(buf, len) ((flags & FLAG_SSL) ? np_net_ssl_read(buf, len) : read(sd, buf, len)) |
47 | # define my_send(buf, len) ((flags & FLAG_SSL) ? np_net_ssl_write(buf, len) : send(sd, buf, len, 0)) | 47 | # 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; | |||
65 | 65 | ||
66 | static int server_port = 0; | 66 | static int server_port = 0; |
67 | static char *server_address = NULL; | 67 | static char *server_address = NULL; |
68 | static int host_specified = FALSE; | 68 | static bool host_specified = false; |
69 | static char *server_send = NULL; | 69 | static char *server_send = NULL; |
70 | static char *server_quit = NULL; | 70 | static char *server_quit = NULL; |
71 | static char **server_expect; | 71 | static char **server_expect; |
72 | static size_t server_expect_count = 0; | 72 | static size_t server_expect_count = 0; |
73 | static size_t maxbytes = 0; | 73 | static ssize_t maxbytes = 0; |
74 | static char **warn_codes = NULL; | 74 | static char **warn_codes = NULL; |
75 | static size_t warn_codes_count = 0; | 75 | static size_t warn_codes_count = 0; |
76 | static char **crit_codes = NULL; | 76 | static char **crit_codes = NULL; |
@@ -88,7 +88,7 @@ static int match_flags = NP_MATCH_EXACT; | |||
88 | 88 | ||
89 | #ifdef HAVE_SSL | 89 | #ifdef HAVE_SSL |
90 | static char *sni = NULL; | 90 | static char *sni = NULL; |
91 | static int sni_specified = FALSE; | 91 | static bool sni_specified = false; |
92 | #endif | 92 | #endif |
93 | 93 | ||
94 | #define FLAG_SSL 0x01 | 94 | #define FLAG_SSL 0x01 |
@@ -102,11 +102,9 @@ int | |||
102 | main (int argc, char **argv) | 102 | main (int argc, char **argv) |
103 | { | 103 | { |
104 | int result = STATE_UNKNOWN; | 104 | int result = STATE_UNKNOWN; |
105 | int i; | ||
106 | char *status = NULL; | 105 | char *status = NULL; |
107 | struct timeval tv; | 106 | struct timeval tv; |
108 | struct timeval timeout; | 107 | struct timeval timeout; |
109 | size_t len; | ||
110 | int match = -1; | 108 | int match = -1; |
111 | fd_set rfds; | 109 | fd_set rfds; |
112 | 110 | ||
@@ -121,10 +119,10 @@ main (int argc, char **argv) | |||
121 | if(progname != NULL) progname++; | 119 | if(progname != NULL) progname++; |
122 | else progname = argv[0]; | 120 | else progname = argv[0]; |
123 | 121 | ||
124 | len = strlen(progname); | 122 | size_t prog_name_len = strlen(progname); |
125 | if(len > 6 && !memcmp(progname, "check_", 6)) { | 123 | if(prog_name_len > 6 && !memcmp(progname, "check_", 6)) { |
126 | SERVICE = strdup(progname + 6); | 124 | SERVICE = strdup(progname + 6); |
127 | for(i = 0; i < len - 6; i++) | 125 | for(size_t i = 0; i < prog_name_len - 6; i++) |
128 | SERVICE[i] = toupper(SERVICE[i]); | 126 | SERVICE[i] = toupper(SERVICE[i]); |
129 | } | 127 | } |
130 | 128 | ||
@@ -247,7 +245,7 @@ main (int argc, char **argv) | |||
247 | #ifdef HAVE_SSL | 245 | #ifdef HAVE_SSL |
248 | if (flags & FLAG_SSL){ | 246 | if (flags & FLAG_SSL){ |
249 | result = np_net_ssl_init_with_hostname(sd, (sni_specified ? sni : NULL)); | 247 | result = np_net_ssl_init_with_hostname(sd, (sni_specified ? sni : NULL)); |
250 | if (result == STATE_OK && check_cert == TRUE) { | 248 | if (result == STATE_OK && check_cert) { |
251 | result = np_net_ssl_check_cert(days_till_exp_warn, days_till_exp_crit); | 249 | result = np_net_ssl_check_cert(days_till_exp_warn, days_till_exp_crit); |
252 | } | 250 | } |
253 | } | 251 | } |
@@ -275,19 +273,21 @@ main (int argc, char **argv) | |||
275 | printf("Quit string: %s\n", server_quit); | 273 | printf("Quit string: %s\n", server_quit); |
276 | } | 274 | } |
277 | printf("server_expect_count: %d\n", (int)server_expect_count); | 275 | printf("server_expect_count: %d\n", (int)server_expect_count); |
278 | for(i = 0; i < server_expect_count; i++) | 276 | for(size_t i = 0; i < server_expect_count; i++) |
279 | printf("\t%d: %s\n", i, server_expect[i]); | 277 | printf("\t%zd: %s\n", i, server_expect[i]); |
280 | } | 278 | } |
281 | 279 | ||
282 | /* if(len) later on, we know we have a non-NULL response */ | 280 | /* if(len) later on, we know we have a non-NULL response */ |
283 | len = 0; | 281 | ssize_t len = 0; |
282 | |||
284 | if (server_expect_count) { | 283 | if (server_expect_count) { |
284 | ssize_t received = 0; | ||
285 | 285 | ||
286 | /* watch for the expect string */ | 286 | /* watch for the expect string */ |
287 | while ((i = my_recv(buffer, sizeof(buffer))) > 0) { | 287 | while ((received = my_recv(buffer, sizeof(buffer))) > 0) { |
288 | status = realloc(status, len + i + 1); | 288 | status = realloc(status, len + received + 1); |
289 | memcpy(&status[len], buffer, i); | 289 | memcpy(&status[len], buffer, received); |
290 | len += i; | 290 | len += received; |
291 | status[len] = '\0'; | 291 | status[len] = '\0'; |
292 | 292 | ||
293 | /* stop reading if user-forced */ | 293 | /* stop reading if user-forced */ |
@@ -307,6 +307,7 @@ main (int argc, char **argv) | |||
307 | if(select(sd + 1, &rfds, NULL, NULL, &timeout) <= 0) | 307 | if(select(sd + 1, &rfds, NULL, NULL, &timeout) <= 0) |
308 | break; | 308 | break; |
309 | } | 309 | } |
310 | |||
310 | if (match == NP_MATCH_RETRY) | 311 | if (match == NP_MATCH_RETRY) |
311 | match = NP_MATCH_FAILURE; | 312 | match = NP_MATCH_FAILURE; |
312 | 313 | ||
@@ -378,18 +379,18 @@ main (int argc, char **argv) | |||
378 | if(match == NP_MATCH_FAILURE) | 379 | if(match == NP_MATCH_FAILURE) |
379 | printf ("|%s", | 380 | printf ("|%s", |
380 | fperfdata ("time", elapsed_time, "s", | 381 | fperfdata ("time", elapsed_time, "s", |
381 | (flags & FLAG_TIME_WARN ? TRUE : FALSE), 0, | 382 | (flags & FLAG_TIME_WARN ? true : false), 0, |
382 | (flags & FLAG_TIME_CRIT ? TRUE : FALSE), 0, | 383 | (flags & FLAG_TIME_CRIT ? true : false), 0, |
383 | TRUE, 0, | 384 | true, 0, |
384 | TRUE, socket_timeout) | 385 | true, socket_timeout) |
385 | ); | 386 | ); |
386 | else | 387 | else |
387 | printf("|%s", | 388 | printf("|%s", |
388 | fperfdata ("time", elapsed_time, "s", | 389 | fperfdata ("time", elapsed_time, "s", |
389 | (flags & FLAG_TIME_WARN ? TRUE : FALSE), warning_time, | 390 | (flags & FLAG_TIME_WARN ? true : false), warning_time, |
390 | (flags & FLAG_TIME_CRIT ? TRUE : FALSE), critical_time, | 391 | (flags & FLAG_TIME_CRIT ? true : false), critical_time, |
391 | TRUE, 0, | 392 | true, 0, |
392 | TRUE, socket_timeout) | 393 | true, socket_timeout) |
393 | ); | 394 | ); |
394 | 395 | ||
395 | putchar('\n'); | 396 | putchar('\n'); |
@@ -399,11 +400,9 @@ main (int argc, char **argv) | |||
399 | 400 | ||
400 | 401 | ||
401 | /* process command-line arguments */ | 402 | /* process command-line arguments */ |
402 | static int | 403 | static int process_arguments (int argc, char **argv) { |
403 | process_arguments (int argc, char **argv) | ||
404 | { | ||
405 | int c; | 404 | int c; |
406 | int escape = 0; | 405 | bool escape = false; |
407 | char *temp; | 406 | char *temp; |
408 | 407 | ||
409 | enum { | 408 | enum { |
@@ -492,7 +491,7 @@ process_arguments (int argc, char **argv) | |||
492 | #endif | 491 | #endif |
493 | break; | 492 | break; |
494 | case 'H': /* hostname */ | 493 | case 'H': /* hostname */ |
495 | host_specified = TRUE; | 494 | host_specified = true; |
496 | server_address = optarg; | 495 | server_address = optarg; |
497 | break; | 496 | break; |
498 | case 'c': /* critical */ | 497 | case 'c': /* critical */ |
@@ -527,7 +526,7 @@ process_arguments (int argc, char **argv) | |||
527 | server_port = atoi (optarg); | 526 | server_port = atoi (optarg); |
528 | break; | 527 | break; |
529 | case 'E': | 528 | case 'E': |
530 | escape = 1; | 529 | escape = true; |
531 | break; | 530 | break; |
532 | case 's': | 531 | case 's': |
533 | if (escape) | 532 | if (escape) |
@@ -601,7 +600,7 @@ process_arguments (int argc, char **argv) | |||
601 | usage2 (_("Invalid certificate expiration period"), optarg); | 600 | usage2 (_("Invalid certificate expiration period"), optarg); |
602 | days_till_exp_warn = atoi (optarg); | 601 | days_till_exp_warn = atoi (optarg); |
603 | } | 602 | } |
604 | check_cert = TRUE; | 603 | check_cert = true; |
605 | flags |= FLAG_SSL; | 604 | flags |= FLAG_SSL; |
606 | break; | 605 | break; |
607 | # endif /* USE_OPENSSL */ | 606 | # endif /* USE_OPENSSL */ |
@@ -617,7 +616,7 @@ process_arguments (int argc, char **argv) | |||
617 | case SNI_OPTION: | 616 | case SNI_OPTION: |
618 | #ifdef HAVE_SSL | 617 | #ifdef HAVE_SSL |
619 | flags |= FLAG_SSL; | 618 | flags |= FLAG_SSL; |
620 | sni_specified = TRUE; | 619 | sni_specified = true; |
621 | sni = optarg; | 620 | sni = optarg; |
622 | #else | 621 | #else |
623 | die (STATE_UNKNOWN, _("Invalid option - SSL is not available")); | 622 | die (STATE_UNKNOWN, _("Invalid option - SSL is not available")); |
@@ -630,15 +629,15 @@ process_arguments (int argc, char **argv) | |||
630 | } | 629 | } |
631 | 630 | ||
632 | c = optind; | 631 | c = optind; |
633 | if(host_specified == FALSE && c < argc) | 632 | if(!host_specified && c < argc) |
634 | server_address = strdup (argv[c++]); | 633 | server_address = strdup (argv[c++]); |
635 | 634 | ||
636 | if (server_address == NULL) | 635 | if (server_address == NULL) |
637 | usage4 (_("You must provide a server address")); | 636 | usage4 (_("You must provide a server address")); |
638 | else if (server_address[0] != '/' && is_host (server_address) == FALSE) | 637 | else if (server_address[0] != '/' && !is_host(server_address)) |
639 | die (STATE_CRITICAL, "%s %s - %s: %s\n", SERVICE, state_text(STATE_CRITICAL), _("Invalid hostname, address or socket"), server_address); | 638 | die (STATE_CRITICAL, "%s %s - %s: %s\n", SERVICE, state_text(STATE_CRITICAL), _("Invalid hostname, address or socket"), server_address); |
640 | 639 | ||
641 | return TRUE; | 640 | return OK; |
642 | } | 641 | } |
643 | 642 | ||
644 | 643 | ||
diff --git a/plugins/check_time.c b/plugins/check_time.c index baf8c591..f50ea427 100644 --- a/plugins/check_time.c +++ b/plugins/check_time.c | |||
@@ -45,16 +45,16 @@ enum { | |||
45 | uint32_t raw_server_time; | 45 | uint32_t raw_server_time; |
46 | unsigned long server_time, diff_time; | 46 | unsigned long server_time, diff_time; |
47 | int warning_time = 0; | 47 | int warning_time = 0; |
48 | int check_warning_time = FALSE; | 48 | bool check_warning_time = false; |
49 | int critical_time = 0; | 49 | int critical_time = 0; |
50 | int check_critical_time = FALSE; | 50 | bool check_critical_time = false; |
51 | unsigned long warning_diff = 0; | 51 | unsigned long warning_diff = 0; |
52 | int check_warning_diff = FALSE; | 52 | bool check_warning_diff = false; |
53 | unsigned long critical_diff = 0; | 53 | unsigned long critical_diff = 0; |
54 | int check_critical_diff = FALSE; | 54 | bool check_critical_diff = false; |
55 | int server_port = TIME_PORT; | 55 | int server_port = TIME_PORT; |
56 | char *server_address = NULL; | 56 | char *server_address = NULL; |
57 | int use_udp = FALSE; | 57 | bool use_udp = false; |
58 | 58 | ||
59 | int process_arguments (int, char **); | 59 | int process_arguments (int, char **); |
60 | void print_help (void); | 60 | void print_help (void); |
@@ -92,9 +92,9 @@ main (int argc, char **argv) | |||
92 | } | 92 | } |
93 | 93 | ||
94 | if (result != STATE_OK) { | 94 | if (result != STATE_OK) { |
95 | if (check_critical_time == TRUE) | 95 | if (check_critical_time) |
96 | result = STATE_CRITICAL; | 96 | result = STATE_CRITICAL; |
97 | else if (check_warning_time == TRUE) | 97 | else if (check_warning_time) |
98 | result = STATE_WARNING; | 98 | result = STATE_WARNING; |
99 | else | 99 | else |
100 | result = STATE_UNKNOWN; | 100 | result = STATE_UNKNOWN; |
@@ -105,9 +105,9 @@ main (int argc, char **argv) | |||
105 | 105 | ||
106 | if (use_udp) { | 106 | if (use_udp) { |
107 | if (send (sd, "", 0, 0) < 0) { | 107 | if (send (sd, "", 0, 0) < 0) { |
108 | if (check_critical_time == TRUE) | 108 | if (check_critical_time) |
109 | result = STATE_CRITICAL; | 109 | result = STATE_CRITICAL; |
110 | else if (check_warning_time == TRUE) | 110 | else if (check_warning_time) |
111 | result = STATE_WARNING; | 111 | result = STATE_WARNING; |
112 | else | 112 | else |
113 | result = STATE_UNKNOWN; | 113 | result = STATE_UNKNOWN; |
@@ -129,9 +129,9 @@ main (int argc, char **argv) | |||
129 | 129 | ||
130 | /* return a WARNING status if we couldn't read any data */ | 130 | /* return a WARNING status if we couldn't read any data */ |
131 | if (result <= 0) { | 131 | if (result <= 0) { |
132 | if (check_critical_time == TRUE) | 132 | if (check_critical_time) |
133 | result = STATE_CRITICAL; | 133 | result = STATE_CRITICAL; |
134 | else if (check_warning_time == TRUE) | 134 | else if (check_warning_time) |
135 | result = STATE_WARNING; | 135 | result = STATE_WARNING; |
136 | else | 136 | else |
137 | result = STATE_UNKNOWN; | 137 | result = STATE_UNKNOWN; |
@@ -143,9 +143,9 @@ main (int argc, char **argv) | |||
143 | result = STATE_OK; | 143 | result = STATE_OK; |
144 | 144 | ||
145 | conntime = (end_time - start_time); | 145 | conntime = (end_time - start_time); |
146 | if (check_critical_time == TRUE && conntime > critical_time) | 146 | if (check_critical_time&& conntime > critical_time) |
147 | result = STATE_CRITICAL; | 147 | result = STATE_CRITICAL; |
148 | else if (check_warning_time == TRUE && conntime > warning_time) | 148 | else if (check_warning_time && conntime > warning_time) |
149 | result = STATE_WARNING; | 149 | result = STATE_WARNING; |
150 | 150 | ||
151 | if (result != STATE_OK) | 151 | if (result != STATE_OK) |
@@ -154,7 +154,7 @@ main (int argc, char **argv) | |||
154 | perfdata ("time", (long)conntime, "s", | 154 | perfdata ("time", (long)conntime, "s", |
155 | check_warning_time, (long)warning_time, | 155 | check_warning_time, (long)warning_time, |
156 | check_critical_time, (long)critical_time, | 156 | check_critical_time, (long)critical_time, |
157 | TRUE, 0, FALSE, 0)); | 157 | true, 0, false, 0)); |
158 | 158 | ||
159 | server_time = ntohl (raw_server_time) - UNIX_EPOCH; | 159 | server_time = ntohl (raw_server_time) - UNIX_EPOCH; |
160 | if (server_time > (unsigned long)end_time) | 160 | if (server_time > (unsigned long)end_time) |
@@ -162,9 +162,9 @@ main (int argc, char **argv) | |||
162 | else | 162 | else |
163 | diff_time = (unsigned long)end_time - server_time; | 163 | diff_time = (unsigned long)end_time - server_time; |
164 | 164 | ||
165 | if (check_critical_diff == TRUE && diff_time > critical_diff) | 165 | if (check_critical_diff&& diff_time > critical_diff) |
166 | result = STATE_CRITICAL; | 166 | result = STATE_CRITICAL; |
167 | else if (check_warning_diff == TRUE && diff_time > warning_diff) | 167 | else if (check_warning_diff&& diff_time > warning_diff) |
168 | result = STATE_WARNING; | 168 | result = STATE_WARNING; |
169 | 169 | ||
170 | printf (_("TIME %s - %lu second time difference|%s %s\n"), | 170 | printf (_("TIME %s - %lu second time difference|%s %s\n"), |
@@ -172,11 +172,11 @@ main (int argc, char **argv) | |||
172 | perfdata ("time", (long)conntime, "s", | 172 | perfdata ("time", (long)conntime, "s", |
173 | check_warning_time, (long)warning_time, | 173 | check_warning_time, (long)warning_time, |
174 | check_critical_time, (long)critical_time, | 174 | check_critical_time, (long)critical_time, |
175 | TRUE, 0, FALSE, 0), | 175 | true, 0, false, 0), |
176 | perfdata ("offset", diff_time, "s", | 176 | perfdata ("offset", diff_time, "s", |
177 | check_warning_diff, warning_diff, | 177 | check_warning_diff, warning_diff, |
178 | check_critical_diff, critical_diff, | 178 | check_critical_diff, critical_diff, |
179 | TRUE, 0, FALSE, 0)); | 179 | true, 0, false, 0)); |
180 | return result; | 180 | return result; |
181 | } | 181 | } |
182 | 182 | ||
@@ -219,7 +219,7 @@ process_arguments (int argc, char **argv) | |||
219 | strcpy (argv[c], "-C"); | 219 | strcpy (argv[c], "-C"); |
220 | } | 220 | } |
221 | 221 | ||
222 | while (1) { | 222 | while (true) { |
223 | c = getopt_long (argc, argv, "hVH:w:c:W:C:p:t:u", longopts, | 223 | c = getopt_long (argc, argv, "hVH:w:c:W:C:p:t:u", longopts, |
224 | &option); | 224 | &option); |
225 | 225 | ||
@@ -236,19 +236,19 @@ process_arguments (int argc, char **argv) | |||
236 | print_revision (progname, NP_VERSION); | 236 | print_revision (progname, NP_VERSION); |
237 | exit (STATE_UNKNOWN); | 237 | exit (STATE_UNKNOWN); |
238 | case 'H': /* hostname */ | 238 | case 'H': /* hostname */ |
239 | if (is_host (optarg) == FALSE) | 239 | if (!is_host (optarg)) |
240 | usage2 (_("Invalid hostname/address"), optarg); | 240 | usage2 (_("Invalid hostname/address"), optarg); |
241 | server_address = optarg; | 241 | server_address = optarg; |
242 | break; | 242 | break; |
243 | case 'w': /* warning-variance */ | 243 | case 'w': /* warning-variance */ |
244 | if (is_intnonneg (optarg)) { | 244 | if (is_intnonneg (optarg)) { |
245 | warning_diff = strtoul (optarg, NULL, 10); | 245 | warning_diff = strtoul (optarg, NULL, 10); |
246 | check_warning_diff = TRUE; | 246 | check_warning_diff = true; |
247 | } | 247 | } |
248 | else if (strspn (optarg, "0123456789:,") > 0) { | 248 | else if (strspn (optarg, "0123456789:,") > 0) { |
249 | if (sscanf (optarg, "%lu%*[:,]%d", &warning_diff, &warning_time) == 2) { | 249 | if (sscanf (optarg, "%lu%*[:,]%d", &warning_diff, &warning_time) == 2) { |
250 | check_warning_diff = TRUE; | 250 | check_warning_diff = true; |
251 | check_warning_time = TRUE; | 251 | check_warning_time = true; |
252 | } | 252 | } |
253 | else { | 253 | else { |
254 | usage4 (_("Warning thresholds must be a positive integer")); | 254 | usage4 (_("Warning thresholds must be a positive integer")); |
@@ -261,13 +261,13 @@ process_arguments (int argc, char **argv) | |||
261 | case 'c': /* critical-variance */ | 261 | case 'c': /* critical-variance */ |
262 | if (is_intnonneg (optarg)) { | 262 | if (is_intnonneg (optarg)) { |
263 | critical_diff = strtoul (optarg, NULL, 10); | 263 | critical_diff = strtoul (optarg, NULL, 10); |
264 | check_critical_diff = TRUE; | 264 | check_critical_diff = true; |
265 | } | 265 | } |
266 | else if (strspn (optarg, "0123456789:,") > 0) { | 266 | else if (strspn (optarg, "0123456789:,") > 0) { |
267 | if (sscanf (optarg, "%lu%*[:,]%d", &critical_diff, &critical_time) == | 267 | if (sscanf (optarg, "%lu%*[:,]%d", &critical_diff, &critical_time) == |
268 | 2) { | 268 | 2) { |
269 | check_critical_diff = TRUE; | 269 | check_critical_diff = true; |
270 | check_critical_time = TRUE; | 270 | check_critical_time = true; |
271 | } | 271 | } |
272 | else { | 272 | else { |
273 | usage4 (_("Critical thresholds must be a positive integer")); | 273 | usage4 (_("Critical thresholds must be a positive integer")); |
@@ -282,14 +282,14 @@ process_arguments (int argc, char **argv) | |||
282 | usage4 (_("Warning threshold must be a positive integer")); | 282 | usage4 (_("Warning threshold must be a positive integer")); |
283 | else | 283 | else |
284 | warning_time = atoi (optarg); | 284 | warning_time = atoi (optarg); |
285 | check_warning_time = TRUE; | 285 | check_warning_time = true; |
286 | break; | 286 | break; |
287 | case 'C': /* critical-connect */ | 287 | case 'C': /* critical-connect */ |
288 | if (!is_intnonneg (optarg)) | 288 | if (!is_intnonneg (optarg)) |
289 | usage4 (_("Critical threshold must be a positive integer")); | 289 | usage4 (_("Critical threshold must be a positive integer")); |
290 | else | 290 | else |
291 | critical_time = atoi (optarg); | 291 | critical_time = atoi (optarg); |
292 | check_critical_time = TRUE; | 292 | check_critical_time = true; |
293 | break; | 293 | break; |
294 | case 'p': /* port */ | 294 | case 'p': /* port */ |
295 | if (!is_intnonneg (optarg)) | 295 | if (!is_intnonneg (optarg)) |
@@ -304,14 +304,14 @@ process_arguments (int argc, char **argv) | |||
304 | socket_timeout = atoi (optarg); | 304 | socket_timeout = atoi (optarg); |
305 | break; | 305 | break; |
306 | case 'u': /* udp */ | 306 | case 'u': /* udp */ |
307 | use_udp = TRUE; | 307 | use_udp = true; |
308 | } | 308 | } |
309 | } | 309 | } |
310 | 310 | ||
311 | c = optind; | 311 | c = optind; |
312 | if (server_address == NULL) { | 312 | if (server_address == NULL) { |
313 | if (argc > c) { | 313 | if (argc > c) { |
314 | if (is_host (argv[c]) == FALSE) | 314 | if (!is_host (argv[c])) |
315 | usage2 (_("Invalid hostname/address"), optarg); | 315 | usage2 (_("Invalid hostname/address"), optarg); |
316 | server_address = argv[c]; | 316 | server_address = argv[c]; |
317 | } | 317 | } |
diff --git a/plugins/check_ups.c b/plugins/check_ups.c index 68737c4b..380ff3bc 100644 --- a/plugins/check_ups.c +++ b/plugins/check_ups.c | |||
@@ -1,665 +1,746 @@ | |||
1 | /***************************************************************************** | 1 | /***************************************************************************** |
2 | * | 2 | * |
3 | * Monitoring check_ups plugin | 3 | * Monitoring check_ups plugin |
4 | * | 4 | * |
5 | * License: GPL | 5 | * License: GPL |
6 | * Copyright (c) 2000 Tom Shields | 6 | * Copyright (c) 2000 Tom Shields |
7 | * 2004 Alain Richard <alain.richard@equation.fr> | 7 | * 2004 Alain Richard <alain.richard@equation.fr> |
8 | * 2004 Arnaud Quette <arnaud.quette@mgeups.com> | 8 | * 2004 Arnaud Quette <arnaud.quette@mgeups.com> |
9 | * Copyright (c) 2002-2007 Monitoring Plugins Development Team | 9 | * Copyright (c) 2002-2023 Monitoring Plugins Development Team |
10 | * | 10 | * |
11 | * Description: | 11 | * Description: |
12 | * | 12 | * |
13 | * This file contains Network UPS Tools plugin for Monitoring | 13 | * This file contains Network UPS Tools plugin for Monitoring |
14 | * | 14 | * |
15 | * This plugin tests the UPS service on the specified host. Network UPS Tools | 15 | * This plugin tests the UPS service on the specified host. Network UPS Tools |
16 | * from www.networkupstools.org must be running for this plugin to work. | 16 | * from www.networkupstools.org must be running for this plugin to work. |
17 | * | 17 | * |
18 | * | 18 | * |
19 | * This program is free software: you can redistribute it and/or modify | 19 | * This program is free software: you can redistribute it and/or modify |
20 | * it under the terms of the GNU General Public License as published by | 20 | * it under the terms of the GNU General Public License as published by |
21 | * the Free Software Foundation, either version 3 of the License, or | 21 | * the Free Software Foundation, either version 3 of the License, or |
22 | * (at your option) any later version. | 22 | * (at your option) any later version. |
23 | * | 23 | * |
24 | * This program is distributed in the hope that it will be useful, | 24 | * This program is distributed in the hope that it will be useful, |
25 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 25 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
26 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 26 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
27 | * GNU General Public License for more details. | 27 | * GNU General Public License for more details. |
28 | * | 28 | * |
29 | * You should have received a copy of the GNU General Public License | 29 | * You should have received a copy of the GNU General Public License |
30 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 30 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
31 | * | 31 | * |
32 | * | 32 | * |
33 | *****************************************************************************/ | 33 | *****************************************************************************/ |
34 | 34 | ||
35 | const char *progname = "check_ups"; | 35 | const char *progname = "check_ups"; |
36 | const char *copyright = "2000-2007"; | 36 | const char *copyright = "2000-2023"; |
37 | const char *email = "devel@monitoring-plugins.org"; | 37 | const char *email = "devel@monitoring-plugins.org"; |
38 | 38 | ||
39 | #include "common.h" | 39 | #include "common.h" |
40 | #include "netutils.h" | 40 | #include "netutils.h" |
41 | #include "utils.h" | 41 | #include "utils.h" |
42 | 42 | ||
43 | enum { | 43 | enum { PORT = 3493 }; |
44 | PORT = 3493 | 44 | |
45 | }; | 45 | #define UPS_NONE 0 /* no supported options */ |
46 | 46 | #define UPS_UTILITY 1 /* supports utility line */ | |
47 | #define CHECK_NONE 0 | 47 | #define UPS_BATTPCT 2 /* supports percent battery remaining */ |
48 | 48 | #define UPS_STATUS 4 /* supports UPS status */ | |
49 | #define UPS_NONE 0 /* no supported options */ | 49 | #define UPS_TEMP 8 /* supports UPS temperature */ |
50 | #define UPS_UTILITY 1 /* supports utility line voltage */ | 50 | #define UPS_LOADPCT 16 /* supports load percent */ |
51 | #define UPS_BATTPCT 2 /* supports percent battery remaining */ | 51 | #define UPS_REALPOWER 32 /* supports real power */ |
52 | #define UPS_STATUS 4 /* supports UPS status */ | 52 | |
53 | #define UPS_TEMP 8 /* supports UPS temperature */ | 53 | #define UPSSTATUS_NONE 0 |
54 | #define UPS_LOADPCT 16 /* supports load percent */ | 54 | #define UPSSTATUS_OFF 1 |
55 | 55 | #define UPSSTATUS_OL 2 | |
56 | #define UPSSTATUS_NONE 0 | 56 | #define UPSSTATUS_OB 4 |
57 | #define UPSSTATUS_OFF 1 | 57 | #define UPSSTATUS_LB 8 |
58 | #define UPSSTATUS_OL 2 | 58 | #define UPSSTATUS_CAL 16 |
59 | #define UPSSTATUS_OB 4 | 59 | #define UPSSTATUS_RB 32 /*Replace Battery */ |
60 | #define UPSSTATUS_LB 8 | 60 | #define UPSSTATUS_BYPASS 64 |
61 | #define UPSSTATUS_CAL 16 | 61 | #define UPSSTATUS_OVER 128 |
62 | #define UPSSTATUS_RB 32 /*Replace Battery */ | 62 | #define UPSSTATUS_TRIM 256 |
63 | #define UPSSTATUS_BYPASS 64 | 63 | #define UPSSTATUS_BOOST 512 |
64 | #define UPSSTATUS_OVER 128 | ||
65 | #define UPSSTATUS_TRIM 256 | ||
66 | #define UPSSTATUS_BOOST 512 | ||
67 | #define UPSSTATUS_CHRG 1024 | 64 | #define UPSSTATUS_CHRG 1024 |
68 | #define UPSSTATUS_DISCHRG 2048 | 65 | #define UPSSTATUS_DISCHRG 2048 |
69 | #define UPSSTATUS_UNKNOWN 4096 | 66 | #define UPSSTATUS_UNKNOWN 4096 |
70 | 67 | #define UPSSTATUS_ALARM 8192 | |
71 | enum { NOSUCHVAR = ERROR-1 }; | 68 | |
72 | 69 | enum { NOSUCHVAR = ERROR - 1 }; | |
73 | int server_port = PORT; | 70 | |
74 | char *server_address; | 71 | typedef struct ups_config { |
75 | char *ups_name = NULL; | 72 | unsigned int server_port; |
76 | double warning_value = 0.0; | 73 | char *server_address; |
77 | double critical_value = 0.0; | 74 | char *ups_name; |
78 | int check_warn = FALSE; | 75 | double warning_value; |
79 | int check_crit = FALSE; | 76 | double critical_value; |
80 | int check_variable = UPS_NONE; | 77 | bool check_warn; |
81 | int supported_options = UPS_NONE; | 78 | bool check_crit; |
82 | int status = UPSSTATUS_NONE; | 79 | int check_variable; |
83 | 80 | int status; | |
84 | double ups_utility_voltage = 0.0; | 81 | bool temp_output_c; |
85 | double ups_battery_percent = 0.0; | 82 | } ups_config; |
86 | double ups_load_percent = 0.0; | 83 | |
87 | double ups_temperature = 0.0; | 84 | ups_config ups_config_init(void) { |
88 | char *ups_status; | 85 | ups_config tmp = {0}; |
89 | int temp_output_c = 0; | 86 | tmp.server_port = PORT; |
90 | 87 | tmp.server_address = NULL; | |
91 | int determine_status (void); | 88 | tmp.ups_name = NULL; |
92 | int get_ups_variable (const char *, char *); | 89 | tmp.check_variable = UPS_NONE; |
93 | 90 | tmp.status = UPSSTATUS_NONE; | |
94 | int process_arguments (int, char **); | 91 | |
95 | int validate_arguments (void); | 92 | return tmp; |
96 | void print_help (void); | 93 | } |
97 | void print_usage (void); | 94 | |
98 | 95 | // Forward declarations | |
99 | int | 96 | int determine_status(ups_config *, int *supported_options); |
100 | main (int argc, char **argv) | 97 | int get_ups_variable(const char *, char *, const ups_config config); |
101 | { | 98 | |
102 | int result = STATE_UNKNOWN; | 99 | int process_arguments(int, char **, ups_config *); |
103 | char *message; | 100 | int validate_arguments(ups_config); |
101 | void print_help(void); | ||
102 | void print_usage(void); | ||
103 | |||
104 | int main(int argc, char **argv) { | ||
105 | setlocale(LC_ALL, ""); | ||
106 | bindtextdomain(PACKAGE, LOCALEDIR); | ||
107 | textdomain(PACKAGE); | ||
108 | |||
109 | char *ups_status; | ||
110 | ups_status = strdup("N/A"); | ||
111 | |||
104 | char *data; | 112 | char *data; |
105 | char *tunits; | 113 | data = strdup(""); |
106 | char temp_buffer[MAX_INPUT_BUFFER]; | ||
107 | double ups_utility_deviation = 0.0; | ||
108 | int res; | ||
109 | 114 | ||
110 | setlocale (LC_ALL, ""); | 115 | char *message; |
111 | bindtextdomain (PACKAGE, LOCALEDIR); | 116 | message = strdup(""); |
112 | textdomain (PACKAGE); | ||
113 | 117 | ||
114 | ups_status = strdup ("N/A"); | 118 | // Exit result |
115 | data = strdup (""); | 119 | int result = STATE_UNKNOWN; |
116 | message = strdup (""); | ||
117 | 120 | ||
118 | /* Parse extra opts if any */ | 121 | /* Parse extra opts if any */ |
119 | argv=np_extra_opts (&argc, argv, progname); | 122 | argv = np_extra_opts(&argc, argv, progname); |
120 | 123 | ||
121 | if (process_arguments (argc, argv) == ERROR) | 124 | // Config from commandline |
122 | usage4 (_("Could not parse arguments")); | 125 | ups_config config = ups_config_init(); |
126 | |||
127 | if (process_arguments(argc, argv, &config) == ERROR) { | ||
128 | usage4(_("Could not parse arguments")); | ||
129 | } | ||
123 | 130 | ||
124 | /* initialize alarm signal handling */ | 131 | /* initialize alarm signal handling */ |
125 | signal (SIGALRM, socket_timeout_alarm_handler); | 132 | signal(SIGALRM, socket_timeout_alarm_handler); |
126 | 133 | ||
127 | /* set socket timeout */ | 134 | /* set socket timeout */ |
128 | alarm (socket_timeout); | 135 | alarm(socket_timeout); |
136 | |||
137 | int supported_options = UPS_NONE; | ||
129 | 138 | ||
130 | /* get the ups status if possible */ | 139 | /* get the ups status if possible */ |
131 | if (determine_status () != OK) | 140 | if (determine_status(&config, &supported_options) != OK) { |
132 | return STATE_CRITICAL; | 141 | return STATE_CRITICAL; |
142 | } | ||
143 | |||
144 | |||
133 | if (supported_options & UPS_STATUS) { | 145 | if (supported_options & UPS_STATUS) { |
134 | 146 | ||
135 | ups_status = strdup (""); | 147 | ups_status = strdup(""); |
148 | |||
136 | result = STATE_OK; | 149 | result = STATE_OK; |
137 | 150 | ||
138 | if (status & UPSSTATUS_OFF) { | 151 | if (config.status & UPSSTATUS_OFF) { |
139 | xasprintf (&ups_status, "Off"); | 152 | xasprintf(&ups_status, "Off"); |
140 | result = STATE_CRITICAL; | 153 | result = STATE_CRITICAL; |
141 | } | 154 | } else if ((config.status & (UPSSTATUS_OB | UPSSTATUS_LB)) == |
142 | else if ((status & (UPSSTATUS_OB | UPSSTATUS_LB)) == | 155 | (UPSSTATUS_OB | UPSSTATUS_LB)) { |
143 | (UPSSTATUS_OB | UPSSTATUS_LB)) { | 156 | xasprintf(&ups_status, _("On Battery, Low Battery")); |
144 | xasprintf (&ups_status, _("On Battery, Low Battery")); | ||
145 | result = STATE_CRITICAL; | 157 | result = STATE_CRITICAL; |
146 | } | 158 | } else { |
147 | else { | 159 | if (config.status & UPSSTATUS_OL) { |
148 | if (status & UPSSTATUS_OL) { | 160 | xasprintf(&ups_status, "%s%s", ups_status, _("Online")); |
149 | xasprintf (&ups_status, "%s%s", ups_status, _("Online")); | ||
150 | } | 161 | } |
151 | if (status & UPSSTATUS_OB) { | 162 | if (config.status & UPSSTATUS_OB) { |
152 | xasprintf (&ups_status, "%s%s", ups_status, _("On Battery")); | 163 | xasprintf(&ups_status, "%s%s", ups_status, _("On Battery")); |
153 | result = STATE_WARNING; | 164 | result = max_state(result, STATE_WARNING); |
154 | } | 165 | } |
155 | if (status & UPSSTATUS_LB) { | 166 | if (config.status & UPSSTATUS_LB) { |
156 | xasprintf (&ups_status, "%s%s", ups_status, _(", Low Battery")); | 167 | xasprintf(&ups_status, "%s%s", ups_status, _(", Low Battery")); |
157 | result = STATE_WARNING; | 168 | result = max_state(result, STATE_WARNING); |
158 | } | 169 | } |
159 | if (status & UPSSTATUS_CAL) { | 170 | if (config.status & UPSSTATUS_CAL) { |
160 | xasprintf (&ups_status, "%s%s", ups_status, _(", Calibrating")); | 171 | xasprintf(&ups_status, "%s%s", ups_status, _(", Calibrating")); |
161 | } | 172 | } |
162 | if (status & UPSSTATUS_RB) { | 173 | if (config.status & UPSSTATUS_RB) { |
163 | xasprintf (&ups_status, "%s%s", ups_status, _(", Replace Battery")); | 174 | xasprintf(&ups_status, "%s%s", ups_status, |
164 | result = STATE_WARNING; | 175 | _(", Replace Battery")); |
176 | result = max_state(result, STATE_WARNING); | ||
165 | } | 177 | } |
166 | if (status & UPSSTATUS_BYPASS) { | 178 | if (config.status & UPSSTATUS_BYPASS) { |
167 | xasprintf (&ups_status, "%s%s", ups_status, _(", On Bypass")); | 179 | xasprintf(&ups_status, "%s%s", ups_status, _(", On Bypass")); |
180 | // Bypassing the battery is likely a bad thing | ||
181 | result = STATE_CRITICAL; | ||
182 | } | ||
183 | if (config.status & UPSSTATUS_OVER) { | ||
184 | xasprintf(&ups_status, "%s%s", ups_status, _(", Overload")); | ||
185 | result = max_state(result, STATE_WARNING); | ||
168 | } | 186 | } |
169 | if (status & UPSSTATUS_OVER) { | 187 | if (config.status & UPSSTATUS_TRIM) { |
170 | xasprintf (&ups_status, "%s%s", ups_status, _(", Overload")); | 188 | xasprintf(&ups_status, "%s%s", ups_status, _(", Trimming")); |
171 | } | 189 | } |
172 | if (status & UPSSTATUS_TRIM) { | 190 | if (config.status & UPSSTATUS_BOOST) { |
173 | xasprintf (&ups_status, "%s%s", ups_status, _(", Trimming")); | 191 | xasprintf(&ups_status, "%s%s", ups_status, _(", Boosting")); |
174 | } | 192 | } |
175 | if (status & UPSSTATUS_BOOST) { | 193 | if (config.status & UPSSTATUS_CHRG) { |
176 | xasprintf (&ups_status, "%s%s", ups_status, _(", Boosting")); | 194 | xasprintf(&ups_status, "%s%s", ups_status, _(", Charging")); |
177 | } | 195 | } |
178 | if (status & UPSSTATUS_CHRG) { | 196 | if (config.status & UPSSTATUS_DISCHRG) { |
179 | xasprintf (&ups_status, "%s%s", ups_status, _(", Charging")); | 197 | xasprintf(&ups_status, "%s%s", ups_status, _(", Discharging")); |
198 | result = max_state(result, STATE_WARNING); | ||
180 | } | 199 | } |
181 | if (status & UPSSTATUS_DISCHRG) { | 200 | if (config.status & UPSSTATUS_ALARM) { |
182 | xasprintf (&ups_status, "%s%s", ups_status, _(", Discharging")); | 201 | xasprintf(&ups_status, "%s%s", ups_status, _(", ALARM")); |
202 | result = STATE_CRITICAL; | ||
183 | } | 203 | } |
184 | if (status & UPSSTATUS_UNKNOWN) { | 204 | if (config.status & UPSSTATUS_UNKNOWN) { |
185 | xasprintf (&ups_status, "%s%s", ups_status, _(", Unknown")); | 205 | xasprintf(&ups_status, "%s%s", ups_status, _(", Unknown")); |
186 | } | 206 | } |
187 | } | 207 | } |
188 | xasprintf (&message, "%sStatus=%s ", message, ups_status); | 208 | xasprintf(&message, "%sStatus=%s ", message, ups_status); |
189 | } | 209 | } |
190 | 210 | ||
211 | int res; | ||
212 | char temp_buffer[MAX_INPUT_BUFFER]; | ||
213 | |||
191 | /* get the ups utility voltage if possible */ | 214 | /* get the ups utility voltage if possible */ |
192 | res=get_ups_variable ("input.voltage", temp_buffer); | 215 | res = get_ups_variable("input.voltage", temp_buffer, config); |
193 | if (res == NOSUCHVAR) supported_options &= ~UPS_UTILITY; | 216 | if (res == NOSUCHVAR) { |
194 | else if (res != OK) | 217 | supported_options &= ~UPS_UTILITY; |
218 | } else if (res != OK) { | ||
195 | return STATE_CRITICAL; | 219 | return STATE_CRITICAL; |
196 | else { | 220 | } else { |
197 | supported_options |= UPS_UTILITY; | 221 | supported_options |= UPS_UTILITY; |
198 | 222 | ||
199 | ups_utility_voltage = atof (temp_buffer); | 223 | double ups_utility_voltage = 0.0; |
200 | xasprintf (&message, "%sUtility=%3.1fV ", message, ups_utility_voltage); | 224 | ups_utility_voltage = atof(temp_buffer); |
225 | xasprintf(&message, "%sUtility=%3.1fV ", message, ups_utility_voltage); | ||
226 | |||
227 | double ups_utility_deviation = 0.0; | ||
201 | 228 | ||
202 | if (ups_utility_voltage > 120.0) | 229 | if (ups_utility_voltage > 120.0) { |
203 | ups_utility_deviation = 120.0 - ups_utility_voltage; | 230 | ups_utility_deviation = 120.0 - ups_utility_voltage; |
204 | else | 231 | } else { |
205 | ups_utility_deviation = ups_utility_voltage - 120.0; | 232 | ups_utility_deviation = ups_utility_voltage - 120.0; |
233 | } | ||
206 | 234 | ||
207 | if (check_variable == UPS_UTILITY) { | 235 | if (config.check_variable == UPS_UTILITY) { |
208 | if (check_crit==TRUE && ups_utility_deviation>=critical_value) { | 236 | if (config.check_crit && |
237 | ups_utility_deviation >= config.critical_value) { | ||
209 | result = STATE_CRITICAL; | 238 | result = STATE_CRITICAL; |
239 | } else if (config.check_warn && | ||
240 | ups_utility_deviation >= config.warning_value) { | ||
241 | result = max_state(result, STATE_WARNING); | ||
210 | } | 242 | } |
211 | else if (check_warn==TRUE && ups_utility_deviation>=warning_value) { | 243 | xasprintf(&data, "%s", |
212 | result = max_state (result, STATE_WARNING); | 244 | perfdata("voltage", (long)(1000 * ups_utility_voltage), |
213 | } | 245 | "mV", config.check_warn, |
214 | xasprintf (&data, "%s", | 246 | (long)(1000 * config.warning_value), |
215 | perfdata ("voltage", (long)(1000*ups_utility_voltage), "mV", | 247 | config.check_crit, |
216 | check_warn, (long)(1000*warning_value), | 248 | (long)(1000 * config.critical_value), true, 0, |
217 | check_crit, (long)(1000*critical_value), | 249 | false, 0)); |
218 | TRUE, 0, FALSE, 0)); | ||
219 | } else { | 250 | } else { |
220 | xasprintf (&data, "%s", | 251 | xasprintf(&data, "%s", |
221 | perfdata ("voltage", (long)(1000*ups_utility_voltage), "mV", | 252 | perfdata("voltage", (long)(1000 * ups_utility_voltage), |
222 | FALSE, 0, FALSE, 0, TRUE, 0, FALSE, 0)); | 253 | "mV", false, 0, false, 0, true, 0, false, 0)); |
223 | } | 254 | } |
224 | } | 255 | } |
225 | 256 | ||
226 | /* get the ups battery percent if possible */ | 257 | /* get the ups battery percent if possible */ |
227 | res=get_ups_variable ("battery.charge", temp_buffer); | 258 | res = get_ups_variable("battery.charge", temp_buffer, config); |
228 | if (res == NOSUCHVAR) supported_options &= ~UPS_BATTPCT; | 259 | if (res == NOSUCHVAR) { |
229 | else if ( res != OK) | 260 | supported_options &= ~UPS_BATTPCT; |
261 | } else if (res != OK) { | ||
230 | return STATE_CRITICAL; | 262 | return STATE_CRITICAL; |
231 | else { | 263 | } else { |
232 | supported_options |= UPS_BATTPCT; | 264 | supported_options |= UPS_BATTPCT; |
233 | ups_battery_percent = atof (temp_buffer); | ||
234 | xasprintf (&message, "%sBatt=%3.1f%% ", message, ups_battery_percent); | ||
235 | 265 | ||
236 | if (check_variable == UPS_BATTPCT) { | 266 | double ups_battery_percent = 0.0; |
237 | if (check_crit==TRUE && ups_battery_percent <= critical_value) { | 267 | ups_battery_percent = atof(temp_buffer); |
268 | xasprintf(&message, "%sBatt=%3.1f%% ", message, ups_battery_percent); | ||
269 | |||
270 | if (config.check_variable == UPS_BATTPCT) { | ||
271 | if (config.check_crit && | ||
272 | ups_battery_percent <= config.critical_value) { | ||
238 | result = STATE_CRITICAL; | 273 | result = STATE_CRITICAL; |
274 | } else if (config.check_warn && | ||
275 | ups_battery_percent <= config.warning_value) { | ||
276 | result = max_state(result, STATE_WARNING); | ||
239 | } | 277 | } |
240 | else if (check_warn==TRUE && ups_battery_percent<=warning_value) { | 278 | xasprintf(&data, "%s %s", data, |
241 | result = max_state (result, STATE_WARNING); | 279 | perfdata("battery", (long)ups_battery_percent, "%", |
242 | } | 280 | config.check_warn, (long)(config.warning_value), |
243 | xasprintf (&data, "%s %s", data, | 281 | config.check_crit, (long)(config.critical_value), |
244 | perfdata ("battery", (long)ups_battery_percent, "%", | 282 | true, 0, true, 100)); |
245 | check_warn, (long)(warning_value), | ||
246 | check_crit, (long)(critical_value), | ||
247 | TRUE, 0, TRUE, 100)); | ||
248 | } else { | 283 | } else { |
249 | xasprintf (&data, "%s %s", data, | 284 | xasprintf(&data, "%s %s", data, |
250 | perfdata ("battery", (long)ups_battery_percent, "%", | 285 | perfdata("battery", (long)ups_battery_percent, "%", false, |
251 | FALSE, 0, FALSE, 0, TRUE, 0, TRUE, 100)); | 286 | 0, false, 0, true, 0, true, 100)); |
252 | } | 287 | } |
253 | } | 288 | } |
254 | 289 | ||
255 | /* get the ups load percent if possible */ | 290 | /* get the ups load percent if possible */ |
256 | res=get_ups_variable ("ups.load", temp_buffer); | 291 | res = get_ups_variable("ups.load", temp_buffer, config); |
257 | if ( res == NOSUCHVAR ) supported_options &= ~UPS_LOADPCT; | 292 | if (res == NOSUCHVAR) { |
258 | else if ( res != OK) | 293 | supported_options &= ~UPS_LOADPCT; |
294 | } else if (res != OK) { | ||
259 | return STATE_CRITICAL; | 295 | return STATE_CRITICAL; |
260 | else { | 296 | } else { |
261 | supported_options |= UPS_LOADPCT; | 297 | supported_options |= UPS_LOADPCT; |
262 | ups_load_percent = atof (temp_buffer); | ||
263 | xasprintf (&message, "%sLoad=%3.1f%% ", message, ups_load_percent); | ||
264 | 298 | ||
265 | if (check_variable == UPS_LOADPCT) { | 299 | double ups_load_percent = 0.0; |
266 | if (check_crit==TRUE && ups_load_percent>=critical_value) { | 300 | ups_load_percent = atof(temp_buffer); |
301 | xasprintf(&message, "%sLoad=%3.1f%% ", message, ups_load_percent); | ||
302 | |||
303 | if (config.check_variable == UPS_LOADPCT) { | ||
304 | if (config.check_crit && | ||
305 | ups_load_percent >= config.critical_value) { | ||
267 | result = STATE_CRITICAL; | 306 | result = STATE_CRITICAL; |
307 | } else if (config.check_warn && | ||
308 | ups_load_percent >= config.warning_value) { | ||
309 | result = max_state(result, STATE_WARNING); | ||
268 | } | 310 | } |
269 | else if (check_warn==TRUE && ups_load_percent>=warning_value) { | 311 | xasprintf(&data, "%s %s", data, |
270 | result = max_state (result, STATE_WARNING); | 312 | perfdata("load", (long)ups_load_percent, "%", |
271 | } | 313 | config.check_warn, (long)(config.warning_value), |
272 | xasprintf (&data, "%s %s", data, | 314 | config.check_crit, (long)(config.critical_value), |
273 | perfdata ("load", (long)ups_load_percent, "%", | 315 | true, 0, true, 100)); |
274 | check_warn, (long)(warning_value), | ||
275 | check_crit, (long)(critical_value), | ||
276 | TRUE, 0, TRUE, 100)); | ||
277 | } else { | 316 | } else { |
278 | xasprintf (&data, "%s %s", data, | 317 | xasprintf(&data, "%s %s", data, |
279 | perfdata ("load", (long)ups_load_percent, "%", | 318 | perfdata("load", (long)ups_load_percent, "%", false, 0, |
280 | FALSE, 0, FALSE, 0, TRUE, 0, TRUE, 100)); | 319 | false, 0, true, 0, true, 100)); |
281 | } | 320 | } |
282 | } | 321 | } |
283 | 322 | ||
284 | /* get the ups temperature if possible */ | 323 | /* get the ups temperature if possible */ |
285 | res=get_ups_variable ("ups.temperature", temp_buffer); | 324 | res = get_ups_variable("ups.temperature", temp_buffer, config); |
286 | if ( res == NOSUCHVAR ) supported_options &= ~UPS_TEMP; | 325 | if (res == NOSUCHVAR) { |
287 | else if ( res != OK) | 326 | supported_options &= ~UPS_TEMP; |
327 | } else if (res != OK) { | ||
288 | return STATE_CRITICAL; | 328 | return STATE_CRITICAL; |
289 | else { | 329 | } else { |
290 | supported_options |= UPS_TEMP; | 330 | supported_options |= UPS_TEMP; |
291 | if (temp_output_c) { | 331 | |
292 | tunits="degC"; | 332 | double ups_temperature = 0.0; |
293 | ups_temperature = atof (temp_buffer); | 333 | char *tunits; |
294 | xasprintf (&message, "%sTemp=%3.1fC", message, ups_temperature); | 334 | |
295 | } | 335 | if (config.temp_output_c) { |
296 | else { | 336 | tunits = "degC"; |
297 | tunits="degF"; | 337 | ups_temperature = atof(temp_buffer); |
298 | ups_temperature = (atof (temp_buffer) * 1.8) + 32; | 338 | xasprintf(&message, "%sTemp=%3.1fC", message, ups_temperature); |
299 | xasprintf (&message, "%sTemp=%3.1fF", message, ups_temperature); | 339 | } else { |
340 | tunits = "degF"; | ||
341 | ups_temperature = (atof(temp_buffer) * 1.8) + 32; | ||
342 | xasprintf(&message, "%sTemp=%3.1fF", message, ups_temperature); | ||
300 | } | 343 | } |
301 | 344 | ||
302 | if (check_variable == UPS_TEMP) { | 345 | if (config.check_variable == UPS_TEMP) { |
303 | if (check_crit==TRUE && ups_temperature>=critical_value) { | 346 | if (config.check_crit && ups_temperature >= config.critical_value) { |
304 | result = STATE_CRITICAL; | 347 | result = STATE_CRITICAL; |
348 | } else if (config.check_warn && | ||
349 | ups_temperature >= config.warning_value) { | ||
350 | result = max_state(result, STATE_WARNING); | ||
305 | } | 351 | } |
306 | else if (check_warn == TRUE && ups_temperature>=warning_value) { | 352 | xasprintf(&data, "%s %s", data, |
307 | result = max_state (result, STATE_WARNING); | 353 | perfdata("temp", (long)ups_temperature, tunits, |
354 | config.check_warn, (long)(config.warning_value), | ||
355 | config.check_crit, (long)(config.critical_value), | ||
356 | true, 0, false, 0)); | ||
357 | } else { | ||
358 | xasprintf(&data, "%s %s", data, | ||
359 | perfdata("temp", (long)ups_temperature, tunits, false, 0, | ||
360 | false, 0, true, 0, false, 0)); | ||
361 | } | ||
362 | } | ||
363 | |||
364 | /* get the ups real power if possible */ | ||
365 | res = get_ups_variable("ups.realpower", temp_buffer, config); | ||
366 | if (res == NOSUCHVAR) { | ||
367 | supported_options &= ~UPS_REALPOWER; | ||
368 | } else if (res != OK) { | ||
369 | return STATE_CRITICAL; | ||
370 | } else { | ||
371 | supported_options |= UPS_REALPOWER; | ||
372 | double ups_realpower = 0.0; | ||
373 | ups_realpower = atof(temp_buffer); | ||
374 | xasprintf(&message, "%sReal power=%3.1fW ", message, ups_realpower); | ||
375 | |||
376 | if (config.check_variable == UPS_REALPOWER) { | ||
377 | if (config.check_crit && ups_realpower >= config.critical_value) { | ||
378 | result = STATE_CRITICAL; | ||
379 | } else if (config.check_warn && | ||
380 | ups_realpower >= config.warning_value) { | ||
381 | result = max_state(result, STATE_WARNING); | ||
308 | } | 382 | } |
309 | xasprintf (&data, "%s %s", data, | 383 | xasprintf(&data, "%s %s", data, |
310 | perfdata ("temp", (long)ups_temperature, tunits, | 384 | perfdata("realpower", (long)ups_realpower, "W", |
311 | check_warn, (long)(warning_value), | 385 | config.check_warn, (long)(config.warning_value), |
312 | check_crit, (long)(critical_value), | 386 | config.check_crit, (long)(config.critical_value), |
313 | TRUE, 0, FALSE, 0)); | 387 | true, 0, false, 0)); |
314 | } else { | 388 | } else { |
315 | xasprintf (&data, "%s %s", data, | 389 | xasprintf(&data, "%s %s", data, |
316 | perfdata ("temp", (long)ups_temperature, tunits, | 390 | perfdata("realpower", (long)ups_realpower, "W", false, 0, |
317 | FALSE, 0, FALSE, 0, TRUE, 0, FALSE, 0)); | 391 | false, 0, true, 0, false, 0)); |
318 | } | 392 | } |
319 | } | 393 | } |
320 | 394 | ||
321 | /* if the UPS does not support any options we are looking for, report an error */ | 395 | /* if the UPS does not support any options we are looking for, report an |
396 | * error */ | ||
322 | if (supported_options == UPS_NONE) { | 397 | if (supported_options == UPS_NONE) { |
323 | result = STATE_CRITICAL; | 398 | result = STATE_CRITICAL; |
324 | xasprintf (&message, _("UPS does not support any available options\n")); | 399 | xasprintf(&message, _("UPS does not support any available options\n")); |
325 | } | 400 | } |
326 | 401 | ||
327 | /* reset timeout */ | 402 | /* reset timeout */ |
328 | alarm (0); | 403 | alarm(0); |
329 | 404 | ||
330 | printf ("UPS %s - %s|%s\n", state_text(result), message, data); | 405 | printf("UPS %s - %s|%s\n", state_text(result), message, data); |
331 | return result; | 406 | return result; |
332 | } | 407 | } |
333 | 408 | ||
334 | |||
335 | |||
336 | /* determines what options are supported by the UPS */ | 409 | /* determines what options are supported by the UPS */ |
337 | int | 410 | int determine_status(ups_config *config, int *supported_options) { |
338 | determine_status (void) | ||
339 | { | ||
340 | char recv_buffer[MAX_INPUT_BUFFER]; | 411 | char recv_buffer[MAX_INPUT_BUFFER]; |
341 | char temp_buffer[MAX_INPUT_BUFFER]; | ||
342 | char *ptr; | ||
343 | int res; | ||
344 | 412 | ||
345 | res=get_ups_variable ("ups.status", recv_buffer); | 413 | int res = get_ups_variable("ups.status", recv_buffer, *config); |
346 | if (res == NOSUCHVAR) return OK; | 414 | if (res == NOSUCHVAR) { |
415 | return OK; | ||
416 | } | ||
417 | |||
347 | if (res != STATE_OK) { | 418 | if (res != STATE_OK) { |
348 | printf ("%s\n", _("Invalid response received from host")); | 419 | printf("%s\n", _("Invalid response received from host")); |
349 | return ERROR; | 420 | return ERROR; |
350 | } | 421 | } |
351 | 422 | ||
352 | supported_options |= UPS_STATUS; | 423 | *supported_options |= UPS_STATUS; |
353 | 424 | ||
354 | strcpy (temp_buffer, recv_buffer); | 425 | char temp_buffer[MAX_INPUT_BUFFER]; |
355 | for (ptr = (char *) strtok (temp_buffer, " "); ptr != NULL; | 426 | |
356 | ptr = (char *) strtok (NULL, " ")) { | 427 | strcpy(temp_buffer, recv_buffer); |
357 | if (!strcmp (ptr, "OFF")) | 428 | for (char *ptr = (char *)strtok(temp_buffer, " "); ptr != NULL; |
358 | status |= UPSSTATUS_OFF; | 429 | ptr = (char *)strtok(NULL, " ")) { |
359 | else if (!strcmp (ptr, "OL")) | 430 | if (!strcmp(ptr, "OFF")) { |
360 | status |= UPSSTATUS_OL; | 431 | config->status |= UPSSTATUS_OFF; |
361 | else if (!strcmp (ptr, "OB")) | 432 | } else if (!strcmp(ptr, "OL")) { |
362 | status |= UPSSTATUS_OB; | 433 | config->status |= UPSSTATUS_OL; |
363 | else if (!strcmp (ptr, "LB")) | 434 | } else if (!strcmp(ptr, "OB")) { |
364 | status |= UPSSTATUS_LB; | 435 | config->status |= UPSSTATUS_OB; |
365 | else if (!strcmp (ptr, "CAL")) | 436 | } else if (!strcmp(ptr, "LB")) { |
366 | status |= UPSSTATUS_CAL; | 437 | config->status |= UPSSTATUS_LB; |
367 | else if (!strcmp (ptr, "RB")) | 438 | } else if (!strcmp(ptr, "CAL")) { |
368 | status |= UPSSTATUS_RB; | 439 | config->status |= UPSSTATUS_CAL; |
369 | else if (!strcmp (ptr, "BYPASS")) | 440 | } else if (!strcmp(ptr, "RB")) { |
370 | status |= UPSSTATUS_BYPASS; | 441 | config->status |= UPSSTATUS_RB; |
371 | else if (!strcmp (ptr, "OVER")) | 442 | } else if (!strcmp(ptr, "BYPASS")) { |
372 | status |= UPSSTATUS_OVER; | 443 | config->status |= UPSSTATUS_BYPASS; |
373 | else if (!strcmp (ptr, "TRIM")) | 444 | } else if (!strcmp(ptr, "OVER")) { |
374 | status |= UPSSTATUS_TRIM; | 445 | config->status |= UPSSTATUS_OVER; |
375 | else if (!strcmp (ptr, "BOOST")) | 446 | } else if (!strcmp(ptr, "TRIM")) { |
376 | status |= UPSSTATUS_BOOST; | 447 | config->status |= UPSSTATUS_TRIM; |
377 | else if (!strcmp (ptr, "CHRG")) | 448 | } else if (!strcmp(ptr, "BOOST")) { |
378 | status |= UPSSTATUS_CHRG; | 449 | config->status |= UPSSTATUS_BOOST; |
379 | else if (!strcmp (ptr, "DISCHRG")) | 450 | } else if (!strcmp(ptr, "CHRG")) { |
380 | status |= UPSSTATUS_DISCHRG; | 451 | config->status |= UPSSTATUS_CHRG; |
381 | else | 452 | } else if (!strcmp(ptr, "DISCHRG")) { |
382 | status |= UPSSTATUS_UNKNOWN; | 453 | config->status |= UPSSTATUS_DISCHRG; |
454 | } else if (!strcmp(ptr, "ALARM")) { | ||
455 | config->status |= UPSSTATUS_ALARM; | ||
456 | } else { | ||
457 | config->status |= UPSSTATUS_UNKNOWN; | ||
458 | } | ||
383 | } | 459 | } |
384 | 460 | ||
385 | return OK; | 461 | return OK; |
386 | } | 462 | } |
387 | 463 | ||
388 | |||
389 | /* gets a variable value for a specific UPS */ | 464 | /* gets a variable value for a specific UPS */ |
390 | int | 465 | int get_ups_variable(const char *varname, char *buf, const ups_config config) { |
391 | get_ups_variable (const char *varname, char *buf) | ||
392 | { | ||
393 | /* char command[MAX_INPUT_BUFFER]; */ | ||
394 | char temp_buffer[MAX_INPUT_BUFFER]; | ||
395 | char send_buffer[MAX_INPUT_BUFFER]; | 466 | char send_buffer[MAX_INPUT_BUFFER]; |
396 | char *ptr; | ||
397 | char *logout = "OK Goodbye\n"; | ||
398 | int logout_len = strlen(logout); | ||
399 | int len; | ||
400 | |||
401 | *buf=0; | ||
402 | 467 | ||
403 | /* create the command string to send to the UPS daemon */ | 468 | /* create the command string to send to the UPS daemon */ |
404 | /* Add LOGOUT to avoid read failure logs */ | 469 | /* Add LOGOUT to avoid read failure logs */ |
405 | if (snprintf (send_buffer, sizeof(send_buffer), "GET VAR %s %s\nLOGOUT\n", ups_name, varname) >= sizeof(send_buffer)) { | 470 | int res = snprintf(send_buffer, sizeof(send_buffer), |
471 | "GET VAR %s %s\nLOGOUT\n", config.ups_name, varname); | ||
472 | if ((res > 0) && ((size_t)res >= sizeof(send_buffer))) { | ||
406 | printf("%s\n", _("UPS name to long for buffer")); | 473 | printf("%s\n", _("UPS name to long for buffer")); |
407 | return ERROR; | 474 | return ERROR; |
408 | } | 475 | } |
409 | 476 | ||
477 | char temp_buffer[MAX_INPUT_BUFFER]; | ||
478 | |||
410 | /* send the command to the daemon and get a response back */ | 479 | /* send the command to the daemon and get a response back */ |
411 | if (process_tcp_request | 480 | if (process_tcp_request(config.server_address, config.server_port, |
412 | (server_address, server_port, send_buffer, temp_buffer, | 481 | send_buffer, temp_buffer, |
413 | sizeof (temp_buffer)) != STATE_OK) { | 482 | sizeof(temp_buffer)) != STATE_OK) { |
414 | printf ("%s\n", _("Invalid response received from host")); | 483 | printf("%s\n", _("Invalid response received from host")); |
415 | return ERROR; | 484 | return ERROR; |
416 | } | 485 | } |
417 | 486 | ||
418 | ptr = temp_buffer; | 487 | char *ptr = temp_buffer; |
419 | len = strlen(ptr); | 488 | int len = strlen(ptr); |
420 | if (len > logout_len && strcmp (ptr + len - logout_len, logout) == 0) len -= logout_len; | 489 | const char *logout = "OK Goodbye\n"; |
421 | if (len > 0 && ptr[len-1] == '\n') ptr[len-1]=0; | 490 | const int logout_len = strlen(logout); |
422 | if (strcmp (ptr, "ERR UNKNOWN-UPS") == 0) { | 491 | |
423 | printf (_("CRITICAL - no such UPS '%s' on that host\n"), ups_name); | 492 | if (len > logout_len && strcmp(ptr + len - logout_len, logout) == 0) { |
493 | len -= logout_len; | ||
494 | } | ||
495 | if (len > 0 && ptr[len - 1] == '\n') { | ||
496 | ptr[len - 1] = 0; | ||
497 | } | ||
498 | if (strcmp(ptr, "ERR UNKNOWN-UPS") == 0) { | ||
499 | printf(_("CRITICAL - no such UPS '%s' on that host\n"), | ||
500 | config.ups_name); | ||
424 | return ERROR; | 501 | return ERROR; |
425 | } | 502 | } |
426 | 503 | ||
427 | if (strcmp (ptr, "ERR VAR-NOT-SUPPORTED") == 0) { | 504 | if (strcmp(ptr, "ERR VAR-NOT-SUPPORTED") == 0) { |
428 | /*printf ("Error: Variable '%s' is not supported\n", varname);*/ | 505 | /*printf ("Error: Variable '%s' is not supported\n", varname);*/ |
429 | return NOSUCHVAR; | 506 | return NOSUCHVAR; |
430 | } | 507 | } |
431 | 508 | ||
432 | if (strcmp (ptr, "ERR DATA-STALE") == 0) { | 509 | if (strcmp(ptr, "ERR DATA-STALE") == 0) { |
433 | printf ("%s\n", _("CRITICAL - UPS data is stale")); | 510 | printf("%s\n", _("CRITICAL - UPS data is stale")); |
434 | return ERROR; | 511 | return ERROR; |
435 | } | 512 | } |
436 | 513 | ||
437 | if (strncmp (ptr, "ERR", 3) == 0) { | 514 | if (strncmp(ptr, "ERR", 3) == 0) { |
438 | printf (_("Unknown error: %s\n"), ptr); | 515 | printf(_("Unknown error: %s\n"), ptr); |
439 | return ERROR; | 516 | return ERROR; |
440 | } | 517 | } |
441 | 518 | ||
442 | ptr = temp_buffer + strlen (varname) + strlen (ups_name) + 6; | 519 | ptr = temp_buffer + strlen(varname) + strlen(config.ups_name) + 6; |
443 | len = strlen(ptr); | 520 | len = strlen(ptr); |
444 | if (len < 2 || ptr[0] != '"' || ptr[len-1] != '"') { | 521 | if (len < 2 || ptr[0] != '"' || ptr[len - 1] != '"') { |
445 | printf ("%s\n", _("Error: unable to parse variable")); | 522 | printf("%s\n", _("Error: unable to parse variable")); |
446 | return ERROR; | 523 | return ERROR; |
447 | } | 524 | } |
448 | strncpy (buf, ptr+1, len - 2); | 525 | |
526 | *buf = 0; | ||
527 | strncpy(buf, ptr + 1, len - 2); | ||
449 | buf[len - 2] = 0; | 528 | buf[len - 2] = 0; |
450 | 529 | ||
451 | return OK; | 530 | return OK; |
452 | } | 531 | } |
453 | 532 | ||
454 | |||
455 | /* Command line: CHECK_UPS -H <host_address> -u ups [-p port] [-v variable] | 533 | /* Command line: CHECK_UPS -H <host_address> -u ups [-p port] [-v variable] |
456 | [-wv warn_value] [-cv crit_value] [-to to_sec] */ | 534 | [-wv warn_value] [-cv crit_value] [-to to_sec] */ |
457 | 535 | ||
458 | |||
459 | /* process command-line arguments */ | 536 | /* process command-line arguments */ |
460 | int | 537 | int process_arguments(int argc, char **argv, ups_config *config) { |
461 | process_arguments (int argc, char **argv) | 538 | |
462 | { | 539 | static struct option longopts[] = {{"hostname", required_argument, 0, 'H'}, |
463 | int c; | 540 | {"ups", required_argument, 0, 'u'}, |
464 | 541 | {"port", required_argument, 0, 'p'}, | |
465 | int option = 0; | 542 | {"critical", required_argument, 0, 'c'}, |
466 | static struct option longopts[] = { | 543 | {"warning", required_argument, 0, 'w'}, |
467 | {"hostname", required_argument, 0, 'H'}, | 544 | {"timeout", required_argument, 0, 't'}, |
468 | {"ups", required_argument, 0, 'u'}, | 545 | {"temperature", no_argument, 0, 'T'}, |
469 | {"port", required_argument, 0, 'p'}, | 546 | {"variable", required_argument, 0, 'v'}, |
470 | {"critical", required_argument, 0, 'c'}, | 547 | {"version", no_argument, 0, 'V'}, |
471 | {"warning", required_argument, 0, 'w'}, | 548 | {"help", no_argument, 0, 'h'}, |
472 | {"timeout", required_argument, 0, 't'}, | 549 | {0, 0, 0, 0}}; |
473 | {"temperature", no_argument, 0, 'T'}, | 550 | |
474 | {"variable", required_argument, 0, 'v'}, | 551 | if (argc < 2) { |
475 | {"version", no_argument, 0, 'V'}, | ||
476 | {"help", no_argument, 0, 'h'}, | ||
477 | {0, 0, 0, 0} | ||
478 | }; | ||
479 | |||
480 | if (argc < 2) | ||
481 | return ERROR; | 552 | return ERROR; |
553 | } | ||
482 | 554 | ||
555 | int c; | ||
483 | for (c = 1; c < argc; c++) { | 556 | for (c = 1; c < argc; c++) { |
484 | if (strcmp ("-to", argv[c]) == 0) | 557 | if (strcmp("-to", argv[c]) == 0) { |
485 | strcpy (argv[c], "-t"); | 558 | strcpy(argv[c], "-t"); |
486 | else if (strcmp ("-wt", argv[c]) == 0) | 559 | } else if (strcmp("-wt", argv[c]) == 0) { |
487 | strcpy (argv[c], "-w"); | 560 | strcpy(argv[c], "-w"); |
488 | else if (strcmp ("-ct", argv[c]) == 0) | 561 | } else if (strcmp("-ct", argv[c]) == 0) { |
489 | strcpy (argv[c], "-c"); | 562 | strcpy(argv[c], "-c"); |
563 | } | ||
490 | } | 564 | } |
491 | 565 | ||
566 | int option = 0; | ||
492 | while (1) { | 567 | while (1) { |
493 | c = getopt_long (argc, argv, "hVTH:u:p:v:c:w:t:", longopts, | 568 | c = getopt_long(argc, argv, "hVTH:u:p:v:c:w:t:", longopts, &option); |
494 | &option); | ||
495 | 569 | ||
496 | if (c == -1 || c == EOF) | 570 | if (c == -1 || c == EOF) { |
497 | break; | 571 | break; |
572 | } | ||
498 | 573 | ||
499 | switch (c) { | 574 | switch (c) { |
500 | case '?': /* help */ | 575 | case '?': /* help */ |
501 | usage5 (); | 576 | usage5(); |
502 | case 'H': /* hostname */ | 577 | case 'H': /* hostname */ |
503 | if (is_host (optarg)) { | 578 | if (is_host(optarg)) { |
504 | server_address = optarg; | 579 | config->server_address = optarg; |
505 | } | 580 | } else { |
506 | else { | 581 | usage2(_("Invalid hostname/address"), optarg); |
507 | usage2 (_("Invalid hostname/address"), optarg); | ||
508 | } | 582 | } |
509 | break; | 583 | break; |
510 | case 'T': /* FIXME: to be improved (ie "-T C" for Celsius or "-T F" for Fahrenheit) */ | 584 | case 'T': /* FIXME: to be improved (ie "-T C" for Celsius or "-T F" for |
511 | temp_output_c = 1; | 585 | Fahrenheit) */ |
586 | config->temp_output_c = true; | ||
512 | break; | 587 | break; |
513 | case 'u': /* ups name */ | 588 | case 'u': /* ups name */ |
514 | ups_name = optarg; | 589 | config->ups_name = optarg; |
515 | break; | 590 | break; |
516 | case 'p': /* port */ | 591 | case 'p': /* port */ |
517 | if (is_intpos (optarg)) { | 592 | if (is_intpos(optarg)) { |
518 | server_port = atoi (optarg); | 593 | config->server_port = atoi(optarg); |
519 | } | 594 | } else { |
520 | else { | 595 | usage2(_("Port must be a positive integer"), optarg); |
521 | usage2 (_("Port must be a positive integer"), optarg); | ||
522 | } | 596 | } |
523 | break; | 597 | break; |
524 | case 'c': /* critical time threshold */ | 598 | case 'c': /* critical time threshold */ |
525 | if (is_intnonneg (optarg)) { | 599 | if (is_intnonneg(optarg)) { |
526 | critical_value = atoi (optarg); | 600 | config->critical_value = atoi(optarg); |
527 | check_crit = TRUE; | 601 | config->check_crit = true; |
528 | } | 602 | } else { |
529 | else { | 603 | usage2(_("Critical time must be a positive integer"), optarg); |
530 | usage2 (_("Critical time must be a positive integer"), optarg); | ||
531 | } | 604 | } |
532 | break; | 605 | break; |
533 | case 'w': /* warning time threshold */ | 606 | case 'w': /* warning time threshold */ |
534 | if (is_intnonneg (optarg)) { | 607 | if (is_intnonneg(optarg)) { |
535 | warning_value = atoi (optarg); | 608 | config->warning_value = atoi(optarg); |
536 | check_warn = TRUE; | 609 | config->check_warn = true; |
537 | } | 610 | } else { |
538 | else { | 611 | usage2(_("Warning time must be a positive integer"), optarg); |
539 | usage2 (_("Warning time must be a positive integer"), optarg); | ||
540 | } | 612 | } |
541 | break; | 613 | break; |
542 | case 'v': /* variable */ | 614 | case 'v': /* variable */ |
543 | if (!strcmp (optarg, "LINE")) | 615 | if (!strcmp(optarg, "LINE")) { |
544 | check_variable = UPS_UTILITY; | 616 | config->check_variable = UPS_UTILITY; |
545 | else if (!strcmp (optarg, "TEMP")) | 617 | } else if (!strcmp(optarg, "TEMP")) { |
546 | check_variable = UPS_TEMP; | 618 | config->check_variable = UPS_TEMP; |
547 | else if (!strcmp (optarg, "BATTPCT")) | 619 | } else if (!strcmp(optarg, "BATTPCT")) { |
548 | check_variable = UPS_BATTPCT; | 620 | config->check_variable = UPS_BATTPCT; |
549 | else if (!strcmp (optarg, "LOADPCT")) | 621 | } else if (!strcmp(optarg, "LOADPCT")) { |
550 | check_variable = UPS_LOADPCT; | 622 | config->check_variable = UPS_LOADPCT; |
551 | else | 623 | } else if (!strcmp(optarg, "REALPOWER")) { |
552 | usage2 (_("Unrecognized UPS variable"), optarg); | 624 | config->check_variable = UPS_REALPOWER; |
553 | break; | 625 | } else { |
554 | case 't': /* timeout */ | 626 | usage2(_("Unrecognized UPS variable"), optarg); |
555 | if (is_intnonneg (optarg)) { | ||
556 | socket_timeout = atoi (optarg); | ||
557 | } | 627 | } |
558 | else { | 628 | break; |
559 | usage4 (_("Timeout interval must be a positive integer")); | 629 | case 't': /* timeout */ |
630 | if (is_intnonneg(optarg)) { | ||
631 | socket_timeout = atoi(optarg); | ||
632 | } else { | ||
633 | usage4(_("Timeout interval must be a positive integer")); | ||
560 | } | 634 | } |
561 | break; | 635 | break; |
562 | case 'V': /* version */ | 636 | case 'V': /* version */ |
563 | print_revision (progname, NP_VERSION); | 637 | print_revision(progname, NP_VERSION); |
564 | exit (STATE_UNKNOWN); | 638 | exit(STATE_UNKNOWN); |
565 | case 'h': /* help */ | 639 | case 'h': /* help */ |
566 | print_help (); | 640 | print_help(); |
567 | exit (STATE_UNKNOWN); | 641 | exit(STATE_UNKNOWN); |
568 | } | 642 | } |
569 | } | 643 | } |
570 | 644 | ||
571 | 645 | if (config->server_address == NULL && argc > optind) { | |
572 | if (server_address == NULL && argc > optind) { | 646 | if (is_host(argv[optind])) { |
573 | if (is_host (argv[optind])) | 647 | config->server_address = argv[optind++]; |
574 | server_address = argv[optind++]; | 648 | } else { |
575 | else | 649 | usage2(_("Invalid hostname/address"), optarg); |
576 | usage2 (_("Invalid hostname/address"), optarg); | 650 | } |
577 | } | 651 | } |
578 | 652 | ||
579 | if (server_address == NULL) | 653 | if (config->server_address == NULL) { |
580 | server_address = strdup("127.0.0.1"); | 654 | config->server_address = strdup("127.0.0.1"); |
655 | } | ||
581 | 656 | ||
582 | return validate_arguments(); | 657 | return validate_arguments(*config); |
583 | } | 658 | } |
584 | 659 | ||
585 | 660 | int validate_arguments(ups_config config) { | |
586 | int | 661 | if (!config.ups_name) { |
587 | validate_arguments (void) | 662 | printf("%s\n", _("Error : no UPS indicated")); |
588 | { | ||
589 | if (! ups_name) { | ||
590 | printf ("%s\n", _("Error : no UPS indicated")); | ||
591 | return ERROR; | 663 | return ERROR; |
592 | } | 664 | } |
593 | return OK; | 665 | return OK; |
594 | } | 666 | } |
595 | 667 | ||
668 | void print_help(void) { | ||
669 | print_revision(progname, NP_VERSION); | ||
596 | 670 | ||
597 | void | 671 | printf("Copyright (c) 2000 Tom Shields\n"); |
598 | print_help (void) | 672 | printf("Copyright (c) 2004 Alain Richard <alain.richard@equation.fr>\n"); |
599 | { | 673 | printf("Copyright (c) 2004 Arnaud Quette <arnaud.quette@mgeups.com>\n"); |
600 | char *myport; | 674 | printf(COPYRIGHT, copyright, email); |
601 | xasprintf (&myport, "%d", PORT); | ||
602 | |||
603 | print_revision (progname, NP_VERSION); | ||
604 | |||
605 | printf ("Copyright (c) 2000 Tom Shields\n"); | ||
606 | printf ("Copyright (c) 2004 Alain Richard <alain.richard@equation.fr>\n"); | ||
607 | printf ("Copyright (c) 2004 Arnaud Quette <arnaud.quette@mgeups.com>\n"); | ||
608 | printf (COPYRIGHT, copyright, email); | ||
609 | |||
610 | printf ("%s\n", _("This plugin tests the UPS service on the specified host. Network UPS Tools")); | ||
611 | printf ("%s\n", _("from www.networkupstools.org must be running for this plugin to work.")); | ||
612 | |||
613 | printf ("\n\n"); | ||
614 | |||
615 | print_usage (); | ||
616 | 675 | ||
617 | printf (UT_HELP_VRSN); | 676 | printf("%s\n", _("This plugin tests the UPS service on the specified host. " |
618 | printf (UT_EXTRA_OPTS); | 677 | "Network UPS Tools")); |
678 | printf("%s\n", _("from www.networkupstools.org must be running for this " | ||
679 | "plugin to work.")); | ||
619 | 680 | ||
620 | printf (UT_HOST_PORT, 'p', myport); | 681 | printf("\n\n"); |
621 | 682 | ||
622 | printf (" %s\n", "-u, --ups=STRING"); | 683 | print_usage(); |
623 | printf (" %s\n", _("Name of UPS")); | ||
624 | printf (" %s\n", "-T, --temperature"); | ||
625 | printf (" %s\n", _("Output of temperatures in Celsius")); | ||
626 | printf (" %s\n", "-v, --variable=STRING"); | ||
627 | printf (" %s %s\n", _("Valid values for STRING are"), "LINE, TEMP, BATTPCT or LOADPCT"); | ||
628 | 684 | ||
629 | printf (UT_WARN_CRIT); | 685 | printf(UT_HELP_VRSN); |
686 | printf(UT_EXTRA_OPTS); | ||
630 | 687 | ||
631 | printf (UT_CONN_TIMEOUT, DEFAULT_SOCKET_TIMEOUT); | 688 | char *myport; |
632 | 689 | xasprintf(&myport, "%d", PORT); | |
633 | /* TODO: -v clashing with -v/-variable. Commenting out help text since verbose | 690 | printf(UT_HOST_PORT, 'p', myport); |
634 | is unused up to now */ | 691 | |
635 | /* printf (UT_VERBOSE); */ | 692 | printf(" %s\n", "-u, --ups=STRING"); |
636 | 693 | printf(" %s\n", _("Name of UPS")); | |
637 | printf ("\n"); | 694 | printf(" %s\n", "-T, --temperature"); |
638 | printf ("%s\n", _("This plugin attempts to determine the status of a UPS (Uninterruptible Power")); | 695 | printf(" %s\n", _("Output of temperatures in Celsius")); |
639 | printf ("%s\n", _("Supply) on a local or remote host. If the UPS is online or calibrating, the")); | 696 | printf(" %s\n", "-v, --variable=STRING"); |
640 | printf ("%s\n", _("plugin will return an OK state. If the battery is on it will return a WARNING")); | 697 | printf(" %s %s\n", _("Valid values for STRING are"), |
641 | printf ("%s\n", _("state. If the UPS is off or has a low battery the plugin will return a CRITICAL")); | 698 | "LINE, TEMP, BATTPCT, LOADPCT or REALPOWER"); |
642 | printf ("%s\n", _("state.")); | 699 | |
643 | 700 | printf(UT_WARN_CRIT); | |
644 | printf ("\n"); | 701 | |
645 | printf ("%s\n", _("Notes:")); | 702 | printf(UT_CONN_TIMEOUT, DEFAULT_SOCKET_TIMEOUT); |
646 | printf (" %s\n", _("You may also specify a variable to check (such as temperature, utility voltage,")); | 703 | |
647 | printf (" %s\n", _("battery load, etc.) as well as warning and critical thresholds for the value")); | 704 | /* TODO: -v clashing with -v/-variable. Commenting out help text since |
648 | printf (" %s\n", _("of that variable. If the remote host has multiple UPS that are being monitored")); | 705 | verbose is unused up to now */ |
649 | printf (" %s\n", _("you will have to use the --ups option to specify which UPS to check.")); | 706 | /* printf (UT_VERBOSE); */ |
650 | printf ("\n"); | 707 | |
651 | printf (" %s\n", _("This plugin requires that the UPSD daemon distributed with Russell Kroll's")); | 708 | printf("\n"); |
652 | printf (" %s\n", _("Network UPS Tools be installed on the remote host. If you do not have the")); | 709 | printf("%s\n", _("This plugin attempts to determine the status of a UPS " |
653 | printf (" %s\n", _("package installed on your system, you can download it from")); | 710 | "(Uninterruptible Power")); |
654 | printf (" %s\n", _("http://www.networkupstools.org")); | 711 | printf("%s\n", _("Supply) on a local or remote host. If the UPS is online " |
655 | 712 | "or calibrating, the")); | |
656 | printf (UT_SUPPORT); | 713 | printf("%s\n", _("plugin will return an OK state. If the battery is on it " |
714 | "will return a WARNING")); | ||
715 | printf("%s\n", _("state. If the UPS is off or has a low battery the plugin " | ||
716 | "will return a CRITICAL")); | ||
717 | printf("%s\n", _("state.")); | ||
718 | |||
719 | printf("\n"); | ||
720 | printf("%s\n", _("Notes:")); | ||
721 | printf(" %s\n", _("You may also specify a variable to check (such as " | ||
722 | "temperature, utility voltage,")); | ||
723 | printf(" %s\n", _("battery load, etc.) as well as warning and critical " | ||
724 | "thresholds for the value")); | ||
725 | printf(" %s\n", _("of that variable. If the remote host has multiple UPS " | ||
726 | "that are being monitored")); | ||
727 | printf(" %s\n", _("you will have to use the --ups option to specify which " | ||
728 | "UPS to check.")); | ||
729 | printf("\n"); | ||
730 | printf(" %s\n", _("This plugin requires that the UPSD daemon distributed " | ||
731 | "with Russell Kroll's")); | ||
732 | printf(" %s\n", _("Network UPS Tools be installed on the remote host. If " | ||
733 | "you do not have the")); | ||
734 | printf(" %s\n", | ||
735 | _("package installed on your system, you can download it from")); | ||
736 | printf(" %s\n", _("http://www.networkupstools.org")); | ||
737 | |||
738 | printf(UT_SUPPORT); | ||
657 | } | 739 | } |
658 | 740 | ||
659 | 741 | void print_usage(void) { | |
660 | void | 742 | printf("%s\n", _("Usage:")); |
661 | print_usage (void) | 743 | printf("%s -H host -u ups [-p port] [-v variable] [-w warn_value] [-c " |
662 | { | 744 | "crit_value] [-to to_sec] [-T]\n", |
663 | printf ("%s\n", _("Usage:")); | 745 | progname); |
664 | printf ("%s -H host -u ups [-p port] [-v variable] [-w warn_value] [-c crit_value] [-to to_sec] [-T]\n", progname); | ||
665 | } | 746 | } |
diff --git a/plugins/check_users.c b/plugins/check_users.c index 2a9ee986..89b95369 100644 --- a/plugins/check_users.c +++ b/plugins/check_users.c | |||
@@ -179,7 +179,7 @@ main (int argc, char **argv) | |||
179 | printf (_("USERS %s - %d users currently logged in |%s\n"), | 179 | printf (_("USERS %s - %d users currently logged in |%s\n"), |
180 | state_text(result), users, | 180 | state_text(result), users, |
181 | sperfdata_int("users", users, "", warning_range, | 181 | sperfdata_int("users", users, "", warning_range, |
182 | critical_range, TRUE, 0, FALSE, 0)); | 182 | critical_range, true, 0, false, 0)); |
183 | } | 183 | } |
184 | 184 | ||
185 | return result; | 185 | return result; |
@@ -202,7 +202,7 @@ process_arguments (int argc, char **argv) | |||
202 | if (argc < 2) | 202 | if (argc < 2) |
203 | usage ("\n"); | 203 | usage ("\n"); |
204 | 204 | ||
205 | while (1) { | 205 | while (true) { |
206 | c = getopt_long (argc, argv, "+hVvc:w:", longopts, &option); | 206 | c = getopt_long (argc, argv, "+hVvc:w:", longopts, &option); |
207 | 207 | ||
208 | if (c == -1 || c == EOF || c == 1) | 208 | if (c == -1 || c == EOF || c == 1) |
@@ -227,18 +227,23 @@ process_arguments (int argc, char **argv) | |||
227 | } | 227 | } |
228 | 228 | ||
229 | c = optind; | 229 | c = optind; |
230 | |||
230 | if (warning_range == NULL && argc > c) | 231 | if (warning_range == NULL && argc > c) |
231 | warning_range = argv[c++]; | 232 | warning_range = argv[c++]; |
233 | |||
232 | if (critical_range == NULL && argc > c) | 234 | if (critical_range == NULL && argc > c) |
233 | critical_range = argv[c++]; | 235 | critical_range = argv[c++]; |
234 | 236 | ||
235 | /* this will abort in case of invalid ranges */ | 237 | /* this will abort in case of invalid ranges */ |
236 | set_thresholds (&thlds, warning_range, critical_range); | 238 | set_thresholds (&thlds, warning_range, critical_range); |
237 | 239 | ||
238 | if (thlds->warning->end < 0) | 240 | if (!thlds->warning) { |
239 | usage4 (_("Warning threshold must be a positive integer")); | 241 | usage4 (_("Warning threshold must be a valid range expression")); |
240 | if (thlds->critical->end < 0) | 242 | } |
241 | usage4 (_("Critical threshold must be a positive integer")); | 243 | |
244 | if (!thlds->critical) { | ||
245 | usage4 (_("Critical threshold must be a valid range expression")); | ||
246 | } | ||
242 | 247 | ||
243 | return OK; | 248 | return OK; |
244 | } | 249 | } |
@@ -261,10 +266,10 @@ print_help (void) | |||
261 | printf (UT_HELP_VRSN); | 266 | printf (UT_HELP_VRSN); |
262 | printf (UT_EXTRA_OPTS); | 267 | printf (UT_EXTRA_OPTS); |
263 | 268 | ||
264 | printf (" %s\n", "-w, --warning=INTEGER"); | 269 | printf (" %s\n", "-w, --warning=RANGE_EXPRESSION"); |
265 | printf (" %s\n", _("Set WARNING status if more than INTEGER users are logged in")); | 270 | printf (" %s\n", _("Set WARNING status if number of logged in users violates RANGE_EXPRESSION")); |
266 | printf (" %s\n", "-c, --critical=INTEGER"); | 271 | printf (" %s\n", "-c, --critical=RANGE_EXPRESSION"); |
267 | printf (" %s\n", _("Set CRITICAL status if more than INTEGER users are logged in")); | 272 | printf (" %s\n", _("Set CRITICAL status if number of logged in users violates RANGE_EXPRESSION")); |
268 | 273 | ||
269 | printf (UT_SUPPORT); | 274 | printf (UT_SUPPORT); |
270 | } | 275 | } |
diff --git a/plugins/common.h b/plugins/common.h index 0f08e2f6..833479ce 100644 --- a/plugins/common.h +++ b/plugins/common.h | |||
@@ -184,14 +184,6 @@ enum { | |||
184 | ERROR = -1 | 184 | ERROR = -1 |
185 | }; | 185 | }; |
186 | 186 | ||
187 | /* AIX seems to have this defined somewhere else */ | ||
188 | #ifndef FALSE | ||
189 | enum { | ||
190 | FALSE, | ||
191 | TRUE | ||
192 | }; | ||
193 | #endif | ||
194 | |||
195 | enum { | 187 | enum { |
196 | STATE_OK, | 188 | STATE_OK, |
197 | STATE_WARNING, | 189 | STATE_WARNING, |
@@ -225,18 +217,4 @@ enum { | |||
225 | # define __attribute__(x) /* do nothing */ | 217 | # define __attribute__(x) /* do nothing */ |
226 | #endif | 218 | #endif |
227 | 219 | ||
228 | /* Try sysconf(_SC_OPEN_MAX) first, as it can be higher than OPEN_MAX. | ||
229 | * If that fails and the macro isn't defined, we fall back to an educated | ||
230 | * guess. There's no guarantee that our guess is adequate and the program | ||
231 | * will die with SIGSEGV if it isn't and the upper boundary is breached. */ | ||
232 | #define DEFAULT_MAXFD 256 /* fallback value if no max open files value is set */ | ||
233 | #define MAXFD_LIMIT 8192 /* upper limit of open files */ | ||
234 | #ifdef _SC_OPEN_MAX | ||
235 | static long maxfd = 0; | ||
236 | #elif defined(OPEN_MAX) | ||
237 | # define maxfd OPEN_MAX | ||
238 | #else /* sysconf macro unavailable, so guess (may be wildly inaccurate) */ | ||
239 | # define maxfd DEFAULT_MAXFD | ||
240 | #endif | ||
241 | |||
242 | #endif /* _COMMON_H_ */ | 220 | #endif /* _COMMON_H_ */ |
diff --git a/plugins/negate.c b/plugins/negate.c index 50f62d33..c5fe7e13 100644 --- a/plugins/negate.c +++ b/plugins/negate.c | |||
@@ -47,7 +47,7 @@ static const char **process_arguments (int, char **); | |||
47 | void validate_arguments (char **); | 47 | void validate_arguments (char **); |
48 | void print_help (void); | 48 | void print_help (void); |
49 | void print_usage (void); | 49 | void print_usage (void); |
50 | int subst_text = FALSE; | 50 | bool subst_text = false; |
51 | 51 | ||
52 | static int state[4] = { | 52 | static int state[4] = { |
53 | STATE_OK, | 53 | STATE_OK, |
@@ -63,7 +63,6 @@ main (int argc, char **argv) | |||
63 | char *sub; | 63 | char *sub; |
64 | char **command_line; | 64 | char **command_line; |
65 | output chld_out, chld_err; | 65 | output chld_out, chld_err; |
66 | int i; | ||
67 | 66 | ||
68 | setlocale (LC_ALL, ""); | 67 | setlocale (LC_ALL, ""); |
69 | bindtextdomain (PACKAGE, LOCALEDIR); | 68 | bindtextdomain (PACKAGE, LOCALEDIR); |
@@ -86,7 +85,7 @@ main (int argc, char **argv) | |||
86 | result = cmd_run_array (command_line, &chld_out, &chld_err, 0); | 85 | result = cmd_run_array (command_line, &chld_out, &chld_err, 0); |
87 | } | 86 | } |
88 | if (chld_err.lines > 0) { | 87 | if (chld_err.lines > 0) { |
89 | for (i = 0; i < chld_err.lines; i++) { | 88 | for (size_t i = 0; i < chld_err.lines; i++) { |
90 | fprintf (stderr, "%s\n", chld_err.line[i]); | 89 | fprintf (stderr, "%s\n", chld_err.line[i]); |
91 | } | 90 | } |
92 | } | 91 | } |
@@ -95,7 +94,7 @@ main (int argc, char **argv) | |||
95 | if (chld_out.lines == 0) | 94 | if (chld_out.lines == 0) |
96 | die (max_state_alt (result, STATE_UNKNOWN), _("No data returned from command\n")); | 95 | die (max_state_alt (result, STATE_UNKNOWN), _("No data returned from command\n")); |
97 | 96 | ||
98 | for (i = 0; i < chld_out.lines; i++) { | 97 | for (size_t i = 0; i < chld_out.lines; i++) { |
99 | if (subst_text && result >= 0 && result <= 4 && result != state[result]) { | 98 | if (subst_text && result >= 0 && result <= 4 && result != state[result]) { |
100 | /* Loop over each match found */ | 99 | /* Loop over each match found */ |
101 | while ((sub = strstr (chld_out.line[i], state_text (result)))) { | 100 | while ((sub = strstr (chld_out.line[i], state_text (result)))) { |
@@ -122,7 +121,7 @@ static const char ** | |||
122 | process_arguments (int argc, char **argv) | 121 | process_arguments (int argc, char **argv) |
123 | { | 122 | { |
124 | int c; | 123 | int c; |
125 | int permute = TRUE; | 124 | bool permute = true; |
126 | 125 | ||
127 | int option = 0; | 126 | int option = 0; |
128 | static struct option longopts[] = { | 127 | static struct option longopts[] = { |
@@ -168,26 +167,26 @@ process_arguments (int argc, char **argv) | |||
168 | case 'o': /* replacement for OK */ | 167 | case 'o': /* replacement for OK */ |
169 | if ((state[STATE_OK] = mp_translate_state(optarg)) == ERROR) | 168 | if ((state[STATE_OK] = mp_translate_state(optarg)) == ERROR) |
170 | usage4 (_("Ok must be a valid state name (OK, WARNING, CRITICAL, UNKNOWN) or integer (0-3).")); | 169 | usage4 (_("Ok must be a valid state name (OK, WARNING, CRITICAL, UNKNOWN) or integer (0-3).")); |
171 | permute = FALSE; | 170 | permute = false; |
172 | break; | 171 | break; |
173 | 172 | ||
174 | case 'w': /* replacement for WARNING */ | 173 | case 'w': /* replacement for WARNING */ |
175 | if ((state[STATE_WARNING] = mp_translate_state(optarg)) == ERROR) | 174 | if ((state[STATE_WARNING] = mp_translate_state(optarg)) == ERROR) |
176 | usage4 (_("Warning must be a valid state name (OK, WARNING, CRITICAL, UNKNOWN) or integer (0-3).")); | 175 | usage4 (_("Warning must be a valid state name (OK, WARNING, CRITICAL, UNKNOWN) or integer (0-3).")); |
177 | permute = FALSE; | 176 | permute = false; |
178 | break; | 177 | break; |
179 | case 'c': /* replacement for CRITICAL */ | 178 | case 'c': /* replacement for CRITICAL */ |
180 | if ((state[STATE_CRITICAL] = mp_translate_state(optarg)) == ERROR) | 179 | if ((state[STATE_CRITICAL] = mp_translate_state(optarg)) == ERROR) |
181 | usage4 (_("Critical must be a valid state name (OK, WARNING, CRITICAL, UNKNOWN) or integer (0-3).")); | 180 | usage4 (_("Critical must be a valid state name (OK, WARNING, CRITICAL, UNKNOWN) or integer (0-3).")); |
182 | permute = FALSE; | 181 | permute = false; |
183 | break; | 182 | break; |
184 | case 'u': /* replacement for UNKNOWN */ | 183 | case 'u': /* replacement for UNKNOWN */ |
185 | if ((state[STATE_UNKNOWN] = mp_translate_state(optarg)) == ERROR) | 184 | if ((state[STATE_UNKNOWN] = mp_translate_state(optarg)) == ERROR) |
186 | usage4 (_("Unknown must be a valid state name (OK, WARNING, CRITICAL, UNKNOWN) or integer (0-3).")); | 185 | usage4 (_("Unknown must be a valid state name (OK, WARNING, CRITICAL, UNKNOWN) or integer (0-3).")); |
187 | permute = FALSE; | 186 | permute = false; |
188 | break; | 187 | break; |
189 | case 's': /* Substitute status text */ | 188 | case 's': /* Substitute status text */ |
190 | subst_text = TRUE; | 189 | subst_text = true; |
191 | break; | 190 | break; |
192 | } | 191 | } |
193 | } | 192 | } |
@@ -221,8 +220,10 @@ print_help (void) | |||
221 | 220 | ||
222 | printf (COPYRIGHT, copyright, email); | 221 | printf (COPYRIGHT, copyright, email); |
223 | 222 | ||
224 | printf ("%s\n", _("Negates the status of a plugin (returns OK for CRITICAL and vice-versa).")); | 223 | printf ("%s\n", _("Negates only the return code of a plugin (returns OK for CRITICAL and vice-versa) by default.")); |
225 | printf ("%s\n", _("Additional switches can be used to control which state becomes what.")); | 224 | printf ("%s\n", _("Additional switches can be used to control:\n")); |
225 | printf ("\t - which state becomes what\n"); | ||
226 | printf ("\t - changing the plugin output text to match the return code"); | ||
226 | 227 | ||
227 | printf ("\n\n"); | 228 | printf ("\n\n"); |
228 | 229 | ||
diff --git a/plugins/netutils.c b/plugins/netutils.c index 1bb4f076..c6af248e 100644 --- a/plugins/netutils.c +++ b/plugins/netutils.c | |||
@@ -34,7 +34,7 @@ unsigned int socket_timeout = DEFAULT_SOCKET_TIMEOUT; | |||
34 | unsigned int socket_timeout_state = STATE_CRITICAL; | 34 | unsigned int socket_timeout_state = STATE_CRITICAL; |
35 | 35 | ||
36 | int econn_refuse_state = STATE_CRITICAL; | 36 | int econn_refuse_state = STATE_CRITICAL; |
37 | int was_refused = FALSE; | 37 | bool was_refused = false; |
38 | #if USE_IPV6 | 38 | #if USE_IPV6 |
39 | int address_family = AF_UNSPEC; | 39 | int address_family = AF_UNSPEC; |
40 | #else | 40 | #else |
@@ -215,14 +215,14 @@ np_net_connect (const char *host_name, int port, int *sd, int proto) | |||
215 | result = connect (*sd, r->ai_addr, r->ai_addrlen); | 215 | result = connect (*sd, r->ai_addr, r->ai_addrlen); |
216 | 216 | ||
217 | if (result == 0) { | 217 | if (result == 0) { |
218 | was_refused = FALSE; | 218 | was_refused = false; |
219 | break; | 219 | break; |
220 | } | 220 | } |
221 | 221 | ||
222 | if (result < 0) { | 222 | if (result < 0) { |
223 | switch (errno) { | 223 | switch (errno) { |
224 | case ECONNREFUSED: | 224 | case ECONNREFUSED: |
225 | was_refused = TRUE; | 225 | was_refused = true; |
226 | break; | 226 | break; |
227 | } | 227 | } |
228 | } | 228 | } |
@@ -246,7 +246,7 @@ np_net_connect (const char *host_name, int port, int *sd, int proto) | |||
246 | } | 246 | } |
247 | result = connect(*sd, (struct sockaddr *)&su, sizeof(su)); | 247 | result = connect(*sd, (struct sockaddr *)&su, sizeof(su)); |
248 | if (result < 0 && errno == ECONNREFUSED) | 248 | if (result < 0 && errno == ECONNREFUSED) |
249 | was_refused = TRUE; | 249 | was_refused = true; |
250 | } | 250 | } |
251 | 251 | ||
252 | if (result == 0) | 252 | if (result == 0) |
@@ -326,13 +326,11 @@ send_request (int sd, int proto, const char *send_buffer, char *recv_buffer, int | |||
326 | } | 326 | } |
327 | 327 | ||
328 | 328 | ||
329 | int | 329 | bool is_host (const char *address) { |
330 | is_host (const char *address) | ||
331 | { | ||
332 | if (is_addr (address) || is_hostname (address)) | 330 | if (is_addr (address) || is_hostname (address)) |
333 | return (TRUE); | 331 | return (true); |
334 | 332 | ||
335 | return (FALSE); | 333 | return (false); |
336 | } | 334 | } |
337 | 335 | ||
338 | void | 336 | void |
@@ -342,20 +340,18 @@ host_or_die(const char *str) | |||
342 | usage_va(_("Invalid hostname/address - %s"), str); | 340 | usage_va(_("Invalid hostname/address - %s"), str); |
343 | } | 341 | } |
344 | 342 | ||
345 | int | 343 | bool is_addr (const char *address) { |
346 | is_addr (const char *address) | ||
347 | { | ||
348 | #ifdef USE_IPV6 | 344 | #ifdef USE_IPV6 |
349 | if (address_family == AF_INET && is_inet_addr (address)) | 345 | if (address_family == AF_INET && is_inet_addr (address)) |
350 | return TRUE; | 346 | return true; |
351 | else if (address_family == AF_INET6 && is_inet6_addr (address)) | 347 | else if (address_family == AF_INET6 && is_inet6_addr (address)) |
352 | return TRUE; | 348 | return true; |
353 | #else | 349 | #else |
354 | if (is_inet_addr (address)) | 350 | if (is_inet_addr (address)) |
355 | return (TRUE); | 351 | return (true); |
356 | #endif | 352 | #endif |
357 | 353 | ||
358 | return (FALSE); | 354 | return (false); |
359 | } | 355 | } |
360 | 356 | ||
361 | int | 357 | int |
@@ -370,10 +366,10 @@ dns_lookup (const char *in, struct sockaddr_storage *ss, int family) | |||
370 | 366 | ||
371 | retval = getaddrinfo (in, NULL, &hints, &res); | 367 | retval = getaddrinfo (in, NULL, &hints, &res); |
372 | if (retval != 0) | 368 | if (retval != 0) |
373 | return FALSE; | 369 | return false; |
374 | 370 | ||
375 | if (ss != NULL) | 371 | if (ss != NULL) |
376 | memcpy (ss, res->ai_addr, res->ai_addrlen); | 372 | memcpy (ss, res->ai_addr, res->ai_addrlen); |
377 | freeaddrinfo (res); | 373 | freeaddrinfo (res); |
378 | return TRUE; | 374 | return true; |
379 | } | 375 | } |
diff --git a/plugins/netutils.h b/plugins/netutils.h index d7ee0ddd..a95057e0 100644 --- a/plugins/netutils.h +++ b/plugins/netutils.h | |||
@@ -73,8 +73,8 @@ int send_request (int sd, int proto, const char *send_buffer, char *recv_buffer, | |||
73 | 73 | ||
74 | 74 | ||
75 | /* "is_*" wrapper macros and functions */ | 75 | /* "is_*" wrapper macros and functions */ |
76 | int is_host (const char *); | 76 | bool is_host (const char *); |
77 | int is_addr (const char *); | 77 | bool is_addr (const char *); |
78 | int dns_lookup (const char *, struct sockaddr_storage *, int); | 78 | int dns_lookup (const char *, struct sockaddr_storage *, int); |
79 | void host_or_die(const char *str); | 79 | void host_or_die(const char *str); |
80 | #define resolve_host_or_addr(addr, family) dns_lookup(addr, NULL, family) | 80 | #define resolve_host_or_addr(addr, family) dns_lookup(addr, NULL, family) |
@@ -89,10 +89,10 @@ void host_or_die(const char *str); | |||
89 | extern unsigned int socket_timeout; | 89 | extern unsigned int socket_timeout; |
90 | extern unsigned int socket_timeout_state; | 90 | extern unsigned int socket_timeout_state; |
91 | extern int econn_refuse_state; | 91 | extern int econn_refuse_state; |
92 | extern int was_refused; | 92 | extern bool was_refused; |
93 | extern int address_family; | 93 | extern int address_family; |
94 | 94 | ||
95 | RETSIGTYPE socket_timeout_alarm_handler (int) __attribute__((noreturn)); | 95 | void socket_timeout_alarm_handler (int) __attribute__((noreturn)); |
96 | 96 | ||
97 | /* SSL-Related functionality */ | 97 | /* SSL-Related functionality */ |
98 | #ifdef HAVE_SSL | 98 | #ifdef HAVE_SSL |
diff --git a/plugins/popen.c b/plugins/popen.c index 723817d5..54e63bc5 100644 --- a/plugins/popen.c +++ b/plugins/popen.c | |||
@@ -38,8 +38,9 @@ | |||
38 | * | 38 | * |
39 | *****************************************************************************/ | 39 | *****************************************************************************/ |
40 | 40 | ||
41 | #include "common.h" | 41 | #include "./common.h" |
42 | #include "utils.h" | 42 | #include "./utils.h" |
43 | #include "../lib/maxfd.h" | ||
43 | 44 | ||
44 | /* extern so plugin has pid to kill exec'd process on timeouts */ | 45 | /* extern so plugin has pid to kill exec'd process on timeouts */ |
45 | extern pid_t *childpid; | 46 | extern pid_t *childpid; |
@@ -49,9 +50,9 @@ extern FILE *child_process; | |||
49 | FILE *spopen (const char *); | 50 | FILE *spopen (const char *); |
50 | int spclose (FILE *); | 51 | int spclose (FILE *); |
51 | #ifdef REDHAT_SPOPEN_ERROR | 52 | #ifdef REDHAT_SPOPEN_ERROR |
52 | RETSIGTYPE popen_sigchld_handler (int); | 53 | void popen_sigchld_handler (int); |
53 | #endif | 54 | #endif |
54 | RETSIGTYPE popen_timeout_alarm_handler (int); | 55 | void popen_timeout_alarm_handler (int); |
55 | 56 | ||
56 | #include <stdarg.h> /* ANSI C header file */ | 57 | #include <stdarg.h> /* ANSI C header file */ |
57 | #include <fcntl.h> | 58 | #include <fcntl.h> |
@@ -104,7 +105,7 @@ spopen (const char *cmdstring) | |||
104 | #endif | 105 | #endif |
105 | 106 | ||
106 | env[0] = strdup("LC_ALL=C"); | 107 | env[0] = strdup("LC_ALL=C"); |
107 | env[1] = '\0'; | 108 | env[1] = NULL; |
108 | 109 | ||
109 | /* if no command was passed, return with no error */ | 110 | /* if no command was passed, return with no error */ |
110 | if (cmdstring == NULL) | 111 | if (cmdstring == NULL) |
@@ -177,8 +178,7 @@ spopen (const char *cmdstring) | |||
177 | } | 178 | } |
178 | argv[i] = NULL; | 179 | argv[i] = NULL; |
179 | 180 | ||
180 | if(maxfd == 0) | 181 | long maxfd = mp_open_max(); |
181 | maxfd = open_max(); | ||
182 | 182 | ||
183 | if (childpid == NULL) { /* first time through */ | 183 | if (childpid == NULL) { /* first time through */ |
184 | if ((childpid = calloc ((size_t)maxfd, sizeof (pid_t))) == NULL) | 184 | if ((childpid = calloc ((size_t)maxfd, sizeof (pid_t))) == NULL) |
@@ -266,7 +266,7 @@ spclose (FILE * fp) | |||
266 | } | 266 | } |
267 | 267 | ||
268 | #ifdef REDHAT_SPOPEN_ERROR | 268 | #ifdef REDHAT_SPOPEN_ERROR |
269 | RETSIGTYPE | 269 | void |
270 | popen_sigchld_handler (int signo) | 270 | popen_sigchld_handler (int signo) |
271 | { | 271 | { |
272 | if (signo == SIGCHLD) | 272 | if (signo == SIGCHLD) |
@@ -274,7 +274,7 @@ popen_sigchld_handler (int signo) | |||
274 | } | 274 | } |
275 | #endif | 275 | #endif |
276 | 276 | ||
277 | RETSIGTYPE | 277 | void |
278 | popen_timeout_alarm_handler (int signo) | 278 | popen_timeout_alarm_handler (int signo) |
279 | { | 279 | { |
280 | int fh; | 280 | int fh; |
diff --git a/plugins/popen.h b/plugins/popen.h index a5dd8fa7..1ea69632 100644 --- a/plugins/popen.h +++ b/plugins/popen.h | |||
@@ -5,7 +5,7 @@ | |||
5 | 5 | ||
6 | FILE *spopen (const char *); | 6 | FILE *spopen (const char *); |
7 | int spclose (FILE *); | 7 | int spclose (FILE *); |
8 | RETSIGTYPE popen_timeout_alarm_handler (int); | 8 | void popen_timeout_alarm_handler (int); |
9 | 9 | ||
10 | pid_t *childpid=NULL; | 10 | pid_t *childpid=NULL; |
11 | int *child_stderr_array=NULL; | 11 | int *child_stderr_array=NULL; |
diff --git a/plugins/runcmd.c b/plugins/runcmd.c index 102191e4..ed49bb99 100644 --- a/plugins/runcmd.c +++ b/plugins/runcmd.c | |||
@@ -60,6 +60,8 @@ | |||
60 | # define SIG_ERR ((Sigfunc *)-1) | 60 | # define SIG_ERR ((Sigfunc *)-1) |
61 | #endif | 61 | #endif |
62 | 62 | ||
63 | #include "../lib/maxfd.h" | ||
64 | |||
63 | /* This variable must be global, since there's no way the caller | 65 | /* This variable must be global, since there's no way the caller |
64 | * can forcibly slay a dead or ungainly running program otherwise. | 66 | * can forcibly slay a dead or ungainly running program otherwise. |
65 | * Multithreading apps and plugins can initialize it (via NP_RUNCMD_INIT) | 67 | * Multithreading apps and plugins can initialize it (via NP_RUNCMD_INIT) |
@@ -88,8 +90,7 @@ extern void die (int, const char *, ...) | |||
88 | * through this api and thus achieve async-safeness throughout the api */ | 90 | * through this api and thus achieve async-safeness throughout the api */ |
89 | void np_runcmd_init(void) | 91 | void np_runcmd_init(void) |
90 | { | 92 | { |
91 | if(maxfd == 0) | 93 | long maxfd = mp_open_max(); |
92 | maxfd = open_max(); | ||
93 | if(!np_pids) np_pids = calloc(maxfd, sizeof(pid_t)); | 94 | if(!np_pids) np_pids = calloc(maxfd, sizeof(pid_t)); |
94 | } | 95 | } |
95 | 96 | ||
@@ -114,7 +115,7 @@ np_runcmd_open(const char *cmdstring, int *pfd, int *pfderr) | |||
114 | if(!np_pids) NP_RUNCMD_INIT; | 115 | if(!np_pids) NP_RUNCMD_INIT; |
115 | 116 | ||
116 | env[0] = strdup("LC_ALL=C"); | 117 | env[0] = strdup("LC_ALL=C"); |
117 | env[1] = '\0'; | 118 | env[1] = NULL; |
118 | 119 | ||
119 | /* make copy of command string so strtok() doesn't silently modify it */ | 120 | /* make copy of command string so strtok() doesn't silently modify it */ |
120 | /* (the calling program may want to access it later) */ | 121 | /* (the calling program may want to access it later) */ |
@@ -192,6 +193,7 @@ np_runcmd_open(const char *cmdstring, int *pfd, int *pfderr) | |||
192 | /* close all descriptors in np_pids[] | 193 | /* close all descriptors in np_pids[] |
193 | * This is executed in a separate address space (pure child), | 194 | * This is executed in a separate address space (pure child), |
194 | * so we don't have to worry about async safety */ | 195 | * so we don't have to worry about async safety */ |
196 | long maxfd = mp_open_max(); | ||
195 | for (i = 0; i < maxfd; i++) | 197 | for (i = 0; i < maxfd; i++) |
196 | if(np_pids[i] > 0) | 198 | if(np_pids[i] > 0) |
197 | close (i); | 199 | close (i); |
@@ -219,6 +221,7 @@ np_runcmd_close(int fd) | |||
219 | pid_t pid; | 221 | pid_t pid; |
220 | 222 | ||
221 | /* make sure this fd was opened by popen() */ | 223 | /* make sure this fd was opened by popen() */ |
224 | long maxfd = mp_open_max(); | ||
222 | if(fd < 0 || fd > maxfd || !np_pids || (pid = np_pids[fd]) == 0) | 225 | if(fd < 0 || fd > maxfd || !np_pids || (pid = np_pids[fd]) == 0) |
223 | return -1; | 226 | return -1; |
224 | 227 | ||
@@ -237,12 +240,12 @@ np_runcmd_close(int fd) | |||
237 | void | 240 | void |
238 | runcmd_timeout_alarm_handler (int signo) | 241 | runcmd_timeout_alarm_handler (int signo) |
239 | { | 242 | { |
240 | size_t i; | ||
241 | 243 | ||
242 | if (signo == SIGALRM) | 244 | if (signo == SIGALRM) |
243 | puts(_("CRITICAL - Plugin timed out while executing system call")); | 245 | puts(_("CRITICAL - Plugin timed out while executing system call")); |
244 | 246 | ||
245 | if(np_pids) for(i = 0; i < maxfd; i++) { | 247 | long maxfd = mp_open_max(); |
248 | if(np_pids) for(long int i = 0; i < maxfd; i++) { | ||
246 | if(np_pids[i] != 0) kill(np_pids[i], SIGKILL); | 249 | if(np_pids[i] != 0) kill(np_pids[i], SIGKILL); |
247 | } | 250 | } |
248 | 251 | ||
diff --git a/plugins/sslutils.c b/plugins/sslutils.c index 666a0120..6bc0ba81 100644 --- a/plugins/sslutils.c +++ b/plugins/sslutils.c | |||
@@ -31,9 +31,8 @@ | |||
31 | #include "netutils.h" | 31 | #include "netutils.h" |
32 | 32 | ||
33 | #ifdef HAVE_SSL | 33 | #ifdef HAVE_SSL |
34 | static SSL_CTX *c=NULL; | 34 | static SSL_CTX *ctx=NULL; |
35 | static SSL *s=NULL; | 35 | static SSL *s=NULL; |
36 | static int initialized=0; | ||
37 | 36 | ||
38 | int np_net_ssl_init(int sd) { | 37 | int np_net_ssl_init(int sd) { |
39 | return np_net_ssl_init_with_hostname(sd, NULL); | 38 | return np_net_ssl_init_with_hostname(sd, NULL); |
@@ -48,24 +47,24 @@ int np_net_ssl_init_with_hostname_and_version(int sd, char *host_name, int versi | |||
48 | } | 47 | } |
49 | 48 | ||
50 | int np_net_ssl_init_with_hostname_version_and_cert(int sd, char *host_name, int version, char *cert, char *privkey) { | 49 | int np_net_ssl_init_with_hostname_version_and_cert(int sd, char *host_name, int version, char *cert, char *privkey) { |
51 | const SSL_METHOD *method = NULL; | ||
52 | long options = 0; | 50 | long options = 0; |
53 | 51 | ||
52 | if ((ctx = SSL_CTX_new(TLS_client_method())) == NULL) { | ||
53 | printf("%s\n", _("CRITICAL - Cannot create SSL context.")); | ||
54 | return STATE_CRITICAL; | ||
55 | } | ||
56 | |||
54 | switch (version) { | 57 | switch (version) { |
55 | case MP_SSLv2: /* SSLv2 protocol */ | 58 | case MP_SSLv2: /* SSLv2 protocol */ |
56 | #if defined(USE_GNUTLS) || defined(OPENSSL_NO_SSL2) | ||
57 | printf("%s\n", _("UNKNOWN - SSL protocol version 2 is not supported by your SSL library.")); | 59 | printf("%s\n", _("UNKNOWN - SSL protocol version 2 is not supported by your SSL library.")); |
58 | return STATE_UNKNOWN; | 60 | return STATE_UNKNOWN; |
59 | #else | ||
60 | method = SSLv2_client_method(); | ||
61 | break; | ||
62 | #endif | ||
63 | case MP_SSLv3: /* SSLv3 protocol */ | 61 | case MP_SSLv3: /* SSLv3 protocol */ |
64 | #if defined(OPENSSL_NO_SSL3) | 62 | #if defined(OPENSSL_NO_SSL3) |
65 | printf("%s\n", _("UNKNOWN - SSL protocol version 3 is not supported by your SSL library.")); | 63 | printf("%s\n", _("UNKNOWN - SSL protocol version 3 is not supported by your SSL library.")); |
66 | return STATE_UNKNOWN; | 64 | return STATE_UNKNOWN; |
67 | #else | 65 | #else |
68 | method = SSLv3_client_method(); | 66 | SSL_CTX_set_min_proto_version(ctx, SSL3_VERSION); |
67 | SSL_CTX_set_max_proto_version(ctx, SSL3_VERSION); | ||
69 | break; | 68 | break; |
70 | #endif | 69 | #endif |
71 | case MP_TLSv1: /* TLSv1 protocol */ | 70 | case MP_TLSv1: /* TLSv1 protocol */ |
@@ -73,7 +72,8 @@ int np_net_ssl_init_with_hostname_version_and_cert(int sd, char *host_name, int | |||
73 | printf("%s\n", _("UNKNOWN - TLS protocol version 1 is not supported by your SSL library.")); | 72 | printf("%s\n", _("UNKNOWN - TLS protocol version 1 is not supported by your SSL library.")); |
74 | return STATE_UNKNOWN; | 73 | return STATE_UNKNOWN; |
75 | #else | 74 | #else |
76 | method = TLSv1_client_method(); | 75 | SSL_CTX_set_min_proto_version(ctx, TLS1_VERSION); |
76 | SSL_CTX_set_max_proto_version(ctx, TLS1_VERSION); | ||
77 | break; | 77 | break; |
78 | #endif | 78 | #endif |
79 | case MP_TLSv1_1: /* TLSv1.1 protocol */ | 79 | case MP_TLSv1_1: /* TLSv1.1 protocol */ |
@@ -81,7 +81,8 @@ int np_net_ssl_init_with_hostname_version_and_cert(int sd, char *host_name, int | |||
81 | printf("%s\n", _("UNKNOWN - TLS protocol version 1.1 is not supported by your SSL library.")); | 81 | printf("%s\n", _("UNKNOWN - TLS protocol version 1.1 is not supported by your SSL library.")); |
82 | return STATE_UNKNOWN; | 82 | return STATE_UNKNOWN; |
83 | #else | 83 | #else |
84 | method = TLSv1_1_client_method(); | 84 | SSL_CTX_set_min_proto_version(ctx, TLS1_1_VERSION); |
85 | SSL_CTX_set_max_proto_version(ctx, TLS1_1_VERSION); | ||
85 | break; | 86 | break; |
86 | #endif | 87 | #endif |
87 | case MP_TLSv1_2: /* TLSv1.2 protocol */ | 88 | case MP_TLSv1_2: /* TLSv1.2 protocol */ |
@@ -89,7 +90,8 @@ int np_net_ssl_init_with_hostname_version_and_cert(int sd, char *host_name, int | |||
89 | printf("%s\n", _("UNKNOWN - TLS protocol version 1.2 is not supported by your SSL library.")); | 90 | printf("%s\n", _("UNKNOWN - TLS protocol version 1.2 is not supported by your SSL library.")); |
90 | return STATE_UNKNOWN; | 91 | return STATE_UNKNOWN; |
91 | #else | 92 | #else |
92 | method = TLSv1_2_client_method(); | 93 | SSL_CTX_set_min_proto_version(ctx, TLS1_2_VERSION); |
94 | SSL_CTX_set_max_proto_version(ctx, TLS1_2_VERSION); | ||
93 | break; | 95 | break; |
94 | #endif | 96 | #endif |
95 | case MP_TLSv1_2_OR_NEWER: | 97 | case MP_TLSv1_2_OR_NEWER: |
@@ -97,56 +99,43 @@ int np_net_ssl_init_with_hostname_version_and_cert(int sd, char *host_name, int | |||
97 | printf("%s\n", _("UNKNOWN - Disabling TLSv1.1 is not supported by your SSL library.")); | 99 | printf("%s\n", _("UNKNOWN - Disabling TLSv1.1 is not supported by your SSL library.")); |
98 | return STATE_UNKNOWN; | 100 | return STATE_UNKNOWN; |
99 | #else | 101 | #else |
100 | options |= SSL_OP_NO_TLSv1_1; | 102 | SSL_CTX_set_min_proto_version(ctx, TLS1_2_VERSION); |
103 | break; | ||
101 | #endif | 104 | #endif |
102 | /* FALLTHROUGH */ | ||
103 | case MP_TLSv1_1_OR_NEWER: | 105 | case MP_TLSv1_1_OR_NEWER: |
104 | #if !defined(SSL_OP_NO_TLSv1) | 106 | #if !defined(SSL_OP_NO_TLSv1) |
105 | printf("%s\n", _("UNKNOWN - Disabling TLSv1 is not supported by your SSL library.")); | 107 | printf("%s\n", _("UNKNOWN - Disabling TLSv1 is not supported by your SSL library.")); |
106 | return STATE_UNKNOWN; | 108 | return STATE_UNKNOWN; |
107 | #else | 109 | #else |
108 | options |= SSL_OP_NO_TLSv1; | 110 | SSL_CTX_set_min_proto_version(ctx, TLS1_1_VERSION); |
111 | break; | ||
109 | #endif | 112 | #endif |
110 | /* FALLTHROUGH */ | ||
111 | case MP_TLSv1_OR_NEWER: | 113 | case MP_TLSv1_OR_NEWER: |
112 | #if defined(SSL_OP_NO_SSLv3) | 114 | #if defined(SSL_OP_NO_SSLv3) |
113 | options |= SSL_OP_NO_SSLv3; | 115 | SSL_CTX_set_min_proto_version(ctx, TLS1_VERSION); |
116 | break; | ||
114 | #endif | 117 | #endif |
115 | /* FALLTHROUGH */ | ||
116 | case MP_SSLv3_OR_NEWER: | 118 | case MP_SSLv3_OR_NEWER: |
117 | #if defined(SSL_OP_NO_SSLv2) | 119 | #if defined(SSL_OP_NO_SSLv2) |
118 | options |= SSL_OP_NO_SSLv2; | 120 | SSL_CTX_set_min_proto_version(ctx, SSL3_VERSION); |
121 | break; | ||
119 | #endif | 122 | #endif |
120 | case MP_SSLv2_OR_NEWER: | ||
121 | /* FALLTHROUGH */ | ||
122 | default: /* Default to auto negotiation */ | ||
123 | method = SSLv23_client_method(); | ||
124 | } | ||
125 | if (!initialized) { | ||
126 | /* Initialize SSL context */ | ||
127 | SSLeay_add_ssl_algorithms(); | ||
128 | SSL_load_error_strings(); | ||
129 | OpenSSL_add_all_algorithms(); | ||
130 | initialized = 1; | ||
131 | } | ||
132 | if ((c = SSL_CTX_new(method)) == NULL) { | ||
133 | printf("%s\n", _("CRITICAL - Cannot create SSL context.")); | ||
134 | return STATE_CRITICAL; | ||
135 | } | 123 | } |
124 | |||
136 | if (cert && privkey) { | 125 | if (cert && privkey) { |
137 | #ifdef USE_OPENSSL | 126 | #ifdef USE_OPENSSL |
138 | if (!SSL_CTX_use_certificate_chain_file(c, cert)) { | 127 | if (!SSL_CTX_use_certificate_chain_file(ctx, cert)) { |
139 | #elif USE_GNUTLS | 128 | #elif USE_GNUTLS |
140 | if (!SSL_CTX_use_certificate_file(c, cert, SSL_FILETYPE_PEM)) { | 129 | if (!SSL_CTX_use_certificate_file(ctx, cert, SSL_FILETYPE_PEM)) { |
141 | #else | 130 | #else |
142 | #error Unported for unknown SSL library | 131 | #error Unported for unknown SSL library |
143 | #endif | 132 | #endif |
144 | printf ("%s\n", _("CRITICAL - Unable to open certificate chain file!\n")); | 133 | printf ("%s\n", _("CRITICAL - Unable to open certificate chain file!\n")); |
145 | return STATE_CRITICAL; | 134 | return STATE_CRITICAL; |
146 | } | 135 | } |
147 | SSL_CTX_use_PrivateKey_file(c, privkey, SSL_FILETYPE_PEM); | 136 | SSL_CTX_use_PrivateKey_file(ctx, privkey, SSL_FILETYPE_PEM); |
148 | #ifdef USE_OPENSSL | 137 | #ifdef USE_OPENSSL |
149 | if (!SSL_CTX_check_private_key(c)) { | 138 | if (!SSL_CTX_check_private_key(ctx)) { |
150 | printf ("%s\n", _("CRITICAL - Private key does not seem to match certificate!\n")); | 139 | printf ("%s\n", _("CRITICAL - Private key does not seem to match certificate!\n")); |
151 | return STATE_CRITICAL; | 140 | return STATE_CRITICAL; |
152 | } | 141 | } |
@@ -155,9 +144,9 @@ int np_net_ssl_init_with_hostname_version_and_cert(int sd, char *host_name, int | |||
155 | #ifdef SSL_OP_NO_TICKET | 144 | #ifdef SSL_OP_NO_TICKET |
156 | options |= SSL_OP_NO_TICKET; | 145 | options |= SSL_OP_NO_TICKET; |
157 | #endif | 146 | #endif |
158 | SSL_CTX_set_options(c, options); | 147 | SSL_CTX_set_options(ctx, options); |
159 | SSL_CTX_set_mode(c, SSL_MODE_AUTO_RETRY); | 148 | SSL_CTX_set_mode(ctx, SSL_MODE_AUTO_RETRY); |
160 | if ((s = SSL_new(c)) != NULL) { | 149 | if ((s = SSL_new(ctx)) != NULL) { |
161 | #ifdef SSL_set_tlsext_host_name | 150 | #ifdef SSL_set_tlsext_host_name |
162 | if (host_name != NULL) | 151 | if (host_name != NULL) |
163 | SSL_set_tlsext_host_name(s, host_name); | 152 | SSL_set_tlsext_host_name(s, host_name); |
@@ -184,9 +173,9 @@ void np_net_ssl_cleanup() { | |||
184 | #endif | 173 | #endif |
185 | SSL_shutdown(s); | 174 | SSL_shutdown(s); |
186 | SSL_free(s); | 175 | SSL_free(s); |
187 | if (c) { | 176 | if (ctx) { |
188 | SSL_CTX_free(c); | 177 | SSL_CTX_free(ctx); |
189 | c=NULL; | 178 | ctx=NULL; |
190 | } | 179 | } |
191 | s=NULL; | 180 | s=NULL; |
192 | } | 181 | } |
diff --git a/plugins/t/check_curl.t b/plugins/t/check_curl.t index eae98cc1..7a930a4e 100644 --- a/plugins/t/check_curl.t +++ b/plugins/t/check_curl.t | |||
@@ -205,9 +205,9 @@ SKIP: { | |||
205 | like ( $res->output, '/time_connect=[\d\.]+/', 'Extended Performance Data Output OK' ); | 205 | like ( $res->output, '/time_connect=[\d\.]+/', 'Extended Performance Data Output OK' ); |
206 | like ( $res->output, '/time_ssl=[\d\.]+/', 'Extended Performance Data SSL Output OK' ); | 206 | like ( $res->output, '/time_ssl=[\d\.]+/', 'Extended Performance Data SSL Output OK' ); |
207 | 207 | ||
208 | $res = NPTest->testCmd( "./$plugin -H www.mozilla.com -u /firefox -f curl" ); | 208 | $res = NPTest->testCmd( "./$plugin -H monitoring-plugins.org -u /download.html -f follow" ); |
209 | is( $res->return_code, 0, "Redirection based on location is okay"); | 209 | is( $res->return_code, 0, "Redirection based on location is okay"); |
210 | 210 | ||
211 | $res = NPTest->testCmd( "./$plugin -H www.mozilla.com --extended-perfdata" ); | 211 | $res = NPTest->testCmd( "./$plugin -H monitoring-plugins.org --extended-perfdata" ); |
212 | like ( $res->output, '/time_connect=[\d\.]+/', 'Extended Performance Data Output OK' ); | 212 | like ( $res->output, '/time_connect=[\d\.]+/', 'Extended Performance Data Output OK' ); |
213 | } | 213 | } |
diff --git a/plugins/t/check_disk.t b/plugins/t/check_disk.t index ca035ce7..9eb77ce4 100644 --- a/plugins/t/check_disk.t +++ b/plugins/t/check_disk.t | |||
@@ -23,11 +23,11 @@ my $mountpoint2_valid = getTestParameter( "NP_MOUNTPOINT2_VALID", "Path to anoth | |||
23 | if ($mountpoint_valid eq "" or $mountpoint2_valid eq "") { | 23 | if ($mountpoint_valid eq "" or $mountpoint2_valid eq "") { |
24 | plan skip_all => "Need 2 mountpoints to test"; | 24 | plan skip_all => "Need 2 mountpoints to test"; |
25 | } else { | 25 | } else { |
26 | plan tests => 88; | 26 | plan tests => 94; |
27 | } | 27 | } |
28 | 28 | ||
29 | $result = NPTest->testCmd( | 29 | $result = NPTest->testCmd( |
30 | "./check_disk -w 1% -c 1% -p $mountpoint_valid -w 1% -c 1% -p $mountpoint2_valid" | 30 | "./check_disk -w 1% -c 1% -p $mountpoint_valid -w 1% -c 1% -p $mountpoint2_valid" |
31 | ); | 31 | ); |
32 | cmp_ok( $result->return_code, "==", 0, "Checking two mountpoints (must have at least 1% free in space and inodes)"); | 32 | cmp_ok( $result->return_code, "==", 0, "Checking two mountpoints (must have at least 1% free in space and inodes)"); |
33 | my $c = 0; | 33 | my $c = 0; |
@@ -44,7 +44,7 @@ my @perf_data = sort(split(/ /, $result->perf_output)); | |||
44 | # Calculate avg_free free on mountpoint1 and mountpoint2 | 44 | # Calculate avg_free free on mountpoint1 and mountpoint2 |
45 | # because if you check in the middle, you should get different errors | 45 | # because if you check in the middle, you should get different errors |
46 | $_ = $result->output; | 46 | $_ = $result->output; |
47 | my ($free_on_mp1, $free_on_mp2) = (m/\((\d+)%.*\((\d+)%/); | 47 | my ($free_on_mp1, $free_on_mp2) = (m/\((\d+\.\d+)%.*\((\d+\.\d+)%/); |
48 | die "Cannot parse output: $_" unless ($free_on_mp1 && $free_on_mp2); | 48 | die "Cannot parse output: $_" unless ($free_on_mp1 && $free_on_mp2); |
49 | my $avg_free = ceil(($free_on_mp1+$free_on_mp2)/2); | 49 | my $avg_free = ceil(($free_on_mp1+$free_on_mp2)/2); |
50 | my ($more_free, $less_free); | 50 | my ($more_free, $less_free); |
@@ -103,8 +103,8 @@ is ($crit_percth_data, int((1-10/100)*$total_percth_data), "Wrong critical in pe | |||
103 | 103 | ||
104 | 104 | ||
105 | # Check when order of mount points are reversed, that perf data remains same | 105 | # Check when order of mount points are reversed, that perf data remains same |
106 | $result = NPTest->testCmd( | 106 | $result = NPTest->testCmd( |
107 | "./check_disk -w 1% -c 1% -p $mountpoint2_valid -w 1% -c 1% -p $mountpoint_valid" | 107 | "./check_disk -w 1% -c 1% -p $mountpoint2_valid -w 1% -c 1% -p $mountpoint_valid" |
108 | ); | 108 | ); |
109 | @_ = sort(split(/ /, $result->perf_output)); | 109 | @_ = sort(split(/ /, $result->perf_output)); |
110 | is_deeply( \@perf_data, \@_, "perf data for both filesystems same when reversed"); | 110 | 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"); | |||
119 | 119 | ||
120 | $result = NPTest->testCmd( "./check_disk -w 1 -c 1 -p $more_free -p $less_free" ); | 120 | $result = NPTest->testCmd( "./check_disk -w 1 -c 1 -p $more_free -p $less_free" ); |
121 | cmp_ok( $result->return_code, '==', 0, "At least 1 MB available on $more_free and $less_free"); | 121 | cmp_ok( $result->return_code, '==', 0, "At least 1 MB available on $more_free and $less_free"); |
122 | |||
122 | $_ = $result->output; | 123 | $_ = $result->output; |
124 | |||
123 | my ($free_mb_on_mp1, $free_mb_on_mp2) = (m/(\d+)MiB .* (\d+)MiB /g); | 125 | my ($free_mb_on_mp1, $free_mb_on_mp2) = (m/(\d+)MiB .* (\d+)MiB /g); |
126 | die "Cannot parse output: $_" unless ($free_mb_on_mp1 && $free_mb_on_mp2); | ||
127 | |||
124 | my $free_mb_on_all = $free_mb_on_mp1 + $free_mb_on_mp2; | 128 | my $free_mb_on_all = $free_mb_on_mp1 + $free_mb_on_mp2; |
125 | 129 | ||
126 | 130 | ||
@@ -134,8 +138,8 @@ cmp_ok( $result->return_code, '==', 0, "Old syntax okay" ); | |||
134 | $result = NPTest->testCmd( "./check_disk -w 1% -c 1% -p $more_free" ); | 138 | $result = NPTest->testCmd( "./check_disk -w 1% -c 1% -p $more_free" ); |
135 | cmp_ok( $result->return_code, "==", 0, "At least 1% free" ); | 139 | cmp_ok( $result->return_code, "==", 0, "At least 1% free" ); |
136 | 140 | ||
137 | $result = NPTest->testCmd( | 141 | $result = NPTest->testCmd( |
138 | "./check_disk -w 1% -c 1% -p $more_free -w 100% -c 100% -p $less_free" | 142 | "./check_disk -w 1% -c 1% -p $more_free -w 100% -c 100% -p $less_free" |
139 | ); | 143 | ); |
140 | cmp_ok( $result->return_code, "==", 2, "Get critical on less_free mountpoint $less_free" ); | 144 | cmp_ok( $result->return_code, "==", 2, "Get critical on less_free mountpoint $less_free" ); |
141 | like( $result->output, $failureOutput, "Right output" ); | 145 | like( $result->output, $failureOutput, "Right output" ); |
@@ -151,14 +155,14 @@ $result = NPTest->testCmd( | |||
151 | ); | 155 | ); |
152 | cmp_ok( $result->return_code, '==', 0, "Get ok on more_free mountpoint, when checking avg_free"); | 156 | cmp_ok( $result->return_code, '==', 0, "Get ok on more_free mountpoint, when checking avg_free"); |
153 | 157 | ||
154 | $result = NPTest->testCmd( | 158 | $result = NPTest->testCmd( |
155 | "./check_disk -w $avg_free% -c 0% -p $less_free -w $avg_free% -c $avg_free% -p $more_free" | 159 | "./check_disk -w $avg_free% -c 0% -p $less_free -w $avg_free% -c $avg_free% -p $more_free" |
156 | ); | 160 | ); |
157 | cmp_ok( $result->return_code, "==", 1, "Combining above two tests, get warning"); | 161 | cmp_ok( $result->return_code, "==", 1, "Combining above two tests, get warning"); |
158 | my $all_disks = $result->output; | 162 | my $all_disks = $result->output; |
159 | 163 | ||
160 | $result = NPTest->testCmd( | 164 | $result = NPTest->testCmd( |
161 | "./check_disk -e -w $avg_free% -c 0% -p $less_free -w $avg_free% -c $avg_free% -p $more_free" | 165 | "./check_disk -e -w $avg_free% -c 0% -p $less_free -w $avg_free% -c $avg_free% -p $more_free" |
162 | ); | 166 | ); |
163 | isnt( $result->output, $all_disks, "-e gives different output"); | 167 | isnt( $result->output, $all_disks, "-e gives different output"); |
164 | 168 | ||
@@ -240,7 +244,7 @@ TODO: { | |||
240 | cmp_ok( $result->return_code, '==', 3, "Invalid command line options" ); | 244 | cmp_ok( $result->return_code, '==', 3, "Invalid command line options" ); |
241 | } | 245 | } |
242 | 246 | ||
243 | $result = NPTest->testCmd( | 247 | $result = NPTest->testCmd( |
244 | "./check_disk -p $mountpoint_valid -w 10% -c 15%" | 248 | "./check_disk -p $mountpoint_valid -w 10% -c 15%" |
245 | ); | 249 | ); |
246 | cmp_ok( $result->return_code, "==", 3, "Invalid options: -p must come after thresholds" ); | 250 | 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 | |||
311 | like( $result->output, '/;.*;\|/', "-C selects partitions if -p is not given"); | 315 | like( $result->output, '/;.*;\|/', "-C selects partitions if -p is not given"); |
312 | 316 | ||
313 | # grouping: exit crit if the sum of free megs on mp1+mp2 is less than warn/crit | 317 | # grouping: exit crit if the sum of free megs on mp1+mp2 is less than warn/crit |
314 | $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" ); | 318 | $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" ); |
315 | cmp_ok( $result->return_code, '==', 2, "grouping: exit crit if the sum of free megs on mp1+mp2 is less than warn/crit"); | 319 | 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); |
316 | 320 | ||
317 | # grouping: exit warning if the sum of free megs on mp1+mp2 is between -w and -c | 321 | # grouping: exit warning if the sum of free megs on mp1+mp2 is between -w and -c |
318 | $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 | $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 | |||
322 | $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" ); | 326 | $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" ); |
323 | cmp_ok( $result->return_code, '==', 0, "grouping: exit ok if the sum of free megs on mp1+mp2 is more than warn/crit"); | 327 | cmp_ok( $result->return_code, '==', 0, "grouping: exit ok if the sum of free megs on mp1+mp2 is more than warn/crit"); |
324 | 328 | ||
325 | # grouping: exit unknown if group name is given after -p | 329 | # grouping: exit unknown if group name is given after -p |
326 | $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" ); | 330 | $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" ); |
327 | cmp_ok( $result->return_code, '==', 3, "Invalid options: -p must come after groupname"); | 331 | cmp_ok( $result->return_code, '==', 3, "Invalid options: -p must come after groupname"); |
328 | 332 | ||
@@ -355,17 +359,17 @@ like( $result->output, qr/$mountpoint2_valid/,"ignore: output data does have $mo | |||
355 | # ignore-missing: exit okay, when fs is not accessible | 359 | # ignore-missing: exit okay, when fs is not accessible |
356 | $result = NPTest->testCmd( "./check_disk --ignore-missing -w 0% -c 0% -p /bob"); | 360 | $result = NPTest->testCmd( "./check_disk --ignore-missing -w 0% -c 0% -p /bob"); |
357 | cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay for not existing filesystem /bob"); | 361 | cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay for not existing filesystem /bob"); |
358 | like( $result->output, '/^DISK OK - No disks were found for provided parameters; - ignored paths: /bob;.*$/', 'Output OK'); | 362 | like( $result->output, '/^DISK OK - No disks were found for provided parameters - ignored paths: /bob;.*$/', 'Output OK'); |
359 | 363 | ||
360 | # ignore-missing: exit okay, when regex does not match | 364 | # ignore-missing: exit okay, when regex does not match |
361 | $result = NPTest->testCmd( "./check_disk --ignore-missing -w 0% -c 0% -r /bob"); | 365 | $result = NPTest->testCmd( "./check_disk --ignore-missing -w 0% -c 0% -r /bob"); |
362 | cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay for regular expression not matching"); | 366 | cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay for regular expression not matching"); |
363 | like( $result->output, '/^DISK OK - No disks were found for provided parameters;.*$/', 'Output OK'); | 367 | like( $result->output, '/^DISK OK - No disks were found for provided parameters.*$/', 'Output OK'); |
364 | 368 | ||
365 | # ignore-missing: exit okay, when fs with exact match (-E) is not found | 369 | # ignore-missing: exit okay, when fs with exact match (-E) is not found |
366 | $result = NPTest->testCmd( "./check_disk --ignore-missing -w 0% -c 0% -E -p /etc"); | 370 | $result = NPTest->testCmd( "./check_disk --ignore-missing -w 0% -c 0% -E -p /etc"); |
367 | cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay when exact match does not find fs"); | 371 | cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay when exact match does not find fs"); |
368 | like( $result->output, '/^DISK OK - No disks were found for provided parameters; - ignored paths: /etc;.*$/', 'Output OK'); | 372 | like( $result->output, '/^DISK OK - No disks were found for provided parameters - ignored paths: /etc;.*$/', 'Output OK'); |
369 | 373 | ||
370 | # ignore-missing: exit okay, when checking one existing fs and one non-existing fs (regex) | 374 | # ignore-missing: exit okay, when checking one existing fs and one non-existing fs (regex) |
371 | $result = NPTest->testCmd( "./check_disk --ignore-missing -w 0% -c 0% -r '/bob' -r '^/\$'"); | 375 | $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'); | |||
375 | # ignore-missing: exit okay, when checking one existing fs and one non-existing fs (path) | 379 | # ignore-missing: exit okay, when checking one existing fs and one non-existing fs (path) |
376 | $result = NPTest->testCmd( "./check_disk --ignore-missing -w 0% -c 0% -p '/bob' -p '/'"); | 380 | $result = NPTest->testCmd( "./check_disk --ignore-missing -w 0% -c 0% -p '/bob' -p '/'"); |
377 | cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay for regular expression not matching"); | 381 | cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay for regular expression not matching"); |
378 | like( $result->output, '/^DISK OK - free space: / .*; - ignored paths: /bob;.*$/', 'Output OK'); \ No newline at end of file | 382 | like( $result->output, '/^DISK OK - free space: / .*; - ignored paths: /bob;.*$/', 'Output OK'); |
383 | |||
384 | # ignore-missing: exit okay, when checking one non-existing fs (path) and one ignored | ||
385 | $result = NPTest->testCmd( "./check_disk -n -w 0% -c 0% -r /dummy -i /dummy2"); | ||
386 | cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay for regular expression not matching"); | ||
387 | like( $result->output, '/^DISK OK - No disks were found for provided parameters\|$/', 'Output OK'); | ||
388 | |||
389 | # ignore-missing: exit okay, when regex match does not find anything | ||
390 | $result = NPTest->testCmd( "./check_disk -n -e -l -w 10% -c 5% -W 10% -K 5% -r /dummy"); | ||
391 | cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay for regular expression not matching"); | ||
392 | like( $result->output, '/^DISK OK\|$/', 'Output OK'); | ||
393 | |||
394 | # ignore-missing: exit okay, when regex match does not find anything | ||
395 | $result = NPTest->testCmd( "./check_disk -n -l -w 10% -c 5% -W 10% -K 5% -r /dummy"); | ||
396 | cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay for regular expression not matching"); | ||
397 | like( $result->output, '/^DISK OK - No disks were found for provided parameters\|$/', 'Output OK'); | ||
diff --git a/plugins/t/check_http.t b/plugins/t/check_http.t index 1f2fbdfd..6ab4a5b6 100644 --- a/plugins/t/check_http.t +++ b/plugins/t/check_http.t | |||
@@ -166,10 +166,10 @@ SKIP: { | |||
166 | like ( $res->output, '/time_connect=[\d\.]+/', 'Extended Performance Data Output OK' ); | 166 | like ( $res->output, '/time_connect=[\d\.]+/', 'Extended Performance Data Output OK' ); |
167 | like ( $res->output, '/time_ssl=[\d\.]+/', 'Extended Performance Data SSL Output OK' ); | 167 | like ( $res->output, '/time_ssl=[\d\.]+/', 'Extended Performance Data SSL Output OK' ); |
168 | 168 | ||
169 | $res = NPTest->testCmd( "./$plugin -H www.mozilla.com -u /firefox -f follow" ); | 169 | $res = NPTest->testCmd( "./$plugin -H monitoring-plugins.org -u /download.html -f follow" ); |
170 | is( $res->return_code, 0, "Redirection based on location is okay"); | 170 | is( $res->return_code, 0, "Redirection based on location is okay"); |
171 | 171 | ||
172 | $res = NPTest->testCmd( "./$plugin -H www.mozilla.com --extended-perfdata" ); | 172 | $res = NPTest->testCmd( "./$plugin -H monitoring-plugins.org --extended-perfdata" ); |
173 | like ( $res->output, '/time_connect=[\d\.]+/', 'Extended Performance Data Output OK' ); | 173 | like ( $res->output, '/time_connect=[\d\.]+/', 'Extended Performance Data Output OK' ); |
174 | } | 174 | } |
175 | 175 | ||
diff --git a/plugins/t/check_imap.t b/plugins/t/check_imap.t index 7c74e564..cf2f81c8 100644 --- a/plugins/t/check_imap.t +++ b/plugins/t/check_imap.t | |||
@@ -25,7 +25,7 @@ $t = NPTest->testCmd( "./check_imap $host_tcp_imap -p 143 -wt 9 -ct 9 -to 10 -e | |||
25 | cmp_ok( $t->return_code, '==', 0, "Check old parameter options" ); | 25 | cmp_ok( $t->return_code, '==', 0, "Check old parameter options" ); |
26 | 26 | ||
27 | $t = NPTest->testCmd( "./check_imap $host_nonresponsive" ); | 27 | $t = NPTest->testCmd( "./check_imap $host_nonresponsive" ); |
28 | cmp_ok( $t->return_code, '==', 2, "Get error with non reponsive host" ); | 28 | cmp_ok( $t->return_code, '==', 2, "Get error with non responsive host" ); |
29 | 29 | ||
30 | $t = NPTest->testCmd( "./check_imap $hostname_invalid" ); | 30 | $t = NPTest->testCmd( "./check_imap $hostname_invalid" ); |
31 | cmp_ok( $t->return_code, '==', 2, "Invalid hostname" ); | 31 | cmp_ok( $t->return_code, '==', 2, "Invalid hostname" ); |
diff --git a/plugins/t/check_ssh.t b/plugins/t/check_ssh.t index a5cd23ce..907d33a8 100644 --- a/plugins/t/check_ssh.t +++ b/plugins/t/check_ssh.t | |||
@@ -8,34 +8,116 @@ use strict; | |||
8 | use Test::More; | 8 | use Test::More; |
9 | use NPTest; | 9 | use NPTest; |
10 | 10 | ||
11 | my $res; | ||
12 | |||
11 | # Required parameters | 13 | # Required parameters |
12 | my $ssh_host = getTestParameter("NP_SSH_HOST", "A host providing SSH service", "localhost"); | 14 | my $ssh_host = getTestParameter("NP_SSH_HOST", |
13 | my $host_nonresponsive = getTestParameter("NP_HOST_NONRESPONSIVE", "The hostname of system not responsive to network requests", "10.0.0.1" ); | 15 | "A host providing SSH service", |
14 | my $hostname_invalid = getTestParameter("NP_HOSTNAME_INVALID", "An invalid (not known to DNS) hostname", "nosuchhost" ); | 16 | "localhost"); |
17 | |||
18 | my $host_nonresponsive = getTestParameter("NP_HOST_NONRESPONSIVE", | ||
19 | "The hostname of system not responsive to network requests", | ||
20 | "10.0.0.1" ); | ||
21 | |||
22 | my $hostname_invalid = getTestParameter("NP_HOSTNAME_INVALID", | ||
23 | "An invalid (not known to DNS) hostname", | ||
24 | "nosuchhost" ); | ||
25 | |||
26 | |||
27 | plan tests => 14 + 6; | ||
28 | |||
29 | SKIP: { | ||
30 | skip "SSH_HOST must be defined", 6 unless $ssh_host; | ||
31 | my $result = NPTest->testCmd( | ||
32 | "./check_ssh -H $ssh_host" | ||
33 | ); | ||
34 | cmp_ok($result->return_code, '==', 0, "Exit with return code 0 (OK)"); | ||
35 | like($result->output, '/^SSH OK - /', "Status text if command returned none (OK)"); | ||
36 | |||
37 | |||
38 | $result = NPTest->testCmd( | ||
39 | "./check_ssh -H $host_nonresponsive -t 2" | ||
40 | ); | ||
41 | cmp_ok($result->return_code, '==', 2, "Exit with return code 0 (OK)"); | ||
42 | like($result->output, '/^CRITICAL - Socket timeout after 2 seconds/', "Status text if command returned none (OK)"); | ||
43 | |||
44 | |||
45 | |||
46 | $result = NPTest->testCmd( | ||
47 | "./check_ssh -H $hostname_invalid -t 2" | ||
48 | ); | ||
49 | cmp_ok($result->return_code, '==', 3, "Exit with return code 0 (OK)"); | ||
50 | like($result->output, '/^check_ssh: Invalid hostname/', "Status text if command returned none (OK)"); | ||
51 | |||
15 | 52 | ||
53 | } | ||
54 | SKIP: { | ||
16 | 55 | ||
17 | plan skip_all => "SSH_HOST must be defined" unless $ssh_host; | 56 | skip "No netcat available", 14 unless (system("which nc > /dev/null") == 0); |
18 | plan tests => 6; | ||
19 | 57 | ||
58 | # netcat on linux (on debian) will just keep the socket open if not advised otherwise | ||
59 | # therefore we add -q to close it after two seconds after receiving the EOF from input | ||
60 | my $nc_flags = "-l 5003 -N"; | ||
61 | #A valid protocol version control string has the form | ||
62 | # SSH-protoversion-softwareversion SP comments CR LF | ||
63 | # | ||
64 | # where `comments` is optional, protoversion is the SSH protocol version and | ||
65 | # softwareversion is an arbitrary string representing the server software version | ||
66 | open(NC, "echo 'SSH-2.0-nagiosplug.ssh.0.1' | nc ${nc_flags}|"); | ||
67 | sleep 0.1; | ||
68 | $res = NPTest->testCmd( "./check_ssh -H localhost -p 5003" ); | ||
69 | cmp_ok( $res->return_code, '==', 0, "Got SSH protocol version control string"); | ||
70 | like( $res->output, '/^SSH OK - nagiosplug.ssh.0.1 \(protocol 2.0\)/', "Output OK"); | ||
71 | close NC; | ||
20 | 72 | ||
21 | my $result = NPTest->testCmd( | 73 | open(NC, "echo 'SSH-2.0-3.2.9.1' | nc ${nc_flags}|"); |
22 | "./check_ssh -H $ssh_host" | 74 | sleep 0.1; |
23 | ); | 75 | $res = NPTest->testCmd( "./check_ssh -H localhost -p 5003" ); |
24 | cmp_ok($result->return_code, '==', 0, "Exit with return code 0 (OK)"); | 76 | cmp_ok( $res->return_code, "==", 0, "Got SSH protocol version control string with non-alpha softwareversion string"); |
25 | like($result->output, '/^SSH OK - /', "Status text if command returned none (OK)"); | 77 | like( $res->output, '/^SSH OK - 3.2.9.1 \(protocol 2.0\)/', "Output OK for non-alpha softwareversion string"); |
78 | close NC; | ||
26 | 79 | ||
80 | open(NC, "echo 'SSH-2.0-nagiosplug.ssh.0.1 this is a comment' | nc ${nc_flags} |"); | ||
81 | sleep 0.1; | ||
82 | $res = NPTest->testCmd( "./check_ssh -H localhost -p 5003 -r nagiosplug.ssh.0.1" ); | ||
83 | cmp_ok( $res->return_code, '==', 0, "Got SSH protocol version control string, and parsed comment appropriately"); | ||
84 | like( $res->output, '/^SSH OK - nagiosplug.ssh.0.1 \(protocol 2.0\)/', "Output OK"); | ||
85 | close NC; | ||
27 | 86 | ||
28 | $result = NPTest->testCmd( | 87 | open(NC, "echo 'SSH-' | nc ${nc_flags}|"); |
29 | "./check_ssh -H $host_nonresponsive -t 2" | 88 | sleep 0.1; |
30 | ); | 89 | $res = NPTest->testCmd( "./check_ssh -H localhost -p 5003" ); |
31 | cmp_ok($result->return_code, '==', 2, "Exit with return code 0 (OK)"); | 90 | cmp_ok( $res->return_code, '==', 2, "Got invalid SSH protocol version control string"); |
32 | like($result->output, '/^CRITICAL - Socket timeout after 2 seconds/', "Status text if command returned none (OK)"); | 91 | like( $res->output, '/^SSH CRITICAL/', "Output OK"); |
92 | close NC; | ||
33 | 93 | ||
94 | open(NC, "echo '' | nc ${nc_flags}|"); | ||
95 | sleep 0.1; | ||
96 | $res = NPTest->testCmd( "./check_ssh -H localhost -p 5003" ); | ||
97 | cmp_ok( $res->return_code, '==', 2, "No version control string received"); | ||
98 | like( $res->output, '/^SSH CRITICAL - No version control string received/', "Output OK"); | ||
99 | close NC; | ||
34 | 100 | ||
101 | open(NC, "echo 'Not a version control string' | nc ${nc_flags}|"); | ||
102 | sleep 0.1; | ||
103 | $res = NPTest->testCmd( "./check_ssh -H localhost -p 5003" ); | ||
104 | cmp_ok( $res->return_code, '==', 2, "No version control string received"); | ||
105 | like( $res->output, '/^SSH CRITICAL - No version control string received/', "Output OK"); | ||
106 | close NC; | ||
35 | 107 | ||
36 | $result = NPTest->testCmd( | ||
37 | "./check_ssh -H $hostname_invalid -t 2" | ||
38 | ); | ||
39 | cmp_ok($result->return_code, '==', 3, "Exit with return code 0 (OK)"); | ||
40 | like($result->output, '/^check_ssh: Invalid hostname/', "Status text if command returned none (OK)"); | ||
41 | 108 | ||
109 | #RFC 4253 permits servers to send any number of data lines prior to sending the protocol version control string | ||
110 | open(NC, "{ echo 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'; sleep 0.5; | ||
111 | echo 'BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB'; sleep 0.5; | ||
112 | echo 'CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC'; sleep 0.2; | ||
113 | echo 'DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD'; sleep 0.3; | ||
114 | printf 'EEEEEEEEEEEEEEEEEE'; sleep 0.2; | ||
115 | printf 'EEEEEEEEEEEEEEEEEE\n'; sleep 0.2; | ||
116 | echo 'Some\nPrepended\nData\nLines\n'; sleep 0.2; | ||
117 | echo 'SSH-2.0-nagiosplug.ssh.0.2';} | nc ${nc_flags}|"); | ||
118 | sleep 0.1; | ||
119 | $res = NPTest->testCmd( "./check_ssh -H localhost -p 5003" ); | ||
120 | cmp_ok( $res->return_code, '==', 0, "Got delayed SSH protocol version control string"); | ||
121 | like( $res->output, '/^SSH OK - nagiosplug.ssh.0.2 \(protocol 2.0\)/', "Output OK"); | ||
122 | close NC; | ||
123 | } | ||
diff --git a/plugins/t/check_swap.t b/plugins/t/check_swap.t index de9e0f05..18780386 100644 --- a/plugins/t/check_swap.t +++ b/plugins/t/check_swap.t | |||
@@ -5,7 +5,7 @@ | |||
5 | # | 5 | # |
6 | 6 | ||
7 | use strict; | 7 | use strict; |
8 | use Test::More tests => 8; | 8 | use Test::More tests => 14; |
9 | use NPTest; | 9 | use NPTest; |
10 | 10 | ||
11 | my $successOutput = '/^SWAP OK - [0-9]+\% free \([0-9]+MB out of [0-9]+MB\)/'; | 11 | 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\) | |||
14 | 14 | ||
15 | my $result; | 15 | my $result; |
16 | 16 | ||
17 | $result = NPTest->testCmd( "./check_swap" ); # Always OK | ||
18 | cmp_ok( $result->return_code, "==", 0, "Always OK" ); | ||
19 | like( $result->output, $successOutput, "Right output" ); | ||
20 | |||
17 | $result = NPTest->testCmd( "./check_swap -w 1048576 -c 1048576" ); # 1 MB free | 21 | $result = NPTest->testCmd( "./check_swap -w 1048576 -c 1048576" ); # 1 MB free |
18 | cmp_ok( $result->return_code, "==", 0, "At least 1MB free" ); | 22 | cmp_ok( $result->return_code, "==", 0, "At least 1MB free" ); |
19 | like( $result->output, $successOutput, "Right output" ); | 23 | like( $result->output, $successOutput, "Right output" ); |
@@ -29,3 +33,11 @@ like( $result->output, $failureOutput, "Right output" ); | |||
29 | $result = NPTest->testCmd( "./check_swap -w 100% -c 1%" ); # 100% (always warn) | 33 | $result = NPTest->testCmd( "./check_swap -w 100% -c 1%" ); # 100% (always warn) |
30 | cmp_ok( $result->return_code, "==", 1, 'Get warning because not 100% free' ); | 34 | cmp_ok( $result->return_code, "==", 1, 'Get warning because not 100% free' ); |
31 | like( $result->output, $warnOutput, "Right output" ); | 35 | like( $result->output, $warnOutput, "Right output" ); |
36 | |||
37 | $result = NPTest->testCmd( "./check_swap -w 100%" ); # 100% (single threshold, always warn) | ||
38 | cmp_ok( $result->return_code, "==", 1, 'Get warning because not 100% free' ); | ||
39 | like( $result->output, $warnOutput, "Right output" ); | ||
40 | |||
41 | $result = NPTest->testCmd( "./check_swap -c 100%" ); # 100% (single threshold, always critical) | ||
42 | cmp_ok( $result->return_code, "==", 2, 'Get critical because not 100% free' ); | ||
43 | like( $result->output, $failureOutput, "Right output" ); | ||
diff --git a/plugins/t/check_users.t b/plugins/t/check_users.t index 088f3b52..21c3e53d 100644 --- a/plugins/t/check_users.t +++ b/plugins/t/check_users.t | |||
@@ -2,7 +2,7 @@ | |||
2 | # | 2 | # |
3 | # Logged in Users Tests via check_users | 3 | # Logged in Users Tests via check_users |
4 | # | 4 | # |
5 | # Trick: This ckeck requires at least 1 user logged in. These commands should | 5 | # Trick: This check requires at least 1 user logged in. These commands should |
6 | # leave a session open forever in the background: | 6 | # leave a session open forever in the background: |
7 | # | 7 | # |
8 | # $ ssh -tt localhost </dev/null >/dev/null 2>/dev/null & | 8 | # $ ssh -tt localhost </dev/null >/dev/null 2>/dev/null & |
@@ -13,10 +13,11 @@ use Test; | |||
13 | use NPTest; | 13 | use NPTest; |
14 | 14 | ||
15 | use vars qw($tests); | 15 | use vars qw($tests); |
16 | BEGIN {$tests = 8; plan tests => $tests} | 16 | BEGIN {$tests = 12; plan tests => $tests} |
17 | 17 | ||
18 | my $successOutput = '/^USERS OK - [0-9]+ users currently logged in/'; | 18 | my $successOutput = '/^USERS OK - [0-9]+ users currently logged in/'; |
19 | my $failureOutput = '/^USERS CRITICAL - [0-9]+ users currently logged in/'; | 19 | my $failureOutput = '/^USERS CRITICAL - [0-9]+ users currently logged in/'; |
20 | my $wrongOptionOutput = '/Usage:/'; | ||
20 | 21 | ||
21 | my $t; | 22 | my $t; |
22 | 23 | ||
@@ -24,6 +25,8 @@ $t += checkCmd( "./check_users 1000 1000", 0, $successOutput ); | |||
24 | $t += checkCmd( "./check_users 0 0", 2, $failureOutput ); | 25 | $t += checkCmd( "./check_users 0 0", 2, $failureOutput ); |
25 | $t += checkCmd( "./check_users -w 0:1000 -c 0:1000", 0, $successOutput ); | 26 | $t += checkCmd( "./check_users -w 0:1000 -c 0:1000", 0, $successOutput ); |
26 | $t += checkCmd( "./check_users -w 0:0 -c 0:0", 2, $failureOutput ); | 27 | $t += checkCmd( "./check_users -w 0:0 -c 0:0", 2, $failureOutput ); |
28 | $t += checkCmd( "./check_users -w 0:1000", 3, $wrongOptionOutput); | ||
29 | $t += checkCmd( "./check_users", 3, $wrongOptionOutput); | ||
27 | 30 | ||
28 | exit(0) if defined($Test::Harness::VERSION); | 31 | exit(0) if defined($Test::Harness::VERSION); |
29 | exit($tests - $t); | 32 | exit($tests - $t); |
diff --git a/plugins/tests/check_curl.t b/plugins/tests/check_curl.t index 72f2b7c2..eaa9f518 100755 --- a/plugins/tests/check_curl.t +++ b/plugins/tests/check_curl.t | |||
@@ -9,7 +9,7 @@ | |||
9 | # Country Name (2 letter code) [AU]:DE | 9 | # Country Name (2 letter code) [AU]:DE |
10 | # State or Province Name (full name) [Some-State]:Bavaria | 10 | # State or Province Name (full name) [Some-State]:Bavaria |
11 | # Locality Name (eg, city) []:Munich | 11 | # Locality Name (eg, city) []:Munich |
12 | # Organization Name (eg, company) [Internet Widgits Pty Ltd]:Monitoring Plugins | 12 | # Organization Name (eg, company) [Internet Widgets Pty Ltd]:Monitoring Plugins |
13 | # Organizational Unit Name (eg, section) []: | 13 | # Organizational Unit Name (eg, section) []: |
14 | # Common Name (e.g. server FQDN or YOUR name) []:Monitoring Plugins | 14 | # Common Name (e.g. server FQDN or YOUR name) []:Monitoring Plugins |
15 | # Email Address []:devel@monitoring-plugins.org | 15 | # Email Address []:devel@monitoring-plugins.org |
@@ -21,7 +21,7 @@ use FindBin qw($Bin); | |||
21 | 21 | ||
22 | $ENV{'LC_TIME'} = "C"; | 22 | $ENV{'LC_TIME'} = "C"; |
23 | 23 | ||
24 | my $common_tests = 73; | 24 | my $common_tests = 75; |
25 | my $ssl_only_tests = 8; | 25 | my $ssl_only_tests = 8; |
26 | # Check that all dependent modules are available | 26 | # Check that all dependent modules are available |
27 | eval "use HTTP::Daemon 6.01;"; | 27 | eval "use HTTP::Daemon 6.01;"; |
@@ -178,6 +178,11 @@ sub run_server { | |||
178 | $c->send_basic_header; | 178 | $c->send_basic_header; |
179 | $c->send_crlf; | 179 | $c->send_crlf; |
180 | $c->send_response(HTTP::Response->new( 200, 'OK', undef, 'redirected' )); | 180 | $c->send_response(HTTP::Response->new( 200, 'OK', undef, 'redirected' )); |
181 | } elsif ($r->url->path eq "/redirect_rel") { | ||
182 | $c->send_basic_header(302); | ||
183 | $c->send_header("Location", "/redirect2" ); | ||
184 | $c->send_crlf; | ||
185 | $c->send_response('moved to /redirect2'); | ||
181 | } elsif ($r->url->path eq "/redir_timeout") { | 186 | } elsif ($r->url->path eq "/redir_timeout") { |
182 | $c->send_redirect( "/timeout" ); | 187 | $c->send_redirect( "/timeout" ); |
183 | } elsif ($r->url->path eq "/timeout") { | 188 | } elsif ($r->url->path eq "/timeout") { |
@@ -471,9 +476,12 @@ sub run_common_tests { | |||
471 | is( $result->return_code, 0, $cmd); | 476 | is( $result->return_code, 0, $cmd); |
472 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | 477 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); |
473 | 478 | ||
474 | # These tests may block | 479 | $cmd = "$command -f follow -u /redirect_rel -s redirected"; |
475 | print "ALRM\n"; | 480 | $result = NPTest->testCmd( $cmd ); |
481 | is( $result->return_code, 0, $cmd); | ||
482 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | ||
476 | 483 | ||
484 | # These tests may block | ||
477 | # stickyport - on full urlS port is set back to 80 otherwise | 485 | # stickyport - on full urlS port is set back to 80 otherwise |
478 | $cmd = "$command -f stickyport -u /redir_external -t 5 -s redirected"; | 486 | $cmd = "$command -f stickyport -u /redir_external -t 5 -s redirected"; |
479 | eval { | 487 | eval { |
diff --git a/plugins/tests/check_http.t b/plugins/tests/check_http.t index 6078b274..6eaf85b2 100755 --- a/plugins/tests/check_http.t +++ b/plugins/tests/check_http.t | |||
@@ -13,7 +13,7 @@ use IO::Socket::INET; | |||
13 | 13 | ||
14 | $ENV{'LC_TIME'} = "C"; | 14 | $ENV{'LC_TIME'} = "C"; |
15 | 15 | ||
16 | my $common_tests = 71; | 16 | my $common_tests = 73; |
17 | my $virtual_port_tests = 8; | 17 | my $virtual_port_tests = 8; |
18 | my $ssl_only_tests = 12; | 18 | my $ssl_only_tests = 12; |
19 | my $chunked_encoding_special_tests = 1; | 19 | my $chunked_encoding_special_tests = 1; |
@@ -199,6 +199,11 @@ sub run_server { | |||
199 | $c->send_basic_header; | 199 | $c->send_basic_header; |
200 | $c->send_crlf; | 200 | $c->send_crlf; |
201 | $c->send_response(HTTP::Response->new( 200, 'OK', undef, 'redirected' )); | 201 | $c->send_response(HTTP::Response->new( 200, 'OK', undef, 'redirected' )); |
202 | } elsif ($r->url->path eq "/redirect_rel") { | ||
203 | $c->send_basic_header(302); | ||
204 | $c->send_header("Location", "/redirect2" ); | ||
205 | $c->send_crlf; | ||
206 | $c->send_response('moved to /redirect2'); | ||
202 | } elsif ($r->url->path eq "/redir_timeout") { | 207 | } elsif ($r->url->path eq "/redir_timeout") { |
203 | $c->send_redirect( "/timeout" ); | 208 | $c->send_redirect( "/timeout" ); |
204 | } elsif ($r->url->path eq "/timeout") { | 209 | } elsif ($r->url->path eq "/timeout") { |
@@ -515,6 +520,11 @@ sub run_common_tests { | |||
515 | is( $result->return_code, 0, $cmd); | 520 | is( $result->return_code, 0, $cmd); |
516 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | 521 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); |
517 | 522 | ||
523 | $cmd = "$command -f follow -u /redirect_rel -s redirected"; | ||
524 | $result = NPTest->testCmd( $cmd ); | ||
525 | is( $result->return_code, 0, $cmd); | ||
526 | like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); | ||
527 | |||
518 | # These tests may block | 528 | # These tests may block |
519 | print "ALRM\n"; | 529 | print "ALRM\n"; |
520 | 530 | ||
diff --git a/plugins/utils.c b/plugins/utils.c index b4214c61..77d6a6f9 100644 --- a/plugins/utils.c +++ b/plugins/utils.c | |||
@@ -23,13 +23,15 @@ | |||
23 | *****************************************************************************/ | 23 | *****************************************************************************/ |
24 | 24 | ||
25 | #include "common.h" | 25 | #include "common.h" |
26 | #include "utils.h" | 26 | #include "./utils.h" |
27 | #include "utils_base.h" | 27 | #include "utils_base.h" |
28 | #include <stdarg.h> | 28 | #include <stdarg.h> |
29 | #include <limits.h> | 29 | #include <limits.h> |
30 | #include <string.h> | 30 | #include <string.h> |
31 | #include <errno.h> | 31 | #include <errno.h> |
32 | 32 | ||
33 | #include <stdbool.h> | ||
34 | |||
33 | #include <arpa/inet.h> | 35 | #include <arpa/inet.h> |
34 | 36 | ||
35 | extern void print_usage (void); | 37 | extern void print_usage (void); |
@@ -147,98 +149,107 @@ print_revision (const char *command_name, const char *revision) | |||
147 | command_name, revision, PACKAGE, VERSION); | 149 | command_name, revision, PACKAGE, VERSION); |
148 | } | 150 | } |
149 | 151 | ||
150 | int | 152 | bool is_numeric (char *number) { |
151 | is_numeric (char *number) | ||
152 | { | ||
153 | char tmp[1]; | 153 | char tmp[1]; |
154 | float x; | 154 | float x; |
155 | 155 | ||
156 | if (!number) | 156 | if (!number) |
157 | return FALSE; | 157 | return false; |
158 | else if (sscanf (number, "%f%c", &x, tmp) == 1) | 158 | else if (sscanf (number, "%f%c", &x, tmp) == 1) |
159 | return TRUE; | 159 | return true; |
160 | else | 160 | else |
161 | return FALSE; | 161 | return false; |
162 | } | 162 | } |
163 | 163 | ||
164 | int | 164 | bool is_positive (char *number) { |
165 | is_positive (char *number) | ||
166 | { | ||
167 | if (is_numeric (number) && atof (number) > 0.0) | 165 | if (is_numeric (number) && atof (number) > 0.0) |
168 | return TRUE; | 166 | return true; |
169 | else | 167 | else |
170 | return FALSE; | 168 | return false; |
171 | } | 169 | } |
172 | 170 | ||
173 | int | 171 | bool is_negative (char *number) { |
174 | is_negative (char *number) | ||
175 | { | ||
176 | if (is_numeric (number) && atof (number) < 0.0) | 172 | if (is_numeric (number) && atof (number) < 0.0) |
177 | return TRUE; | 173 | return true; |
178 | else | 174 | else |
179 | return FALSE; | 175 | return false; |
180 | } | 176 | } |
181 | 177 | ||
182 | int | 178 | bool is_nonnegative (char *number) { |
183 | is_nonnegative (char *number) | ||
184 | { | ||
185 | if (is_numeric (number) && atof (number) >= 0.0) | 179 | if (is_numeric (number) && atof (number) >= 0.0) |
186 | return TRUE; | 180 | return true; |
187 | else | 181 | else |
188 | return FALSE; | 182 | return false; |
189 | } | 183 | } |
190 | 184 | ||
191 | int | 185 | bool is_percentage (char *number) { |
192 | is_percentage (char *number) | ||
193 | { | ||
194 | int x; | 186 | int x; |
195 | if (is_numeric (number) && (x = atof (number)) >= 0 && x <= 100) | 187 | if (is_numeric (number) && (x = atof (number)) >= 0 && x <= 100) |
196 | return TRUE; | 188 | return true; |
197 | else | 189 | else |
198 | return FALSE; | 190 | return false; |
199 | } | 191 | } |
200 | 192 | ||
201 | int | 193 | bool is_percentage_expression (const char str[]) { |
202 | is_integer (char *number) | 194 | if (!str) { |
203 | { | 195 | return false; |
196 | } | ||
197 | |||
198 | size_t len = strlen(str); | ||
199 | |||
200 | if (str[len-1] != '%') { | ||
201 | return false; | ||
202 | } | ||
203 | |||
204 | char *foo = calloc(sizeof(char), len + 1); | ||
205 | |||
206 | if (!foo) { | ||
207 | die (STATE_UNKNOWN, _("calloc failed \n")); | ||
208 | } | ||
209 | |||
210 | strcpy(foo, str); | ||
211 | foo[len-1] = '\0'; | ||
212 | |||
213 | bool result = is_numeric(foo); | ||
214 | |||
215 | free(foo); | ||
216 | |||
217 | return result; | ||
218 | } | ||
219 | |||
220 | bool is_integer (char *number) { | ||
204 | long int n; | 221 | long int n; |
205 | 222 | ||
206 | if (!number || (strspn (number, "-0123456789 ") != strlen (number))) | 223 | if (!number || (strspn (number, "-0123456789 ") != strlen (number))) |
207 | return FALSE; | 224 | return false; |
208 | 225 | ||
209 | n = strtol (number, NULL, 10); | 226 | n = strtol (number, NULL, 10); |
210 | 227 | ||
211 | if (errno != ERANGE && n >= INT_MIN && n <= INT_MAX) | 228 | if (errno != ERANGE && n >= INT_MIN && n <= INT_MAX) |
212 | return TRUE; | 229 | return true; |
213 | else | 230 | else |
214 | return FALSE; | 231 | return false; |
215 | } | 232 | } |
216 | 233 | ||
217 | int | 234 | bool is_intpos (char *number) { |
218 | is_intpos (char *number) | ||
219 | { | ||
220 | if (is_integer (number) && atoi (number) > 0) | 235 | if (is_integer (number) && atoi (number) > 0) |
221 | return TRUE; | 236 | return true; |
222 | else | 237 | else |
223 | return FALSE; | 238 | return false; |
224 | } | 239 | } |
225 | 240 | ||
226 | int | 241 | bool is_intneg (char *number) { |
227 | is_intneg (char *number) | ||
228 | { | ||
229 | if (is_integer (number) && atoi (number) < 0) | 242 | if (is_integer (number) && atoi (number) < 0) |
230 | return TRUE; | 243 | return true; |
231 | else | 244 | else |
232 | return FALSE; | 245 | return false; |
233 | } | 246 | } |
234 | 247 | ||
235 | int | 248 | bool is_intnonneg (char *number) { |
236 | is_intnonneg (char *number) | ||
237 | { | ||
238 | if (is_integer (number) && atoi (number) >= 0) | 249 | if (is_integer (number) && atoi (number) >= 0) |
239 | return TRUE; | 250 | return true; |
240 | else | 251 | else |
241 | return FALSE; | 252 | return false; |
242 | } | 253 | } |
243 | 254 | ||
244 | /* | 255 | /* |
@@ -246,19 +257,27 @@ is_intnonneg (char *number) | |||
246 | * On success the number will be written to the _target_ address, if _target_ is not set | 257 | * On success the number will be written to the _target_ address, if _target_ is not set |
247 | * to NULL. | 258 | * to NULL. |
248 | */ | 259 | */ |
249 | int is_int64(char *number, int64_t *target) { | 260 | bool is_int64(char *number, int64_t *target) { |
250 | errno = 0; | 261 | errno = 0; |
251 | uint64_t tmp = strtoll(number, NULL, 10); | 262 | char *endptr = { 0 }; |
263 | |||
264 | int64_t tmp = strtoll(number, &endptr, 10); | ||
252 | if (errno != 0) { | 265 | if (errno != 0) { |
266 | return false; | ||
267 | } | ||
268 | |||
269 | if (*endptr == '\0') { | ||
253 | return 0; | 270 | return 0; |
254 | } | 271 | } |
272 | |||
255 | if (tmp < INT64_MIN || tmp > INT64_MAX) { | 273 | if (tmp < INT64_MIN || tmp > INT64_MAX) { |
256 | return 0; | 274 | return false; |
257 | } | 275 | } |
276 | |||
258 | if (target != NULL) { | 277 | if (target != NULL) { |
259 | *target = tmp; | 278 | *target = tmp; |
260 | } | 279 | } |
261 | return 1; | 280 | return true; |
262 | } | 281 | } |
263 | 282 | ||
264 | /* | 283 | /* |
@@ -266,40 +285,45 @@ int is_int64(char *number, int64_t *target) { | |||
266 | * On success the number will be written to the _target_ address, if _target_ is not set | 285 | * On success the number will be written to the _target_ address, if _target_ is not set |
267 | * to NULL. | 286 | * to NULL. |
268 | */ | 287 | */ |
269 | int is_uint64(char *number, uint64_t *target) { | 288 | bool is_uint64(char *number, uint64_t *target) { |
270 | errno = 0; | 289 | errno = 0; |
271 | uint64_t tmp = strtoll(number, NULL, 10); | 290 | char *endptr = { 0 }; |
291 | unsigned long long tmp = strtoull(number, &endptr, 10); | ||
292 | |||
272 | if (errno != 0) { | 293 | if (errno != 0) { |
273 | return 0; | 294 | return false; |
274 | } | 295 | } |
275 | if (tmp < 0 || tmp > UINT64_MAX) { | 296 | |
276 | return 0; | 297 | if (*endptr != '\0') { |
298 | return false; | ||
299 | } | ||
300 | |||
301 | if (tmp > UINT64_MAX) { | ||
302 | return false; | ||
277 | } | 303 | } |
304 | |||
278 | if (target != NULL) { | 305 | if (target != NULL) { |
279 | *target = tmp; | 306 | *target = (uint64_t)tmp; |
280 | } | 307 | } |
281 | return 1; | 308 | |
309 | return true; | ||
282 | } | 310 | } |
283 | 311 | ||
284 | int | 312 | bool is_intpercent (char *number) { |
285 | is_intpercent (char *number) | ||
286 | { | ||
287 | int i; | 313 | int i; |
288 | if (is_integer (number) && (i = atoi (number)) >= 0 && i <= 100) | 314 | if (is_integer (number) && (i = atoi (number)) >= 0 && i <= 100) |
289 | return TRUE; | 315 | return true; |
290 | else | 316 | else |
291 | return FALSE; | 317 | return false; |
292 | } | 318 | } |
293 | 319 | ||
294 | int | 320 | bool is_option (char *str) { |
295 | is_option (char *str) | ||
296 | { | ||
297 | if (!str) | 321 | if (!str) |
298 | return FALSE; | 322 | return false; |
299 | else if (strspn (str, "-") == 1 || strspn (str, "-") == 2) | 323 | else if (strspn (str, "-") == 1 || strspn (str, "-") == 2) |
300 | return TRUE; | 324 | return true; |
301 | else | 325 | else |
302 | return FALSE; | 326 | return false; |
303 | } | 327 | } |
304 | 328 | ||
305 | #ifdef NEED_GETTIMEOFDAY | 329 | #ifdef NEED_GETTIMEOFDAY |
@@ -804,19 +828,3 @@ char *sperfdata_int (const char *label, | |||
804 | 828 | ||
805 | return data; | 829 | return data; |
806 | } | 830 | } |
807 | |||
808 | int | ||
809 | open_max (void) | ||
810 | { | ||
811 | errno = 0; | ||
812 | if (maxfd > 0) | ||
813 | return(maxfd); | ||
814 | |||
815 | if ((maxfd = sysconf (_SC_OPEN_MAX)) < 0) { | ||
816 | if (errno == 0) | ||
817 | maxfd = DEFAULT_MAXFD; /* it's indeterminate */ | ||
818 | else | ||
819 | die (STATE_UNKNOWN, _("sysconf error for _SC_OPEN_MAX\n")); | ||
820 | } | ||
821 | return(maxfd); | ||
822 | } | ||
diff --git a/plugins/utils.h b/plugins/utils.h index c76b3216..f939e337 100644 --- a/plugins/utils.h +++ b/plugins/utils.h | |||
@@ -16,6 +16,8 @@ suite of plugins. */ | |||
16 | /* now some functions etc are being defined in ../lib/utils_base.c */ | 16 | /* now some functions etc are being defined in ../lib/utils_base.c */ |
17 | #include "utils_base.h" | 17 | #include "utils_base.h" |
18 | 18 | ||
19 | #include <stdbool.h> | ||
20 | |||
19 | 21 | ||
20 | #ifdef NP_EXTRA_OPTS | 22 | #ifdef NP_EXTRA_OPTS |
21 | /* Include extra-opts functions if compiled in */ | 23 | /* Include extra-opts functions if compiled in */ |
@@ -34,21 +36,22 @@ extern time_t start_time, end_time; | |||
34 | 36 | ||
35 | /* Test input types */ | 37 | /* Test input types */ |
36 | 38 | ||
37 | int is_integer (char *); | 39 | bool is_integer (char *); |
38 | int is_intpos (char *); | 40 | bool is_intpos (char *); |
39 | int is_intneg (char *); | 41 | bool is_intneg (char *); |
40 | int is_intnonneg (char *); | 42 | bool is_intnonneg (char *); |
41 | int is_intpercent (char *); | 43 | bool is_intpercent (char *); |
42 | int is_uint64(char *number, uint64_t *target); | 44 | bool is_uint64(char *number, uint64_t *target); |
43 | int is_int64(char *number, int64_t *target); | 45 | bool is_int64(char *number, int64_t *target); |
44 | 46 | ||
45 | int is_numeric (char *); | 47 | bool is_numeric (char *); |
46 | int is_positive (char *); | 48 | bool is_positive (char *); |
47 | int is_negative (char *); | 49 | bool is_negative (char *); |
48 | int is_nonnegative (char *); | 50 | bool is_nonnegative (char *); |
49 | int is_percentage (char *); | 51 | bool is_percentage (char *); |
52 | bool is_percentage_expression (const char[]); | ||
50 | 53 | ||
51 | int is_option (char *); | 54 | bool is_option (char *); |
52 | 55 | ||
53 | /* Generalized timer that will do milliseconds if available */ | 56 | /* Generalized timer that will do milliseconds if available */ |
54 | #ifndef HAVE_STRUCT_TIMEVAL | 57 | #ifndef HAVE_STRUCT_TIMEVAL |
@@ -106,8 +109,6 @@ char *sperfdata (const char *, double, const char *, char *, char *, | |||
106 | char *sperfdata_int (const char *, int, const char *, char *, char *, | 109 | char *sperfdata_int (const char *, int, const char *, char *, char *, |
107 | int, int, int, int); | 110 | int, int, int, int); |
108 | 111 | ||
109 | int open_max (void); | ||
110 | |||
111 | /* The idea here is that, although not every plugin will use all of these, | 112 | /* The idea here is that, although not every plugin will use all of these, |
112 | most will or should. Therefore, for consistency, these very common | 113 | most will or should. Therefore, for consistency, these very common |
113 | options should have only these meanings throughout the overall suite */ | 114 | options should have only these meanings throughout the overall suite */ |