X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=plugins%2Fcheck_dig.c;h=5c6f1e12e8bdb45985d0ac535d8c79bdcab1de42;hb=7ceff0d5a95f5c5f34235ef6682595f169864d2f;hp=ba41ebda361eab74d6836b1ff332ed0a2e637bf6;hpb=9728dcad931d1c442a6d8e3e6765e2d9870600d1;p=nagiosplug.git diff --git a/plugins/check_dig.c b/plugins/check_dig.c index ba41ebd..5c6f1e1 100644 --- a/plugins/check_dig.c +++ b/plugins/check_dig.c @@ -25,7 +25,7 @@ #include "utils.h" #include "popen.h" -#define PROGNAME "check_dig" +const char *progname = "check_dig"; #define REVISION "$Revision$" #define COPYRIGHT "2000-2002" #define AUTHOR "Karl DeBisschop" @@ -46,7 +46,7 @@ main (int argc, char **argv) { char input_buffer[MAX_INPUT_BUFFER]; char *command_line = NULL; - char *output = NULL; + char *output = ""; int result = STATE_UNKNOWN; /* Set signal handling and alarm */ @@ -75,8 +75,6 @@ main (int argc, char **argv) if (child_stderr == NULL) printf ("Could not open stderr for %s\n", command_line); - output = strscpy (output, ""); - while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process)) { /* the server is responding, we just got the host name... */ @@ -90,11 +88,11 @@ main (int argc, char **argv) input_buffer[strcspn (input_buffer, "\r\n")] = '\0'; if (strstr (input_buffer, query_address) == input_buffer) { - output = strscpy (output, input_buffer); + asprintf (&output, input_buffer); result = STATE_OK; } else { - strcpy (output, "Server not found in ANSWER SECTION"); + asprintf (&output, "Server not found in ANSWER SECTION"); result = STATE_WARNING; } @@ -104,15 +102,15 @@ main (int argc, char **argv) } if (result != STATE_OK) { - strcpy (output, "No ANSWER SECTION found"); + asprintf (&output, "No ANSWER SECTION found"); } while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr)) { /* If we get anything on STDERR, at least set warning */ result = max_state (result, STATE_WARNING); printf ("%s", input_buffer); - if (!strcmp (output, "")) - strcpy (output, 1 + index (input_buffer, ':')); + if (strlen (output) == 0) + asprintf (&output, 1 + index (input_buffer, ':')); } (void) fclose (child_stderr); @@ -120,27 +118,24 @@ main (int argc, char **argv) /* close the pipe */ if (spclose (child_process)) { result = max_state (result, STATE_WARNING); - if (!strcmp (output, "")) - strcpy (output, "nslookup returned error status"); + if (strlen (output) == 0) + asprintf (&output, "dig returned error status"); } (void) time (&end_time); + if (output == NULL || strlen (output) == 0) + asprintf (&output, " Probably a non-existent host/domain"); + if (result == STATE_OK) 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", - !strcmp (output, - "") ? " Probably a non-existent host/domain" : output); + printf ("DNS WARNING - %s\n", output); else if (result == STATE_CRITICAL) - printf ("DNS CRITICAL - %s\n", - !strcmp (output, - "") ? " Probably a non-existent host/domain" : output); + printf ("DNS CRITICAL - %s\n", output); else - printf ("DNS problem - %s\n", - !strcmp (output, - "") ? " Probably a non-existent host/domain" : output); + printf ("DNS problem - %s\n", output); return result; } @@ -202,7 +197,7 @@ process_arguments (int argc, char **argv) } break; case 'V': /* version */ - print_revision (PROGNAME, "$Revision$"); + print_revision (progname, "$Revision$"); exit (STATE_OK); case 'h': /* help */ print_help (); @@ -221,7 +216,7 @@ process_arguments (int argc, char **argv) } } else { - dns_server = strscpy (NULL, "127.0.0.1"); + asprintf (&dns_server, "127.0.0.1"); } } @@ -245,7 +240,7 @@ validate_arguments (void) void print_help (void) { - print_revision (PROGNAME, "$Revision$"); + print_revision (progname, "$Revision$"); printf ("Copyright (c) %s %s <%s>\n\n%s\n", COPYRIGHT, AUTHOR, EMAIL, SUMMARY); @@ -277,5 +272,5 @@ print_usage (void) printf ("Usage: %s -H host -l lookup [-t timeout] [-v]\n" " %s --help\n" - " %s --version\n", PROGNAME, PROGNAME, PROGNAME); + " %s --version\n", progname, progname, progname); }