summaryrefslogtreecommitdiffstats
path: root/plugins/check_users.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/check_users.c')
-rw-r--r--plugins/check_users.c74
1 files changed, 26 insertions, 48 deletions
diff --git a/plugins/check_users.c b/plugins/check_users.c
index 2b8fa15..e39e0d2 100644
--- a/plugins/check_users.c
+++ b/plugins/check_users.c
@@ -49,11 +49,14 @@
49#include "utils.h" 49#include "utils.h"
50 50
51#define PROGNAME "check_users" 51#define PROGNAME "check_users"
52#define REVISION "$Revision$"
53#define COPYRIGHT "1999-2002"
54#define AUTHOR "Ethan Galstad"
55#define EMAIL "nagios@nagios.org"
52 56
53#define possibly_set(a,b) ((a) == 0 ? (b) : 0) 57#define possibly_set(a,b) ((a) == 0 ? (b) : 0)
54 58
55int process_arguments (int, char **); 59int process_arguments (int, char **);
56int call_getopt (int, char **);
57void print_usage (void); 60void print_usage (void);
58void print_help (void); 61void print_help (void);
59 62
@@ -133,40 +136,6 @@ process_arguments (int argc, char **argv)
133{ 136{
134 int c; 137 int c;
135 138
136 if (argc < 2)
137 usage ("\n");
138
139 c = 0;
140 while ((c += call_getopt (argc - c, &argv[c])) < argc) {
141
142 if (is_option (argv[c]))
143 continue;
144
145 if (wusers == -1 && argc > c) {
146 if (is_intnonneg (argv[c]) == FALSE)
147 usage ("Warning threshold must be a nonnegative integer\n");
148 wusers = atoi (argv[c]);
149
150 }
151 else if (cusers == -1 && argc > c) {
152 if (is_intnonneg (argv[c]) == FALSE)
153 usage ("Warning threshold must be a nonnegative integer\n");
154 cusers = atoi (argv[c]);
155 }
156 }
157
158 return OK;
159}
160
161
162
163
164
165int
166call_getopt (int argc, char **argv)
167{
168 int c, i = 0;
169
170#ifdef HAVE_GETOPT_H 139#ifdef HAVE_GETOPT_H
171 int option_index = 0; 140 int option_index = 0;
172 static struct option long_options[] = { 141 static struct option long_options[] = {
@@ -178,6 +147,9 @@ call_getopt (int argc, char **argv)
178 }; 147 };
179#endif 148#endif
180 149
150 if (argc < 2)
151 usage ("\n");
152
181 while (1) { 153 while (1) {
182#ifdef HAVE_GETOPT_H 154#ifdef HAVE_GETOPT_H
183 c = getopt_long (argc, argv, "+hVvc:w:", long_options, &option_index); 155 c = getopt_long (argc, argv, "+hVvc:w:", long_options, &option_index);
@@ -185,27 +157,19 @@ call_getopt (int argc, char **argv)
185 c = getopt (argc, argv, "+hVvc:w:"); 157 c = getopt (argc, argv, "+hVvc:w:");
186#endif 158#endif
187 159
188 i++;
189
190 if (c == -1 || c == EOF || c == 1) 160 if (c == -1 || c == EOF || c == 1)
191 break; 161 break;
192 162
193 switch (c) { 163 switch (c) {
194 case 'c':
195 case 'w':
196 i++;
197 }
198
199 switch (c) {
200 case '?': /* print short usage statement if args not parsable */ 164 case '?': /* print short usage statement if args not parsable */
201 printf ("%s: Unknown argument: %s\n\n", my_basename (argv[0]), optarg); 165 printf ("%s: Unknown argument: %s\n\n", PROGNAME, optarg);
202 print_usage (); 166 print_usage ();
203 exit (STATE_UNKNOWN); 167 exit (STATE_UNKNOWN);
204 case 'h': /* help */ 168 case 'h': /* help */
205 print_help (); 169 print_help ();
206 exit (STATE_OK); 170 exit (STATE_OK);
207 case 'V': /* version */ 171 case 'V': /* version */
208 print_revision (my_basename (argv[0]), "$Revision$"); 172 print_revision (PROGNAME, REVISION);
209 exit (STATE_OK); 173 exit (STATE_OK);
210 case 'c': /* critical */ 174 case 'c': /* critical */
211 if (!is_intnonneg (optarg)) 175 if (!is_intnonneg (optarg))
@@ -219,7 +183,21 @@ call_getopt (int argc, char **argv)
219 break; 183 break;
220 } 184 }
221 } 185 }
222 return i; 186
187 c = optind;
188 if (wusers == -1 && argc > c) {
189 if (is_intnonneg (argv[c]) == FALSE)
190 usage ("Warning threshold must be a nonnegative integer\n");
191 wusers = atoi (argv[c++]);
192 }
193
194 if (cusers == -1 && argc > c) {
195 if (is_intnonneg (argv[c]) == FALSE)
196 usage ("Warning threshold must be a nonnegative integer\n");
197 cusers = atoi (argv[c]);
198 }
199
200 return OK;
223} 201}
224 202
225 203
@@ -239,9 +217,9 @@ print_usage (void)
239void 217void
240print_help (void) 218print_help (void)
241{ 219{
242 print_revision (PROGNAME, "$Revision$"); 220 print_revision (PROGNAME, REVISION);
243 printf 221 printf
244 ("Copyright (c) 1999 Ethan Galstad (nagios@nagios.org)\n\n" 222 ("Copyright (c) " COPYRIGHT " " AUTHOR "(" EMAIL ")\n\n"
245 "This plugin checks the number of users currently logged in on the local\n" 223 "This plugin checks the number of users currently logged in on the local\n"
246 "system and generates an error if the number exceeds the thresholds specified.\n"); 224 "system and generates an error if the number exceeds the thresholds specified.\n");
247 print_usage (); 225 print_usage ();