From 234481163fc3caf0cb8b14f601f0f9f1458f97f5 Mon Sep 17 00:00:00 2001 From: Benoit Mortier Date: Thu, 2 Dec 2004 16:51:25 +0000 Subject: [PATCH] More internationalization work new usage4 function to permit localisation of think like check_ssh: xxxxx git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@979 f882894a-f735-0410-b71e-b25c423dba1c --- plugins/check_by_ssh.c | 7 ++----- plugins/check_dig.c | 4 ++-- plugins/check_disk.c | 2 +- plugins/check_dns.c | 5 ++--- plugins/check_fping.c | 2 +- plugins/check_game.c | 16 ++-------------- plugins/check_hpjd.c | 2 +- plugins/check_http.c | 2 +- plugins/check_ldap.c | 2 +- plugins/check_load.c | 2 +- plugins/check_mrtg.c | 2 +- plugins/check_mrtgtraf.c | 6 +++--- plugins/check_mysql.c | 2 +- plugins/check_nagios.c | 7 +++---- plugins/check_nt.c | 2 +- plugins/check_nwstat.c | 2 +- plugins/check_overcr.c | 2 +- plugins/check_pgsql.c | 5 ++--- plugins/check_ping.c | 5 ++--- plugins/check_procs.c | 5 ++--- plugins/check_radius.c | 2 +- plugins/check_real.c | 2 +- plugins/check_smtp.c | 2 +- plugins/check_snmp.c | 2 +- plugins/check_ssh.c | 2 +- plugins/check_swap.c | 2 +- plugins/check_tcp.c | 4 ++-- plugins/check_time.c | 2 +- plugins/check_udp.c | 2 +- plugins/check_ups.c | 2 +- plugins/check_users.c | 2 +- plugins/negate.c | 3 ++- plugins/popen.c | 1 + plugins/utils.c | 7 +++++++ 34 files changed, 53 insertions(+), 64 deletions(-) diff --git a/plugins/check_by_ssh.c b/plugins/check_by_ssh.c index 20ae628..f569731 100644 --- a/plugins/check_by_ssh.c +++ b/plugins/check_by_ssh.c @@ -69,17 +69,14 @@ main (int argc, char **argv) /* process arguments */ if (process_arguments (argc, argv) != TRUE) - usage (_("check_by_ssh: could not parse arguments\n")); - + usage4 (_("Could not parse arguments")); /* Set signal handling and alarm timeout */ if (signal (SIGALRM, popen_timeout_alarm_handler) == SIG_ERR) { - printf (_("Cannot catch SIGALRM")); - return STATE_UNKNOWN; + usage4 (_(" Cannot catch SIGALRM")); } alarm (timeout_interval); - /* run the command */ if (verbose) diff --git a/plugins/check_dig.c b/plugins/check_dig.c index 14c0da5..0102ea5 100644 --- a/plugins/check_dig.c +++ b/plugins/check_dig.c @@ -66,10 +66,10 @@ main (int argc, char **argv) /* Set signal handling and alarm */ if (signal (SIGALRM, popen_timeout_alarm_handler) == SIG_ERR) - usage (_("Cannot catch SIGALRM\n")); + usage4 (_("Cannot catch SIGALRM")); if (process_arguments (argc, argv) != TRUE) - usage (_("Could not parse arguments\n")); + usage4 (_("Could not parse arguments")); /* get the command to run */ asprintf (&command_line, "%s @%s -p %d %s -t %s", diff --git a/plugins/check_disk.c b/plugins/check_disk.c index 0cab9ac..c7ea344 100644 --- a/plugins/check_disk.c +++ b/plugins/check_disk.c @@ -164,7 +164,7 @@ main (int argc, char **argv) mount_list = read_filesystem_list (0); if (process_arguments (argc, argv) != TRUE) - usage (_("check_disk: could not parse arguments\n")); + usage4 (_("Could not parse arguments")); for (me = mount_list; me; me = me->me_next) { diff --git a/plugins/check_dns.c b/plugins/check_dns.c index d64431a..070223e 100644 --- a/plugins/check_dns.c +++ b/plugins/check_dns.c @@ -68,12 +68,11 @@ main (int argc, char **argv) /* Set signal handling and alarm */ if (signal (SIGALRM, popen_timeout_alarm_handler) == SIG_ERR) { - printf (_("Cannot catch SIGALRM")); - return STATE_UNKNOWN; + usage4 (_("Cannot catch SIGALRM")); } if (process_arguments (argc, argv) != TRUE) { - usage (_("check_dns: could not parse arguments\n")); + usage4 (_("Could not parse arguments")); } /* get the command to run */ diff --git a/plugins/check_fping.c b/plugins/check_fping.c index 74236d9..817d647 100644 --- a/plugins/check_fping.c +++ b/plugins/check_fping.c @@ -68,7 +68,7 @@ main (int argc, char **argv) textdomain (PACKAGE); if (process_arguments (argc, argv) != TRUE) - usage (_("check_fping: could not parse arguments\n")); + usage4 (_("Could not parse arguments")); server = strscpy (server, server_name); diff --git a/plugins/check_game.c b/plugins/check_game.c index c8492d8..89c212e 100644 --- a/plugins/check_game.c +++ b/plugins/check_game.c @@ -64,22 +64,9 @@ main (int argc, char **argv) setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); - -// result = process_arguments (argc, argv); if (process_arguments (argc, argv) != TRUE) - usage (_("check_game: could not parse arguments\n")); - -/* if (result != OK) { - printf (_("Incorrect arguments supplied\n")); - printf ("\n"); - print_revision (progname, revision); - printf ("Copyright (c) 1999 Ian Cass, Knowledge Matters Limited\n"); - printf (_("License: GPL\n")); - printf ("\n"); - return STATE_UNKNOWN; - } -*/ + usage4 (_("Could not parse arguments")); result = STATE_OK; @@ -312,6 +299,7 @@ print_help (void) { print_revision (progname, revision); + printf ("Copyright (c) 1999 Ian Cass, Knowledge Matters Limited\n"); printf (_(COPYRIGHT), copyright, email); printf (_("This plugin tests %s connections with the specified host."), progname); diff --git a/plugins/check_hpjd.c b/plugins/check_hpjd.c index 5fdfc8a..7c56e5d 100644 --- a/plugins/check_hpjd.c +++ b/plugins/check_hpjd.c @@ -85,7 +85,7 @@ main (int argc, char **argv) textdomain (PACKAGE); if (process_arguments (argc, argv) != TRUE) - usage (_("check_hpjd: could not parse arguments\n")); + usage4 (_("Could not parse arguments\n")); /* removed ' 2>1' at end of command 10/27/1999 - EG */ /* create the query string */ diff --git a/plugins/check_http.c b/plugins/check_http.c index e962e02..93bff45 100644 --- a/plugins/check_http.c +++ b/plugins/check_http.c @@ -146,7 +146,7 @@ main (int argc, char **argv) clean_revstring (revision), VERSION); if (process_arguments (argc, argv) != TRUE) - usage (_("check_http: could not parse arguments\n")); + usage4 (_("Could not parse arguments")); if (strstr (timestamp, ":")) { if (strstr (server_url, "?")) diff --git a/plugins/check_ldap.c b/plugins/check_ldap.c index 07b89ac..9c41cc3 100644 --- a/plugins/check_ldap.c +++ b/plugins/check_ldap.c @@ -73,7 +73,7 @@ main (int argc, char *argv[]) textdomain (PACKAGE); if (process_arguments (argc, argv) != TRUE) - usage (_("check_ldap: could not parse arguments\n")); + usage4 (_("Could not parse arguments")); /* initialize alarm signal handling */ signal (SIGALRM, socket_timeout_alarm_handler); diff --git a/plugins/check_load.c b/plugins/check_load.c index 8322dbb..b918fa5 100644 --- a/plugins/check_load.c +++ b/plugins/check_load.c @@ -74,7 +74,7 @@ main (int argc, char **argv) textdomain (PACKAGE); if (process_arguments (argc, argv) != TRUE) - usage (_("check_load: could not parse arguments\n")); + usage4 (_("Could not parse arguments")); #if HAVE_GETLOADAVG==1 result = getloadavg (la, 3); diff --git a/plugins/check_mrtg.c b/plugins/check_mrtg.c index 58717bf..31d132d 100644 --- a/plugins/check_mrtg.c +++ b/plugins/check_mrtg.c @@ -60,7 +60,7 @@ main (int argc, char **argv) textdomain (PACKAGE); if (process_arguments (argc, argv) != TRUE) - usage (_("check_mrtg: could not parse arguments\n")); + usage4 (_("Could not parse arguments\n")); /* open the MRTG log file for reading */ fp = fopen (log_file, "r"); diff --git a/plugins/check_mrtgtraf.c b/plugins/check_mrtgtraf.c index 5bbce50..24ccaa9 100644 --- a/plugins/check_mrtgtraf.c +++ b/plugins/check_mrtgtraf.c @@ -63,12 +63,12 @@ main (int argc, char **argv) char outgoing_speed_rating[8]; if (process_arguments (argc, argv) != TRUE) - usage (_("check_ldap: could not parse arguments\n")); + usage4 (_("Could not parse arguments")); /* open the MRTG log file for reading */ fp = fopen (log_file, "r"); if (fp == NULL) - usage (_("Unable to open MRTG log file\n")); + usage4 (_("Unable to open MRTG log file")); line = 0; while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, fp)) { @@ -110,7 +110,7 @@ main (int argc, char **argv) /* if we couldn't read enough data, return an unknown error */ if (line <= 2) - usage (_("Unable to process MRTG log file\n")); + usage4 (_("Unable to process MRTG log file")); /* make sure the MRTG data isn't too old */ time (¤t_time); diff --git a/plugins/check_mysql.c b/plugins/check_mysql.c index 0564f7c..f55630b 100644 --- a/plugins/check_mysql.c +++ b/plugins/check_mysql.c @@ -56,7 +56,7 @@ main (int argc, char **argv) textdomain (PACKAGE); if (process_arguments (argc, argv) != TRUE) - usage (_("check_mysql: could not parse arguments\n")); + usage4 (_("Could not parse arguments")); /* initialize mysql */ mysql_init (&mysql); diff --git a/plugins/check_nagios.c b/plugins/check_nagios.c index 7c36d11..618ee57 100644 --- a/plugins/check_nagios.c +++ b/plugins/check_nagios.c @@ -66,12 +66,11 @@ main (int argc, char **argv) textdomain (PACKAGE); if (process_arguments (argc, argv) != TRUE) - usage (_("check_nagios: could not parse arguments\n")); + usage4 (_("Could not parse arguments")); - /* Set signal handling and alarm */ + /* Set signal handling and alarm timeout */ if (signal (SIGALRM, timeout_alarm_handler) == SIG_ERR) { - printf (_("Cannot catch SIGALRM")); - return STATE_UNKNOWN; + usage4 (_("Cannot catch SIGALRM")); } /* handle timeouts gracefully... */ diff --git a/plugins/check_nt.c b/plugins/check_nt.c index c7fc745..efd7cde 100644 --- a/plugins/check_nt.c +++ b/plugins/check_nt.c @@ -111,7 +111,7 @@ int main(int argc, char **argv){ textdomain (PACKAGE); if(process_arguments(argc,argv) != TRUE) - usage (_("check_nt: could not parse arguments\n")); + usage4 (_("Could not parse arguments")); /* initialize alarm signal handling */ signal(SIGALRM,socket_timeout_alarm_handler); diff --git a/plugins/check_nwstat.c b/plugins/check_nwstat.c index a6d2e24..ce5773b 100644 --- a/plugins/check_nwstat.c +++ b/plugins/check_nwstat.c @@ -122,7 +122,7 @@ main(int argc, char **argv) { textdomain (PACKAGE); if (process_arguments(argc,argv) != TRUE) - usage (_("check_nwstat: could not parse arguments\n")); + usage4 (_("Could not parse arguments")); /* initialize alarm signal handling */ signal(SIGALRM,socket_timeout_alarm_handler); diff --git a/plugins/check_overcr.c b/plugins/check_overcr.c index cb85dc6..22277f6 100644 --- a/plugins/check_overcr.c +++ b/plugins/check_overcr.c @@ -86,7 +86,7 @@ main (int argc, char **argv) textdomain (PACKAGE); if (process_arguments (argc, argv) != TRUE) - usage (_("check_overcr: could not parse arguments\n")); + usage4 (_("Could not parse arguments")); /* initialize alarm signal handling */ signal (SIGALRM, socket_timeout_alarm_handler); diff --git a/plugins/check_pgsql.c b/plugins/check_pgsql.c index 5c3b810..f9d6611 100644 --- a/plugins/check_pgsql.c +++ b/plugins/check_pgsql.c @@ -133,12 +133,11 @@ main (int argc, char **argv) textdomain (PACKAGE); if (process_arguments (argc, argv) != TRUE) - usage (_("check_pgsql: could not parse arguments\n")); + usage4 (_("Could not parse arguments")); /* Set signal handling and alarm */ if (signal (SIGALRM, timeout_alarm_handler) == SIG_ERR) { - printf (_("Cannot catch SIGALRM")); - return STATE_UNKNOWN; + usage4 (_("Cannot catch SIGALRM")); } alarm (timeout_interval); diff --git a/plugins/check_ping.c b/plugins/check_ping.c index 6d8ef06..ecaf03e 100644 --- a/plugins/check_ping.c +++ b/plugins/check_ping.c @@ -79,12 +79,11 @@ main (int argc, char **argv) addresses[0] = NULL; if (process_arguments (argc, argv) != TRUE) - usage (_("check_ping: could not parse arguments\n")); + usage4 (_("Could not parse arguments")); /* Set signal handling and alarm */ if (signal (SIGALRM, popen_timeout_alarm_handler) == SIG_ERR) { - printf (_("Cannot catch SIGALRM")); - return STATE_UNKNOWN; + usage4 (_("Cannot catch SIGALRM")); } /* handle timeouts gracefully */ diff --git a/plugins/check_procs.c b/plugins/check_procs.c index d1e1b7c..4bc87c0 100644 --- a/plugins/check_procs.c +++ b/plugins/check_procs.c @@ -116,12 +116,11 @@ main (int argc, char **argv) metric = METRIC_PROCS; if (process_arguments (argc, argv) != TRUE) - usage (_("check_procs: could not parse arguments\n")); + usage4 (_("Could not parse arguments")); /* Set signal handling and alarm timeout */ if (signal (SIGALRM, popen_timeout_alarm_handler) == SIG_ERR) { - printf (_("Cannot catch SIGALRM")); - return STATE_UNKNOWN; + usage4 (_("Cannot catch SIGALRM")); } alarm (timeout_interval); diff --git a/plugins/check_radius.c b/plugins/check_radius.c index 405b417..68ed4d8 100644 --- a/plugins/check_radius.c +++ b/plugins/check_radius.c @@ -113,7 +113,7 @@ main (int argc, char **argv) textdomain (PACKAGE); if (process_arguments (argc, argv) != TRUE) - usage (_("check_radius: could not parse arguments\n")); + usage4 (_("Could not parse arguments")); str = strdup ("dictionary"); if ((config_file && rc_read_config (config_file)) || diff --git a/plugins/check_real.c b/plugins/check_real.c index 9a8f42a..4ede6a5 100644 --- a/plugins/check_real.c +++ b/plugins/check_real.c @@ -65,7 +65,7 @@ main (int argc, char **argv) textdomain (PACKAGE); if (process_arguments (argc, argv) != TRUE) - usage (_("check_real: could not parse arguments\n")); + usage4 (_("Could not parse arguments")); /* initialize alarm signal handling */ signal (SIGALRM, socket_timeout_alarm_handler); diff --git a/plugins/check_smtp.c b/plugins/check_smtp.c index 3322494..257a38b 100644 --- a/plugins/check_smtp.c +++ b/plugins/check_smtp.c @@ -89,7 +89,7 @@ main (int argc, char **argv) textdomain (PACKAGE); if (process_arguments (argc, argv) != TRUE) - usage (_("check_smtp: could not parse arguments\n")); + usage4 (_("Could not parse arguments")); /* initialize the HELO command with the localhostname */ #ifndef HOST_MAX_BYTES diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c index c7dff3d..6a41c6a 100644 --- a/plugins/check_snmp.c +++ b/plugins/check_snmp.c @@ -157,7 +157,7 @@ main (int argc, char **argv) miblist = strdup (DEFAULT_MIBLIST); if (process_arguments (argc, argv) != TRUE) - usage (_("check_snmp: could not parse arguments\n")); + usage4 (_("Could not parse arguments")); /* create the command line to execute */ asprintf (&command_line, "%s -t 1 -r %d -m %s -v %s %s %s:%s %s", diff --git a/plugins/check_ssh.c b/plugins/check_ssh.c index f9bbd12..82d0aca 100644 --- a/plugins/check_ssh.c +++ b/plugins/check_ssh.c @@ -58,7 +58,7 @@ main (int argc, char **argv) textdomain (PACKAGE); if (process_arguments (argc, argv) != TRUE) - usage (_("check_ssh: could not parse arguments\n")); + usage4 (_("Could not parse arguments")); /* initialize alarm signal handling */ signal (SIGALRM, socket_timeout_alarm_handler); diff --git a/plugins/check_swap.c b/plugins/check_swap.c index f2d722c..608080a 100644 --- a/plugins/check_swap.c +++ b/plugins/check_swap.c @@ -90,7 +90,7 @@ main (int argc, char **argv) perf = strdup (""); if (process_arguments (argc, argv) != TRUE) - usage (_("Incorrect arguments supplied\n")); + usage4 (_("Could not parse arguments")); #ifdef HAVE_PROC_MEMINFO fp = fopen (PROC_MEMINFO, "r"); diff --git a/plugins/check_tcp.c b/plugins/check_tcp.c index ed51e94..af3c720 100644 --- a/plugins/check_tcp.c +++ b/plugins/check_tcp.c @@ -240,7 +240,7 @@ main (int argc, char **argv) status = strdup (""); if (process_arguments (argc, argv) != TRUE) - usage (_("check_tcp: could not parse arguments\n")); + usage4 (_("Could not parse arguments")); /* use default expect if none listed in process_arguments() */ if (EXPECT && server_expect_count == 0) { @@ -265,7 +265,7 @@ main (int argc, char **argv) X509_free(server_cert); } else { - printf("CRITICAL Cannot retrieve server certificate.\n"); + printf("CRITICAL - Cannot retrieve server certificate.\n"); result = STATE_CRITICAL; } SSL_shutdown (ssl); diff --git a/plugins/check_time.c b/plugins/check_time.c index 042a7d5..ee6ff43 100644 --- a/plugins/check_time.c +++ b/plugins/check_time.c @@ -63,7 +63,7 @@ main (int argc, char **argv) textdomain (PACKAGE); if (process_arguments (argc, argv) != TRUE) - usage (_("check_time: could not parse arguments\n")); + usage4 (_("Could not parse arguments")); /* initialize alarm signal handling */ signal (SIGALRM, socket_timeout_alarm_handler); diff --git a/plugins/check_udp.c b/plugins/check_udp.c index fb7cae1..5d67174 100644 --- a/plugins/check_udp.c +++ b/plugins/check_udp.c @@ -52,7 +52,7 @@ main (int argc, char **argv) textdomain (PACKAGE); if (process_arguments (argc, argv) != TRUE) - usage (_("check_udp: could not parse arguments\n")); + usage4 (_("Could not parse arguments")); /* initialize alarm signal handling */ signal (SIGALRM, socket_timeout_alarm_handler); diff --git a/plugins/check_ups.c b/plugins/check_ups.c index 4006031..e974b75 100644 --- a/plugins/check_ups.c +++ b/plugins/check_ups.c @@ -112,7 +112,7 @@ main (int argc, char **argv) message = strdup (""); if (process_arguments (argc, argv) != TRUE) - usage (_("check_ups: could not parse arguments\n")); + usage4 (_("Could not parse arguments")); /* initialize alarm signal handling */ signal (SIGALRM, socket_timeout_alarm_handler); diff --git a/plugins/check_users.c b/plugins/check_users.c index 23f8973..891fe3b 100644 --- a/plugins/check_users.c +++ b/plugins/check_users.c @@ -51,7 +51,7 @@ main (int argc, char **argv) perf = strdup(""); if (process_arguments (argc, argv) != TRUE) - usage (_("check_users: could not parse arguments\n")); + usage4 (_("Could not parse arguments")); /* run the command */ child_process = spopen (WHO_COMMAND); diff --git a/plugins/negate.c b/plugins/negate.c index 02838a6..9e25ebc 100644 --- a/plugins/negate.c +++ b/plugins/negate.c @@ -84,7 +84,7 @@ main (int argc, char **argv) textdomain (PACKAGE); if (process_arguments (argc, argv) != TRUE) - usage (_("negate: could not parse arguments\n")); + usage4 (_("Could not parse arguments")); /* Set signal handling and alarm */ if (signal (SIGALRM, timeout_alarm_handler) == SIG_ERR) @@ -97,6 +97,7 @@ main (int argc, char **argv) die (STATE_UNKNOWN, _("Could not open pipe: %s\n"), command_line); child_stderr = fdopen (child_stderr_array[fileno (child_process)], "r"); + if (child_stderr == NULL) { printf (_("Could not open stderr for %s\n"), command_line); } diff --git a/plugins/popen.c b/plugins/popen.c index f05fe97..94ad583 100644 --- a/plugins/popen.c +++ b/plugins/popen.c @@ -112,6 +112,7 @@ spopen (const char *cmdstring) /* there cannot be more args than characters */ argc = strlen (cmdstring) + 1; /* add 1 for NULL termination */ argv = malloc (sizeof(char*)*argc); + if (argv == NULL) { printf ("Could not malloc argv array in popen()\n"); return NULL; diff --git a/plugins/utils.c b/plugins/utils.c index 460ff82..1d7c0db 100644 --- a/plugins/utils.c +++ b/plugins/utils.c @@ -73,6 +73,13 @@ usage3 (const char *msg, int arg) exit (STATE_UNKNOWN); } +void +usage4 (const char *msg) +{ + printf ("%s: %s\n", progname, msg); + print_usage(); + exit (STATE_UNKNOWN); +} void support (void) -- 2.30.2