[Nagiosplug-checkins] CVS: nagiosplug/plugins check_load.c,1.1.1.1,1.2
Karl DeBisschop
kdebisschop at users.sourceforge.net
Thu Oct 17 22:56:04 CEST 2002
Update of /cvsroot/nagiosplug/nagiosplug/plugins
In directory usw-pr-cvs1:/tmp/cvs-serv27624
Modified Files:
check_load.c
Log Message:
remove old call_getopt code, fix bug taking single float, allow colon as separators in additin to commas
Index: check_load.c
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/check_load.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -r1.1.1.1 -r1.2
*** check_load.c 28 Feb 2002 06:42:58 -0000 1.1.1.1
--- check_load.c 18 Oct 2002 05:55:56 -0000 1.2
***************
*** 48,52 ****
int process_arguments (int argc, char **argv);
- int call_getopt (int argc, char **argv);
int validate_arguments (void);
void print_usage (void);
--- 48,51 ----
***************
*** 153,190 ****
process_arguments (int argc, char **argv)
{
- int c;
-
- if (argc < 2)
- return ERROR;
-
- c = 0;
- while (c += (call_getopt (argc - c, &argv[c]))) {
- if (argc <= c)
- break;
-
- if (wload1 < 0 && is_nonnegative (argv[c]))
- wload1 = atof (argv[c]);
- else if (cload1 < 0 && is_nonnegative (argv[c]))
- cload1 = atof (argv[c]);
- else if (wload5 < 0 && is_nonnegative (argv[c]))
- wload5 = atof (argv[c]);
- else if (cload5 < 0 && is_nonnegative (argv[c]))
- cload5 = atof (argv[c]);
- else if (wload15 < 0 && is_nonnegative (argv[c]))
- wload15 = atof (argv[c]);
- else if (cload15 < 0 && is_nonnegative (argv[c]))
- cload15 = atof (argv[c]);
- }
-
- return validate_arguments ();
- }
-
-
-
-
-
- int
- call_getopt (int argc, char **argv)
- {
int c, i = 0;
--- 152,155 ----
***************
*** 200,256 ****
#endif
while (1) {
#ifdef HAVE_GETOPT_H
! c = getopt_long (argc, argv, "+?Vhc:w:", long_options, &option_index);
#else
! c = getopt (argc, argv, "+?Vhc:w:");
#endif
-
- i++;
-
if (c == -1 || c == EOF)
break;
switch (c) {
- case 'c':
- case 'w':
- i++;
- }
-
- switch (c) {
case 'w': /* warning time threshold */
if (is_intnonneg (optarg)) {
! if (wload1 < 0 && is_nonnegative (argv[c]))
! wload1 = atof (argv[c]);
! else if (wload5 < 0 && is_nonnegative (argv[c]))
! wload5 = atof (argv[c]);
! else if (wload15 < 0 && is_nonnegative (argv[c]))
! wload15 = atof (argv[c]);
break;
}
else if (strstr (optarg, ",") &&
! sscanf (optarg, "%f,%f,%f", &wload1, &wload5, &wload15) == 3) {
break;
! }
! else {
usage ("Warning threshold must be float or float triplet!\n");
! }
case 'c': /* critical time threshold */
if (is_intnonneg (optarg)) {
! if (cload1 < 0 && is_nonnegative (argv[c]))
! cload1 = atof (argv[c]);
! else if (cload5 < 0 && is_nonnegative (argv[c]))
! cload5 = atof (argv[c]);
! else if (cload15 < 0 && is_nonnegative (argv[c]))
! cload15 = atof (argv[c]);
break;
}
else if (strstr (optarg, ",") &&
! sscanf (optarg, "%f,%f,%f", &cload1, &cload5, &cload15) == 3) {
break;
! }
! else {
usage ("Critical threshold must be float or float triplet!\n");
! }
case 'V': /* version */
print_revision (my_basename (argv[0]), "$Revision$");
--- 165,215 ----
#endif
+ #define OPTCHARS "Vhc:w:"
+
+ if (argc < 2)
+ return ERROR;
+
while (1) {
#ifdef HAVE_GETOPT_H
! c = getopt_long (argc, argv, OPTCHARS, long_options, &option_index);
#else
! c = getopt (argc, argv, OPTCHARS);
#endif
if (c == -1 || c == EOF)
break;
switch (c) {
case 'w': /* warning time threshold */
if (is_intnonneg (optarg)) {
! wload1 = atof (optarg);
! wload5 = atof (optarg);
! wload15 = atof (optarg);
break;
}
else if (strstr (optarg, ",") &&
! sscanf (optarg, "%f,%f,%f", &wload1, &wload5, &wload15) == 3)
break;
! else if (strstr (optarg, ":") &&
! sscanf (optarg, "%f:%f:%f", &wload1, &wload5, &wload15) == 3)
! break;
! else
usage ("Warning threshold must be float or float triplet!\n");
! break;
case 'c': /* critical time threshold */
if (is_intnonneg (optarg)) {
! cload1 = atof (optarg);
! cload5 = atof (optarg);
! cload15 = atof (optarg);
break;
}
else if (strstr (optarg, ",") &&
! sscanf (optarg, "%f,%f,%f", &cload1, &cload5, &cload15) == 3)
break;
! else if (strstr (optarg, ":") &&
! sscanf (optarg, "%f:%f:%f", &cload1, &cload5, &cload15) == 3)
! break;
! else
usage ("Critical threshold must be float or float triplet!\n");
! break;
case 'V': /* version */
print_revision (my_basename (argv[0]), "$Revision$");
***************
*** 263,267 ****
}
}
! return i;
}
--- 222,258 ----
}
}
!
! c = optind;
! if (c == argc)
! return validate_arguments ();
! if (wload1 < 0 && is_nonnegative (argv[c]))
! wload1 = atof (argv[c]);
!
! if (c == argc)
! return validate_arguments ();
! if (cload1 < 0 && is_nonnegative (argv[c]))
! cload1 = atof (argv[c]);
!
! if (c == argc)
! return validate_arguments ();
! if (wload5 < 0 && is_nonnegative (argv[c]))
! wload5 = atof (argv[c]);
!
! if (c == argc)
! return validate_arguments ();
! if (cload5 < 0 && is_nonnegative (argv[c]))
! cload5 = atof (argv[c]);
!
! if (c == argc)
! return validate_arguments ();
! if (wload15 < 0 && is_nonnegative (argv[c]))
! wload15 = atof (argv[c]);
!
! if (c == argc)
! return validate_arguments ();
! if (cload15 < 0 && is_nonnegative (argv[c]))
! cload15 = atof (argv[c]);
!
! return validate_arguments ();
}
More information about the Commits
mailing list