From d3faf13961c61b3ad69b47960124d3269c5f335e Mon Sep 17 00:00:00 2001 From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> Date: Wed, 27 Mar 2024 00:36:41 +0100 Subject: check_disk: Fail on missing arguments for --warning and --critical and fix a test case (#1935) * check_disk: Fail on missing arguments for --warning and --critical * Add new test function for percentage expressions and use it in check_disk * Add error abort in tests if they fail to parse output * Fix typo in test which probably broke the test since forever :-( --- plugins/utils.c | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'plugins/utils.c') diff --git a/plugins/utils.c b/plugins/utils.c index aff17906..77d6a6f9 100644 --- a/plugins/utils.c +++ b/plugins/utils.c @@ -23,13 +23,15 @@ *****************************************************************************/ #include "common.h" -#include "utils.h" +#include "./utils.h" #include "utils_base.h" #include #include #include #include +#include + #include extern void print_usage (void); @@ -188,6 +190,33 @@ bool is_percentage (char *number) { return false; } +bool is_percentage_expression (const char str[]) { + if (!str) { + return false; + } + + size_t len = strlen(str); + + if (str[len-1] != '%') { + return false; + } + + char *foo = calloc(sizeof(char), len + 1); + + if (!foo) { + die (STATE_UNKNOWN, _("calloc failed \n")); + } + + strcpy(foo, str); + foo[len-1] = '\0'; + + bool result = is_numeric(foo); + + free(foo); + + return result; +} + bool is_integer (char *number) { long int n; -- cgit v1.2.3-74-g34f1