summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--NEWS6
-rw-r--r--lib/tests/test_disk.c45
-rw-r--r--lib/utils_disk.c21
-rw-r--r--lib/utils_disk.h2
-rw-r--r--plugins/check_disk.c81
-rw-r--r--plugins/t/check_disk.t31
6 files changed, 168 insertions, 18 deletions
diff --git a/NEWS b/NEWS
index 7572b59..2ef3915 100644
--- a/NEWS
+++ b/NEWS
@@ -20,6 +20,12 @@ This file documents the major additions and syntax changes between releases.
20 - stop evaluating command line options through shell twice 20 - stop evaluating command line options through shell twice
21 - enforce a full path for the command to run 21 - enforce a full path for the command to run
22 The "negate" utility can now remap custom states 22 The "negate" utility can now remap custom states
23 New check_disk -i/-I option to ignore pathes/partitions based on regular expressions
24 New check_disk -A option to select all filesystems explicitly
25 WARNING: check_disk's -E option must now be passed before -p or -r/-R arguments
26 Passing -E after -p or -r results in UNKNOWN state, now
27 This is needed due to the new ignore feature
28 Fix bug when mixing case sensitive and case insensitive regex arguments
23 29
241.4.9 4th June 2006 301.4.9 4th June 2006
25 Inclusion of contrib/check_cluster2 as check_cluster with some improvements 31 Inclusion of contrib/check_cluster2 as check_cluster with some improvements
diff --git a/lib/tests/test_disk.c b/lib/tests/test_disk.c
index ac9db00..fcde4f8 100644
--- a/lib/tests/test_disk.c
+++ b/lib/tests/test_disk.c
@@ -36,14 +36,15 @@ main (int argc, char **argv)
36 struct name_list *dummy_mountlist = NULL; 36 struct name_list *dummy_mountlist = NULL;
37 struct name_list *temp_name; 37 struct name_list *temp_name;
38 struct parameter_list *paths = NULL; 38 struct parameter_list *paths = NULL;
39 struct parameter_list *p; 39 struct parameter_list *p, *prev, *last;
40 40
41 struct mount_entry *dummy_mount_list; 41 struct mount_entry *dummy_mount_list;
42 struct mount_entry *me; 42 struct mount_entry *me;
43 struct mount_entry **mtail = &dummy_mount_list; 43 struct mount_entry **mtail = &dummy_mount_list;
44 int cflags = REG_NOSUB | REG_EXTENDED; 44 int cflags = REG_NOSUB | REG_EXTENDED;
45 int found = 0, count = 0;
45 46
46 plan_tests(29); 47 plan_tests(33);
47 48
48 ok( np_find_name(exclude_filesystem, "/var/log") == FALSE, "/var/log not in list"); 49 ok( np_find_name(exclude_filesystem, "/var/log") == FALSE, "/var/log not in list");
49 np_add_name(&exclude_filesystem, "/var/log"); 50 np_add_name(&exclude_filesystem, "/var/log");
@@ -160,6 +161,46 @@ main (int argc, char **argv)
160 } 161 }
161 } 162 }
162 163
164 /* test deleting first element in paths */
165 paths = np_del_parameter(paths, NULL);
166 for (p = paths; p; p = p->name_next) {
167 if (! strcmp(p->name, "/home/groups"))
168 found = 1;
169 }
170 ok(found == 0, "first element successfully deleted");
171 found = 0;
172
173 p=paths;
174 while (p) {
175 if (! strcmp(p->name, "/tmp"))
176 p = np_del_parameter(p, prev);
177 else {
178 prev = p;
179 p = p->name_next;
180 }
181 }
182
183 for (p = paths; p; p = p->name_next) {
184 if (! strcmp(p->name, "/tmp"))
185 found = 1;
186 if (p->name_next)
187 prev = p;
188 else
189 last = p;
190 }
191 ok(found == 0, "/tmp element successfully deleted");
192
193 p = np_del_parameter(last, prev);
194 for (p = paths; p; p = p->name_next) {
195 if (! strcmp(p->name, "/home"))
196 found = 1;
197 last = p;
198 count++;
199 }
200 ok(found == 0, "last (/home) element successfully deleted");
201 ok(count == 2, "two elements remaining");
202
203
163 return exit_status(); 204 return exit_status();
164} 205}
165 206
diff --git a/lib/utils_disk.c b/lib/utils_disk.c
index 96f5a30..3f9c8a9 100644
--- a/lib/utils_disk.c
+++ b/lib/utils_disk.c
@@ -74,6 +74,26 @@ np_add_parameter(struct parameter_list **list, const char *name)
74 return new_path; 74 return new_path;
75} 75}
76 76
77/* Delete a given parameter from list and return pointer to next element*/
78struct parameter_list *
79np_del_parameter(struct parameter_list *item, struct parameter_list *prev)
80{
81 struct parameter_list *next;
82 if (item->name_next)
83 next = item->name_next;
84 else
85 next = NULL;
86
87
88 free(item);
89 if (prev)
90 prev->name_next = next;
91
92 return next;
93
94}
95
96
77/* returns a pointer to the struct found in the list */ 97/* returns a pointer to the struct found in the list */
78struct parameter_list * 98struct parameter_list *
79np_find_parameter(struct parameter_list *list, const char *name) 99np_find_parameter(struct parameter_list *list, const char *name)
@@ -166,3 +186,4 @@ np_regex_match_mount_entry (struct mount_entry* me, regex_t* re)
166 return false; 186 return false;
167 } 187 }
168} 188}
189
diff --git a/lib/utils_disk.h b/lib/utils_disk.h
index 6263339..f99b905 100644
--- a/lib/utils_disk.h
+++ b/lib/utils_disk.h
@@ -31,6 +31,8 @@ int np_find_name (struct name_list *list, const char *name);
31int np_seen_name (struct name_list *list, const char *name); 31int np_seen_name (struct name_list *list, const char *name);
32struct parameter_list *np_add_parameter(struct parameter_list **list, const char *name); 32struct parameter_list *np_add_parameter(struct parameter_list **list, const char *name);
33struct parameter_list *np_find_parameter(struct parameter_list *list, const char *name); 33struct parameter_list *np_find_parameter(struct parameter_list *list, const char *name);
34struct parameter_list *np_del_parameter(struct parameter_list *item, struct parameter_list *prev);
35
34int search_parameter_list (struct parameter_list *list, const char *name); 36int search_parameter_list (struct parameter_list *list, const char *name);
35void np_set_best_match(struct parameter_list *desired, struct mount_entry *mount_list, int exact); 37void np_set_best_match(struct parameter_list *desired, struct mount_entry *mount_list, int exact);
36int np_regex_match_mount_entry (struct mount_entry* me, regex_t* re); 38int np_regex_match_mount_entry (struct mount_entry* me, regex_t* re);
diff --git a/plugins/check_disk.c b/plugins/check_disk.c
index 90b2248..d267409 100644
--- a/plugins/check_disk.c
+++ b/plugins/check_disk.c
@@ -447,15 +447,16 @@ int
447process_arguments (int argc, char **argv) 447process_arguments (int argc, char **argv)
448{ 448{
449 int c, err; 449 int c, err;
450 struct parameter_list *se, *se2; 450 struct parameter_list *se;
451 struct parameter_list *temp_list; 451 struct parameter_list *temp_list = NULL, *previous = NULL;
452 struct parameter_list *temp_path_select_list = NULL; 452 struct parameter_list *temp_path_select_list = NULL;
453 struct mount_entry *me; 453 struct mount_entry *me, *temp_me;
454 int result = OK; 454 int result = OK;
455 regex_t re; 455 regex_t re;
456 int cflags = REG_NOSUB | REG_EXTENDED; 456 int cflags = REG_NOSUB | REG_EXTENDED;
457 int default_cflags = cflags;
457 char errbuf[MAX_INPUT_BUFFER]; 458 char errbuf[MAX_INPUT_BUFFER];
458 bool fnd = false; 459 int fnd = 0;
459 460
460 int option = 0; 461 int option = 0;
461 static struct option longopts[] = { 462 static struct option longopts[] = {
@@ -478,9 +479,14 @@ process_arguments (int argc, char **argv)
478 {"eregi-partition", required_argument, 0, 'R'}, 479 {"eregi-partition", required_argument, 0, 'R'},
479 {"ereg-path", required_argument, 0, 'r'}, 480 {"ereg-path", required_argument, 0, 'r'},
480 {"ereg-partition", required_argument, 0, 'r'}, 481 {"ereg-partition", required_argument, 0, 'r'},
482 {"ignore-ereg-path", required_argument, 0, 'i'},
483 {"ignore-ereg-partition", required_argument, 0, 'i'},
484 {"ignore-eregi-path", required_argument, 0, 'I'},
485 {"ignore-eregi-partition", required_argument, 0, 'I'},
481 {"mountpoint", no_argument, 0, 'M'}, 486 {"mountpoint", no_argument, 0, 'M'},
482 {"errors-only", no_argument, 0, 'e'}, 487 {"errors-only", no_argument, 0, 'e'},
483 {"exact-match", no_argument, 0, 'E'}, 488 {"exact-match", no_argument, 0, 'E'},
489 {"all", no_argument, 0, 'A'},
484 {"verbose", no_argument, 0, 'v'}, 490 {"verbose", no_argument, 0, 'v'},
485 {"quiet", no_argument, 0, 'q'}, 491 {"quiet", no_argument, 0, 'q'},
486 {"clear", no_argument, 0, 'C'}, 492 {"clear", no_argument, 0, 'C'},
@@ -499,7 +505,7 @@ process_arguments (int argc, char **argv)
499 strcpy (argv[c], "-t"); 505 strcpy (argv[c], "-t");
500 506
501 while (1) { 507 while (1) {
502 c = getopt_long (argc, argv, "+?VqhveCt:c:w:K:W:u:p:x:X:mklg:R:r:ME", longopts, &option); 508 c = getopt_long (argc, argv, "+?VqhveCt:c:w:K:W:u:p:x:X:mklg:R:r:i:I:MEA", longopts, &option);
503 509
504 if (c == -1 || c == EOF) 510 if (c == -1 || c == EOF)
505 break; 511 break;
@@ -613,18 +619,13 @@ process_arguments (int argc, char **argv)
613 die (STATE_UNKNOWN, "DISK %s: %s", _("UNKNOWN"), _("Must set a threshold value before using -p\n")); 619 die (STATE_UNKNOWN, "DISK %s: %s", _("UNKNOWN"), _("Must set a threshold value before using -p\n"));
614 } 620 }
615 621
616 /* get the real mountdir of the specified path. np_find_parameter won't find an entry if -p is not
617 * exactly the same string as the mountdir */
618 se2 = np_add_parameter(&temp_path_select_list, optarg);
619 np_set_best_match(se2, mount_list, FALSE);
620
621
622 /* add parameter if not found. overwrite thresholds if path has already been added */ 622 /* add parameter if not found. overwrite thresholds if path has already been added */
623 if (! (se = np_find_parameter(path_select_list, optarg))) { 623 if (! (se = np_find_parameter(path_select_list, optarg))) {
624 se = np_add_parameter(&path_select_list, optarg); 624 se = np_add_parameter(&path_select_list, optarg);
625 } 625 }
626 se->group = group; 626 se->group = group;
627 set_all_thresholds(se); 627 set_all_thresholds(se);
628 np_set_best_match(se, mount_list, exact_match);
628 path_selected = true; 629 path_selected = true;
629 break; 630 break;
630 case 'x': /* exclude path or partition */ 631 case 'x': /* exclude path or partition */
@@ -644,13 +645,56 @@ process_arguments (int argc, char **argv)
644 erronly = TRUE; 645 erronly = TRUE;
645 break; 646 break;
646 case 'E': 647 case 'E':
648 if (path_selected)
649 die (STATE_UNKNOWN, "DISK %s: %s", _("UNKNOWN"), _("Must set -E before selecting pathes\n"));
647 exact_match = TRUE; 650 exact_match = TRUE;
648 break; 651 break;
649 case 'g': 652 case 'g':
650 if (path_selected) 653 if (path_selected)
651 die (STATE_UNKNOWN, "DISK %s: %s", _("UNKNOWN"), _("Must set group value before using -p\n")); 654 die (STATE_UNKNOWN, "DISK %s: %s", _("UNKNOWN"), _("Must set group value before selecting pathes \n"));
652 group = optarg; 655 group = optarg;
653 break; 656 break;
657 case 'I':
658 cflags |= REG_ICASE;
659 case 'i':
660 if (!path_selected)
661 die (STATE_UNKNOWN, "DISK %s: %s\n", _("UNKNOWN"), _("Pathes need to be selected before using -i/-I. Use -A to select all pathes explicitly"));
662 err = regcomp(&re, optarg, cflags);
663 if (err != 0) {
664 regerror (err, &re, errbuf, MAX_INPUT_BUFFER);
665 die (STATE_UNKNOWN, "DISK %s: %s - %s\n",_("UNKNOWN"), _("Could not compile regular expression"), errbuf);
666 }
667
668 temp_list = path_select_list;
669
670 previous = NULL;
671 while (temp_list) {
672 if (temp_list->best_match) {
673 if (np_regex_match_mount_entry(temp_list->best_match, &re)) {
674
675 if (verbose >=3)
676 printf("ignoring %s matching regex\n", temp_list->name);
677
678 temp_list = np_del_parameter(temp_list, previous);
679 /* pointer to first element needs to be uĆ¼dated if first item gets deleted */
680 if (previous == NULL)
681 path_select_list = temp_list;
682 } else {
683 previous = temp_list;
684 temp_list = temp_list->name_next;
685 }
686 } else {
687 previous = temp_list;
688 temp_list = temp_list->name_next;
689 }
690 }
691
692
693 cflags = default_cflags;
694 break;
695
696 case 'A':
697 optarg = strdup(".*");
654 case 'R': 698 case 'R':
655 cflags |= REG_ICASE; 699 cflags |= REG_ICASE;
656 case 'r': 700 case 'r':
@@ -669,9 +713,9 @@ process_arguments (int argc, char **argv)
669 713
670 for (me = mount_list; me; me = me->me_next) { 714 for (me = mount_list; me; me = me->me_next) {
671 if (np_regex_match_mount_entry(me, &re)) { 715 if (np_regex_match_mount_entry(me, &re)) {
672 fnd = true; 716 fnd = true;
673 if (verbose > 3) 717 if (verbose > 3)
674 printf("%s %s matching expression %s\n", me->me_devname, me->me_mountdir, optarg); 718 printf("%s %s matching expression %s\n", me->me_devname, me->me_mountdir, optarg);
675 719
676 /* add parameter if not found. overwrite thresholds if path has already been added */ 720 /* add parameter if not found. overwrite thresholds if path has already been added */
677 if (! (se = np_find_parameter(path_select_list, me->me_mountdir))) { 721 if (! (se = np_find_parameter(path_select_list, me->me_mountdir))) {
@@ -688,6 +732,9 @@ process_arguments (int argc, char **argv)
688 732
689 fnd = false; 733 fnd = false;
690 path_selected = true; 734 path_selected = true;
735 np_set_best_match(path_select_list, mount_list, exact_match);
736 cflags = default_cflags;
737
691 break; 738 break;
692 case 'M': /* display mountpoint */ 739 case 'M': /* display mountpoint */
693 display_mntp = TRUE; 740 display_mntp = TRUE;
@@ -871,10 +918,16 @@ print_help (void)
871 printf (" %s\n", _("Display the mountpoint instead of the partition")); 918 printf (" %s\n", _("Display the mountpoint instead of the partition"));
872 printf (" %s\n", "-m, --megabytes"); 919 printf (" %s\n", "-m, --megabytes");
873 printf (" %s\n", _("Same as '--units MB'")); 920 printf (" %s\n", _("Same as '--units MB'"));
921 printf (" %s\n", "-A, --all");
922 printf (" %s\n", _("Explicitly select all pathes. This is equivalent to -R '.*'"));
874 printf (" %s\n", "-R, --eregi-path=PATH, --eregi-partition=PARTITION"); 923 printf (" %s\n", "-R, --eregi-path=PATH, --eregi-partition=PARTITION");
875 printf (" %s\n", _("Case insensitive regular expression for path/partition (may be repeated)")); 924 printf (" %s\n", _("Case insensitive regular expression for path/partition (may be repeated)"));
876 printf (" %s\n", "-r, --ereg-path=PATH, --ereg-partition=PARTITION"); 925 printf (" %s\n", "-r, --ereg-path=PATH, --ereg-partition=PARTITION");
877 printf (" %s\n", _("Regular expression for path or partition (may be repeated)")); 926 printf (" %s\n", _("Regular expression for path or partition (may be repeated)"));
927 printf (" %s\n", "-I, --ignore-eregi-path=PATH, --ignore-eregi-partition=PARTITION");
928 printf (" %s\n", _("Regular expression to ignore selected path/partition (case insensitive) (may be repeated)"));
929 printf (" %s\n", "-i, --ignore-ereg-path=PATH, --ignore-ereg-partition=PARTITION");
930 printf (" %s\n", _("Regular expression to ignore selected path or partition (may be repeated)"));
878 printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT); 931 printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT);
879 printf (" %s\n", "-u, --units=STRING"); 932 printf (" %s\n", "-u, --units=STRING");
880 printf (" %s\n", _("Choose bytes, kB, MB, GB, TB (default: MB)")); 933 printf (" %s\n", _("Choose bytes, kB, MB, GB, TB (default: MB)"));
diff --git a/plugins/t/check_disk.t b/plugins/t/check_disk.t
index 4f5c4bc..99c434a 100644
--- a/plugins/t/check_disk.t
+++ b/plugins/t/check_disk.t
@@ -24,7 +24,7 @@ my $mountpoint2_valid = getTestParameter( "NP_MOUNTPOINT2_VALID", "Path to anoth
24if ($mountpoint_valid eq "" or $mountpoint2_valid eq "") { 24if ($mountpoint_valid eq "" or $mountpoint2_valid eq "") {
25 plan skip_all => "Need 2 mountpoints to test"; 25 plan skip_all => "Need 2 mountpoints to test";
26} else { 26} else {
27 plan tests => 69; 27 plan tests => 78;
28} 28}
29 29
30$result = NPTest->testCmd( 30$result = NPTest->testCmd(
@@ -284,9 +284,15 @@ $result = NPTest->testCmd( "./check_disk -w 0% -c 0% -p /etc" );
284cmp_ok( $result->return_code, '==', 0, "Checking /etc - should return info for /" ); 284cmp_ok( $result->return_code, '==', 0, "Checking /etc - should return info for /" );
285cmp_ok( $result->output, 'eq', $root_output, "check_disk /etc gives same as check_disk /"); 285cmp_ok( $result->output, 'eq', $root_output, "check_disk /etc gives same as check_disk /");
286 286
287$result = NPTest->testCmd( "./check_disk -w 0% -c 0% -p /etc -E" ); 287$result = NPTest->testCmd( "./check_disk -w 0% -c 0% -E -p /etc " );
288cmp_ok( $result->return_code, '==', 2, "... unless -E/--exact-match is specified"); 288cmp_ok( $result->return_code, '==', 2, "... unless -E/--exact-match is specified");
289 289
290$result = NPTest->testCmd( "./check_disk -w 0% -c 0% -p /etc -E " );
291cmp_ok( $result->return_code, '==', 3, "-E/--exact-match must be specified before -p");
292
293$result = NPTest->testCmd( "./check_disk -w 0% -c 0% -r /etc -E " );
294cmp_ok( $result->return_code, '==', 3, "-E/--exact-match must be specified before -r");
295
290$result = NPTest->testCmd( "./check_disk -w 0% -c 0% -p / -p /bob" ); 296$result = NPTest->testCmd( "./check_disk -w 0% -c 0% -p / -p /bob" );
291cmp_ok( $result->return_code, '==', 2, "Checking / and /bob gives critical"); 297cmp_ok( $result->return_code, '==', 2, "Checking / and /bob gives critical");
292unlike( $result->perf_output, '/\/bob/', "perf data does not have /bob in it"); 298unlike( $result->perf_output, '/\/bob/', "perf data does not have /bob in it");
@@ -318,3 +324,24 @@ cmp_ok( $result->return_code, '==', 3, "Invalid options: -p must come after grou
318$result = NPTest->testCmd( "./check_disk -w 1 -c 1 -r '('" ); 324$result = NPTest->testCmd( "./check_disk -w 1 -c 1 -r '('" );
319cmp_ok( $result->return_code, '==', 3, "Exit UNKNOWN if regex is not compileable"); 325cmp_ok( $result->return_code, '==', 3, "Exit UNKNOWN if regex is not compileable");
320 326
327# ignore: exit unknown, if all pathes are deselected using -i
328$result = NPTest->testCmd( "./check_disk -w 0% -c 0% -p $mountpoint_valid -p $mountpoint2_valid -i '$mountpoint_valid' -i '$mountpoint2_valid'" );
329cmp_ok( $result->return_code, '==', 3, "ignore-ereg: Unknown if all fs are ignored (case sensitive)");
330
331# ignore: exit unknown, if all pathes are deselected using -I
332$result = NPTest->testCmd( "./check_disk -w 0% -c 0% -p $mountpoint_valid -p $mountpoint2_valid -I '".uc($mountpoint_valid)."' -I '".uc($mountpoint2_valid)."'" );
333cmp_ok( $result->return_code, '==', 3, "ignore-ereg: Unknown if all fs are ignored (case insensitive)");
334
335# ignore: exit unknown, if all pathes are deselected using -i
336$result = NPTest->testCmd( "./check_disk -w 0% -c 0% -p $mountpoint_valid -p $mountpoint2_valid -i '.*'" );
337cmp_ok( $result->return_code, '==', 3, "ignore-ereg: Unknown if all fs are ignored using -i '.*'");
338
339# ignore: test if ignored path is actually ignored
340$result = NPTest->testCmd( "./check_disk -w 0% -c 0% -p $mountpoint_valid -p $mountpoint2_valid -i '^$mountpoint2_valid\$'");
341like( $result->output, qr/$mountpoint_valid/, "output data does have $mountpoint_valid in it");
342unlike( $result->output, qr/$mountpoint2_valid/, "output data does not have $mountpoint2_valid in it");
343
344# ignore: test if all pathes are listed when ignore regex doesn't match
345$result = NPTest->testCmd( "./check_disk -w 0% -c 0% -p $mountpoint_valid -p $mountpoint2_valid -i '^barbazJodsf\$'");
346like( $result->output, qr/$mountpoint_valid/, "ignore: output data does have $mountpoint_valid when regex doesn't match");
347like( $result->output, qr/$mountpoint2_valid/,"ignore: output data does have $mountpoint2_valid when regex doesn't match");