summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 6c9be74)
raw | patch | inline | side by side (parent: 6c9be74)
author | Ton Voon <tonvoon@users.sourceforge.net> | |
Wed, 18 Feb 2004 02:09:50 +0000 (02:09 +0000) | ||
committer | Ton Voon <tonvoon@users.sourceforge.net> | |
Wed, 18 Feb 2004 02:09:50 +0000 (02:09 +0000) |
Also cleanup of comments and handles multi-line nslookup output (MacOSX 10.3)
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@803 f882894a-f735-0410-b71e-b25c423dba1c
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@803 f882894a-f735-0410-b71e-b25c423dba1c
plugins/check_dns.c | patch | blob | history |
diff --git a/plugins/check_dns.c b/plugins/check_dns.c
index 309c65b7ca04344f6601c3e3d9c552f809e00d8e..1fc4039fe590e849c7cb9e0f3d3ce60c0b3e2f18 100644 (file)
--- a/plugins/check_dns.c
+++ b/plugins/check_dns.c
/******************************************************************************
- *
- * CHECK_DNS.C
- *
- * Program: DNS plugin for Nagios
- * License: GPL
- * Copyright (c) 1999 Ethan Galstad (nagios@nagios.org)
- *
- * Last Modified: $Date$
- *
- * Notes:
- * - Safe popen added by Karl DeBisschop 9-11-99
- * - expected-address parameter added by Alex Chaffee - 7 Oct 2002
- *
- * Command line: (see print_usage)
- *
- * Description:
- *
- * This program will use the nslookup program to obtain the IP address
- * for a given host name. A optional DNS server may be specified. If
- * no DNS server is specified, the default server(s) for the system
- * are used.
- *
- * Return Values:
- * OK The DNS query was successful (host IP address was returned).
- * WARNING The DNS server responded, but could not fulfill the request.
- * CRITICAL The DNS server is not responding or encountered an error.
- *
- * License Information:
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- *****************************************************************************/
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+******************************************************************************/
#include "common.h"
#include "popen.h"
const char *progname = "check_dns";
const char *revision = "$Revision$";
-const char *copyright = "2000-2003";
+const char *copyright = "2000-2004";
const char *email = "nagiosplug-devel@lists.sourceforge.net";
int process_arguments (int, char **);
long microsec;
struct timeval tv;
int multi_address;
+ int parse_address = FALSE; /* This flag scans for Address: but only after Name: */
setlocale (LC_ALL, "");
bindtextdomain (PACKAGE, LOCALEDIR);
if (verbose)
printf ("%s\n", command_line);
+
/* run the command */
child_process = spopen (command_line);
if (child_process == NULL) {
while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process)) {
if (verbose)
- printf ("%s\n", input_buffer);
+ printf ("%s", input_buffer);
if (strstr (input_buffer, ".in-addr.arpa")) {
if ((temp_buffer = strstr (input_buffer, "name = ")))
}
/* the server is responding, we just got the host name... */
- if (strstr (input_buffer, "Name:")) {
-
- /* get the host address */
- if (!fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process))
- break;
-
- if (verbose)
- printf ("%s\n", input_buffer);
-
- if ((temp_buffer = index (input_buffer, ':'))) {
- temp_buffer++;
- /* Strip leading spaces */
- for (; *temp_buffer != '\0' && *temp_buffer == ' '; temp_buffer++)
- /* NOOP */;
- address = strdup (temp_buffer);
- strip (address);
- if (address==NULL || strlen(address)==0)
- die (STATE_CRITICAL,
- _("DNS CRITICAL - '%s' returned empty host name string\n"),
+ if (strstr (input_buffer, "Name:"))
+ parse_address = TRUE;
+ else if (strstr (input_buffer, "Address:") && parse_address == TRUE) {
+ temp_buffer = index (input_buffer, ':');
+ temp_buffer++;
+
+ /* Strip leading spaces */
+ for (; *temp_buffer != '\0' && *temp_buffer == ' '; temp_buffer++)
+ /* NOOP */;
+
+ strip(temp_buffer);
+ if (temp_buffer==NULL || strlen(temp_buffer)==0) {
+ die (STATE_CRITICAL, _("DNS CRITICAL - '%s' returned empty host name string\n"),
NSLOOKUP_COMMAND);
- result = STATE_OK;
- }
- else {
- output = strdup (_("Unknown error (plugin)"));
- result = STATE_WARNING;
}
- break;
+ if (address == NULL)
+ address = strdup (temp_buffer);
+ else
+ asprintf(&address, "%s,%s", address, temp_buffer);
}
result = error_scan (input_buffer);
else
multi_address = TRUE;
- printf (_("DNS ok - %.3f seconds response time, address%s %s|%s\n"),
- elapsed_time, (multi_address==TRUE ? "es are" : " is"), address,
- perfdata ("time", microsec, "us", FALSE, 0, FALSE, 0, TRUE, 0, FALSE, 0));
+ printf ("%s %s: ", _("DNS"), _("OK"));
+ printf (ngettext("%.3f second response time, ", "%.3f seconds response time, ", elapsed_time), elapsed_time);
+ printf (_("%s returns %s"), query_address, address);
+ printf ("|%s\n", perfdata ("time", microsec, "us", FALSE, 0, FALSE, 0, TRUE, 0, FALSE, 0));
}
else if (result == STATE_WARNING)
printf (_("DNS WARNING - %s\n"),