summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--plugins/check_dig.c79
1 files changed, 58 insertions, 21 deletions
diff --git a/plugins/check_dig.c b/plugins/check_dig.c
index 9e1d8479..41c445c5 100644
--- a/plugins/check_dig.c
+++ b/plugins/check_dig.c
@@ -37,6 +37,8 @@ enum {
37}; 37};
38 38
39char *query_address = NULL; 39char *query_address = NULL;
40char *record_type = "A";
41char *expected_address = NULL;
40char *dns_server = NULL; 42char *dns_server = NULL;
41int verbose = FALSE; 43int verbose = FALSE;
42int server_port = DEFAULT_PORT; 44int server_port = DEFAULT_PORT;
@@ -68,14 +70,20 @@ main (int argc, char **argv)
68 usage (_("Could not parse arguments\n")); 70 usage (_("Could not parse arguments\n"));
69 71
70 /* get the command to run */ 72 /* get the command to run */
71 asprintf (&command_line, "%s @%s -p %d %s", 73 asprintf (&command_line, "%s @%s -p %d %s -t %s",
72 PATH_TO_DIG, dns_server, server_port, query_address); 74 PATH_TO_DIG, dns_server, server_port, query_address, record_type);
73 75
74 alarm (timeout_interval); 76 alarm (timeout_interval);
75 gettimeofday (&tv, NULL); 77 gettimeofday (&tv, NULL);
76 78
77 if (verbose) 79 if (verbose) {
78 printf ("%s\n", command_line); 80 printf ("%s\n", command_line);
81 if(expected_address != NULL) {
82 printf ("Looking for: '%s'\n", expected_address);
83 } else {
84 printf ("Looking for: '%s'\n", query_address);
85 }
86 }
79 87
80 /* run the command */ 88 /* run the command */
81 child_process = spopen (command_line); 89 child_process = spopen (command_line);
@@ -93,28 +101,39 @@ main (int argc, char **argv)
93 /* the server is responding, we just got the host name... */ 101 /* the server is responding, we just got the host name... */
94 if (strstr (input_buffer, ";; ANSWER SECTION:")) { 102 if (strstr (input_buffer, ";; ANSWER SECTION:")) {
95 103
96 /* get the host address */ 104 /* loop through the whole 'ANSWER SECTION' */
97 if (!fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process)) 105 do {
98 break; 106 /* get the host address */
107 if (!fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process))
108 break;
99 109
100 if (strpbrk (input_buffer, "\r\n")) 110 if (strpbrk (input_buffer, "\r\n"))
101 input_buffer[strcspn (input_buffer, "\r\n")] = '\0'; 111 input_buffer[strcspn (input_buffer, "\r\n")] = '\0';
102 112
103 if (strstr (input_buffer, query_address) == input_buffer) { 113 if (verbose && !strstr (input_buffer, ";; "))
104 output = strdup(input_buffer); 114 printf ("%s\n", input_buffer);
105 result = STATE_OK; 115
106 } 116 if (expected_address==NULL && strstr (input_buffer, query_address) != NULL) {
107 else { 117 output = strdup(input_buffer);
108 asprintf (&output, _("Server not found in ANSWER SECTION")); 118 result = STATE_OK;
109 result = STATE_WARNING; 119 }
110 } 120 else if (expected_address != NULL && strstr (input_buffer, expected_address) != NULL) {
121 output = strdup(input_buffer);
122 result = STATE_OK;
123 }
124
125 } while (!strstr (input_buffer, ";; "));
126
127 if (result == STATE_UNKNOWN) {
128 asprintf (&output, _("Server not found in ANSWER SECTION"));
129 result = STATE_WARNING;
130 }
111 131
112 continue;
113 } 132 }
114 133
115 } 134 }
116 135
117 if (result != STATE_OK) { 136 if (result == STATE_UNKNOWN) {
118 asprintf (&output, _("No ANSWER SECTION found")); 137 asprintf (&output, _("No ANSWER SECTION found"));
119 } 138 }
120 139
@@ -181,6 +200,8 @@ process_arguments (int argc, char **argv)
181 {"verbose", no_argument, 0, 'v'}, 200 {"verbose", no_argument, 0, 'v'},
182 {"version", no_argument, 0, 'V'}, 201 {"version", no_argument, 0, 'V'},
183 {"help", no_argument, 0, 'h'}, 202 {"help", no_argument, 0, 'h'},
203 {"record_type", required_argument, 0, 'T'},
204 {"expected_address", required_argument, 0, 'a'},
184 {0, 0, 0, 0} 205 {0, 0, 0, 0}
185 }; 206 };
186 207
@@ -188,7 +209,7 @@ process_arguments (int argc, char **argv)
188 return ERROR; 209 return ERROR;
189 210
190 while (1) { 211 while (1) {
191 c = getopt_long (argc, argv, "hVvt:l:H:w:c:", longopts, &option); 212 c = getopt_long (argc, argv, "hVvt:l:H:w:c:T:a:", longopts, &option);
192 213
193 if (c == -1 || c == EOF) 214 if (c == -1 || c == EOF)
194 break; 215 break;
@@ -248,6 +269,12 @@ process_arguments (int argc, char **argv)
248 case 'v': /* verbose */ 269 case 'v': /* verbose */
249 verbose = TRUE; 270 verbose = TRUE;
250 break; 271 break;
272 case 'T':
273 record_type = optarg;
274 break;
275 case 'a':
276 expected_address = optarg;
277 break;
251 } 278 }
252 } 279 }
253 280
@@ -309,6 +336,15 @@ print_help (void)
309 -l, --lookup=STRING\n\ 336 -l, --lookup=STRING\n\
310 machine name to lookup\n")); 337 machine name to lookup\n"));
311 338
339 printf (_("\
340 -T, --record_type=STRING\n\
341 record type to lookup (default: A)\n"));
342
343 printf (_("\
344 -a, --expected_address=STRING\n\
345 an address expected to be in the asnwer section.\n\
346 if not set, uses whatever was in -l\n"));
347
312 printf (_(UT_WARN_CRIT)); 348 printf (_(UT_WARN_CRIT));
313 349
314 printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT); 350 printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT);
@@ -325,8 +361,9 @@ void
325print_usage (void) 361print_usage (void)
326{ 362{
327 printf (_("\ 363 printf (_("\
328Usage: %s -H host -l lookup [-p <server port>] [-w <warning interval>]\n\ 364Usage: %s -H host -l lookup [-p <server port>] [-T <query type>]\n\
329 [-c <critical interval>] [-t <timeout>] [-v]\n"), 365 [-w <warning interval>] [-c <critical interval>] [-t <timeout>]\n\
366 [-a <expected answer address>] [-v]\n"),
330 progname); 367 progname);
331 printf (" %s (-h|--help)\n", progname); 368 printf (" %s (-h|--help)\n", progname);
332 printf (" %s (-V|--version)\n", progname); 369 printf (" %s (-V|--version)\n", progname);