Просмотр исходного кода

check_mrtgtraf - verbose output

Add some basic verbose output.
Spenser Reinhardt 11 лет назад
Родитель
Сommit
be8ed182cd
1 измененных файлов с 22 добавлено и 2 удалено
  1. 22 2
      plugins/check_mrtgtraf.c

+ 22 - 2
plugins/check_mrtgtraf.c

@@ -41,6 +41,7 @@ int validate_arguments (void);
 void print_help(void);
 void print_usage(void);
 
+int verbose = false;
 char *log_file = NULL;
 int expire_minutes = -1;
 int use_average = TRUE;
@@ -88,6 +89,7 @@ main (int argc, char **argv)
 		usage4 (_("Unable to open MRTG log file"));
 
 	line = 0;
+
 	while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, fp)) {
 
 		line++;
@@ -104,22 +106,32 @@ main (int argc, char **argv)
 		/* grab the timestamp */
 		temp_buffer = strtok (input_buffer, " ");
 		timestamp = strtoul (temp_buffer, NULL, 10);
+		if (verbose)
+			printf("%s %lu\n", _("Found timestamp of:"), timestamp);
 
 		/* grab the average incoming transfer rate */
 		temp_buffer = strtok (NULL, " ");
 		average_incoming_rate = strtoul (temp_buffer, NULL, 10);
+		if (verbose)
+			printf("%s %lu\n", _("Found average incoming rate of:"), average_incoming_rate);
 
 		/* grab the average outgoing transfer rate */
 		temp_buffer = strtok (NULL, " ");
 		average_outgoing_rate = strtoul (temp_buffer, NULL, 10);
+		if (verbose)
+			printf("%s %lu\n", _("Found average outgoing rate of:"), average_outgoing_rate);
 
 		/* grab the maximum incoming transfer rate */
 		temp_buffer = strtok (NULL, " ");
 		maximum_incoming_rate = strtoul (temp_buffer, NULL, 10);
+		if (verbose)
+			printf("%s %lu\n", _("Found maximum incoming rate of:"), maximum_incoming_rate);
 
 		/* grab the maximum outgoing transfer rate */
 		temp_buffer = strtok (NULL, " ");
 		maximum_outgoing_rate = strtoul (temp_buffer, NULL, 10);
+		if (verbose)
+			printf("%s %lu\n", _("Found maximum outgoing rate of:"), maximum_outgoing_rate);
 	}
 
 	/* close the log file */
@@ -138,10 +150,12 @@ main (int argc, char **argv)
 
 	/* else check the incoming/outgoing rates */
 	if (use_average == TRUE) {
+		if (verbose) printf("%s\n", _("Using average rates not maximum."));
 		incoming_rate = average_incoming_rate;
 		outgoing_rate = average_outgoing_rate;
 	}
 	else {
+		if (verbose) printf("%s\n", _("Using default maximum rates."));
 		incoming_rate = maximum_incoming_rate;
 		outgoing_rate = maximum_outgoing_rate;
 	}
@@ -224,6 +238,7 @@ process_arguments (int argc, char **argv)
 		{"aggregation", required_argument, 0, 'a'},
 		{"critical", required_argument, 0, 'c'},
 		{"warning", required_argument, 0, 'w'},
+		{"verbose", no_argument, 0, 'v'},
 		{"version", no_argument, 0, 'V'},
 		{"help", no_argument, 0, 'h'},
 		{0, 0, 0, 0}
@@ -242,7 +257,7 @@ process_arguments (int argc, char **argv)
 	}
 
 	while (1) {
-		c = getopt_long (argc, argv, "hVF:e:a:c:w:", longopts, &option);
+		c = getopt_long (argc, argv, "hVvF:e:a:c:w:", longopts, &option);
 
 		if (c == -1 || c == EOF)
 			break;
@@ -268,6 +283,9 @@ process_arguments (int argc, char **argv)
 			sscanf (optarg, "%lu,%lu", &incoming_warning_threshold,
 							&outgoing_warning_threshold);
 			break;
+		case 'v':
+			verbose = true;
+			break;
 		case 'V':									/* version */
 			print_revision (progname, NP_VERSION);
 			exit (STATE_OK);
@@ -356,9 +374,11 @@ print_help (void)
   printf ("    %s\n", _("Warning threshold pair <incoming>,<outgoing>"));
   printf (" %s\n", "-c, --critical");
   printf ("    %s\n", _("Critical threshold pair <incoming>,<outgoing>"));
+  printf (" %s\n", _("-v, --verbose"));
+  printf ("    %s\n", _("Verbose output durring plugin runtime."));
 
   printf ("\n");
-	printf ("%s\n", _("Notes:"));
+  printf ("%s\n", _("Notes:"));
   printf (" %s\n", _("- MRTG stands for Multi Router Traffic Grapher. It can be downloaded from"));
   printf (" %s\n", "  http://ee-staff.ethz.ch/~oetiker/webtools/mrtg/mrtg.html");
   printf (" %s\n", _("- While MRTG can monitor things other than traffic rates, this"));