diff --git a/plugins/check_dns.c b/plugins/check_dns.c
index 39023f950b45e8db31d9c6b41a5925417d1d7b4e..94d4300c85e5f54c004120549a62b3f21562813f 100644 (file)
--- a/plugins/check_dns.c
+++ b/plugins/check_dns.c
LIMITATION: nslookup on Solaris 7 can return output over 2 lines, which will not
be picked up by this plugin
LIMITATION: nslookup on Solaris 7 can return output over 2 lines, which will not
be picked up by this plugin
+
+ $Id$
******************************************************************************/
******************************************************************************/
-#include "common.h"
-#include "popen.h"
-#include "utils.h"
-#include "netutils.h"
-
const char *progname = "check_dns";
const char *revision = "$Revision$";
const char *copyright = "2000-2004";
const char *email = "nagiosplug-devel@lists.sourceforge.net";
const char *progname = "check_dns";
const char *revision = "$Revision$";
const char *copyright = "2000-2004";
const char *email = "nagiosplug-devel@lists.sourceforge.net";
+#include "common.h"
+#include "popen.h"
+#include "utils.h"
+#include "netutils.h"
+
int process_arguments (int, char **);
int validate_arguments (void);
int error_scan (char *);
int process_arguments (int, char **);
int validate_arguments (void);
int error_scan (char *);
/* Set signal handling and alarm */
if (signal (SIGALRM, popen_timeout_alarm_handler) == SIG_ERR) {
/* 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) != OK) {
- print_usage ();
- return STATE_UNKNOWN;
+ if (process_arguments (argc, argv) == ERROR) {
+ usage4 (_("Could not parse arguments"));
}
/* get the command to run */
}
/* get the command to run */
if ((temp_buffer = strstr (input_buffer, "name = ")))
address = strdup (temp_buffer + 7);
else {
if ((temp_buffer = strstr (input_buffer, "name = ")))
address = strdup (temp_buffer + 7);
else {
- output = strdup (_("Unknown error (plugin)"));
+ output = strdup (_("Warning plugin error"));
result = STATE_WARNING;
}
}
result = STATE_WARNING;
}
}
asprintf(&address, "%s,%s", address, temp_buffer);
}
asprintf(&address, "%s,%s", address, temp_buffer);
}
- else if (strstr (input_buffer, "Non-authoritative answer:")) {
+ else if (strstr (input_buffer, _("Non-authoritative answer:"))) {
non_authoritative = TRUE;
}
non_authoritative = TRUE;
}
/* scan stderr */
while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr)) {
/* scan stderr */
while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr)) {
+
+ if (verbose)
+ printf ("%s", input_buffer);
+
if (error_scan (input_buffer) != STATE_OK) {
result = max_state (result, error_scan (input_buffer));
output = strdup (1 + index (input_buffer, ':'));
if (error_scan (input_buffer) != STATE_OK) {
result = max_state (result, error_scan (input_buffer));
output = strdup (1 + index (input_buffer, ':'));
/* close stdout */
if (spclose (child_process)) {
result = max_state (result, STATE_WARNING);
/* close stdout */
if (spclose (child_process)) {
result = max_state (result, STATE_WARNING);
- if (!strcmp (output, ""))
+ if (output == NULL || !strcmp (output, ""))
output = strdup (_("nslookup returned error status"));
}
output = strdup (_("nslookup returned error status"));
}
multi_address = TRUE;
printf ("DNS %s: ", _("OK"));
multi_address = TRUE;
printf ("DNS %s: ", _("OK"));
- printf (ngettext("%.3f second response time, ", "%.3f seconds response time, ", elapsed_time), elapsed_time);
+ printf (ngettext("%.3f second response time ", "%.3f seconds response time ", elapsed_time), elapsed_time);
printf (_("%s returns %s"), query_address, address);
printf ("|%s\n", fperfdata ("time", elapsed_time, "s", FALSE, 0, FALSE, 0, TRUE, 0, FALSE, 0));
}
printf (_("%s returns %s"), query_address, address);
printf ("|%s\n", fperfdata ("time", elapsed_time, "s", FALSE, 0, FALSE, 0, TRUE, 0, FALSE, 0));
}
printf (_("DNS CRITICAL - %s\n"),
!strcmp (output, "") ? _(" Probably a non-existent host/domain") : output);
else
printf (_("DNS CRITICAL - %s\n"),
!strcmp (output, "") ? _(" Probably a non-existent host/domain") : output);
else
- printf (_("DNS problem - %s\n"),
+ printf (_("DNS UNKNOW - %s\n"),
!strcmp (output, "") ? _(" Probably a non-existent host/domain") : output);
return result;
}
!strcmp (output, "") ? _(" Probably a non-existent host/domain") : output);
return result;
}
+
+
int
error_scan (char *input_buffer)
{
/* the DNS lookup timed out */
int
error_scan (char *input_buffer)
{
/* the DNS lookup timed out */
- if (strstr (input_buffer, "Note: nslookup is deprecated and may be removed from future releases.") ||
- strstr (input_buffer, "Consider using the `dig' or `host' programs instead. Run nslookup with") ||
- strstr (input_buffer, "the `-sil[ent]' option to prevent this message from appearing."))
+ if (strstr (input_buffer, _("Note: nslookup is deprecated and may be removed from future releases.")) ||
+ strstr (input_buffer, _("Consider using the `dig' or `host' programs instead. Run nslookup with")) ||
+ strstr (input_buffer, _("the `-sil[ent]' option to prevent this message from appearing.")))
return STATE_OK;
/* DNS server is not running... */
return STATE_OK;
/* DNS server is not running... */
/* Connection was refused */
else if (strstr (input_buffer, "Connection refused") ||
/* Connection was refused */
else if (strstr (input_buffer, "Connection refused") ||
+ strstr (input_buffer, "Couldn't find server") ||
strstr (input_buffer, "Refused") ||
(strstr (input_buffer, "** server can't find") &&
strstr (input_buffer, ": REFUSED")))
die (STATE_CRITICAL, _("Connection to DNS %s was refused\n"), dns_server);
strstr (input_buffer, "Refused") ||
(strstr (input_buffer, "** server can't find") &&
strstr (input_buffer, ": REFUSED")))
die (STATE_CRITICAL, _("Connection to DNS %s was refused\n"), dns_server);
+ /* Query refused (usually by an ACL in the namserver) */
+ else if (strstr (input_buffer, "Query refused"))
+ die (STATE_CRITICAL, _("Query was refused by DNS server at %s\n"), dns_server);
+
+ /* No information (e.g. nameserver IP has two PTR records) */
+ else if (strstr (input_buffer, "No information"))
+ die (STATE_CRITICAL, _("No information returned by DNS server at %s\n"), dns_server);
+
/* Host or domain name does not exist */
else if (strstr (input_buffer, "Non-existent") ||
strstr (input_buffer, "** server can't find") ||
/* Host or domain name does not exist */
else if (strstr (input_buffer, "Non-existent") ||
strstr (input_buffer, "** server can't find") ||
- strstr (input_buffer,"NXDOMAIN"))
+ strstr (input_buffer,"NXDOMAIN"))
die (STATE_CRITICAL, _("Domain %s was not found by the server\n"), query_address);
/* Network is unreachable */
die (STATE_CRITICAL, _("Domain %s was not found by the server\n"), query_address);
/* Network is unreachable */
}
}
+
/* process command-line arguments */
int
process_arguments (int argc, char **argv)
/* process command-line arguments */
int
process_arguments (int argc, char **argv)
switch (c) {
case '?': /* args not parsable */
switch (c) {
case '?': /* args not parsable */
- printf (_("%s: Unknown argument: %s\n\n"), progname, optarg);
- print_usage ();
- exit (STATE_UNKNOWN);
+ usage2 (_("Unknown argument"), optarg);
case 'h': /* help */
print_help ();
exit (STATE_OK);
case 'h': /* help */
print_help ();
exit (STATE_OK);
/* TODO: this is_host check is probably unnecessary. */
/* Better to confirm nslookup response matches */
if (is_host (optarg) == FALSE) {
/* TODO: this is_host check is probably unnecessary. */
/* Better to confirm nslookup response matches */
if (is_host (optarg) == FALSE) {
- printf (_("Invalid server name/address\n\n"));
- print_usage ();
- exit (STATE_UNKNOWN);
+ usage2 (_("Invalid hostname/address"), optarg);
}
if (strlen (optarg) >= ADDRESS_LENGTH)
die (STATE_UNKNOWN, _("Input buffer overflow\n"));
}
if (strlen (optarg) >= ADDRESS_LENGTH)
die (STATE_UNKNOWN, _("Input buffer overflow\n"));
case 'r': /* reverse server name */
/* TODO: Is this is_host necessary? */
if (is_host (optarg) == FALSE) {
case 'r': /* reverse server name */
/* TODO: Is this is_host necessary? */
if (is_host (optarg) == FALSE) {
- printf (_("Invalid host name/address\n\n"));
- print_usage ();
- exit (STATE_UNKNOWN);
+ usage2 (_("Invalid hostname/address"), optarg);
}
if (strlen (optarg) >= ADDRESS_LENGTH)
die (STATE_UNKNOWN, _("Input buffer overflow\n"));
}
if (strlen (optarg) >= ADDRESS_LENGTH)
die (STATE_UNKNOWN, _("Input buffer overflow\n"));
if (strlen(dns_server)==0 && c<argc) {
/* TODO: See -s option */
if (is_host(argv[c]) == FALSE) {
if (strlen(dns_server)==0 && c<argc) {
/* TODO: See -s option */
if (is_host(argv[c]) == FALSE) {
- printf (_("Invalid name/address: %s\n\n"), argv[c]);
+ printf (_("Invalid hostname/address: %s\n\n"), argv[c]);
return ERROR;
}
if (strlen(argv[c]) >= ADDRESS_LENGTH)
return ERROR;
}
if (strlen(argv[c]) >= ADDRESS_LENGTH)
return validate_arguments ();
}
return validate_arguments ();
}
+
int
validate_arguments ()
{
int
validate_arguments ()
{
}
}
-
-
-
-\f
void
print_help (void)
{
print_revision (progname, revision);
void
print_help (void)
{
print_revision (progname, revision);
- printf (_("Copyright (c) 1999 Ethan Galstad <nagios@nagios.org>\n"));
- printf (_(COPYRIGHT), copyright, email);
+ printf ("Copyright (c) 1999 Ethan Galstad <nagios@nagios.org>\n");
+ printf (COPYRIGHT, copyright, email);
+
+ printf (_("\
+This plugin uses the nslookup program to obtain the IP address\n\
+for the given host/domain query. A optional DNS server to use may\n\
+be specified. If no DNS server is specified, the default server(s)\n\
+specified in /etc/resolv.conf will be used.\n\n"));
print_usage ();
print_usage ();
printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT);
printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT);
- printf (_("\n\
-This plugin uses the nslookup program to obtain the IP address\n\
-for the given host/domain query. A optional DNS server to use may\n\
-be specified. If no DNS server is specified, the default server(s)\n\
-specified in /etc/resolv.conf will be used.\n"));
-
printf (_(UT_SUPPORT));
}
printf (_(UT_SUPPORT));
}
-
-
void
print_usage (void)
{
void
print_usage (void)
{
- printf (_("\
-Usage: %s -H host [-s server] [-a expected-address] [-A] [-t timeout]\n\
- %s --help\n\
- %s --version\n"), progname, progname, progname);
+ printf ("\
+Usage: %s -H host [-s server] [-a expected-address] [-A] [-t timeout]\n", progname);
}
}