summaryrefslogtreecommitdiffstats
path: root/plugins/check_mrtg.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/check_mrtg.c')
-rw-r--r--plugins/check_mrtg.c166
1 files changed, 67 insertions, 99 deletions
diff --git a/plugins/check_mrtg.c b/plugins/check_mrtg.c
index b86686d..4d297aa 100644
--- a/plugins/check_mrtg.c
+++ b/plugins/check_mrtg.c
@@ -86,7 +86,6 @@ Notes:\n\
86#include "utils.h" 86#include "utils.h"
87 87
88int process_arguments (int, char **); 88int process_arguments (int, char **);
89int call_getopt (int, char **);
90int validate_arguments (void); 89int validate_arguments (void);
91void print_help (void); 90void print_help (void);
92void print_usage (void); 91void print_usage (void);
@@ -97,8 +96,8 @@ int use_average = TRUE;
97int variable_number = -1; 96int variable_number = -1;
98unsigned long value_warning_threshold = 0L; 97unsigned long value_warning_threshold = 0L;
99unsigned long value_critical_threshold = 0L; 98unsigned long value_critical_threshold = 0L;
100char *value_label = NULL; 99char *value_label = "";
101char *units_label = NULL; 100char *units_label = "";
102 101
103int 102int
104main (int argc, char **argv) 103main (int argc, char **argv)
@@ -215,83 +214,6 @@ process_arguments (int argc, char **argv)
215{ 214{
216 int c; 215 int c;
217 216
218 if (argc < 2)
219 return ERROR;
220
221 for (c = 1; c < argc; c++) {
222 if (strcmp ("-to", argv[c]) == 0)
223 strcpy (argv[c], "-t");
224 else if (strcmp ("-wt", argv[c]) == 0)
225 strcpy (argv[c], "-w");
226 else if (strcmp ("-ct", argv[c]) == 0)
227 strcpy (argv[c], "-c");
228 }
229
230
231
232 c = 0;
233 while ((c += (call_getopt (argc - c, &argv[c]))) < argc) {
234
235 if (is_option (argv[c]))
236 continue;
237
238 if (log_file == NULL) {
239 log_file = argv[c];
240 }
241 else if (expire_minutes <= 0) {
242 if (is_intpos (argv[c]))
243 expire_minutes = atoi (argv[c]);
244 else
245 terminate (STATE_UNKNOWN,
246 "%s is not a valid expiration time\nUse '%s -h' for additional help\n",
247 argv[c], PROGNAME);
248 }
249 else if (strcmp (argv[c], "MAX") == 0) {
250 use_average = FALSE;
251 }
252 else if (strcmp (argv[c], "AVG") == 0) {
253 use_average = TRUE;
254 }
255 else if (variable_number == -1) {
256 variable_number = atoi (argv[c]);
257 if (variable_number < 1 || variable_number > 2) {
258 printf ("%s :", argv[c]);
259 usage ("Invalid variable number\n");
260 }
261 }
262 else if (value_warning_threshold == 0) {
263 value_warning_threshold = strtoul (argv[c], NULL, 10);
264 }
265 else if (value_critical_threshold == 0) {
266 value_critical_threshold = strtoul (argv[c], NULL, 10);
267 }
268 else if (value_label == NULL) {
269 value_label = argv[c];
270 }
271 else if (units_label == NULL) {
272 units_label = argv[c];
273 }
274 }
275
276 if (value_label == NULL)
277 value_label = strscpy (NULL, "");
278
279 if (units_label == NULL)
280 units_label = strscpy (NULL, "");
281
282 return validate_arguments ();
283}
284
285
286
287
288
289
290int
291call_getopt (int argc, char **argv)
292{
293 int c, i = 0;
294
295#ifdef HAVE_GETOPT_H 217#ifdef HAVE_GETOPT_H
296 int option_index = 0; 218 int option_index = 0;
297 static struct option long_options[] = { 219 static struct option long_options[] = {
@@ -310,33 +232,31 @@ call_getopt (int argc, char **argv)
310 }; 232 };
311#endif 233#endif
312 234
235 if (argc < 2)
236 return ERROR;
237
238 for (c = 1; c < argc; c++) {
239 if (strcmp ("-to", argv[c]) == 0)
240 strcpy (argv[c], "-t");
241 else if (strcmp ("-wt", argv[c]) == 0)
242 strcpy (argv[c], "-w");
243 else if (strcmp ("-ct", argv[c]) == 0)
244 strcpy (argv[c], "-c");
245 }
246
313 while (1) { 247 while (1) {
314#ifdef HAVE_GETOPT_H 248#ifdef HAVE_GETOPT_H
315 c = 249 c =
316 getopt_long (argc, argv, "+hVF:e:a:v:c:w:l:u:", long_options, 250 getopt_long (argc, argv, "hVF:e:a:v:c:w:l:u:", long_options,
317 &option_index); 251 &option_index);
318#else 252#else
319 c = getopt (argc, argv, "+?hVF:e:a:v:c:w:l:u:"); 253 c = getopt (argc, argv, "hVF:e:a:v:c:w:l:u:");
320#endif 254#endif
321 255
322 i++; 256 if (c == -1 || c == EOF)
323
324 if (c == -1 || c == EOF || c == 1)
325 break; 257 break;
326 258
327 switch (c) { 259 switch (c) {
328 case 'F':
329 case 'e':
330 case 'a':
331 case 'v':
332 case 'c':
333 case 'w':
334 case 'l':
335 case 'u':
336 i++;
337 }
338
339 switch (c) {
340 case 'F': /* input file */ 260 case 'F': /* input file */
341 log_file = optarg; 261 log_file = optarg;
342 break; 262 break;
@@ -367,7 +287,7 @@ call_getopt (int argc, char **argv)
367 units_label = optarg; 287 units_label = optarg;
368 break; 288 break;
369 case 'V': /* version */ 289 case 'V': /* version */
370 print_revision (PROGNAME, "$Revision$"); 290 print_revision (PROGNAME, REVISION);
371 exit (STATE_OK); 291 exit (STATE_OK);
372 case 'h': /* help */ 292 case 'h': /* help */
373 print_help (); 293 print_help ();
@@ -376,7 +296,55 @@ call_getopt (int argc, char **argv)
376 usage ("Invalid argument\n"); 296 usage ("Invalid argument\n");
377 } 297 }
378 } 298 }
379 return i; 299
300 c = optind;
301 if (log_file == NULL && argc > c) {
302 log_file = argv[c++];
303 }
304
305 if (expire_minutes <= 0 && argc > c) {
306 if (is_intpos (argv[c]))
307 expire_minutes = atoi (argv[c++]);
308 else
309 terminate (STATE_UNKNOWN,
310 "%s is not a valid expiration time\nUse '%s -h' for additional help\n",
311 argv[c], PROGNAME);
312 }
313
314 if (argc > c && strcmp (argv[c], "MAX") == 0) {
315 use_average = FALSE;
316 c++;
317 }
318 else if (argc > c && strcmp (argv[c], "AVG") == 0) {
319 use_average = TRUE;
320 c++;
321 }
322
323 if (argc > c && variable_number == -1) {
324 variable_number = atoi (argv[c++]);
325 if (variable_number < 1 || variable_number > 2) {
326 printf ("%s :", argv[c]);
327 usage ("Invalid variable number\n");
328 }
329 }
330
331 if (argc > c && value_warning_threshold == 0) {
332 value_warning_threshold = strtoul (argv[c++], NULL, 10);
333 }
334
335 if (vargc > c && alue_critical_threshold == 0) {
336 value_critical_threshold = strtoul (argv[c++], NULL, 10);
337 }
338
339 if (argc > c && strlen (value_label) == 0) {
340 value_label = argv[c++];
341 }
342
343 if (argc > c && strlen (units_label) == 0) {
344 units_label = argv[c++];
345 }
346
347 return validate_arguments ();
380} 348}
381 349
382int 350int