Sfoglia il codice sorgente

markup for translation

git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@620 f882894a-f735-0410-b71e-b25c423dba1c
Karl DeBisschop 22 anni fa
parent
commit
ccead7695f
5 ha cambiato i file con 135 aggiunte e 99 eliminazioni
  1. 105 78
      plugins/check_dig.c
  2. 9 4
      plugins/check_pgsql.c
  3. 12 12
      plugins/check_swap.c
  4. 3 1
      plugins/check_tcp.c
  5. 6 4
      plugins/utils.h

+ 105 - 78
plugins/check_dig.c

@@ -16,45 +16,75 @@
 *
 *****************************************************************************/
 
+#include "config.h"
+#include "common.h"
+#include "netutils.h"
+#include "utils.h"
+#include "popen.h"
+
+int process_arguments (int, char **);
+int validate_arguments (void);
+void print_help (void);
+void print_usage (void);
+
 const char *progname = "check_dig";
 const char *revision = "$Revision$";
 const char *copyright = "2002-2003";
-const char *authors = "Nagios Plugin Development Team";
 const char *email = "nagiosplug-devel@lists.sourceforge.net";
 
-const char *summary = "Test the DNS service on the specified host using dig\n";
+enum {
+	DEFAULT_PORT = 53
+};
+
+void
+print_usage (void)
+{
+	printf (_("\
+Usage: %s -H host -l lookup [-p <server port>] [-w <warning interval>]\n\
+         [-c <critical interval>] [-t <timeout>] [-v]\n"),
+	        progname);
+	printf ("       %s (-h|--help)\n", progname);
+	printf ("       %s (-V|--version)\n", progname);
+}
+
+void
+print_help (void)
+{
+	char *myport;
+
+	asprintf (&myport, "%d", DEFAULT_PORT);
+
+	print_revision (progname, revision);
 
-const char *option_summary = "-H host -l lookup [-t timeout] [-v]";
+	printf (_(COPYRIGHT), copyright, email);
 
-const char *options = "\
- -H, --hostname=STRING or IPADDRESS\n\
-   Check server on the indicated host\n\
+	printf (_("Test the DNS service on the specified host using dig\n\n"));
+
+	print_usage ();
+
+	printf (_(HELP_VRSN));
+
+	printf (_(HOST_PORT), 'P', myport);
+
+	printf (_("\
  -l, --lookup=STRING\n\
-   machine name to lookup\n\
- -t, --timeout=INTEGER\n\
-   Seconds before connection attempt times out (default: %d)\n\
- -v, --verbose\n\
-   Print extra information (command-line use only)\n";
-
-const char *standard_options = "\
- -h, --help\n\
-    Print detailed help screen\n\
- -V, --version\n\
-    Print version information\n\n";
+   machine name to lookup\n"));
 
-#include "config.h"
-#include "common.h"
-#include "utils.h"
-#include "popen.h"
+	printf (_(WARN_CRIT_TO), DEFAULT_SOCKET_TIMEOUT);
 
-int process_arguments (int, char **);
-int validate_arguments (void);
-void print_help (void);
-void print_usage (void);
+	printf (_(VRBS));
+
+	support ();
+}
+
 
 char *query_address = NULL;
 char *dns_server = NULL;
 int verbose = FALSE;
+int server_port = DEFAULT_PORT;
+int warning_interval = -1;
+int critical_interval = -1;
+
 
 int
 main (int argc, char **argv)
@@ -66,13 +96,14 @@ main (int argc, char **argv)
 
 	/* Set signal handling and alarm */
 	if (signal (SIGALRM, popen_timeout_alarm_handler) == SIG_ERR)
-		usage ("Cannot catch SIGALRM\n");
+		usage (_("Cannot catch SIGALRM\n"));
 
 	if (process_arguments (argc, argv) != OK)
-		usage ("Could not parse arguments\n");
+		usage (_("Could not parse arguments\n"));
 
 	/* get the command to run */
-	asprintf (&command_line, "%s @%s %s", PATH_TO_DIG, dns_server, query_address);
+	asprintf (&command_line, "%s @%s -p %d %s",
+	          PATH_TO_DIG, dns_server, server_port, query_address);
 
 	alarm (timeout_interval);
 	time (&start_time);
@@ -82,13 +113,13 @@ main (int argc, char **argv)
 	/* run the command */
 	child_process = spopen (command_line);
 	if (child_process == NULL) {
-		printf ("Could not open pipe: %s\n", command_line);
+		printf (_("Could not open pipe: %s\n"), command_line);
 		return STATE_UNKNOWN;
 	}
 
 	child_stderr = fdopen (child_stderr_array[fileno (child_process)], "r");
 	if (child_stderr == NULL)
-		printf ("Could not open stderr for %s\n", command_line);
+		printf (_("Could not open stderr for %s\n"), command_line);
 
 	while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process)) {
 
@@ -107,7 +138,7 @@ main (int argc, char **argv)
 				result = STATE_OK;
 			}
 			else {
-				asprintf (&output, "Server not found in ANSWER SECTION");
+				asprintf (&output, _("Server not found in ANSWER SECTION"));
 				result = STATE_WARNING;
 			}
 
