From f457615d845ec3bf9d3072511999b69d93c934c5 Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Wed, 23 Aug 2023 17:33:16 +0200 Subject: Introduce regex_list --- lib/utils_disk.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/utils_disk.h b/lib/utils_disk.h index 3b5a45f8..442fd94f 100644 --- a/lib/utils_disk.h +++ b/lib/utils_disk.h @@ -10,6 +10,12 @@ struct name_list struct name_list *next; }; +struct regex_list +{ + regex_t regex; + struct regex_list *next; +}; + struct parameter_list { char *name; -- cgit v1.2.3-74-g34f1 From d31a696cadb0bba0914d76aad0eb48c6e7962b8e Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Wed, 23 Aug 2023 18:13:01 +0200 Subject: Introduce np_add_regex() --- lib/utils_disk.c | 11 +++++++++++ lib/utils_disk.h | 1 + 2 files changed, 12 insertions(+) diff --git a/lib/utils_disk.c b/lib/utils_disk.c index 582d3ea1..ce02fdff 100644 --- a/lib/utils_disk.c +++ b/lib/utils_disk.c @@ -40,6 +40,17 @@ np_add_name (struct name_list **list, const char *name) *list = new_entry; } +/* Initialises a new regex at the begin of list via regcomp(3) */ +int +np_add_regex (struct regex_list **list, const char *regex, int cflags) +{ + struct regex_list *new_entry = (struct regex_list *) malloc (sizeof *new_entry); + new_entry->next = *list; + *list = new_entry; + + return regcomp(&new_entry->regex, regex, cflags); +} + /* Initialises a new parameter at the end of list */ struct parameter_list * np_add_parameter(struct parameter_list **list, const char *name) diff --git a/lib/utils_disk.h b/lib/utils_disk.h index 442fd94f..bda088f6 100644 --- a/lib/utils_disk.h +++ b/lib/utils_disk.h @@ -41,6 +41,7 @@ struct parameter_list void np_add_name (struct name_list **list, const char *name); int np_find_name (struct name_list *list, const char *name); int np_seen_name (struct name_list *list, const char *name); +int np_add_regex (struct regex_list **list, const char *regex, int cflags); struct parameter_list *np_add_parameter(struct parameter_list **list, const char *name); struct parameter_list *np_find_parameter(struct parameter_list *list, const char *name); struct parameter_list *np_del_parameter(struct parameter_list *item, struct parameter_list *prev); -- cgit v1.2.3-74-g34f1 From 1f694195b4a6beef30bbbbffa5835a993be97a9c Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Wed, 23 Aug 2023 18:26:12 +0200 Subject: Introduce np_find_regmatch() --- lib/utils_disk.c | 25 +++++++++++++++++++++++++ lib/utils_disk.h | 1 + 2 files changed, 26 insertions(+) diff --git a/lib/utils_disk.c b/lib/utils_disk.c index ce02fdff..34401e21 100644 --- a/lib/utils_disk.c +++ b/lib/utils_disk.c @@ -29,6 +29,7 @@ #include "common.h" #include "utils_disk.h" #include "gl/fsusage.h" +#include void np_add_name (struct name_list **list, const char *name) @@ -207,6 +208,30 @@ np_find_name (struct name_list *list, const char *name) return FALSE; } +/* Returns TRUE if name is in list */ +bool +np_find_regmatch (struct regex_list *list, const char *name) +{ + int len; + regmatch_t m; + + if (name == NULL) { + return false; + } + + len = strlen(name); + + for (; list; list = list->next) { + /* Emulate a full match as if surrounded with ^( )$ + by checking whether the match spans the whole name */ + if (!regexec(&list->regex, name, 1, &m, 0) && m.rm_so == 0 && m.rm_eo == len) { + return true; + } + } + + return false; +} + int np_seen_name(struct name_list *list, const char *name) { diff --git a/lib/utils_disk.h b/lib/utils_disk.h index bda088f6..6b83ac74 100644 --- a/lib/utils_disk.h +++ b/lib/utils_disk.h @@ -42,6 +42,7 @@ void np_add_name (struct name_list **list, const char *name); int np_find_name (struct name_list *list, const char *name); int np_seen_name (struct name_list *list, const char *name); int np_add_regex (struct regex_list **list, const char *regex, int cflags); +bool np_find_regmatch (struct regex_list *list, const char *name); struct parameter_list *np_add_parameter(struct parameter_list **list, const char *name); struct parameter_list *np_find_parameter(struct parameter_list *list, const char *name); struct parameter_list *np_del_parameter(struct parameter_list *item, struct parameter_list *prev); -- cgit v1.2.3-74-g34f1 From 4bb444f3353fbb49086bd0e212b3cad8009761dd Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Tue, 12 Sep 2023 14:55:00 +0200 Subject: check_disk: make -X a regex list --- plugins/check_disk.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/plugins/check_disk.c b/plugins/check_disk.c index 7dc1c4b1..e7e9378f 100644 --- a/plugins/check_disk.c +++ b/plugins/check_disk.c @@ -93,7 +93,7 @@ static int stat_remote_fs = 0; /* Linked list of filesystem types to omit. If the list is empty, don't exclude any types. */ -static struct name_list *fs_exclude_list; +static struct regex_list *fs_exclude_list = NULL; /* Linked list of filesystem types to check. If the list is empty, include all types. */ @@ -300,7 +300,7 @@ main (int argc, char **argv) } else if (me->me_dummy && !show_all_fs) { continue; /* Skip excluded fstypes */ - } else if (fs_exclude_list && np_find_name (fs_exclude_list, me->me_type)) { + } else if (fs_exclude_list && np_find_regmatch (fs_exclude_list, me->me_type)) { continue; /* Skip excluded fs's */ } else if (dp_exclude_list && @@ -543,7 +543,7 @@ process_arguments (int argc, char **argv) if (argc < 2) return ERROR; - np_add_name(&fs_exclude_list, "iso9660"); + np_add_regex(&fs_exclude_list, "iso9660", REG_EXTENDED); for (c = 1; c < argc; c++) if (strcmp ("-to", argv[c]) == 0) @@ -716,7 +716,11 @@ process_arguments (int argc, char **argv) np_add_name(&dp_exclude_list, optarg); break; case 'X': /* exclude file system type */ - np_add_name(&fs_exclude_list, optarg); + err = np_add_regex(&fs_exclude_list, optarg, REG_EXTENDED); + if (err != 0) { + regerror (err, &fs_exclude_list->regex, errbuf, MAX_INPUT_BUFFER); + die (STATE_UNKNOWN, "DISK %s: %s - %s\n",_("UNKNOWN"), _("Could not compile regular expression"), errbuf); + } break; case 'N': /* include file system type */ np_add_name(&fs_include_list, optarg); @@ -1003,8 +1007,8 @@ print_help (void) printf (" %s\n", "-u, --units=STRING"); printf (" %s\n", _("Choose bytes, kB, MB, GB, TB (default: MB)")); printf (UT_VERBOSE); - printf (" %s\n", "-X, --exclude-type=TYPE"); - printf (" %s\n", _("Ignore all filesystems of indicated type (may be repeated)")); + printf (" %s\n", "-X, --exclude-type=TYPE_REGEX"); + printf (" %s\n", _("Ignore all filesystems of types matching given regex(7) (may be repeated)")); printf (" %s\n", "-N, --include-type=TYPE"); printf (" %s\n", _("Check only filesystems of indicated type (may be repeated)")); @@ -1037,7 +1041,7 @@ print_usage (void) printf ("%s\n", _("Usage:")); printf (" %s {-w absolute_limit |-w percentage_limit%% | -W inode_percentage_limit } {-c absolute_limit|-c percentage_limit%% | -K inode_percentage_limit } {-p path | -x device}\n", progname); printf ("[-C] [-E] [-e] [-f] [-g group ] [-k] [-l] [-M] [-m] [-R path ] [-r path ]\n"); - printf ("[-t timeout] [-u unit] [-v] [-X type] [-N type]\n"); + printf ("[-t timeout] [-u unit] [-v] [-X type_regex] [-N type]\n"); } bool -- cgit v1.2.3-74-g34f1 From 677bbd21a97a95bf149a8bbbeac397a92a0e19d2 Mon Sep 17 00:00:00 2001 From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> Date: Thu, 28 Sep 2023 12:40:27 +0200 Subject: Update translations --- po/de.po | 11 ++++++----- po/fr.po | 12 +++++++----- po/monitoring-plugins.pot | 11 ++++++----- 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/po/de.po b/po/de.po index 9ea32df9..bd95ee64 100644 --- a/po/de.po +++ b/po/de.po @@ -9,7 +9,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: devel@monitoring-plugins.org\n" -"POT-Creation-Date: 2023-09-22 15:36+0200\n" +"POT-Creation-Date: 2023-09-28 12:40+0200\n" "PO-Revision-Date: 2004-12-23 17:46+0100\n" "Last-Translator: \n" "Language-Team: Monitoring Plugin Development Team \n" "Language-Team: LANGUAGE \n" @@ -291,6 +291,9 @@ msgstr "" msgid "Must set a threshold value before using -p\n" msgstr "" +msgid "Could not compile regular expression" +msgstr "" + msgid "Must set -E before selecting paths\n" msgstr "" @@ -302,9 +305,6 @@ msgid "" "explicitly" msgstr "" -msgid "Could not compile regular expression" -msgstr "" - msgid "" "Must set a threshold value before using -r/-R/-A (--ereg-path/--eregi-path/--" "all)\n" @@ -423,7 +423,8 @@ msgstr "" msgid "Choose bytes, kB, MB, GB, TB (default: MB)" msgstr "" -msgid "Ignore all filesystems of indicated type (may be repeated)" +msgid "" +"Ignore all filesystems of types matching given regex(7) (may be repeated)" msgstr "" msgid "Check only filesystems of indicated type (may be repeated)" -- cgit v1.2.3-74-g34f1 From 6947a8cea9335c2eeefb8929aa663db49ecac5a1 Mon Sep 17 00:00:00 2001 From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> Date: Sat, 30 Sep 2023 12:54:21 +0200 Subject: check_disk: Use regex also to include fs types --- plugins/check_disk.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/plugins/check_disk.c b/plugins/check_disk.c index e7e9378f..06576d86 100644 --- a/plugins/check_disk.c +++ b/plugins/check_disk.c @@ -97,7 +97,7 @@ static struct regex_list *fs_exclude_list = NULL; /* Linked list of filesystem types to check. If the list is empty, include all types. */ -static struct name_list *fs_include_list; +static struct regex_list *fs_include_list; static struct name_list *dp_exclude_list; @@ -308,7 +308,7 @@ main (int argc, char **argv) np_find_name (dp_exclude_list, me->me_mountdir))) { continue; /* Skip not included fstypes */ - } else if (fs_include_list && !np_find_name (fs_include_list, me->me_type)) { + } else if (fs_include_list && !np_find_regmatch(fs_include_list, me->me_type)) { continue; } } @@ -723,7 +723,11 @@ process_arguments (int argc, char **argv) } break; case 'N': /* include file system type */ - np_add_name(&fs_include_list, optarg); + err = np_add_regex(&fs_include_list, optarg, REG_EXTENDED); + if (err != 0) { + regerror (err, &fs_exclude_list->regex, errbuf, MAX_INPUT_BUFFER); + die (STATE_UNKNOWN, "DISK %s: %s - %s\n",_("UNKNOWN"), _("Could not compile regular expression"), errbuf); + } break; case 'v': /* verbose */ verbose++; -- cgit v1.2.3-74-g34f1 From 51aa8b2d9d3812b74fb4d15da712a31d549d928b Mon Sep 17 00:00:00 2001 From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> Date: Sat, 30 Sep 2023 12:55:49 +0200 Subject: Document new np_add_regex more and add error handling --- lib/utils_disk.c | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/lib/utils_disk.c b/lib/utils_disk.c index 34401e21..884f0052 100644 --- a/lib/utils_disk.c +++ b/lib/utils_disk.c @@ -41,15 +41,40 @@ np_add_name (struct name_list **list, const char *name) *list = new_entry; } -/* Initialises a new regex at the begin of list via regcomp(3) */ +/* @brief Initialises a new regex at the begin of list via regcomp(3) + * + * @details if the regex fails to compile the error code of regcomp(3) is returned + * and list is not modified, otherwise list is modified to point to the new + * element + * @param list Pointer to a linked list of regex_list elements + * @param regex the string containing the regex which should be inserted into the list + * @param clags the cflags parameter for regcomp(3) + */ int np_add_regex (struct regex_list **list, const char *regex, int cflags) { struct regex_list *new_entry = (struct regex_list *) malloc (sizeof *new_entry); - new_entry->next = *list; - *list = new_entry; - return regcomp(&new_entry->regex, regex, cflags); + if (new_entry == NULL) { + die(STATE_UNKNOWN, _("Cannot allocate memory: %s"), + strerror(errno)); + } + + int regcomp_result = regcomp(&new_entry->regex, regex, cflags); + + if (!regcomp_result) { + // regcomp succeded + new_entry->next = *list; + *list = new_entry; + + return 0; + } else { + // regcomp failed + free(new_entry); + + return regcomp_result; + } + } /* Initialises a new parameter at the end of list */ -- cgit v1.2.3-74-g34f1 From 128a24be2296af175c5e7adf875f9d0e8a619278 Mon Sep 17 00:00:00 2001 From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> Date: Sat, 30 Sep 2023 12:59:26 +0200 Subject: Fix typo --- lib/utils_disk.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/utils_disk.c b/lib/utils_disk.c index 884f0052..f5ac0b30 100644 --- a/lib/utils_disk.c +++ b/lib/utils_disk.c @@ -63,7 +63,7 @@ np_add_regex (struct regex_list **list, const char *regex, int cflags) int regcomp_result = regcomp(&new_entry->regex, regex, cflags); if (!regcomp_result) { - // regcomp succeded + // regcomp succeeded new_entry->next = *list; *list = new_entry; -- cgit v1.2.3-74-g34f1 From 819f90b726805f50d6de72f06b58bf02744f4763 Mon Sep 17 00:00:00 2001 From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> Date: Sun, 1 Oct 2023 00:41:55 +0200 Subject: check_disk: Change usage for --include-type to indicated regexes are now possible --- plugins/check_disk.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/check_disk.c b/plugins/check_disk.c index 06576d86..2f066c7b 100644 --- a/plugins/check_disk.c +++ b/plugins/check_disk.c @@ -1013,8 +1013,8 @@ print_help (void) printf (UT_VERBOSE); printf (" %s\n", "-X, --exclude-type=TYPE_REGEX"); printf (" %s\n", _("Ignore all filesystems of types matching given regex(7) (may be repeated)")); - printf (" %s\n", "-N, --include-type=TYPE"); - printf (" %s\n", _("Check only filesystems of indicated type (may be repeated)")); + printf (" %s\n", "-N, --include-type=TYPE_REGEX"); + printf (" %s\n", _("Check only filesystems where the type matches this given regex(7) (may be repeated)")); printf ("\n"); printf ("%s\n", _("General usage hints:")); -- cgit v1.2.3-74-g34f1 From 15ceeaf46ed893e86499f25578fd1a27945b2677 Mon Sep 17 00:00:00 2001 From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> Date: Sun, 1 Oct 2023 00:48:10 +0200 Subject: Update translations --- po/de.po | 6 ++++-- po/fr.po | 12 ++++++++++-- po/monitoring-plugins.pot | 6 ++++-- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/po/de.po b/po/de.po index bd95ee64..c25a2b47 100644 --- a/po/de.po +++ b/po/de.po @@ -9,7 +9,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: devel@monitoring-plugins.org\n" -"POT-Creation-Date: 2023-09-28 12:40+0200\n" +"POT-Creation-Date: 2023-10-01 00:46+0200\n" "PO-Revision-Date: 2004-12-23 17:46+0100\n" "Last-Translator: \n" "Language-Team: Monitoring Plugin Development Team \n" "Language-Team: LANGUAGE \n" @@ -427,7 +427,9 @@ msgid "" "Ignore all filesystems of types matching given regex(7) (may be repeated)" msgstr "" -msgid "Check only filesystems of indicated type (may be repeated)" +msgid "" +"Check only filesystems where the type matches this given regex(7) (may be " +"repeated)" msgstr "" msgid "General usage hints:" -- cgit v1.2.3-74-g34f1