summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/check_dns.c115
1 files changed, 41 insertions, 74 deletions
diff --git a/plugins/check_dns.c b/plugins/check_dns.c
index 309c65b..1fc4039 100644
--- a/plugins/check_dns.c
+++ b/plugins/check_dns.c
@@ -1,48 +1,20 @@
1/****************************************************************************** 1/******************************************************************************
2 * 2
3 * CHECK_DNS.C 3 This program is free software; you can redistribute it and/or modify
4 * 4 it under the terms of the GNU General Public License as published by
5 * Program: DNS plugin for Nagios 5 the Free Software Foundation; either version 2 of the License, or
6 * License: GPL 6 (at your option) any later version.
7 * Copyright (c) 1999 Ethan Galstad (nagios@nagios.org) 7
8 * 8 This program is distributed in the hope that it will be useful,
9 * Last Modified: $Date$ 9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * 10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * Notes: 11 GNU General Public License for more details.
12 * - Safe popen added by Karl DeBisschop 9-11-99 12
13 * - expected-address parameter added by Alex Chaffee - 7 Oct 2002 13 You should have received a copy of the GNU General Public License
14 * 14 along with this program; if not, write to the Free Software
15 * Command line: (see print_usage) 15 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
16 * 16
17 * Description: 17******************************************************************************/
18 *
19 * This program will use the nslookup program to obtain the IP address
20 * for a given host name. A optional DNS server may be specified. If
21 * no DNS server is specified, the default server(s) for the system
22 * are used.
23 *
24 * Return Values:
25 * OK The DNS query was successful (host IP address was returned).
26 * WARNING The DNS server responded, but could not fulfill the request.
27 * CRITICAL The DNS server is not responding or encountered an error.
28 *
29 * License Information:
30 *
31 * This program is free software; you can redistribute it and/or modify
32 * it under the terms of the GNU General Public License as published by
33 * the Free Software Foundation; either version 2 of the License, or
34 * (at your option) any later version.
35 *
36 * This program is distributed in the hope that it will be useful,
37 * but WITHOUT ANY WARRANTY; without even the implied warranty of
38 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
39 * GNU General Public License for more details.
40 *
41 * You should have received a copy of the GNU General Public License
42 * along with this program; if not, write to the Free Software
43 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
44 *
45 *****************************************************************************/
46 18
47#include "common.h" 19#include "common.h"
48#include "popen.h" 20#include "popen.h"
@@ -51,7 +23,7 @@
51 23
52const char *progname = "check_dns"; 24const char *progname = "check_dns";
53const char *revision = "$Revision$"; 25const char *revision = "$Revision$";
54const char *copyright = "2000-2003"; 26const char *copyright = "2000-2004";
55const char *email = "nagiosplug-devel@lists.sourceforge.net"; 27const char *email = "nagiosplug-devel@lists.sourceforge.net";
56 28
57int process_arguments (int, char **); 29int process_arguments (int, char **);
@@ -81,6 +53,7 @@ main (int argc, char **argv)
81 long microsec; 53 long microsec;
82 struct timeval tv; 54 struct timeval tv;
83 int multi_address; 55 int multi_address;
56 int parse_address = FALSE; /* This flag scans for Address: but only after Name: */
84 57
85 setlocale (LC_ALL, ""); 58 setlocale (LC_ALL, "");
86 bindtextdomain (PACKAGE, LOCALEDIR); 59 bindtextdomain (PACKAGE, LOCALEDIR);
@@ -105,6 +78,7 @@ main (int argc, char **argv)
105 78
106 if (verbose) 79 if (verbose)
107 printf ("%s\n", command_line); 80 printf ("%s\n", command_line);
81
108 /* run the command */ 82 /* run the command */
109 child_process = spopen (command_line); 83 child_process = spopen (command_line);
110 if (child_process == NULL) { 84 if (child_process == NULL) {
@@ -120,7 +94,7 @@ main (int argc, char **argv)
120 while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process)) { 94 while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process)) {
121 95
122 if (verbose) 96 if (verbose)
123 printf ("%s\n", input_buffer); 97 printf ("%s", input_buffer);
124 98
125 if (strstr (input_buffer, ".in-addr.arpa")) { 99 if (strstr (input_buffer, ".in-addr.arpa")) {
126 if ((temp_buffer = strstr (input_buffer, "name = "))) 100 if ((temp_buffer = strstr (input_buffer, "name = ")))
@@ -132,34 +106,26 @@ main (int argc, char **argv)
132 } 106 }
133 107
134 /* the server is responding, we just got the host name... */ 108 /* the server is responding, we just got the host name... */
135 if (strstr (input_buffer, "Name:")) { 109 if (strstr (input_buffer, "Name:"))
136 110 parse_address = TRUE;
137 /* get the host address */ 111 else if (strstr (input_buffer, "Address:") && parse_address == TRUE) {
138 if (!fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process)) 112 temp_buffer = index (input_buffer, ':');
139 break; 113 temp_buffer++;
140 114
141 if (verbose) 115 /* Strip leading spaces */
142 printf ("%s\n", input_buffer); 116 for (; *temp_buffer != '\0' && *temp_buffer == ' '; temp_buffer++)
143 117 /* NOOP */;
144 if ((temp_buffer = index (input_buffer, ':'))) { 118
145 temp_buffer++; 119 strip(temp_buffer);
146 /* Strip leading spaces */ 120 if (temp_buffer==NULL || strlen(temp_buffer)==0) {
147 for (; *temp_buffer != '\0' && *temp_buffer == ' '; temp_buffer++) 121 die (STATE_CRITICAL, _("DNS CRITICAL - '%s' returned empty host name string\n"),
148 /* NOOP */;
149 address = strdup (temp_buffer);
150 strip (address);
151 if (address==NULL || strlen(address)==0)
152 die (STATE_CRITICAL,
153 _("DNS CRITICAL - '%s' returned empty host name string\n"),
154 NSLOOKUP_COMMAND); 122 NSLOOKUP_COMMAND);
155 result = STATE_OK;
156 }
157 else {
158 output = strdup (_("Unknown error (plugin)"));
159 result = STATE_WARNING;
160 } 123 }
161 124
162 break; 125 if (address == NULL)
126 address = strdup (temp_buffer);
127 else
128 asprintf(&address, "%s,%s", address, temp_buffer);
163 } 129 }
164 130
165 result = error_scan (input_buffer); 131 result = error_scan (input_buffer);
@@ -212,9 +178,10 @@ main (int argc, char **argv)
212 else 178 else
213 multi_address = TRUE; 179 multi_address = TRUE;
214 180
215 printf (_("DNS ok - %.3f seconds response time, address%s %s|%s\n"), 181 printf ("%s %s: ", _("DNS"), _("OK"));
216 elapsed_time, (multi_address==TRUE ? "es are" : " is"), address, 182 printf (ngettext("%.3f second response time, ", "%.3f seconds response time, ", elapsed_time), elapsed_time);
217 perfdata ("time", microsec, "us", FALSE, 0, FALSE, 0, TRUE, 0, FALSE, 0)); 183 printf (_("%s returns %s"), query_address, address);
184 printf ("|%s\n", perfdata ("time", microsec, "us", FALSE, 0, FALSE, 0, TRUE, 0, FALSE, 0));
218 } 185 }
219 else if (result == STATE_WARNING) 186 else if (result == STATE_WARNING)
220 printf (_("DNS WARNING - %s\n"), 187 printf (_("DNS WARNING - %s\n"),