summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 4edea20)
raw | patch | inline | side by side (parent: 4edea20)
author | Ton Voon <tonvoon@users.sourceforge.net> | |
Wed, 12 Jul 2006 22:53:27 +0000 (22:53 +0000) | ||
committer | Ton Voon <tonvoon@users.sourceforge.net> | |
Wed, 12 Jul 2006 22:53:27 +0000 (22:53 +0000) |
loop. Added extra tests for possible duplicate filesystems.
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1449 f882894a-f735-0410-b71e-b25c423dba1c
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1449 f882894a-f735-0410-b71e-b25c423dba1c
plugins/check_disk.c | patch | blob | history | |
plugins/t/check_disk.t | patch | blob | history | |
plugins/utils_disk.c | patch | blob | history | |
plugins/utils_disk.h | patch | blob | history |
diff --git a/plugins/check_disk.c b/plugins/check_disk.c
index 8e9c1fceabc39a773c446604872ff76b46a1bbcc..142344835a01ff677474d541d3b9d4431c8b6ef9 100644 (file)
--- a/plugins/check_disk.c
+++ b/plugins/check_disk.c
void print_path (const char *mypath);
int validate_arguments (uintmax_t, uintmax_t, double, double, double, double, char *);
int check_disk (double usp, uintmax_t free_disk, double uisp);
-int walk_parameter_list (struct parameter_list *list, const char *name);
void print_help (void);
void print_usage (void);
int verbose = 0;
int erronly = FALSE;
int display_mntp = FALSE;
-
+int exact_match = FALSE;
int
struct mount_entry *me;
struct fs_usage fsp;
- struct parameter_list *temp_list;
+ struct parameter_list *temp_list, *path;
+ struct name_list *seen = NULL;
output = strdup (" - free space:");
details = strdup ("");
if (process_arguments (argc, argv) == ERROR)
usage4 (_("Could not parse arguments"));
- /* if a list of paths has been selected, preseed the list with
- * the longest matching filesystem name by iterating across
- * the mountlist once ahead of time. this will allow a query on
- * "/var/log" to return information about "/var" if no "/var/log"
- * filesystem exists, etc. this is the default behavior already
- * with df-based checks, but for systems with their own space
- * checking routines, this should make them more consistent.
+ /* If a list of paths has not been selected, find entire
+ mount list and create list of paths
*/
- if(path_select_list){
+ if (! path_select_list) {
for (me = mount_list; me; me = me->me_next) {
- walk_parameter_list(path_select_list, me->me_mountdir);
- walk_parameter_list(path_select_list, me->me_devname);
+ path = np_add_parameter(&path_select_list, me->me_mountdir);
+ path->w_df = w_df;
+ path->c_df = c_df;
+ path->w_dfp = w_dfp;
+ path->c_dfp = c_dfp;
+ path->w_idfp = w_idfp;
+ path->c_idfp = c_idfp;
+ path->best_match = me;
}
- /* now pretend we never saw anything, but keep found_len.
- * thus future searches will only match the best match */
- for (temp_list = path_select_list; temp_list; temp_list=temp_list->name_next){
- temp_list->found=0;
+ } else {
+ np_set_best_match(path_select_list, mount_list, exact_match);
+
+ /* Error if no match found for specified paths */
+ temp_list = path_select_list;
+ while (temp_list) {
+ if (! temp_list->best_match) {
+ die (STATE_CRITICAL, _("DISK %s: %s not found\n"), _("CRITICAL"), temp_list->name);
+ }
+ temp_list = temp_list->name_next;
}
}
- /* for every mount entry */
- for (me = mount_list; me; me = me->me_next) {
- /* if there's a list of paths to select, the current mount
- * entry matches in path or device name, get fs usage */
- if (path_select_list &&
- (walk_parameter_list (path_select_list, me->me_mountdir) ||
- walk_parameter_list (path_select_list, me->me_devname) ) ) {
- get_fs_usage (me->me_mountdir, me->me_devname, &fsp);
- /* else if there's a list of paths/devices to select (but
- * we didn't match above) skip to the next mount entry */
- } else if (path_select_list) {
+ /* Process for every path in list */
+ for (path = path_select_list; path; path=path->name_next) {
+ me = path->best_match;
+ w_df = path->w_df;
+ c_df = path->c_df;
+ w_dfp = path->w_dfp;
+ c_dfp = path->c_dfp;
+ w_idfp = path->w_idfp;
+ c_idfp = path->c_idfp;
+
+ /* Filters */
+
+ /* Remove filesystems already seen */
+ if (np_seen_name(seen, me->me_mountdir)) {
continue;
- /* skip remote filesystems if we're not interested in them */
- } else if (me->me_remote && show_local_fs) {
+ } else {
+ np_add_name(&seen, me->me_mountdir);
+ }
+ /* Skip remote filesystems if we're not interested in them */
+ if (me->me_remote && show_local_fs) {
continue;
- /* skip pseudo fs's if we haven't asked for all fs's */
+ /* Skip pseudo fs's if we haven't asked for all fs's */
} else if (me->me_dummy && !show_all_fs) {
continue;
- /* skip excluded fstypes */
+ /* Skip excluded fstypes */
} else if (fs_exclude_list && np_find_name (fs_exclude_list, me->me_type)) {
continue;
- /* skip excluded fs's */
+ /* Skip excluded fs's */
} else if (dp_exclude_list &&
(np_find_name (dp_exclude_list, me->me_devname) ||
np_find_name (dp_exclude_list, me->me_mountdir))) {
continue;
- /* otherwise, get fs usage */
- } else {
- get_fs_usage (me->me_mountdir, me->me_devname, &fsp);
}
+ get_fs_usage (me->me_mountdir, me->me_devname, &fsp);
+
if (fsp.fsu_blocks && strcmp ("none", me->me_mountdir)) {
usp = (double)(fsp.fsu_blocks - fsp.fsu_bavail) * 100 / fsp.fsu_blocks;
uisp = (double)(fsp.fsu_files - fsp.fsu_ffree) * 100 / fsp.fsu_files;
if (verbose > 2)
asprintf (&output, "%s%s", output, details);
- /* Override result if paths specified and not found */
- temp_list = path_select_list;
- while (temp_list) {
- if (!temp_list->found) {
- asprintf (&output, _("%s [%s not found]"), output, temp_list->name);
- result = STATE_CRITICAL;
- }
- temp_list = temp_list->name_next;
- }
printf ("DISK %s%s|%s\n", state_text (result), output, perf);
return result;
{"exclude-type", required_argument, 0, 'X'},
{"mountpoint", no_argument, 0, 'M'},
{"errors-only", no_argument, 0, 'e'},
+ {"exact-match", no_argument, 0, 'E'},
{"verbose", no_argument, 0, 'v'},
{"quiet", no_argument, 0, 'q'},
{"clear", no_argument, 0, 'C'},
strcpy (argv[c], "-t");
while (1) {
- c = getopt_long (argc, argv, "+?VqhveCt:c:w:K:W:u:p:x:X:mklM", longopts, &option);
+ c = getopt_long (argc, argv, "+?VqhveCt:c:w:K:W:u:p:x:X:mklME", longopts, &option);
if (c == -1 || c == EOF)
break;
case 'e':
erronly = TRUE;
break;
+ case 'E':
+ exact_match = TRUE;
+ break;
case 'M': /* display mountpoint */
display_mntp = TRUE;
break;
-int
-walk_parameter_list (struct parameter_list *list, const char *name)
-{
- int name_len;
- name_len = strlen(name);
- while (list) {
- /* if the paths match up to the length of the mount path,
- * AND if the mount path name is longer than the longest
- * found match, we have a new winner */
- if (name_len >= list->found_len &&
- ! strncmp(list->name, name, name_len)) {
- list->found = 1;
- list->found_len = name_len;
- /* if required for parameter_lists that have not saved w_df, etc (eg exclude lists) */
- if (list->w_df) w_df = list->w_df;
- if (list->c_df) c_df = list->c_df;
- if (list->w_dfp>=0.0) w_dfp = list->w_dfp;
- if (list->c_dfp>=0.0) c_dfp = list->c_dfp;
- return TRUE;
- }
- list = list->name_next;
- }
- return FALSE;
-}
printf (" %s\n", _("Ignore all filesystems of indicated type (may be repeated)"));
printf (" %s\n", "-m, --mountpoint");
printf (" %s\n", _("Display the mountpoint instead of the partition"));
+ printf (" %s\n", "-E, --exact-match");
+ printf (" %s\n", _("For paths or partitions specified with -p, only check for exact paths"));
printf (" %s\n", "-e, --errors-only");
printf (" %s\n", _("Display only devices/mountpoints with errors"));
printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT);
{
printf (_("Usage:"));
printf (" %s -w limit -c limit [-p path | -x device] [-t timeout]", progname);
- printf ("[-m] [-e] [-W limit] [-K limit] [-v] [-q]\n");
+ printf ("[-m] [-e] [-W limit] [-K limit] [-v] [-q] [-E]\n");
}
diff --git a/plugins/t/check_disk.t b/plugins/t/check_disk.t
index 14bc8dedd75d766fa3346c31fa70ed7967af6981..70d8415cfdfc3e400a2e303fb053e2b1d6f38ebe 100644 (file)
--- a/plugins/t/check_disk.t
+++ b/plugins/t/check_disk.t
if ($mountpoint_valid eq "" or $mountpoint2_valid eq "") {
plan skip_all => "Need 2 mountpoints to test";
} else {
- plan tests => 32;
+ plan tests => 35;
}
$result = NPTest->testCmd(
);
cmp_ok( $result->return_code, '==', 2, "Combining above two tests, get critical");
+$result = NPTest->testCmd(
+ "./check_disk -w $avg_free% -c $avg_free% -p $less_free -w $avg_free% -c 0% -p $more_free"
+ );
+cmp_ok( $result->return_code, '==', 2, "And reversing arguments should not make a difference");
+
+
$result = NPTest->testCmd(
cmp_ok( $result->return_code, '==', 0, "Checking /etc - should return info for /" );
cmp_ok( $result->output, 'eq', $root_output, "check_disk /etc gives same as check_disk /");
+$result = NPTest->testCmd( "./check_disk -w 0% -c 0% -p /etc -E" );
+cmp_ok( $result->return_code, '==', 2, "... unless -E/--exact-match is specified");
+
$result = NPTest->testCmd( "./check_disk -w 0% -c 0% -p / -p /bob" );
cmp_ok( $result->return_code, '==', 2, "Checking / and /bob gives critical");
unlike( $result->perf_output, '/\/bob/', "perf data does not have /bob in it");
+
+$result = NPTest->testCmd( "./check_disk -w 0% -c 0% -p / -p /" );
+unlike( $result->output, '/ \/ .* \/ /', "Should not show same filesystem twice");
diff --git a/plugins/utils_disk.c b/plugins/utils_disk.c
index 0a71d7920f69dd07492dc3a719fe2dca108fd716..31284d5d9284ddda9fd78b2a053c42a8daab6b3a 100644 (file)
--- a/plugins/utils_disk.c
+++ b/plugins/utils_disk.c
*list = new_entry;
}
-void
+/* Initialises a new parameter at the end of list */
+struct parameter_list *
np_add_parameter(struct parameter_list **list, const char *name)
{
+ struct parameter_list *current = *list;
struct parameter_list *new_path;
new_path = (struct parameter_list *) malloc (sizeof *new_path);
new_path->name = (char *) name;
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;
+ new_path->best_match = NULL;
+
+ if (current == NULL) {
+ *list = new_path;
+ } else {
+ while (current->name_next) {
+ current = current->name_next;
+ }
+ current->name_next = new_path;
+ }
+ return new_path;
}
void
if (best_match) {
d->best_match = best_match;
d->found = TRUE;
+ } else {
+ d->best_match = NULL; /* Not sure why this is needed as it should be null on initialisation */
}
}
}
return FALSE;
}
+int
+np_seen_name(struct name_list *list, const char *name)
+{
+ const struct name_list *s;
+ for (s = list; s; s=s->next) {
+ if (!strcmp(s->name, name)) {
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
diff --git a/plugins/utils_disk.h b/plugins/utils_disk.h
index c1919fe97f0e5e4255774cd4bf556274c6d67803..676ca09abde4459b74f7fea9b4a6101686c2d6b0 100644 (file)
--- a/plugins/utils_disk.h
+++ b/plugins/utils_disk.h
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 np_seen_name (struct name_list *list, const char *name);
+struct parameter_list *np_add_parameter(struct parameter_list **list, const char *name);
int search_parameter_list (struct parameter_list *list, const char *name);