[Nagiosplug-checkins] CVS: nagiosplug/plugins check_disk.c,1.24,1.25
Ton Voon
tonvoon at users.sourceforge.net
Wed Jun 25 08:45:13 CEST 2003
Update of /cvsroot/nagiosplug/nagiosplug/plugins
In directory sc8-pr-cvs1:/tmp/cvs-serv22444
Modified Files:
check_disk.c
Log Message:
Support for different thresholds for different filesystems
Index: check_disk.c
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/check_disk.c,v
retrieving revision 1.24
retrieving revision 1.25
diff -C2 -r1.24 -r1.25
*** check_disk.c 25 Jun 2003 13:38:22 -0000 1.24
--- check_disk.c 25 Jun 2003 15:43:31 -0000 1.25
***************
*** 58,61 ****
--- 58,63 ----
-e, --errors-only\n\
Display only devices/mountpoints with errors\n\
+ -C, --clear\n\
+ Clear thresholds\n\
-v, --verbose\n\
Show details for command-line debugging (do not use with nagios server)\n\
***************
*** 68,71 ****
--- 70,78 ----
\n";
+ const char *examples = "\
+ check_disk -w 10% -c 5% -p /tmp -p /var -C -w 100000 -c 50000 -p /\n\
+ Checks /tmp and /var at 10%,5% and / at 100MB, 50MB\n\
+ \n";
+
#include "common.h"
#if HAVE_INTTYPES_H
***************
*** 108,111 ****
--- 115,122 ----
char *name;
int found;
+ int w_df;
+ int c_df;
+ float w_dfp;
+ float c_dfp;
struct name_list *name_next;
};
***************
*** 152,156 ****
int process_arguments (int, char **);
! int validate_arguments (void);
int check_disk (int usp, int free_disk);
int walk_name_list (struct name_list *list, const char *name);
--- 163,167 ----
int process_arguments (int, char **);
! int validate_arguments (int, int, float, float, char *);
int check_disk (int usp, int free_disk);
int walk_name_list (struct name_list *list, const char *name);
***************
*** 238,242 ****
free_space_pct,
(!strcmp(file_system, "none") || display_mntp) ? me->me_devname : me->me_mountdir);
! asprintf (&details, "%s\n%.0f of %.0f %s (%2.0f%%) free on %s (type %s mounted on %s)",
details,
free_space,
--- 249,253 ----
free_space_pct,
(!strcmp(file_system, "none") || display_mntp) ? me->me_devname : me->me_mountdir);
! asprintf (&details, "%s\n%.0f of %.0f %s (%2.0f%%) free on %s (type %s mounted on %s) warn:%d crit:%d warn%%:%.0f%% crit%%:%.0f%%",
details,
free_space,
***************
*** 246,250 ****
me->me_devname,
me->me_type,
! me->me_mountdir);
}
--- 257,262 ----
me->me_devname,
me->me_type,
! me->me_mountdir,
! w_df, c_df, w_dfp, c_dfp);
}
***************
*** 280,283 ****
--- 292,297 ----
struct name_list **fstail = &fs_exclude_list;
struct name_list **dptail = &dp_exclude_list;
+ struct name_list *temp_list;
+ int result = OK;
int option_index = 0;
***************
*** 298,301 ****
--- 312,316 ----
{"verbose", no_argument, 0, 'v'},
{"quiet", no_argument, 0, 'q'},
+ {"clear", no_argument, 0, 'C'},
{"version", no_argument, 0, 'V'},
{"help", no_argument, 0, 'h'},
***************
*** 317,321 ****
while (1) {
! c = getopt_long (argc, argv, "+?Vqhvet:c:w:u:p:x:X:mklM", long_options, &option_index);
if (c == -1 || c == EOF)
--- 332,336 ----
while (1) {
! c = getopt_long (argc, argv, "+?VqhveCt:c:w:u:p:x:X:mklM", long_options, &option_index);
if (c == -1 || c == EOF)
***************
*** 398,401 ****
--- 413,420 ----
se->name = strdup (optarg);
se->name_next = NULL;
+ se->w_df = w_df;
+ se->c_df = c_df;
+ se->w_dfp = w_dfp;
+ se->c_dfp = c_dfp;
*pathtail = se;
pathtail = &se->name_next;
***************
*** 428,431 ****
--- 447,456 ----
display_mntp = TRUE;
break;
+ case 'C':
+ w_df = -1;
+ c_df = -1;
+ w_dfp = -1.0;
+ c_dfp = -1.0;
+ break;
case 'V': /* version */
print_revision (progname, revision);
***************
*** 450,477 ****
path = argv[c++];
! return validate_arguments ();
}
int
! validate_arguments ()
{
! if (w_df < 0 && c_df < 0 && w_dfp < 0 && c_dfp < 0) {
! printf ("INPUT ERROR: Unable to parse command line\n");
return ERROR;
}
! else if ((w_dfp >= 0 || c_dfp >= 0)
! && (w_dfp < 0 || c_dfp < 0 || w_dfp > 100 || c_dfp > 100
! || c_dfp > w_dfp)) {
printf
! ("INPUT ERROR: C_DFP (%f) should be less than W_DFP (%f) and both should be between zero and 100 percent, inclusive\n",
! c_dfp, w_dfp);
return ERROR;
}
! else if ((w_df > 0 || c_df > 0) && (w_df < 0 || c_df < 0 || c_df > w_df)) {
printf
! ("INPUT ERROR: C_DF (%d) should be less than W_DF (%d) and both should be greater than zero\n",
! c_df, w_df);
return ERROR;
}
--- 475,521 ----
path = argv[c++];
! if (path_select_list) {
! temp_list = path_select_list;
! while (temp_list) {
! if (validate_arguments (temp_list->w_df, temp_list->c_df, temp_list->w_dfp, temp_list->c_dfp, temp_list->name) == ERROR)
! result = ERROR;
! temp_list = temp_list->name_next;
! }
! return result;
! } else {
! return validate_arguments (w_df, c_df, w_dfp, c_dfp, NULL);
! }
}
+ void print_path (char *path)
+ {
+ if (path)
+ printf (" for %s", path);
+ printf ("\n");
+ }
int
! validate_arguments (int w, int c, float wp, float cp, char *path)
{
! if (w < 0 && c < 0 && wp < 0 && cp < 0) {
! printf ("INPUT ERROR: No thresholds specified");
! print_path (path);
return ERROR;
}
! else if ((wp >= 0 || cp >= 0)
! && (wp < 0 || cp < 0 || wp > 100 || cp > 100
! || cp > wp)) {
printf
! ("INPUT ERROR: C_DFP (%f) should be less than W_DFP (%.1f) and both should be between zero and 100 percent, inclusive",
! cp, wp);
! print_path (path);
return ERROR;
}
! else if ((w > 0 || c > 0) && (w < 0 || c < 0 || c > w)) {
printf
! ("INPUT ERROR: C_DF (%d) should be less than W_DF (%d) and both should be greater than zero",
! c, w);
! print_path (path);
return ERROR;
}
***************
*** 510,513 ****
--- 554,561 ----
if (! strcmp(list->name, name)) {
list->found = 1;
+ w_df = list->w_df;
+ c_df = list->c_df;
+ w_dfp = list->w_dfp;
+ c_dfp = list->c_dfp;
return TRUE;
}
***************
*** 530,533 ****
--- 578,582 ----
printf (options);
printf (notes);
+ printf ("Examples:\n%s", examples);
support ();
}
More information about the Commits
mailing list