Merge branch 'master' into merge-jitter

This commit is contained in:
datamuc 2023-10-06 11:01:01 +02:00 committed by GitHub
commit 5886cfbcb0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 123 additions and 30 deletions

View file

@ -29,6 +29,7 @@
#include "common.h"
#include "utils_disk.h"
#include "gl/fsusage.h"
#include <string.h>
void
np_add_name (struct name_list **list, const char *name)
@ -40,6 +41,42 @@ np_add_name (struct name_list **list, const char *name)
*list = new_entry;
}
/* @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);
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 succeeded
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 */
struct parameter_list *
np_add_parameter(struct parameter_list **list, const char *name)
@ -196,6 +233,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)
{

View file

@ -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;
@ -35,6 +41,8 @@ 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);
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);

View file

@ -93,11 +93,11 @@ 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. */
static struct name_list *fs_include_list;
static struct regex_list *fs_include_list;
static struct name_list *dp_exclude_list;
@ -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 &&
@ -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;
}
}
@ -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,10 +716,18 @@ 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);
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++;
@ -1003,10 +1011,10 @@ 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", "-N, --include-type=TYPE");
printf (" %s\n", _("Check only 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_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:"));
@ -1037,7 +1045,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

View file

@ -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-27 12:16+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 <devel@monitoring-plugins."
@ -308,6 +308,9 @@ msgstr "UNKNOWN"
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 ""
@ -319,9 +322,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"
@ -446,10 +446,13 @@ 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)"
msgid ""
"Check only filesystems where the type matches this given regex(7) (may be "
"repeated)"
msgstr ""
msgid "General usage hints:"

View file

@ -10,7 +10,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: devel@monitoring-plugins.org\n"
"POT-Creation-Date: 2023-09-27 12:16+0200\n"
"POT-Creation-Date: 2023-10-01 00:46+0200\n"
"PO-Revision-Date: 2010-04-21 23:38-0400\n"
"Last-Translator: \n"
"Language-Team: Monitoring Plugin Development Team <devel@monitoring-plugins."
@ -307,6 +307,9 @@ msgstr "INCONNU"
msgid "Must set a threshold value before using -p\n"
msgstr ""
msgid "Could not compile regular expression"
msgstr "Impossible de compiler l'expression rationnelle"
msgid "Must set -E before selecting paths\n"
msgstr ""
@ -318,9 +321,6 @@ msgid ""
"explicitly"
msgstr ""
msgid "Could not compile regular expression"
msgstr "Impossible de compiler l'expression rationnelle"
msgid ""
"Must set a threshold value before using -r/-R/-A (--ereg-path/--eregi-path/--"
"all)\n"
@ -461,13 +461,17 @@ msgstr ""
msgid "Choose bytes, kB, MB, GB, TB (default: MB)"
msgstr "Choisissez octets, kb, MB, GB, TB (par défaut: MB)"
msgid "Ignore all filesystems of indicated type (may be repeated)"
#, fuzzy
msgid ""
"Ignore all filesystems of types matching given regex(7) (may be repeated)"
msgstr ""
"Ignorer tout les systèmes de fichiers qui correspondent au type indiqué "
"(peut être utilisé plusieurs fois)"
#, fuzzy
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 ""
"Ignorer tout les systèmes de fichiers qui correspondent au type indiqué "
"(peut être utilisé plusieurs fois)"
@ -5359,6 +5363,12 @@ msgstr ""
msgid "The -v switch can be specified several times for increased verbosity."
msgstr ""
#, fuzzy
#~ msgid "Check only filesystems of indicated type (may be repeated)"
#~ msgstr ""
#~ "Ignorer tout les systèmes de fichiers qui correspondent au type indiqué "
#~ "(peut être utilisé plusieurs fois)"
#~ msgid "Path or partition (may be repeated)"
#~ msgstr "Répertoire ou partition (peut être utilisé plusieurs fois)"

View file

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: devel@monitoring-plugins.org\n"
"POT-Creation-Date: 2023-09-27 12:16+0200\n"
"POT-Creation-Date: 2023-10-01 00:46+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\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,10 +423,13 @@ 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)"
msgid ""
"Check only filesystems where the type matches this given regex(7) (may be "
"repeated)"
msgstr ""
msgid "General usage hints:"