diff options
| author | Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> | 2025-03-31 23:58:02 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-03-31 23:58:02 +0200 |
| commit | 4924bc877f714ec00ac8b02378d11f1508bbe8b4 (patch) | |
| tree | 276d2c7b746e593133cf1fc6ca548e10f71e1b5f /lib | |
| parent | 922d16ab2e44594d0ae4e4ac0c2b095cb1a1003f (diff) | |
| parent | d0647ec7e1500c0e6164ac9820a7d623582bdde2 (diff) | |
| download | monitoring-plugins-4924bc877f714ec00ac8b02378d11f1508bbe8b4.tar.gz | |
Merge pull request #2113 from RincewindsHat/refactor/check_disk
Refactor/check disk
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/Makefile.am | 3 | ||||
| -rw-r--r-- | lib/output.c | 16 | ||||
| -rw-r--r-- | lib/output.h | 16 | ||||
| -rw-r--r-- | lib/perfdata.c | 83 | ||||
| -rw-r--r-- | lib/perfdata.h | 12 | ||||
| -rw-r--r-- | lib/tests/Makefile.am | 6 | ||||
| -rw-r--r-- | lib/tests/test_disk.c | 192 | ||||
| -rwxr-xr-x | lib/tests/test_disk.t | 6 | ||||
| -rw-r--r-- | lib/thresholds.c | 14 | ||||
| -rw-r--r-- | lib/thresholds.h | 3 | ||||
| -rw-r--r-- | lib/utils_base.c | 18 | ||||
| -rw-r--r-- | lib/utils_disk.c | 255 | ||||
| -rw-r--r-- | lib/utils_disk.h | 48 |
13 files changed, 144 insertions, 528 deletions
diff --git a/lib/Makefile.am b/lib/Makefile.am index e41201c4..a9f3ff40 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am | |||
| @@ -7,10 +7,9 @@ noinst_LIBRARIES = libmonitoringplug.a | |||
| 7 | AM_CPPFLAGS = -DNP_STATE_DIR_PREFIX=\"$(localstatedir)\" \ | 7 | AM_CPPFLAGS = -DNP_STATE_DIR_PREFIX=\"$(localstatedir)\" \ |
| 8 | -I$(srcdir) -I$(top_srcdir)/gl -I$(top_srcdir)/intl -I$(top_srcdir)/plugins | 8 | -I$(srcdir) -I$(top_srcdir)/gl -I$(top_srcdir)/intl -I$(top_srcdir)/plugins |
| 9 | 9 | ||
| 10 | libmonitoringplug_a_SOURCES = utils_base.c utils_disk.c utils_tcp.c utils_cmd.c maxfd.c output.c perfdata.c output.c thresholds.c vendor/cJSON/cJSON.c | 10 | libmonitoringplug_a_SOURCES = utils_base.c utils_tcp.c utils_cmd.c maxfd.c output.c perfdata.c output.c thresholds.c vendor/cJSON/cJSON.c |
| 11 | 11 | ||
| 12 | EXTRA_DIST = utils_base.h \ | 12 | EXTRA_DIST = utils_base.h \ |
| 13 | utils_disk.h \ | ||
| 14 | utils_tcp.h \ | 13 | utils_tcp.h \ |
| 15 | utils_cmd.h \ | 14 | utils_cmd.h \ |
| 16 | parse_ini.h \ | 15 | parse_ini.h \ |
diff --git a/lib/output.c b/lib/output.c index 61fbf832..c408a2f5 100644 --- a/lib/output.c +++ b/lib/output.c | |||
| @@ -13,6 +13,7 @@ | |||
| 13 | 13 | ||
| 14 | // == Global variables | 14 | // == Global variables |
| 15 | static mp_output_format output_format = MP_FORMAT_DEFAULT; | 15 | static mp_output_format output_format = MP_FORMAT_DEFAULT; |
| 16 | static mp_output_detail_level level_of_detail = MP_DETAIL_ALL; | ||
| 16 | 17 | ||
| 17 | // == Prototypes == | 18 | // == Prototypes == |
| 18 | static char *fmt_subcheck_output(mp_output_format output_format, mp_subcheck check, unsigned int indentation); | 19 | static char *fmt_subcheck_output(mp_output_format output_format, mp_subcheck check, unsigned int indentation); |
| @@ -202,7 +203,12 @@ mp_state_enum mp_compute_subcheck_state(const mp_subcheck check) { | |||
| 202 | } | 203 | } |
| 203 | 204 | ||
| 204 | mp_subcheck_list *scl = check.subchecks; | 205 | mp_subcheck_list *scl = check.subchecks; |
| 205 | mp_state_enum result = check.default_state; | 206 | |
| 207 | if (scl == NULL) { | ||
| 208 | return check.default_state; | ||
| 209 | } | ||
| 210 | |||
| 211 | mp_state_enum result = STATE_OK; | ||
| 206 | 212 | ||
| 207 | while (scl != NULL) { | 213 | while (scl != NULL) { |
| 208 | result = max_state_alt(result, mp_compute_subcheck_state(scl->subcheck)); | 214 | result = max_state_alt(result, mp_compute_subcheck_state(scl->subcheck)); |
| @@ -247,7 +253,9 @@ char *mp_fmt_output(mp_check check) { | |||
| 247 | mp_subcheck_list *subchecks = check.subchecks; | 253 | mp_subcheck_list *subchecks = check.subchecks; |
| 248 | 254 | ||
| 249 | while (subchecks != NULL) { | 255 | while (subchecks != NULL) { |
| 250 | asprintf(&result, "%s\n%s", result, fmt_subcheck_output(MP_FORMAT_MULTI_LINE, subchecks->subcheck, 1)); | 256 | if (level_of_detail == MP_DETAIL_ALL || mp_compute_subcheck_state(subchecks->subcheck) != STATE_OK) { |
| 257 | asprintf(&result, "%s\n%s", result, fmt_subcheck_output(MP_FORMAT_MULTI_LINE, subchecks->subcheck, 1)); | ||
| 258 | } | ||
| 251 | subchecks = subchecks->next; | 259 | subchecks = subchecks->next; |
| 252 | } | 260 | } |
| 253 | 261 | ||
| @@ -539,3 +547,7 @@ parsed_output_format mp_parse_output_format(char *format_string) { | |||
| 539 | void mp_set_format(mp_output_format format) { output_format = format; } | 547 | void mp_set_format(mp_output_format format) { output_format = format; } |
| 540 | 548 | ||
| 541 | mp_output_format mp_get_format(void) { return output_format; } | 549 | mp_output_format mp_get_format(void) { return output_format; } |
| 550 | |||
| 551 | void mp_set_level_of_detail(mp_output_detail_level level) { level_of_detail = level; } | ||
| 552 | |||
| 553 | mp_output_detail_level mp_get_level_of_detail(void) { return level_of_detail; } | ||
diff --git a/lib/output.h b/lib/output.h index 2bdfa074..3bd91f90 100644 --- a/lib/output.h +++ b/lib/output.h | |||
| @@ -38,8 +38,18 @@ typedef enum output_format { | |||
| 38 | /* | 38 | /* |
| 39 | * Format related functions | 39 | * Format related functions |
| 40 | */ | 40 | */ |
| 41 | void mp_set_format(mp_output_format format); | 41 | void mp_set_format(mp_output_format format); |
| 42 | mp_output_format mp_get_format(void); | 42 | mp_output_format mp_get_format(void); |
| 43 | |||
| 44 | // Output detail level | ||
| 45 | |||
| 46 | typedef enum output_detail_level { | ||
| 47 | MP_DETAIL_ALL, | ||
| 48 | MP_DETAIL_NON_OK_ONLY, | ||
| 49 | } mp_output_detail_level; | ||
| 50 | |||
| 51 | void mp_set_level_of_detail(mp_output_detail_level level); | ||
| 52 | mp_output_detail_level mp_get_level_of_detail(void); | ||
| 43 | 53 | ||
| 44 | /* | 54 | /* |
| 45 | * The main state object of a plugin. Exists only ONCE per plugin. | 55 | * The main state object of a plugin. Exists only ONCE per plugin. |
| @@ -48,7 +58,7 @@ typedef enum output_format { | |||
| 48 | * in the first layer of subchecks | 58 | * in the first layer of subchecks |
| 49 | */ | 59 | */ |
| 50 | typedef struct { | 60 | typedef struct { |
| 51 | char *summary; // Overall summary, if not set a summary will be automatically generated | 61 | char *summary; // Overall summary, if not set a summary will be automatically generated |
| 52 | mp_subcheck_list *subchecks; | 62 | mp_subcheck_list *subchecks; |
| 53 | } mp_check; | 63 | } mp_check; |
| 54 | 64 | ||
diff --git a/lib/perfdata.c b/lib/perfdata.c index 661756c5..f425ffcf 100644 --- a/lib/perfdata.c +++ b/lib/perfdata.c | |||
| @@ -33,7 +33,7 @@ char *pd_value_to_string(const mp_perfdata_value pd) { | |||
| 33 | char *pd_to_string(mp_perfdata pd) { | 33 | char *pd_to_string(mp_perfdata pd) { |
| 34 | assert(pd.label != NULL); | 34 | assert(pd.label != NULL); |
| 35 | char *result = NULL; | 35 | char *result = NULL; |
| 36 | asprintf(&result, "%s=", pd.label); | 36 | asprintf(&result, "'%s'=", pd.label); |
| 37 | 37 | ||
| 38 | asprintf(&result, "%s%s", result, pd_value_to_string(pd.value)); | 38 | asprintf(&result, "%s%s", result, pd_value_to_string(pd.value)); |
| 39 | 39 | ||
| @@ -514,3 +514,84 @@ perfdata_value_parser_wrapper parse_pd_value(const char *input) { | |||
| 514 | } | 514 | } |
| 515 | return result; | 515 | return result; |
| 516 | } | 516 | } |
| 517 | |||
| 518 | mp_perfdata mp_set_pd_max_value(mp_perfdata perfdata, mp_perfdata_value value) { | ||
| 519 | perfdata.max = value; | ||
| 520 | perfdata.max_present = true; | ||
| 521 | return perfdata; | ||
| 522 | } | ||
| 523 | |||
| 524 | mp_perfdata mp_set_pd_min_value(mp_perfdata perfdata, mp_perfdata_value value) { | ||
| 525 | perfdata.min = value; | ||
| 526 | perfdata.min_present = true; | ||
| 527 | return perfdata; | ||
| 528 | } | ||
| 529 | |||
| 530 | double mp_get_pd_value(mp_perfdata_value value) { | ||
| 531 | assert(value.type != PD_TYPE_NONE); | ||
| 532 | switch (value.type) { | ||
| 533 | case PD_TYPE_DOUBLE: | ||
| 534 | return value.pd_double; | ||
| 535 | case PD_TYPE_INT: | ||
| 536 | return (double)value.pd_int; | ||
| 537 | case PD_TYPE_UINT: | ||
| 538 | return (double)value.pd_uint; | ||
| 539 | default: | ||
| 540 | return 0; // just to make the compiler happy | ||
| 541 | } | ||
| 542 | } | ||
| 543 | |||
| 544 | mp_perfdata_value mp_pd_value_multiply(mp_perfdata_value left, mp_perfdata_value right) { | ||
| 545 | if (left.type == right.type) { | ||
| 546 | switch (left.type) { | ||
| 547 | case PD_TYPE_DOUBLE: | ||
| 548 | left.pd_double *= right.pd_double; | ||
| 549 | return left; | ||
| 550 | case PD_TYPE_INT: | ||
| 551 | left.pd_int *= right.pd_int; | ||
| 552 | return left; | ||
| 553 | case PD_TYPE_UINT: | ||
| 554 | left.pd_uint *= right.pd_uint; | ||
| 555 | return left; | ||
| 556 | default: | ||
| 557 | // what to here? | ||
| 558 | return left; | ||
| 559 | } | ||
| 560 | } | ||
| 561 | |||
| 562 | // Different types, oh boy, just do the lazy thing for now and switch to double | ||
| 563 | switch (left.type) { | ||
| 564 | case PD_TYPE_INT: | ||
| 565 | left.pd_double = (double)left.pd_int; | ||
| 566 | left.type = PD_TYPE_DOUBLE; | ||
| 567 | break; | ||
| 568 | case PD_TYPE_UINT: | ||
| 569 | left.pd_double = (double)left.pd_uint; | ||
| 570 | left.type = PD_TYPE_DOUBLE; | ||
| 571 | break; | ||
| 572 | } | ||
| 573 | |||
| 574 | switch (right.type) { | ||
| 575 | case PD_TYPE_INT: | ||
| 576 | right.pd_double = (double)right.pd_int; | ||
| 577 | right.type = PD_TYPE_DOUBLE; | ||
| 578 | break; | ||
| 579 | case PD_TYPE_UINT: | ||
| 580 | right.pd_double = (double)right.pd_uint; | ||
| 581 | right.type = PD_TYPE_DOUBLE; | ||
| 582 | break; | ||
| 583 | } | ||
| 584 | |||
| 585 | left.pd_double *= right.pd_double; | ||
| 586 | return left; | ||
| 587 | } | ||
| 588 | |||
| 589 | mp_range mp_range_multiply(mp_range range, mp_perfdata_value factor) { | ||
| 590 | if (!range.end_infinity) { | ||
| 591 | range.end = mp_pd_value_multiply(range.end, factor); | ||
| 592 | } | ||
| 593 | if (!range.start_infinity) { | ||
| 594 | range.start = mp_pd_value_multiply(range.start, factor); | ||
| 595 | } | ||
| 596 | return range; | ||
| 597 | } | ||
diff --git a/lib/perfdata.h b/lib/perfdata.h index 74583ee5..cb552678 100644 --- a/lib/perfdata.h +++ b/lib/perfdata.h | |||
| @@ -171,6 +171,11 @@ mp_perfdata_value mp_create_pd_value_u_long(unsigned long); | |||
| 171 | mp_perfdata_value mp_create_pd_value_long_long(long long); | 171 | mp_perfdata_value mp_create_pd_value_long_long(long long); |
| 172 | mp_perfdata_value mp_create_pd_value_u_long_long(unsigned long long); | 172 | mp_perfdata_value mp_create_pd_value_u_long_long(unsigned long long); |
| 173 | 173 | ||
| 174 | mp_perfdata mp_set_pd_max_value(mp_perfdata perfdata, mp_perfdata_value value); | ||
| 175 | mp_perfdata mp_set_pd_min_value(mp_perfdata perfdata, mp_perfdata_value value); | ||
| 176 | |||
| 177 | double mp_get_pd_value(mp_perfdata_value value); | ||
| 178 | |||
| 174 | /* | 179 | /* |
| 175 | * Free the memory used by a pd_list | 180 | * Free the memory used by a pd_list |
| 176 | */ | 181 | */ |
| @@ -178,6 +183,13 @@ void pd_list_free(pd_list[1]); | |||
| 178 | 183 | ||
| 179 | int cmp_perfdata_value(mp_perfdata_value, mp_perfdata_value); | 184 | int cmp_perfdata_value(mp_perfdata_value, mp_perfdata_value); |
| 180 | 185 | ||
| 186 | // ================ | ||
| 187 | // Helper functions | ||
| 188 | // ================ | ||
| 189 | |||
| 190 | mp_perfdata_value mp_pd_value_multiply(mp_perfdata_value left, mp_perfdata_value right); | ||
| 191 | mp_range mp_range_multiply(mp_range range, mp_perfdata_value factor); | ||
| 192 | |||
| 181 | // ================= | 193 | // ================= |
| 182 | // String formatters | 194 | // String formatters |
| 183 | // ================= | 195 | // ================= |
diff --git a/lib/tests/Makefile.am b/lib/tests/Makefile.am index 9be94f6d..7798a72e 100644 --- a/lib/tests/Makefile.am +++ b/lib/tests/Makefile.am | |||
| @@ -8,9 +8,9 @@ check_PROGRAMS = @EXTRA_TEST@ | |||
| 8 | AM_CPPFLAGS = -DNP_STATE_DIR_PREFIX=\"$(localstatedir)\" \ | 8 | AM_CPPFLAGS = -DNP_STATE_DIR_PREFIX=\"$(localstatedir)\" \ |
| 9 | -I$(top_srcdir)/lib -I$(top_srcdir)/gl -I$(top_srcdir)/intl -I$(top_srcdir)/plugins | 9 | -I$(top_srcdir)/lib -I$(top_srcdir)/gl -I$(top_srcdir)/intl -I$(top_srcdir)/plugins |
| 10 | 10 | ||
| 11 | EXTRA_PROGRAMS = test_utils test_disk test_tcp test_cmd test_base64 test_ini1 test_ini3 test_opts1 test_opts2 test_opts3 test_generic_output | 11 | EXTRA_PROGRAMS = test_utils test_tcp test_cmd test_base64 test_ini1 test_ini3 test_opts1 test_opts2 test_opts3 test_generic_output |
| 12 | 12 | ||
| 13 | np_test_scripts = test_base64.t test_cmd.t test_disk.t test_ini1.t test_ini3.t test_opts1.t test_opts2.t test_opts3.t test_tcp.t test_utils.t test_generic_output.t | 13 | np_test_scripts = test_base64.t test_cmd.t test_ini1.t test_ini3.t test_opts1.t test_opts2.t test_opts3.t test_tcp.t test_utils.t test_generic_output.t |
| 14 | np_test_files = config-dos.ini config-opts.ini config-tiny.ini plugin.ini plugins.ini | 14 | np_test_files = config-dos.ini config-opts.ini config-tiny.ini plugin.ini plugins.ini |
| 15 | EXTRA_DIST = $(np_test_scripts) $(np_test_files) var | 15 | EXTRA_DIST = $(np_test_scripts) $(np_test_files) var |
| 16 | 16 | ||
| @@ -29,7 +29,7 @@ AM_CFLAGS = -g -I$(top_srcdir)/lib -I$(top_srcdir)/gl $(tap_cflags) | |||
| 29 | AM_LDFLAGS = $(tap_ldflags) -ltap | 29 | AM_LDFLAGS = $(tap_ldflags) -ltap |
| 30 | LDADD = $(top_srcdir)/lib/libmonitoringplug.a $(top_srcdir)/gl/libgnu.a $(LIB_CRYPTO) | 30 | LDADD = $(top_srcdir)/lib/libmonitoringplug.a $(top_srcdir)/gl/libgnu.a $(LIB_CRYPTO) |
| 31 | 31 | ||
| 32 | SOURCES = test_utils.c test_disk.c test_tcp.c test_cmd.c test_base64.c test_ini1.c test_ini3.c test_opts1.c test_opts2.c test_opts3.c test_generic_output.c | 32 | SOURCES = test_utils.c test_tcp.c test_cmd.c test_base64.c test_ini1.c test_ini3.c test_opts1.c test_opts2.c test_opts3.c test_generic_output.c |
| 33 | 33 | ||
| 34 | test: ${noinst_PROGRAMS} | 34 | test: ${noinst_PROGRAMS} |
| 35 | perl -MTest::Harness -e '$$Test::Harness::switches=""; runtests(map {$$_ .= ".t"} @ARGV)' $(EXTRA_PROGRAMS) | 35 | perl -MTest::Harness -e '$$Test::Harness::switches=""; runtests(map {$$_ .= ".t"} @ARGV)' $(EXTRA_PROGRAMS) |
diff --git a/lib/tests/test_disk.c b/lib/tests/test_disk.c deleted file mode 100644 index c18db7a4..00000000 --- a/lib/tests/test_disk.c +++ /dev/null | |||
| @@ -1,192 +0,0 @@ | |||
| 1 | /***************************************************************************** | ||
| 2 | * | ||
| 3 | * This program is free software: you can redistribute it and/or modify | ||
| 4 | * it under the terms of the GNU General Public License as published by | ||
| 5 | * the Free Software Foundation, either version 3 of the License, or | ||
| 6 | * (at your option) any later version. | ||
| 7 | * | ||
| 8 | * This program is distributed in the hope that it will be useful, | ||
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 11 | * GNU General Public License for more details. | ||
| 12 | * | ||
| 13 | * You should have received a copy of the GNU General Public License | ||
| 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 15 | * | ||
| 16 | * | ||
| 17 | *****************************************************************************/ | ||
| 18 | |||
| 19 | #include "common.h" | ||
| 20 | #include "utils_disk.h" | ||
| 21 | #include "tap.h" | ||
| 22 | #include "regex.h" | ||
| 23 | |||
| 24 | void np_test_mount_entry_regex(struct mount_entry *dummy_mount_list, char *regstr, int cflags, int expect, char *desc); | ||
| 25 | |||
| 26 | int main(int argc, char **argv) { | ||
| 27 | struct name_list *exclude_filesystem = NULL; | ||
| 28 | struct name_list *exclude_fstype = NULL; | ||
| 29 | struct name_list *dummy_mountlist = NULL; | ||
| 30 | struct name_list *temp_name; | ||
| 31 | struct parameter_list *paths = NULL; | ||
| 32 | struct parameter_list *p, *prev = NULL, *last = NULL; | ||
| 33 | |||
| 34 | struct mount_entry *dummy_mount_list; | ||
| 35 | struct mount_entry *me; | ||
| 36 | struct mount_entry **mtail = &dummy_mount_list; | ||
| 37 | int cflags = REG_NOSUB | REG_EXTENDED; | ||
| 38 | int found = 0, count = 0; | ||
| 39 | |||
| 40 | plan_tests(33); | ||
| 41 | |||
| 42 | ok(np_find_name(exclude_filesystem, "/var/log") == false, "/var/log not in list"); | ||
| 43 | np_add_name(&exclude_filesystem, "/var/log"); | ||
| 44 | ok(np_find_name(exclude_filesystem, "/var/log") == true, "is in list now"); | ||
| 45 | ok(np_find_name(exclude_filesystem, "/home") == false, "/home not in list"); | ||
| 46 | np_add_name(&exclude_filesystem, "/home"); | ||
| 47 | ok(np_find_name(exclude_filesystem, "/home") == true, "is in list now"); | ||
| 48 | ok(np_find_name(exclude_filesystem, "/var/log") == true, "/var/log still in list"); | ||
| 49 | |||
| 50 | ok(np_find_name(exclude_fstype, "iso9660") == false, "iso9660 not in list"); | ||
| 51 | np_add_name(&exclude_fstype, "iso9660"); | ||
| 52 | ok(np_find_name(exclude_fstype, "iso9660") == true, "is in list now"); | ||
| 53 | |||
| 54 | ok(np_find_name(exclude_filesystem, "iso9660") == false, "Make sure no clashing in variables"); | ||
| 55 | |||
| 56 | /* | ||
| 57 | for (temp_name = exclude_filesystem; temp_name; temp_name = temp_name->next) { | ||
| 58 | printf("Name: %s\n", temp_name->name); | ||
| 59 | } | ||
| 60 | */ | ||
| 61 | |||
| 62 | me = (struct mount_entry *)malloc(sizeof *me); | ||
| 63 | me->me_devname = strdup("/dev/c0t0d0s0"); | ||
| 64 | me->me_mountdir = strdup("/"); | ||
| 65 | *mtail = me; | ||
| 66 | mtail = &me->me_next; | ||
| 67 | |||
| 68 | me = (struct mount_entry *)malloc(sizeof *me); | ||
| 69 | me->me_devname = strdup("/dev/c1t0d1s0"); | ||
| 70 | me->me_mountdir = strdup("/var"); | ||
| 71 | *mtail = me; | ||
| 72 | mtail = &me->me_next; | ||
| 73 | |||
| 74 | me = (struct mount_entry *)malloc(sizeof *me); | ||
| 75 | me->me_devname = strdup("/dev/c2t0d0s0"); | ||
| 76 | me->me_mountdir = strdup("/home"); | ||
| 77 | *mtail = me; | ||
| 78 | mtail = &me->me_next; | ||
| 79 | |||
| 80 | np_test_mount_entry_regex(dummy_mount_list, strdup("/"), cflags, 3, strdup("a")); | ||
| 81 | np_test_mount_entry_regex(dummy_mount_list, strdup("/dev"), cflags, 3, strdup("regex on dev names:")); | ||
| 82 | np_test_mount_entry_regex(dummy_mount_list, strdup("/foo"), cflags, 0, strdup("regex on non existent dev/path:")); | ||
| 83 | np_test_mount_entry_regex(dummy_mount_list, strdup("/Foo"), cflags | REG_ICASE, 0, strdup("regi on non existent dev/path:")); | ||
| 84 | np_test_mount_entry_regex(dummy_mount_list, strdup("/c.t0"), cflags, 3, strdup("partial devname regex match:")); | ||
| 85 | np_test_mount_entry_regex(dummy_mount_list, strdup("c0t0"), cflags, 1, strdup("partial devname regex match:")); | ||
| 86 | np_test_mount_entry_regex(dummy_mount_list, strdup("C0t0"), cflags | REG_ICASE, 1, strdup("partial devname regi match:")); | ||
| 87 | np_test_mount_entry_regex(dummy_mount_list, strdup("home"), cflags, 1, strdup("partial pathname regex match:")); | ||
| 88 | np_test_mount_entry_regex(dummy_mount_list, strdup("hOme"), cflags | REG_ICASE, 1, strdup("partial pathname regi match:")); | ||
| 89 | np_test_mount_entry_regex(dummy_mount_list, strdup("(/home)|(/var)"), cflags, 2, strdup("grouped regex pathname match:")); | ||
| 90 | np_test_mount_entry_regex(dummy_mount_list, strdup("(/homE)|(/Var)"), cflags | REG_ICASE, 2, strdup("grouped regi pathname match:")); | ||
| 91 | |||
| 92 | np_add_parameter(&paths, "/home/groups"); | ||
| 93 | np_add_parameter(&paths, "/var"); | ||
| 94 | np_add_parameter(&paths, "/tmp"); | ||
| 95 | np_add_parameter(&paths, "/home/tonvoon"); | ||
| 96 | np_add_parameter(&paths, "/dev/c2t0d0s0"); | ||
| 97 | |||
| 98 | np_set_best_match(paths, dummy_mount_list, false); | ||
| 99 | for (p = paths; p; p = p->name_next) { | ||
| 100 | struct mount_entry *temp_me; | ||
| 101 | temp_me = p->best_match; | ||
| 102 | if (!strcmp(p->name, "/home/groups")) { | ||
| 103 | ok(temp_me && !strcmp(temp_me->me_mountdir, "/home"), "/home/groups got right best match: /home"); | ||
| 104 | } else if (!strcmp(p->name, "/var")) { | ||
| 105 | ok(temp_me && !strcmp(temp_me->me_mountdir, "/var"), "/var got right best match: /var"); | ||
| 106 | } else if (!strcmp(p->name, "/tmp")) { | ||
| 107 | ok(temp_me && !strcmp(temp_me->me_mountdir, "/"), "/tmp got right best match: /"); | ||
| 108 | } else if (!strcmp(p->name, "/home/tonvoon")) { | ||
| 109 | ok(temp_me && !strcmp(temp_me->me_mountdir, "/home"), "/home/tonvoon got right best match: /home"); | ||
| 110 | } else if (!strcmp(p->name, "/dev/c2t0d0s0")) { | ||
| 111 | ok(temp_me && !strcmp(temp_me->me_devname, "/dev/c2t0d0s0"), "/dev/c2t0d0s0 got right best match: /dev/c2t0d0s0"); | ||
| 112 | } | ||
| 113 | } | ||
| 114 | |||
| 115 | paths = NULL; /* Bad boy - should free, but this is a test suite */ | ||
| 116 | np_add_parameter(&paths, "/home/groups"); | ||
| 117 | np_add_parameter(&paths, "/var"); | ||
| 118 | np_add_parameter(&paths, "/tmp"); | ||
| 119 | np_add_parameter(&paths, "/home/tonvoon"); | ||
| 120 | np_add_parameter(&paths, "/home"); | ||
| 121 | |||
| 122 | np_set_best_match(paths, dummy_mount_list, true); | ||
| 123 | for (p = paths; p; p = p->name_next) { | ||
| 124 | if (!strcmp(p->name, "/home/groups")) { | ||
| 125 | ok(!p->best_match, "/home/groups correctly not found"); | ||
| 126 | } else if (!strcmp(p->name, "/var")) { | ||
| 127 | ok(p->best_match, "/var found"); | ||
| 128 | } else if (!strcmp(p->name, "/tmp")) { | ||
| 129 | ok(!p->best_match, "/tmp correctly not found"); | ||
| 130 | } else if (!strcmp(p->name, "/home/tonvoon")) { | ||
| 131 | ok(!p->best_match, "/home/tonvoon not found"); | ||
| 132 | } else if (!strcmp(p->name, "/home")) { | ||
| 133 | ok(p->best_match, "/home found"); | ||
| 134 | } | ||
| 135 | } | ||
| 136 | |||
| 137 | /* test deleting first element in paths */ | ||
| 138 | paths = np_del_parameter(paths, NULL); | ||
| 139 | for (p = paths; p; p = p->name_next) { | ||
| 140 | if (!strcmp(p->name, "/home/groups")) | ||
| 141 | found = 1; | ||
| 142 | } | ||
| 143 | ok(found == 0, "first element successfully deleted"); | ||
| 144 | found = 0; | ||
| 145 | |||
| 146 | p = paths; | ||
| 147 | while (p) { | ||
| 148 | if (!strcmp(p->name, "/tmp")) | ||
| 149 | p = np_del_parameter(p, prev); | ||
| 150 | else { | ||
| 151 | prev = p; | ||
| 152 | p = p->name_next; | ||
| 153 | } | ||
| 154 | } | ||
| 155 | |||
| 156 | for (p = paths; p; p = p->name_next) { | ||
| 157 | if (!strcmp(p->name, "/tmp")) | ||
| 158 | found = 1; | ||
| 159 | if (p->name_next) | ||
| 160 | prev = p; | ||
| 161 | else | ||
| 162 | last = p; | ||
| 163 | } | ||
| 164 | ok(found == 0, "/tmp element successfully deleted"); | ||
| 165 | |||
| 166 | p = np_del_parameter(last, prev); | ||
| 167 | for (p = paths; p; p = p->name_next) { | ||
| 168 | if (!strcmp(p->name, "/home")) | ||
| 169 | found = 1; | ||
| 170 | last = p; | ||
| 171 | count++; | ||
| 172 | } | ||
| 173 | ok(found == 0, "last (/home) element successfully deleted"); | ||
| 174 | ok(count == 2, "two elements remaining"); | ||
| 175 | |||
| 176 | return exit_status(); | ||
| 177 | } | ||
| 178 | |||
| 179 | void np_test_mount_entry_regex(struct mount_entry *dummy_mount_list, char *regstr, int cflags, int expect, char *desc) { | ||
| 180 | int matches = 0; | ||
| 181 | regex_t re; | ||
| 182 | struct mount_entry *me; | ||
| 183 | if (regcomp(&re, regstr, cflags) == 0) { | ||
| 184 | for (me = dummy_mount_list; me; me = me->me_next) { | ||
| 185 | if (np_regex_match_mount_entry(me, &re)) | ||
| 186 | matches++; | ||
| 187 | } | ||
| 188 | ok(matches == expect, "%s '%s' matched %i/3 entries. ok: %i/3", desc, regstr, expect, matches); | ||
| 189 | |||
| 190 | } else | ||
| 191 | ok(false, "regex '%s' not compilable", regstr); | ||
| 192 | } | ||
diff --git a/lib/tests/test_disk.t b/lib/tests/test_disk.t deleted file mode 100755 index da84dfdf..00000000 --- a/lib/tests/test_disk.t +++ /dev/null | |||
| @@ -1,6 +0,0 @@ | |||
| 1 | #!/usr/bin/perl | ||
| 2 | use Test::More; | ||
| 3 | if (! -e "./test_disk") { | ||
| 4 | plan skip_all => "./test_disk not compiled - please enable libtap library to test"; | ||
| 5 | } | ||
| 6 | exec "./test_disk"; | ||
diff --git a/lib/thresholds.c b/lib/thresholds.c index ddefae37..de2b9315 100644 --- a/lib/thresholds.c +++ b/lib/thresholds.c | |||
| @@ -51,9 +51,21 @@ mp_state_enum mp_get_pd_status(mp_perfdata perfdata) { | |||
| 51 | } | 51 | } |
| 52 | if (perfdata.warn_present) { | 52 | if (perfdata.warn_present) { |
| 53 | if (mp_check_range(perfdata.value, perfdata.warn)) { | 53 | if (mp_check_range(perfdata.value, perfdata.warn)) { |
| 54 | return STATE_CRITICAL; | 54 | return STATE_WARNING; |
| 55 | } | 55 | } |
| 56 | } | 56 | } |
| 57 | 57 | ||
| 58 | return STATE_OK; | 58 | return STATE_OK; |
| 59 | } | 59 | } |
| 60 | |||
| 61 | mp_thresholds mp_thresholds_set_warn(mp_thresholds thlds, mp_range warn) { | ||
| 62 | thlds.warning = warn; | ||
| 63 | thlds.warning_is_set = true; | ||
| 64 | return thlds; | ||
| 65 | } | ||
| 66 | |||
| 67 | mp_thresholds mp_thresholds_set_crit(mp_thresholds thlds, mp_range crit) { | ||
| 68 | thlds.critical = crit; | ||
| 69 | thlds.critical_is_set = true; | ||
| 70 | return thlds; | ||
| 71 | } | ||
diff --git a/lib/thresholds.h b/lib/thresholds.h index 4e7defee..5f9f9247 100644 --- a/lib/thresholds.h +++ b/lib/thresholds.h | |||
| @@ -24,5 +24,8 @@ mp_perfdata mp_pd_set_thresholds(mp_perfdata /* pd */, mp_thresholds /* th */); | |||
| 24 | 24 | ||
| 25 | mp_state_enum mp_get_pd_status(mp_perfdata /* pd */); | 25 | mp_state_enum mp_get_pd_status(mp_perfdata /* pd */); |
| 26 | 26 | ||
| 27 | mp_thresholds mp_thresholds_set_warn(mp_thresholds thlds, mp_range warn); | ||
| 28 | mp_thresholds mp_thresholds_set_crit(mp_thresholds thlds, mp_range crit); | ||
| 29 | |||
| 27 | char *fmt_threshold_warning(thresholds th); | 30 | char *fmt_threshold_warning(thresholds th); |
| 28 | char *fmt_threshold_critical(thresholds th); | 31 | char *fmt_threshold_critical(thresholds th); |
diff --git a/lib/utils_base.c b/lib/utils_base.c index ff9540c7..c49a473f 100644 --- a/lib/utils_base.c +++ b/lib/utils_base.c | |||
| @@ -225,27 +225,15 @@ bool mp_check_range(const mp_perfdata_value value, const mp_range my_range) { | |||
| 225 | if (my_range.end_infinity == false && my_range.start_infinity == false) { | 225 | if (my_range.end_infinity == false && my_range.start_infinity == false) { |
| 226 | // range: .........|---inside---|........... | 226 | // range: .........|---inside---|........... |
| 227 | // value | 227 | // value |
| 228 | if ((cmp_perfdata_value(my_range.start, value) < 1) && (cmp_perfdata_value(value, my_range.end) <= 0)) { | 228 | is_inside = ((cmp_perfdata_value(my_range.start, value) < 1) && (cmp_perfdata_value(value, my_range.end) <= 0)); |
| 229 | is_inside = true; | ||
| 230 | } else { | ||
| 231 | is_inside = false; | ||
| 232 | } | ||
| 233 | } else if (my_range.start_infinity == false && my_range.end_infinity == true) { | 229 | } else if (my_range.start_infinity == false && my_range.end_infinity == true) { |
| 234 | // range: .........|---inside--------- | 230 | // range: .........|---inside--------- |
| 235 | // value | 231 | // value |
| 236 | if (cmp_perfdata_value(my_range.start, value) < 0) { | 232 | is_inside = (cmp_perfdata_value(my_range.start, value) < 0); |
| 237 | is_inside = true; | ||
| 238 | } else { | ||
| 239 | is_inside = false; | ||
| 240 | } | ||
| 241 | } else if (my_range.start_infinity == true && my_range.end_infinity == false) { | 233 | } else if (my_range.start_infinity == true && my_range.end_infinity == false) { |
| 242 | // range: -inside--------|.................... | 234 | // range: -inside--------|.................... |
| 243 | // value | 235 | // value |
| 244 | if (cmp_perfdata_value(value, my_range.end) == -1) { | 236 | is_inside = (cmp_perfdata_value(value, my_range.end) == -1); |
| 245 | is_inside = true; | ||
| 246 | } else { | ||
| 247 | is_inside = false; | ||
| 248 | } | ||
| 249 | } else { | 237 | } else { |
| 250 | // range from -inf to inf, so always inside | 238 | // range from -inf to inf, so always inside |
| 251 | is_inside = true; | 239 | is_inside = true; |
diff --git a/lib/utils_disk.c b/lib/utils_disk.c deleted file mode 100644 index 2b761f5e..00000000 --- a/lib/utils_disk.c +++ /dev/null | |||
| @@ -1,255 +0,0 @@ | |||
| 1 | /***************************************************************************** | ||
| 2 | * | ||
| 3 | * Library for check_disk | ||
| 4 | * | ||
| 5 | * License: GPL | ||
| 6 | * Copyright (c) 1999-2024 Monitoring Plugins Development Team | ||
| 7 | * | ||
| 8 | * Description: | ||
| 9 | * | ||
| 10 | * This file contains utilities for check_disk. These are tested by libtap | ||
| 11 | * | ||
| 12 | * | ||
| 13 | * This program is free software: you can redistribute it and/or modify | ||
| 14 | * it under the terms of the GNU General Public License as published by | ||
| 15 | * the Free Software Foundation, either version 3 of the License, or | ||
| 16 | * (at your option) any later version. | ||
| 17 | * | ||
| 18 | * This program is distributed in the hope that it will be useful, | ||
| 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 21 | * GNU General Public License for more details. | ||
| 22 | * | ||
| 23 | * You should have received a copy of the GNU General Public License | ||
| 24 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 25 | * | ||
| 26 | * | ||
| 27 | *****************************************************************************/ | ||
| 28 | |||
| 29 | #include "common.h" | ||
| 30 | #include "utils_disk.h" | ||
| 31 | #include "gl/fsusage.h" | ||
| 32 | #include <string.h> | ||
| 33 | |||
| 34 | void np_add_name(struct name_list **list, const char *name) { | ||
| 35 | struct name_list *new_entry; | ||
| 36 | new_entry = (struct name_list *)malloc(sizeof *new_entry); | ||
| 37 | new_entry->name = (char *)name; | ||
| 38 | new_entry->next = *list; | ||
| 39 | *list = new_entry; | ||
| 40 | } | ||
| 41 | |||
| 42 | /* @brief Initialises a new regex at the begin of list via regcomp(3) | ||
| 43 | * | ||
| 44 | * @details if the regex fails to compile the error code of regcomp(3) is returned | ||
| 45 | * and list is not modified, otherwise list is modified to point to the new | ||
| 46 | * element | ||
| 47 | * @param list Pointer to a linked list of regex_list elements | ||
| 48 | * @param regex the string containing the regex which should be inserted into the list | ||
| 49 | * @param clags the cflags parameter for regcomp(3) | ||
| 50 | */ | ||
| 51 | int np_add_regex(struct regex_list **list, const char *regex, int cflags) { | ||
| 52 | struct regex_list *new_entry = (struct regex_list *)malloc(sizeof *new_entry); | ||
| 53 | |||
| 54 | if (new_entry == NULL) { | ||
| 55 | die(STATE_UNKNOWN, _("Cannot allocate memory: %s"), strerror(errno)); | ||
| 56 | } | ||
| 57 | |||
| 58 | int regcomp_result = regcomp(&new_entry->regex, regex, cflags); | ||
| 59 | |||
| 60 | if (!regcomp_result) { | ||
| 61 | // regcomp succeeded | ||
| 62 | new_entry->next = *list; | ||
| 63 | *list = new_entry; | ||
| 64 | |||
| 65 | return 0; | ||
| 66 | } else { | ||
| 67 | // regcomp failed | ||
| 68 | free(new_entry); | ||
| 69 | |||
| 70 | return regcomp_result; | ||
| 71 | } | ||
| 72 | } | ||
| 73 | |||
| 74 | /* Initialises a new parameter at the end of list */ | ||
| 75 | struct parameter_list *np_add_parameter(struct parameter_list **list, const char *name) { | ||
| 76 | struct parameter_list *current = *list; | ||
| 77 | struct parameter_list *new_path; | ||
| 78 | new_path = (struct parameter_list *)malloc(sizeof *new_path); | ||
| 79 | new_path->name = (char *)malloc(strlen(name) + 1); | ||
| 80 | new_path->best_match = NULL; | ||
| 81 | new_path->name_next = NULL; | ||
| 82 | new_path->name_prev = NULL; | ||
| 83 | new_path->freespace_bytes = NULL; | ||
| 84 | new_path->freespace_units = NULL; | ||
| 85 | new_path->freespace_percent = NULL; | ||
| 86 | new_path->usedspace_bytes = NULL; | ||
| 87 | new_path->usedspace_units = NULL; | ||
| 88 | new_path->usedspace_percent = NULL; | ||
| 89 | new_path->usedinodes_percent = NULL; | ||
| 90 | new_path->freeinodes_percent = NULL; | ||
| 91 | new_path->group = NULL; | ||
| 92 | new_path->dfree_pct = -1; | ||
| 93 | new_path->dused_pct = -1; | ||
| 94 | new_path->total = 0; | ||
| 95 | new_path->available = 0; | ||
| 96 | new_path->available_to_root = 0; | ||
| 97 | new_path->used = 0; | ||
| 98 | new_path->dused_units = 0; | ||
| 99 | new_path->dfree_units = 0; | ||
| 100 | new_path->dtotal_units = 0; | ||
| 101 | new_path->inodes_total = 0; | ||
| 102 | new_path->inodes_free = 0; | ||
| 103 | new_path->inodes_free_to_root = 0; | ||
| 104 | new_path->inodes_used = 0; | ||
| 105 | new_path->dused_inodes_percent = 0; | ||
| 106 | new_path->dfree_inodes_percent = 0; | ||
| 107 | |||
| 108 | strcpy(new_path->name, name); | ||
| 109 | |||
| 110 | if (current == NULL) { | ||
| 111 | *list = new_path; | ||
| 112 | new_path->name_prev = NULL; | ||
| 113 | } else { | ||
| 114 | while (current->name_next) { | ||
| 115 | current = current->name_next; | ||
| 116 | } | ||
| 117 | current->name_next = new_path; | ||
| 118 | new_path->name_prev = current; | ||
| 119 | } | ||
| 120 | return new_path; | ||
| 121 | } | ||
| 122 | |||
| 123 | /* Delete a given parameter from list and return pointer to next element*/ | ||
| 124 | struct parameter_list *np_del_parameter(struct parameter_list *item, struct parameter_list *prev) { | ||
| 125 | if (item == NULL) { | ||
| 126 | return NULL; | ||
| 127 | } | ||
| 128 | struct parameter_list *next; | ||
| 129 | |||
| 130 | if (item->name_next) | ||
| 131 | next = item->name_next; | ||
| 132 | else | ||
| 133 | next = NULL; | ||
| 134 | |||
| 135 | if (next) | ||
| 136 | next->name_prev = prev; | ||
| 137 | |||
| 138 | if (prev) | ||
| 139 | prev->name_next = next; | ||
| 140 | |||
| 141 | if (item->name) { | ||
| 142 | free(item->name); | ||
| 143 | } | ||
| 144 | free(item); | ||
| 145 | |||
| 146 | return next; | ||
| 147 | } | ||
| 148 | |||
| 149 | /* returns a pointer to the struct found in the list */ | ||
| 150 | struct parameter_list *np_find_parameter(struct parameter_list *list, const char *name) { | ||
| 151 | struct parameter_list *temp_list; | ||
| 152 | for (temp_list = list; temp_list; temp_list = temp_list->name_next) { | ||
| 153 | if (!strcmp(temp_list->name, name)) | ||
| 154 | return temp_list; | ||
| 155 | } | ||
| 156 | |||
| 157 | return NULL; | ||
| 158 | } | ||
| 159 | |||
| 160 | void np_set_best_match(struct parameter_list *desired, struct mount_entry *mount_list, bool exact) { | ||
| 161 | struct parameter_list *d; | ||
| 162 | for (d = desired; d; d = d->name_next) { | ||
| 163 | if (!d->best_match) { | ||
| 164 | struct mount_entry *me; | ||
| 165 | size_t name_len = strlen(d->name); | ||
| 166 | size_t best_match_len = 0; | ||
| 167 | struct mount_entry *best_match = NULL; | ||
| 168 | struct fs_usage fsp; | ||
| 169 | |||
| 170 | /* set best match if path name exactly matches a mounted device name */ | ||
| 171 | for (me = mount_list; me; me = me->me_next) { | ||
| 172 | if (strcmp(me->me_devname, d->name) == 0) { | ||
| 173 | if (get_fs_usage(me->me_mountdir, me->me_devname, &fsp) >= 0) { | ||
| 174 | best_match = me; | ||
| 175 | } | ||
| 176 | } | ||
| 177 | } | ||
| 178 | |||
| 179 | /* set best match by directory name if no match was found by devname */ | ||
| 180 | if (!best_match) { | ||
| 181 | for (me = mount_list; me; me = me->me_next) { | ||
| 182 | size_t len = strlen(me->me_mountdir); | ||
| 183 | if ((!exact && | ||
| 184 | (best_match_len <= len && len <= name_len && (len == 1 || strncmp(me->me_mountdir, d->name, len) == 0))) || | ||
| 185 | (exact && strcmp(me->me_mountdir, d->name) == 0)) { | ||
| 186 | if (get_fs_usage(me->me_mountdir, me->me_devname, &fsp) >= 0) { | ||
| 187 | best_match = me; | ||
| 188 | best_match_len = len; | ||
| 189 | } | ||
| 190 | } | ||
| 191 | } | ||
| 192 | } | ||
| 193 | |||
| 194 | if (best_match) { | ||
| 195 | d->best_match = best_match; | ||
| 196 | } else { | ||
| 197 | d->best_match = NULL; /* Not sure why this is needed as it should be null on initialisation */ | ||
| 198 | } | ||
| 199 | } | ||
| 200 | } | ||
| 201 | } | ||
| 202 | |||
| 203 | /* Returns true if name is in list */ | ||
| 204 | bool np_find_name(struct name_list *list, const char *name) { | ||
| 205 | const struct name_list *n; | ||
| 206 | |||
| 207 | if (list == NULL || name == NULL) { | ||
| 208 | return false; | ||
| 209 | } | ||
| 210 | for (n = list; n; n = n->next) { | ||
| 211 | if (!strcmp(name, n->name)) { | ||
| 212 | return true; | ||
| 213 | } | ||
| 214 | } | ||
| 215 | return false; | ||
| 216 | } | ||
| 217 | |||
| 218 | /* Returns true if name is in list */ | ||
| 219 | bool np_find_regmatch(struct regex_list *list, const char *name) { | ||
| 220 | int len; | ||
| 221 | regmatch_t m; | ||
| 222 | |||
| 223 | if (name == NULL) { | ||
| 224 | return false; | ||
| 225 | } | ||
| 226 | |||
| 227 | len = strlen(name); | ||
| 228 | |||
| 229 | for (; list; list = list->next) { | ||
| 230 | /* Emulate a full match as if surrounded with ^( )$ | ||
| 231 | by checking whether the match spans the whole name */ | ||
| 232 | if (!regexec(&list->regex, name, 1, &m, 0) && m.rm_so == 0 && m.rm_eo == len) { | ||
| 233 | return true; | ||
| 234 | } | ||
| 235 | } | ||
| 236 | |||
| 237 | return false; | ||
| 238 | } | ||
| 239 | |||
| 240 | bool np_seen_name(struct name_list *list, const char *name) { | ||
| 241 | const struct name_list *s; | ||
| 242 | for (s = list; s; s = s->next) { | ||
| 243 | if (!strcmp(s->name, name)) { | ||
| 244 | return true; | ||
| 245 | } | ||
| 246 | } | ||
| 247 | return false; | ||
| 248 | } | ||
| 249 | |||
| 250 | bool np_regex_match_mount_entry(struct mount_entry *me, regex_t *re) { | ||
| 251 | if (regexec(re, me->me_devname, (size_t)0, NULL, 0) == 0 || regexec(re, me->me_mountdir, (size_t)0, NULL, 0) == 0) { | ||
| 252 | return true; | ||
| 253 | } | ||
| 254 | return false; | ||
| 255 | } | ||
diff --git a/lib/utils_disk.h b/lib/utils_disk.h deleted file mode 100644 index c5e81dc1..00000000 --- a/lib/utils_disk.h +++ /dev/null | |||
| @@ -1,48 +0,0 @@ | |||
| 1 | /* Header file for utils_disk */ | ||
| 2 | |||
| 3 | #include "mountlist.h" | ||
| 4 | #include "utils_base.h" | ||
| 5 | #include "regex.h" | ||
| 6 | |||
| 7 | struct name_list { | ||
| 8 | char *name; | ||
| 9 | struct name_list *next; | ||
| 10 | }; | ||
| 11 | |||
| 12 | struct regex_list { | ||
| 13 | regex_t regex; | ||
| 14 | struct regex_list *next; | ||
| 15 | }; | ||
| 16 | |||
| 17 | struct parameter_list { | ||
| 18 | char *name; | ||
| 19 | thresholds *freespace_bytes; | ||
| 20 | thresholds *freespace_units; | ||
| 21 | thresholds *freespace_percent; | ||
| 22 | thresholds *usedspace_bytes; | ||
| 23 | thresholds *usedspace_units; | ||
| 24 | thresholds *usedspace_percent; | ||
| 25 | thresholds *usedinodes_percent; | ||
| 26 | thresholds *freeinodes_percent; | ||
| 27 | char *group; | ||
| 28 | struct mount_entry *best_match; | ||
| 29 | struct parameter_list *name_next; | ||
| 30 | struct parameter_list *name_prev; | ||
| 31 | uintmax_t total, available, available_to_root, used, inodes_free, inodes_free_to_root, inodes_used, inodes_total; | ||
| 32 | double dfree_pct, dused_pct; | ||
| 33 | uint64_t dused_units, dfree_units, dtotal_units; | ||
| 34 | double dused_inodes_percent, dfree_inodes_percent; | ||
| 35 | }; | ||
| 36 | |||
| 37 | void np_add_name(struct name_list **list, const char *name); | ||
| 38 | bool np_find_name(struct name_list *list, const char *name); | ||
| 39 | bool np_seen_name(struct name_list *list, const char *name); | ||
| 40 | int np_add_regex(struct regex_list **list, const char *regex, int cflags); | ||
| 41 | bool np_find_regmatch(struct regex_list *list, const char *name); | ||
| 42 | struct parameter_list *np_add_parameter(struct parameter_list **list, const char *name); | ||
| 43 | struct parameter_list *np_find_parameter(struct parameter_list *list, const char *name); | ||
| 44 | struct parameter_list *np_del_parameter(struct parameter_list *item, struct parameter_list *prev); | ||
| 45 | |||
| 46 | int search_parameter_list(struct parameter_list *list, const char *name); | ||
| 47 | void np_set_best_match(struct parameter_list *desired, struct mount_entry *mount_list, bool exact); | ||
| 48 | bool np_regex_match_mount_entry(struct mount_entry *me, regex_t *re); | ||
