diff options
author | Lorenz <12514511+RincewindsHat@users.noreply.github.com> | 2022-11-25 10:30:05 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-25 10:30:05 +0100 |
commit | 917dba07fded8ef04967183a4c0443b5cce2db82 (patch) | |
tree | bd3017f225186b3e7f29db257f0d3b5790846ff2 /plugins | |
parent | 4ff0dfa44306c4e8a7dc46fcb1c508f7a191638b (diff) | |
parent | 1bc6d81651c5b5fe865515d420fc2772f4997059 (diff) | |
download | monitoring-plugins-917dba07fded8ef04967183a4c0443b5cce2db82.tar.gz |
Merge branch 'master' into dev/check_ssh-patches
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/check_curl.c | 22 | ||||
-rw-r--r-- | plugins/check_disk.c | 67 | ||||
-rw-r--r-- | plugins/check_http.c | 23 | ||||
-rw-r--r-- | plugins/check_load.c | 122 | ||||
-rw-r--r-- | plugins/check_ntp.c | 8 | ||||
-rw-r--r-- | plugins/check_pgsql.c | 48 | ||||
-rw-r--r-- | plugins/check_swap.c | 9 | ||||
-rw-r--r-- | plugins/t/check_curl.t | 39 | ||||
-rw-r--r-- | plugins/t/check_load.t | 15 | ||||
-rw-r--r-- | plugins/utils.c | 24 |
10 files changed, 179 insertions, 198 deletions
diff --git a/plugins/check_curl.c b/plugins/check_curl.c index a69854a8..2ad373c0 100644 --- a/plugins/check_curl.c +++ b/plugins/check_curl.c | |||
@@ -476,6 +476,18 @@ check_http (void) | |||
476 | printf ("* curl CURLOPT_RESOLVE: %s\n", dnscache); | 476 | printf ("* curl CURLOPT_RESOLVE: %s\n", dnscache); |
477 | } | 477 | } |
478 | 478 | ||
479 | // If server_address is an IPv6 address it must be surround by square brackets | ||
480 | struct in6_addr tmp_in_addr; | ||
481 | if (inet_pton(AF_INET6, server_address, &tmp_in_addr) == 1) { | ||
482 | char *new_server_address = malloc(strlen(server_address) + 3); | ||
483 | if (new_server_address == NULL) { | ||
484 | die(STATE_UNKNOWN, "HTTP UNKNOWN - Unable to allocate memory\n"); | ||
485 | } | ||
486 | snprintf(new_server_address, strlen(server_address)+3, "[%s]", server_address); | ||
487 | free(server_address); | ||
488 | server_address = new_server_address; | ||
489 | } | ||
490 | |||
479 | /* compose URL: use the address we want to connect to, set Host: header later */ | 491 | /* compose URL: use the address we want to connect to, set Host: header later */ |
480 | snprintf (url, DEFAULT_BUFFER_SIZE, "%s://%s:%d%s", | 492 | snprintf (url, DEFAULT_BUFFER_SIZE, "%s://%s:%d%s", |
481 | use_ssl ? "https" : "http", | 493 | use_ssl ? "https" : "http", |
@@ -999,10 +1011,12 @@ GOT_FIRST_CERT: | |||
999 | result = max_state_alt(get_status(total_time, thlds), result); | 1011 | result = max_state_alt(get_status(total_time, thlds), result); |
1000 | 1012 | ||
1001 | /* Cut-off trailing characters */ | 1013 | /* Cut-off trailing characters */ |
1002 | if(msg[strlen(msg)-2] == ',') | 1014 | if (strlen(msg) >= 2) { |
1003 | msg[strlen(msg)-2] = '\0'; | 1015 | if(msg[strlen(msg)-2] == ',') |
1004 | else | 1016 | msg[strlen(msg)-2] = '\0'; |
1005 | msg[strlen(msg)-3] = '\0'; | 1017 | else |
1018 | msg[strlen(msg)-3] = '\0'; | ||
1019 | } | ||
1006 | 1020 | ||
1007 | /* TODO: separate _() msg and status code: die (result, "HTTP %s: %s\n", state_text(result), msg); */ | 1021 | /* TODO: separate _() msg and status code: die (result, "HTTP %s: %s\n", state_text(result), msg); */ |
1008 | die (result, "HTTP %s: %s %d %s%s%s - %d bytes in %.3f second response time %s|%s\n%s%s", | 1022 | die (result, "HTTP %s: %s %d %s%s%s - %d bytes in %.3f second response time %s|%s\n%s%s", |
diff --git a/plugins/check_disk.c b/plugins/check_disk.c index 66c5dd39..7018c6fd 100644 --- a/plugins/check_disk.c +++ b/plugins/check_disk.c | |||
@@ -171,7 +171,6 @@ main (int argc, char **argv) | |||
171 | char *perf_ilabel; | 171 | char *perf_ilabel; |
172 | char *preamble; | 172 | char *preamble; |
173 | char *flag_header; | 173 | char *flag_header; |
174 | double inode_space_pct; | ||
175 | int temp_result; | 174 | int temp_result; |
176 | 175 | ||
177 | struct mount_entry *me; | 176 | struct mount_entry *me; |
@@ -288,7 +287,7 @@ main (int argc, char **argv) | |||
288 | get_stats (path, &fsp); | 287 | get_stats (path, &fsp); |
289 | 288 | ||
290 | if (verbose >= 3) { | 289 | if (verbose >= 3) { |
291 | 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", | 290 | printf ("For %s, used_pct=%g free_pct=%g used_units=%lu free_units=%lu total_units=%lu used_inodes_pct=%g free_inodes_pct=%g fsp.fsu_blocksize=%lu mult=%lu\n", |
292 | me->me_mountdir, | 291 | me->me_mountdir, |
293 | path->dused_pct, | 292 | path->dused_pct, |
294 | path->dfree_pct, | 293 | path->dfree_pct, |
@@ -369,10 +368,10 @@ main (int argc, char **argv) | |||
369 | critical_high_tide = UINT64_MAX; | 368 | critical_high_tide = UINT64_MAX; |
370 | 369 | ||
371 | if (path->freeinodes_percent->warning != NULL) { | 370 | if (path->freeinodes_percent->warning != NULL) { |
372 | warning_high_tide = llabs( min( (double) warning_high_tide, (double) (1.0 - path->freeinodes_percent->warning->end/100)*path->inodes_total )); | 371 | warning_high_tide = (uint64_t) fabs( min( (double) warning_high_tide, (double) (1.0 - path->freeinodes_percent->warning->end/100)*path->inodes_total )); |
373 | } | 372 | } |
374 | if (path->freeinodes_percent->critical != NULL) { | 373 | if (path->freeinodes_percent->critical != NULL) { |
375 | critical_high_tide = llabs( min( (double) critical_high_tide, (double) (1.0 - path->freeinodes_percent->critical->end/100)*path->inodes_total )); | 374 | critical_high_tide = (uint64_t) fabs( min( (double) critical_high_tide, (double) (1.0 - path->freeinodes_percent->critical->end/100)*path->inodes_total )); |
376 | } | 375 | } |
377 | 376 | ||
378 | xasprintf (&perf_ilabel, "%s (inodes)", (!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir); | 377 | xasprintf (&perf_ilabel, "%s (inodes)", (!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir); |
@@ -406,15 +405,7 @@ main (int argc, char **argv) | |||
406 | xasprintf(&output, "%s inode=%.0f%%)%s;", output, path->dfree_inodes_percent, ((disk_result && verbose >= 1) ? "]" : "")); | 405 | xasprintf(&output, "%s inode=%.0f%%)%s;", output, path->dfree_inodes_percent, ((disk_result && verbose >= 1) ? "]" : "")); |
407 | } | 406 | } |
408 | free(flag_header); | 407 | free(flag_header); |
409 | /* TODO: Need to do a similar debug line | ||
410 | 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%%"), | ||
411 | details, dfree_units, dtotal_units, units, dfree_pct, inode_space_pct, | ||
412 | me->me_devname, me->me_type, me->me_mountdir, | ||
413 | (unsigned long)w_df, (unsigned long)c_df, w_dfp, c_dfp); | ||
414 | */ | ||
415 | |||
416 | } | 408 | } |
417 | |||
418 | } | 409 | } |
419 | 410 | ||
420 | if (verbose >= 2) | 411 | if (verbose >= 2) |
@@ -689,6 +680,7 @@ process_arguments (int argc, char **argv) | |||
689 | break; | 680 | break; |
690 | case 'I': | 681 | case 'I': |
691 | cflags |= REG_ICASE; | 682 | cflags |= REG_ICASE; |
683 | // Intentional fallthrough | ||
692 | case 'i': | 684 | case 'i': |
693 | if (!path_selected) | 685 | if (!path_selected) |
694 | die (STATE_UNKNOWN, "DISK %s: %s\n", _("UNKNOWN"), _("Paths need to be selected before using -i/-I. Use -A to select all paths explicitly")); | 686 | die (STATE_UNKNOWN, "DISK %s: %s\n", _("UNKNOWN"), _("Paths need to be selected before using -i/-I. Use -A to select all paths explicitly")); |
@@ -728,8 +720,10 @@ process_arguments (int argc, char **argv) | |||
728 | 720 | ||
729 | case 'A': | 721 | case 'A': |
730 | optarg = strdup(".*"); | 722 | optarg = strdup(".*"); |
723 | // Intentional fallthrough | ||
731 | case 'R': | 724 | case 'R': |
732 | cflags |= REG_ICASE; | 725 | cflags |= REG_ICASE; |
726 | // Intentional fallthrough | ||
733 | case 'r': | 727 | case 'r': |
734 | if (! (warn_freespace_units || crit_freespace_units || warn_freespace_percent || | 728 | if (! (warn_freespace_units || crit_freespace_units || warn_freespace_percent || |
735 | crit_freespace_percent || warn_usedspace_units || crit_usedspace_units || | 729 | crit_freespace_percent || warn_usedspace_units || crit_usedspace_units || |
@@ -862,51 +856,6 @@ set_all_thresholds (struct parameter_list *path) | |||
862 | set_thresholds(&path->freeinodes_percent, warn_freeinodes_percent, crit_freeinodes_percent); | 856 | set_thresholds(&path->freeinodes_percent, warn_freeinodes_percent, crit_freeinodes_percent); |
863 | } | 857 | } |
864 | 858 | ||
865 | /* TODO: Remove? | ||
866 | |||
867 | int | ||
868 | validate_arguments (uintmax_t w, uintmax_t c, double wp, double cp, double iwp, double icp, char *mypath) | ||
869 | { | ||
870 | if (w < 0 && c < 0 && wp < 0.0 && cp < 0.0) { | ||
871 | printf (_("INPUT ERROR: No thresholds specified")); | ||
872 | print_path (mypath); | ||
873 | return ERROR; | ||
874 | } | ||
875 | else if ((wp >= 0.0 || cp >= 0.0) && | ||
876 | (wp < 0.0 || cp < 0.0 || wp > 100.0 || cp > 100.0 || cp > wp)) { | ||
877 | printf (_("\ | ||
878 | INPUT ERROR: C_DFP (%f) should be less than W_DFP (%.1f) and both should be between zero and 100 percent, inclusive"), | ||
879 | cp, wp); | ||
880 | print_path (mypath); | ||
881 | return ERROR; | ||
882 | } | ||
883 | else if ((iwp >= 0.0 || icp >= 0.0) && | ||
884 | (iwp < 0.0 || icp < 0.0 || iwp > 100.0 || icp > 100.0 || icp > iwp)) { | ||
885 | printf (_("\ | ||
886 | INPUT ERROR: C_IDFP (%f) should be less than W_IDFP (%.1f) and both should be between zero and 100 percent, inclusive"), | ||
887 | icp, iwp); | ||
888 | print_path (mypath); | ||
889 | return ERROR; | ||
890 | } | ||
891 | else if ((w > 0 || c > 0) && (w == 0 || c == 0 || c > w)) { | ||
892 | printf (_("\ | ||
893 | INPUT ERROR: C_DF (%lu) should be less than W_DF (%lu) and both should be greater than zero"), | ||
894 | (unsigned long)c, (unsigned long)w); | ||
895 | print_path (mypath); | ||
896 | return ERROR; | ||
897 | } | ||
898 | |||
899 | return OK; | ||
900 | } | ||
901 | |||
902 | */ | ||
903 | |||
904 | |||
905 | |||
906 | |||
907 | |||
908 | |||
909 | |||
910 | void | 859 | void |
911 | print_help (void) | 860 | print_help (void) |
912 | { | 861 | { |
@@ -1042,7 +991,7 @@ get_stats (struct parameter_list *p, struct fs_usage *fsp) { | |||
1042 | get_fs_usage (p_list->best_match->me_mountdir, p_list->best_match->me_devname, &tmpfsp); | 991 | get_fs_usage (p_list->best_match->me_mountdir, p_list->best_match->me_devname, &tmpfsp); |
1043 | get_path_stats(p_list, &tmpfsp); | 992 | get_path_stats(p_list, &tmpfsp); |
1044 | if (verbose >= 3) | 993 | if (verbose >= 3) |
1045 | printf("Group %s: adding %llu blocks sized %llu, (%s) used_units=%lu free_units=%llu total_units=%llu mult=%llu\n", | 994 | printf("Group %s: adding %lu blocks sized %lu, (%s) used_units=%lu free_units=%lu total_units=%lu mult=%lu\n", |
1046 | p_list->group, | 995 | p_list->group, |
1047 | tmpfsp.fsu_blocks, | 996 | tmpfsp.fsu_blocks, |
1048 | tmpfsp.fsu_blocksize, | 997 | tmpfsp.fsu_blocksize, |
@@ -1071,7 +1020,7 @@ get_stats (struct parameter_list *p, struct fs_usage *fsp) { | |||
1071 | first = 0; | 1020 | first = 0; |
1072 | } | 1021 | } |
1073 | if (verbose >= 3) | 1022 | if (verbose >= 3) |
1074 | printf("Group %s now has: used_units=%llu free_units=%llu total_units=%llu fsu_blocksize=%llu mult=%llu\n", | 1023 | printf("Group %s now has: used_units=%lu free_units=%lu total_units=%lu fsu_blocksize=%lu mult=%lu\n", |
1075 | p->group, | 1024 | p->group, |
1076 | p->dused_units, | 1025 | p->dused_units, |
1077 | p->dfree_units, | 1026 | p->dfree_units, |
diff --git a/plugins/check_http.c b/plugins/check_http.c index f8ec853b..41d47816 100644 --- a/plugins/check_http.c +++ b/plugins/check_http.c | |||
@@ -1070,9 +1070,8 @@ check_http (void) | |||
1070 | } | 1070 | } |
1071 | 1071 | ||
1072 | xasprintf (&buf, "%sContent-Length: %i\r\n\r\n", buf, (int)strlen (http_post_data)); | 1072 | xasprintf (&buf, "%sContent-Length: %i\r\n\r\n", buf, (int)strlen (http_post_data)); |
1073 | xasprintf (&buf, "%s%s%s", buf, http_post_data, CRLF); | 1073 | xasprintf (&buf, "%s%s", buf, http_post_data); |
1074 | } | 1074 | } else { |
1075 | else { | ||
1076 | /* or just a newline so the server knows we're done with the request */ | 1075 | /* or just a newline so the server knows we're done with the request */ |
1077 | xasprintf (&buf, "%s%s", buf, CRLF); | 1076 | xasprintf (&buf, "%s%s", buf, CRLF); |
1078 | } | 1077 | } |
@@ -1363,7 +1362,9 @@ check_http (void) | |||
1363 | #define HD2 URI_HTTP "://" URI_HOST "/" URI_PATH | 1362 | #define HD2 URI_HTTP "://" URI_HOST "/" URI_PATH |
1364 | #define HD3 URI_HTTP "://" URI_HOST ":" URI_PORT | 1363 | #define HD3 URI_HTTP "://" URI_HOST ":" URI_PORT |
1365 | #define HD4 URI_HTTP "://" URI_HOST | 1364 | #define HD4 URI_HTTP "://" URI_HOST |
1366 | #define HD5 URI_PATH | 1365 | /* relative reference redirect like //www.site.org/test https://tools.ietf.org/html/rfc3986 */ |
1366 | #define HD5 "//" URI_HOST "/" URI_PATH | ||
1367 | #define HD6 URI_PATH | ||
1367 | 1368 | ||
1368 | void | 1369 | void |
1369 | redir (char *pos, char *status_line) | 1370 | redir (char *pos, char *status_line) |
@@ -1440,9 +1441,21 @@ redir (char *pos, char *status_line) | |||
1440 | use_ssl = server_type_check (type); | 1441 | use_ssl = server_type_check (type); |
1441 | i = server_port_check (use_ssl); | 1442 | i = server_port_check (use_ssl); |
1442 | } | 1443 | } |
1444 | /* URI_HTTP, URI_HOST, URI_PATH */ | ||
1445 | else if (sscanf (pos, HD5, addr, url) == 2) { | ||
1446 | if(use_ssl){ | ||
1447 | strcpy (type,"https"); | ||
1448 | } | ||
1449 | else{ | ||
1450 | strcpy (type, server_type); | ||
1451 | } | ||
1452 | xasprintf (&url, "/%s", url); | ||
1453 | use_ssl = server_type_check (type); | ||
1454 | i = server_port_check (use_ssl); | ||
1455 | } | ||
1443 | 1456 | ||
1444 | /* URI_PATH */ | 1457 | /* URI_PATH */ |
1445 | else if (sscanf (pos, HD5, url) == 1) { | 1458 | else if (sscanf (pos, HD6, url) == 1) { |
1446 | /* relative url */ | 1459 | /* relative url */ |
1447 | if ((url[0] != '/')) { | 1460 | if ((url[0] != '/')) { |
1448 | if ((x = strrchr(server_url, '/'))) | 1461 | if ((x = strrchr(server_url, '/'))) |
diff --git a/plugins/check_load.c b/plugins/check_load.c index 0e4de54e..00f7c877 100644 --- a/plugins/check_load.c +++ b/plugins/check_load.c | |||
@@ -1,41 +1,43 @@ | |||
1 | /***************************************************************************** | 1 | /***************************************************************************** |
2 | * | 2 | * |
3 | * Monitoring check_load plugin | 3 | * Monitoring check_load plugin |
4 | * | 4 | * |
5 | * License: GPL | 5 | * License: GPL |
6 | * Copyright (c) 1999-2007 Monitoring Plugins Development Team | 6 | * Copyright (c) 1999-2007 Monitoring Plugins Development Team |
7 | * | 7 | * |
8 | * Description: | 8 | * Description: |
9 | * | 9 | * |
10 | * This file contains the check_load plugin | 10 | * This file contains the check_load plugin |
11 | * | 11 | * |
12 | * This plugin tests the current system load average. | 12 | * This plugin tests the current system load average. |
13 | * | 13 | * |
14 | * | 14 | * |
15 | * This program is free software: you can redistribute it and/or modify | 15 | * This program is free software: you can redistribute it and/or modify |
16 | * it under the terms of the GNU General Public License as published by | 16 | * it under the terms of the GNU General Public License as published by |
17 | * the Free Software Foundation, either version 3 of the License, or | 17 | * the Free Software Foundation, either version 3 of the License, or |
18 | * (at your option) any later version. | 18 | * (at your option) any later version. |
19 | * | 19 | * |
20 | * This program is distributed in the hope that it will be useful, | 20 | * This program is distributed in the hope that it will be useful, |
21 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 21 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
22 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 22 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
23 | * GNU General Public License for more details. | 23 | * GNU General Public License for more details. |
24 | * | 24 | * |
25 | * You should have received a copy of the GNU General Public License | 25 | * You should have received a copy of the GNU General Public License |
26 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 26 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
27 | * | 27 | * |
28 | * | 28 | * |
29 | *****************************************************************************/ | 29 | *****************************************************************************/ |
30 | 30 | ||
31 | const char *progname = "check_load"; | 31 | const char *progname = "check_load"; |
32 | const char *copyright = "1999-2007"; | 32 | const char *copyright = "1999-2022"; |
33 | const char *email = "devel@monitoring-plugins.org"; | 33 | const char *email = "devel@monitoring-plugins.org"; |
34 | 34 | ||
35 | #include "common.h" | 35 | #include "./common.h" |
36 | #include "runcmd.h" | 36 | #include "./runcmd.h" |
37 | #include "utils.h" | 37 | #include "./utils.h" |
38 | #include "popen.h" | 38 | #include "./popen.h" |
39 | |||
40 | #include <string.h> | ||
39 | 41 | ||
40 | #ifdef HAVE_SYS_LOADAVG_H | 42 | #ifdef HAVE_SYS_LOADAVG_H |
41 | #include <sys/loadavg.h> | 43 | #include <sys/loadavg.h> |
@@ -68,7 +70,7 @@ double cload[3] = { 0.0, 0.0, 0.0 }; | |||
68 | #define la15 la[2] | 70 | #define la15 la[2] |
69 | 71 | ||
70 | char *status_line; | 72 | char *status_line; |
71 | int take_into_account_cpus = 0; | 73 | bool take_into_account_cpus = false; |
72 | 74 | ||
73 | static void | 75 | static void |
74 | get_threshold(char *arg, double *th) | 76 | get_threshold(char *arg, double *th) |
@@ -101,7 +103,7 @@ get_threshold(char *arg, double *th) | |||
101 | int | 103 | int |
102 | main (int argc, char **argv) | 104 | main (int argc, char **argv) |
103 | { | 105 | { |
104 | int result; | 106 | int result = -1; |
105 | int i; | 107 | int i; |
106 | long numcpus; | 108 | long numcpus; |
107 | 109 | ||
@@ -164,7 +166,7 @@ main (int argc, char **argv) | |||
164 | sscanf (input_buffer, "%*[^l]load averages: %lf, %lf, %lf", &la1, &la5, &la15); | 166 | sscanf (input_buffer, "%*[^l]load averages: %lf, %lf, %lf", &la1, &la5, &la15); |
165 | } | 167 | } |
166 | else { | 168 | else { |
167 | printf (_("could not parse load from uptime %s: %s\n"), PATH_TO_UPTIME, result); | 169 | printf (_("could not parse load from uptime %s: %d\n"), PATH_TO_UPTIME, result); |
168 | return STATE_UNKNOWN; | 170 | return STATE_UNKNOWN; |
169 | } | 171 | } |
170 | 172 | ||
@@ -176,13 +178,6 @@ main (int argc, char **argv) | |||
176 | # endif | 178 | # endif |
177 | #endif | 179 | #endif |
178 | 180 | ||
179 | if (take_into_account_cpus == 1) { | ||
180 | if ((numcpus = GET_NUMBER_OF_CPUS()) > 0) { | ||
181 | la[0] = la[0] / numcpus; | ||
182 | la[1] = la[1] / numcpus; | ||
183 | la[2] = la[2] / numcpus; | ||
184 | } | ||
185 | } | ||
186 | if ((la[0] < 0.0) || (la[1] < 0.0) || (la[2] < 0.0)) { | 181 | if ((la[0] < 0.0) || (la[1] < 0.0) || (la[2] < 0.0)) { |
187 | #ifdef HAVE_GETLOADAVG | 182 | #ifdef HAVE_GETLOADAVG |
188 | printf (_("Error in getloadavg()\n")); | 183 | printf (_("Error in getloadavg()\n")); |
@@ -200,18 +195,49 @@ main (int argc, char **argv) | |||
200 | result = STATE_OK; | 195 | result = STATE_OK; |
201 | 196 | ||
202 | xasprintf(&status_line, _("load average: %.2f, %.2f, %.2f"), la1, la5, la15); | 197 | xasprintf(&status_line, _("load average: %.2f, %.2f, %.2f"), la1, la5, la15); |
198 | xasprintf(&status_line, ("total %s"), status_line); | ||
199 | |||
200 | |||
201 | double scaled_la[3] = { 0.0, 0.0, 0.0 }; | ||
202 | bool is_using_scaled_load_values = false; | ||
203 | |||
204 | if (take_into_account_cpus == true && (numcpus = GET_NUMBER_OF_CPUS()) > 0) { | ||
205 | is_using_scaled_load_values = true; | ||
206 | |||
207 | scaled_la[0] = la[0] / numcpus; | ||
208 | scaled_la[1] = la[1] / numcpus; | ||
209 | scaled_la[2] = la[2] / numcpus; | ||
210 | |||
211 | char *tmp = NULL; | ||
212 | xasprintf(&tmp, _("load average: %.2f, %.2f, %.2f"), scaled_la[0], scaled_la[1], scaled_la[2]); | ||
213 | xasprintf(&status_line, "scaled %s - %s", tmp, status_line); | ||
214 | } | ||
203 | 215 | ||
204 | for(i = 0; i < 3; i++) { | 216 | for(i = 0; i < 3; i++) { |
205 | if(la[i] > cload[i]) { | 217 | if (is_using_scaled_load_values) { |
206 | result = STATE_CRITICAL; | 218 | if(scaled_la[i] > cload[i]) { |
207 | break; | 219 | result = STATE_CRITICAL; |
220 | break; | ||
221 | } | ||
222 | else if(scaled_la[i] > wload[i]) result = STATE_WARNING; | ||
223 | } else { | ||
224 | if(la[i] > cload[i]) { | ||
225 | result = STATE_CRITICAL; | ||
226 | break; | ||
227 | } | ||
228 | else if(la[i] > wload[i]) result = STATE_WARNING; | ||
208 | } | 229 | } |
209 | else if(la[i] > wload[i]) result = STATE_WARNING; | ||
210 | } | 230 | } |
211 | 231 | ||
212 | printf("LOAD %s - %s|", state_text(result), status_line); | 232 | printf("LOAD %s - %s|", state_text(result), status_line); |
213 | for(i = 0; i < 3; i++) | 233 | for(i = 0; i < 3; i++) { |
214 | printf("load%d=%.3f;%.3f;%.3f;0; ", nums[i], la[i], wload[i], cload[i]); | 234 | if (is_using_scaled_load_values) { |
235 | printf("load%d=%.3f;;;0; ", nums[i], la[i]); | ||
236 | printf("scaled_load%d=%.3f;%.3f;%.3f;0; ", nums[i], scaled_la[i], wload[i], cload[i]); | ||
237 | } else { | ||
238 | printf("load%d=%.3f;%.3f;%.3f;0; ", nums[i], la[i], wload[i], cload[i]); | ||
239 | } | ||
240 | } | ||
215 | 241 | ||
216 | putchar('\n'); | 242 | putchar('\n'); |
217 | if (n_procs_to_show > 0) { | 243 | if (n_procs_to_show > 0) { |
@@ -255,7 +281,7 @@ process_arguments (int argc, char **argv) | |||
255 | get_threshold(optarg, cload); | 281 | get_threshold(optarg, cload); |
256 | break; | 282 | break; |
257 | case 'r': /* Divide load average by number of CPUs */ | 283 | case 'r': /* Divide load average by number of CPUs */ |
258 | take_into_account_cpus = 1; | 284 | take_into_account_cpus = true; |
259 | break; | 285 | break; |
260 | case 'V': /* version */ | 286 | case 'V': /* version */ |
261 | print_revision (progname, NP_VERSION); | 287 | print_revision (progname, NP_VERSION); |
@@ -289,7 +315,6 @@ process_arguments (int argc, char **argv) | |||
289 | } | 315 | } |
290 | 316 | ||
291 | 317 | ||
292 | |||
293 | static int | 318 | static int |
294 | validate_arguments (void) | 319 | validate_arguments (void) |
295 | { | 320 | { |
@@ -310,7 +335,6 @@ validate_arguments (void) | |||
310 | } | 335 | } |
311 | 336 | ||
312 | 337 | ||
313 | |||
314 | void | 338 | void |
315 | print_help (void) | 339 | print_help (void) |
316 | { | 340 | { |
@@ -321,7 +345,7 @@ print_help (void) | |||
321 | 345 | ||
322 | printf (_("This plugin tests the current system load average.")); | 346 | printf (_("This plugin tests the current system load average.")); |
323 | 347 | ||
324 | printf ("\n\n"); | 348 | printf ("\n\n"); |
325 | 349 | ||
326 | print_usage (); | 350 | print_usage (); |
327 | 351 | ||
@@ -329,15 +353,15 @@ print_help (void) | |||
329 | printf (UT_EXTRA_OPTS); | 353 | printf (UT_EXTRA_OPTS); |
330 | 354 | ||
331 | printf (" %s\n", "-w, --warning=WLOAD1,WLOAD5,WLOAD15"); | 355 | printf (" %s\n", "-w, --warning=WLOAD1,WLOAD5,WLOAD15"); |
332 | printf (" %s\n", _("Exit with WARNING status if load average exceeds WLOADn")); | 356 | printf (" %s\n", _("Exit with WARNING status if load average exceeds WLOADn")); |
333 | printf (" %s\n", "-c, --critical=CLOAD1,CLOAD5,CLOAD15"); | 357 | printf (" %s\n", "-c, --critical=CLOAD1,CLOAD5,CLOAD15"); |
334 | printf (" %s\n", _("Exit with CRITICAL status if load average exceed CLOADn")); | 358 | printf (" %s\n", _("Exit with CRITICAL status if load average exceed CLOADn")); |
335 | printf (" %s\n", _("the load average format is the same used by \"uptime\" and \"w\"")); | 359 | printf (" %s\n", _("the load average format is the same used by \"uptime\" and \"w\"")); |
336 | printf (" %s\n", "-r, --percpu"); | 360 | printf (" %s\n", "-r, --percpu"); |
337 | printf (" %s\n", _("Divide the load averages by the number of CPUs (when possible)")); | 361 | printf (" %s\n", _("Divide the load averages by the number of CPUs (when possible)")); |
338 | printf (" %s\n", "-n, --procs-to-show=NUMBER_OF_PROCS"); | 362 | printf (" %s\n", "-n, --procs-to-show=NUMBER_OF_PROCS"); |
339 | printf (" %s\n", _("Number of processes to show when printing the top consuming processes.")); | 363 | printf (" %s\n", _("Number of processes to show when printing the top consuming processes.")); |
340 | printf (" %s\n", _("NUMBER_OF_PROCS=0 disables this feature. Default value is 0")); | 364 | printf (" %s\n", _("NUMBER_OF_PROCS=0 disables this feature. Default value is 0")); |
341 | 365 | ||
342 | printf (UT_SUPPORT); | 366 | printf (UT_SUPPORT); |
343 | } | 367 | } |
@@ -345,8 +369,8 @@ print_help (void) | |||
345 | void | 369 | void |
346 | print_usage (void) | 370 | print_usage (void) |
347 | { | 371 | { |
348 | printf ("%s\n", _("Usage:")); | 372 | printf ("%s\n", _("Usage:")); |
349 | printf ("%s [-r] -w WLOAD1,WLOAD5,WLOAD15 -c CLOAD1,CLOAD5,CLOAD15 [-n NUMBER_OF_PROCS]\n", progname); | 373 | printf ("%s [-r] -w WLOAD1,WLOAD5,WLOAD15 -c CLOAD1,CLOAD5,CLOAD15 [-n NUMBER_OF_PROCS]\n", progname); |
350 | } | 374 | } |
351 | 375 | ||
352 | #ifdef PS_USES_PROCPCPU | 376 | #ifdef PS_USES_PROCPCPU |
@@ -384,8 +408,8 @@ static int print_top_consuming_processes() { | |||
384 | #ifdef PS_USES_PROCPCPU | 408 | #ifdef PS_USES_PROCPCPU |
385 | qsort(chld_out.line + 1, chld_out.lines - 1, sizeof(char*), cmpstringp); | 409 | qsort(chld_out.line + 1, chld_out.lines - 1, sizeof(char*), cmpstringp); |
386 | #endif /* PS_USES_PROCPCPU */ | 410 | #endif /* PS_USES_PROCPCPU */ |
387 | int lines_to_show = chld_out.lines < (n_procs_to_show + 1) | 411 | int lines_to_show = chld_out.lines < (size_t)(n_procs_to_show + 1) |
388 | ? chld_out.lines : n_procs_to_show + 1; | 412 | ? (int)chld_out.lines : n_procs_to_show + 1; |
389 | for (i = 0; i < lines_to_show; i += 1) { | 413 | for (i = 0; i < lines_to_show; i += 1) { |
390 | printf("%s\n", chld_out.line[i]); | 414 | printf("%s\n", chld_out.line[i]); |
391 | } | 415 | } |
diff --git a/plugins/check_ntp.c b/plugins/check_ntp.c index 914b40ce..8b776ba1 100644 --- a/plugins/check_ntp.c +++ b/plugins/check_ntp.c | |||
@@ -355,7 +355,7 @@ int best_offset_server(const ntp_server_results *slist, int nservers){ | |||
355 | * - we also "manually" handle resolving host names and connecting, because | 355 | * - we also "manually" handle resolving host names and connecting, because |
356 | * we have to do it in a way that our lazy macros don't handle currently :( */ | 356 | * we have to do it in a way that our lazy macros don't handle currently :( */ |
357 | double offset_request(const char *host, int *status){ | 357 | double offset_request(const char *host, int *status){ |
358 | int i=0, j=0, ga_result=0, num_hosts=0, *socklist=NULL, respnum=0; | 358 | int i=0, ga_result=0, num_hosts=0, *socklist=NULL, respnum=0; |
359 | int servers_completed=0, one_read=0, servers_readable=0, best_index=-1; | 359 | int servers_completed=0, one_read=0, servers_readable=0, best_index=-1; |
360 | time_t now_time=0, start_ts=0; | 360 | time_t now_time=0, start_ts=0; |
361 | ntp_message *req=NULL; | 361 | ntp_message *req=NULL; |
@@ -488,7 +488,7 @@ double offset_request(const char *host, int *status){ | |||
488 | /* cleanup */ | 488 | /* cleanup */ |
489 | /* FIXME: Not closing the socket to avoid re-use of the local port | 489 | /* FIXME: Not closing the socket to avoid re-use of the local port |
490 | * which can cause old NTP packets to be read instead of NTP control | 490 | * which can cause old NTP packets to be read instead of NTP control |
491 | * pactets in jitter_request(). THERE MUST BE ANOTHER WAY... | 491 | * packets in jitter_request(). THERE MUST BE ANOTHER WAY... |
492 | * for(j=0; j<num_hosts; j++){ close(socklist[j]); } */ | 492 | * for(j=0; j<num_hosts; j++){ close(socklist[j]); } */ |
493 | free(socklist); | 493 | free(socklist); |
494 | free(ufds); | 494 | free(ufds); |
@@ -512,7 +512,7 @@ setup_control_request(ntp_control_message *p, uint8_t opcode, uint16_t seq){ | |||
512 | } | 512 | } |
513 | 513 | ||
514 | /* XXX handle responses with the error bit set */ | 514 | /* XXX handle responses with the error bit set */ |
515 | double jitter_request(const char *host, int *status){ | 515 | double jitter_request(int *status){ |
516 | int conn=-1, i, npeers=0, num_candidates=0, syncsource_found=0; | 516 | int conn=-1, i, npeers=0, num_candidates=0, syncsource_found=0; |
517 | int run=0, min_peer_sel=PEER_INCLUDED, num_selected=0, num_valid=0; | 517 | int run=0, min_peer_sel=PEER_INCLUDED, num_selected=0, num_valid=0; |
518 | int peers_size=0, peer_offset=0; | 518 | int peers_size=0, peer_offset=0; |
@@ -803,7 +803,7 @@ int main(int argc, char *argv[]){ | |||
803 | * (for example) will result in an error | 803 | * (for example) will result in an error |
804 | */ | 804 | */ |
805 | if(do_jitter){ | 805 | if(do_jitter){ |
806 | jitter=jitter_request(server_address, &jitter_result); | 806 | jitter=jitter_request(&jitter_result); |
807 | result = max_state_alt(result, get_status(jitter, jitter_thresholds)); | 807 | result = max_state_alt(result, get_status(jitter, jitter_thresholds)); |
808 | /* -1 indicates that we couldn't calculate the jitter | 808 | /* -1 indicates that we couldn't calculate the jitter |
809 | * Only overrides STATE_OK from the offset */ | 809 | * Only overrides STATE_OK from the offset */ |
diff --git a/plugins/check_pgsql.c b/plugins/check_pgsql.c index c893386c..c26cd439 100644 --- a/plugins/check_pgsql.c +++ b/plugins/check_pgsql.c | |||
@@ -69,7 +69,6 @@ int process_arguments (int, char **); | |||
69 | int validate_arguments (void); | 69 | int validate_arguments (void); |
70 | void print_usage (void); | 70 | void print_usage (void); |
71 | void print_help (void); | 71 | void print_help (void); |
72 | int is_pg_dbname (char *); | ||
73 | int is_pg_logname (char *); | 72 | int is_pg_logname (char *); |
74 | int do_query (PGconn *, char *); | 73 | int do_query (PGconn *, char *); |
75 | 74 | ||
@@ -347,10 +346,10 @@ process_arguments (int argc, char **argv) | |||
347 | pgport = optarg; | 346 | pgport = optarg; |
348 | break; | 347 | break; |
349 | case 'd': /* database name */ | 348 | case 'd': /* database name */ |
350 | if (!is_pg_dbname (optarg)) /* checks length and valid chars */ | 349 | if (strlen(optarg) >= NAMEDATALEN) { |
351 | usage2 (_("Database name is not valid"), optarg); | 350 | usage2 (_("Database name exceeds the maximum length"), optarg); |
352 | else /* we know length, and know optarg is terminated, so us strcpy */ | 351 | } |
353 | snprintf(dbName, NAMEDATALEN, "%s", optarg); | 352 | snprintf(dbName, NAMEDATALEN, "%s", optarg); |
354 | break; | 353 | break; |
355 | case 'l': /* login name */ | 354 | case 'l': /* login name */ |
356 | if (!is_pg_logname (optarg)) | 355 | if (!is_pg_logname (optarg)) |
@@ -414,45 +413,6 @@ validate_arguments () | |||
414 | return OK; | 413 | return OK; |
415 | } | 414 | } |
416 | 415 | ||
417 | |||
418 | /****************************************************************************** | ||
419 | |||
420 | @@- | ||
421 | <sect3> | ||
422 | <title>is_pg_dbname</title> | ||
423 | |||
424 | <para>&PROTO_is_pg_dbname;</para> | ||
425 | |||
426 | <para>Given a database name, this function returns TRUE if the string | ||
427 | is a valid PostgreSQL database name, and returns false if it is | ||
428 | not.</para> | ||
429 | |||
430 | <para>Valid PostgreSQL database names are less than &NAMEDATALEN; | ||
431 | characters long and consist of letters, numbers, and underscores. The | ||
432 | first character cannot be a number, however.</para> | ||
433 | |||
434 | </sect3> | ||
435 | -@@ | ||
436 | ******************************************************************************/ | ||
437 | |||
438 | |||
439 | |||
440 | int | ||
441 | is_pg_dbname (char *dbname) | ||
442 | { | ||
443 | char txt[NAMEDATALEN]; | ||
444 | char tmp[NAMEDATALEN]; | ||
445 | if (strlen (dbname) > NAMEDATALEN - 1) | ||
446 | return (FALSE); | ||
447 | strncpy (txt, dbname, NAMEDATALEN - 1); | ||
448 | txt[NAMEDATALEN - 1] = 0; | ||
449 | if (sscanf (txt, "%[_a-zA-Z]%[^_a-zA-Z0-9-]", tmp, tmp) == 1) | ||
450 | return (TRUE); | ||
451 | if (sscanf (txt, "%[_a-zA-Z]%[_a-zA-Z0-9-]%[^_a-zA-Z0-9-]", tmp, tmp, tmp) == | ||
452 | 2) return (TRUE); | ||
453 | return (FALSE); | ||
454 | } | ||
455 | |||
456 | /** | 416 | /** |
457 | 417 | ||
458 | the tango program should eventually create an entity here based on the | 418 | the tango program should eventually create an entity here based on the |
diff --git a/plugins/check_swap.c b/plugins/check_swap.c index ff58b15f..a607da1e 100644 --- a/plugins/check_swap.c +++ b/plugins/check_swap.c | |||
@@ -410,7 +410,6 @@ check_swap(float free_swap_mb, float total_swap_mb) | |||
410 | uint64_t usage_percentage = ((total_swap_mb - free_swap_mb) / total_swap_mb) * 100; | 410 | uint64_t usage_percentage = ((total_swap_mb - free_swap_mb) / total_swap_mb) * 100; |
411 | 411 | ||
412 | if (crit.is_percentage && | 412 | if (crit.is_percentage && |
413 | usage_percentage >= 0 && | ||
414 | crit.value != 0 && | 413 | crit.value != 0 && |
415 | usage_percentage >= (100 - crit.value)) | 414 | usage_percentage >= (100 - crit.value)) |
416 | { | 415 | { |
@@ -418,7 +417,6 @@ check_swap(float free_swap_mb, float total_swap_mb) | |||
418 | } | 417 | } |
419 | 418 | ||
420 | if (warn.is_percentage && | 419 | if (warn.is_percentage && |
421 | usage_percentage >= 0 && | ||
422 | warn.value != 0 && | 420 | warn.value != 0 && |
423 | usage_percentage >= (100 - warn.value)) | 421 | usage_percentage >= (100 - warn.value)) |
424 | { | 422 | { |
@@ -475,10 +473,9 @@ process_arguments (int argc, char **argv) | |||
475 | if (is_uint64(optarg, &warn.value)) { | 473 | if (is_uint64(optarg, &warn.value)) { |
476 | if (warn.value > 100) { | 474 | if (warn.value > 100) { |
477 | usage4 (_("Warning threshold percentage must be <= 100!")); | 475 | usage4 (_("Warning threshold percentage must be <= 100!")); |
478 | } else { | ||
479 | break; | ||
480 | } | 476 | } |
481 | } | 477 | } |
478 | break; | ||
482 | } else { | 479 | } else { |
483 | /* It's Bytes */ | 480 | /* It's Bytes */ |
484 | warn.is_percentage = 0; | 481 | warn.is_percentage = 0; |
@@ -506,10 +503,9 @@ process_arguments (int argc, char **argv) | |||
506 | if (is_uint64(optarg, &crit.value)) { | 503 | if (is_uint64(optarg, &crit.value)) { |
507 | if (crit.value> 100) { | 504 | if (crit.value> 100) { |
508 | usage4 (_("Critical threshold percentage must be <= 100!")); | 505 | usage4 (_("Critical threshold percentage must be <= 100!")); |
509 | } else { | ||
510 | break; | ||
511 | } | 506 | } |
512 | } | 507 | } |
508 | break; | ||
513 | } else { | 509 | } else { |
514 | /* It's Bytes */ | 510 | /* It's Bytes */ |
515 | crit.is_percentage = 0; | 511 | crit.is_percentage = 0; |
@@ -527,6 +523,7 @@ process_arguments (int argc, char **argv) | |||
527 | if ((no_swap_state = mp_translate_state(optarg)) == ERROR) { | 523 | if ((no_swap_state = mp_translate_state(optarg)) == ERROR) { |
528 | usage4 (_("no-swap result must be a valid state name (OK, WARNING, CRITICAL, UNKNOWN) or integer (0-3).")); | 524 | usage4 (_("no-swap result must be a valid state name (OK, WARNING, CRITICAL, UNKNOWN) or integer (0-3).")); |
529 | } | 525 | } |
526 | break; | ||
530 | case 'v': /* verbose */ | 527 | case 'v': /* verbose */ |
531 | verbose++; | 528 | verbose++; |
532 | break; | 529 | break; |
diff --git a/plugins/t/check_curl.t b/plugins/t/check_curl.t index 693f4b25..eae98cc1 100644 --- a/plugins/t/check_curl.t +++ b/plugins/t/check_curl.t | |||
@@ -1,15 +1,22 @@ | |||
1 | #! /usr/bin/perl -w -I .. | 1 | #! /usr/bin/perl -w -I .. |
2 | # | 2 | # |
3 | # HyperText Transfer Protocol (HTTP) Test via check_http | 3 | # HyperText Transfer Protocol (HTTP) Test via check_curl |
4 | # | 4 | # |
5 | # | 5 | # |
6 | 6 | ||
7 | use strict; | 7 | use strict; |
8 | use Test::More; | 8 | use Test::More; |
9 | use POSIX qw/mktime strftime/; | 9 | use POSIX qw/mktime strftime/; |
10 | use NPTest; | ||
11 | 10 | ||
12 | plan tests => 57; | 11 | use vars qw($tests $has_ipv6); |
12 | |||
13 | BEGIN { | ||
14 | use NPTest; | ||
15 | $has_ipv6 = NPTest::has_ipv6(); | ||
16 | $tests = $has_ipv6 ? 59 : 57; | ||
17 | plan tests => $tests; | ||
18 | } | ||
19 | |||
13 | 20 | ||
14 | my $successOutput = '/OK.*HTTP.*second/'; | 21 | my $successOutput = '/OK.*HTTP.*second/'; |
15 | 22 | ||
@@ -18,6 +25,7 @@ my $plugin = 'check_http'; | |||
18 | $plugin = 'check_curl' if $0 =~ m/check_curl/mx; | 25 | $plugin = 'check_curl' if $0 =~ m/check_curl/mx; |
19 | 26 | ||
20 | my $host_tcp_http = getTestParameter("NP_HOST_TCP_HTTP", "A host providing the HTTP Service (a web server)", "localhost"); | 27 | my $host_tcp_http = getTestParameter("NP_HOST_TCP_HTTP", "A host providing the HTTP Service (a web server)", "localhost"); |
28 | my $host_tcp_http_ipv6 = getTestParameter("NP_HOST_TCP_HTTP_IPV6", "An IPv6 address providing a HTTP Service (a web server)", "::1"); | ||
21 | my $host_tls_http = getTestParameter("NP_HOST_TLS_HTTP", "A host providing the HTTPS Service (a tls web server)", "localhost"); | 29 | my $host_tls_http = getTestParameter("NP_HOST_TLS_HTTP", "A host providing the HTTPS Service (a tls web server)", "localhost"); |
22 | my $host_tls_cert = getTestParameter("NP_HOST_TLS_CERT", "the common name of the certificate.", "localhost"); | 30 | my $host_tls_cert = getTestParameter("NP_HOST_TLS_CERT", "the common name of the certificate.", "localhost"); |
23 | my $host_nonresponsive = getTestParameter("NP_HOST_NONRESPONSIVE", "The hostname of system not responsive to network requests", "10.0.0.1"); | 31 | my $host_nonresponsive = getTestParameter("NP_HOST_NONRESPONSIVE", "The hostname of system not responsive to network requests", "10.0.0.1"); |
@@ -31,26 +39,35 @@ my $faketime = -x '/usr/bin/faketime' ? 1 : 0; | |||
31 | 39 | ||
32 | 40 | ||
33 | $res = NPTest->testCmd( | 41 | $res = NPTest->testCmd( |
34 | "./$plugin $host_tcp_http -wt 300 -ct 600" | 42 | "./$plugin $host_tcp_http -wt 300 -ct 600" |
35 | ); | 43 | ); |
36 | cmp_ok( $res->return_code, '==', 0, "Webserver $host_tcp_http responded" ); | 44 | cmp_ok( $res->return_code, '==', 0, "Webserver $host_tcp_http responded" ); |
37 | like( $res->output, $successOutput, "Output OK" ); | 45 | like( $res->output, $successOutput, "Output OK" ); |
38 | 46 | ||
47 | if ($has_ipv6) { | ||
48 | # Test for IPv6 formatting | ||
49 | $res = NPTest->testCmd( | ||
50 | "./$plugin -I $host_tcp_http_ipv6 -wt 300 -ct 600" | ||
51 | ); | ||
52 | cmp_ok( $res->return_code, '==', 0, "IPv6 URL formatting is working" ); | ||
53 | like( $res->output, $successOutput, "Output OK" ); | ||
54 | } | ||
55 | |||
39 | $res = NPTest->testCmd( | 56 | $res = NPTest->testCmd( |
40 | "./$plugin $host_tcp_http -wt 300 -ct 600 -v -v -v -k 'bob:there' -k 'carl:frown'" | 57 | "./$plugin $host_tcp_http -wt 300 -ct 600 -v -v -v -k 'bob:there' -k 'carl:frown'" |
41 | ); | 58 | ); |
42 | like( $res->output, '/bob:there\r\ncarl:frown\r\n/', "Got headers with multiple -k options" ); | 59 | like( $res->output, '/bob:there\r\ncarl:frown\r\n/', "Got headers with multiple -k options" ); |
43 | 60 | ||
44 | $res = NPTest->testCmd( | 61 | $res = NPTest->testCmd( |
45 | "./$plugin $host_nonresponsive -wt 1 -ct 2 -t 3" | 62 | "./$plugin $host_nonresponsive -wt 1 -ct 2 -t 3" |
46 | ); | 63 | ); |
47 | cmp_ok( $res->return_code, '==', 2, "Webserver $host_nonresponsive not responding" ); | 64 | cmp_ok( $res->return_code, '==', 2, "Webserver $host_nonresponsive not responding" ); |
48 | # was CRITICAL only, but both check_curl and check_http print HTTP CRITICAL (puzzle?!) | 65 | # was CRITICAL only, but both check_curl and check_http print HTTP CRITICAL (puzzle?!) |
49 | like( $res->output, "/HTTP CRITICAL - Invalid HTTP response received from host on port 80: cURL returned 28 - Connection timed out after/", "Output OK"); | 66 | like( $res->output, "/HTTP CRITICAL - Invalid HTTP response received from host on port 80: cURL returned 28 - Connection timed out after/", "Output OK"); |
50 | 67 | ||
51 | $res = NPTest->testCmd( | 68 | $res = NPTest->testCmd( |
52 | "./$plugin $hostname_invalid -wt 1 -ct 2" | 69 | "./$plugin $hostname_invalid -wt 1 -ct 2" |
53 | ); | 70 | ); |
54 | cmp_ok( $res->return_code, '==', 2, "Webserver $hostname_invalid not valid" ); | 71 | cmp_ok( $res->return_code, '==', 2, "Webserver $hostname_invalid not valid" ); |
55 | # The first part of the message comes from the OS catalogue, so cannot check this. | 72 | # The first part of the message comes from the OS catalogue, so cannot check this. |
56 | # On Debian, it is Name or service not known, on Darwin, it is No address associated with nodename | 73 | # On Debian, it is Name or service not known, on Darwin, it is No address associated with nodename |
diff --git a/plugins/t/check_load.t b/plugins/t/check_load.t index 60837ef6..bba8947c 100644 --- a/plugins/t/check_load.t +++ b/plugins/t/check_load.t | |||
@@ -11,10 +11,12 @@ 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 = "/^LOAD OK - load average: $loadValue, $loadValue, $loadValue/"; | 14 | my $successOutput = "/^LOAD OK - total load average: $loadValue, $loadValue, $loadValue/"; |
15 | my $failureOutput = "/^LOAD CRITICAL - load average: $loadValue, $loadValue, $loadValue/"; | 15 | my $successScaledOutput = "/^LOAD OK - scaled load average: $loadValue, $loadValue, $loadValue - total load average: $loadValue, $loadValue, $loadValue/"; |
16 | my $failureOutput = "/^LOAD CRITICAL - total load average: $loadValue, $loadValue, $loadValue/"; | ||
17 | my $failurScaledOutput = "/^LOAD CRITICAL - scaled load average: $loadValue, $loadValue, $loadValue - total load average: $loadValue, $loadValue, $loadValue/"; | ||
16 | 18 | ||
17 | plan tests => 11; | 19 | plan tests => 13; |
18 | 20 | ||
19 | $res = NPTest->testCmd( "./check_load -w 100,100,100 -c 100,100,100" ); | 21 | $res = NPTest->testCmd( "./check_load -w 100,100,100 -c 100,100,100" ); |
20 | cmp_ok( $res->return_code, 'eq', 0, "load not over 100"); | 22 | cmp_ok( $res->return_code, 'eq', 0, "load not over 100"); |
@@ -26,7 +28,7 @@ like( $res->output, $failureOutput, "Output OK"); | |||
26 | 28 | ||
27 | $res = NPTest->testCmd( "./check_load -r -w 0,0,0 -c 0,0,0" ); | 29 | $res = NPTest->testCmd( "./check_load -r -w 0,0,0 -c 0,0,0" ); |
28 | cmp_ok( $res->return_code, 'eq', 2, "Load over 0 with per cpu division"); | 30 | cmp_ok( $res->return_code, 'eq', 2, "Load over 0 with per cpu division"); |
29 | like( $res->output, $failureOutput, "Output OK"); | 31 | like( $res->output, $failurScaledOutput, "Output OK"); |
30 | 32 | ||
31 | $res = NPTest->testCmd( "./check_load -w 100 -c 100,110" ); | 33 | $res = NPTest->testCmd( "./check_load -w 100 -c 100,110" ); |
32 | cmp_ok( $res->return_code, 'eq', 0, "Plugin can handle non-triplet-arguments"); | 34 | cmp_ok( $res->return_code, 'eq', 0, "Plugin can handle non-triplet-arguments"); |
@@ -34,3 +36,8 @@ like( $res->output, $successOutput, "Output OK"); | |||
34 | like( $res->perf_output, "/load1=$loadValue;100.000;100.000/", "Test handling of non triplet thresholds (load1)"); | 36 | like( $res->perf_output, "/load1=$loadValue;100.000;100.000/", "Test handling of non triplet thresholds (load1)"); |
35 | like( $res->perf_output, "/load5=$loadValue;100.000;110.000/", "Test handling of non triplet thresholds (load5)"); | 37 | like( $res->perf_output, "/load5=$loadValue;100.000;110.000/", "Test handling of non triplet thresholds (load5)"); |
36 | like( $res->perf_output, "/load15=$loadValue;100.000;110.000/", "Test handling of non triplet thresholds (load15)"); | 38 | like( $res->perf_output, "/load15=$loadValue;100.000;110.000/", "Test handling of non triplet thresholds (load15)"); |
39 | |||
40 | |||
41 | $res = NPTest->testCmd( "./check_load -w 100,100,100 -c 100,100,100 -r" ); | ||
42 | cmp_ok( $res->return_code, 'eq', 0, "load not over 100"); | ||
43 | like( $res->output, $successScaledOutput, "Output OK"); | ||
diff --git a/plugins/utils.c b/plugins/utils.c index 17dd5814..b4214c61 100644 --- a/plugins/utils.c +++ b/plugins/utils.c | |||
@@ -615,27 +615,27 @@ char *perfdata_uint64 (const char *label, | |||
615 | char *data = NULL; | 615 | char *data = NULL; |
616 | 616 | ||
617 | if (strpbrk (label, "'= ")) | 617 | if (strpbrk (label, "'= ")) |
618 | xasprintf (&data, "'%s'=%ld%s;", label, val, uom); | 618 | xasprintf (&data, "'%s'=%" PRIu64 "%s;", label, val, uom); |
619 | else | 619 | else |
620 | xasprintf (&data, "%s=%ld%s;", label, val, uom); | 620 | xasprintf (&data, "%s=%" PRIu64 "%s;", label, val, uom); |
621 | 621 | ||
622 | if (warnp) | 622 | if (warnp) |
623 | xasprintf (&data, "%s%lu;", data, warn); | 623 | xasprintf (&data, "%s%" PRIu64 ";", data, warn); |
624 | else | 624 | else |
625 | xasprintf (&data, "%s;", data); | 625 | xasprintf (&data, "%s;", data); |
626 | 626 | ||
627 | if (critp) | 627 | if (critp) |
628 | xasprintf (&data, "%s%lu;", data, crit); | 628 | xasprintf (&data, "%s%" PRIu64 ";", data, crit); |
629 | else | 629 | else |
630 | xasprintf (&data, "%s;", data); | 630 | xasprintf (&data, "%s;", data); |
631 | 631 | ||
632 | if (minp) | 632 | if (minp) |
633 | xasprintf (&data, "%s%lu;", data, minv); | 633 | xasprintf (&data, "%s%" PRIu64 ";", data, minv); |
634 | else | 634 | else |
635 | xasprintf (&data, "%s;", data); | 635 | xasprintf (&data, "%s;", data); |
636 | 636 | ||
637 | if (maxp) | 637 | if (maxp) |
638 | xasprintf (&data, "%s%lu", data, maxv); | 638 | xasprintf (&data, "%s%" PRIu64, data, maxv); |
639 | 639 | ||
640 | return data; | 640 | return data; |
641 | } | 641 | } |
@@ -656,27 +656,27 @@ char *perfdata_int64 (const char *label, | |||
656 | char *data = NULL; | 656 | char *data = NULL; |
657 | 657 | ||
658 | if (strpbrk (label, "'= ")) | 658 | if (strpbrk (label, "'= ")) |
659 | xasprintf (&data, "'%s'=%ld%s;", label, val, uom); | 659 | xasprintf (&data, "'%s'=%" PRId64 "%s;", label, val, uom); |
660 | else | 660 | else |
661 | xasprintf (&data, "%s=%ld%s;", label, val, uom); | 661 | xasprintf (&data, "%s=%" PRId64 "%s;", label, val, uom); |
662 | 662 | ||
663 | if (warnp) | 663 | if (warnp) |
664 | xasprintf (&data, "%s%ld;", data, warn); | 664 | xasprintf (&data, "%s%" PRId64 ";", data, warn); |
665 | else | 665 | else |
666 | xasprintf (&data, "%s;", data); | 666 | xasprintf (&data, "%s;", data); |
667 | 667 | ||
668 | if (critp) | 668 | if (critp) |
669 | xasprintf (&data, "%s%ld;", data, crit); | 669 | xasprintf (&data, "%s%" PRId64 ";", data, crit); |
670 | else | 670 | else |
671 | xasprintf (&data, "%s;", data); | 671 | xasprintf (&data, "%s;", data); |
672 | 672 | ||
673 | if (minp) | 673 | if (minp) |
674 | xasprintf (&data, "%s%ld;", data, minv); | 674 | xasprintf (&data, "%s%" PRId64 ";", data, minv); |
675 | else | 675 | else |
676 | xasprintf (&data, "%s;", data); | 676 | xasprintf (&data, "%s;", data); |
677 | 677 | ||
678 | if (maxp) | 678 | if (maxp) |
679 | xasprintf (&data, "%s%ld", data, maxv); | 679 | xasprintf (&data, "%s%" PRId64, data, maxv); |
680 | 680 | ||
681 | return data; | 681 | return data; |
682 | } | 682 | } |