summaryrefslogtreecommitdiffstats
path: root/plugins/check_dns.c
diff options
context:
space:
mode:
authorSubhendu Ghosh <sghosh@users.sourceforge.net>2002-10-07 19:05:24 (GMT)
committerSubhendu Ghosh <sghosh@users.sourceforge.net>2002-10-07 19:05:24 (GMT)
commit6e4ba8514b9a68214b3315a997c5774cad1f6b3c (patch)
treef5126767f737fb5146b82f8e6002a417cbc1ab5b /plugins/check_dns.c
parent0505e9fb07a5bd701efd3ce335a6dc8e13cbd6e1 (diff)
downloadmonitoring-plugins-6e4ba8514b9a68214b3315a997c5774cad1f6b3c.tar.gz
patch for expected IP address
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@109 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'plugins/check_dns.c')
-rw-r--r--plugins/check_dns.c32
1 files changed, 28 insertions, 4 deletions
diff --git a/plugins/check_dns.c b/plugins/check_dns.c
index a0d6e85..bc0400f 100644
--- a/plugins/check_dns.c
+++ b/plugins/check_dns.c
@@ -10,8 +10,9 @@
10 * 10 *
11 * Notes: 11 * Notes:
12 * - Safe popen added by Karl DeBisschop 9-11-99 12 * - Safe popen added by Karl DeBisschop 9-11-99
13 * - expected-address parameter added by Alex Chaffee - 7 Oct 2002
13 * 14 *
14 * Command line: CHECK_DNS <query_address> [dns_server] 15 * Command line: (see print_usage)
15 * 16 *
16 * Description: 17 * Description:
17 * 18 *
@@ -59,6 +60,8 @@ char query_address[ADDRESS_LENGTH] = "";
59char dns_server[ADDRESS_LENGTH] = ""; 60char dns_server[ADDRESS_LENGTH] = "";
60char ptr_server[ADDRESS_LENGTH] = ""; 61char ptr_server[ADDRESS_LENGTH] = "";
61int verbose = FALSE; 62int verbose = FALSE;
63char expected_address[ADDRESS_LENGTH] = "";
64int match_expected_address = FALSE;
62 65
63int 66int
64main (int argc, char **argv) 67main (int argc, char **argv)
@@ -165,6 +168,12 @@ main (int argc, char **argv)
165 output = strscpy (output, "nslookup returned error status"); 168 output = strscpy (output, "nslookup returned error status");
166 } 169 }
167 170
171 /* compare to expected address */
172 if (result == STATE_OK && match_expected_address && strcmp(address, expected_address)) {
173 result = STATE_CRITICAL;
174 output = ssprintf(output, "expected %s but got %s", expected_address, address);
175 }
176
168 (void) time (&end_time); 177 (void) time (&end_time);
169 178
170 if (result == STATE_OK) 179 if (result == STATE_OK)
@@ -297,6 +306,7 @@ call_getopt (int argc, char **argv)
297 {"hostname", required_argument, 0, 'H'}, 306 {"hostname", required_argument, 0, 'H'},
298 {"server", required_argument, 0, 's'}, 307 {"server", required_argument, 0, 's'},
299 {"reverse-server", required_argument, 0, 'r'}, 308 {"reverse-server", required_argument, 0, 'r'},
309 {"expected-address", required_argument, 0, 'a'},
300 {0, 0, 0, 0} 310 {0, 0, 0, 0}
301 }; 311 };
302#endif 312#endif
@@ -304,9 +314,9 @@ call_getopt (int argc, char **argv)
304 314
305 while (1) { 315 while (1) {
306#ifdef HAVE_GETOPT_H 316#ifdef HAVE_GETOPT_H
307 c = getopt_long (argc, argv, "+?hVvt:H:s:r:", long_opts, &opt_index); 317 c = getopt_long (argc, argv, "+?hVvt:H:s:r:a:", long_opts, &opt_index);
308#else 318#else
309 c = getopt (argc, argv, "+?hVvt:H:s:r:"); 319 c = getopt (argc, argv, "+?hVvt:H:s:r:a:");
310#endif 320#endif
311 321
312 if (c == -1 || c == EOF) 322 if (c == -1 || c == EOF)
@@ -318,6 +328,7 @@ call_getopt (int argc, char **argv)
318 case 'H': 328 case 'H':
319 case 's': 329 case 's':
320 case 'r': 330 case 'r':
331 case 'a':
321 i++; 332 i++;
322 } 333 }
323 334
@@ -368,6 +379,17 @@ call_getopt (int argc, char **argv)
368 terminate (STATE_UNKNOWN, "Input buffer overflow\n"); 379 terminate (STATE_UNKNOWN, "Input buffer overflow\n");
369 strcpy (ptr_server, optarg); 380 strcpy (ptr_server, optarg);
370 break; 381 break;
382 case 'a': /* expected address */
383 if (is_dotted_quad (optarg) == FALSE) {
384 printf ("Invalid expected address\n\n");
385 print_usage (my_basename (argv[0]));
386 exit (STATE_UNKNOWN);
387 }
388 if (strlen (optarg) >= ADDRESS_LENGTH)
389 terminate (STATE_UNKNOWN, "Input buffer overflow\n");
390 strcpy (expected_address, optarg);
391 match_expected_address = TRUE;
392 break;
371 } 393 }
372 } 394 }
373 return i; 395 return i;
@@ -385,7 +407,7 @@ validate_arguments ()
385void 407void
386print_usage (char *cmd) 408print_usage (char *cmd)
387{ 409{
388 printf ("Usage: %s -H host [-s server] [-t timeout]\n" " %s --help\n" 410 printf ("Usage: %s -H host [-s server] [-a expected-address] [-t timeout]\n" " %s --help\n"
389 " %s --version\n", cmd, cmd, cmd); 411 " %s --version\n", cmd, cmd, cmd);
390} 412}
391 413
@@ -401,6 +423,8 @@ print_help (char *cmd)
401 " The name or address you want to query\n" 423 " The name or address you want to query\n"
402 "-s, --server=HOST\n" 424 "-s, --server=HOST\n"
403 " Optional DNS server you want to use for the lookup\n" 425 " Optional DNS server you want to use for the lookup\n"
426 "-a, --expected-address=IP-ADDRESS\n"
427 " Optional IP address you expect the DNS server to return\n"
404 "-t, --timeout=INTEGER\n" 428 "-t, --timeout=INTEGER\n"
405 " Seconds before connection times out (default: %d)\n" 429 " Seconds before connection times out (default: %d)\n"
406 "-h, --help\n" 430 "-h, --help\n"