summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: ee03f14)
raw | patch | inline | side by side (parent: ee03f14)
author | Ton Voon <tonvoon@users.sourceforge.net> | |
Wed, 12 Jul 2006 19:30:20 +0000 (19:30 +0000) | ||
committer | Ton Voon <tonvoon@users.sourceforge.net> | |
Wed, 12 Jul 2006 19:30:20 +0000 (19:30 +0000) |
now work out best match or exact match.
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1448 f882894a-f735-0410-b71e-b25c423dba1c
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1448 f882894a-f735-0410-b71e-b25c423dba1c
diff --git a/plugins/check_disk.c b/plugins/check_disk.c
index f0a679dd5f13f9b2843363ccceffeab2ada7e764..8e9c1fceabc39a773c446604872ff76b46a1bbcc 100644 (file)
--- a/plugins/check_disk.c
+++ b/plugins/check_disk.c
SunOs4.1.3, for one. It is *not* necessary on Linux. */
/* static int require_sync = 0; */
-/* A filesystem type to display. */
-struct parameter_list
-{
- char *name;
- int found;
- int found_len;
- uintmax_t w_df;
- uintmax_t c_df;
- double w_dfp;
- double c_dfp;
- double w_idfp;
- double c_idfp;
- struct parameter_list *name_next;
-};
-
/* Linked list of filesystem types to display.
If `fs_select_list' is NULL, list all types.
This table is generated dynamically from command-line options,
index 94b5122a51ee59781ad801fdd2f1945ffe474fdd..6dc692f54a5ca6787cdb2f5eb4614ca75950c3f0 100644 (file)
--- a/plugins/tests/.cvsignore
+++ b/plugins/tests/.cvsignore
Makefile
Makefile.in
test_utils
+test_disk
.deps
index 19cc3acd30dd390bd2a62b02e8a8eb0e4c831ee6..8940236b069c5b8147c916d0c0c4069d2962a7aa 100644 (file)
{
struct name_list *exclude_filesystem=NULL;
struct name_list *exclude_fstype=NULL;
+ struct name_list *dummy_mountlist = NULL;
+ struct name_list *temp_name;
+ struct parameter_list *paths = NULL;
+ struct parameter_list *p;
- plan_tests(8);
+ struct mount_entry *dummy_mount_list;
+ struct mount_entry *me;
+ struct mount_entry **mtail = &dummy_mount_list;
- ok( np_find_name(exclude_filesystem, "/var") == FALSE, "/var not in list");
- np_add_name(&exclude_filesystem, "/var");
- ok( np_find_name(exclude_filesystem, "/var") == TRUE, "is in list now");
+ plan_tests(17);
+
+ ok( np_find_name(exclude_filesystem, "/var/log") == FALSE, "/var/log not in list");
+ np_add_name(&exclude_filesystem, "/var/log");
+ ok( np_find_name(exclude_filesystem, "/var/log") == TRUE, "is in list now");
ok( np_find_name(exclude_filesystem, "/home") == FALSE, "/home not in list");
np_add_name(&exclude_filesystem, "/home");
ok( np_find_name(exclude_filesystem, "/home") == TRUE, "is in list now");
- ok( np_find_name(exclude_filesystem, "/var") == TRUE, "/var still in list");
+ ok( np_find_name(exclude_filesystem, "/var/log") == TRUE, "/var/log still in list");
ok( np_find_name(exclude_fstype, "iso9660") == FALSE, "iso9660 not in list");
np_add_name(&exclude_fstype, "iso9660");
ok( np_find_name(exclude_filesystem, "iso9660") == FALSE, "Make sure no clashing in variables");
-
-
-
/*
- range = parse_range_string("6");
- ok( range != NULL, "'6' is valid range");
- ok( range->start == 0, "Start correct");
- ok( range->start_infinity == FALSE, "Not using negative infinity");
- ok( range->end == 6, "End correct");
- ok( range->end_infinity == FALSE, "Not using infinity");
- free(range);
-
- range = parse_range_string("-7:23");
- ok( range != NULL, "'-7:23' is valid range");
- ok( range->start == -7, "Start correct");
- ok( range->start_infinity == FALSE, "Not using negative infinity");
- ok( range->end == 23, "End correct");
- ok( range->end_infinity == FALSE, "Not using infinity");
- free(range);
-
- range = parse_range_string(":5.75");
- ok( range != NULL, "':5.75' is valid range");
- ok( range->start == 0, "Start correct");
- ok( range->start_infinity == FALSE, "Not using negative infinity");
- ok( range->end == 5.75, "End correct");
- ok( range->end_infinity == FALSE, "Not using infinity");
- free(range);
-
- range = parse_range_string("~:-95.99");
- ok( range != NULL, "~:-95.99' is valid range");
- ok( range->start_infinity == TRUE, "Using negative infinity");
- ok( range->end == -95.99, "End correct (with rounding errors)");
- ok( range->end_infinity == FALSE, "Not using infinity");
- free(range);
+ for (temp_name = exclude_filesystem; temp_name; temp_name = temp_name->next) {
+ printf("Name: %s\n", temp_name->name);
+ }
*/
+ me = (struct mount_entry *) malloc(sizeof *me);
+ me->me_devname = strdup("/dev/c0t0d0s0");
+ me->me_mountdir = strdup("/");
+ *mtail = me;
+ mtail = &me->me_next;
+
+ me = (struct mount_entry *) malloc(sizeof *me);
+ me->me_devname = strdup("/dev/c1t0d1s0");
+ me->me_mountdir = strdup("/var");
+ *mtail = me;
+ mtail = &me->me_next;
+
+ me = (struct mount_entry *) malloc(sizeof *me);
+ me->me_devname = strdup("/dev/c2t0d0s0");
+ me->me_mountdir = strdup("/home");
+ *mtail = me;
+ mtail = &me->me_next;
+
+
+ np_add_parameter(&paths, "/home/groups");
+ np_add_parameter(&paths, "/var");
+ np_add_parameter(&paths, "/tmp");
+ np_add_parameter(&paths, "/home/tonvoon");
+ np_add_parameter(&paths, "/dev/c2t0d0s0");
+
+ np_set_best_match(paths, dummy_mount_list, FALSE);
+ for (p = paths; p; p = p->name_next) {
+ struct mount_entry *temp_me;
+ temp_me = p->best_match;
+ if (! strcmp(p->name, "/home/groups")) {
+ ok( temp_me && !strcmp(temp_me->me_mountdir, "/home"), "/home/groups got right best match: /home");
+ } else if (! strcmp(p->name, "/var")) {
+ ok( temp_me && !strcmp(temp_me->me_mountdir, "/var"), "/var got right best match: /var");
+ } else if (! strcmp(p->name, "/tmp")) {
+ ok( temp_me && !strcmp(temp_me->me_mountdir, "/"), "/tmp got right best match: /");
+ } else if (! strcmp(p->name, "/home/tonvoon")) {
+ ok( temp_me && !strcmp(temp_me->me_mountdir, "/home"), "/home/tonvoon got right best match: /home");
+ } else if (! strcmp(p->name, "/dev/c2t0d0s0")) {
+ ok( temp_me && !strcmp(temp_me->me_devname, "/dev/c2t0d0s0"), "/dev/c2t0d0s0 got right best match: /dev/c2t0d0s0");
+ }
+ }
+
+ paths = NULL; /* Bad boy - should free, but this is a test suite */
+ np_add_parameter(&paths, "/home/groups");
+ np_add_parameter(&paths, "/var");
+ np_add_parameter(&paths, "/tmp");
+ np_add_parameter(&paths, "/home/tonvoon");
+
+ np_set_best_match(paths, dummy_mount_list, TRUE);
+ for (p = paths; p; p = p->name_next) {
+ if (! strcmp(p->name, "/home/groups")) {
+ ok( p->found == 0, "/home/groups correctly not found");
+ } else if (! strcmp(p->name, "/var")) {
+ ok( p->found == 1, "/var found");
+ } else if (! strcmp(p->name, "/tmp")) {
+ ok( p->found == 0, "/tmp correctly not found");
+ } else if (! strcmp(p->name, "/home/tonvoon")) {
+ ok( p->found == 0, "/home/tonvoon not found");
+ }
+ }
+
return exit_status();
}
diff --git a/plugins/utils_disk.c b/plugins/utils_disk.c
index 6380df35ba0fa9ddadc0a0e30b1f27c272de11fb..0a71d7920f69dd07492dc3a719fe2dca108fd716 100644 (file)
--- a/plugins/utils_disk.c
+++ b/plugins/utils_disk.c
*list = new_entry;
}
+void
+np_add_parameter(struct parameter_list **list, const char *name)
+{
+ struct parameter_list *new_path;
+ new_path = (struct parameter_list *) malloc (sizeof *new_path);
+ new_path->name = (char *) name;
+ new_path->found = 0;
+ new_path->found_len = 0;
+ new_path->w_df = 0;
+ new_path->c_df = 0;
+ new_path->w_dfp = -1.0;
+ new_path->c_dfp = -1.0;
+ new_path->w_idfp = -1.0;
+ new_path->c_idfp = -1.0;
+ new_path->name_next = *list;
+ *list = new_path;
+}
+
+void
+np_set_best_match(struct parameter_list *desired, struct mount_entry *mount_list, int exact)
+{
+ struct parameter_list *d;
+ for (d = desired; d; d= d->name_next) {
+ struct mount_entry *me;
+ size_t name_len = strlen(d->name);
+ size_t best_match_len = 0;
+ struct mount_entry *best_match = NULL;
+
+ for (me = mount_list; me; me = me->me_next) {
+ size_t len = strlen (me->me_mountdir);
+ if ((exact == FALSE && (best_match_len <= len && len <= name_len &&
+ (len == 1 || strncmp (me->me_mountdir, d->name, len) == 0)))
+ || (exact == TRUE && strcmp(me->me_mountdir, d->name)==0))
+ {
+ best_match = me;
+ best_match_len = len;
+ } else {
+ len = strlen (me->me_devname);
+ if ((exact == FALSE && (best_match_len <= len && len <= name_len &&
+ (len == 1 || strncmp (me->me_devname, d->name, len) == 0)))
+ || (exact == TRUE && strcmp(me->me_devname, d->name)==0))
+ {
+ best_match = me;
+ best_match_len = len;
+ }
+ }
+ }
+ if (best_match) {
+ d->best_match = best_match;
+ d->found = TRUE;
+ }
+ }
+}
+
/* Returns TRUE if name is in list */
int
np_find_name (struct name_list *list, const char *name)
diff --git a/plugins/utils_disk.h b/plugins/utils_disk.h
index f173c916a204bdde708d759fb7e4a1f675662aaf..c1919fe97f0e5e4255774cd4bf556274c6d67803 100644 (file)
--- a/plugins/utils_disk.h
+++ b/plugins/utils_disk.h
/* Header file for utils_disk */
+#include "mountlist.h"
struct name_list
{
struct name_list *next;
};
+struct parameter_list
+{
+ char *name;
+ int found;
+ int found_len;
+ uintmax_t w_df;
+ uintmax_t c_df;
+ double w_dfp;
+ double c_dfp;
+ double w_idfp;
+ double c_idfp;
+ struct mount_entry *best_match;
+ struct parameter_list *name_next;
+};
+
void np_add_name (struct name_list **list, const char *name);
int np_find_name (struct name_list *list, const char *name);
-
+void np_add_parameter(struct parameter_list **list, const char *name);
+int search_parameter_list (struct parameter_list *list, const char *name);