diff options
author | Matthias Eble <psychotrahe@users.sourceforge.net> | 2007-07-10 20:18:55 +0000 |
---|---|---|
committer | Matthias Eble <psychotrahe@users.sourceforge.net> | 2007-07-10 20:18:55 +0000 |
commit | 5e633124e4573c98d5457144e401fb0d22e45ae6 (patch) | |
tree | 4cd3e9085503cdc10719de3d09f0fa12b810e996 /plugins | |
parent | 5d11612ecb23c6496d8faaedbcc1b9371628be53 (diff) | |
download | monitoring-plugins-5e633124e4573c98d5457144e401fb0d22e45ae6.tar.gz |
Check_disk now calls stat() for all filesystems to check.
Check_disk prints an strerror() message if the call of stat() fails.
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1754 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/check_disk.c | 39 | ||||
-rw-r--r-- | plugins/t/check_disk.t | 2 |
2 files changed, 12 insertions, 29 deletions
diff --git a/plugins/check_disk.c b/plugins/check_disk.c index c32c7ab3..cceb5be8 100644 --- a/plugins/check_disk.c +++ b/plugins/check_disk.c | |||
@@ -176,6 +176,7 @@ main (int argc, char **argv) | |||
176 | struct fs_usage fsp, tmpfsp; | 176 | struct fs_usage fsp, tmpfsp; |
177 | struct parameter_list *temp_list, *path; | 177 | struct parameter_list *temp_list, *path; |
178 | struct name_list *seen = NULL; | 178 | struct name_list *seen = NULL; |
179 | struct stat *stat_buf; | ||
179 | 180 | ||
180 | preamble = strdup (" - free space:"); | 181 | preamble = strdup (" - free space:"); |
181 | output = strdup (""); | 182 | output = strdup (""); |
@@ -208,14 +209,22 @@ main (int argc, char **argv) | |||
208 | 209 | ||
209 | /* Error if no match found for specified paths */ | 210 | /* Error if no match found for specified paths */ |
210 | temp_list = path_select_list; | 211 | temp_list = path_select_list; |
212 | |||
213 | stat_buf = malloc(sizeof *stat_buf); | ||
211 | while (temp_list) { | 214 | while (temp_list) { |
212 | if (! temp_list->best_match) { | 215 | if (! temp_list->best_match) { |
213 | die (STATE_CRITICAL, _("DISK %s: %s not found\n"), _("CRITICAL"), temp_list->name); | 216 | die (STATE_CRITICAL, _("DISK %s: %s not found\n"), _("CRITICAL"), temp_list->name); |
214 | } | 217 | } |
218 | |||
219 | /* Stat each entry to check that dir exists */ | ||
220 | if (stat (temp_list->name, &stat_buf[0])) { | ||
221 | printf("DISK %s - ", _("CRITICAL")); | ||
222 | die (STATE_CRITICAL, _("%s %s: %s\n"), temp_list->name, _("is not accessible"), strerror(errno)); | ||
223 | } | ||
215 | temp_list = temp_list->name_next; | 224 | temp_list = temp_list->name_next; |
216 | } | 225 | } |
226 | free(stat_buf); | ||
217 | 227 | ||
218 | |||
219 | /* Process for every path in list */ | 228 | /* Process for every path in list */ |
220 | for (path = path_select_list; path; path=path->name_next) { | 229 | for (path = path_select_list; path; path=path->name_next) { |
221 | 230 | ||
@@ -444,7 +453,6 @@ process_arguments (int argc, char **argv) | |||
444 | struct parameter_list *temp_path_select_list = NULL; | 453 | struct parameter_list *temp_path_select_list = NULL; |
445 | struct mount_entry *me; | 454 | struct mount_entry *me; |
446 | int result = OK; | 455 | int result = OK; |
447 | struct stat *stat_buf; | ||
448 | regex_t re; | 456 | regex_t re; |
449 | int cflags = REG_NOSUB | REG_EXTENDED; | 457 | int cflags = REG_NOSUB | REG_EXTENDED; |
450 | char errbuf[MAX_INPUT_BUFFER]; | 458 | char errbuf[MAX_INPUT_BUFFER]; |
@@ -743,32 +751,7 @@ process_arguments (int argc, char **argv) | |||
743 | mult = (uintmax_t)1024 * 1024; | 751 | mult = (uintmax_t)1024 * 1024; |
744 | } | 752 | } |
745 | 753 | ||
746 | if (path_select_list) { | 754 | return TRUE; |
747 | temp_list = path_select_list; | ||
748 | stat_buf = malloc(sizeof *stat_buf); | ||
749 | while (temp_list) { | ||
750 | /* Stat each entry to check that dir exists */ | ||
751 | if (stat (temp_list->name, &stat_buf[0])) { | ||
752 | printf("DISK %s - ", _("CRITICAL")); | ||
753 | die (STATE_CRITICAL, _("%s does not exist\n"), temp_list->name); | ||
754 | } | ||
755 | /* if (validate_arguments (temp_list->w_df, | ||
756 | temp_list->c_df, | ||
757 | temp_list->w_dfp, | ||
758 | temp_list->c_dfp, | ||
759 | temp_list->w_idfp, | ||
760 | temp_list->c_idfp, | ||
761 | temp_list->name) == ERROR) | ||
762 | result = ERROR; | ||
763 | */ | ||
764 | temp_list = temp_list->name_next; | ||
765 | } | ||
766 | free(stat_buf); | ||
767 | return result; | ||
768 | } else { | ||
769 | return TRUE; | ||
770 | /* return validate_arguments (w_df, c_df, w_dfp, c_dfp, w_idfp, c_idfp, NULL); */ | ||
771 | } | ||
772 | } | 755 | } |
773 | 756 | ||
774 | 757 | ||
diff --git a/plugins/t/check_disk.t b/plugins/t/check_disk.t index 5c6aa39a..4f5c4bc4 100644 --- a/plugins/t/check_disk.t +++ b/plugins/t/check_disk.t | |||
@@ -275,7 +275,7 @@ TODO: { | |||
275 | 275 | ||
276 | $result = NPTest->testCmd( "./check_disk -w 0% -c 0% -p /bob" ); | 276 | $result = NPTest->testCmd( "./check_disk -w 0% -c 0% -p /bob" ); |
277 | cmp_ok( $result->return_code, '==', 2, "Checking /bob - return error because /bob does not exist" ); | 277 | cmp_ok( $result->return_code, '==', 2, "Checking /bob - return error because /bob does not exist" ); |
278 | cmp_ok( $result->output, 'eq', 'DISK CRITICAL - /bob does not exist', 'Output OK'); | 278 | like( $result->output, '/^DISK CRITICAL - /bob is not accessible:.*$/', 'Output OK'); |
279 | 279 | ||
280 | $result = NPTest->testCmd( "./check_disk -w 0% -c 0% -p /" ); | 280 | $result = NPTest->testCmd( "./check_disk -w 0% -c 0% -p /" ); |
281 | my $root_output = $result->output; | 281 | my $root_output = $result->output; |