diff options
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/check_by_ssh.c | 2 | ||||
-rw-r--r-- | plugins/check_curl.c | 87 | ||||
-rw-r--r-- | plugins/check_disk.c | 203 | ||||
-rw-r--r-- | plugins/check_dns.c | 61 | ||||
-rw-r--r-- | plugins/check_hpjd.c | 17 | ||||
-rw-r--r-- | plugins/check_http.c | 4 | ||||
-rw-r--r-- | plugins/check_ldap.c | 5 | ||||
-rw-r--r-- | plugins/check_load.c | 2 | ||||
-rw-r--r-- | plugins/check_ping.c | 14 | ||||
-rw-r--r-- | plugins/check_procs.c | 52 | ||||
-rw-r--r-- | plugins/check_smtp.c | 18 | ||||
-rw-r--r-- | plugins/check_snmp.c | 11 | ||||
-rw-r--r-- | plugins/check_swap.c | 278 | ||||
-rw-r--r-- | plugins/check_ups.c | 5 | ||||
-rw-r--r-- | plugins/t/check_curl.t | 2 | ||||
-rw-r--r-- | plugins/t/check_disk.t | 7 | ||||
-rw-r--r-- | plugins/t/check_dns.t | 10 | ||||
-rw-r--r-- | plugins/t/check_load.t | 4 | ||||
-rw-r--r-- | plugins/t/check_swap.t | 6 | ||||
-rwxr-xr-x | plugins/tests/check_procs.t | 26 | ||||
-rwxr-xr-x | plugins/tests/check_snmp.t | 17 | ||||
-rw-r--r-- | plugins/tests/var/ps-axwo.debian | 219 | ||||
-rw-r--r-- | plugins/tests/var/ps_axwo.debian | 84 | ||||
-rw-r--r-- | plugins/utils.c | 130 | ||||
-rw-r--r-- | plugins/utils.h | 9 |
25 files changed, 878 insertions, 395 deletions
diff --git a/plugins/check_by_ssh.c b/plugins/check_by_ssh.c index 13d8bc3..485bf3b 100644 --- a/plugins/check_by_ssh.c +++ b/plugins/check_by_ssh.c | |||
@@ -230,7 +230,6 @@ process_arguments (int argc, char **argv) | |||
230 | timeout_interval = atoi (optarg); | 230 | timeout_interval = atoi (optarg); |
231 | break; | 231 | break; |
232 | case 'H': /* host */ | 232 | case 'H': /* host */ |
233 | host_or_die(optarg); | ||
234 | hostname = optarg; | 233 | hostname = optarg; |
235 | break; | 234 | break; |
236 | case 'p': /* port number */ | 235 | case 'p': /* port number */ |
@@ -329,7 +328,6 @@ process_arguments (int argc, char **argv) | |||
329 | if (c <= argc) { | 328 | if (c <= argc) { |
330 | die (STATE_UNKNOWN, _("%s: You must provide a host name\n"), progname); | 329 | die (STATE_UNKNOWN, _("%s: You must provide a host name\n"), progname); |
331 | } | 330 | } |
332 | host_or_die(argv[c]); | ||
333 | hostname = argv[c++]; | 331 | hostname = argv[c++]; |
334 | } | 332 | } |
335 | 333 | ||
diff --git a/plugins/check_curl.c b/plugins/check_curl.c index 59e398b..14cc846 100644 --- a/plugins/check_curl.c +++ b/plugins/check_curl.c | |||
@@ -55,6 +55,12 @@ const char *email = "devel@monitoring-plugins.org"; | |||
55 | 55 | ||
56 | #include <arpa/inet.h> | 56 | #include <arpa/inet.h> |
57 | 57 | ||
58 | #if defined(HAVE_SSL) && defined(USE_OPENSSL) | ||
59 | #include <openssl/opensslv.h> | ||
60 | #endif | ||
61 | |||
62 | #include <netdb.h> | ||
63 | |||
58 | #define MAKE_LIBCURL_VERSION(major, minor, patch) ((major)*0x10000 + (minor)*0x100 + (patch)) | 64 | #define MAKE_LIBCURL_VERSION(major, minor, patch) ((major)*0x10000 + (minor)*0x100 + (patch)) |
59 | 65 | ||
60 | #define DEFAULT_BUFFER_SIZE 2048 | 66 | #define DEFAULT_BUFFER_SIZE 2048 |
@@ -206,6 +212,7 @@ int maximum_age = -1; | |||
206 | int address_family = AF_UNSPEC; | 212 | int address_family = AF_UNSPEC; |
207 | curlhelp_ssl_library ssl_library = CURLHELP_SSL_LIBRARY_UNKNOWN; | 213 | curlhelp_ssl_library ssl_library = CURLHELP_SSL_LIBRARY_UNKNOWN; |
208 | int curl_http_version = CURL_HTTP_VERSION_NONE; | 214 | int curl_http_version = CURL_HTTP_VERSION_NONE; |
215 | int automatic_decompression = FALSE; | ||
209 | 216 | ||
210 | int process_arguments (int, char**); | 217 | int process_arguments (int, char**); |
211 | void handle_curl_option_return_code (CURLcode res, const char* option); | 218 | void handle_curl_option_return_code (CURLcode res, const char* option); |
@@ -285,7 +292,9 @@ int verify_callback(int preverify_ok, X509_STORE_CTX *x509_ctx) | |||
285 | * TODO: is the last certificate always the server certificate? | 292 | * TODO: is the last certificate always the server certificate? |
286 | */ | 293 | */ |
287 | cert = X509_STORE_CTX_get_current_cert(x509_ctx); | 294 | cert = X509_STORE_CTX_get_current_cert(x509_ctx); |
295 | #if OPENSSL_VERSION_NUMBER >= 0x10100000L | ||
288 | X509_up_ref(cert); | 296 | X509_up_ref(cert); |
297 | #endif | ||
289 | if (verbose>=2) { | 298 | if (verbose>=2) { |
290 | puts("* SSL verify callback with certificate:"); | 299 | puts("* SSL verify callback with certificate:"); |
291 | X509_NAME *subject, *issuer; | 300 | X509_NAME *subject, *issuer; |
@@ -363,12 +372,55 @@ handle_curl_option_return_code (CURLcode res, const char* option) | |||
363 | } | 372 | } |
364 | 373 | ||
365 | int | 374 | int |
375 | lookup_host (const char *host, char *buf, size_t buflen) | ||
376 | { | ||
377 | struct addrinfo hints, *res, *result; | ||
378 | int errcode; | ||
379 | void *ptr; | ||
380 | |||
381 | memset (&hints, 0, sizeof (hints)); | ||
382 | hints.ai_family = address_family; | ||
383 | hints.ai_socktype = SOCK_STREAM; | ||
384 | hints.ai_flags |= AI_CANONNAME; | ||
385 | |||
386 | errcode = getaddrinfo (host, NULL, &hints, &result); | ||
387 | if (errcode != 0) | ||
388 | return errcode; | ||
389 | |||
390 | res = result; | ||
391 | |||
392 | while (res) { | ||
393 | inet_ntop (res->ai_family, res->ai_addr->sa_data, buf, buflen); | ||
394 | switch (res->ai_family) { | ||
395 | case AF_INET: | ||
396 | ptr = &((struct sockaddr_in *) res->ai_addr)->sin_addr; | ||
397 | break; | ||
398 | case AF_INET6: | ||
399 | ptr = &((struct sockaddr_in6 *) res->ai_addr)->sin6_addr; | ||
400 | break; | ||
401 | } | ||
402 | inet_ntop (res->ai_family, ptr, buf, buflen); | ||
403 | if (verbose >= 1) | ||
404 | printf ("* getaddrinfo IPv%d address: %s\n", | ||
405 | res->ai_family == PF_INET6 ? 6 : 4, buf); | ||
406 | res = res->ai_next; | ||
407 | } | ||
408 | |||
409 | freeaddrinfo(result); | ||
410 | |||
411 | return 0; | ||
412 | } | ||
413 | |||
414 | int | ||
366 | check_http (void) | 415 | check_http (void) |
367 | { | 416 | { |
368 | int result = STATE_OK; | 417 | int result = STATE_OK; |
369 | int page_len = 0; | 418 | int page_len = 0; |
370 | int i; | 419 | int i; |
371 | char *force_host_header = NULL; | 420 | char *force_host_header = NULL; |
421 | struct curl_slist *host = NULL; | ||
422 | char addrstr[100]; | ||
423 | char dnscache[DEFAULT_BUFFER_SIZE]; | ||
372 | 424 | ||
373 | /* initialize curl */ | 425 | /* initialize curl */ |
374 | if (curl_global_init (CURL_GLOBAL_DEFAULT) != CURLE_OK) | 426 | if (curl_global_init (CURL_GLOBAL_DEFAULT) != CURLE_OK) |
@@ -383,6 +435,13 @@ check_http (void) | |||
383 | /* print everything on stdout like check_http would do */ | 435 | /* print everything on stdout like check_http would do */ |
384 | handle_curl_option_return_code (curl_easy_setopt(curl, CURLOPT_STDERR, stdout), "CURLOPT_STDERR"); | 436 | handle_curl_option_return_code (curl_easy_setopt(curl, CURLOPT_STDERR, stdout), "CURLOPT_STDERR"); |
385 | 437 | ||
438 | if (automatic_decompression) | ||
439 | #if LIBCURL_VERSION_NUM >= MAKE_LIBCURL_VERSION(7, 21, 6) | ||
440 | handle_curl_option_return_code (curl_easy_setopt(curl, CURLOPT_ACCEPT_ENCODING, ""), "CURLOPT_ACCEPT_ENCODING"); | ||
441 | #else | ||
442 | handle_curl_option_return_code (curl_easy_setopt(curl, CURLOPT_ENCODING, ""), "CURLOPT_ENCODING"); | ||
443 | #endif /* LIBCURL_VERSION_NUM >= MAKE_LIBCURL_VERSION(7, 21, 6) */ | ||
444 | |||
386 | /* initialize buffer for body of the answer */ | 445 | /* initialize buffer for body of the answer */ |
387 | if (curlhelp_initwritebuffer(&body_buf) < 0) | 446 | if (curlhelp_initwritebuffer(&body_buf) < 0) |
388 | die (STATE_UNKNOWN, "HTTP CRITICAL - out of memory allocating buffer for body\n"); | 447 | die (STATE_UNKNOWN, "HTTP CRITICAL - out of memory allocating buffer for body\n"); |
@@ -404,9 +463,12 @@ check_http (void) | |||
404 | 463 | ||
405 | // 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 | 464 | // 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 |
406 | if(use_ssl && host_name != NULL) { | 465 | if(use_ssl && host_name != NULL) { |
407 | struct curl_slist *host = NULL; | 466 | if ( (res=lookup_host (server_address, addrstr, 100)) != 0) { |
408 | char dnscache[DEFAULT_BUFFER_SIZE]; | 467 | snprintf (msg, DEFAULT_BUFFER_SIZE, _("Unable to lookup IP address for '%s': getaddrinfo returned %d - %s"), |
409 | snprintf (dnscache, DEFAULT_BUFFER_SIZE, "%s:%d:%s", host_name, server_port, server_address); | 468 | server_address, res, gai_strerror (res)); |
469 | die (STATE_CRITICAL, "HTTP CRITICAL - %s\n", msg); | ||
470 | } | ||
471 | snprintf (dnscache, DEFAULT_BUFFER_SIZE, "%s:%d:%s", host_name, server_port, addrstr); | ||
410 | host = curl_slist_append(NULL, dnscache); | 472 | host = curl_slist_append(NULL, dnscache); |
411 | curl_easy_setopt(curl, CURLOPT_RESOLVE, host); | 473 | curl_easy_setopt(curl, CURLOPT_RESOLVE, host); |
412 | if (verbose>=1) | 474 | if (verbose>=1) |
@@ -971,8 +1033,8 @@ char* | |||
971 | uri_string (const UriTextRangeA range, char* buf, size_t buflen) | 1033 | uri_string (const UriTextRangeA range, char* buf, size_t buflen) |
972 | { | 1034 | { |
973 | if (!range.first) return "(null)"; | 1035 | if (!range.first) return "(null)"; |
974 | strncpy (buf, range.first, max (buflen, range.afterLast - range.first)); | 1036 | strncpy (buf, range.first, max (buflen-1, range.afterLast - range.first)); |
975 | buf[max (buflen, range.afterLast - range.first)] = '\0'; | 1037 | buf[max (buflen-1, range.afterLast - range.first)] = '\0'; |
976 | buf[range.afterLast - range.first] = '\0'; | 1038 | buf[range.afterLast - range.first] = '\0'; |
977 | return buf; | 1039 | return buf; |
978 | } | 1040 | } |
@@ -1092,8 +1154,8 @@ redir (curlhelp_write_curlbuf* header_buf) | |||
1092 | !strncmp(server_address, new_host, MAX_IPV4_HOSTLENGTH) && | 1154 | !strncmp(server_address, new_host, MAX_IPV4_HOSTLENGTH) && |
1093 | (host_name && !strncmp(host_name, new_host, MAX_IPV4_HOSTLENGTH)) && | 1155 | (host_name && !strncmp(host_name, new_host, MAX_IPV4_HOSTLENGTH)) && |
1094 | !strcmp(server_url, new_url)) | 1156 | !strcmp(server_url, new_url)) |
1095 | die (STATE_WARNING, | 1157 | die (STATE_CRITICAL, |
1096 | _("HTTP WARNING - redirection creates an infinite loop - %s://%s:%d%s%s\n"), | 1158 | _("HTTP CRITICAL - redirection creates an infinite loop - %s://%s:%d%s%s\n"), |
1097 | use_ssl ? "https" : "http", new_host, new_port, new_url, (display_html ? "</A>" : "")); | 1159 | use_ssl ? "https" : "http", new_host, new_port, new_url, (display_html ? "</A>" : "")); |
1098 | 1160 | ||
1099 | /* set new values for redirected request */ | 1161 | /* set new values for redirected request */ |
@@ -1149,7 +1211,8 @@ process_arguments (int argc, char **argv) | |||
1149 | INVERT_REGEX = CHAR_MAX + 1, | 1211 | INVERT_REGEX = CHAR_MAX + 1, |
1150 | SNI_OPTION, | 1212 | SNI_OPTION, |
1151 | CA_CERT_OPTION, | 1213 | CA_CERT_OPTION, |
1152 | HTTP_VERSION_OPTION | 1214 | HTTP_VERSION_OPTION, |
1215 | AUTOMATIC_DECOMPRESSION | ||
1153 | }; | 1216 | }; |
1154 | 1217 | ||
1155 | int option = 0; | 1218 | int option = 0; |
@@ -1192,6 +1255,7 @@ process_arguments (int argc, char **argv) | |||
1192 | {"extended-perfdata", no_argument, 0, 'E'}, | 1255 | {"extended-perfdata", no_argument, 0, 'E'}, |
1193 | {"show-body", no_argument, 0, 'B'}, | 1256 | {"show-body", no_argument, 0, 'B'}, |
1194 | {"http-version", required_argument, 0, HTTP_VERSION_OPTION}, | 1257 | {"http-version", required_argument, 0, HTTP_VERSION_OPTION}, |
1258 | {"enable-automatic-decompression", no_argument, 0, AUTOMATIC_DECOMPRESSION}, | ||
1195 | {0, 0, 0, 0} | 1259 | {0, 0, 0, 0} |
1196 | }; | 1260 | }; |
1197 | 1261 | ||
@@ -1358,7 +1422,7 @@ process_arguments (int argc, char **argv) | |||
1358 | #ifdef LIBCURL_FEATURE_SSL | 1422 | #ifdef LIBCURL_FEATURE_SSL |
1359 | case 'D': /* verify peer certificate & host */ | 1423 | case 'D': /* verify peer certificate & host */ |
1360 | verify_peer_and_host = TRUE; | 1424 | verify_peer_and_host = TRUE; |
1361 | goto enable_ssl; | 1425 | break; |
1362 | #endif | 1426 | #endif |
1363 | case 'S': /* use SSL */ | 1427 | case 'S': /* use SSL */ |
1364 | #ifdef LIBCURL_FEATURE_SSL | 1428 | #ifdef LIBCURL_FEATURE_SSL |
@@ -1583,6 +1647,9 @@ process_arguments (int argc, char **argv) | |||
1583 | exit (STATE_WARNING); | 1647 | exit (STATE_WARNING); |
1584 | } | 1648 | } |
1585 | break; | 1649 | break; |
1650 | case AUTOMATIC_DECOMPRESSION: | ||
1651 | automatic_decompression = TRUE; | ||
1652 | break; | ||
1586 | case '?': | 1653 | case '?': |
1587 | /* print short usage statement if args not parsable */ | 1654 | /* print short usage statement if args not parsable */ |
1588 | usage5 (); | 1655 | usage5 (); |
@@ -1793,6 +1860,8 @@ print_help (void) | |||
1793 | printf (" %s\n", "--http-version=VERSION"); | 1860 | printf (" %s\n", "--http-version=VERSION"); |
1794 | printf (" %s\n", _("Connect via specific HTTP protocol.")); | 1861 | printf (" %s\n", _("Connect via specific HTTP protocol.")); |
1795 | printf (" %s\n", _("1.0 = HTTP/1.0, 1.1 = HTTP/1.1, 2.0 = HTTP/2 (HTTP/2 will fail without -S)")); | 1862 | printf (" %s\n", _("1.0 = HTTP/1.0, 1.1 = HTTP/1.1, 2.0 = HTTP/2 (HTTP/2 will fail without -S)")); |
1863 | printf (" %s\n", "--enable-automatic-decompression"); | ||
1864 | printf (" %s\n", _("Enable automatic decompression of body (CURLOPT_ACCEPT_ENCODING).")); | ||
1796 | printf ("\n"); | 1865 | printf ("\n"); |
1797 | 1866 | ||
1798 | printf (UT_WARN_CRIT); | 1867 | printf (UT_WARN_CRIT); |
diff --git a/plugins/check_disk.c b/plugins/check_disk.c index 844e625..54befca 100644 --- a/plugins/check_disk.c +++ b/plugins/check_disk.c | |||
@@ -1,29 +1,29 @@ | |||
1 | /***************************************************************************** | 1 | /***************************************************************************** |
2 | * | 2 | * |
3 | * Monitoring check_disk plugin | 3 | * Monitoring check_disk plugin |
4 | * | 4 | * |
5 | * License: GPL | 5 | * License: GPL |
6 | * Copyright (c) 1999-2008 Monitoring Plugins Development Team | 6 | * Copyright (c) 1999-2008 Monitoring Plugins Development Team |
7 | * | 7 | * |
8 | * Description: | 8 | * Description: |
9 | * | 9 | * |
10 | * This file contains the check_disk plugin | 10 | * This file contains the check_disk plugin |
11 | * | 11 | * |
12 | * | 12 | * |
13 | * This program is free software: you can redistribute it and/or modify | 13 | * This program is free software: you can redistribute it and/or modify |
14 | * it under the terms of the GNU General Public License as published by | 14 | * it under the terms of the GNU General Public License as published by |
15 | * the Free Software Foundation, either version 3 of the License, or | 15 | * the Free Software Foundation, either version 3 of the License, or |
16 | * (at your option) any later version. | 16 | * (at your option) any later version. |
17 | * | 17 | * |
18 | * This program is distributed in the hope that it will be useful, | 18 | * This program is distributed in the hope that it will be useful, |
19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
21 | * GNU General Public License for more details. | 21 | * GNU General Public License for more details. |
22 | * | 22 | * |
23 | * You should have received a copy of the GNU General Public License | 23 | * You should have received a copy of the GNU General Public License |
24 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 24 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
25 | * | 25 | * |
26 | * | 26 | * |
27 | *****************************************************************************/ | 27 | *****************************************************************************/ |
28 | 28 | ||
29 | const char *progname = "check_disk"; | 29 | const char *progname = "check_disk"; |
@@ -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 "intprops.h" /* necessary for TYPE_MAXIMUM */ |
50 | #if HAVE_LIMITS_H | 50 | #if HAVE_LIMITS_H |
51 | # include <limits.h> | 51 | # include <limits.h> |
52 | #endif | 52 | #endif |
@@ -172,8 +172,6 @@ main (int argc, char **argv) | |||
172 | char *preamble; | 172 | char *preamble; |
173 | char *flag_header; | 173 | char *flag_header; |
174 | double inode_space_pct; | 174 | double inode_space_pct; |
175 | double warning_high_tide; | ||
176 | double critical_high_tide; | ||
177 | int temp_result; | 175 | int temp_result; |
178 | 176 | ||
179 | struct mount_entry *me; | 177 | struct mount_entry *me; |
@@ -245,17 +243,17 @@ main (int argc, char **argv) | |||
245 | 243 | ||
246 | #ifdef __CYGWIN__ | 244 | #ifdef __CYGWIN__ |
247 | if (strncmp(path->name, "/cygdrive/", 10) != 0 || strlen(path->name) > 11) | 245 | if (strncmp(path->name, "/cygdrive/", 10) != 0 || strlen(path->name) > 11) |
248 | continue; | 246 | continue; |
249 | snprintf(mountdir, sizeof(mountdir), "%s:\\", me->me_mountdir + 10); | 247 | snprintf(mountdir, sizeof(mountdir), "%s:\\", me->me_mountdir + 10); |
250 | if (GetDriveType(mountdir) != DRIVE_FIXED) | 248 | if (GetDriveType(mountdir) != DRIVE_FIXED) |
251 | me->me_remote = 1; | 249 | me->me_remote = 1; |
252 | #endif | 250 | #endif |
253 | /* Filters */ | 251 | /* Filters */ |
254 | 252 | ||
255 | /* Remove filesystems already seen */ | 253 | /* Remove filesystems already seen */ |
256 | if (np_seen_name(seen, me->me_mountdir)) { | 254 | if (np_seen_name(seen, me->me_mountdir)) { |
257 | continue; | 255 | continue; |
258 | } | 256 | } |
259 | np_add_name(&seen, me->me_mountdir); | 257 | np_add_name(&seen, me->me_mountdir); |
260 | 258 | ||
261 | if (path->group == NULL) { | 259 | if (path->group == NULL) { |
@@ -288,8 +286,17 @@ main (int argc, char **argv) | |||
288 | get_stats (path, &fsp); | 286 | get_stats (path, &fsp); |
289 | 287 | ||
290 | if (verbose >= 3) { | 288 | if (verbose >= 3) { |
291 | printf ("For %s, used_pct=%g free_pct=%g used_units=%g free_units=%g total_units=%g used_inodes_pct=%g free_inodes_pct=%g fsp.fsu_blocksize=%llu mult=%llu\n", | 289 | printf ("For %s, used_pct=%g free_pct=%g used_units=%llu free_units=%llu total_units=%llu used_inodes_pct=%g free_inodes_pct=%g fsp.fsu_blocksize=%llu mult=%llu\n", |
292 | me->me_mountdir, path->dused_pct, path->dfree_pct, path->dused_units, path->dfree_units, path->dtotal_units, path->dused_inodes_percent, path->dfree_inodes_percent, fsp.fsu_blocksize, mult); | 290 | me->me_mountdir, |
291 | path->dused_pct, | ||
292 | path->dfree_pct, | ||
293 | path->dused_units, | ||
294 | path->dfree_units, | ||
295 | path->dtotal_units, | ||
296 | path->dused_inodes_percent, | ||
297 | path->dfree_inodes_percent, | ||
298 | fsp.fsu_blocksize, | ||
299 | mult); | ||
293 | } | 300 | } |
294 | 301 | ||
295 | /* Threshold comparisons */ | 302 | /* Threshold comparisons */ |
@@ -326,77 +333,79 @@ main (int argc, char **argv) | |||
326 | */ | 333 | */ |
327 | 334 | ||
328 | /* *_high_tide must be reinitialized at each run */ | 335 | /* *_high_tide must be reinitialized at each run */ |
329 | warning_high_tide = UINT_MAX; | 336 | uint64_t warning_high_tide = UINT64_MAX; |
330 | critical_high_tide = UINT_MAX; | ||
331 | 337 | ||
332 | if (path->freespace_units->warning != NULL) { | 338 | if (path->freespace_units->warning != NULL) { |
333 | warning_high_tide = path->dtotal_units - path->freespace_units->warning->end; | 339 | warning_high_tide = (path->dtotal_units - path->freespace_units->warning->end) * mult; |
334 | } | 340 | } |
335 | if (path->freespace_percent->warning != NULL) { | 341 | if (path->freespace_percent->warning != NULL) { |
336 | warning_high_tide = abs( min( (double) warning_high_tide, (double) (1.0 - path->freespace_percent->warning->end/100)*path->dtotal_units )); | 342 | warning_high_tide = min( warning_high_tide, (uint64_t)((1.0 - path->freespace_percent->warning->end/100) * (path->dtotal_units * mult)) ); |
337 | } | 343 | } |
344 | |||
345 | uint64_t critical_high_tide = UINT64_MAX; | ||
346 | |||
338 | if (path->freespace_units->critical != NULL) { | 347 | if (path->freespace_units->critical != NULL) { |
339 | critical_high_tide = path->dtotal_units - path->freespace_units->critical->end; | 348 | critical_high_tide = (path->dtotal_units - path->freespace_units->critical->end) * mult; |
340 | } | 349 | } |
341 | if (path->freespace_percent->critical != NULL) { | 350 | if (path->freespace_percent->critical != NULL) { |
342 | critical_high_tide = abs( min( (double) critical_high_tide, (double) (1.0 - path->freespace_percent->critical->end/100)*path->dtotal_units )); | 351 | critical_high_tide = min( critical_high_tide, (uint64_t)((1.0 - path->freespace_percent->critical->end/100) * (path->dtotal_units * mult)) ); |
343 | } | 352 | } |
344 | 353 | ||
345 | /* Nb: *_high_tide are unset when == UINT_MAX */ | 354 | /* Nb: *_high_tide are unset when == UINT64_MAX */ |
346 | xasprintf (&perf, "%s %s", perf, | 355 | xasprintf (&perf, "%s %s", perf, |
347 | perfdata ((!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir, | 356 | perfdata_uint64 ( |
348 | path->dused_units, units, | 357 | (!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir, |
349 | (warning_high_tide != UINT_MAX ? TRUE : FALSE), warning_high_tide, | 358 | path->dused_units * mult, "B", |
350 | (critical_high_tide != UINT_MAX ? TRUE : FALSE), critical_high_tide, | 359 | (warning_high_tide == UINT64_MAX ? FALSE : TRUE), warning_high_tide, |
351 | TRUE, 0, | 360 | (critical_high_tide == UINT64_MAX ? FALSE : TRUE), critical_high_tide, |
352 | TRUE, path->dtotal_units)); | 361 | TRUE, 0, |
362 | TRUE, path->dtotal_units * mult)); | ||
353 | 363 | ||
354 | if (display_inodes_perfdata) { | 364 | if (display_inodes_perfdata) { |
355 | /* *_high_tide must be reinitialized at each run */ | 365 | /* *_high_tide must be reinitialized at each run */ |
356 | warning_high_tide = UINT_MAX; | 366 | warning_high_tide = UINT64_MAX; |
357 | critical_high_tide = UINT_MAX; | 367 | critical_high_tide = UINT64_MAX; |
358 | 368 | ||
359 | if (path->freeinodes_percent->warning != NULL) { | 369 | if (path->freeinodes_percent->warning != NULL) { |
360 | warning_high_tide = abs( min( (double) warning_high_tide, (double) (1.0 - path->freeinodes_percent->warning->end/100)*path->inodes_total )); | 370 | warning_high_tide = llabs( min( (double) warning_high_tide, (double) (1.0 - path->freeinodes_percent->warning->end/100)*path->inodes_total )); |
361 | } | 371 | } |
362 | if (path->freeinodes_percent->critical != NULL) { | 372 | if (path->freeinodes_percent->critical != NULL) { |
363 | critical_high_tide = abs( min( (double) critical_high_tide, (double) (1.0 - path->freeinodes_percent->critical->end/100)*path->inodes_total )); | 373 | critical_high_tide = llabs( min( (double) critical_high_tide, (double) (1.0 - path->freeinodes_percent->critical->end/100)*path->inodes_total )); |
364 | } | 374 | } |
365 | 375 | ||
366 | xasprintf (&perf_ilabel, "%s (inodes)", (!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir); | 376 | xasprintf (&perf_ilabel, "%s (inodes)", (!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir); |
367 | /* Nb: *_high_tide are unset when == UINT_MAX */ | 377 | /* Nb: *_high_tide are unset when == UINT64_MAX */ |
368 | xasprintf (&perf, "%s %s", perf, | 378 | xasprintf (&perf, "%s %s", perf, |
369 | perfdata (perf_ilabel, | 379 | perfdata_uint64 (perf_ilabel, |
370 | path->inodes_used, "", | 380 | path->inodes_used, "", |
371 | (warning_high_tide != UINT_MAX ? TRUE : FALSE), warning_high_tide, | 381 | (warning_high_tide != UINT64_MAX ? TRUE : FALSE), warning_high_tide, |
372 | (critical_high_tide != UINT_MAX ? TRUE : FALSE), critical_high_tide, | 382 | (critical_high_tide != UINT64_MAX ? TRUE : FALSE), critical_high_tide, |
373 | TRUE, 0, | 383 | TRUE, 0, |
374 | TRUE, path->inodes_total)); | 384 | TRUE, path->inodes_total)); |
375 | } | 385 | } |
376 | 386 | ||
377 | if (disk_result==STATE_OK && erronly && !verbose) | 387 | if (disk_result==STATE_OK && erronly && !verbose) |
378 | continue; | 388 | continue; |
379 | 389 | ||
380 | if(disk_result && verbose >= 1) { | 390 | if(disk_result && verbose >= 1) { |
381 | xasprintf(&flag_header, " %s [", state_text (disk_result)); | 391 | xasprintf(&flag_header, " %s [", state_text (disk_result)); |
382 | } else { | 392 | } else { |
383 | xasprintf(&flag_header, ""); | 393 | xasprintf(&flag_header, ""); |
384 | } | 394 | } |
385 | xasprintf (&output, "%s%s %s %.0f %s (%.0f%%", | 395 | xasprintf (&output, "%s%s %s %llu%s (%.0f%%", |
386 | output, flag_header, | 396 | output, flag_header, |
387 | (!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir, | 397 | (!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir, |
388 | path->dfree_units, | 398 | path->dfree_units, |
389 | units, | 399 | units, |
390 | path->dfree_pct); | 400 | path->dfree_pct); |
391 | if (path->dused_inodes_percent < 0) { | 401 | if (path->dused_inodes_percent < 0) { |
392 | xasprintf(&output, "%s inode=-)%s;", output, (disk_result ? "]" : "")); | 402 | xasprintf(&output, "%s inode=-)%s;", output, (disk_result ? "]" : "")); |
393 | } else { | 403 | } else { |
394 | xasprintf(&output, "%s inode=%.0f%%)%s;", output, path->dfree_inodes_percent, ((disk_result && verbose >= 1) ? "]" : "")); | 404 | xasprintf(&output, "%s inode=%.0f%%)%s;", output, path->dfree_inodes_percent, ((disk_result && verbose >= 1) ? "]" : "")); |
395 | } | 405 | } |
396 | free(flag_header); | 406 | free(flag_header); |
397 | /* TODO: Need to do a similar debug line | 407 | /* TODO: Need to do a similar debug line |
398 | xasprintf (&details, _("%s\n\ | 408 | xasprintf (&details, _("%s\n\%.0f of %.0f %s (%.0f%% inode=%.0f%%) free on %s (type %s mounted on %s) warn:%lu crit:%lu warn%%:%.0f%% crit%%:%.0f%%"), |
399 | %.0f of %.0f %s (%.0f%% inode=%.0f%%) free on %s (type %s mounted on %s) warn:%lu crit:%lu warn%%:%.0f%% crit%%:%.0f%%"), | ||
400 | details, dfree_units, dtotal_units, units, dfree_pct, inode_space_pct, | 409 | details, dfree_units, dtotal_units, units, dfree_pct, inode_space_pct, |
401 | me->me_devname, me->me_type, me->me_mountdir, | 410 | me->me_devname, me->me_type, me->me_mountdir, |
402 | (unsigned long)w_df, (unsigned long)c_df, w_dfp, c_dfp); | 411 | (unsigned long)w_df, (unsigned long)c_df, w_dfp, c_dfp); |
@@ -557,14 +566,14 @@ process_arguments (int argc, char **argv) | |||
557 | } | 566 | } |
558 | break; | 567 | break; |
559 | 568 | ||
560 | case 'W': /* warning inode threshold */ | 569 | case 'W': /* warning inode threshold */ |
561 | if (*optarg == '@') { | 570 | if (*optarg == '@') { |
562 | warn_freeinodes_percent = optarg; | 571 | warn_freeinodes_percent = optarg; |
563 | } else { | 572 | } else { |
564 | xasprintf(&warn_freeinodes_percent, "@%s", optarg); | 573 | xasprintf(&warn_freeinodes_percent, "@%s", optarg); |
565 | } | 574 | } |
566 | break; | 575 | break; |
567 | case 'K': /* critical inode threshold */ | 576 | case 'K': /* critical inode threshold */ |
568 | if (*optarg == '@') { | 577 | if (*optarg == '@') { |
569 | crit_freeinodes_percent = optarg; | 578 | crit_freeinodes_percent = optarg; |
570 | } else { | 579 | } else { |
@@ -574,21 +583,24 @@ process_arguments (int argc, char **argv) | |||
574 | case 'u': | 583 | case 'u': |
575 | if (units) | 584 | if (units) |
576 | free(units); | 585 | free(units); |
577 | if (! strcmp (optarg, "bytes")) { | 586 | if (! strcasecmp (optarg, "bytes")) { |
578 | mult = (uintmax_t)1; | 587 | mult = (uintmax_t)1; |
579 | units = strdup ("B"); | 588 | units = strdup ("B"); |
580 | } else if (! strcmp (optarg, "kB")) { | 589 | } else if ( (! strcmp (optarg, "kB")) || (!strcmp(optarg, "KiB")) ) { |
581 | mult = (uintmax_t)1024; | 590 | mult = (uintmax_t)1024; |
582 | units = strdup ("kB"); | 591 | units = strdup ("kiB"); |
583 | } else if (! strcmp (optarg, "MB")) { | 592 | } else if ( (! strcmp (optarg, "MB")) || (!strcmp(optarg, "MiB")) ) { |
584 | mult = (uintmax_t)1024 * 1024; | 593 | mult = (uintmax_t)1024 * 1024; |
585 | units = strdup ("MB"); | 594 | units = strdup ("MiB"); |
586 | } else if (! strcmp (optarg, "GB")) { | 595 | } else if ( (! strcmp (optarg, "GB")) || (!strcmp(optarg, "GiB")) ) { |
587 | mult = (uintmax_t)1024 * 1024 * 1024; | 596 | mult = (uintmax_t)1024 * 1024 * 1024; |
588 | units = strdup ("GB"); | 597 | units = strdup ("GiB"); |
589 | } else if (! strcmp (optarg, "TB")) { | 598 | } else if ( (! strcmp (optarg, "TB")) || (!strcmp(optarg, "TiB")) ) { |
590 | mult = (uintmax_t)1024 * 1024 * 1024 * 1024; | 599 | mult = (uintmax_t)1024 * 1024 * 1024 * 1024; |
591 | units = strdup ("TB"); | 600 | units = strdup ("TiB"); |
601 | } else if ( (! strcmp (optarg, "PB")) || (!strcmp(optarg, "PiB")) ) { | ||
602 | mult = (uintmax_t)1024 * 1024 * 1024 * 1024 * 1024; | ||
603 | units = strdup ("PiB"); | ||
592 | } else { | 604 | } else { |
593 | die (STATE_UNKNOWN, _("unit type %s not known\n"), optarg); | 605 | die (STATE_UNKNOWN, _("unit type %s not known\n"), optarg); |
594 | } | 606 | } |
@@ -599,13 +611,13 @@ process_arguments (int argc, char **argv) | |||
599 | mult = 1024; | 611 | mult = 1024; |
600 | if (units) | 612 | if (units) |
601 | free(units); | 613 | free(units); |
602 | units = strdup ("kB"); | 614 | units = strdup ("kiB"); |
603 | break; | 615 | break; |
604 | case 'm': /* display mountpoint */ | 616 | case 'm': /* display mountpoint */ |
605 | mult = 1024 * 1024; | 617 | mult = 1024 * 1024; |
606 | if (units) | 618 | if (units) |
607 | free(units); | 619 | free(units); |
608 | units = strdup ("MB"); | 620 | units = strdup ("MiB"); |
609 | break; | 621 | break; |
610 | case 'L': | 622 | case 'L': |
611 | stat_remote_fs = 1; | 623 | stat_remote_fs = 1; |
@@ -812,7 +824,7 @@ process_arguments (int argc, char **argv) | |||
812 | } | 824 | } |
813 | 825 | ||
814 | if (units == NULL) { | 826 | if (units == NULL) { |
815 | units = strdup ("MB"); | 827 | units = strdup ("MiB"); |
816 | mult = (uintmax_t)1024 * 1024; | 828 | mult = (uintmax_t)1024 * 1024; |
817 | } | 829 | } |
818 | 830 | ||
@@ -1026,20 +1038,26 @@ get_stats (struct parameter_list *p, struct fs_usage *fsp) { | |||
1026 | if (p_list->group && ! (strcmp(p_list->group, p->group))) { | 1038 | if (p_list->group && ! (strcmp(p_list->group, p->group))) { |
1027 | stat_path(p_list); | 1039 | stat_path(p_list); |
1028 | get_fs_usage (p_list->best_match->me_mountdir, p_list->best_match->me_devname, &tmpfsp); | 1040 | get_fs_usage (p_list->best_match->me_mountdir, p_list->best_match->me_devname, &tmpfsp); |
1029 | get_path_stats(p_list, &tmpfsp); | 1041 | get_path_stats(p_list, &tmpfsp); |
1030 | if (verbose >= 3) | 1042 | if (verbose >= 3) |
1031 | printf("Group %s: adding %llu blocks sized %llu, (%s) used_units=%g free_units=%g total_units=%g fsu_blocksize=%llu mult=%llu\n", | 1043 | printf("Group %s: adding %llu blocks sized %llu, (%s) used_units=%lu free_units=%llu total_units=%llu mult=%llu\n", |
1032 | p_list->group, tmpfsp.fsu_bavail, tmpfsp.fsu_blocksize, p_list->best_match->me_mountdir, p_list->dused_units, p_list->dfree_units, | 1044 | p_list->group, |
1033 | p_list->dtotal_units, mult); | 1045 | tmpfsp.fsu_blocks, |
1034 | 1046 | tmpfsp.fsu_blocksize, | |
1035 | /* prevent counting the first FS of a group twice since its parameter_list entry | 1047 | p_list->best_match->me_mountdir, |
1048 | p_list->dused_units, | ||
1049 | p_list->dfree_units, | ||
1050 | p_list->dtotal_units, | ||
1051 | mult); | ||
1052 | |||
1053 | /* prevent counting the first FS of a group twice since its parameter_list entry | ||
1036 | * is used to carry the information of all file systems of the entire group */ | 1054 | * is used to carry the information of all file systems of the entire group */ |
1037 | if (! first) { | 1055 | if (! first) { |
1038 | p->total += p_list->total; | 1056 | p->total += p_list->total; |
1039 | p->available += p_list->available; | 1057 | p->available += p_list->available; |
1040 | p->available_to_root += p_list->available_to_root; | 1058 | p->available_to_root += p_list->available_to_root; |
1041 | p->used += p_list->used; | 1059 | p->used += p_list->used; |
1042 | 1060 | ||
1043 | p->dused_units += p_list->dused_units; | 1061 | p->dused_units += p_list->dused_units; |
1044 | p->dfree_units += p_list->dfree_units; | 1062 | p->dfree_units += p_list->dfree_units; |
1045 | p->dtotal_units += p_list->dtotal_units; | 1063 | p->dtotal_units += p_list->dtotal_units; |
@@ -1050,28 +1068,29 @@ get_stats (struct parameter_list *p, struct fs_usage *fsp) { | |||
1050 | } | 1068 | } |
1051 | first = 0; | 1069 | first = 0; |
1052 | } | 1070 | } |
1053 | if (verbose >= 3) | 1071 | if (verbose >= 3) |
1054 | printf("Group %s now has: used_units=%g free_units=%g total_units=%g fsu_blocksize=%llu mult=%llu\n", | 1072 | printf("Group %s now has: used_units=%llu free_units=%llu total_units=%llu fsu_blocksize=%llu mult=%llu\n", |
1055 | p->group, tmpfsp.fsu_bavail, tmpfsp.fsu_blocksize, p->best_match->me_mountdir, p->dused_units, | 1073 | p->group, |
1056 | p->dfree_units, p->dtotal_units, mult); | 1074 | p->dused_units, |
1075 | p->dfree_units, | ||
1076 | p->dtotal_units, | ||
1077 | tmpfsp.fsu_blocksize, | ||
1078 | mult); | ||
1057 | } | 1079 | } |
1058 | /* modify devname and mountdir for output */ | 1080 | /* modify devname and mountdir for output */ |
1059 | p->best_match->me_mountdir = p->best_match->me_devname = p->group; | 1081 | p->best_match->me_mountdir = p->best_match->me_devname = p->group; |
1060 | } | 1082 | } |
1061 | /* finally calculate percentages for either plain FS or summed up group */ | 1083 | /* finally calculate percentages for either plain FS or summed up group */ |
1062 | p->dused_pct = calculate_percent( p->used, p->used + p->available ); /* used + available can never be > uintmax */ | 1084 | p->dused_pct = calculate_percent( p->used, p->used + p->available ); /* used + available can never be > uintmax */ |
1063 | p->dfree_pct = 100 - p->dused_pct; | 1085 | p->dfree_pct = 100 - p->dused_pct; |
1064 | p->dused_inodes_percent = calculate_percent(p->inodes_total - p->inodes_free, p->inodes_total); | 1086 | p->dused_inodes_percent = calculate_percent(p->inodes_total - p->inodes_free, p->inodes_total); |
1065 | p->dfree_inodes_percent = 100 - p->dused_inodes_percent; | 1087 | p->dfree_inodes_percent = 100 - p->dused_inodes_percent; |
1066 | 1088 | ||
1067 | } | 1089 | } |
1068 | 1090 | ||
1069 | void | 1091 | void |
1070 | get_path_stats (struct parameter_list *p, struct fs_usage *fsp) { | 1092 | get_path_stats (struct parameter_list *p, struct fs_usage *fsp) { |
1071 | /* 2007-12-08 - Workaround for Gnulib reporting insanely high available | 1093 | p->available = fsp->fsu_bavail; |
1072 | * space on BSD (the actual value should be negative but fsp->fsu_bavail | ||
1073 | * is unsigned) */ | ||
1074 | p->available = fsp->fsu_bavail > fsp->fsu_bfree ? 0 : fsp->fsu_bavail; | ||
1075 | p->available_to_root = fsp->fsu_bfree; | 1094 | p->available_to_root = fsp->fsu_bfree; |
1076 | p->used = fsp->fsu_blocks - fsp->fsu_bfree; | 1095 | p->used = fsp->fsu_blocks - fsp->fsu_bfree; |
1077 | if (freespace_ignore_reserved) { | 1096 | if (freespace_ignore_reserved) { |
@@ -1081,7 +1100,7 @@ get_path_stats (struct parameter_list *p, struct fs_usage *fsp) { | |||
1081 | /* default behaviour : take all the blocks into account */ | 1100 | /* default behaviour : take all the blocks into account */ |
1082 | p->total = fsp->fsu_blocks; | 1101 | p->total = fsp->fsu_blocks; |
1083 | } | 1102 | } |
1084 | 1103 | ||
1085 | p->dused_units = p->used*fsp->fsu_blocksize/mult; | 1104 | p->dused_units = p->used*fsp->fsu_blocksize/mult; |
1086 | p->dfree_units = p->available*fsp->fsu_blocksize/mult; | 1105 | p->dfree_units = p->available*fsp->fsu_blocksize/mult; |
1087 | p->dtotal_units = p->total*fsp->fsu_blocksize/mult; | 1106 | p->dtotal_units = p->total*fsp->fsu_blocksize/mult; |
diff --git a/plugins/check_dns.c b/plugins/check_dns.c index 0f2e654..9de6caf 100644 --- a/plugins/check_dns.c +++ b/plugins/check_dns.c | |||
@@ -41,7 +41,7 @@ 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 *); | 44 | int error_scan (char *, int *); |
45 | int ip_match_cidr(const char *, const char *); | 45 | int 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); |
@@ -54,6 +54,7 @@ char ptr_server[ADDRESS_LENGTH] = ""; | |||
54 | int verbose = FALSE; | 54 | int 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 | 58 | ||
58 | int expect_authority = FALSE; | 59 | int expect_authority = FALSE; |
59 | int all_match = FALSE; | 60 | int all_match = FALSE; |
@@ -87,6 +88,7 @@ main (int argc, char **argv) | |||
87 | int parse_address = FALSE; /* This flag scans for Address: but only after Name: */ | 88 | int parse_address = FALSE; /* This flag scans for Address: but only after Name: */ |
88 | output chld_out, chld_err; | 89 | output chld_out, chld_err; |
89 | size_t i; | 90 | size_t i; |
91 | int is_nxdomain = FALSE; | ||
90 | 92 | ||
91 | setlocale (LC_ALL, ""); | 93 | setlocale (LC_ALL, ""); |
92 | bindtextdomain (PACKAGE, LOCALEDIR); | 94 | bindtextdomain (PACKAGE, LOCALEDIR); |
@@ -186,7 +188,7 @@ main (int argc, char **argv) | |||
186 | } | 188 | } |
187 | 189 | ||
188 | 190 | ||
189 | result = error_scan (chld_out.line[i]); | 191 | result = error_scan (chld_out.line[i], &is_nxdomain); |
190 | if (result != STATE_OK) { | 192 | if (result != STATE_OK) { |
191 | msg = strchr (chld_out.line[i], ':'); | 193 | msg = strchr (chld_out.line[i], ':'); |
192 | if(msg) msg++; | 194 | if(msg) msg++; |
@@ -199,8 +201,8 @@ main (int argc, char **argv) | |||
199 | if (verbose) | 201 | if (verbose) |
200 | puts(chld_err.line[i]); | 202 | puts(chld_err.line[i]); |
201 | 203 | ||
202 | if (error_scan (chld_err.line[i]) != STATE_OK) { | 204 | if (error_scan (chld_err.line[i], &is_nxdomain) != STATE_OK) { |
203 | result = max_state (result, error_scan (chld_err.line[i])); | 205 | result = max_state (result, error_scan (chld_err.line[i], &is_nxdomain)); |
204 | msg = strchr(input_buffer, ':'); | 206 | msg = strchr(input_buffer, ':'); |
205 | if(msg) | 207 | if(msg) |
206 | msg++; | 208 | msg++; |
@@ -209,6 +211,10 @@ main (int argc, char **argv) | |||
209 | } | 211 | } |
210 | } | 212 | } |
211 | 213 | ||
214 | if (is_nxdomain && !expect_nxdomain) { | ||
215 | die (STATE_CRITICAL, _("Domain '%s' was not found by the server\n"), query_address); | ||
216 | } | ||
217 | |||
212 | if (addresses) { | 218 | if (addresses) { |
213 | int i,slen; | 219 | int i,slen; |
214 | char *adrp; | 220 | char *adrp; |
@@ -260,6 +266,16 @@ main (int argc, char **argv) | |||
260 | } | 266 | } |
261 | } | 267 | } |
262 | 268 | ||
269 | if (expect_nxdomain) { | ||
270 | if (!is_nxdomain) { | ||
271 | result = STATE_CRITICAL; | ||
272 | xasprintf(&msg, _("Domain '%s' was found by the server: '%s'\n"), query_address, address); | ||
273 | } else { | ||
274 | if (address != NULL) free(address); | ||
275 | address = "NXDOMAIN"; | ||
276 | } | ||
277 | } | ||
278 | |||
263 | /* check if authoritative */ | 279 | /* check if authoritative */ |
264 | if (result == STATE_OK && expect_authority && non_authoritative) { | 280 | if (result == STATE_OK && expect_authority && non_authoritative) { |
265 | result = STATE_CRITICAL; | 281 | result = STATE_CRITICAL; |
@@ -339,9 +355,15 @@ ip2long(const char* src) { | |||
339 | } | 355 | } |
340 | 356 | ||
341 | int | 357 | int |
342 | error_scan (char *input_buffer) | 358 | error_scan (char *input_buffer, int *is_nxdomain) |
343 | { | 359 | { |
344 | 360 | ||
361 | const int nxdomain = strstr (input_buffer, "Non-existent") || | ||
362 | strstr (input_buffer, "** server can't find") || | ||
363 | strstr (input_buffer, "** Can't find") || | ||
364 | strstr (input_buffer, "NXDOMAIN"); | ||
365 | if (nxdomain) *is_nxdomain = TRUE; | ||
366 | |||
345 | /* the DNS lookup timed out */ | 367 | /* the DNS lookup timed out */ |
346 | if (strstr (input_buffer, _("Note: nslookup is deprecated and may be removed from future releases.")) || | 368 | if (strstr (input_buffer, _("Note: nslookup is deprecated and may be removed from future releases.")) || |
347 | strstr (input_buffer, _("Consider using the `dig' or `host' programs instead. Run nslookup with")) || | 369 | strstr (input_buffer, _("Consider using the `dig' or `host' programs instead. Run nslookup with")) || |
@@ -360,7 +382,7 @@ error_scan (char *input_buffer) | |||
360 | 382 | ||
361 | /* Connection was refused */ | 383 | /* Connection was refused */ |
362 | else if (strstr (input_buffer, "Connection refused") || | 384 | else if (strstr (input_buffer, "Connection refused") || |
363 | strstr (input_buffer, "Couldn't find server") || | 385 | strstr (input_buffer, "Couldn't find server") || |
364 | strstr (input_buffer, "Refused") || | 386 | strstr (input_buffer, "Refused") || |
365 | (strstr (input_buffer, "** server can't find") && | 387 | (strstr (input_buffer, "** server can't find") && |
366 | strstr (input_buffer, ": REFUSED"))) | 388 | strstr (input_buffer, ": REFUSED"))) |
@@ -374,13 +396,6 @@ error_scan (char *input_buffer) | |||
374 | else if (strstr (input_buffer, "No information")) | 396 | else if (strstr (input_buffer, "No information")) |
375 | die (STATE_CRITICAL, _("No information returned by DNS server at %s\n"), dns_server); | 397 | die (STATE_CRITICAL, _("No information returned by DNS server at %s\n"), dns_server); |
376 | 398 | ||
377 | /* Host or domain name does not exist */ | ||
378 | else if (strstr (input_buffer, "Non-existent") || | ||
379 | strstr (input_buffer, "** server can't find") || | ||
380 | strstr (input_buffer, "** Can't find") || | ||
381 | strstr (input_buffer,"NXDOMAIN")) | ||
382 | die (STATE_CRITICAL, _("Domain %s was not found by the server\n"), query_address); | ||
383 | |||
384 | /* Network is unreachable */ | 399 | /* Network is unreachable */ |
385 | else if (strstr (input_buffer, "Network is unreachable")) | 400 | else if (strstr (input_buffer, "Network is unreachable")) |
386 | die (STATE_CRITICAL, _("Network is unreachable\n")); | 401 | die (STATE_CRITICAL, _("Network is unreachable\n")); |
@@ -417,6 +432,7 @@ process_arguments (int argc, char **argv) | |||
417 | {"server", required_argument, 0, 's'}, | 432 | {"server", required_argument, 0, 's'}, |
418 | {"reverse-server", required_argument, 0, 'r'}, | 433 | {"reverse-server", required_argument, 0, 'r'}, |
419 | {"expected-address", required_argument, 0, 'a'}, | 434 | {"expected-address", required_argument, 0, 'a'}, |
435 | {"expect-nxdomain", no_argument, 0, 'n'}, | ||
420 | {"expect-authority", no_argument, 0, 'A'}, | 436 | {"expect-authority", no_argument, 0, 'A'}, |
421 | {"all", no_argument, 0, 'L'}, | 437 | {"all", no_argument, 0, 'L'}, |
422 | {"warning", required_argument, 0, 'w'}, | 438 | {"warning", required_argument, 0, 'w'}, |
@@ -432,7 +448,7 @@ process_arguments (int argc, char **argv) | |||
432 | strcpy (argv[c], "-t"); | 448 | strcpy (argv[c], "-t"); |
433 | 449 | ||
434 | while (1) { | 450 | while (1) { |
435 | c = getopt_long (argc, argv, "hVvALt:H:s:r:a:w:c:", long_opts, &opt_index); | 451 | c = getopt_long (argc, argv, "hVvALnt:H:s:r:a:w:c:", long_opts, &opt_index); |
436 | 452 | ||
437 | if (c == -1 || c == EOF) | 453 | if (c == -1 || c == EOF) |
438 | break; | 454 | break; |
@@ -491,6 +507,9 @@ process_arguments (int argc, char **argv) | |||
491 | expected_address_cnt++; | 507 | expected_address_cnt++; |
492 | } | 508 | } |
493 | break; | 509 | break; |
510 | case 'n': /* expect NXDOMAIN */ | ||
511 | expect_nxdomain = TRUE; | ||
512 | break; | ||
494 | case 'A': /* expect authority */ | 513 | case 'A': /* expect authority */ |
495 | expect_authority = TRUE; | 514 | expect_authority = TRUE; |
496 | break; | 515 | break; |
@@ -532,8 +551,15 @@ process_arguments (int argc, char **argv) | |||
532 | int | 551 | int |
533 | validate_arguments () | 552 | validate_arguments () |
534 | { | 553 | { |
535 | if (query_address[0] == 0) | 554 | if (query_address[0] == 0) { |
555 | printf ("missing --host argument\n"); | ||
556 | return ERROR; | ||
557 | } | ||
558 | |||
559 | if (expected_address_cnt > 0 && expect_nxdomain) { | ||
560 | printf ("--expected-address and --expect-nxdomain cannot be combined\n"); | ||
536 | return ERROR; | 561 | return ERROR; |
562 | } | ||
537 | 563 | ||
538 | return OK; | 564 | return OK; |
539 | } | 565 | } |
@@ -566,6 +592,9 @@ print_help (void) | |||
566 | printf (" %s\n", _("Optional IP-ADDRESS/CIDR you expect the DNS server to return. HOST must end")); | 592 | printf (" %s\n", _("Optional IP-ADDRESS/CIDR you expect the DNS server to return. HOST must end")); |
567 | printf (" %s\n", _("with a dot (.). This option can be repeated multiple times (Returns OK if any")); | 593 | printf (" %s\n", _("with a dot (.). This option can be repeated multiple times (Returns OK if any")); |
568 | printf (" %s\n", _("value matches).")); | 594 | printf (" %s\n", _("value matches).")); |
595 | printf (" -n, --expect-nxdomain\n"); | ||
596 | printf (" %s\n", _("Expect the DNS server to return NXDOMAIN (i.e. the domain was not found)")); | ||
597 | printf (" %s\n", _("Cannot be used together with -a")); | ||
569 | printf (" -A, --expect-authority\n"); | 598 | printf (" -A, --expect-authority\n"); |
570 | printf (" %s\n", _("Optionally expect the DNS server to be authoritative for the lookup")); | 599 | printf (" %s\n", _("Optionally expect the DNS server to be authoritative for the lookup")); |
571 | printf (" -w, --warning=seconds\n"); | 600 | printf (" -w, --warning=seconds\n"); |
@@ -586,5 +615,5 @@ void | |||
586 | print_usage (void) | 615 | print_usage (void) |
587 | { | 616 | { |
588 | printf ("%s\n", _("Usage:")); | 617 | printf ("%s\n", _("Usage:")); |
589 | printf ("%s -H host [-s server] [-a expected-address] [-A] [-t timeout] [-w warn] [-c crit] [-L]\n", progname); | 618 | printf ("%s -H host [-s server] [-a expected-address] [-n] [-A] [-t timeout] [-w warn] [-c crit] [-L]\n", progname); |
590 | } | 619 | } |
diff --git a/plugins/check_hpjd.c b/plugins/check_hpjd.c index 6546556..c4b4417 100644 --- a/plugins/check_hpjd.c +++ b/plugins/check_hpjd.c | |||
@@ -66,7 +66,7 @@ void print_usage (void); | |||
66 | 66 | ||
67 | char *community = NULL; | 67 | char *community = NULL; |
68 | char *address = NULL; | 68 | char *address = NULL; |
69 | char *port = NULL; | 69 | unsigned int port = 0; |
70 | int check_paper_out = 1; | 70 | int check_paper_out = 1; |
71 | 71 | ||
72 | int | 72 | int |
@@ -121,8 +121,12 @@ main (int argc, char **argv) | |||
121 | HPJD_GD_DOOR_OPEN, HPJD_GD_PAPER_OUTPUT, HPJD_GD_STATUS_DISPLAY); | 121 | HPJD_GD_DOOR_OPEN, HPJD_GD_PAPER_OUTPUT, HPJD_GD_STATUS_DISPLAY); |
122 | 122 | ||
123 | /* get the command to run */ | 123 | /* get the command to run */ |
124 | sprintf (command_line, "%s -OQa -m : -v 1 -c %s %s:%hd %s", PATH_TO_SNMPGET, community, | 124 | sprintf (command_line, "%s -OQa -m : -v 1 -c %s %s:%u %s", |
125 | address, port, query_string); | 125 | PATH_TO_SNMPGET, |
126 | community, | ||
127 | address, | ||
128 | port, | ||
129 | query_string); | ||
126 | 130 | ||
127 | /* run the command */ | 131 | /* run the command */ |
128 | child_process = spopen (command_line); | 132 | child_process = spopen (command_line); |
@@ -380,11 +384,8 @@ process_arguments (int argc, char **argv) | |||
380 | community = strdup (DEFAULT_COMMUNITY); | 384 | community = strdup (DEFAULT_COMMUNITY); |
381 | } | 385 | } |
382 | 386 | ||
383 | if (port == NULL) { | 387 | if (port == 0) { |
384 | if (argv[c] != NULL ) | 388 | port = atoi(DEFAULT_PORT); |
385 | port = argv[c]; | ||
386 | else | ||
387 | port = atoi (DEFAULT_PORT); | ||
388 | } | 389 | } |
389 | 390 | ||
390 | return validate_arguments (); | 391 | return validate_arguments (); |
diff --git a/plugins/check_http.c b/plugins/check_http.c index 0b71266..34fb4f0 100644 --- a/plugins/check_http.c +++ b/plugins/check_http.c | |||
@@ -1453,8 +1453,8 @@ redir (char *pos, char *status_line) | |||
1453 | !strncmp(server_address, addr, MAX_IPV4_HOSTLENGTH) && | 1453 | !strncmp(server_address, addr, MAX_IPV4_HOSTLENGTH) && |
1454 | (host_name && !strncmp(host_name, addr, MAX_IPV4_HOSTLENGTH)) && | 1454 | (host_name && !strncmp(host_name, addr, MAX_IPV4_HOSTLENGTH)) && |
1455 | !strcmp(server_url, url)) | 1455 | !strcmp(server_url, url)) |
1456 | die (STATE_WARNING, | 1456 | die (STATE_CRITICAL, |
1457 | _("HTTP WARNING - redirection creates an infinite loop - %s://%s:%d%s%s\n"), | 1457 | _("HTTP CRITICAL - redirection creates an infinite loop - %s://%s:%d%s%s\n"), |
1458 | type, addr, i, url, (display_html ? "</A>" : "")); | 1458 | type, addr, i, url, (display_html ? "</A>" : "")); |
1459 | 1459 | ||
1460 | strcpy (server_type, type); | 1460 | strcpy (server_type, type); |
diff --git a/plugins/check_ldap.c b/plugins/check_ldap.c index bc7bd44..845a4f5 100644 --- a/plugins/check_ldap.c +++ b/plugins/check_ldap.c | |||
@@ -432,6 +432,9 @@ validate_arguments () | |||
432 | set_thresholds(&entries_thresholds, | 432 | set_thresholds(&entries_thresholds, |
433 | warn_entries, crit_entries); | 433 | warn_entries, crit_entries); |
434 | } | 434 | } |
435 | if (ld_passwd==NULL) | ||
436 | ld_passwd = getenv("LDAP_PASSWORD"); | ||
437 | |||
435 | return OK; | 438 | return OK; |
436 | } | 439 | } |
437 | 440 | ||
@@ -465,7 +468,7 @@ print_help (void) | |||
465 | printf (" %s\n", "-D [--bind]"); | 468 | printf (" %s\n", "-D [--bind]"); |
466 | printf (" %s\n", _("ldap bind DN (if required)")); | 469 | printf (" %s\n", _("ldap bind DN (if required)")); |
467 | printf (" %s\n", "-P [--pass]"); | 470 | printf (" %s\n", "-P [--pass]"); |
468 | printf (" %s\n", _("ldap password (if required)")); | 471 | printf (" %s\n", _("ldap password (if required, or set the password through environment variable 'LDAP_PASSWORD')")); |
469 | printf (" %s\n", "-T [--starttls]"); | 472 | printf (" %s\n", "-T [--starttls]"); |
470 | printf (" %s\n", _("use starttls mechanism introduced in protocol version 3")); | 473 | printf (" %s\n", _("use starttls mechanism introduced in protocol version 3")); |
471 | printf (" %s\n", "-S [--ssl]"); | 474 | printf (" %s\n", "-S [--ssl]"); |
diff --git a/plugins/check_load.c b/plugins/check_load.c index bf7b94b..0e4de54 100644 --- a/plugins/check_load.c +++ b/plugins/check_load.c | |||
@@ -209,7 +209,7 @@ main (int argc, char **argv) | |||
209 | else if(la[i] > wload[i]) result = STATE_WARNING; | 209 | else if(la[i] > wload[i]) result = STATE_WARNING; |
210 | } | 210 | } |
211 | 211 | ||
212 | printf("%s - %s|", state_text(result), status_line); | 212 | printf("LOAD %s - %s|", state_text(result), status_line); |
213 | for(i = 0; i < 3; i++) | 213 | for(i = 0; i < 3; i++) |
214 | printf("load%d=%.3f;%.3f;%.3f;0; ", nums[i], la[i], wload[i], cload[i]); | 214 | printf("load%d=%.3f;%.3f;%.3f;0; ", nums[i], la[i], wload[i], cload[i]); |
215 | 215 | ||
diff --git a/plugins/check_ping.c b/plugins/check_ping.c index 423ecbe..ba7af37 100644 --- a/plugins/check_ping.c +++ b/plugins/check_ping.c | |||
@@ -37,6 +37,8 @@ const char *email = "devel@monitoring-plugins.org"; | |||
37 | #include "popen.h" | 37 | #include "popen.h" |
38 | #include "utils.h" | 38 | #include "utils.h" |
39 | 39 | ||
40 | #include <signal.h> | ||
41 | |||
40 | #define WARN_DUPLICATES "DUPLICATES FOUND! " | 42 | #define WARN_DUPLICATES "DUPLICATES FOUND! " |
41 | #define UNKNOWN_TRIP_TIME -1.0 /* -1 seconds */ | 43 | #define UNKNOWN_TRIP_TIME -1.0 /* -1 seconds */ |
42 | 44 | ||
@@ -163,10 +165,14 @@ main (int argc, char **argv) | |||
163 | printf ("</A>"); | 165 | printf ("</A>"); |
164 | 166 | ||
165 | /* Print performance data */ | 167 | /* Print performance data */ |
166 | printf("|%s", fperfdata ("rta", (double) rta, "ms", | 168 | if (pl != 100) { |
167 | wrta>0?TRUE:FALSE, wrta, | 169 | printf("|%s", fperfdata ("rta", (double) rta, "ms", |
168 | crta>0?TRUE:FALSE, crta, | 170 | wrta>0?TRUE:FALSE, wrta, |
169 | TRUE, 0, FALSE, 0)); | 171 | crta>0?TRUE:FALSE, crta, |
172 | TRUE, 0, FALSE, 0)); | ||
173 | } else { | ||
174 | printf("| rta=U;%f;%f;;", wrta, crta); | ||
175 | } | ||
170 | printf(" %s\n", perfdata ("pl", (long) pl, "%", | 176 | printf(" %s\n", perfdata ("pl", (long) pl, "%", |
171 | wpl>0?TRUE:FALSE, wpl, | 177 | wpl>0?TRUE:FALSE, wpl, |
172 | cpl>0?TRUE:FALSE, cpl, | 178 | cpl>0?TRUE:FALSE, cpl, |
diff --git a/plugins/check_procs.c b/plugins/check_procs.c index f7917c3..4872340 100644 --- a/plugins/check_procs.c +++ b/plugins/check_procs.c | |||
@@ -1,34 +1,34 @@ | |||
1 | /***************************************************************************** | 1 | /***************************************************************************** |
2 | * | 2 | * |
3 | * Monitoring check_procs plugin | 3 | * Monitoring check_procs plugin |
4 | * | 4 | * |
5 | * License: GPL | 5 | * License: GPL |
6 | * Copyright (c) 2000-2008 Monitoring Plugins Development Team | 6 | * Copyright (c) 2000-2008 Monitoring Plugins Development Team |
7 | * | 7 | * |
8 | * Description: | 8 | * Description: |
9 | * | 9 | * |
10 | * This file contains the check_procs plugin | 10 | * This file contains the check_procs plugin |
11 | * | 11 | * |
12 | * Checks all processes and generates WARNING or CRITICAL states if the | 12 | * Checks all processes and generates WARNING or CRITICAL states if the |
13 | * specified metric is outside the required threshold ranges. The metric | 13 | * specified metric is outside the required threshold ranges. The metric |
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 | * | 17 | * |
18 | * This program is free software: you can redistribute it and/or modify | 18 | * 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 | 19 | * it under the terms of the GNU General Public License as published by |
20 | * the Free Software Foundation, either version 3 of the License, or | 20 | * the Free Software Foundation, either version 3 of the License, or |
21 | * (at your option) any later version. | 21 | * (at your option) any later version. |
22 | * | 22 | * |
23 | * This program is distributed in the hope that it will be useful, | 23 | * This program is distributed in the hope that it will be useful, |
24 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 24 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
25 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 25 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
26 | * GNU General Public License for more details. | 26 | * GNU General Public License for more details. |
27 | * | 27 | * |
28 | * You should have received a copy of the GNU General Public License | 28 | * You should have received a copy of the GNU General Public License |
29 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 29 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
30 | * | 30 | * |
31 | * | 31 | * |
32 | *****************************************************************************/ | 32 | *****************************************************************************/ |
33 | 33 | ||
34 | const char *progname = "check_procs"; | 34 | const char *progname = "check_procs"; |
@@ -50,7 +50,7 @@ const char *email = "devel@monitoring-plugins.org"; | |||
50 | 50 | ||
51 | int process_arguments (int, char **); | 51 | int process_arguments (int, char **); |
52 | int validate_arguments (void); | 52 | int validate_arguments (void); |
53 | int convert_to_seconds (char *); | 53 | int convert_to_seconds (char *); |
54 | void print_help (void); | 54 | void print_help (void); |
55 | void print_usage (void); | 55 | void print_usage (void); |
56 | 56 | ||
@@ -230,9 +230,9 @@ main (int argc, char **argv) | |||
230 | procseconds = convert_to_seconds(procetime); | 230 | procseconds = convert_to_seconds(procetime); |
231 | 231 | ||
232 | if (verbose >= 3) | 232 | if (verbose >= 3) |
233 | printf ("proc#=%d uid=%d vsz=%d rss=%d pid=%d ppid=%d pcpu=%.2f stat=%s etime=%s prog=%s args=%s\n", | 233 | printf ("proc#=%d uid=%d vsz=%d rss=%d pid=%d ppid=%d pcpu=%.2f stat=%s etime=%s prog=%s args=%s\n", |
234 | procs, procuid, procvsz, procrss, | 234 | procs, procuid, procvsz, procrss, |
235 | procpid, procppid, procpcpu, procstat, | 235 | procpid, procppid, procpcpu, procstat, |
236 | procetime, procprog, procargs); | 236 | procetime, procprog, procargs); |
237 | 237 | ||
238 | /* Ignore self */ | 238 | /* Ignore self */ |
@@ -265,7 +265,7 @@ main (int argc, char **argv) | |||
265 | } | 265 | } |
266 | } | 266 | } |
267 | 267 | ||
268 | if ((options & STAT) && (strstr (statopts, procstat))) | 268 | if ((options & STAT) && (strstr (procstat, statopts))) |
269 | resultsum |= STAT; | 269 | resultsum |= STAT; |
270 | if ((options & ARGS) && procargs && (strstr (procargs, args) != NULL)) | 270 | if ((options & ARGS) && procargs && (strstr (procargs, args) != NULL)) |
271 | resultsum |= ARGS; | 271 | resultsum |= ARGS; |
@@ -292,9 +292,9 @@ main (int argc, char **argv) | |||
292 | 292 | ||
293 | procs++; | 293 | procs++; |
294 | if (verbose >= 2) { | 294 | if (verbose >= 2) { |
295 | printf ("Matched: uid=%d vsz=%d rss=%d pid=%d ppid=%d pcpu=%.2f stat=%s etime=%s prog=%s args=%s\n", | 295 | printf ("Matched: uid=%d vsz=%d rss=%d pid=%d ppid=%d pcpu=%.2f stat=%s etime=%s prog=%s args=%s\n", |
296 | procuid, procvsz, procrss, | 296 | procuid, procvsz, procrss, |
297 | procpid, procppid, procpcpu, procstat, | 297 | procpid, procppid, procpcpu, procstat, |
298 | procetime, procprog, procargs); | 298 | procetime, procprog, procargs); |
299 | } | 299 | } |
300 | 300 | ||
@@ -320,7 +320,7 @@ main (int argc, char **argv) | |||
320 | result = max_state (result, i); | 320 | result = max_state (result, i); |
321 | } | 321 | } |
322 | } | 322 | } |
323 | } | 323 | } |
324 | /* This should not happen */ | 324 | /* This should not happen */ |
325 | else if (verbose) { | 325 | else if (verbose) { |
326 | printf(_("Not parseable: %s"), input_buffer); | 326 | printf(_("Not parseable: %s"), input_buffer); |
@@ -332,7 +332,7 @@ main (int argc, char **argv) | |||
332 | return STATE_UNKNOWN; | 332 | return STATE_UNKNOWN; |
333 | } | 333 | } |
334 | 334 | ||
335 | if ( result == STATE_UNKNOWN ) | 335 | if ( result == STATE_UNKNOWN ) |
336 | result = STATE_OK; | 336 | result = STATE_OK; |
337 | 337 | ||
338 | /* Needed if procs found, but none match filter */ | 338 | /* Needed if procs found, but none match filter */ |
@@ -352,9 +352,9 @@ main (int argc, char **argv) | |||
352 | if (metric != METRIC_PROCS) { | 352 | if (metric != METRIC_PROCS) { |
353 | printf (_("%d crit, %d warn out of "), crit, warn); | 353 | printf (_("%d crit, %d warn out of "), crit, warn); |
354 | } | 354 | } |
355 | } | 355 | } |
356 | printf (ngettext ("%d process", "%d processes", (unsigned long) procs), procs); | 356 | printf (ngettext ("%d process", "%d processes", (unsigned long) procs), procs); |
357 | 357 | ||
358 | if (strcmp(fmt,"") != 0) { | 358 | if (strcmp(fmt,"") != 0) { |
359 | printf (_(" with %s"), fmt); | 359 | printf (_(" with %s"), fmt); |
360 | } | 360 | } |
@@ -440,7 +440,7 @@ process_arguments (int argc, char **argv) | |||
440 | break; | 440 | break; |
441 | case 'c': /* critical threshold */ | 441 | case 'c': /* critical threshold */ |
442 | critical_range = optarg; | 442 | critical_range = optarg; |
443 | break; | 443 | break; |
444 | case 'w': /* warning threshold */ | 444 | case 'w': /* warning threshold */ |
445 | warning_range = optarg; | 445 | warning_range = optarg; |
446 | break; | 446 | break; |
@@ -542,11 +542,11 @@ process_arguments (int argc, char **argv) | |||
542 | if ( strcmp(optarg, "PROCS") == 0) { | 542 | if ( strcmp(optarg, "PROCS") == 0) { |
543 | metric = METRIC_PROCS; | 543 | metric = METRIC_PROCS; |
544 | break; | 544 | break; |
545 | } | 545 | } |
546 | else if ( strcmp(optarg, "VSZ") == 0) { | 546 | else if ( strcmp(optarg, "VSZ") == 0) { |
547 | metric = METRIC_VSZ; | 547 | metric = METRIC_VSZ; |
548 | break; | 548 | break; |
549 | } | 549 | } |
550 | else if ( strcmp(optarg, "RSS") == 0 ) { | 550 | else if ( strcmp(optarg, "RSS") == 0 ) { |
551 | metric = METRIC_RSS; | 551 | metric = METRIC_RSS; |
552 | break; | 552 | break; |
@@ -559,7 +559,7 @@ process_arguments (int argc, char **argv) | |||
559 | metric = METRIC_ELAPSED; | 559 | metric = METRIC_ELAPSED; |
560 | break; | 560 | break; |
561 | } | 561 | } |
562 | 562 | ||
563 | usage4 (_("Metric must be one of PROCS, VSZ, RSS, CPU, ELAPSED!")); | 563 | usage4 (_("Metric must be one of PROCS, VSZ, RSS, CPU, ELAPSED!")); |
564 | case 'k': /* linux kernel thread filter */ | 564 | case 'k': /* linux kernel thread filter */ |
565 | kthread_filter = 1; | 565 | kthread_filter = 1; |
@@ -642,7 +642,7 @@ convert_to_seconds(char *etime) { | |||
642 | seconds = 0; | 642 | seconds = 0; |
643 | 643 | ||
644 | for (ptr = etime; *ptr != '\0'; ptr++) { | 644 | for (ptr = etime; *ptr != '\0'; ptr++) { |
645 | 645 | ||
646 | if (*ptr == '-') { | 646 | if (*ptr == '-') { |
647 | hyphcnt++; | 647 | hyphcnt++; |
648 | continue; | 648 | continue; |
diff --git a/plugins/check_smtp.c b/plugins/check_smtp.c index d37c57c..c1e92df 100644 --- a/plugins/check_smtp.c +++ b/plugins/check_smtp.c | |||
@@ -55,6 +55,7 @@ enum { | |||
55 | #define SMTP_EXPECT "220" | 55 | #define SMTP_EXPECT "220" |
56 | #define SMTP_HELO "HELO " | 56 | #define SMTP_HELO "HELO " |
57 | #define SMTP_EHLO "EHLO " | 57 | #define SMTP_EHLO "EHLO " |
58 | #define SMTP_LHLO "LHLO " | ||
58 | #define SMTP_QUIT "QUIT\r\n" | 59 | #define SMTP_QUIT "QUIT\r\n" |
59 | #define SMTP_STARTTLS "STARTTLS\r\n" | 60 | #define SMTP_STARTTLS "STARTTLS\r\n" |
60 | #define SMTP_AUTH_LOGIN "AUTH LOGIN\r\n" | 61 | #define SMTP_AUTH_LOGIN "AUTH LOGIN\r\n" |
@@ -102,6 +103,7 @@ int check_critical_time = FALSE; | |||
102 | int verbose = 0; | 103 | int verbose = 0; |
103 | int use_ssl = FALSE; | 104 | int use_ssl = FALSE; |
104 | short use_ehlo = FALSE; | 105 | short use_ehlo = FALSE; |
106 | short use_lhlo = FALSE; | ||
105 | short ssl_established = 0; | 107 | short ssl_established = 0; |
106 | char *localhostname = NULL; | 108 | char *localhostname = NULL; |
107 | int sd; | 109 | int sd; |
@@ -152,7 +154,9 @@ main (int argc, char **argv) | |||
152 | return STATE_CRITICAL; | 154 | return STATE_CRITICAL; |
153 | } | 155 | } |
154 | } | 156 | } |
155 | if(use_ehlo) | 157 | if(use_lhlo) |
158 | xasprintf (&helocmd, "%s%s%s", SMTP_LHLO, localhostname, "\r\n"); | ||
159 | else if(use_ehlo) | ||
156 | xasprintf (&helocmd, "%s%s%s", SMTP_EHLO, localhostname, "\r\n"); | 160 | xasprintf (&helocmd, "%s%s%s", SMTP_EHLO, localhostname, "\r\n"); |
157 | else | 161 | else |
158 | xasprintf (&helocmd, "%s%s%s", SMTP_HELO, localhostname, "\r\n"); | 162 | xasprintf (&helocmd, "%s%s%s", SMTP_HELO, localhostname, "\r\n"); |
@@ -197,7 +201,7 @@ main (int argc, char **argv) | |||
197 | if (recvlines(buffer, MAX_INPUT_BUFFER) <= 0) { | 201 | if (recvlines(buffer, MAX_INPUT_BUFFER) <= 0) { |
198 | printf (_("recv() failed\n")); | 202 | printf (_("recv() failed\n")); |
199 | return STATE_WARNING; | 203 | return STATE_WARNING; |
200 | } else if(use_ehlo){ | 204 | } else if(use_ehlo || use_lhlo){ |
201 | if(strstr(buffer, "250 STARTTLS") != NULL || | 205 | if(strstr(buffer, "250 STARTTLS") != NULL || |
202 | strstr(buffer, "250-STARTTLS") != NULL){ | 206 | strstr(buffer, "250-STARTTLS") != NULL){ |
203 | supports_tls=TRUE; | 207 | supports_tls=TRUE; |
@@ -470,6 +474,7 @@ process_arguments (int argc, char **argv) | |||
470 | {"use-ipv4", no_argument, 0, '4'}, | 474 | {"use-ipv4", no_argument, 0, '4'}, |
471 | {"use-ipv6", no_argument, 0, '6'}, | 475 | {"use-ipv6", no_argument, 0, '6'}, |
472 | {"help", no_argument, 0, 'h'}, | 476 | {"help", no_argument, 0, 'h'}, |
477 | {"lmtp", no_argument, 0, 'L'}, | ||
473 | {"starttls",no_argument,0,'S'}, | 478 | {"starttls",no_argument,0,'S'}, |
474 | {"certificate",required_argument,0,'D'}, | 479 | {"certificate",required_argument,0,'D'}, |
475 | {"ignore-quit-failure",no_argument,0,'q'}, | 480 | {"ignore-quit-failure",no_argument,0,'q'}, |
@@ -489,7 +494,7 @@ process_arguments (int argc, char **argv) | |||
489 | } | 494 | } |
490 | 495 | ||
491 | while (1) { | 496 | while (1) { |
492 | c = getopt_long (argc, argv, "+hVv46t:p:f:e:c:w:H:C:R:SD:F:A:U:P:q", | 497 | c = getopt_long (argc, argv, "+hVv46Lt:p:f:e:c:w:H:C:R:SD:F:A:U:P:q", |
493 | longopts, &option); | 498 | longopts, &option); |
494 | 499 | ||
495 | if (c == -1 || c == EOF) | 500 | if (c == -1 || c == EOF) |
@@ -616,6 +621,9 @@ process_arguments (int argc, char **argv) | |||
616 | use_ssl = TRUE; | 621 | use_ssl = TRUE; |
617 | use_ehlo = TRUE; | 622 | use_ehlo = TRUE; |
618 | break; | 623 | break; |
624 | case 'L': | ||
625 | use_lhlo = TRUE; | ||
626 | break; | ||
619 | case '4': | 627 | case '4': |
620 | address_family = AF_INET; | 628 | address_family = AF_INET; |
621 | break; | 629 | break; |
@@ -824,6 +832,8 @@ print_help (void) | |||
824 | printf (" %s\n", _("SMTP AUTH username")); | 832 | printf (" %s\n", _("SMTP AUTH username")); |
825 | printf (" %s\n", "-P, --authpass=STRING"); | 833 | printf (" %s\n", "-P, --authpass=STRING"); |
826 | printf (" %s\n", _("SMTP AUTH password")); | 834 | printf (" %s\n", _("SMTP AUTH password")); |
835 | printf (" %s\n", "-L, --lmtp"); | ||
836 | printf (" %s\n", _("Send LHLO instead of HELO/EHLO")); | ||
827 | printf (" %s\n", "-q, --ignore-quit-failure"); | 837 | printf (" %s\n", "-q, --ignore-quit-failure"); |
828 | printf (" %s\n", _("Ignore failure when sending QUIT command to server")); | 838 | printf (" %s\n", _("Ignore failure when sending QUIT command to server")); |
829 | 839 | ||
@@ -850,6 +860,6 @@ print_usage (void) | |||
850 | printf ("%s\n", _("Usage:")); | 860 | printf ("%s\n", _("Usage:")); |
851 | printf ("%s -H host [-p port] [-4|-6] [-e expect] [-C command] [-R response] [-f from addr]\n", progname); | 861 | printf ("%s -H host [-p port] [-4|-6] [-e expect] [-C command] [-R response] [-f from addr]\n", progname); |
852 | printf ("[-A authtype -U authuser -P authpass] [-w warn] [-c crit] [-t timeout] [-q]\n"); | 862 | printf ("[-A authtype -U authuser -P authpass] [-w warn] [-c crit] [-t timeout] [-q]\n"); |
853 | printf ("[-F fqdn] [-S] [-D warn days cert expire[,crit days cert expire]] [-v] \n"); | 863 | printf ("[-F fqdn] [-S] [-L] [-D warn days cert expire[,crit days cert expire]] [-v] \n"); |
854 | } | 864 | } |
855 | 865 | ||
diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c index afc568b..abe54cf 100644 --- a/plugins/check_snmp.c +++ b/plugins/check_snmp.c | |||
@@ -468,6 +468,9 @@ main (int argc, char **argv) | |||
468 | /* Process this block for numeric comparisons */ | 468 | /* Process this block for numeric comparisons */ |
469 | /* Make some special values,like Timeticks numeric only if a threshold is defined */ | 469 | /* Make some special values,like Timeticks numeric only if a threshold is defined */ |
470 | if (thlds[i]->warning || thlds[i]->critical || calculate_rate) { | 470 | if (thlds[i]->warning || thlds[i]->critical || calculate_rate) { |
471 | if (verbose > 2) { | ||
472 | print_thresholds(" thresholds", thlds[i]); | ||
473 | } | ||
471 | ptr = strpbrk (show, "-0123456789"); | 474 | ptr = strpbrk (show, "-0123456789"); |
472 | if (ptr == NULL) | 475 | if (ptr == NULL) |
473 | die (STATE_UNKNOWN,_("No valid data returned (%s)\n"), show); | 476 | die (STATE_UNKNOWN,_("No valid data returned (%s)\n"), show); |
@@ -581,14 +584,16 @@ main (int argc, char **argv) | |||
581 | 584 | ||
582 | if (warning_thresholds) { | 585 | if (warning_thresholds) { |
583 | strncat(perfstr, ";", sizeof(perfstr)-strlen(perfstr)-1); | 586 | strncat(perfstr, ";", sizeof(perfstr)-strlen(perfstr)-1); |
584 | strncat(perfstr, warning_thresholds, sizeof(perfstr)-strlen(perfstr)-1); | 587 | if(thlds[i]->warning && thlds[i]->warning->text) |
588 | strncat(perfstr, thlds[i]->warning->text, sizeof(perfstr)-strlen(perfstr)-1); | ||
585 | } | 589 | } |
586 | 590 | ||
587 | if (critical_thresholds) { | 591 | if (critical_thresholds) { |
588 | if (!warning_thresholds) | 592 | if (!warning_thresholds) |
589 | strncat(perfstr, ";", sizeof(perfstr)-strlen(perfstr)-1); | 593 | strncat(perfstr, ";", sizeof(perfstr)-strlen(perfstr)-1); |
590 | strncat(perfstr, ";", sizeof(perfstr)-strlen(perfstr)-1); | 594 | strncat(perfstr, ";", sizeof(perfstr)-strlen(perfstr)-1); |
591 | strncat(perfstr, critical_thresholds, sizeof(perfstr)-strlen(perfstr)-1); | 595 | if(thlds[i]->critical && thlds[i]->critical->text) |
596 | strncat(perfstr, thlds[i]->critical->text, sizeof(perfstr)-strlen(perfstr)-1); | ||
592 | } | 597 | } |
593 | 598 | ||
594 | strncat(perfstr, " ", sizeof(perfstr)-strlen(perfstr)-1); | 599 | strncat(perfstr, " ", sizeof(perfstr)-strlen(perfstr)-1); |
@@ -1161,7 +1166,7 @@ print_help (void) | |||
1161 | printf ("(%s \"%s\")\n", _("default is") ,DEFAULT_COMMUNITY); | 1166 | printf ("(%s \"%s\")\n", _("default is") ,DEFAULT_COMMUNITY); |
1162 | printf (" %s\n", "-U, --secname=USERNAME"); | 1167 | printf (" %s\n", "-U, --secname=USERNAME"); |
1163 | printf (" %s\n", _("SNMPv3 username")); | 1168 | printf (" %s\n", _("SNMPv3 username")); |
1164 | printf (" %s\n", "-A, --authpassword=PASSWORD"); | 1169 | printf (" %s\n", "-A, --authpasswd=PASSWORD"); |
1165 | printf (" %s\n", _("SNMPv3 authentication password")); | 1170 | printf (" %s\n", _("SNMPv3 authentication password")); |
1166 | printf (" %s\n", "-X, --privpasswd=PASSWORD"); | 1171 | printf (" %s\n", "-X, --privpasswd=PASSWORD"); |
1167 | printf (" %s\n", _("SNMPv3 privacy password")); | 1172 | printf (" %s\n", _("SNMPv3 privacy password")); |
diff --git a/plugins/check_swap.c b/plugins/check_swap.c index 0ff0c77..7da26cf 100644 --- a/plugins/check_swap.c +++ b/plugins/check_swap.c | |||
@@ -34,6 +34,9 @@ const char *email = "devel@monitoring-plugins.org"; | |||
34 | #include "common.h" | 34 | #include "common.h" |
35 | #include "popen.h" | 35 | #include "popen.h" |
36 | #include "utils.h" | 36 | #include "utils.h" |
37 | #include <string.h> | ||
38 | #include <math.h> | ||
39 | #include <libintl.h> | ||
37 | 40 | ||
38 | #ifdef HAVE_DECL_SWAPCTL | 41 | #ifdef HAVE_DECL_SWAPCTL |
39 | # ifdef HAVE_SYS_PARAM_H | 42 | # ifdef HAVE_SYS_PARAM_H |
@@ -51,16 +54,19 @@ const char *email = "devel@monitoring-plugins.org"; | |||
51 | # define SWAP_CONVERSION 1 | 54 | # define SWAP_CONVERSION 1 |
52 | #endif | 55 | #endif |
53 | 56 | ||
54 | int check_swap (int usp, float free_swap_mb, float total_swap_mb); | 57 | typedef struct { |
58 | int is_percentage; | ||
59 | uint64_t value; | ||
60 | } threshold_t; | ||
61 | |||
62 | int check_swap (float free_swap_mb, float total_swap_mb); | ||
55 | int process_arguments (int argc, char **argv); | 63 | int process_arguments (int argc, char **argv); |
56 | int validate_arguments (void); | 64 | int validate_arguments (void); |
57 | void print_usage (void); | 65 | void print_usage (void); |
58 | void print_help (void); | 66 | void print_help (void); |
59 | 67 | ||
60 | int warn_percent = 0; | 68 | threshold_t warn; |
61 | int crit_percent = 0; | 69 | threshold_t crit; |
62 | float warn_size_bytes = 0; | ||
63 | float crit_size_bytes = 0; | ||
64 | int verbose; | 70 | int verbose; |
65 | int allswaps; | 71 | int allswaps; |
66 | int no_swap_state = STATE_CRITICAL; | 72 | int no_swap_state = STATE_CRITICAL; |
@@ -68,9 +74,10 @@ int no_swap_state = STATE_CRITICAL; | |||
68 | int | 74 | int |
69 | main (int argc, char **argv) | 75 | main (int argc, char **argv) |
70 | { | 76 | { |
71 | int percent_used, percent; | 77 | unsigned int percent_used, percent; |
72 | float total_swap_mb = 0, used_swap_mb = 0, free_swap_mb = 0; | 78 | uint64_t total_swap_mb = 0, used_swap_mb = 0, free_swap_mb = 0; |
73 | float dsktotal_mb = 0, dskused_mb = 0, dskfree_mb = 0, tmp_mb = 0; | 79 | uint64_t dsktotal_mb = 0, dskused_mb = 0, dskfree_mb = 0; |
80 | uint64_t tmp_KB = 0; | ||
74 | int result = STATE_UNKNOWN; | 81 | int result = STATE_UNKNOWN; |
75 | char input_buffer[MAX_INPUT_BUFFER]; | 82 | char input_buffer[MAX_INPUT_BUFFER]; |
76 | #ifdef HAVE_PROC_MEMINFO | 83 | #ifdef HAVE_PROC_MEMINFO |
@@ -116,10 +123,15 @@ main (int argc, char **argv) | |||
116 | } | 123 | } |
117 | fp = fopen (PROC_MEMINFO, "r"); | 124 | fp = fopen (PROC_MEMINFO, "r"); |
118 | while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, fp)) { | 125 | while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, fp)) { |
119 | if (sscanf (input_buffer, "%*[S]%*[w]%*[a]%*[p]%*[:] %f %f %f", &dsktotal_mb, &dskused_mb, &dskfree_mb) == 3) { | 126 | /* |
120 | dsktotal_mb = dsktotal_mb / 1048576; /* Apply conversion */ | 127 | * The following sscanf call looks for a line looking like: "Swap: 123 123 123" |
121 | dskused_mb = dskused_mb / 1048576; | 128 | * On which kind of system this format exists, I can not say, but I wanted to |
122 | dskfree_mb = dskfree_mb / 1048576; | 129 | * document this for people who are not adapt with sscanf anymore, like me |
130 | */ | ||
131 | if (sscanf (input_buffer, "%*[S]%*[w]%*[a]%*[p]%*[:] %lu %lu %lu", &dsktotal_mb, &dskused_mb, &dskfree_mb) == 3) { | ||
132 | dsktotal_mb = dsktotal_mb / (1024 * 1024); /* Apply conversion */ | ||
133 | dskused_mb = dskused_mb / (1024 * 1024); | ||
134 | dskfree_mb = dskfree_mb / (1024 * 1024); | ||
123 | total_swap_mb += dsktotal_mb; | 135 | total_swap_mb += dsktotal_mb; |
124 | used_swap_mb += dskused_mb; | 136 | used_swap_mb += dskused_mb; |
125 | free_swap_mb += dskfree_mb; | 137 | free_swap_mb += dskfree_mb; |
@@ -128,21 +140,25 @@ main (int argc, char **argv) | |||
128 | percent=100.0; | 140 | percent=100.0; |
129 | else | 141 | else |
130 | percent = 100 * (((double) dskused_mb) / ((double) dsktotal_mb)); | 142 | percent = 100 * (((double) dskused_mb) / ((double) dsktotal_mb)); |
131 | result = max_state (result, check_swap (percent, dskfree_mb, dsktotal_mb)); | 143 | result = max_state (result, check_swap (dskfree_mb, dsktotal_mb)); |
132 | if (verbose) | 144 | if (verbose) |
133 | xasprintf (&status, "%s [%.0f (%d%%)]", status, dskfree_mb, 100 - percent); | 145 | xasprintf (&status, "%s [%lu (%d%%)]", status, dskfree_mb, 100 - percent); |
134 | } | 146 | } |
135 | } | 147 | } |
136 | else if (sscanf (input_buffer, "%*[S]%*[w]%*[a]%*[p]%[TotalFre]%*[:] %f %*[k]%*[B]", str, &tmp_mb)) { | 148 | /* |
149 | * The following sscanf call looks for lines looking like: "SwapTotal: 123" and "SwapFree: 123" | ||
150 | * This format exists at least on Debian Linux with a 5.* kernel | ||
151 | */ | ||
152 | else if (sscanf (input_buffer, "%*[S]%*[w]%*[a]%*[p]%[TotalFre]%*[:] %lu %*[k]%*[B]", str, &tmp_KB)) { | ||
137 | if (verbose >= 3) { | 153 | if (verbose >= 3) { |
138 | printf("Got %s with %f\n", str, tmp_mb); | 154 | printf("Got %s with %lu\n", str, tmp_KB); |
139 | } | 155 | } |
140 | /* I think this part is always in Kb, so convert to mb */ | 156 | /* I think this part is always in Kb, so convert to mb */ |
141 | if (strcmp ("Total", str) == 0) { | 157 | if (strcmp ("Total", str) == 0) { |
142 | dsktotal_mb = tmp_mb / 1024; | 158 | dsktotal_mb = tmp_KB / 1024; |
143 | } | 159 | } |
144 | else if (strcmp ("Free", str) == 0) { | 160 | else if (strcmp ("Free", str) == 0) { |
145 | dskfree_mb = tmp_mb / 1024; | 161 | dskfree_mb = tmp_KB / 1024; |
146 | } | 162 | } |
147 | } | 163 | } |
148 | } | 164 | } |
@@ -227,7 +243,7 @@ main (int argc, char **argv) | |||
227 | free_swap_mb += dskfree_mb; | 243 | free_swap_mb += dskfree_mb; |
228 | if (allswaps) { | 244 | if (allswaps) { |
229 | percent = 100 * (((double) dskused_mb) / ((double) dsktotal_mb)); | 245 | percent = 100 * (((double) dskused_mb) / ((double) dsktotal_mb)); |
230 | result = max_state (result, check_swap (percent, dskfree_mb, dsktotal_mb)); | 246 | result = max_state (result, check_swap (dskfree_mb, dsktotal_mb)); |
231 | if (verbose) | 247 | if (verbose) |
232 | xasprintf (&status, "%s [%.0f (%d%%)]", status, dskfree_mb, 100 - percent); | 248 | xasprintf (&status, "%s [%.0f (%d%%)]", status, dskfree_mb, 100 - percent); |
233 | } | 249 | } |
@@ -289,7 +305,7 @@ main (int argc, char **argv) | |||
289 | 305 | ||
290 | if(allswaps && dsktotal_mb > 0){ | 306 | if(allswaps && dsktotal_mb > 0){ |
291 | percent = 100 * (((double) dskused_mb) / ((double) dsktotal_mb)); | 307 | percent = 100 * (((double) dskused_mb) / ((double) dsktotal_mb)); |
292 | result = max_state (result, check_swap (percent, dskfree_mb, dsktotal_mb)); | 308 | result = max_state (result, check_swap (dskfree_mb, dsktotal_mb)); |
293 | if (verbose) { | 309 | if (verbose) { |
294 | xasprintf (&status, "%s [%.0f (%d%%)]", status, dskfree_mb, 100 - percent); | 310 | xasprintf (&status, "%s [%.0f (%d%%)]", status, dskfree_mb, 100 - percent); |
295 | } | 311 | } |
@@ -328,7 +344,7 @@ main (int argc, char **argv) | |||
328 | 344 | ||
329 | if(allswaps && dsktotal_mb > 0){ | 345 | if(allswaps && dsktotal_mb > 0){ |
330 | percent = 100 * (((double) dskused_mb) / ((double) dsktotal_mb)); | 346 | percent = 100 * (((double) dskused_mb) / ((double) dsktotal_mb)); |
331 | result = max_state (result, check_swap (percent, dskfree_mb, dsktotal_mb)); | 347 | result = max_state (result, check_swap(dskfree_mb, dsktotal_mb)); |
332 | if (verbose) { | 348 | if (verbose) { |
333 | xasprintf (&status, "%s [%.0f (%d%%)]", status, dskfree_mb, 100 - percent); | 349 | xasprintf (&status, "%s [%.0f (%d%%)]", status, dskfree_mb, 100 - percent); |
334 | } | 350 | } |
@@ -355,14 +371,19 @@ main (int argc, char **argv) | |||
355 | status = "- Swap is either disabled, not present, or of zero size. "; | 371 | status = "- Swap is either disabled, not present, or of zero size. "; |
356 | } | 372 | } |
357 | 373 | ||
358 | result = max_state (result, check_swap (percent_used, free_swap_mb, total_swap_mb)); | 374 | result = max_state (result, check_swap(free_swap_mb, total_swap_mb)); |
359 | printf (_("SWAP %s - %d%% free (%d MB out of %d MB) %s|"), | 375 | printf (_("SWAP %s - %d%% free (%dMB out of %dMB) %s|"), |
360 | state_text (result), | 376 | state_text (result), |
361 | (100 - percent_used), (int) free_swap_mb, (int) total_swap_mb, status); | 377 | (100 - percent_used), (int) free_swap_mb, (int) total_swap_mb, status); |
362 | 378 | ||
363 | puts (perfdata ("swap", (long) free_swap_mb, "MB", | 379 | uint64_t warn_print = warn.value; |
364 | TRUE, (long) max (warn_size_bytes/(1024 * 1024), warn_percent/100.0*total_swap_mb), | 380 | if (warn.is_percentage) warn_print = warn.value * (total_swap_mb *1024 *1024/100); |
365 | TRUE, (long) max (crit_size_bytes/(1024 * 1024), crit_percent/100.0*total_swap_mb), | 381 | uint64_t crit_print = crit.value; |
382 | if (crit.is_percentage) crit_print = crit.value * (total_swap_mb *1024 *1024/100); | ||
383 | |||
384 | puts (perfdata_uint64 ("swap", free_swap_mb *1024 *1024, "B", | ||
385 | TRUE, warn_print, | ||
386 | TRUE, crit_print, | ||
366 | TRUE, 0, | 387 | TRUE, 0, |
367 | TRUE, (long) total_swap_mb)); | 388 | TRUE, (long) total_swap_mb)); |
368 | 389 | ||
@@ -370,26 +391,37 @@ main (int argc, char **argv) | |||
370 | } | 391 | } |
371 | 392 | ||
372 | 393 | ||
373 | |||
374 | int | 394 | int |
375 | check_swap (int usp, float free_swap_mb, float total_swap_mb) | 395 | check_swap(float free_swap_mb, float total_swap_mb) |
376 | { | 396 | { |
377 | 397 | ||
378 | if (!total_swap_mb) return no_swap_state; | 398 | if (!total_swap_mb) return no_swap_state; |
379 | 399 | ||
380 | int result = STATE_UNKNOWN; | 400 | uint64_t free_swap = free_swap_mb * (1024 * 1024); /* Convert back to bytes as warn and crit specified in bytes */ |
381 | float free_swap = free_swap_mb * (1024 * 1024); /* Convert back to bytes as warn and crit specified in bytes */ | 401 | |
382 | if (usp >= 0 && crit_percent != 0 && usp >= (100.0 - crit_percent)) | 402 | if (!crit.is_percentage && crit.value >= free_swap) return STATE_CRITICAL; |
383 | result = STATE_CRITICAL; | 403 | if (!warn.is_percentage && warn.value >= free_swap) return STATE_WARNING; |
384 | else if (crit_size_bytes > 0 && free_swap <= crit_size_bytes) | 404 | |
385 | result = STATE_CRITICAL; | 405 | |
386 | else if (usp >= 0 && warn_percent != 0 && usp >= (100.0 - warn_percent)) | 406 | uint64_t usage_percentage = ((total_swap_mb - free_swap_mb) / total_swap_mb) * 100; |
387 | result = STATE_WARNING; | 407 | |
388 | else if (warn_size_bytes > 0 && free_swap <= warn_size_bytes) | 408 | if (crit.is_percentage && |
389 | result = STATE_WARNING; | 409 | usage_percentage >= 0 && |
390 | else if (usp >= 0.0) | 410 | crit.value != 0 && |
391 | result = STATE_OK; | 411 | usage_percentage >= (100 - crit.value)) |
392 | return result; | 412 | { |
413 | return STATE_CRITICAL; | ||
414 | } | ||
415 | |||
416 | if (warn.is_percentage && | ||
417 | usage_percentage >= 0 && | ||
418 | warn.value != 0 && | ||
419 | usage_percentage >= (100 - warn.value)) | ||
420 | { | ||
421 | return STATE_WARNING; | ||
422 | } | ||
423 | |||
424 | return STATE_OK; | ||
393 | } | 425 | } |
394 | 426 | ||
395 | 427 | ||
@@ -422,42 +454,68 @@ process_arguments (int argc, char **argv) | |||
422 | break; | 454 | break; |
423 | 455 | ||
424 | switch (c) { | 456 | switch (c) { |
425 | case 'w': /* warning size threshold */ | 457 | case 'w': /* warning size threshold */ |
426 | if (is_intnonneg (optarg)) { | 458 | { |
427 | warn_size_bytes = (float) atoi (optarg); | 459 | /* |
428 | break; | 460 | * We expect either a positive integer value without a unit, which means |
429 | } | 461 | * the unit is Bytes or a positive integer value and a percentage sign (%), |
430 | else if (strstr (optarg, ",") && | 462 | * which means the value must be with 0 and 100 and is relative to the total swap |
431 | strstr (optarg, "%") && | 463 | */ |
432 | sscanf (optarg, "%f,%d%%", &warn_size_bytes, &warn_percent) == 2) { | 464 | size_t length; |
433 | warn_size_bytes = floorf(warn_size_bytes); | 465 | length = strlen(optarg); |
434 | break; | 466 | |
435 | } | 467 | if (optarg[length - 1] == '%') { |
436 | else if (strstr (optarg, "%") && | 468 | /* It's percentage */ |
437 | sscanf (optarg, "%d%%", &warn_percent) == 1) { | 469 | warn.is_percentage = 1; |
438 | break; | 470 | optarg[length - 1] = '\0'; |
439 | } | 471 | if (is_uint64(optarg, &warn.value)) { |
440 | else { | 472 | if (warn.value > 100) { |
441 | usage4 (_("Warning threshold must be integer or percentage!")); | 473 | usage4 (_("Warning threshold percentage must be <= 100!")); |
442 | } | 474 | } else { |
443 | case 'c': /* critical size threshold */ | 475 | break; |
444 | if (is_intnonneg (optarg)) { | 476 | } |
445 | crit_size_bytes = (float) atoi (optarg); | 477 | } |
446 | break; | 478 | } else { |
447 | } | 479 | /* It's Bytes */ |
448 | else if (strstr (optarg, ",") && | 480 | warn.is_percentage = 0; |
449 | strstr (optarg, "%") && | 481 | if (is_uint64(optarg, &warn.value)) { |
450 | sscanf (optarg, "%f,%d%%", &crit_size_bytes, &crit_percent) == 2) { | 482 | break; |
451 | crit_size_bytes = floorf(crit_size_bytes); | 483 | } else { |
452 | break; | 484 | usage4 (_("Warning threshold be positive integer or percentage!")); |
453 | } | 485 | } |
454 | else if (strstr (optarg, "%") && | 486 | } |
455 | sscanf (optarg, "%d%%", &crit_percent) == 1) { | ||
456 | break; | ||
457 | } | ||
458 | else { | ||
459 | usage4 (_("Critical threshold must be integer or percentage!")); | ||
460 | } | 487 | } |
488 | case 'c': /* critical size threshold */ | ||
489 | { | ||
490 | /* | ||
491 | * We expect either a positive integer value without a unit, which means | ||
492 | * the unit is Bytes or a positive integer value and a percentage sign (%), | ||
493 | * which means the value must be with 0 and 100 and is relative to the total swap | ||
494 | */ | ||
495 | size_t length; | ||
496 | length = strlen(optarg); | ||
497 | |||
498 | if (optarg[length - 1] == '%') { | ||
499 | /* It's percentage */ | ||
500 | crit.is_percentage = 1; | ||
501 | optarg[length - 1] = '\0'; | ||
502 | if (is_uint64(optarg, &crit.value)) { | ||
503 | if (crit.value> 100) { | ||
504 | usage4 (_("Critical threshold percentage must be <= 100!")); | ||
505 | } else { | ||
506 | break; | ||
507 | } | ||
508 | } | ||
509 | } else { | ||
510 | /* It's Bytes */ | ||
511 | crit.is_percentage = 0; | ||
512 | if (is_uint64(optarg, &crit.value)) { | ||
513 | break; | ||
514 | } else { | ||
515 | usage4 (_("Critical threshold be positive integer or percentage!")); | ||
516 | } | ||
517 | } | ||
518 | } | ||
461 | case 'a': /* all swap */ | 519 | case 'a': /* all swap */ |
462 | allswaps = TRUE; | 520 | allswaps = TRUE; |
463 | break; | 521 | break; |
@@ -482,23 +540,6 @@ process_arguments (int argc, char **argv) | |||
482 | c = optind; | 540 | c = optind; |
483 | if (c == argc) | 541 | if (c == argc) |
484 | return validate_arguments (); | 542 | return validate_arguments (); |
485 | if (warn_percent == 0 && is_intnonneg (argv[c])) | ||
486 | warn_percent = atoi (argv[c++]); | ||
487 | |||
488 | if (c == argc) | ||
489 | return validate_arguments (); | ||
490 | if (crit_percent == 0 && is_intnonneg (argv[c])) | ||
491 | crit_percent = atoi (argv[c++]); | ||
492 | |||
493 | if (c == argc) | ||
494 | return validate_arguments (); | ||
495 | if (warn_size_bytes == 0 && is_intnonneg (argv[c])) | ||
496 | warn_size_bytes = (float) atoi (argv[c++]); | ||
497 | |||
498 | if (c == argc) | ||
499 | return validate_arguments (); | ||
500 | if (crit_size_bytes == 0 && is_intnonneg (argv[c])) | ||
501 | crit_size_bytes = (float) atoi (argv[c++]); | ||
502 | 543 | ||
503 | return validate_arguments (); | 544 | return validate_arguments (); |
504 | } | 545 | } |
@@ -508,17 +549,15 @@ process_arguments (int argc, char **argv) | |||
508 | int | 549 | int |
509 | validate_arguments (void) | 550 | validate_arguments (void) |
510 | { | 551 | { |
511 | if (warn_percent == 0 && crit_percent == 0 && warn_size_bytes == 0 | 552 | if (warn.value == 0 && crit.value == 0) { |
512 | && crit_size_bytes == 0) { | ||
513 | return ERROR; | 553 | return ERROR; |
514 | } | 554 | } |
515 | else if (warn_percent < crit_percent) { | 555 | else if ((warn.is_percentage == crit.is_percentage) && (warn.value < crit.value)) { |
516 | usage4 | 556 | /* This is NOT triggered if warn and crit are different units, e.g warn is percentage |
517 | (_("Warning percentage should be more than critical percentage")); | 557 | * and crit is absolut. We cannot determine the condition at this point since we |
518 | } | 558 | * dont know the value of total swap yet |
519 | else if (warn_size_bytes < crit_size_bytes) { | 559 | */ |
520 | usage4 | 560 | usage4(_("Warning should be more than critical")); |
521 | (_("Warning free space should be more than critical free space")); | ||
522 | } | 561 | } |
523 | return OK; | 562 | return OK; |
524 | } | 563 | } |
@@ -534,7 +573,7 @@ print_help (void) | |||
534 | 573 | ||
535 | printf ("%s\n", _("Check swap space on local machine.")); | 574 | printf ("%s\n", _("Check swap space on local machine.")); |
536 | 575 | ||
537 | printf ("\n\n"); | 576 | printf ("\n\n"); |
538 | 577 | ||
539 | print_usage (); | 578 | print_usage (); |
540 | 579 | ||
@@ -542,33 +581,32 @@ print_help (void) | |||
542 | printf (UT_EXTRA_OPTS); | 581 | printf (UT_EXTRA_OPTS); |
543 | 582 | ||
544 | printf (" %s\n", "-w, --warning=INTEGER"); | 583 | printf (" %s\n", "-w, --warning=INTEGER"); |
545 | printf (" %s\n", _("Exit with WARNING status if less than INTEGER bytes of swap space are free")); | 584 | printf (" %s\n", _("Exit with WARNING status if less than INTEGER bytes of swap space are free")); |
546 | printf (" %s\n", "-w, --warning=PERCENT%%"); | 585 | printf (" %s\n", "-w, --warning=PERCENT%"); |
547 | printf (" %s\n", _("Exit with WARNING status if less than PERCENT of swap space is free")); | 586 | printf (" %s\n", _("Exit with WARNING status if less than PERCENT of swap space is free")); |
548 | printf (" %s\n", "-c, --critical=INTEGER"); | 587 | printf (" %s\n", "-c, --critical=INTEGER"); |
549 | printf (" %s\n", _("Exit with CRITICAL status if less than INTEGER bytes of swap space are free")); | 588 | printf (" %s\n", _("Exit with CRITICAL status if less than INTEGER bytes of swap space are free")); |
550 | printf (" %s\n", "-c, --critical=PERCENT%%"); | 589 | printf (" %s\n", "-c, --critical=PERCENT%"); |
551 | printf (" %s\n", _("Exit with CRITICAL status if less than PERCENT of swap space is free")); | 590 | printf (" %s\n", _("Exit with CRITICAL status if less than PERCENT of swap space is free")); |
552 | printf (" %s\n", "-a, --allswaps"); | 591 | printf (" %s\n", "-a, --allswaps"); |
553 | printf (" %s\n", _("Conduct comparisons for all swap partitions, one by one")); | 592 | printf (" %s\n", _("Conduct comparisons for all swap partitions, one by one")); |
554 | printf (" %s\n", "-n, --no-swap=<ok|warning|critical|unknown>"); | 593 | printf (" %s\n", "-n, --no-swap=<ok|warning|critical|unknown>"); |
555 | printf (" %s %s\n", _("Resulting state when there is no swap regardless of thresholds. Default:"), state_text(no_swap_state)); | 594 | printf (" %s %s\n", _("Resulting state when there is no swap regardless of thresholds. Default:"), state_text(no_swap_state)); |
556 | printf (UT_VERBOSE); | 595 | printf (UT_VERBOSE); |
557 | 596 | ||
558 | printf ("\n"); | 597 | printf ("\n"); |
559 | printf ("%s\n", _("Notes:")); | 598 | printf ("%s\n", _("Notes:")); |
560 | printf (" %s\n", _("Both INTEGER and PERCENT thresholds can be specified, they are all checked.")); | 599 | printf (" %s\n", _("Both INTEGER and PERCENT thresholds can be specified, they are all checked.")); |
561 | printf (" %s\n", _("On AIX, if -a is specified, uses lsps -a, otherwise uses lsps -s.")); | 600 | printf (" %s\n", _("On AIX, if -a is specified, uses lsps -a, otherwise uses lsps -s.")); |
562 | 601 | ||
563 | printf (UT_SUPPORT); | 602 | printf (UT_SUPPORT); |
564 | } | 603 | } |
565 | 604 | ||
566 | 605 | ||
567 | |||
568 | void | 606 | void |
569 | print_usage (void) | 607 | print_usage (void) |
570 | { | 608 | { |
571 | printf ("%s\n", _("Usage:")); | 609 | printf ("%s\n", _("Usage:")); |
572 | printf (" %s [-av] -w <percent_free>%% -c <percent_free>%%\n",progname); | 610 | printf (" %s [-av] -w <percent_free>%% -c <percent_free>%%\n",progname); |
573 | printf (" -w <bytes_free> -c <bytes_free> [-n <state>]\n"); | 611 | printf (" -w <bytes_free> -c <bytes_free> [-n <state>]\n"); |
574 | } | 612 | } |
diff --git a/plugins/check_ups.c b/plugins/check_ups.c index e9e56a5..0de37a2 100644 --- a/plugins/check_ups.c +++ b/plugins/check_ups.c | |||
@@ -402,7 +402,10 @@ get_ups_variable (const char *varname, char *buf, size_t buflen) | |||
402 | 402 | ||
403 | /* create the command string to send to the UPS daemon */ | 403 | /* create the command string to send to the UPS daemon */ |
404 | /* Add LOGOUT to avoid read failure logs */ | 404 | /* Add LOGOUT to avoid read failure logs */ |
405 | sprintf (send_buffer, "GET VAR %s %s\nLOGOUT\n", ups_name, varname); | 405 | if (snprintf (send_buffer, sizeof(send_buffer), "GET VAR %s %s\nLOGOUT\n", ups_name, varname) >= sizeof(send_buffer)) { |
406 | printf("%s\n", _("UPS name to long for buffer")); | ||
407 | return ERROR; | ||
408 | } | ||
406 | 409 | ||
407 | /* send the command to the daemon and get a response back */ | 410 | /* send the command to the daemon and get a response back */ |
408 | if (process_tcp_request | 411 | if (process_tcp_request |
diff --git a/plugins/t/check_curl.t b/plugins/t/check_curl.t index 45ee533..ada6a04 100644 --- a/plugins/t/check_curl.t +++ b/plugins/t/check_curl.t | |||
@@ -95,7 +95,7 @@ SKIP: { | |||
95 | $res = NPTest->testCmd("./$plugin -v -H $host_tls_http:443 -S -p 443"); | 95 | $res = NPTest->testCmd("./$plugin -v -H $host_tls_http:443 -S -p 443"); |
96 | like( $res->output, '/^Host: '.$host_tls_http.'\s*$/ms', "Host Header OK" ); | 96 | like( $res->output, '/^Host: '.$host_tls_http.'\s*$/ms', "Host Header OK" ); |
97 | 97 | ||
98 | $res = NPTest->testCmd("./$plugin -v -H $host_tls_http -D -p 443"); | 98 | $res = NPTest->testCmd("./$plugin -v -H $host_tls_http -D -S -p 443"); |
99 | like( $res->output, '/(^Host: '.$host_tls_http.'\s*$)|(cURL returned 60)/ms', "Host Header OK" ); | 99 | like( $res->output, '/(^Host: '.$host_tls_http.'\s*$)|(cURL returned 60)/ms', "Host Header OK" ); |
100 | }; | 100 | }; |
101 | 101 | ||
diff --git a/plugins/t/check_disk.t b/plugins/t/check_disk.t index fdd8769..ec527e7 100644 --- a/plugins/t/check_disk.t +++ b/plugins/t/check_disk.t | |||
@@ -88,8 +88,9 @@ $result = NPTest->testCmd( | |||
88 | ); | 88 | ); |
89 | $_ = $result->perf_output; | 89 | $_ = $result->perf_output; |
90 | my ($warn_absth_data, $crit_absth_data, $total_absth_data) = (m/=.[^;]*;(\d+);(\d+);\d+;(\d+)/); | 90 | my ($warn_absth_data, $crit_absth_data, $total_absth_data) = (m/=.[^;]*;(\d+);(\d+);\d+;(\d+)/); |
91 | is ($warn_absth_data, $total_absth_data - 20, "Wrong warning in perf data using absolute thresholds"); | 91 | # default unit is MiB, but perfdata is always bytes |
92 | is ($crit_absth_data, $total_absth_data - 10, "Wrong critical in perf data using absolute thresholds"); | 92 | is ($warn_absth_data, $total_absth_data - (20 * (2 ** 20)), "Wrong warning in perf data using absolute thresholds"); |
93 | is ($crit_absth_data, $total_absth_data - (10 * (2 ** 20)), "Wrong critical in perf data using absolute thresholds"); | ||
93 | 94 | ||
94 | # Then check percent thresholds. | 95 | # Then check percent thresholds. |
95 | $result = NPTest->testCmd( | 96 | $result = NPTest->testCmd( |
@@ -119,7 +120,7 @@ like ( $result->only_output, qr/$more_free/, "Have disk name in text"); | |||
119 | $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" ); |
120 | 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"); |
121 | $_ = $result->output; | 122 | $_ = $result->output; |
122 | my ($free_mb_on_mp1, $free_mb_on_mp2) = (m/(\d+) MB .* (\d+) MB /g); | 123 | my ($free_mb_on_mp1, $free_mb_on_mp2) = (m/(\d+)MiB .* (\d+)MiB /g); |
123 | my $free_mb_on_all = $free_mb_on_mp1 + $free_mb_on_mp2; | 124 | my $free_mb_on_all = $free_mb_on_mp1 + $free_mb_on_mp2; |
124 | 125 | ||
125 | 126 | ||
diff --git a/plugins/t/check_dns.t b/plugins/t/check_dns.t index cdfbe60..afb2062 100644 --- a/plugins/t/check_dns.t +++ b/plugins/t/check_dns.t | |||
@@ -10,7 +10,7 @@ use NPTest; | |||
10 | 10 | ||
11 | plan skip_all => "check_dns not compiled" unless (-x "check_dns"); | 11 | plan skip_all => "check_dns not compiled" unless (-x "check_dns"); |
12 | 12 | ||
13 | plan tests => 19; | 13 | plan tests => 23; |
14 | 14 | ||
15 | my $successOutput = '/DNS OK: [\.0-9]+ seconds? response time/'; | 15 | my $successOutput = '/DNS OK: [\.0-9]+ seconds? response time/'; |
16 | 16 | ||
@@ -105,3 +105,11 @@ cmp_ok( $res->return_code, '==', 0, "Got expected address"); | |||
105 | $res = NPTest->testCmd("./check_dns -H $hostname_valid -a $hostname_invalid_cidr -t 5"); | 105 | $res = NPTest->testCmd("./check_dns -H $hostname_valid -a $hostname_invalid_cidr -t 5"); |
106 | cmp_ok( $res->return_code, '==', 2, "Got wrong address"); | 106 | cmp_ok( $res->return_code, '==', 2, "Got wrong address"); |
107 | like ( $res->output, "/^DNS CRITICAL.*expected '$hostname_invalid_cidr' but got '$hostname_valid_ip'".'$/', "Output OK"); | 107 | like ( $res->output, "/^DNS CRITICAL.*expected '$hostname_invalid_cidr' but got '$hostname_valid_ip'".'$/', "Output OK"); |
108 | |||
109 | $res = NPTest->testCmd("./check_dns -H $hostname_valid -n"); | ||
110 | cmp_ok( $res->return_code, '==', 2, "Found $hostname_valid"); | ||
111 | like ( $res->output, "/^DNS CRITICAL.*Domain '$hostname_valid' was found by the server:/", "Output OK"); | ||
112 | |||
113 | $res = NPTest->testCmd("./check_dns -H $hostname_invalid -n"); | ||
114 | cmp_ok( $res->return_code, '==', 0, "Did not find $hostname_invalid"); | ||
115 | like ( $res->output, $successOutput, "Output OK" ); | ||
diff --git a/plugins/t/check_load.t b/plugins/t/check_load.t index 55f6f75..60837ef 100644 --- a/plugins/t/check_load.t +++ b/plugins/t/check_load.t | |||
@@ -11,8 +11,8 @@ use NPTest; | |||
11 | my $res; | 11 | my $res; |
12 | 12 | ||
13 | my $loadValue = "[0-9]+\.?[0-9]+"; | 13 | my $loadValue = "[0-9]+\.?[0-9]+"; |
14 | my $successOutput = "/^OK - load average: $loadValue, $loadValue, $loadValue/"; | 14 | my $successOutput = "/^LOAD OK - load average: $loadValue, $loadValue, $loadValue/"; |
15 | my $failureOutput = "/^CRITICAL - load average: $loadValue, $loadValue, $loadValue/"; | 15 | my $failureOutput = "/^LOAD CRITICAL - load average: $loadValue, $loadValue, $loadValue/"; |
16 | 16 | ||
17 | plan tests => 11; | 17 | plan tests => 11; |
18 | 18 | ||
diff --git a/plugins/t/check_swap.t b/plugins/t/check_swap.t index e44adc9..de9e0f0 100644 --- a/plugins/t/check_swap.t +++ b/plugins/t/check_swap.t | |||
@@ -8,9 +8,9 @@ use strict; | |||
8 | use Test::More tests => 8; | 8 | use Test::More tests => 8; |
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\)/'; |
12 | my $failureOutput = '/^SWAP CRITICAL - [0-9]+\% free \([0-9]+ MB out of [0-9]+ MB\)/'; | 12 | my $failureOutput = '/^SWAP CRITICAL - [0-9]+\% free \([0-9]+MB out of [0-9]+MB\)/'; |
13 | my $warnOutput = '/^SWAP WARNING - [0-9]+\% free \([0-9]+ MB out of [0-9]+ MB\)/'; | 13 | 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 | ||
diff --git a/plugins/tests/check_procs.t b/plugins/tests/check_procs.t index 54d43d9..3af218f 100755 --- a/plugins/tests/check_procs.t +++ b/plugins/tests/check_procs.t | |||
@@ -8,13 +8,14 @@ use Test::More; | |||
8 | use NPTest; | 8 | use NPTest; |
9 | 9 | ||
10 | if (-x "./check_procs") { | 10 | if (-x "./check_procs") { |
11 | plan tests => 50; | 11 | plan tests => 52; |
12 | } else { | 12 | } else { |
13 | plan skip_all => "No check_procs compiled"; | 13 | plan skip_all => "No check_procs compiled"; |
14 | } | 14 | } |
15 | 15 | ||
16 | my $result; | 16 | my $result; |
17 | my $command = "./check_procs --input-file=tests/var/ps-axwo.darwin"; | 17 | my $command = "./check_procs --input-file=tests/var/ps-axwo.darwin"; |
18 | my $cmd_etime = "./check_procs --input-file=tests/var/ps-axwo.debian"; | ||
18 | 19 | ||
19 | $result = NPTest->testCmd( "$command" ); | 20 | $result = NPTest->testCmd( "$command" ); |
20 | is( $result->return_code, 0, "Run with no options" ); | 21 | is( $result->return_code, 0, "Run with no options" ); |
@@ -69,9 +70,21 @@ SKIP: { | |||
69 | like( $result->output, '/^PROCS OK: 0 processes with UID = -2 \(nobody\), args \'UsB\'/', "Output correct" ); | 70 | like( $result->output, '/^PROCS OK: 0 processes with UID = -2 \(nobody\), args \'UsB\'/', "Output correct" ); |
70 | }; | 71 | }; |
71 | 72 | ||
72 | $result = NPTest->testCmd( "$command --ereg-argument-array='mdworker.*501'" ); | 73 | SKIP: { |
73 | is( $result->return_code, 0, "Checking regexp search of arguments" ); | 74 | skip 'check_procs is compiled with etime format support', 2 if `$command -vvv` =~ m/etime/mx; |
74 | is( $result->output, "PROCS OK: 1 process with regex args 'mdworker.*501' | procs=1;;;0;", "Output correct" ); | 75 | |
76 | $result = NPTest->testCmd( "$command --ereg-argument-array='mdworker.*501'" ); | ||
77 | is( $result->return_code, 0, "Checking regexp search of arguments" ); | ||
78 | is( $result->output, "PROCS OK: 1 process with regex args 'mdworker.*501' | procs=1;;;0;", "Output correct" ); | ||
79 | } | ||
80 | |||
81 | SKIP: { | ||
82 | skip 'check_procs is compiled without etime format support', 2 if `$cmd_etime -vvv` !~ m/etime/mx; | ||
83 | |||
84 | $result = NPTest->testCmd( "$cmd_etime -m ELAPSED -C apache2 -w 1000 -c 2000" ); | ||
85 | is( $result->return_code, 2, "Checking elapsed time threshold" ); | ||
86 | is( $result->output, "ELAPSED CRITICAL: 10 crit, 0 warn out of 10 processes with command name 'apache2' | procs=10;;;0; procs_warn=0;;;0; procs_crit=10;;;0;", "Output correct" ); | ||
87 | } | ||
75 | 88 | ||
76 | $result = NPTest->testCmd( "$command --vsz 1000000" ); | 89 | $result = NPTest->testCmd( "$command --vsz 1000000" ); |
77 | is( $result->return_code, 0, "Checking filter by VSZ" ); | 90 | is( $result->return_code, 0, "Checking filter by VSZ" ); |
@@ -83,7 +96,7 @@ is( $result->output, 'PROCS OK: 3 processes with RSS >= 100000 | procs=3;;;0;', | |||
83 | 96 | ||
84 | $result = NPTest->testCmd( "$command -s S" ); | 97 | $result = NPTest->testCmd( "$command -s S" ); |
85 | is( $result->return_code, 0, "Checking filter for sleeping processes" ); | 98 | is( $result->return_code, 0, "Checking filter for sleeping processes" ); |
86 | like( $result->output, '/^PROCS OK: 44 processes with STATE = S/', "Output correct" ); | 99 | like( $result->output, '/^PROCS OK: 88 processes with STATE = S/', "Output correct" ); |
87 | 100 | ||
88 | $result = NPTest->testCmd( "$command -s Z" ); | 101 | $result = NPTest->testCmd( "$command -s Z" ); |
89 | is( $result->return_code, 0, "Checking filter for zombies" ); | 102 | is( $result->return_code, 0, "Checking filter for zombies" ); |
@@ -129,4 +142,3 @@ is( $result->output, 'RSS CRITICAL: 5 crit, 0 warn out of 95 processes [WindowSe | |||
129 | $result = NPTest->testCmd( "$command --ereg-argument-array='(nosuchname|nosuch2name)'" ); | 142 | $result = NPTest->testCmd( "$command --ereg-argument-array='(nosuchname|nosuch2name)'" ); |
130 | is( $result->return_code, 0, "Checking no pipe symbol in output" ); | 143 | is( $result->return_code, 0, "Checking no pipe symbol in output" ); |
131 | is( $result->output, "PROCS OK: 0 processes with regex args '(nosuchname,nosuch2name)' | procs=0;;;0;", "Output correct" ); | 144 | is( $result->output, "PROCS OK: 0 processes with regex args '(nosuchname,nosuch2name)' | procs=0;;;0;", "Output correct" ); |
132 | |||
diff --git a/plugins/tests/check_snmp.t b/plugins/tests/check_snmp.t index 85d6bf5..0a77fa8 100755 --- a/plugins/tests/check_snmp.t +++ b/plugins/tests/check_snmp.t | |||
@@ -9,7 +9,7 @@ use NPTest; | |||
9 | use FindBin qw($Bin); | 9 | use FindBin qw($Bin); |
10 | use POSIX qw/strftime/; | 10 | use POSIX qw/strftime/; |
11 | 11 | ||
12 | my $tests = 67; | 12 | my $tests = 73; |
13 | # Check that all dependent modules are available | 13 | # Check that all dependent modules are available |
14 | eval { | 14 | eval { |
15 | require NetSNMP::OID; | 15 | require NetSNMP::OID; |
@@ -251,9 +251,20 @@ is($res->output, 'SNMP CRITICAL - *-4* | iso.3.6.1.4.1.8072.3.2.67.17=-4;-2:;-3: | |||
251 | 251 | ||
252 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.18 -c '~:-6.5'" ); | 252 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.18 -c '~:-6.5'" ); |
253 | is($res->return_code, 0, "Negative float OK" ); | 253 | is($res->return_code, 0, "Negative float OK" ); |
254 | is($res->output, 'SNMP OK - -6.6 | iso.3.6.1.4.1.8072.3.2.67.18=-6.6;;~:-6.5 ', "Negative float OK output" ); | 254 | is($res->output, 'SNMP OK - -6.6 | iso.3.6.1.4.1.8072.3.2.67.18=-6.6;;@-6.5:~ ', "Negative float OK output" ); |
255 | 255 | ||
256 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.18 -w '~:-6.65' -c '~:-6.55'" ); | 256 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.18 -w '~:-6.65' -c '~:-6.55'" ); |
257 | is($res->return_code, 1, "Negative float WARNING" ); | 257 | is($res->return_code, 1, "Negative float WARNING" ); |
258 | is($res->output, 'SNMP WARNING - *-6.6* | iso.3.6.1.4.1.8072.3.2.67.18=-6.6;~:-6.65;~:-6.55 ', "Negative float WARNING output" ); | 258 | is($res->output, 'SNMP WARNING - *-6.6* | iso.3.6.1.4.1.8072.3.2.67.18=-6.6;@-6.65:~;@-6.55:~ ', "Negative float WARNING output" ); |
259 | 259 | ||
260 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10,.1.3.6.1.4.1.8072.3.2.67.17 -w '1:100000,-10:20' -c '2:200000,-20:30'" ); | ||
261 | is($res->return_code, 0, "Multiple OIDs with thresholds" ); | ||
262 | like($res->output, '/SNMP OK - \d+ -4 | iso.3.6.1.4.1.8072.3.2.67.10=\d+c;1:100000;2:200000 iso.3.6.1.4.1.8072.3.2.67.17=-4;-10:20;-20:30/', "Multiple OIDs with thresholds output" ); | ||
263 | |||
264 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10,.1.3.6.1.4.1.8072.3.2.67.17 -w '1:100000,-1:2' -c '2:200000,-20:30'" ); | ||
265 | is($res->return_code, 1, "Multiple OIDs with thresholds" ); | ||
266 | like($res->output, '/SNMP WARNING - \d+ \*-4\* | iso.3.6.1.4.1.8072.3.2.67.10=\d+c;1:100000;2:200000 iso.3.6.1.4.1.8072.3.2.67.17=-4;-10:20;-20:30/', "Multiple OIDs with thresholds output" ); | ||
267 | |||
268 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10,.1.3.6.1.4.1.8072.3.2.67.17 -w 1,2 -c 1" ); | ||
269 | is($res->return_code, 2, "Multiple OIDs with some thresholds" ); | ||
270 | like($res->output, '/SNMP CRITICAL - \*\d+\* \*-4\* | iso.3.6.1.4.1.8072.3.2.67.10=\d+c;1;2 iso.3.6.1.4.1.8072.3.2.67.17=-4;;/', "Multiple OIDs with thresholds output" ); | ||
diff --git a/plugins/tests/var/ps-axwo.debian b/plugins/tests/var/ps-axwo.debian new file mode 100644 index 0000000..5889e9a --- /dev/null +++ b/plugins/tests/var/ps-axwo.debian | |||
@@ -0,0 +1,219 @@ | |||
1 | STAT UID PID PPID VSZ RSS %CPU ELAPSED COMMAND COMMAND | ||
2 | Ss 0 1 0 167244 7144 0.1 26-03:07:26 systemd /lib/systemd/systemd --system --deserialize 17 | ||
3 | S 0 2 0 0 0 0.0 26-03:07:26 kthreadd [kthreadd] | ||
4 | I< 0 3 2 0 0 0.0 26-03:07:26 rcu_gp [rcu_gp] | ||
5 | I< 0 4 2 0 0 0.0 26-03:07:26 rcu_par_gp [rcu_par_gp] | ||
6 | I< 0 6 2 0 0 0.0 26-03:07:26 kworker/0:0H-ev [kworker/0:0H-events_highpri] | ||
7 | I< 0 9 2 0 0 0.0 26-03:07:26 mm_percpu_wq [mm_percpu_wq] | ||
8 | S 0 10 2 0 0 0.0 26-03:07:26 rcu_tasks_rude_ [rcu_tasks_rude_] | ||
9 | S 0 11 2 0 0 0.0 26-03:07:26 rcu_tasks_trace [rcu_tasks_trace] | ||
10 | S 0 12 2 0 0 0.0 26-03:07:26 ksoftirqd/0 [ksoftirqd/0] | ||
11 | I 0 13 2 0 0 0.0 26-03:07:26 rcu_sched [rcu_sched] | ||
12 | S 0 14 2 0 0 0.0 26-03:07:26 migration/0 [migration/0] | ||
13 | S 0 15 2 0 0 0.0 26-03:07:26 cpuhp/0 [cpuhp/0] | ||
14 | S 0 16 2 0 0 0.0 26-03:07:26 cpuhp/1 [cpuhp/1] | ||
15 | S 0 17 2 0 0 0.0 26-03:07:26 migration/1 [migration/1] | ||
16 | S 0 18 2 0 0 0.0 26-03:07:26 ksoftirqd/1 [ksoftirqd/1] | ||
17 | I< 0 20 2 0 0 0.0 26-03:07:26 kworker/1:0H-ev [kworker/1:0H-events_highpri] | ||
18 | S 0 21 2 0 0 0.0 26-03:07:26 cpuhp/2 [cpuhp/2] | ||
19 | S 0 22 2 0 0 0.0 26-03:07:26 migration/2 [migration/2] | ||
20 | S 0 23 2 0 0 0.0 26-03:07:26 ksoftirqd/2 [ksoftirqd/2] | ||
21 | I< 0 25 2 0 0 0.0 26-03:07:26 kworker/2:0H-ev [kworker/2:0H-events_highpri] | ||
22 | S 0 26 2 0 0 0.0 26-03:07:26 cpuhp/3 [cpuhp/3] | ||
23 | S 0 27 2 0 0 0.0 26-03:07:26 migration/3 [migration/3] | ||
24 | S 0 28 2 0 0 0.0 26-03:07:26 ksoftirqd/3 [ksoftirqd/3] | ||
25 | I< 0 30 2 0 0 0.0 26-03:07:26 kworker/3:0H-ev [kworker/3:0H-events_highpri] | ||
26 | S 0 35 2 0 0 0.0 26-03:07:26 kdevtmpfs [kdevtmpfs] | ||
27 | I< 0 36 2 0 0 0.0 26-03:07:26 netns [netns] | ||
28 | S 0 37 2 0 0 0.0 26-03:07:26 kauditd [kauditd] | ||
29 | S 0 38 2 0 0 0.0 26-03:07:26 khungtaskd [khungtaskd] | ||
30 | S 0 39 2 0 0 0.0 26-03:07:26 oom_reaper [oom_reaper] | ||
31 | I< 0 40 2 0 0 0.0 26-03:07:26 writeback [writeback] | ||
32 | S 0 41 2 0 0 0.0 26-03:07:26 kcompactd0 [kcompactd0] | ||
33 | SN 0 42 2 0 0 0.0 26-03:07:26 ksmd [ksmd] | ||
34 | SN 0 43 2 0 0 0.0 26-03:07:26 khugepaged [khugepaged] | ||
35 | I< 0 62 2 0 0 0.0 26-03:07:26 kintegrityd [kintegrityd] | ||
36 | I< 0 63 2 0 0 0.0 26-03:07:26 kblockd [kblockd] | ||
37 | I< 0 64 2 0 0 0.0 26-03:07:26 blkcg_punt_bio [blkcg_punt_bio] | ||
38 | I< 0 65 2 0 0 0.0 26-03:07:26 edac-poller [edac-poller] | ||
39 | I< 0 66 2 0 0 0.0 26-03:07:26 devfreq_wq [devfreq_wq] | ||
40 | I< 0 67 2 0 0 0.0 26-03:07:26 kworker/2:1H-ev [kworker/2:1H-events_highpri] | ||
41 | S 0 70 2 0 0 0.3 26-03:07:25 kswapd0 [kswapd0] | ||
42 | I< 0 71 2 0 0 0.0 26-03:07:25 kthrotld [kthrotld] | ||
43 | I< 0 72 2 0 0 0.0 26-03:07:25 acpi_thermal_pm [acpi_thermal_pm] | ||
44 | I< 0 74 2 0 0 0.0 26-03:07:25 ipv6_addrconf [ipv6_addrconf] | ||
45 | I< 0 80 2 0 0 0.0 26-03:07:25 kworker/3:1H-ev [kworker/3:1H-events_highpri] | ||
46 | I< 0 84 2 0 0 0.0 26-03:07:25 kstrp [kstrp] | ||
47 | I< 0 87 2 0 0 0.0 26-03:07:25 zswap-shrink [zswap-shrink] | ||
48 | I< 0 110 2 0 0 0.0 26-03:07:25 kworker/0:1H-ev [kworker/0:1H-events_highpri] | ||
49 | I< 0 141 2 0 0 0.0 26-03:07:25 ata_sff [ata_sff] | ||
50 | S 0 143 2 0 0 0.0 26-03:07:25 scsi_eh_0 [scsi_eh_0] | ||
51 | I< 0 144 2 0 0 0.0 26-03:07:25 scsi_tmf_0 [scsi_tmf_0] | ||
52 | S 0 145 2 0 0 0.0 26-03:07:25 scsi_eh_1 [scsi_eh_1] | ||
53 | I< 0 146 2 0 0 0.0 26-03:07:25 scsi_tmf_1 [scsi_tmf_1] | ||
54 | S 0 147 2 0 0 0.0 26-03:07:25 scsi_eh_2 [scsi_eh_2] | ||
55 | I< 0 148 2 0 0 0.0 26-03:07:25 scsi_tmf_2 [scsi_tmf_2] | ||
56 | S 0 149 2 0 0 0.0 26-03:07:25 scsi_eh_3 [scsi_eh_3] | ||
57 | I< 0 150 2 0 0 0.0 26-03:07:25 scsi_tmf_3 [scsi_tmf_3] | ||
58 | S 0 151 2 0 0 0.0 26-03:07:25 scsi_eh_4 [scsi_eh_4] | ||
59 | I< 0 152 2 0 0 0.0 26-03:07:25 scsi_tmf_4 [scsi_tmf_4] | ||
60 | S 0 153 2 0 0 0.0 26-03:07:25 scsi_eh_5 [scsi_eh_5] | ||
61 | I< 0 154 2 0 0 0.0 26-03:07:25 scsi_tmf_5 [scsi_tmf_5] | ||
62 | S 0 158 2 0 0 0.0 26-03:07:25 card0-crtc0 [card0-crtc0] | ||
63 | S 0 159 2 0 0 0.0 26-03:07:25 card0-crtc1 [card0-crtc1] | ||
64 | S 0 160 2 0 0 0.0 26-03:07:25 card0-crtc2 [card0-crtc2] | ||
65 | I< 0 162 2 0 0 0.0 26-03:07:25 kworker/1:1H-ev [kworker/1:1H-events_highpri] | ||
66 | S 0 163 2 0 0 0.0 26-03:07:25 scsi_eh_6 [scsi_eh_6] | ||
67 | I< 0 164 2 0 0 0.0 26-03:07:25 scsi_tmf_6 [scsi_tmf_6] | ||
68 | S 0 165 2 0 0 0.0 26-03:07:25 usb-storage [usb-storage] | ||
69 | I< 0 167 2 0 0 0.0 26-03:07:25 uas [uas] | ||
70 | I< 0 176 2 0 0 0.0 26-03:07:25 kdmflush [kdmflush] | ||
71 | I< 0 177 2 0 0 0.0 26-03:07:25 kdmflush [kdmflush] | ||
72 | S 0 202 2 0 0 0.0 26-03:07:24 scsi_eh_7 [scsi_eh_7] | ||
73 | I< 0 203 2 0 0 0.0 26-03:07:24 scsi_tmf_7 [scsi_tmf_7] | ||
74 | S 0 204 2 0 0 0.0 26-03:07:24 usb-storage [usb-storage] | ||
75 | I< 0 232 2 0 0 0.0 26-03:07:23 btrfs-worker [btrfs-worker] | ||
76 | I< 0 233 2 0 0 0.0 26-03:07:23 btrfs-worker-hi [btrfs-worker-hi] | ||
77 | I< 0 234 2 0 0 0.0 26-03:07:23 btrfs-delalloc [btrfs-delalloc] | ||
78 | I< 0 235 2 0 0 0.0 26-03:07:23 btrfs-flush_del [btrfs-flush_del] | ||
79 | I< 0 236 2 0 0 0.0 26-03:07:23 btrfs-cache [btrfs-cache] | ||
80 | I< 0 237 2 0 0 0.0 26-03:07:23 btrfs-fixup [btrfs-fixup] | ||
81 | I< 0 238 2 0 0 0.0 26-03:07:23 btrfs-endio [btrfs-endio] | ||
82 | I< 0 239 2 0 0 0.0 26-03:07:23 btrfs-endio-met [btrfs-endio-met] | ||
83 | I< 0 240 2 0 0 0.0 26-03:07:23 btrfs-endio-met [btrfs-endio-met] | ||
84 | I< 0 241 2 0 0 0.0 26-03:07:23 btrfs-endio-rai [btrfs-endio-rai] | ||
85 | I< 0 242 2 0 0 0.0 26-03:07:23 btrfs-rmw [btrfs-rmw] | ||
86 | I< 0 243 2 0 0 0.0 26-03:07:23 btrfs-endio-wri [btrfs-endio-wri] | ||
87 | I< 0 244 2 0 0 0.0 26-03:07:23 btrfs-freespace [btrfs-freespace] | ||
88 | I< 0 245 2 0 0 0.0 26-03:07:23 btrfs-delayed-m [btrfs-delayed-m] | ||
89 | I< 0 246 2 0 0 0.0 26-03:07:23 btrfs-readahead [btrfs-readahead] | ||
90 | I< 0 247 2 0 0 0.0 26-03:07:23 btrfs-qgroup-re [btrfs-qgroup-re] | ||
91 | S 0 248 2 0 0 0.0 26-03:07:23 btrfs-cleaner [btrfs-cleaner] | ||
92 | S 0 249 2 0 0 0.2 26-03:07:23 btrfs-transacti [btrfs-transacti] | ||
93 | I< 0 317 2 0 0 0.0 26-03:07:22 rpciod [rpciod] | ||
94 | I< 0 322 2 0 0 0.0 26-03:07:22 xprtiod [xprtiod] | ||
95 | S 0 381 2 0 0 0.0 26-03:07:22 irq/133-mei_me [irq/133-mei_me] | ||
96 | S 0 422 2 0 0 0.0 26-03:07:22 watchdogd [watchdogd] | ||
97 | I< 0 523 2 0 0 0.0 26-03:07:22 led_workqueue [led_workqueue] | ||
98 | I< 0 583 2 0 0 0.0 26-03:07:22 cryptd [cryptd] | ||
99 | I< 0 590 2 0 0 0.0 26-03:07:22 ext4-rsv-conver [ext4-rsv-conver] | ||
100 | Ss 104 693 1 12324 4292 0.5 26-03:07:21 dbus-daemon /usr/bin/dbus-daemon --system --address=systemd: --nofork --nopidfile --systemd-activation --syslog-only | ||
101 | Ss 0 731 1 575120 1368 0.0 26-03:07:21 systemd-logind /lib/systemd/systemd-logind | ||
102 | Ssl 0 1111 1 121248 732 0.0 26-03:07:18 unattended-upgr /usr/bin/python3 /usr/share/unattended-upgrades/unattended-upgrade-shutdown --wait-for-signal | ||
103 | S 0 1141 2 0 0 0.0 26-03:07:18 lockd [lockd] | ||
104 | I< 0 1459 2 0 0 0.0 26-03:07:16 nfsiod [nfsiod] | ||
105 | S 0 1621 2 0 0 0.0 26-03:07:15 NFSv4 callback [NFSv4 callback] | ||
106 | Ssl 0 1771 1 1548340 676 0.0 26-03:07:13 libvirtd /usr/sbin/libvirtd | ||
107 | I< 0 24315 2 0 0 0.0 26-02:49:02 cifsiod [cifsiod] | ||
108 | I< 0 24316 2 0 0 0.0 26-02:49:02 smb3decryptd [smb3decryptd] | ||
109 | I< 0 24317 2 0 0 0.0 26-02:49:02 cifsfileinfoput [cifsfileinfoput] | ||
110 | I< 0 24318 2 0 0 0.0 26-02:49:02 cifsoplockd [cifsoplockd] | ||
111 | I< 0 24319 2 0 0 0.0 26-02:49:02 cifs-dfscache [cifs-dfscache] | ||
112 | S 0 24322 2 0 0 0.0 26-02:49:02 cifsd [cifsd] | ||
113 | I< 0 24413 2 0 0 0.0 26-02:48:57 btrfs-worker [btrfs-worker] | ||
114 | I< 0 24414 2 0 0 0.0 26-02:48:57 btrfs-worker-hi [btrfs-worker-hi] | ||
115 | I< 0 24415 2 0 0 0.0 26-02:48:57 btrfs-delalloc [btrfs-delalloc] | ||
116 | I< 0 24416 2 0 0 0.0 26-02:48:57 btrfs-flush_del [btrfs-flush_del] | ||
117 | I< 0 24418 2 0 0 0.0 26-02:48:57 btrfs-cache [btrfs-cache] | ||
118 | I< 0 24419 2 0 0 0.0 26-02:48:57 btrfs-fixup [btrfs-fixup] | ||
119 | I< 0 24420 2 0 0 0.0 26-02:48:57 btrfs-endio [btrfs-endio] | ||
120 | I< 0 24421 2 0 0 0.0 26-02:48:57 btrfs-endio-met [btrfs-endio-met] | ||
121 | I< 0 24422 2 0 0 0.0 26-02:48:57 btrfs-endio-met [btrfs-endio-met] | ||
122 | I< 0 24423 2 0 0 0.0 26-02:48:57 btrfs-endio-rai [btrfs-endio-rai] | ||
123 | I< 0 24424 2 0 0 0.0 26-02:48:57 btrfs-rmw [btrfs-rmw] | ||
124 | I< 0 24425 2 0 0 0.0 26-02:48:57 btrfs-endio-wri [btrfs-endio-wri] | ||
125 | I< 0 24426 2 0 0 0.0 26-02:48:57 btrfs-freespace [btrfs-freespace] | ||
126 | I< 0 24427 2 0 0 0.0 26-02:48:57 btrfs-delayed-m [btrfs-delayed-m] | ||
127 | I< 0 24428 2 0 0 0.0 26-02:48:57 btrfs-readahead [btrfs-readahead] | ||
128 | I< 0 24429 2 0 0 0.0 26-02:48:57 btrfs-qgroup-re [btrfs-qgroup-re] | ||
129 | S 0 24450 2 0 0 0.0 26-02:48:53 btrfs-cleaner [btrfs-cleaner] | ||
130 | S 0 24451 2 0 0 0.0 26-02:48:53 btrfs-transacti [btrfs-transacti] | ||
131 | I< 0 747708 2 0 0 0.0 16-21:06:20 xfsalloc [xfsalloc] | ||
132 | I< 0 747709 2 0 0 0.0 16-21:06:20 xfs_mru_cache [xfs_mru_cache] | ||
133 | S 0 747713 2 0 0 0.0 16-21:06:20 jfsIO [jfsIO] | ||
134 | S 0 747714 2 0 0 0.0 16-21:06:20 jfsCommit [jfsCommit] | ||
135 | S 0 747715 2 0 0 0.0 16-21:06:20 jfsCommit [jfsCommit] | ||
136 | S 0 747716 2 0 0 0.0 16-21:06:20 jfsCommit [jfsCommit] | ||
137 | S 0 747717 2 0 0 0.0 16-21:06:20 jfsCommit [jfsCommit] | ||
138 | S 0 747718 2 0 0 0.0 16-21:06:20 jfsSync [jfsSync] | ||
139 | Ss 0 1071687 1 105976 28304 0.0 3-03:12:31 systemd-journal /lib/systemd/systemd-journald | ||
140 | Ss 0 1934146 1 25672 4704 0.0 11:19:31 cupsd /usr/sbin/cupsd -l | ||
141 | Ssl 0 1934148 1 182868 8540 0.0 11:19:31 cups-browsed /usr/sbin/cups-browsed | ||
142 | S 13 1934155 3392655 5752 88 0.0 11:19:31 pinger (pinger) | ||
143 | S< 33 1934166 3393034 57996 5460 0.0 11:19:31 apache2 /usr/sbin/apache2 -k start | ||
144 | S< 33 1934167 3393034 216944 13892 0.0 11:19:30 apache2 /usr/sbin/apache2 -k start | ||
145 | S< 33 1934168 3393034 216944 13756 0.0 11:19:30 apache2 /usr/sbin/apache2 -k start | ||
146 | S< 33 1934169 3393034 216936 13732 0.0 11:19:30 apache2 /usr/sbin/apache2 -k start | ||
147 | S< 33 1934170 3393034 216944 13888 0.0 11:19:30 apache2 /usr/sbin/apache2 -k start | ||
148 | S< 33 1934172 3393034 216944 15388 0.0 11:19:30 apache2 /usr/sbin/apache2 -k start | ||
149 | S< 33 1934701 3393034 216936 13736 0.0 11:19:29 apache2 /usr/sbin/apache2 -k start | ||
150 | S< 33 1935056 3393034 216920 13724 0.0 11:19:28 apache2 /usr/sbin/apache2 -k start | ||
151 | S 7 1936834 1934146 16652 832 0.0 11:18:12 dbus /usr/lib/cups/notifier/dbus dbus:// | ||
152 | S< 33 1955909 3393034 216928 13792 0.0 11:00:25 apache2 /usr/sbin/apache2 -k start | ||
153 | I< 0 2531464 2 0 0 0.0 06:35:47 kworker/u9:0-i9 [kworker/u9:0-i915_flip] | ||
154 | I 0 2570506 2 0 0 0.0 06:27:41 kworker/1:0-cgr [kworker/1:0-cgroup_destroy] | ||
155 | I 0 2596195 2 0 0 0.0 06:21:52 kworker/1:1-eve [kworker/1:1-events] | ||
156 | I 0 2785341 2 0 0 0.0 03:34:16 kworker/u8:8-bt [kworker/u8:8-btrfs-endio-write] | ||
157 | I 0 2785520 2 0 0 0.0 03:33:50 kworker/3:0-eve [kworker/3:0-events] | ||
158 | I 0 2798669 2 0 0 0.0 03:21:09 kworker/u8:5-bt [kworker/u8:5-btrfs-endio-write] | ||
159 | Ss 0 2803015 1 5616 3108 0.0 03:17:54 cron /usr/sbin/cron -f | ||
160 | I 0 2845483 2 0 0 0.0 02:38:11 kworker/0:3-eve [kworker/0:3-events] | ||
161 | I 0 2939490 2 0 0 0.1 01:10:32 kworker/0:0-eve [kworker/0:0-events] | ||
162 | I 0 2939754 2 0 0 0.0 01:10:26 kworker/u8:1-i9 [kworker/u8:1-i915] | ||
163 | I 0 2942040 2 0 0 0.0 01:08:02 kworker/u8:7-bt [kworker/u8:7-btrfs-endio-meta] | ||
164 | S 117 2954268 3392551 40044 5772 0.0 56:37 pickup pickup -l -t unix -u -c | ||
165 | I 0 2965195 2 0 0 0.0 46:00 kworker/u8:0-bt [kworker/u8:0-btrfs-worker] | ||
166 | I 0 2977972 2 0 0 0.0 33:54 kworker/u8:2-bt [kworker/u8:2-btrfs-endio-write] | ||
167 | I 0 2985488 2 0 0 0.0 27:02 kworker/u8:3-bl [kworker/u8:3-blkcg_punt_bio] | ||
168 | I 0 2987519 2 0 0 1.0 25:15 kworker/2:1-eve [kworker/2:1-events] | ||
169 | I 0 2987601 2 0 0 0.0 25:03 kworker/u8:9-i9 [kworker/u8:9-i915] | ||
170 | I< 0 2995218 2 0 0 0.0 18:41 kworker/u9:2-xp [kworker/u9:2-xprtiod] | ||
171 | I 0 2997170 2 0 0 0.0 16:41 kworker/3:1-rcu [kworker/3:1-rcu_gp] | ||
172 | I 0 3001264 2 0 0 0.0 13:01 kworker/u8:4-bt [kworker/u8:4-btrfs-endio-write] | ||
173 | I 0 3004697 2 0 0 0.7 09:41 kworker/2:0-eve [kworker/2:0-events] | ||
174 | I 0 3010619 2 0 0 1.0 04:29 kworker/2:2-eve [kworker/2:2-events] | ||
175 | I 0 3014612 2 0 0 0.0 00:41 kworker/3:2-eve [kworker/3:2-events] | ||
176 | S 0 3015082 2803015 6716 3028 0.0 00:30 cron /usr/sbin/CRON -f | ||
177 | I 0 3015382 2 0 0 0.0 00:00 kworker/u8:6-bt [kworker/u8:6-btrfs-endio-meta] | ||
178 | Ss 1 3392068 1 5592 504 0.0 15-02:34:39 atd /usr/sbin/atd -f | ||
179 | Ssl 0 3392072 1 235796 1740 0.0 15-02:34:39 accounts-daemon /usr/libexec/accounts-daemon | ||
180 | Ssl 106 3392076 1 315708 6128 0.0 15-02:34:39 colord /usr/libexec/colord | ||
181 | Ss 0 3392083 1 8120 720 0.0 15-02:34:39 haveged /usr/sbin/haveged --Foreground --verbose=1 | ||
182 | Ss 0 3392090 1 5168 132 0.0 15-02:34:39 blkmapd /usr/sbin/blkmapd | ||
183 | SNsl 111 3392094 1 155648 440 0.0 15-02:34:39 rtkit-daemon /usr/libexec/rtkit-daemon | ||
184 | Ssl 0 3392097 1 290168 1352 0.0 15-02:34:39 packagekitd /usr/libexec/packagekitd | ||
185 | Ss 128 3392100 1 7960 448 0.0 15-02:34:39 rpcbind /sbin/rpcbind -f -w | ||
186 | Ss 0 3392114 1 13432 616 0.0 15-02:34:39 systemd-machine /lib/systemd/systemd-machined | ||
187 | Ss 0 3392118 1 13316 848 0.0 15-02:34:39 sshd sshd: /usr/sbin/sshd -D [listener] 0 of 10-100 startups | ||
188 | Ssl 0 3392124 1 244072 2456 0.0 15-02:34:39 upowerd /usr/libexec/upowerd | ||
189 | Ssl 0 3392138 1 1634748 10684 0.0 15-02:34:39 containerd /usr/bin/containerd | ||
190 | Ssl 0 3392139 1 222768 1784 0.0 15-02:34:39 rsyslogd /usr/sbin/rsyslogd -n -iNONE | ||
191 | Ss 13 3392140 1 3344 152 0.0 15-02:34:39 polipo /usr/bin/polipo -c /etc/polipo/config pidFile=/var/run/polipo/polipo.pid daemonise=true | ||
192 | Ssl 119 3392156 1 76472 1688 0.0 15-02:34:39 ntpd /usr/sbin/ntpd -p /var/run/ntpd.pid -g -u 119:126 | ||
193 | Ss 120 3392168 1 4656 276 0.0 15-02:34:39 rpc.statd /sbin/rpc.statd --no-notify | ||
194 | Ss 0 3392171 1 5072 432 0.0 15-02:34:39 rpc.mountd /usr/sbin/rpc.mountd --manage-gids | ||
195 | Ss 0 3392176 1 5008 288 0.0 15-02:34:39 rpc.idmapd /usr/sbin/rpc.idmapd | ||
196 | Ss 105 3392184 1 15544 6816 3.5 15-02:34:39 avahi-daemon avahi-daemon: running [tsui.local] | ||
197 | Ss 0 3392186 1 25288 3860 0.0 15-02:34:39 systemd-udevd /lib/systemd/systemd-udevd | ||
198 | S 105 3392190 3392184 8788 52 0.0 15-02:34:39 avahi-daemon avahi-daemon: chroot helper | ||
199 | Ssl 0 3392197 1 396120 4188 0.0 15-02:34:39 udisksd /usr/libexec/udisks2/udisksd | ||
200 | Ssl 0 3392214 1 237504 6632 0.0 15-02:34:39 polkitd /usr/libexec/polkitd --no-debug | ||
201 | Ss 0 3392284 1 9684 560 0.0 15-02:34:38 xinetd /usr/sbin/xinetd -pidfile /run/xinetd.pid -stayalive -inetd_compat -inetd_ipv6 | ||
202 | Ssl 0 3392285 1 314840 1352 0.0 15-02:34:38 ModemManager /usr/sbin/ModemManager | ||
203 | Ss 0 3392317 1 2352 140 0.0 15-02:34:38 acpid /usr/sbin/acpid | ||
204 | S 0 3392400 2 0 0 0.0 15-02:34:38 nfsd [nfsd] | ||
205 | S 0 3392401 2 0 0 0.0 15-02:34:38 nfsd [nfsd] | ||
206 | S 0 3392402 2 0 0 0.0 15-02:34:38 nfsd [nfsd] | ||
207 | S 0 3392403 2 0 0 0.0 15-02:34:38 nfsd [nfsd] | ||
208 | S 0 3392404 2 0 0 0.0 15-02:34:38 nfsd [nfsd] | ||
209 | S 0 3392405 2 0 0 0.0 15-02:34:38 nfsd [nfsd] | ||
210 | S 0 3392407 2 0 0 0.0 15-02:34:38 nfsd [nfsd] | ||
211 | S 0 3392410 2 0 0 0.0 15-02:34:38 nfsd [nfsd] | ||
212 | Ss 0 3392551 1 40092 1304 0.0 15-02:34:37 master /usr/lib/postfix/sbin/master -w | ||
213 | S 117 3392553 3392551 40156 568 0.0 15-02:34:37 qmgr qmgr -l -t unix -u | ||
214 | Ss 0 3392650 1 63652 4 0.0 15-02:34:36 squid /usr/sbin/squid --foreground -sYC | ||
215 | Ssl 116 3392652 1 1675196 93848 0.0 15-02:34:36 mariadbd /usr/sbin/mariadbd | ||
216 | S 13 3392655 3392650 81776 21232 0.0 15-02:34:36 squid (squid-1) --kid squid-1 --foreground -sYC | ||
217 | S 13 3392657 3392655 5572 68 0.0 15-02:34:36 log_file_daemon (logfile-daemon) /var/log/squid/access.log | ||
218 | S<s 0 3393034 1 216648 7560 0.0 15-02:34:34 apache2 /usr/sbin/apache2 -k start | ||
219 | Ss 33 3393037 1 3432 180 0.0 15-02:34:34 htcacheclean /usr/bin/htcacheclean -d 120 -p /var/cache/apache2/mod_cache_disk -l 300M -n | ||
diff --git a/plugins/tests/var/ps_axwo.debian b/plugins/tests/var/ps_axwo.debian deleted file mode 100644 index 37a2d35..0000000 --- a/plugins/tests/var/ps_axwo.debian +++ /dev/null | |||
@@ -1,84 +0,0 @@ | |||
1 | STAT UID PID PPID VSZ RSS %CPU COMMAND COMMAND | ||
2 | S 0 1 0 1504 428 0.0 init init [2] | ||
3 | SN 0 2 1 0 0 0.0 ksoftirqd/0 [ksoftirqd/0] | ||
4 | S< 0 3 1 0 0 0.0 events/0 [events/0] | ||
5 | S< 0 4 3 0 0 0.0 khelper [khelper] | ||
6 | S< 0 5 3 0 0 0.0 kacpid [kacpid] | ||
7 | S< 0 38 3 0 0 0.0 kblockd/0 [kblockd/0] | ||
8 | S 0 48 3 0 0 0.0 pdflush [pdflush] | ||
9 | S< 0 51 3 0 0 0.0 aio/0 [aio/0] | ||
10 | S 0 50 1 0 0 0.0 kswapd0 [kswapd0] | ||
11 | S 0 193 1 0 0 0.0 kseriod [kseriod] | ||
12 | S 0 214 1 0 0 0.0 scsi_eh_0 [scsi_eh_0] | ||
13 | S 0 221 1 0 0 0.0 khubd [khubd] | ||
14 | S 0 299 1 0 0 0.3 kjournald [kjournald] | ||
15 | S 0 1148 1 0 0 0.0 pciehpd_event [pciehpd_event] | ||
16 | S 0 1168 1 0 0 0.0 shpchpd_event [shpchpd_event] | ||
17 | Ss 1 1795 1 1612 276 0.0 portmap /sbin/portmap | ||
18 | Ss 0 2200 1 1652 568 0.0 vmware-guestd /usr/sbin/vmware-guestd --background /var/run/vmware-guestd.pid | ||
19 | Ss 0 2209 1 2240 532 0.0 inetd /usr/sbin/inetd | ||
20 | Ss 0 2319 1 3468 792 0.0 sshd /usr/sbin/sshd | ||
21 | Ss 0 2323 1 2468 676 0.0 rpc.statd /sbin/rpc.statd | ||
22 | Ss 1 2332 1 1684 488 0.0 atd /usr/sbin/atd | ||
23 | Ss 0 2335 1 1764 636 0.0 cron /usr/sbin/cron | ||
24 | Ss+ 0 2350 1 1500 348 0.0 getty /sbin/getty 38400 tty1 | ||
25 | Ss+ 0 2351 1 1500 348 0.0 getty /sbin/getty 38400 tty2 | ||
26 | Ss+ 0 2352 1 1500 348 0.0 getty /sbin/getty 38400 tty3 | ||
27 | Ss+ 0 2353 1 1500 348 0.0 getty /sbin/getty 38400 tty4 | ||
28 | Ss+ 0 2354 1 1500 348 0.0 getty /sbin/getty 38400 tty5 | ||
29 | Ss+ 0 2355 1 1500 348 0.0 getty /sbin/getty 38400 tty6 | ||
30 | S 0 6907 1 2308 892 0.0 mysqld_safe /bin/sh /usr/bin/mysqld_safe | ||
31 | S 103 6944 6907 123220 27724 0.0 mysqld /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --user=mysql --pid-file=/var/run/mysqld/mysqld.pid --skip-locking --port=3306 --socket=/var/run/mysqld/mysqld.sock | ||
32 | S 0 6945 6907 1488 420 0.0 logger logger -p daemon.err -t mysqld_safe -i -t mysqld | ||
33 | S 1001 17778 1 6436 1588 0.0 snmpd /usr/sbin/snmpd -u nagios -Lsd -Lf /dev/null -p/var/run/snmpd.pid | ||
34 | Ss 0 17789 1 9496 5556 0.0 snmptrapd /usr/sbin/snmptrapd -t -m ALL -M /usr/share/snmp/mibs:/usr/local/monitoring/snmp/load -p /var/run/snmptrapd.pid | ||
35 | Ss 0 847 2319 14452 1752 0.0 sshd sshd: tonvoon [priv] | ||
36 | S 1000 857 847 14616 1832 0.0 sshd sshd: tonvoon@pts/3 | ||
37 | Ss 1000 860 857 2984 1620 0.0 bash -bash | ||
38 | S 0 868 860 2588 1428 0.0 bash -su | ||
39 | S+ 1001 877 868 2652 1568 0.0 bash -su | ||
40 | S 0 6086 3 0 0 0.0 pdflush [pdflush] | ||
41 | Ss 0 17832 2319 14452 1752 0.0 sshd sshd: tonvoon [priv] | ||
42 | S 1000 18155 17832 14620 1840 0.0 sshd sshd: tonvoon@pts/0 | ||
43 | Ss 1000 18156 18155 2984 1620 0.0 bash -bash | ||
44 | S 0 18518 18156 2588 1428 0.0 bash -su | ||
45 | S 1001 18955 18518 2672 1600 0.0 bash -su | ||
46 | Ss 0 21683 2319 14452 1756 0.0 sshd sshd: tonvoon [priv] | ||
47 | S 1000 21742 21683 14620 1896 0.0 sshd sshd: tonvoon@pts/1 | ||
48 | Ss 1000 21743 21742 2984 1620 0.0 bash -bash | ||
49 | S 0 21748 21743 2592 1432 0.0 bash -su | ||
50 | S 1001 21757 21748 2620 1540 0.0 bash -su | ||
51 | Ss 0 2334 2319 14452 1756 0.0 sshd sshd: tonvoon [priv] | ||
52 | S 1000 2343 2334 14620 1840 0.0 sshd sshd: tonvoon@pts/2 | ||
53 | Ss 1000 2344 2343 2984 1620 0.0 bash -bash | ||
54 | S 0 2349 2344 2592 1432 0.0 bash -su | ||
55 | S+ 1001 2364 2349 2620 1520 0.0 bash -su | ||
56 | T 1001 2454 2364 2096 1032 0.0 vi vi configure.in.rej | ||
57 | S+ 1001 8500 21757 69604 52576 0.0 opsview_web_ser /usr/bin/perl -w ./script/opsview_web_server.pl -f -d | ||
58 | Ss 0 7609 2319 14452 1756 0.0 sshd sshd: tonvoon [priv] | ||
59 | S 1000 7617 7609 14460 1828 0.0 sshd sshd: tonvoon@pts/4 | ||
60 | Ss 1000 7618 7617 2984 1620 0.0 bash -bash | ||
61 | S 0 7623 7618 2592 1432 0.0 bash -su | ||
62 | S+ 1001 7632 7623 2620 1528 0.0 bash -su | ||
63 | Ss 1001 12678 1 20784 17728 0.0 opsviewd opsviewd | ||
64 | Ss 0 832 1 14512 6360 0.0 apache2 /usr/sbin/apache2 -k start -DSSL | ||
65 | S 33 842 832 14648 6596 0.0 apache2 /usr/sbin/apache2 -k start -DSSL | ||
66 | S 33 843 832 14512 6504 0.0 apache2 /usr/sbin/apache2 -k start -DSSL | ||
67 | S 33 844 832 14512 6476 0.0 apache2 /usr/sbin/apache2 -k start -DSSL | ||
68 | S 33 845 832 14512 6476 0.0 apache2 /usr/sbin/apache2 -k start -DSSL | ||
69 | S 33 846 832 14512 6476 0.0 apache2 /usr/sbin/apache2 -k start -DSSL | ||
70 | Ss 7 4081 1 2464 884 0.0 lpd /usr/sbin/lpd -s | ||
71 | S 33 26484 832 14512 6476 0.0 apache2 /usr/sbin/apache2 -k start -DSSL | ||
72 | Ss 1001 22324 1 20252 1612 0.1 nagios ../../bin/nagios -d /usr/local/nagios/etc/nagios.cfg | ||
73 | Ss 0 23336 2319 14452 1756 0.0 sshd sshd: tonvoon [priv] | ||
74 | S 1000 23339 23336 14620 1840 0.0 sshd sshd: tonvoon@pts/5 | ||
75 | Ss 1000 23340 23339 2996 1636 0.0 bash -bash | ||
76 | S 0 23367 23340 3020 1628 0.0 bash bash | ||
77 | S 1001 23370 23367 3064 1748 0.0 bash bash | ||
78 | Ss 1001 23783 1 3220 764 0.0 ndo2db /usr/local/nagios/bin/ndo2db -c /usr/local/nagios/etc/ndo2db.cfg | ||
79 | Ss 1001 23784 1 6428 4948 0.0 import_ndologsd import_ndologsd | ||
80 | S+ 1001 9803 18955 4132 1936 0.0 ssh ssh altinity@cube02.lei.altinity | ||
81 | S 1001 22505 22324 20256 1616 0.0 nagios ../../bin/nagios -d /usr/local/nagios/etc/nagios.cfg | ||
82 | S 1001 22506 22505 1676 608 0.0 check_ping /usr/local/libexec/check_ping -H 192.168.10.23 -w 3000.0,80% -c 5000.0,100% -p 1 | ||
83 | S 1001 22507 22506 1660 492 0.0 ping /bin/ping -n -U -w 10 -c 1 192.168.10.23 | ||
84 | R+ 1001 22508 23370 2308 680 0.0 ps ps axwo stat uid pid ppid vsz rss pcpu comm args | ||
diff --git a/plugins/utils.c b/plugins/utils.c index 348ec02..17dd581 100644 --- a/plugins/utils.c +++ b/plugins/utils.c | |||
@@ -27,6 +27,8 @@ | |||
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> | ||
31 | #include <errno.h> | ||
30 | 32 | ||
31 | #include <arpa/inet.h> | 33 | #include <arpa/inet.h> |
32 | 34 | ||
@@ -239,6 +241,46 @@ is_intnonneg (char *number) | |||
239 | return FALSE; | 241 | return FALSE; |
240 | } | 242 | } |
241 | 243 | ||
244 | /* | ||
245 | * Checks whether the number in the string _number_ can be put inside a int64_t | ||
246 | * On success the number will be written to the _target_ address, if _target_ is not set | ||
247 | * to NULL. | ||
248 | */ | ||
249 | int is_int64(char *number, int64_t *target) { | ||
250 | errno = 0; | ||
251 | uint64_t tmp = strtoll(number, NULL, 10); | ||
252 | if (errno != 0) { | ||
253 | return 0; | ||
254 | } | ||
255 | if (tmp < INT64_MIN || tmp > INT64_MAX) { | ||
256 | return 0; | ||
257 | } | ||
258 | if (target != NULL) { | ||
259 | *target = tmp; | ||
260 | } | ||
261 | return 1; | ||
262 | } | ||
263 | |||
264 | /* | ||
265 | * Checks whether the number in the string _number_ can be put inside a uint64_t | ||
266 | * On success the number will be written to the _target_ address, if _target_ is not set | ||
267 | * to NULL. | ||
268 | */ | ||
269 | int is_uint64(char *number, uint64_t *target) { | ||
270 | errno = 0; | ||
271 | uint64_t tmp = strtoll(number, NULL, 10); | ||
272 | if (errno != 0) { | ||
273 | return 0; | ||
274 | } | ||
275 | if (tmp < 0 || tmp > UINT64_MAX) { | ||
276 | return 0; | ||
277 | } | ||
278 | if (target != NULL) { | ||
279 | *target = tmp; | ||
280 | } | ||
281 | return 1; | ||
282 | } | ||
283 | |||
242 | int | 284 | int |
243 | is_intpercent (char *number) | 285 | is_intpercent (char *number) |
244 | { | 286 | { |
@@ -547,10 +589,94 @@ char *perfdata (const char *label, | |||
547 | xasprintf (&data, "%s;", data); | 589 | xasprintf (&data, "%s;", data); |
548 | 590 | ||
549 | if (minp) | 591 | if (minp) |
550 | xasprintf (&data, "%s%ld", data, minv); | 592 | xasprintf (&data, "%s%ld;", data, minv); |
593 | else | ||
594 | xasprintf (&data, "%s;", data); | ||
595 | |||
596 | if (maxp) | ||
597 | xasprintf (&data, "%s%ld", data, maxv); | ||
598 | |||
599 | return data; | ||
600 | } | ||
601 | |||
602 | |||
603 | char *perfdata_uint64 (const char *label, | ||
604 | uint64_t val, | ||
605 | const char *uom, | ||
606 | int warnp, /* Warning present */ | ||
607 | uint64_t warn, | ||
608 | int critp, /* Critical present */ | ||
609 | uint64_t crit, | ||
610 | int minp, /* Minimum present */ | ||
611 | uint64_t minv, | ||
612 | int maxp, /* Maximum present */ | ||
613 | uint64_t maxv) | ||
614 | { | ||
615 | char *data = NULL; | ||
616 | |||
617 | if (strpbrk (label, "'= ")) | ||
618 | xasprintf (&data, "'%s'=%ld%s;", label, val, uom); | ||
619 | else | ||
620 | xasprintf (&data, "%s=%ld%s;", label, val, uom); | ||
621 | |||
622 | if (warnp) | ||
623 | xasprintf (&data, "%s%lu;", data, warn); | ||
624 | else | ||
625 | xasprintf (&data, "%s;", data); | ||
626 | |||
627 | if (critp) | ||
628 | xasprintf (&data, "%s%lu;", data, crit); | ||
629 | else | ||
630 | xasprintf (&data, "%s;", data); | ||
631 | |||
632 | if (minp) | ||
633 | xasprintf (&data, "%s%lu;", data, minv); | ||
634 | else | ||
635 | xasprintf (&data, "%s;", data); | ||
636 | |||
637 | if (maxp) | ||
638 | xasprintf (&data, "%s%lu", data, maxv); | ||
639 | |||
640 | return data; | ||
641 | } | ||
642 | |||
643 | |||
644 | char *perfdata_int64 (const char *label, | ||
645 | int64_t val, | ||
646 | const char *uom, | ||
647 | int warnp, /* Warning present */ | ||
648 | int64_t warn, | ||
649 | int critp, /* Critical present */ | ||
650 | int64_t crit, | ||
651 | int minp, /* Minimum present */ | ||
652 | int64_t minv, | ||
653 | int maxp, /* Maximum present */ | ||
654 | int64_t maxv) | ||
655 | { | ||
656 | char *data = NULL; | ||
657 | |||
658 | if (strpbrk (label, "'= ")) | ||
659 | xasprintf (&data, "'%s'=%ld%s;", label, val, uom); | ||
660 | else | ||
661 | xasprintf (&data, "%s=%ld%s;", label, val, uom); | ||
662 | |||
663 | if (warnp) | ||
664 | xasprintf (&data, "%s%ld;", data, warn); | ||
665 | else | ||
666 | xasprintf (&data, "%s;", data); | ||
667 | |||
668 | if (critp) | ||
669 | xasprintf (&data, "%s%ld;", data, crit); | ||
670 | else | ||
671 | xasprintf (&data, "%s;", data); | ||
672 | |||
673 | if (minp) | ||
674 | xasprintf (&data, "%s%ld;", data, minv); | ||
675 | else | ||
676 | xasprintf (&data, "%s;", data); | ||
551 | 677 | ||
552 | if (maxp) | 678 | if (maxp) |
553 | xasprintf (&data, "%s;%ld", data, maxv); | 679 | xasprintf (&data, "%s%ld", data, maxv); |
554 | 680 | ||
555 | return data; | 681 | return data; |
556 | } | 682 | } |
diff --git a/plugins/utils.h b/plugins/utils.h index 33a2054..5b54da3 100644 --- a/plugins/utils.h +++ b/plugins/utils.h | |||
@@ -16,6 +16,7 @@ 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 | |||
19 | #ifdef NP_EXTRA_OPTS | 20 | #ifdef NP_EXTRA_OPTS |
20 | /* Include extra-opts functions if compiled in */ | 21 | /* Include extra-opts functions if compiled in */ |
21 | #include "extra_opts.h" | 22 | #include "extra_opts.h" |
@@ -38,6 +39,8 @@ int is_intpos (char *); | |||
38 | int is_intneg (char *); | 39 | int is_intneg (char *); |
39 | int is_intnonneg (char *); | 40 | int is_intnonneg (char *); |
40 | int is_intpercent (char *); | 41 | int is_intpercent (char *); |
42 | int is_uint64(char *number, uint64_t *target); | ||
43 | int is_int64(char *number, int64_t *target); | ||
41 | 44 | ||
42 | int is_numeric (char *); | 45 | int is_numeric (char *); |
43 | int is_positive (char *); | 46 | int is_positive (char *); |
@@ -88,6 +91,12 @@ void usage_va(const char *fmt, ...) __attribute__((noreturn)); | |||
88 | char *perfdata (const char *, long int, const char *, int, long int, | 91 | char *perfdata (const char *, long int, const char *, int, long int, |
89 | int, long int, int, long int, int, long int); | 92 | int, long int, int, long int, int, long int); |
90 | 93 | ||
94 | char *perfdata_uint64 (const char *, uint64_t , const char *, int, uint64_t, | ||
95 | int, uint64_t, int, uint64_t, int, uint64_t); | ||
96 | |||
97 | char *perfdata_int64 (const char *, int64_t, const char *, int, int64_t, | ||
98 | int, int64_t, int, int64_t, int, int64_t); | ||
99 | |||
91 | char *fperfdata (const char *, double, const char *, int, double, | 100 | char *fperfdata (const char *, double, const char *, int, double, |
92 | int, double, int, double, int, double); | 101 | int, double, int, double, int, double); |
93 | 102 | ||