diff options
author | Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> | 2024-03-26 23:36:41 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-26 23:36:41 (GMT) |
commit | d3faf13961c61b3ad69b47960124d3269c5f335e (patch) | |
tree | d626f2d7d234b194af8fe536dd5b2cf318a7adf6 /plugins/utils.c | |
parent | 66f62dd336832702a1e4f60cbfc4258de2c931cf (diff) | |
download | monitoring-plugins-d3faf13961c61b3ad69b47960124d3269c5f335e.tar.gz |
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 :-(
Diffstat (limited to 'plugins/utils.c')
-rw-r--r-- | plugins/utils.c | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/plugins/utils.c b/plugins/utils.c index aff1790..77d6a6f 100644 --- a/plugins/utils.c +++ b/plugins/utils.c | |||
@@ -23,13 +23,15 @@ | |||
23 | *****************************************************************************/ | 23 | *****************************************************************************/ |
24 | 24 | ||
25 | #include "common.h" | 25 | #include "common.h" |
26 | #include "utils.h" | 26 | #include "./utils.h" |
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> | 30 | #include <string.h> |
31 | #include <errno.h> | 31 | #include <errno.h> |
32 | 32 | ||
33 | #include <stdbool.h> | ||
34 | |||
33 | #include <arpa/inet.h> | 35 | #include <arpa/inet.h> |
34 | 36 | ||
35 | extern void print_usage (void); | 37 | extern void print_usage (void); |
@@ -188,6 +190,33 @@ bool is_percentage (char *number) { | |||
188 | return false; | 190 | return false; |
189 | } | 191 | } |
190 | 192 | ||
193 | bool is_percentage_expression (const char str[]) { | ||
194 | if (!str) { | ||
195 | return false; | ||
196 | } | ||
197 | |||
198 | size_t len = strlen(str); | ||
199 | |||
200 | if (str[len-1] != '%') { | ||
201 | return false; | ||
202 | } | ||
203 | |||
204 | char *foo = calloc(sizeof(char), len + 1); | ||
205 | |||
206 | if (!foo) { | ||
207 | die (STATE_UNKNOWN, _("calloc failed \n")); | ||
208 | } | ||
209 | |||
210 | strcpy(foo, str); | ||
211 | foo[len-1] = '\0'; | ||
212 | |||
213 | bool result = is_numeric(foo); | ||
214 | |||
215 | free(foo); | ||
216 | |||
217 | return result; | ||
218 | } | ||
219 | |||
191 | bool is_integer (char *number) { | 220 | bool is_integer (char *number) { |
192 | long int n; | 221 | long int n; |
193 | 222 | ||