summaryrefslogtreecommitdiffstats
path: root/plugins/check_disk.c
diff options
context:
space:
mode:
authorTon Voon <tonvoon@users.sourceforge.net>2006-07-12 12:15:42 (GMT)
committerTon Voon <tonvoon@users.sourceforge.net>2006-07-12 12:15:42 (GMT)
commitee03f1415acc9f4f8901593d9045244fbb3bbbb0 (patch)
tree32faccd0a0ac25373fec4823499969e62c2541ae /plugins/check_disk.c
parentdf23fd75267c830f85a74cfde3020981c37e82a5 (diff)
downloadmonitoring-plugins-ee03f1415acc9f4f8901593d9045244fbb3bbbb0.tar.gz
Moving check_disk functions into utils_disk.c and testing them
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1447 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'plugins/check_disk.c')
-rw-r--r--plugins/check_disk.c108
1 files changed, 31 insertions, 77 deletions
diff --git a/plugins/check_disk.c b/plugins/check_disk.c
index 8a824c1..f0a679d 100644
--- a/plugins/check_disk.c
+++ b/plugins/check_disk.c
@@ -37,10 +37,6 @@ const char *revision = "$Revision$";
37const char *copyright = "1999-2006"; 37const char *copyright = "1999-2006";
38const char *email = "nagiosplug-devel@lists.sourceforge.net"; 38const char *email = "nagiosplug-devel@lists.sourceforge.net";
39 39
40 /*
41 * Additional inode code by Jorgen Lundman <lundman@lundman.net>
42 */
43
44 40
45#include "common.h" 41#include "common.h"
46#if HAVE_INTTYPES_H 42#if HAVE_INTTYPES_H
@@ -50,12 +46,14 @@ const char *email = "nagiosplug-devel@lists.sourceforge.net";
50#include "popen.h" 46#include "popen.h"
51#include "utils.h" 47#include "utils.h"
52#include <stdarg.h> 48#include <stdarg.h>
53#include "../lib/fsusage.h" 49#include "fsusage.h"
54#include "../lib/mountlist.h" 50#include "mountlist.h"
55#if HAVE_LIMITS_H 51#if HAVE_LIMITS_H
56# include <limits.h> 52# include <limits.h>
57#endif 53#endif
58 54
55#include "utils_disk.h"
56
59/* If nonzero, show inode information. */ 57/* If nonzero, show inode information. */
60static int inode_format; 58static int inode_format;
61 59
@@ -77,8 +75,7 @@ static int show_local_fs = 0;
77/* static int require_sync = 0; */ 75/* static int require_sync = 0; */
78 76
79/* A filesystem type to display. */ 77/* A filesystem type to display. */
80 78struct parameter_list
81struct name_list
82{ 79{
83 char *name; 80 char *name;
84 int found; 81 int found;
@@ -89,7 +86,7 @@ struct name_list
89 double c_dfp; 86 double c_dfp;
90 double w_idfp; 87 double w_idfp;
91 double c_idfp; 88 double c_idfp;
92 struct name_list *name_next; 89 struct parameter_list *name_next;
93}; 90};
94 91
95/* Linked list of filesystem types to display. 92/* Linked list of filesystem types to display.
@@ -103,7 +100,7 @@ struct name_list
103 Some filesystem types: 100 Some filesystem types:
104 4.2 4.3 ufs nfs swap ignore io vm efs dbg */ 101 4.2 4.3 ufs nfs swap ignore io vm efs dbg */
105 102
106/* static struct name_list *fs_select_list; */ 103/* static struct parameter_list *fs_select_list; */
107 104
108/* Linked list of filesystem types to omit. 105/* Linked list of filesystem types to omit.
109 If the list is empty, don't exclude any types. */ 106 If the list is empty, don't exclude any types. */
@@ -112,9 +109,7 @@ static struct name_list *fs_exclude_list;
112 109
113static struct name_list *dp_exclude_list; 110static struct name_list *dp_exclude_list;
114 111
115static struct name_list *path_select_list; 112static struct parameter_list *path_select_list;
116
117static struct name_list *dev_select_list;
118 113
119/* Linked list of mounted filesystems. */ 114/* Linked list of mounted filesystems. */
120static struct mount_entry *mount_list; 115static struct mount_entry *mount_list;
@@ -132,11 +127,14 @@ enum
132 #pragma alloca 127 #pragma alloca
133#endif 128#endif
134 129
130/* Linked list of mounted filesystems. */
131static struct mount_entry *mount_list;
132
135int process_arguments (int, char **); 133int process_arguments (int, char **);
136void print_path (const char *mypath); 134void print_path (const char *mypath);
137int validate_arguments (uintmax_t, uintmax_t, double, double, double, double, char *); 135int validate_arguments (uintmax_t, uintmax_t, double, double, double, double, char *);
138int check_disk (double usp, uintmax_t free_disk, double uisp); 136int check_disk (double usp, uintmax_t free_disk, double uisp);
139int walk_name_list (struct name_list *list, const char *name); 137int walk_parameter_list (struct parameter_list *list, const char *name);
140void print_help (void); 138void print_help (void);
141void print_usage (void); 139void print_usage (void);
142 140
@@ -154,9 +152,6 @@ int verbose = 0;
154int erronly = FALSE; 152int erronly = FALSE;
155int display_mntp = FALSE; 153int display_mntp = FALSE;
156 154
157/* Linked list of mounted filesystems. */
158static struct mount_entry *mount_list;
159
160 155
161 156
162int 157int
@@ -174,7 +169,7 @@ main (int argc, char **argv)
174 169
175 struct mount_entry *me; 170 struct mount_entry *me;
176 struct fs_usage fsp; 171 struct fs_usage fsp;
177 struct name_list *temp_list; 172 struct parameter_list *temp_list;
178 173
179 output = strdup (" - free space:"); 174 output = strdup (" - free space:");
180 details = strdup (""); 175 details = strdup ("");
@@ -199,8 +194,8 @@ main (int argc, char **argv)
199 */ 194 */
200 if(path_select_list){ 195 if(path_select_list){
201 for (me = mount_list; me; me = me->me_next) { 196 for (me = mount_list; me; me = me->me_next) {
202 walk_name_list(path_select_list, me->me_mountdir); 197 walk_parameter_list(path_select_list, me->me_mountdir);
203 walk_name_list(path_select_list, me->me_devname); 198 walk_parameter_list(path_select_list, me->me_devname);
204 } 199 }
205 /* now pretend we never saw anything, but keep found_len. 200 /* now pretend we never saw anything, but keep found_len.
206 * thus future searches will only match the best match */ 201 * thus future searches will only match the best match */
@@ -214,12 +209,12 @@ main (int argc, char **argv)
214 /* if there's a list of paths to select, the current mount 209 /* if there's a list of paths to select, the current mount
215 * entry matches in path or device name, get fs usage */ 210 * entry matches in path or device name, get fs usage */
216 if (path_select_list && 211 if (path_select_list &&
217 (walk_name_list (path_select_list, me->me_mountdir) || 212 (walk_parameter_list (path_select_list, me->me_mountdir) ||
218 walk_name_list (path_select_list, me->me_devname) ) ) { 213 walk_parameter_list (path_select_list, me->me_devname) ) ) {
219 get_fs_usage (me->me_mountdir, me->me_devname, &fsp); 214 get_fs_usage (me->me_mountdir, me->me_devname, &fsp);
220 /* else if there's a list of paths/devices to select (but 215 /* else if there's a list of paths/devices to select (but
221 * we didn't match above) skip to the next mount entry */ 216 * we didn't match above) skip to the next mount entry */
222 } else if (dev_select_list || path_select_list) { 217 } else if (path_select_list) {
223 continue; 218 continue;
224 /* skip remote filesystems if we're not interested in them */ 219 /* skip remote filesystems if we're not interested in them */
225 } else if (me->me_remote && show_local_fs) { 220 } else if (me->me_remote && show_local_fs) {
@@ -228,12 +223,12 @@ main (int argc, char **argv)
228 } else if (me->me_dummy && !show_all_fs) { 223 } else if (me->me_dummy && !show_all_fs) {
229 continue; 224 continue;
230 /* skip excluded fstypes */ 225 /* skip excluded fstypes */
231 } else if (fs_exclude_list && walk_name_list (fs_exclude_list, me->me_type)) { 226 } else if (fs_exclude_list && np_find_name (fs_exclude_list, me->me_type)) {
232 continue; 227 continue;
233 /* skip excluded fs's */ 228 /* skip excluded fs's */
234 } else if (dp_exclude_list && 229 } else if (dp_exclude_list &&
235 (walk_name_list (dp_exclude_list, me->me_devname) || 230 (np_find_name (dp_exclude_list, me->me_devname) ||
236 walk_name_list (dp_exclude_list, me->me_mountdir))) { 231 np_find_name (dp_exclude_list, me->me_mountdir))) {
237 continue; 232 continue;
238 /* otherwise, get fs usage */ 233 /* otherwise, get fs usage */
239 } else { 234 } else {
@@ -312,11 +307,9 @@ int
312process_arguments (int argc, char **argv) 307process_arguments (int argc, char **argv)
313{ 308{
314 int c; 309 int c;
315 struct name_list *se; 310 struct parameter_list *se;
316 struct name_list **pathtail = &path_select_list; 311 struct parameter_list **pathtail = &path_select_list;
317 struct name_list **fstail = &fs_exclude_list; 312 struct parameter_list *temp_list;
318 struct name_list **dptail = &dp_exclude_list;
319 struct name_list *temp_list;
320 int result = OK; 313 int result = OK;
321 struct stat *stat_buf; 314 struct stat *stat_buf;
322 315
@@ -351,13 +344,7 @@ process_arguments (int argc, char **argv)
351 if (argc < 2) 344 if (argc < 2)
352 return ERROR; 345 return ERROR;
353 346
354 se = (struct name_list *) malloc (sizeof (struct name_list)); 347 np_add_name(&fs_exclude_list, "iso9660");
355 se->name = strdup ("iso9660");
356 se->name_next = NULL;
357 se->found = 0;
358 se->found_len = 0;
359 *fstail = se;
360 fstail = &se->name_next;
361 348
362 for (c = 1; c < argc; c++) 349 for (c = 1; c < argc; c++)
363 if (strcmp ("-to", argv[c]) == 0) 350 if (strcmp ("-to", argv[c]) == 0)
@@ -468,7 +455,7 @@ process_arguments (int argc, char **argv)
468 show_local_fs = 1; 455 show_local_fs = 1;
469 break; 456 break;
470 case 'p': /* select path */ 457 case 'p': /* select path */
471 se = (struct name_list *) malloc (sizeof (struct name_list)); 458 se = (struct parameter_list *) malloc (sizeof (struct parameter_list));
472 se->name = optarg; 459 se->name = optarg;
473 se->name_next = NULL; 460 se->name_next = NULL;
474 se->w_df = w_df; 461 se->w_df = w_df;
@@ -483,43 +470,10 @@ process_arguments (int argc, char **argv)
483 pathtail = &se->name_next; 470 pathtail = &se->name_next;
484 break; 471 break;
485 case 'x': /* exclude path or partition */ 472 case 'x': /* exclude path or partition */
486 se = (struct name_list *) malloc (sizeof (struct name_list)); 473 np_add_name(&dp_exclude_list, optarg);
487 se->name = optarg;
488 se->name_next = NULL;
489
490 /* If you don't clear the w_fd etc values here, they
491 * get processed when you walk the list and assigned
492 * to the global w_df!
493 */
494 se->w_df = 0;
495 se->c_df = 0;
496 se->w_dfp = 0;
497 se->c_dfp = 0;
498 se->w_idfp = 0;
499 se->c_idfp = 0;
500 se->found = 0;
501 se->found_len = 0;
502 *dptail = se;
503 dptail = &se->name_next;
504 break; 474 break;
505 case 'X': /* exclude file system type */ 475 case 'X': /* exclude file system type */
506 se = (struct name_list *) malloc (sizeof (struct name_list)); 476 np_add_name(&fs_exclude_list, optarg);
507 se->name = optarg;
508 se->name_next = NULL;
509 /* If you don't clear the w_fd etc values here, they
510 * get processed when you walk the list and assigned
511 * to the global w_df!
512 */
513 se->w_df = 0;
514 se->c_df = 0;
515 se->w_dfp = 0;
516 se->c_dfp = 0;
517 se->w_idfp = 0;
518 se->c_idfp = 0;
519 se->found = 0;
520 se->found_len = 0;
521 *fstail = se;
522 fstail = &se->name_next;
523 break; 477 break;
524 case 'v': /* verbose */ 478 case 'v': /* verbose */
525 verbose++; 479 verbose++;
@@ -561,7 +515,7 @@ process_arguments (int argc, char **argv)
561 c_dfp = (100.0 - atof (argv[c++])); 515 c_dfp = (100.0 - atof (argv[c++]));
562 516
563 if (argc > c && path == NULL) { 517 if (argc > c && path == NULL) {
564 se = (struct name_list *) malloc (sizeof (struct name_list)); 518 se = (struct parameter_list *) malloc (sizeof (struct parameter_list));
565 se->name = strdup (argv[c++]); 519 se->name = strdup (argv[c++]);
566 se->name_next = NULL; 520 se->name_next = NULL;
567 se->w_df = w_df; 521 se->w_df = w_df;
@@ -683,7 +637,7 @@ check_disk (double usp, uintmax_t free_disk, double uisp)
683 637
684 638
685int 639int
686walk_name_list (struct name_list *list, const char *name) 640walk_parameter_list (struct parameter_list *list, const char *name)
687{ 641{
688 int name_len; 642 int name_len;
689 name_len = strlen(name); 643 name_len = strlen(name);
@@ -695,7 +649,7 @@ walk_name_list (struct name_list *list, const char *name)
695 ! strncmp(list->name, name, name_len)) { 649 ! strncmp(list->name, name, name_len)) {
696 list->found = 1; 650 list->found = 1;
697 list->found_len = name_len; 651 list->found_len = name_len;
698 /* if required for name_lists that have not saved w_df, etc (eg exclude lists) */ 652 /* if required for parameter_lists that have not saved w_df, etc (eg exclude lists) */
699 if (list->w_df) w_df = list->w_df; 653 if (list->w_df) w_df = list->w_df;
700 if (list->c_df) c_df = list->c_df; 654 if (list->c_df) c_df = list->c_df;
701 if (list->w_dfp>=0.0) w_dfp = list->w_dfp; 655 if (list->w_dfp>=0.0) w_dfp = list->w_dfp;