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/check_disk.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'plugins/check_disk.c') diff --git a/plugins/check_disk.c b/plugins/check_disk.c index 0d84ecd2..24de2d45 100644 --- a/plugins/check_disk.c +++ b/plugins/check_disk.c @@ -550,6 +550,10 @@ process_arguments (int argc, char **argv) /* See comments for 'c' */ case 'w': /* warning threshold */ + if (!is_percentage_expression(optarg) && !is_numeric(optarg)) { + die(STATE_UNKNOWN, "Argument for --warning invalid or missing: %s\n", optarg); + } + if (strstr(optarg, "%")) { if (*optarg == '@') { warn_freespace_percent = optarg; @@ -571,6 +575,10 @@ process_arguments (int argc, char **argv) force @ at the beginning of the range, so that it is backwards compatible */ case 'c': /* critical threshold */ + if (!is_percentage_expression(optarg) && !is_numeric(optarg)) { + die(STATE_UNKNOWN, "Argument for --critical invalid or missing: %s\n", optarg); + } + if (strstr(optarg, "%")) { if (*optarg == '@') { crit_freespace_percent = optarg; -- cgit v1.2.3-74-g34f1