@@ -117,7 +148,7 @@ main (int argc, char **argv)
 	}
 
 	if (result != STATE_OK) {
-		asprintf (&output, "No ANSWER SECTION found");
+		asprintf (&output, _("No ANSWER SECTION found"));
 	}
 
 	while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr)) {
@@ -134,23 +165,23 @@ main (int argc, char **argv)
 	if (spclose (child_process)) {
 		result = max_state (result, STATE_WARNING);
 		if (strlen (output) == 0)
-			asprintf (&output, "dig returned error status");
+			asprintf (&output, _("dig returned error status"));
 	}
 
 	(void) time (&end_time);
 
 	if (output == NULL || strlen (output) == 0)
-		asprintf (&output, " Probably a non-existent host/domain");
+		asprintf (&output, _(" Probably a non-existent host/domain"));
 
 	if (result == STATE_OK)
-		printf ("DNS OK - %d seconds response time (%s)\n",
+		printf (_("DNS OK - %d seconds response time (%s)\n"),
 						(int) (end_time - start_time), output);
 	else if (result == STATE_WARNING)
-		printf ("DNS WARNING - %s\n", output);
+		printf (_("DNS WARNING - %s\n"), output);
 	else if (result == STATE_CRITICAL)
-		printf ("DNS CRITICAL - %s\n", output);
+		printf (_("DNS CRITICAL - %s\n"), output);
 	else
-		printf ("DNS problem - %s\n", output);
+		printf (_("DNS problem - %s\n"), output);
 
 	return result;
 }
@@ -182,35 +213,59 @@ process_arguments (int argc, char **argv)
 
 		switch (c) {
 		case '?':									/* help */
-			usage3 ("Unknown argument", optopt);
+			usage3 (_("Unknown argument"), optopt);
+		case 'h':									/* help */
+			print_help ();
+			exit (STATE_OK);
+		case 'V':									/* version */
+			print_revision (progname, "$Revision$");
+			exit (STATE_OK);
 		case 'H':									/* hostname */
 			if (is_host (optarg)) {
 				dns_server = optarg;
 			}
 			else {
-				usage ("Invalid host name\n");
+				usage2 (_("Invalid host name"), optarg);
+			}
+			break;
+		case 'p':
+			if (is_intpos (optarg)) {
+				server_port = atoi (optarg);
+			}
+			else {
+				usage2 (_("Server port must be a nonnegative integer\n"), optarg);
 			}
 			break;
 		case 'l':									/* username */
 			query_address = optarg;
 			break;
-		case 'v':									/* verbose */
-			verbose = TRUE;
+		case 'w':									/* timeout */
+			if (is_intnonneg (optarg)) {
+				warning_interval = atoi (optarg);
+			}
+			else {
+				usage2 (_("Warning interval must be a nonnegative integer\n"), optarg);
+			}
+			break;
+		case 'c':									/* timeout */
+			if (is_intnonneg (optarg)) {
+				critical_interval = atoi (optarg);
+			}
+			else {
+				usage2 (_("Critical interval must be a nonnegative integer\n"), optarg);
+			}
 			break;
 		case 't':									/* timeout */
 			if (is_intnonneg (optarg)) {
 				timeout_interval = atoi (optarg);
 			}
 			else {
-				usage ("Time interval must be a nonnegative integer\n");
+				usage2 (_("Time interval must be a nonnegative integer\n"), optarg);
 			}
 			break;
-		case 'V':									/* version */
-			print_revision (progname, "$Revision$");
-			exit (STATE_OK);
-		case 'h':									/* help */
-			print_help ();
-			exit (STATE_OK);
+		case 'v':									/* verbose */
+			verbose = TRUE;
+			break;
 		}
 	}
 
