summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 6fa04c4)
raw | patch | inline | side by side (parent: 6fa04c4)
author | Karl DeBisschop <kdebisschop@users.sourceforge.net> | |
Sat, 9 Nov 2002 11:37:14 +0000 (11:37 +0000) | ||
committer | Karl DeBisschop <kdebisschop@users.sourceforge.net> | |
Sat, 9 Nov 2002 11:37:14 +0000 (11:37 +0000) |
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@182 f882894a-f735-0410-b71e-b25c423dba1c
plugins/check_ups.c | patch | blob | history | |
plugins/check_users.c | patch | blob | history |
diff --git a/plugins/check_ups.c b/plugins/check_ups.c
index 1e1aa39ce6a71637ee2182466c3643377d3dc633..c711de20f4ff8bd2709b8ccd5c3ef1db7a235a03 100644 (file)
--- a/plugins/check_ups.c
+++ b/plugins/check_ups.c
#include "utils.h"
#define PROGNAME "check_ups"
+#define REVISION "$Revision$"
+#define COPYRIGHT "1999-2002"
+#define AUTHOR "Ethan Galstad"
+#define EMAIL "nagios@nagios.org"
#define CHECK_NONE 0
{
int c;
- if (argc < 2)
- return ERROR;
-
- for (c = 1; c < argc; c++) {
- if (strcmp ("-to", argv[c]) == 0)
- strcpy (argv[c], "-t");
- else if (strcmp ("-wt", argv[c]) == 0)
- strcpy (argv[c], "-w");
- else if (strcmp ("-ct", argv[c]) == 0)
- strcpy (argv[c], "-c");
- }
-
- c = 0;
- while ((c += (call_getopt (argc - c, &argv[c]))) < argc) {
-
- if (is_option (argv[c]))
- continue;
-
- if (server_address == NULL) {
- if (is_host (argv[c])) {
- server_address = argv[c];
- }
- else {
- usage ("Invalid host name");
- }
- }
- }
-
- if (server_address == NULL)
- server_address = strscpy (NULL, "127.0.0.1");
-
- return validate_arguments ();
-}
-
-
-
-
-
-
-int
-call_getopt (int argc, char **argv)
-{
- int c, i = 0;
-
#ifdef HAVE_GETOPT_H
int option_index = 0;
static struct option long_options[] = {
};
#endif
+ if (argc < 2)
+ return ERROR;
+
+ for (c = 1; c < argc; c++) {
+ if (strcmp ("-to", argv[c]) == 0)
+ strcpy (argv[c], "-t");
+ else if (strcmp ("-wt", argv[c]) == 0)
+ strcpy (argv[c], "-w");
+ else if (strcmp ("-ct", argv[c]) == 0)
+ strcpy (argv[c], "-c");
+ }
+
while (1) {
#ifdef HAVE_GETOPT_H
c =
- getopt_long (argc, argv, "+hVH:u:p:v:c:w:t:", long_options,
+ getopt_long (argc, argv, "hVH:u:p:v:c:w:t:", long_options,
&option_index);
#else
- c = getopt (argc, argv, "+?hVH:u:p:v:c:w:t:");
+ c = getopt (argc, argv, "hVH:u:p:v:c:w:t:");
#endif
- i++;
-
- if (c == -1 || c == EOF || c == 1)
+ if (c == -1 || c == EOF)
break;
- switch (c) {
- case 'H':
- case 'u':
- case 'p':
- case 'v':
- case 'c':
- case 'w':
- case 't':
- i++;
- }
-
switch (c) {
case '?': /* help */
- usage ("Invalid argument\n");
+ usage3 ("Unknown option", optopt);
case 'H': /* hostname */
if (is_host (optarg)) {
server_address = optarg;
}
else {
- usage ("Invalid host name\n");
+ usage2 ("Invalid host name", optarg);
}
break;
case 'u': /* ups name */
server_port = atoi (optarg);
}
else {
- usage ("Server port must be a positive integer\n");
+ usage2 ("Server port must be a positive integer", optarg);
}
break;
case 'c': /* critical time threshold */
check_critical_value = TRUE;
}
else {
- usage ("Critical time must be a nonnegative integer\n");
+ usage2 ("Critical time must be a nonnegative integer", optarg);
}
break;
case 'w': /* warning time threshold */
check_warning_value = TRUE;
}
else {
- usage ("Warning time must be a nonnegative integer\n");
+ usage2 ("Warning time must be a nonnegative integer", optarg);
}
break;
case 'v': /* variable */
else if (!strcmp (optarg, "LOADPCT"))
check_variable = UPS_LOADPCT;
else
- usage ("Unrecognized UPS variable\n");
+ usage2 ("Unrecognized UPS variable", optarg);
break;
case 't': /* timeout */
if (is_intnonneg (optarg)) {
exit (STATE_OK);
}
}
- return i;
+
+
+ if (server_address == NULL) {
+ if (optind >= argc) {
+ server_address = strscpy (NULL, "127.0.0.1");
+ }
+ else if (is_host (argv[optind])) {
+ server_address = argv[optind++];
+ }
+ else {
+ usage ("Invalid host name");
+ }
+ }
+ return validate_arguments();
}
diff --git a/plugins/check_users.c b/plugins/check_users.c
index 2b8fa15bfea9e9361a4d757b9c842d2bb1deea23..e39e0d2bae25eb0b99f17db8811000a3589118fa 100644 (file)
--- a/plugins/check_users.c
+++ b/plugins/check_users.c
#include "utils.h"
#define PROGNAME "check_users"
+#define REVISION "$Revision$"
+#define COPYRIGHT "1999-2002"
+#define AUTHOR "Ethan Galstad"
+#define EMAIL "nagios@nagios.org"
#define possibly_set(a,b) ((a) == 0 ? (b) : 0)
int process_arguments (int, char **);
-int call_getopt (int, char **);
void print_usage (void);
void print_help (void);
{
int c;
- if (argc < 2)
- usage ("\n");
-
- c = 0;
- while ((c += call_getopt (argc - c, &argv[c])) < argc) {
-
- if (is_option (argv[c]))
- continue;
-
- if (wusers == -1 && argc > c) {
- if (is_intnonneg (argv[c]) == FALSE)
- usage ("Warning threshold must be a nonnegative integer\n");
- wusers = atoi (argv[c]);
-
- }
- else if (cusers == -1 && argc > c) {
- if (is_intnonneg (argv[c]) == FALSE)
- usage ("Warning threshold must be a nonnegative integer\n");
- cusers = atoi (argv[c]);
- }
- }
-
- return OK;
-}
-
-
-
-
-
-int
-call_getopt (int argc, char **argv)
-{
- int c, i = 0;
-
#ifdef HAVE_GETOPT_H
int option_index = 0;
static struct option long_options[] = {
};
#endif
+ if (argc < 2)
+ usage ("\n");
+
while (1) {
#ifdef HAVE_GETOPT_H
c = getopt_long (argc, argv, "+hVvc:w:", long_options, &option_index);
c = getopt (argc, argv, "+hVvc:w:");
#endif
- i++;
-
if (c == -1 || c == EOF || c == 1)
break;
- switch (c) {
- case 'c':
- case 'w':
- i++;
- }
-
switch (c) {
case '?': /* print short usage statement if args not parsable */
- printf ("%s: Unknown argument: %s\n\n", my_basename (argv[0]), optarg);
+ printf ("%s: Unknown argument: %s\n\n", PROGNAME, optarg);
print_usage ();
exit (STATE_UNKNOWN);
case 'h': /* help */
print_help ();
exit (STATE_OK);
case 'V': /* version */
- print_revision (my_basename (argv[0]), "$Revision$");
+ print_revision (PROGNAME, REVISION);
exit (STATE_OK);
case 'c': /* critical */
if (!is_intnonneg (optarg))
break;
}
}
- return i;
+
+ c = optind;
+ if (wusers == -1 && argc > c) {
+ if (is_intnonneg (argv[c]) == FALSE)
+ usage ("Warning threshold must be a nonnegative integer\n");
+ wusers = atoi (argv[c++]);
+ }
+
+ if (cusers == -1 && argc > c) {
+ if (is_intnonneg (argv[c]) == FALSE)
+ usage ("Warning threshold must be a nonnegative integer\n");
+ cusers = atoi (argv[c]);
+ }
+
+ return OK;
}
void
print_help (void)
{
- print_revision (PROGNAME, "$Revision$");
+ print_revision (PROGNAME, REVISION);
printf
- ("Copyright (c) 1999 Ethan Galstad (nagios@nagios.org)\n\n"
+ ("Copyright (c) " COPYRIGHT " " AUTHOR "(" EMAIL ")\n\n"
"This plugin checks the number of users currently logged in on the local\n"
"system and generates an error if the number exceeds the thresholds specified.\n");
print_usage ();