summaryrefslogtreecommitdiffstats
path: root/plugins/check_dig.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/check_dig.c')
-rw-r--r--plugins/check_dig.c183
1 files changed, 105 insertions, 78 deletions
diff --git a/plugins/check_dig.c b/plugins/check_dig.c
index 6e040874..a22a68ac 100644
--- a/plugins/check_dig.c
+++ b/plugins/check_dig.c
@@ -16,45 +16,75 @@
16* 16*
17*****************************************************************************/ 17*****************************************************************************/
18 18
19#include "config.h"
20#include "common.h"
21#include "netutils.h"
22#include "utils.h"
23#include "popen.h"
24
25int process_arguments (int, char **);
26int validate_arguments (void);
27void print_help (void);
28void print_usage (void);
29
19const char *progname = "check_dig"; 30const char *progname = "check_dig";
20const char *revision = "$Revision$"; 31const char *revision = "$Revision$";
21const char *copyright = "2002-2003"; 32const char *copyright = "2002-2003";
22const char *authors = "Nagios Plugin Development Team";
23const char *email = "nagiosplug-devel@lists.sourceforge.net"; 33const char *email = "nagiosplug-devel@lists.sourceforge.net";
24 34
25const char *summary = "Test the DNS service on the specified host using dig\n"; 35enum {
36 DEFAULT_PORT = 53
37};
38
39void
40print_usage (void)
41{
42 printf (_("\
43Usage: %s -H host -l lookup [-p <server port>] [-w <warning interval>]\n\
44 [-c <critical interval>] [-t <timeout>] [-v]\n"),
45 progname);
46 printf (" %s (-h|--help)\n", progname);
47 printf (" %s (-V|--version)\n", progname);
48}
49
50void
51print_help (void)
52{
53 char *myport;
54
55 asprintf (&myport, "%d", DEFAULT_PORT);
56
57 print_revision (progname, revision);
26 58
27const char *option_summary = "-H host -l lookup [-t timeout] [-v]"; 59 printf (_(COPYRIGHT), copyright, email);
28 60
29const char *options = "\ 61 printf (_("Test the DNS service on the specified host using dig\n\n"));
30 -H, --hostname=STRING or IPADDRESS\n\ 62
31 Check server on the indicated host\n\ 63 print_usage ();
64
65 printf (_(HELP_VRSN));
66
67 printf (_(HOST_PORT), 'P', myport);
68
69 printf (_("\
32 -l, --lookup=STRING\n\ 70 -l, --lookup=STRING\n\
33 machine name to lookup\n\ 71 machine name to lookup\n"));
34 -t, --timeout=INTEGER\n\
35 Seconds before connection attempt times out (default: %d)\n\
36 -v, --verbose\n\
37 Print extra information (command-line use only)\n";
38
39const char *standard_options = "\
40 -h, --help\n\
41 Print detailed help screen\n\
42 -V, --version\n\
43 Print version information\n\n";
44 72
45#include "config.h" 73 printf (_(WARN_CRIT_TO), DEFAULT_SOCKET_TIMEOUT);
46#include "common.h"
47#include "utils.h"
48#include "popen.h"
49 74
50int process_arguments (int, char **); 75 printf (_(VRBS));
51int validate_arguments (void); 76
52void print_help (void); 77 support ();
53void print_usage (void); 78}
79
54 80
55char *query_address = NULL; 81char *query_address = NULL;
56char *dns_server = NULL; 82char *dns_server = NULL;
57int verbose = FALSE; 83int verbose = FALSE;
84int server_port = DEFAULT_PORT;
85int warning_interval = -1;
86int critical_interval = -1;
87
58 88
59int 89int
60main (int argc, char **argv) 90main (int argc, char **argv)
@@ -66,13 +96,14 @@ main (int argc, char **argv)
66 96
67 /* Set signal handling and alarm */ 97 /* Set signal handling and alarm */
68 if (signal (SIGALRM, popen_timeout_alarm_handler) == SIG_ERR) 98 if (signal (SIGALRM, popen_timeout_alarm_handler) == SIG_ERR)
69 usage ("Cannot catch SIGALRM\n"); 99 usage (_("Cannot catch SIGALRM\n"));
70 100
71 if (process_arguments (argc, argv) != OK) 101 if (process_arguments (argc, argv) != OK)
72 usage ("Could not parse arguments\n"); 102 usage (_("Could not parse arguments\n"));
73 103
74 /* get the command to run */ 104 /* get the command to run */
75 asprintf (&command_line, "%s @%s %s", PATH_TO_DIG, dns_server, query_address); 105 asprintf (&command_line, "%s @%s -p %d %s",
106 PATH_TO_DIG, dns_server, server_port, query_address);
76 107
77 alarm (timeout_interval); 108 alarm (timeout_interval);
78 time (&start_time); 109 time (&start_time);
@@ -82,13 +113,13 @@ main (int argc, char **argv)
82 /* run the command */ 113 /* run the command */
83 child_process = spopen (command_line); 114 child_process = spopen (command_line);
84 if (child_process == NULL) { 115 if (child_process == NULL) {
85 printf ("Could not open pipe: %s\n", command_line); 116 printf (_("Could not open pipe: %s\n"), command_line);
86 return STATE_UNKNOWN; 117 return STATE_UNKNOWN;
87 } 118 }
88 119
89 child_stderr = fdopen (child_stderr_array[fileno (child_process)], "r"); 120 child_stderr = fdopen (child_stderr_array[fileno (child_process)], "r");
90 if (child_stderr == NULL) 121 if (child_stderr == NULL)
91 printf ("Could not open stderr for %s\n", command_line); 122 printf (_("Could not open stderr for %s\n"), command_line);
92 123
93 while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process)) { 124 while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process)) {
94 125
@@ -107,7 +138,7 @@ main (int argc, char **argv)
107 result = STATE_OK; 138 result = STATE_OK;
108 } 139 }
109 else { 140 else {
110 asprintf (&output, "Server not found in ANSWER SECTION"); 141 asprintf (&output, _("Server not found in ANSWER SECTION"));
111 result = STATE_WARNING; 142 result = STATE_WARNING;
112 } 143 }
113 144
@@ -117,7 +148,7 @@ main (int argc, char **argv)
117 } 148 }
118 149
119 if (result != STATE_OK) { 150 if (result != STATE_OK) {
120 asprintf (&output, "No ANSWER SECTION found"); 151 asprintf (&output, _("No ANSWER SECTION found"));
121 } 152 }
122 153
123 while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr)) { 154 while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr)) {
@@ -134,23 +165,23 @@ main (int argc, char **argv)
134 if (spclose (child_process)) { 165 if (spclose (child_process)) {
135 result = max_state (result, STATE_WARNING); 166 result = max_state (result, STATE_WARNING);
136 if (strlen (output) == 0) 167 if (strlen (output) == 0)
137 asprintf (&output, "dig returned error status"); 168 asprintf (&output, _("dig returned error status"));
138 } 169 }
139 170
140 (void) time (&end_time); 171 (void) time (&end_time);
141 172
142 if (output == NULL || strlen (output) == 0) 173 if (output == NULL || strlen (output) == 0)
143 asprintf (&output, " Probably a non-existent host/domain"); 174 asprintf (&output, _(" Probably a non-existent host/domain"));
144 175
145 if (result == STATE_OK) 176 if (result == STATE_OK)
146 printf ("DNS OK - %d seconds response time (%s)\n", 177 printf (_("DNS OK - %d seconds response time (%s)\n"),
147 (int) (end_time - start_time), output); 178 (int) (end_time - start_time), output);
148 else if (result == STATE_WARNING) 179 else if (result == STATE_WARNING)
149 printf ("DNS WARNING - %s\n", output); 180 printf (_("DNS WARNING - %s\n"), output);
150 else if (result == STATE_CRITICAL) 181 else if (result == STATE_CRITICAL)
151 printf ("DNS CRITICAL - %s\n", output); 182 printf (_("DNS CRITICAL - %s\n"), output);
152 else 183 else
153 printf ("DNS problem - %s\n", output); 184 printf (_("DNS problem - %s\n"), output);
154 185
155 return result; 186 return result;
156} 187}
@@ -182,35 +213,59 @@ process_arguments (int argc, char **argv)
182 213
183 switch (c) { 214 switch (c) {
184 case '?': /* help */ 215 case '?': /* help */
185 usage3 ("Unknown argument", optopt); 216 usage3 (_("Unknown argument"), optopt);
217 case 'h': /* help */
218 print_help ();
219 exit (STATE_OK);
220 case 'V': /* version */
221 print_revision (progname, "$Revision$");
222 exit (STATE_OK);
186 case 'H': /* hostname */ 223 case 'H': /* hostname */
187 if (is_host (optarg)) { 224 if (is_host (optarg)) {
188 dns_server = optarg; 225 dns_server = optarg;
189 } 226 }
190 else { 227 else {
191 usage ("Invalid host name\n"); 228 usage2 (_("Invalid host name"), optarg);
229 }
230 break;
231 case 'p':
232 if (is_intpos (optarg)) {
233 server_port = atoi (optarg);
234 }
235 else {
236 usage2 (_("Server port must be a nonnegative integer\n"), optarg);
192 } 237 }
193 break; 238 break;
194 case 'l': /* username */ 239 case 'l': /* username */
195 query_address = optarg; 240 query_address = optarg;
196 break; 241 break;
197 case 'v': /* verbose */ 242 case 'w': /* timeout */
198 verbose = TRUE; 243 if (is_intnonneg (optarg)) {
244 warning_interval = atoi (optarg);
245 }
246 else {
247 usage2 (_("Warning interval must be a nonnegative integer\n"), optarg);
248 }
249 break;
250 case 'c': /* timeout */
251 if (is_intnonneg (optarg)) {
252 critical_interval = atoi (optarg);
253 }
254 else {
255 usage2 (_("Critical interval must be a nonnegative integer\n"), optarg);
256 }
199 break; 257 break;
200 case 't': /* timeout */ 258 case 't': /* timeout */
201 if (is_intnonneg (optarg)) { 259 if (is_intnonneg (optarg)) {
202 timeout_interval = atoi (optarg); 260 timeout_interval = atoi (optarg);
203 } 261 }
204 else { 262 else {
205 usage ("Time interval must be a nonnegative integer\n"); 263 usage2 (_("Time interval must be a nonnegative integer\n"), optarg);
206 } 264 }
207 break; 265 break;
208 case 'V': /* version */ 266 case 'v': /* verbose */
209 print_revision (progname, "$Revision$"); 267 verbose = TRUE;
210 exit (STATE_OK); 268 break;
211 case 'h': /* help */
212 print_help ();
213 exit (STATE_OK);
214 } 269 }
215 } 270 }
216 271
@@ -221,7 +276,7 @@ process_arguments (int argc, char **argv)
221 dns_server = argv[c]; 276 dns_server = argv[c];
222 } 277 }
223 else { 278 else {
224 usage ("Invalid host name"); 279 usage2 (_("Invalid host name"), argv[c]);
225 } 280 }
226 } 281 }
227 else { 282 else {
@@ -242,31 +297,3 @@ validate_arguments (void)
242 return OK; 297 return OK;
243} 298}
244 299
245
246
247
248
249void
250print_help (void)
251{
252 print_revision (progname, revision);
253 printf ("Copyright (c) %s %s\n\t<%s>\n\n", copyright, authors, email);
254 printf (summary);
255 print_usage ();
256 printf ("\nOptions:\n");
257 printf (options, DEFAULT_SOCKET_TIMEOUT);
258 printf (standard_options);
259 support ();
260}
261
262
263
264
265
266void
267print_usage (void)
268{
269 printf ("Usage: %s %s\n", progname, option_summary);
270 printf (" %s (-h|--help)\n", progname);
271 printf (" %s (-V|--version)\n", progname);
272}