@@ -221,7 +276,7 @@ process_arguments (int argc, char **argv)
 				dns_server = argv[c];
 			}
 			else {
-				usage ("Invalid host name");
+				usage2 (_("Invalid host name"), argv[c]);
 			}
 		}
 		else {
@@ -242,31 +297,3 @@ validate_arguments (void)
 	return OK;
 }
 
-
-
-
-
-void
-print_help (void)
-{
-	print_revision (progname, revision);
-	printf ("Copyright (c) %s %s\n\t<%s>\n\n", copyright, authors, email);
-	printf (summary);
-	print_usage ();
-	printf ("\nOptions:\n");
-	printf (options, DEFAULT_SOCKET_TIMEOUT);
-	printf (standard_options);
-	support ();
-}
-
-
-
-
-
-void
-print_usage (void)
-{
-	printf ("Usage: %s %s\n", progname, option_summary);
-	printf ("       %s (-h|--help)\n", progname);
-	printf ("       %s (-V|--version)\n", progname);
-}

+ 9 - 4
plugins/check_pgsql.c

@@ -29,8 +29,7 @@
 enum {
 	DEFAULT_PORT = 5432,
 	DEFAULT_WARN = 2,
-	DEFAULT_CRIT = 8,
-	DEFAULT_TIMEOUT = 30
+	DEFAULT_CRIT = 8
 };
 
 #include "config.h"
@@ -125,6 +124,10 @@ Please note that all tags must be lowercase to use the DocBook XML DTD.
 void
 print_help (void)
 {
+	char *myport;
+
+	asprintf (&myport, "%d", DEFAULT_PORT);
+
 	print_revision (progname, revision);
 
 	printf (_(COPYRIGHT), copyright, email);
@@ -135,7 +138,9 @@ print_help (void)
 
 	printf (_(HELP_VRSN));
 
-	printf (_(HOST_PORT_46), 'P', "5432");
+	printf (_(HOST_PORT), 'P', myport);
+
+	printf (_(IPv46));
 
 	printf (S_("\
   -d, --database=STRING\n\
@@ -143,7 +148,7 @@ print_help (void)
   -l, --logname = STRING\n\
     Login name of user\n\
   -p, --password = STRING\n\
-    Password (BIG SECURITY ISSUE)\n\n"), DEFAULT_DB);
+    Password (BIG SECURITY ISSUE)\n"), DEFAULT_DB);
 
 	printf (_(WARN_CRIT_TO), DEFAULT_SOCKET_TIMEOUT);
 

+ 12 - 12
plugins/check_swap.c

@@ -124,7 +124,7 @@ main (int argc, char **argv)
 	char *status = "";
 
 	if (process_arguments (argc, argv) != OK)
-		usage ("Invalid command arguments supplied\n");
+		usage (_("Invalid command arguments supplied\n"));
 
 #ifdef HAVE_PROC_MEMINFO
 	fp = fopen (PROC_MEMINFO, "r");
@@ -147,19 +147,19 @@ main (int argc, char **argv)
 	}
 
 	if (verbose >= 2)
-		printf ("Command: %s\n", swap_command);
+		printf (_("Command: %s\n"), swap_command);
 	if (verbose >= 3)
-		printf ("Format: %s\n", swap_format);
+		printf ("_(Format: %s\n"), swap_format);
 
 	child_process = spopen (swap_command);
 	if (child_process == NULL) {
-		printf ("Could not open pipe: %s\n", swap_command);
+		printf (_("Could not open pipe: %s\n"), swap_command);
 		return STATE_UNKNOWN;
 	}
 
 	child_stderr = fdopen (child_stderr_array[fileno (child_process)], "r");
 	if (child_stderr == NULL)
-		printf ("Could not open stderr for %s\n", swap_command);
+		printf (_("Could not open stderr for %s\n"), swap_command);
 
 	sprintf (str, "%s", "");
 	/* read 1st line */
@@ -189,7 +189,7 @@ main (int argc, char **argv)
 			dsktotal = dsktotal / conv_factor;
 			dskfree = dskfree / conv_factor;
 			if (verbose >= 3)
-				printf ("total=%d, free=%d\n", dsktotal, dskfree);
+				printf (_("total=%d, free=%d\n"), dsktotal, dskfree);
 
 			dskused = dsktotal - dskfree;
 #endif
@@ -206,7 +206,7 @@ main (int argc, char **argv)
 	}
 	percent_used = 100 * ((double) used_swap) / ((double) total_swap);
 	result = max_state (result, check_swap (percent_used, free_swap));
