From fbbc9fcbd566db60058047870fbd6a2105e96663 Mon Sep 17 00:00:00 2001 From: Lorenz <12514511+RincewindsHat@users.noreply.github.com> Date: Sun, 11 Sep 2022 06:29:17 +0200 Subject: Check swap compiler warnings (#1756) * Fix compiler warnings * Fix superfluous whitespaces --- plugins/check_swap.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'plugins') 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) uint64_t usage_percentage = ((total_swap_mb - free_swap_mb) / total_swap_mb) * 100; if (crit.is_percentage && - usage_percentage >= 0 && crit.value != 0 && usage_percentage >= (100 - crit.value)) { @@ -418,7 +417,6 @@ check_swap(float free_swap_mb, float total_swap_mb) } if (warn.is_percentage && - usage_percentage >= 0 && warn.value != 0 && usage_percentage >= (100 - warn.value)) { @@ -475,10 +473,9 @@ process_arguments (int argc, char **argv) if (is_uint64(optarg, &warn.value)) { if (warn.value > 100) { usage4 (_("Warning threshold percentage must be <= 100!")); - } else { - break; } } + break; } else { /* It's Bytes */ warn.is_percentage = 0; @@ -506,10 +503,9 @@ process_arguments (int argc, char **argv) if (is_uint64(optarg, &crit.value)) { if (crit.value> 100) { usage4 (_("Critical threshold percentage must be <= 100!")); - } else { - break; } } + break; } else { /* It's Bytes */ crit.is_percentage = 0; @@ -527,6 +523,7 @@ process_arguments (int argc, char **argv) if ((no_swap_state = mp_translate_state(optarg)) == ERROR) { usage4 (_("no-swap result must be a valid state name (OK, WARNING, CRITICAL, UNKNOWN) or integer (0-3).")); } + break; case 'v': /* verbose */ verbose++; break; -- cgit v1.2.3-74-g34f1 From a9cdbc8959a7722494700aaddc63f0c7e0d34062 Mon Sep 17 00:00:00 2001 From: Lorenz <12514511+RincewindsHat@users.noreply.github.com> Date: Sun, 11 Sep 2022 06:29:36 +0200 Subject: Check load compiler warnings (#1759) * Fix compiler warnings due to implizit conversion and formats * Make includes more specific and complement them * Formatting fixes --- plugins/check_load.c | 66 ++++++++++++++++++++++++++-------------------------- 1 file changed, 33 insertions(+), 33 deletions(-) (limited to 'plugins') diff --git a/plugins/check_load.c b/plugins/check_load.c index 0e4de54e..d1bb30a4 100644 --- a/plugins/check_load.c +++ b/plugins/check_load.c @@ -1,41 +1,43 @@ /***************************************************************************** -* +* * Monitoring check_load plugin -* +* * License: GPL * Copyright (c) 1999-2007 Monitoring Plugins Development Team -* +* * Description: -* +* * This file contains the check_load plugin -* +* * This plugin tests the current system load average. -* -* +* +* * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. -* +* * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. -* +* * You should have received a copy of the GNU General Public License * along with this program. If not, see . -* -* +* +* *****************************************************************************/ const char *progname = "check_load"; const char *copyright = "1999-2007"; const char *email = "devel@monitoring-plugins.org"; -#include "common.h" -#include "runcmd.h" -#include "utils.h" -#include "popen.h" +#include "./common.h" +#include "./runcmd.h" +#include "./utils.h" +#include "./popen.h" + +#include #ifdef HAVE_SYS_LOADAVG_H #include @@ -101,7 +103,7 @@ get_threshold(char *arg, double *th) int main (int argc, char **argv) { - int result; + int result = -1; int i; long numcpus; @@ -164,7 +166,7 @@ main (int argc, char **argv) sscanf (input_buffer, "%*[^l]load averages: %lf, %lf, %lf", &la1, &la5, &la15); } else { - printf (_("could not parse load from uptime %s: %s\n"), PATH_TO_UPTIME, result); + printf (_("could not parse load from uptime %s: %d\n"), PATH_TO_UPTIME, result); return STATE_UNKNOWN; } @@ -289,7 +291,6 @@ process_arguments (int argc, char **argv) } - static int validate_arguments (void) { @@ -310,7 +311,6 @@ validate_arguments (void) } - void print_help (void) { @@ -321,7 +321,7 @@ print_help (void) printf (_("This plugin tests the current system load average.")); - printf ("\n\n"); + printf ("\n\n"); print_usage (); @@ -329,15 +329,15 @@ print_help (void) printf (UT_EXTRA_OPTS); printf (" %s\n", "-w, --warning=WLOAD1,WLOAD5,WLOAD15"); - printf (" %s\n", _("Exit with WARNING status if load average exceeds WLOADn")); - printf (" %s\n", "-c, --critical=CLOAD1,CLOAD5,CLOAD15"); - printf (" %s\n", _("Exit with CRITICAL status if load average exceed CLOADn")); - printf (" %s\n", _("the load average format is the same used by \"uptime\" and \"w\"")); - printf (" %s\n", "-r, --percpu"); - printf (" %s\n", _("Divide the load averages by the number of CPUs (when possible)")); - printf (" %s\n", "-n, --procs-to-show=NUMBER_OF_PROCS"); - printf (" %s\n", _("Number of processes to show when printing the top consuming processes.")); - printf (" %s\n", _("NUMBER_OF_PROCS=0 disables this feature. Default value is 0")); + printf (" %s\n", _("Exit with WARNING status if load average exceeds WLOADn")); + printf (" %s\n", "-c, --critical=CLOAD1,CLOAD5,CLOAD15"); + printf (" %s\n", _("Exit with CRITICAL status if load average exceed CLOADn")); + printf (" %s\n", _("the load average format is the same used by \"uptime\" and \"w\"")); + printf (" %s\n", "-r, --percpu"); + printf (" %s\n", _("Divide the load averages by the number of CPUs (when possible)")); + printf (" %s\n", "-n, --procs-to-show=NUMBER_OF_PROCS"); + printf (" %s\n", _("Number of processes to show when printing the top consuming processes.")); + printf (" %s\n", _("NUMBER_OF_PROCS=0 disables this feature. Default value is 0")); printf (UT_SUPPORT); } @@ -345,8 +345,8 @@ print_help (void) void print_usage (void) { - printf ("%s\n", _("Usage:")); - printf ("%s [-r] -w WLOAD1,WLOAD5,WLOAD15 -c CLOAD1,CLOAD5,CLOAD15 [-n NUMBER_OF_PROCS]\n", progname); + printf ("%s\n", _("Usage:")); + printf ("%s [-r] -w WLOAD1,WLOAD5,WLOAD15 -c CLOAD1,CLOAD5,CLOAD15 [-n NUMBER_OF_PROCS]\n", progname); } #ifdef PS_USES_PROCPCPU @@ -384,8 +384,8 @@ static int print_top_consuming_processes() { #ifdef PS_USES_PROCPCPU qsort(chld_out.line + 1, chld_out.lines - 1, sizeof(char*), cmpstringp); #endif /* PS_USES_PROCPCPU */ - int lines_to_show = chld_out.lines < (n_procs_to_show + 1) - ? chld_out.lines : n_procs_to_show + 1; + int lines_to_show = chld_out.lines < (size_t)(n_procs_to_show + 1) + ? (int)chld_out.lines : n_procs_to_show + 1; for (i = 0; i < lines_to_show; i += 1) { printf("%s\n", chld_out.line[i]); } -- cgit v1.2.3-74-g34f1 From ef5796255268cd663a4e66820cf1bd883055ba00 Mon Sep 17 00:00:00 2001 From: Lorenz <12514511+RincewindsHat@users.noreply.github.com> Date: Sun, 11 Sep 2022 06:29:58 +0200 Subject: Check disk compiler warnings (#1758) * Use unused variable * Proper format strings for printf * Use proper functions for absolute values * Remove and add comments at some places --- plugins/check_disk.c | 67 +++++++--------------------------------------------- 1 file changed, 8 insertions(+), 59 deletions(-) (limited to 'plugins') 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) char *perf_ilabel; char *preamble; char *flag_header; - double inode_space_pct; int temp_result; struct mount_entry *me; @@ -288,7 +287,7 @@ main (int argc, char **argv) get_stats (path, &fsp); if (verbose >= 3) { - 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", + 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", me->me_mountdir, path->dused_pct, path->dfree_pct, @@ -369,10 +368,10 @@ main (int argc, char **argv) critical_high_tide = UINT64_MAX; if (path->freeinodes_percent->warning != NULL) { - warning_high_tide = llabs( min( (double) warning_high_tide, (double) (1.0 - path->freeinodes_percent->warning->end/100)*path->inodes_total )); + warning_high_tide = (uint64_t) fabs( min( (double) warning_high_tide, (double) (1.0 - path->freeinodes_percent->warning->end/100)*path->inodes_total )); } if (path->freeinodes_percent->critical != NULL) { - critical_high_tide = llabs( min( (double) critical_high_tide, (double) (1.0 - path->freeinodes_percent->critical->end/100)*path->inodes_total )); + critical_high_tide = (uint64_t) fabs( min( (double) critical_high_tide, (double) (1.0 - path->freeinodes_percent->critical->end/100)*path->inodes_total )); } 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) xasprintf(&output, "%s inode=%.0f%%)%s;", output, path->dfree_inodes_percent, ((disk_result && verbose >= 1) ? "]" : "")); } free(flag_header); - /* TODO: Need to do a similar debug line - 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%%"), - details, dfree_units, dtotal_units, units, dfree_pct, inode_space_pct, - me->me_devname, me->me_type, me->me_mountdir, - (unsigned long)w_df, (unsigned long)c_df, w_dfp, c_dfp); - */ - } - } if (verbose >= 2) @@ -689,6 +680,7 @@ process_arguments (int argc, char **argv) break; case 'I': cflags |= REG_ICASE; + // Intentional fallthrough case 'i': if (!path_selected) 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) case 'A': optarg = strdup(".*"); + // Intentional fallthrough case 'R': cflags |= REG_ICASE; + // Intentional fallthrough case 'r': if (! (warn_freespace_units || crit_freespace_units || warn_freespace_percent || crit_freespace_percent || warn_usedspace_units || crit_usedspace_units || @@ -862,51 +856,6 @@ set_all_thresholds (struct parameter_list *path) set_thresholds(&path->freeinodes_percent, warn_freeinodes_percent, crit_freeinodes_percent); } -/* TODO: Remove? - -int -validate_arguments (uintmax_t w, uintmax_t c, double wp, double cp, double iwp, double icp, char *mypath) -{ - if (w < 0 && c < 0 && wp < 0.0 && cp < 0.0) { - printf (_("INPUT ERROR: No thresholds specified")); - print_path (mypath); - return ERROR; - } - else if ((wp >= 0.0 || cp >= 0.0) && - (wp < 0.0 || cp < 0.0 || wp > 100.0 || cp > 100.0 || cp > wp)) { - printf (_("\ -INPUT ERROR: C_DFP (%f) should be less than W_DFP (%.1f) and both should be between zero and 100 percent, inclusive"), - cp, wp); - print_path (mypath); - return ERROR; - } - else if ((iwp >= 0.0 || icp >= 0.0) && - (iwp < 0.0 || icp < 0.0 || iwp > 100.0 || icp > 100.0 || icp > iwp)) { - printf (_("\ -INPUT ERROR: C_IDFP (%f) should be less than W_IDFP (%.1f) and both should be between zero and 100 percent, inclusive"), - icp, iwp); - print_path (mypath); - return ERROR; - } - else if ((w > 0 || c > 0) && (w == 0 || c == 0 || c > w)) { - printf (_("\ -INPUT ERROR: C_DF (%lu) should be less than W_DF (%lu) and both should be greater than zero"), - (unsigned long)c, (unsigned long)w); - print_path (mypath); - return ERROR; - } - - return OK; -} - -*/ - - - - - - - void print_help (void) { @@ -1042,7 +991,7 @@ get_stats (struct parameter_list *p, struct fs_usage *fsp) { get_fs_usage (p_list->best_match->me_mountdir, p_list->best_match->me_devname, &tmpfsp); get_path_stats(p_list, &tmpfsp); if (verbose >= 3) - printf("Group %s: adding %llu blocks sized %llu, (%s) used_units=%lu free_units=%llu total_units=%llu mult=%llu\n", + printf("Group %s: adding %lu blocks sized %lu, (%s) used_units=%lu free_units=%lu total_units=%lu mult=%lu\n", p_list->group, tmpfsp.fsu_blocks, tmpfsp.fsu_blocksize, @@ -1071,7 +1020,7 @@ get_stats (struct parameter_list *p, struct fs_usage *fsp) { first = 0; } if (verbose >= 3) - printf("Group %s now has: used_units=%llu free_units=%llu total_units=%llu fsu_blocksize=%llu mult=%llu\n", + printf("Group %s now has: used_units=%lu free_units=%lu total_units=%lu fsu_blocksize=%lu mult=%lu\n", p->group, p->dused_units, p->dfree_units, -- cgit v1.2.3-74-g34f1 From b89aee56964f7d933f2da5f371e32b4d7db9410b Mon Sep 17 00:00:00 2001 From: Lorenz <12514511+RincewindsHat@users.noreply.github.com> Date: Wed, 14 Sep 2022 10:54:46 +0200 Subject: Check ntp remove unused variables (#1781) * Remove unused argument * Fix typo in comment --- plugins/check_ntp.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'plugins') 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){ * - we also "manually" handle resolving host names and connecting, because * we have to do it in a way that our lazy macros don't handle currently :( */ double offset_request(const char *host, int *status){ - int i=0, j=0, ga_result=0, num_hosts=0, *socklist=NULL, respnum=0; + int i=0, ga_result=0, num_hosts=0, *socklist=NULL, respnum=0; int servers_completed=0, one_read=0, servers_readable=0, best_index=-1; time_t now_time=0, start_ts=0; ntp_message *req=NULL; @@ -488,7 +488,7 @@ double offset_request(const char *host, int *status){ /* cleanup */ /* FIXME: Not closing the socket to avoid re-use of the local port * which can cause old NTP packets to be read instead of NTP control - * pactets in jitter_request(). THERE MUST BE ANOTHER WAY... + * packets in jitter_request(). THERE MUST BE ANOTHER WAY... * for(j=0; j Date: Mon, 11 Apr 2016 12:52:02 -0500 Subject: Added ability to correctly check redirects with reference format //test.server.com/folder Referenced redirect of the format //www.server.com/folder would result in check_http trying to contact http://hostname:80//www.server.com/folder instead of http://www.server.com/folder. Referenced redirect of this format is listed in rfc3986 ( https://tools.ietf.org/html/rfc3986 ). It should work as expected now. --- plugins/check_http.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'plugins') diff --git a/plugins/check_http.c b/plugins/check_http.c index f8ec853b..36f3b253 100644 --- a/plugins/check_http.c +++ b/plugins/check_http.c @@ -1364,6 +1364,9 @@ check_http (void) #define HD3 URI_HTTP "://" URI_HOST ":" URI_PORT #define HD4 URI_HTTP "://" URI_HOST #define HD5 URI_PATH +/* relative reference redirect like //www.site.org/test https://tools.ietf.org/html/rfc3986 */ +#define HD6 "//" URI_HOST "/" URI_PATH + void redir (char *pos, char *status_line) @@ -1440,6 +1443,21 @@ redir (char *pos, char *status_line) use_ssl = server_type_check (type); i = server_port_check (use_ssl); } + else if (sscanf (pos, HD6, addr, url) == 2) { + //get type from + if(use_ssl){ + //i = server_port_check (use_ssl); + strcpy (type,"https"); + } + //else if(sscanf(server_url,URI_HTTP,type)==1 ){ + //} + else{ + strcpy (type, server_type); + } + xasprintf (&url, "/%s", url); + use_ssl = server_type_check (type); + i = server_port_check (use_ssl); + } /* URI_PATH */ else if (sscanf (pos, HD5, url) == 1) { -- cgit v1.2.3-74-g34f1 From d57d2b0bdda192dc50e17ebeb8becfe249c3f8e3 Mon Sep 17 00:00:00 2001 From: Eric Wunderlin Date: Tue, 12 Apr 2016 09:00:08 -0500 Subject: Remove unused code --- plugins/check_http.c | 4 ---- 1 file changed, 4 deletions(-) (limited to 'plugins') diff --git a/plugins/check_http.c b/plugins/check_http.c index 36f3b253..59755acd 100644 --- a/plugins/check_http.c +++ b/plugins/check_http.c @@ -1444,13 +1444,9 @@ redir (char *pos, char *status_line) i = server_port_check (use_ssl); } else if (sscanf (pos, HD6, addr, url) == 2) { - //get type from if(use_ssl){ - //i = server_port_check (use_ssl); strcpy (type,"https"); } - //else if(sscanf(server_url,URI_HTTP,type)==1 ){ - //} else{ strcpy (type, server_type); } -- cgit v1.2.3-74-g34f1 From e2e405596a070ec3b830696ecf574ee3a243c7b1 Mon Sep 17 00:00:00 2001 From: "John C. Frickson" Date: Mon, 21 Nov 2016 22:40:39 +0100 Subject: I had to make a couple of small changes. --- plugins/check_http.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'plugins') diff --git a/plugins/check_http.c b/plugins/check_http.c index 59755acd..fb38bc5b 100644 --- a/plugins/check_http.c +++ b/plugins/check_http.c @@ -1363,10 +1363,9 @@ check_http (void) #define HD2 URI_HTTP "://" URI_HOST "/" URI_PATH #define HD3 URI_HTTP "://" URI_HOST ":" URI_PORT #define HD4 URI_HTTP "://" URI_HOST -#define HD5 URI_PATH /* relative reference redirect like //www.site.org/test https://tools.ietf.org/html/rfc3986 */ -#define HD6 "//" URI_HOST "/" URI_PATH - +#define HD5 "//" URI_HOST "/" URI_PATH +#define HD5 URI_PATH void redir (char *pos, char *status_line) @@ -1443,7 +1442,8 @@ redir (char *pos, char *status_line) use_ssl = server_type_check (type); i = server_port_check (use_ssl); } - else if (sscanf (pos, HD6, addr, url) == 2) { + /* URI_HTTP, URI_HOST, URI_PATH */ + else if (sscanf (pos, HD5, addr, url) == 2) { if(use_ssl){ strcpy (type,"https"); } @@ -1456,7 +1456,7 @@ redir (char *pos, char *status_line) } /* URI_PATH */ - else if (sscanf (pos, HD5, url) == 1) { + else if (sscanf (pos, HD6, url) == 1) { /* relative url */ if ((url[0] != '/')) { if ((x = strrchr(server_url, '/'))) -- cgit v1.2.3-74-g34f1 From 80872917294340a1e399b8a100c5a81c4f719220 Mon Sep 17 00:00:00 2001 From: Jan Wagner Date: Sat, 31 Dec 2016 13:57:44 +0100 Subject: check_http: Fix HD6 definition --- plugins/check_http.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'plugins') diff --git a/plugins/check_http.c b/plugins/check_http.c index fb38bc5b..ff39c591 100644 --- a/plugins/check_http.c +++ b/plugins/check_http.c @@ -1365,7 +1365,7 @@ check_http (void) #define HD4 URI_HTTP "://" URI_HOST /* relative reference redirect like //www.site.org/test https://tools.ietf.org/html/rfc3986 */ #define HD5 "//" URI_HOST "/" URI_PATH -#define HD5 URI_PATH +#define HD6 URI_PATH void redir (char *pos, char *status_line) -- cgit v1.2.3-74-g34f1 From b90a5757f77cdc0434fa3f45cf59c63b9e695d90 Mon Sep 17 00:00:00 2001 From: Lorenz <12514511+RincewindsHat@users.noreply.github.com> Date: Mon, 19 Sep 2022 10:23:49 +0200 Subject: Display total and scaled load values if check_load scales the values by number of CPUs (#1778) * Renew copyright * Display more verbose output, if scaled load values are used * Actually use scaled value for determining status and print the fitting perfdata depending on input parameters * Add test cases for scaled mode --- plugins/check_load.c | 56 +++++++++++++++++++++++++++++++++++--------------- plugins/t/check_load.t | 15 ++++++++++---- 2 files changed, 51 insertions(+), 20 deletions(-) (limited to 'plugins') diff --git a/plugins/check_load.c b/plugins/check_load.c index d1bb30a4..00f7c877 100644 --- a/plugins/check_load.c +++ b/plugins/check_load.c @@ -29,7 +29,7 @@ *****************************************************************************/ const char *progname = "check_load"; -const char *copyright = "1999-2007"; +const char *copyright = "1999-2022"; const char *email = "devel@monitoring-plugins.org"; #include "./common.h" @@ -70,7 +70,7 @@ double cload[3] = { 0.0, 0.0, 0.0 }; #define la15 la[2] char *status_line; -int take_into_account_cpus = 0; +bool take_into_account_cpus = false; static void get_threshold(char *arg, double *th) @@ -178,13 +178,6 @@ main (int argc, char **argv) # endif #endif - if (take_into_account_cpus == 1) { - if ((numcpus = GET_NUMBER_OF_CPUS()) > 0) { - la[0] = la[0] / numcpus; - la[1] = la[1] / numcpus; - la[2] = la[2] / numcpus; - } - } if ((la[0] < 0.0) || (la[1] < 0.0) || (la[2] < 0.0)) { #ifdef HAVE_GETLOADAVG printf (_("Error in getloadavg()\n")); @@ -202,18 +195,49 @@ main (int argc, char **argv) result = STATE_OK; xasprintf(&status_line, _("load average: %.2f, %.2f, %.2f"), la1, la5, la15); + xasprintf(&status_line, ("total %s"), status_line); + + + double scaled_la[3] = { 0.0, 0.0, 0.0 }; + bool is_using_scaled_load_values = false; + + if (take_into_account_cpus == true && (numcpus = GET_NUMBER_OF_CPUS()) > 0) { + is_using_scaled_load_values = true; + + scaled_la[0] = la[0] / numcpus; + scaled_la[1] = la[1] / numcpus; + scaled_la[2] = la[2] / numcpus; + + char *tmp = NULL; + xasprintf(&tmp, _("load average: %.2f, %.2f, %.2f"), scaled_la[0], scaled_la[1], scaled_la[2]); + xasprintf(&status_line, "scaled %s - %s", tmp, status_line); + } for(i = 0; i < 3; i++) { - if(la[i] > cload[i]) { - result = STATE_CRITICAL; - break; + if (is_using_scaled_load_values) { + if(scaled_la[i] > cload[i]) { + result = STATE_CRITICAL; + break; + } + else if(scaled_la[i] > wload[i]) result = STATE_WARNING; + } else { + if(la[i] > cload[i]) { + result = STATE_CRITICAL; + break; + } + else if(la[i] > wload[i]) result = STATE_WARNING; } - else if(la[i] > wload[i]) result = STATE_WARNING; } printf("LOAD %s - %s|", state_text(result), status_line); - for(i = 0; i < 3; i++) - printf("load%d=%.3f;%.3f;%.3f;0; ", nums[i], la[i], wload[i], cload[i]); + for(i = 0; i < 3; i++) { + if (is_using_scaled_load_values) { + printf("load%d=%.3f;;;0; ", nums[i], la[i]); + printf("scaled_load%d=%.3f;%.3f;%.3f;0; ", nums[i], scaled_la[i], wload[i], cload[i]); + } else { + printf("load%d=%.3f;%.3f;%.3f;0; ", nums[i], la[i], wload[i], cload[i]); + } + } putchar('\n'); if (n_procs_to_show > 0) { @@ -257,7 +281,7 @@ process_arguments (int argc, char **argv) get_threshold(optarg, cload); break; case 'r': /* Divide load average by number of CPUs */ - take_into_account_cpus = 1; + take_into_account_cpus = true; break; case 'V': /* version */ print_revision (progname, NP_VERSION); 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; my $res; my $loadValue = "[0-9]+\.?[0-9]+"; -my $successOutput = "/^LOAD OK - load average: $loadValue, $loadValue, $loadValue/"; -my $failureOutput = "/^LOAD CRITICAL - load average: $loadValue, $loadValue, $loadValue/"; +my $successOutput = "/^LOAD OK - total load average: $loadValue, $loadValue, $loadValue/"; +my $successScaledOutput = "/^LOAD OK - scaled load average: $loadValue, $loadValue, $loadValue - total load average: $loadValue, $loadValue, $loadValue/"; +my $failureOutput = "/^LOAD CRITICAL - total load average: $loadValue, $loadValue, $loadValue/"; +my $failurScaledOutput = "/^LOAD CRITICAL - scaled load average: $loadValue, $loadValue, $loadValue - total load average: $loadValue, $loadValue, $loadValue/"; -plan tests => 11; +plan tests => 13; $res = NPTest->testCmd( "./check_load -w 100,100,100 -c 100,100,100" ); cmp_ok( $res->return_code, 'eq', 0, "load not over 100"); @@ -26,7 +28,7 @@ like( $res->output, $failureOutput, "Output OK"); $res = NPTest->testCmd( "./check_load -r -w 0,0,0 -c 0,0,0" ); cmp_ok( $res->return_code, 'eq', 2, "Load over 0 with per cpu division"); -like( $res->output, $failureOutput, "Output OK"); +like( $res->output, $failurScaledOutput, "Output OK"); $res = NPTest->testCmd( "./check_load -w 100 -c 100,110" ); cmp_ok( $res->return_code, 'eq', 0, "Plugin can handle non-triplet-arguments"); @@ -34,3 +36,8 @@ like( $res->output, $successOutput, "Output OK"); like( $res->perf_output, "/load1=$loadValue;100.000;100.000/", "Test handling of non triplet thresholds (load1)"); like( $res->perf_output, "/load5=$loadValue;100.000;110.000/", "Test handling of non triplet thresholds (load5)"); like( $res->perf_output, "/load15=$loadValue;100.000;110.000/", "Test handling of non triplet thresholds (load15)"); + + +$res = NPTest->testCmd( "./check_load -w 100,100,100 -c 100,100,100 -r" ); +cmp_ok( $res->return_code, 'eq', 0, "load not over 100"); +like( $res->output, $successScaledOutput, "Output OK"); -- cgit v1.2.3-74-g34f1 From 817ac2e5dad1ce5d0e0ea96fa7f726566251b08d Mon Sep 17 00:00:00 2001 From: Andreas Baumann <202930+andreasbaumann@users.noreply.github.com> Date: Fri, 21 Oct 2022 18:31:12 +0200 Subject: using PRId64 and PRIu64 instead of %ld directly (#1800) --- plugins/utils.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'plugins') diff --git a/plugins/utils.c b/plugins/utils.c index 17dd5814..f75cf03b 100644 --- a/plugins/utils.c +++ b/plugins/utils.c @@ -615,27 +615,27 @@ char *perfdata_uint64 (const char *label, char *data = NULL; if (strpbrk (label, "'= ")) - xasprintf (&data, "'%s'=%ld%s;", label, val, uom); + xasprintf (&data, "'%s'=%" PRId64 "%s;", label, val, uom); else - xasprintf (&data, "%s=%ld%s;", label, val, uom); + xasprintf (&data, "%s=%" PRId64 "%s;", label, val, uom); if (warnp) - xasprintf (&data, "%s%lu;", data, warn); + xasprintf (&data, "%s%" PRIu64 ";", data, warn); else xasprintf (&data, "%s;", data); if (critp) - xasprintf (&data, "%s%lu;", data, crit); + xasprintf (&data, "%s%" PRIu64 ";", data, crit); else xasprintf (&data, "%s;", data); if (minp) - xasprintf (&data, "%s%lu;", data, minv); + xasprintf (&data, "%s%" PRIu64 ";", data, minv); else xasprintf (&data, "%s;", data); if (maxp) - xasprintf (&data, "%s%lu", data, maxv); + xasprintf (&data, "%s%" PRIu64, data, maxv); return data; } @@ -656,27 +656,27 @@ char *perfdata_int64 (const char *label, char *data = NULL; if (strpbrk (label, "'= ")) - xasprintf (&data, "'%s'=%ld%s;", label, val, uom); + xasprintf (&data, "'%s'=%" PRId64 "%s;", label, val, uom); else - xasprintf (&data, "%s=%ld%s;", label, val, uom); + xasprintf (&data, "%s=%" PRId64 "%s;", label, val, uom); if (warnp) - xasprintf (&data, "%s%ld;", data, warn); + xasprintf (&data, "%s%" PRId64 ";", data, warn); else xasprintf (&data, "%s;", data); if (critp) - xasprintf (&data, "%s%ld;", data, crit); + xasprintf (&data, "%s%" PRId64 ";", data, crit); else xasprintf (&data, "%s;", data); if (minp) - xasprintf (&data, "%s%ld;", data, minv); + xasprintf (&data, "%s%" PRId64 ";", data, minv); else xasprintf (&data, "%s;", data); if (maxp) - xasprintf (&data, "%s%ld", data, maxv); + xasprintf (&data, "%s%" PRId64, data, maxv); return data; } -- cgit v1.2.3-74-g34f1 From eb2dfdd5c24b87198b66397b224d6406c468a0bc Mon Sep 17 00:00:00 2001 From: Andreas Baumann <202930+andreasbaumann@users.noreply.github.com> Date: Thu, 27 Oct 2022 22:48:18 +0200 Subject: fixed two PRId64 to PRIu64 in perfdata_uint64 (#1802) --- plugins/utils.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'plugins') diff --git a/plugins/utils.c b/plugins/utils.c index f75cf03b..b4214c61 100644 --- a/plugins/utils.c +++ b/plugins/utils.c @@ -615,9 +615,9 @@ char *perfdata_uint64 (const char *label, char *data = NULL; if (strpbrk (label, "'= ")) - xasprintf (&data, "'%s'=%" PRId64 "%s;", label, val, uom); + xasprintf (&data, "'%s'=%" PRIu64 "%s;", label, val, uom); else - xasprintf (&data, "%s=%" PRId64 "%s;", label, val, uom); + xasprintf (&data, "%s=%" PRIu64 "%s;", label, val, uom); if (warnp) xasprintf (&data, "%s%" PRIu64 ";", data, warn); -- cgit v1.2.3-74-g34f1 From 2d9c6276d0a380f831bf94734359f071d0c7e958 Mon Sep 17 00:00:00 2001 From: waja Date: Fri, 4 Nov 2022 19:16:01 +0100 Subject: Removing is_pg_dbname alltogether,using postgres API. (Closes: #1660) (#1803) The problem is that check_pgsql validates the Database name and has different assumptions that postgres itself. I fail to see a reason to validate the database name here. Postgres'es API should do this - So i would suggest a fix like this by removing is_pg_dbname alltogether. Co-authored-by: Florian Lohoff --- plugins/check_pgsql.c | 48 ++++-------------------------------------------- 1 file changed, 4 insertions(+), 44 deletions(-) (limited to 'plugins') 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 **); int validate_arguments (void); void print_usage (void); void print_help (void); -int is_pg_dbname (char *); int is_pg_logname (char *); int do_query (PGconn *, char *); @@ -347,10 +346,10 @@ process_arguments (int argc, char **argv) pgport = optarg; break; case 'd': /* database name */ - if (!is_pg_dbname (optarg)) /* checks length and valid chars */ - usage2 (_("Database name is not valid"), optarg); - else /* we know length, and know optarg is terminated, so us strcpy */ - snprintf(dbName, NAMEDATALEN, "%s", optarg); + if (strlen(optarg) >= NAMEDATALEN) { + usage2 (_("Database name exceeds the maximum length"), optarg); + } + snprintf(dbName, NAMEDATALEN, "%s", optarg); break; case 'l': /* login name */ if (!is_pg_logname (optarg)) @@ -414,45 +413,6 @@ validate_arguments () return OK; } - -/****************************************************************************** - -@@- - -is_pg_dbname - -&PROTO_is_pg_dbname; - -Given a database name, this function returns TRUE if the string -is a valid PostgreSQL database name, and returns false if it is -not. - -Valid PostgreSQL database names are less than &NAMEDATALEN; -characters long and consist of letters, numbers, and underscores. The -first character cannot be a number, however. - - --@@ -******************************************************************************/ - - - -int -is_pg_dbname (char *dbname) -{ - char txt[NAMEDATALEN]; - char tmp[NAMEDATALEN]; - if (strlen (dbname) > NAMEDATALEN - 1) - return (FALSE); - strncpy (txt, dbname, NAMEDATALEN - 1); - txt[NAMEDATALEN - 1] = 0; - if (sscanf (txt, "%[_a-zA-Z]%[^_a-zA-Z0-9-]", tmp, tmp) == 1) - return (TRUE); - if (sscanf (txt, "%[_a-zA-Z]%[_a-zA-Z0-9-]%[^_a-zA-Z0-9-]", tmp, tmp, tmp) == - 2) return (TRUE); - return (FALSE); -} - /** the tango program should eventually create an entity here based on the -- cgit v1.2.3-74-g34f1 From edc84e5d669089fa3f047dc52740679e7cb58fc1 Mon Sep 17 00:00:00 2001 From: Lorenz <12514511+RincewindsHat@users.noreply.github.com> Date: Sat, 5 Nov 2022 13:59:45 +0100 Subject: Remove superflous CRLF in HTTP-Requests in check_http (#1798) * Remove superflous CRLF in HTTP-Requests in check_http --- plugins/check_http.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'plugins') diff --git a/plugins/check_http.c b/plugins/check_http.c index ff39c591..41d47816 100644 --- a/plugins/check_http.c +++ b/plugins/check_http.c @@ -1070,9 +1070,8 @@ check_http (void) } xasprintf (&buf, "%sContent-Length: %i\r\n\r\n", buf, (int)strlen (http_post_data)); - xasprintf (&buf, "%s%s%s", buf, http_post_data, CRLF); - } - else { + xasprintf (&buf, "%s%s", buf, http_post_data); + } else { /* or just a newline so the server knows we're done with the request */ xasprintf (&buf, "%s%s", buf, CRLF); } -- cgit v1.2.3-74-g34f1 From 4a5ddd201119260028db6a4f27027d72aa9a160a Mon Sep 17 00:00:00 2001 From: Lorenz <12514511+RincewindsHat@users.noreply.github.com> Date: Mon, 7 Nov 2022 17:48:28 +0100 Subject: Check curl detect ipv6 (#1809) * If server_address is an IPv6 address surround it with brackets * If the message is too short, we should not have an underflow * Add simple conditional test case available if IPv6 is --- .github/workflows/test.yml | 2 +- plugins/check_curl.c | 22 ++++++++++++++++++---- plugins/t/check_curl.t | 39 ++++++++++++++++++++++++++++----------- 3 files changed, 47 insertions(+), 16 deletions(-) (limited to 'plugins') diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d2785a41..80d49f7e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -40,7 +40,7 @@ jobs: ${{ matrix.distro }} \ /bin/sh -c '${{ matrix.prepare }} && \ tools/setup && \ - ./configure --enable-libtap --with-ipv6=no && \ + ./configure --enable-libtap --with-ipv6=no && \ make && \ make test' docker container prune -f 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) printf ("* curl CURLOPT_RESOLVE: %s\n", dnscache); } + // If server_address is an IPv6 address it must be surround by square brackets + struct in6_addr tmp_in_addr; + if (inet_pton(AF_INET6, server_address, &tmp_in_addr) == 1) { + char *new_server_address = malloc(strlen(server_address) + 3); + if (new_server_address == NULL) { + die(STATE_UNKNOWN, "HTTP UNKNOWN - Unable to allocate memory\n"); + } + snprintf(new_server_address, strlen(server_address)+3, "[%s]", server_address); + free(server_address); + server_address = new_server_address; + } + /* compose URL: use the address we want to connect to, set Host: header later */ snprintf (url, DEFAULT_BUFFER_SIZE, "%s://%s:%d%s", use_ssl ? "https" : "http", @@ -999,10 +1011,12 @@ GOT_FIRST_CERT: result = max_state_alt(get_status(total_time, thlds), result); /* Cut-off trailing characters */ - if(msg[strlen(msg)-2] == ',') - msg[strlen(msg)-2] = '\0'; - else - msg[strlen(msg)-3] = '\0'; + if (strlen(msg) >= 2) { + if(msg[strlen(msg)-2] == ',') + msg[strlen(msg)-2] = '\0'; + else + msg[strlen(msg)-3] = '\0'; + } /* TODO: separate _() msg and status code: die (result, "HTTP %s: %s\n", state_text(result), msg); */ 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/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 @@ #! /usr/bin/perl -w -I .. # -# HyperText Transfer Protocol (HTTP) Test via check_http +# HyperText Transfer Protocol (HTTP) Test via check_curl # # use strict; use Test::More; use POSIX qw/mktime strftime/; -use NPTest; -plan tests => 57; +use vars qw($tests $has_ipv6); + +BEGIN { + use NPTest; + $has_ipv6 = NPTest::has_ipv6(); + $tests = $has_ipv6 ? 59 : 57; + plan tests => $tests; +} + my $successOutput = '/OK.*HTTP.*second/'; @@ -18,6 +25,7 @@ my $plugin = 'check_http'; $plugin = 'check_curl' if $0 =~ m/check_curl/mx; my $host_tcp_http = getTestParameter("NP_HOST_TCP_HTTP", "A host providing the HTTP Service (a web server)", "localhost"); +my $host_tcp_http_ipv6 = getTestParameter("NP_HOST_TCP_HTTP_IPV6", "An IPv6 address providing a HTTP Service (a web server)", "::1"); my $host_tls_http = getTestParameter("NP_HOST_TLS_HTTP", "A host providing the HTTPS Service (a tls web server)", "localhost"); my $host_tls_cert = getTestParameter("NP_HOST_TLS_CERT", "the common name of the certificate.", "localhost"); 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; $res = NPTest->testCmd( - "./$plugin $host_tcp_http -wt 300 -ct 600" - ); + "./$plugin $host_tcp_http -wt 300 -ct 600" + ); cmp_ok( $res->return_code, '==', 0, "Webserver $host_tcp_http responded" ); like( $res->output, $successOutput, "Output OK" ); +if ($has_ipv6) { + # Test for IPv6 formatting + $res = NPTest->testCmd( + "./$plugin -I $host_tcp_http_ipv6 -wt 300 -ct 600" + ); + cmp_ok( $res->return_code, '==', 0, "IPv6 URL formatting is working" ); + like( $res->output, $successOutput, "Output OK" ); +} + $res = NPTest->testCmd( - "./$plugin $host_tcp_http -wt 300 -ct 600 -v -v -v -k 'bob:there' -k 'carl:frown'" - ); + "./$plugin $host_tcp_http -wt 300 -ct 600 -v -v -v -k 'bob:there' -k 'carl:frown'" + ); like( $res->output, '/bob:there\r\ncarl:frown\r\n/', "Got headers with multiple -k options" ); $res = NPTest->testCmd( - "./$plugin $host_nonresponsive -wt 1 -ct 2 -t 3" - ); + "./$plugin $host_nonresponsive -wt 1 -ct 2 -t 3" + ); cmp_ok( $res->return_code, '==', 2, "Webserver $host_nonresponsive not responding" ); # was CRITICAL only, but both check_curl and check_http print HTTP CRITICAL (puzzle?!) like( $res->output, "/HTTP CRITICAL - Invalid HTTP response received from host on port 80: cURL returned 28 - Connection timed out after/", "Output OK"); $res = NPTest->testCmd( - "./$plugin $hostname_invalid -wt 1 -ct 2" - ); + "./$plugin $hostname_invalid -wt 1 -ct 2" + ); cmp_ok( $res->return_code, '==', 2, "Webserver $hostname_invalid not valid" ); # The first part of the message comes from the OS catalogue, so cannot check this. # On Debian, it is Name or service not known, on Darwin, it is No address associated with nodename -- cgit v1.2.3-74-g34f1