Code

Convert tabs to spaces from dig's answer section (Randy O'Meara - 1107651)
[nagiosplug.git] / plugins / check_dig.c
index 92a5eda89366d7e63b65a1b9472b150b2140cc85..4394490e8723ea0fe31c2a0a5d71ca1b0eb022b4 100644 (file)
  along with this program; if not, write to the Free Software
  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
+ $Id$
 *****************************************************************************/
 
+const char *progname = "check_dig";
+const char *revision = "$Revision$";
+const char *copyright = "2002-2004";
+const char *email = "nagiosplug-devel@lists.sourceforge.net";
+
 #include "common.h"
 #include "netutils.h"
 #include "utils.h"
@@ -26,11 +33,6 @@ 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 *email = "nagiosplug-devel@lists.sourceforge.net";
-
 enum {
        UNDEFINED = 0,
        DEFAULT_PORT = 53
@@ -52,6 +54,7 @@ main (int argc, char **argv)
        char input_buffer[MAX_INPUT_BUFFER];
        char *command_line;
        char *output;
+       char *t;
        long microsec;
        double elapsed_time;
        int result = STATE_UNKNOWN;
@@ -64,10 +67,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) != OK)
-               usage (_("Could not parse arguments\n"));
+       if (process_arguments (argc, argv) == ERROR)
+               usage4 (_("Could not parse arguments"));
 
        /* get the command to run */
        asprintf (&command_line, "%s @%s -p %d %s -t %s",
@@ -79,9 +82,9 @@ main (int argc, char **argv)
        if (verbose) {
                printf ("%s\n", command_line);
                if(expected_address != NULL) {
-                       printf ("Looking for: '%s'\n", expected_address);
+                       printf (_("Looking for: '%s'\n"), expected_address);
                } else {
-                       printf ("Looking for: '%s'\n", query_address);
+                       printf (_("Looking for: '%s'\n"), query_address);
                }
        }
 
@@ -122,13 +125,17 @@ main (int argc, char **argv)
                                        result = STATE_OK;
                                }
 
+                               /* Translate output TAB -> SPACE */
+                               t = output;
+                               while ((t = index(t, '\t')) != NULL) 
+                                       *t = ' ';
+
                        } while (!strstr (input_buffer, ";; "));
 
                        if (result == STATE_UNKNOWN) {
                                asprintf (&output, _("Server not found in ANSWER SECTION"));
                                result = STATE_WARNING;
                         }
-
                }
 
        }
@@ -151,7 +158,7 @@ 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 an error status"));
        }
 
        microsec = deltime (tv);
@@ -181,9 +188,6 @@ main (int argc, char **argv)
 
 
 
-
-
-\f
 /* process command-line arguments */
 int
 process_arguments (int argc, char **argv)
@@ -216,19 +220,19 @@ process_arguments (int argc, char **argv)
 
                switch (c) {
                case '?':                                                                       /* help */
-                       usage3 (_("Unknown argument"), optopt);
+                       usage2 (_("Unknown argument"), optarg);
                case 'h':                                                                       /* help */
                        print_help ();
                        exit (STATE_OK);
                case 'V':                                                                       /* version */
-                       print_revision (progname, "$Revision$");
+                       print_revision (progname, revision);
                        exit (STATE_OK);
                case 'H':                                                                       /* hostname */
                        if (is_host (optarg)) {
                                dns_server = optarg;
                        }
                        else {
-                               usage2 (_("Invalid host name"), optarg);
+                               usage2 (_("Invalid hostname/address"), optarg);
                        }
                        break;
                case 'p':                 /* server port */
@@ -236,7 +240,7 @@ process_arguments (int argc, char **argv)
                                server_port = atoi (optarg);
                        }
                        else {
-                               usage2 (_("Server port must be a nonnegative integer"), optarg);
+                               usage2 (_("Port must be a positive integer"), optarg);
                        }
                        break;
                case 'l':                                                                       /* address to lookup */
@@ -247,7 +251,7 @@ process_arguments (int argc, char **argv)
                                warning_interval = strtod (optarg, NULL);
                        }
                        else {
-                               usage2 (_("Warning interval must be a nonnegative integer"), optarg);
+                               usage2 (_("Warning interval must be a positive integer"), optarg);
                        }
                        break;
                case 'c':                                                                       /* critical */
@@ -255,7 +259,7 @@ process_arguments (int argc, char **argv)
                                critical_interval = strtod (optarg, NULL);
                        }
                        else {
-                               usage2 (_("Critical interval must be a nonnegative integer"), optarg);
+                               usage2 (_("Critical interval must be a positive integer"), optarg);
                        }
                        break;
                case 't':                                                                       /* timeout */
@@ -263,7 +267,7 @@ process_arguments (int argc, char **argv)
                                timeout_interval = atoi (optarg);
                        }
                        else {
-                               usage2 (_("Time interval must be a nonnegative integer"), optarg);
+                               usage2 (_("Timeout interval must be a positive integer"), optarg);
                        }
                        break;
                case 'v':                                                                       /* verbose */
@@ -285,7 +289,7 @@ process_arguments (int argc, char **argv)
                                dns_server = argv[c];
                        }
                        else {
-                               usage2 (_("Invalid host name"), argv[c]);
+                               usage2 (_("Invalid hostname/address"), argv[c]);
                        }
                }
                else {
@@ -298,8 +302,6 @@ process_arguments (int argc, char **argv)
 
 
 
-
-
 int
 validate_arguments (void)
 {
@@ -308,10 +310,6 @@ validate_arguments (void)
 
 
 
-
-
-
-\f
 void
 print_help (void)
 {
@@ -342,7 +340,7 @@ print_help (void)
 
         printf (_("\
  -a, --expected_address=STRING\n\
-   an address expected to be in the asnwer section.\n\
+   an address expected to be in the answer section.\n\
    if not set, uses whatever was in -l\n"));
 
        printf (_(UT_WARN_CRIT));
@@ -356,15 +354,11 @@ print_help (void)
 
 
 
-
 void
 print_usage (void)
 {
-       printf (_("\
+       printf ("\
 Usage: %s -H host -l lookup [-p <server port>] [-T <query type>]\n\
-         [-w <warning interval>] [-c <critical interval>] [-t <timeout>]\n\
-         [-a <expected answer address>] [-v]\n"),
-               progname);
-       printf ("       %s (-h|--help)\n", progname);
-       printf ("       %s (-V|--version)\n", progname);
+                  [-w <warning interval>] [-c <critical interval>] [-t <timeout>]\n\
+                  [-a <expected answer address>] [-v]\n", progname);
 }