-	asprintf (&status, " %d%% free (%lu MB out of %lu MB)%s",
+	asprintf (&status, _(" %d%% free (%lu MB out of %lu MB)%s"),
 						(100 - percent_used), free_swap, total_swap, status);
 
 #ifdef HAVE_PROC_MEMINFO
@@ -294,7 +294,7 @@ process_arguments (int argc, char **argv)
 				break;
 			}
 			else {
-				usage ("Warning threshold must be integer or percentage!\n");
+				usage (_("Warning threshold must be integer or percentage!\n"));
 			}
 			wc++;
 		case 'c':									/* critical time threshold */
@@ -312,7 +312,7 @@ process_arguments (int argc, char **argv)
 				break;
 			}
 			else {
-				usage ("Critical threshold must be integer or percentage!\n");
+				usage (_("Critical threshold must be integer or percentage!\n"));
 			}
 			cc++;
 		case 'a':									/* all swap */
@@ -328,7 +328,7 @@ process_arguments (int argc, char **argv)
 			print_help ();
 			exit (STATE_OK);
 		case '?':									/* help */
-			usage ("Invalid argument\n");
+			usage (_("Invalid argument\n"));
 		}
 	}
 
@@ -369,11 +369,11 @@ validate_arguments (void)
 	}
 	else if (warn_percent < crit_percent) {
 		usage
-			("Warning percentage should be more than critical percentage\n");
+			(_("Warning percentage should be more than critical percentage\n"));
 	}
 	else if (warn_size < crit_size) {
 		usage
-			("Warning free space should be more than critical free space\n");
+			(_("Warning free space should be more than critical free space\n"));
 	}
 	return OK;
 }

+ 3 - 1
plugins/check_tcp.c

@@ -118,7 +118,9 @@ print_help (void)
 
 	printf (_(HELP_VRSN));
 
-	printf (_(HOST_PORT_46), 'p', "none");
+	printf (_(HOST_PORT), 'p', "none");
+
+	printf (_(IPv46));
 
 	printf (_("\
  -s, --send=STRING\n\

+ 6 - 4
plugins/utils.h

@@ -99,11 +99,13 @@ char *state_text (int result);
  -V, --version\n\
     Print version information\n"
 
-#define HOST_PORT_46 "\
+#define HOST_PORT "\
  -H, --hostname=ADDRESS\n\
-    Host name or IP Address%s\n\
+    Host name or IP Address\n\
  -%c, --port=INTEGER\n\
-    Port number (default: %s)\n\
+    Port number (default: %s)\n"
+
+#define IPv46 "\
  -4, --use-ipv4\n\
     Use IPv4 connection\n\
  -6, --use-ipv6\n\
@@ -119,4 +121,4 @@ char *state_text (int result);
  -c, --critical=DOUBLE\n\
     Response time to result in critical status (seconds)\n\
  -t, --timeout=INTEGER\n\
-    Seconds before connection times out (default: %s)\n"
+    Seconds before connection times out (default: %d)\n"