check_dns.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587
  1. /*****************************************************************************
  2. *
  3. * Nagios check_dns plugin
  4. *
  5. * License: GPL
  6. * Copyright (c) 2000-2014 Nagios Plugins Development Team
  7. *
  8. * Description:
  9. *
  10. * This file contains the check_dns plugin
  11. *
  12. * LIMITATION: nslookup on Solaris 7 can return output over 2 lines, which
  13. * will not be picked up by this plugin
  14. *
  15. *
  16. * This program is free software: you can redistribute it and/or modify
  17. * it under the terms of the GNU General Public License as published by
  18. * the Free Software Foundation, either version 3 of the License, or
  19. * (at your option) any later version.
  20. *
  21. * This program is distributed in the hope that it will be useful,
  22. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. * GNU General Public License for more details.
  25. *
  26. * You should have received a copy of the GNU General Public License
  27. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  28. *
  29. *
  30. *****************************************************************************/
  31. #define IF_RECORD(label, querytype, verb_str) if (strstr (chld_out.line[i], label) && (strncmp(query_type, querytype, query_size) == 0 || strncmp(query_type, "-querytype=ANY", query_size) == 0)) { \
  32. if (verbose) printf(verb_str); \
  33. temp_buffer = rindex (chld_out.line[i], ' '); \
  34. addresses[n_addresses++] = check_new_address(temp_buffer); \
  35. strncpy(query_found, querytype, sizeof(query_found)); \
  36. memset(query_found, '\0', sizeof(query_found));
  37. const char *progname = "check_dns";
  38. const char *copyright = "2000-2014";
  39. const char *email = "devel@nagios-plugins.org";
  40. #include "common.h"
  41. #include "utils.h"
  42. #include "utils_base.h"
  43. #include "netutils.h"
  44. #include "runcmd.h"
  45. int process_arguments (int, char **);
  46. int validate_arguments (void);
  47. int error_scan (char *);
  48. void print_help (void);
  49. void print_usage (void);
  50. #define ADDRESS_LENGTH 384
  51. char query_address[ADDRESS_LENGTH] = "";
  52. char dns_server[ADDRESS_LENGTH] = "";
  53. char ptr_server[ADDRESS_LENGTH] = "";
  54. char query_type[16] = "";
  55. int query_set = FALSE;
  56. int verbose = FALSE;
  57. char **expected_address = NULL;
  58. int expected_address_cnt = 0;
  59. int expect_authority = FALSE;
  60. int accept_cname = FALSE;
  61. thresholds *time_thresholds = NULL;
  62. static int
  63. qstrcmp(const void *p1, const void *p2)
  64. {
  65. /* The actual arguments to this function are "pointers to
  66. pointers to char", but strcmp() arguments are "pointers
  67. to char", hence the following cast plus dereference */
  68. return strcmp(* (char * const *) p1, * (char * const *) p2);
  69. }
  70. char *
  71. check_new_address(char *temp_buffer)
  72. {
  73. temp_buffer++;
  74. /* Strip leading spaces */
  75. for (; *temp_buffer != '\0' && *temp_buffer == ' '; temp_buffer++)
  76. /* NOOP */;
  77. strip(temp_buffer);
  78. if (temp_buffer==NULL || strlen(temp_buffer)==0)
  79. die (STATE_CRITICAL, "%s%s%s\n", _("DNS CRITICAL - '"), NSLOOKUP_COMMAND, _("' returned empty host name string"));
  80. return temp_buffer;
  81. }
  82. int
  83. main (int argc, char **argv)
  84. {
  85. char *command_line = NULL;
  86. char input_buffer[MAX_INPUT_BUFFER];
  87. char *address = NULL; /* comma seperated str with addrs/ptrs (sorted) */
  88. char **addresses = NULL;
  89. int n_addresses = 0;
  90. char *msg = NULL;
  91. char query_found[16] = "";
  92. int query_size = 16;
  93. char *temp_buffer = NULL;
  94. int non_authoritative = TRUE;
  95. int result = STATE_UNKNOWN;
  96. double elapsed_time;
  97. long microsec;
  98. struct timeval tv;
  99. int multi_address;
  100. int parse_address = FALSE; /* This flag scans for Address: but only after Name: */
  101. output chld_out, chld_err;
  102. size_t i;
  103. setlocale (LC_ALL, "");
  104. bindtextdomain (PACKAGE, LOCALEDIR);
  105. textdomain (PACKAGE);
  106. /* Set signal handling and alarm */
  107. if (signal (SIGALRM, runcmd_timeout_alarm_handler) == SIG_ERR)
  108. usage_va(_("Cannot catch SIGALRM"));
  109. /* Parse extra opts if any */
  110. argv=np_extra_opts (&argc, argv, progname);
  111. if (process_arguments (argc, argv) == ERROR)
  112. usage_va(_("Could not parse arguments"));
  113. /* get the command to run */
  114. xasprintf (&command_line, "%s %s %s %s", NSLOOKUP_COMMAND, query_type, query_address, dns_server);
  115. alarm (timeout_interval);
  116. gettimeofday (&tv, NULL);
  117. if (verbose)
  118. printf ("%s\n", command_line);
  119. /* run the command */
  120. if((np_runcmd(command_line, &chld_out, &chld_err, 0)) != 0) {
  121. msg = (char *)_("nslookup returned an error status");
  122. result = STATE_WARNING;
  123. }
  124. /* scan stdout */
  125. for(i = 0; i < chld_out.lines; i++) {
  126. if (addresses == NULL)
  127. addresses = malloc(sizeof(*addresses)*10);
  128. else if (!(n_addresses % 10))
  129. addresses = realloc(addresses,sizeof(*addresses) * (n_addresses + 10));
  130. if (verbose)
  131. puts(chld_out.line[i]);
  132. /* bug ID: 2946553 - Older versions of bind will use all available dns
  133. + servers, we have to match the one specified */
  134. if (strlen(dns_server) > 0 && strstr(chld_out.line[i], "Server:")) {
  135. temp_buffer = strchr(chld_out.line[i], ':');
  136. temp_buffer++;
  137. /* Strip leading tabs */
  138. for (; *temp_buffer != '\0' && *temp_buffer == '\t'; temp_buffer++)
  139. /* NOOP */;
  140. strip(temp_buffer);
  141. if (temp_buffer==NULL || strlen(temp_buffer)==0)
  142. die (STATE_CRITICAL, "%s%s%s\n", _("DNS CRITICAL - '"), NSLOOKUP_COMMAND, _("' returned empty server string"));
  143. if (strcmp(temp_buffer, dns_server) != 0)
  144. die (STATE_CRITICAL, "%s %s\n", _("DNS CRITICAL - No response from DNS server:"), dns_server);
  145. }
  146. if (strstr (chld_out.line[i], "Authoritative answers can be found from:")) {
  147. non_authoritative = FALSE;
  148. break;
  149. }
  150. /* the server is responding, we just got the host name...*/
  151. if (strstr (chld_out.line[i], "Name:"))
  152. parse_address = TRUE;
  153. /* begin handling types of records */
  154. IF_RECORD("AAAA address", "-querytype=AAAA", "Found AAAA record\n") }
  155. else IF_RECORD("exchanger =", "-querytype=MX", "Found MX record\n") }
  156. else IF_RECORD("service =", "-querytype=SRV", "Found SRV record\n") }
  157. else IF_RECORD("nameserver =", "-querytype=NS", "Found NS record\n") }
  158. else IF_RECORD("dname =", "-querytype=DNAME", "Found DNAME record\n") }
  159. else IF_RECORD("protocol =", "-querytype=WKS", "Found WKS record\n") }
  160. /* TODO: needs to be changed to handle txt output and max size of txt recrods */
  161. else IF_RECORD("text =", "-querytype=TXT", "Found TXT record\n") }
  162. /* only matching for origin records, if requested other fields could be included at a later date */
  163. else IF_RECORD("origin =", "-querytype=SOA", "Found SOA record\n") }
  164. /* cnames cannot use macro as we must check for accepting them separately */
  165. else if (accept_cname && strstr (chld_out.line[i], "canonical name =") && (strncmp(query_type, "-querytype=CNAME", query_size) == 0 || strncmp(query_type, "-querytype=ANY", query_size) == 0)) {
  166. if (verbose) printf("Found CNAME record\n");
  167. temp_buffer = index (chld_out.line[i], '=');
  168. addresses[n_addresses++] = check_new_address(temp_buffer);
  169. strncpy(query_found, "-querytype=CNAME", sizeof(query_found));
  170. }
  171. /* does not need strncmp as we want A at all times unless another record match */
  172. else if (parse_address == TRUE && (strstr (chld_out.line[i], "Address:") || strstr (chld_out.line[i], "Addresses:"))) {
  173. if (verbose) printf("Found A record\n");
  174. temp_buffer = index (chld_out.line[i], ':');
  175. addresses[n_addresses++] = check_new_address(temp_buffer);
  176. strncpy(query_found, "-querytype=A", sizeof(query_found));
  177. }
  178. /* must be after other records with "name" as an identifier, as ptr does not spefify */
  179. else IF_RECORD("name =", "-querytype=PTR", "Found PTR record\n") }
  180. /* needed for non-query ptr\reverse lookup checks */
  181. else if (strstr(chld_out.line[i], ".in-addr.arpa") && !query_set) {
  182. if ((temp_buffer = strstr(chld_out.line[i], "name = ")))
  183. addresses[n_addresses++] = strdup(temp_buffer + 7);
  184. else {
  185. msg = (char *)_("Warning plugin error");
  186. result = STATE_WARNING;
  187. }
  188. }
  189. if (strstr (chld_out.line[i], _("Non-authoritative answer:")))
  190. non_authoritative = TRUE;
  191. result = (result < error_scan(chld_out.line[i])) ? error_scan(chld_out.line[i]) : result;
  192. if (result != STATE_OK) {
  193. msg = strchr (chld_out.line[i], ':');
  194. if(msg) msg++;
  195. break;
  196. }
  197. }
  198. /* scan stderr */
  199. for(i = 0; i < chld_err.lines; i++) {
  200. if (verbose)
  201. puts(chld_err.line[i]);
  202. if (error_scan (chld_err.line[i]) != STATE_OK) {
  203. result = max_state (result, error_scan (chld_err.line[i]));
  204. msg = strchr(input_buffer, ':');
  205. if(msg) msg++;
  206. }
  207. }
  208. if (addresses) {
  209. int i,slen;
  210. char *adrp;
  211. qsort(addresses, n_addresses, sizeof(*addresses), qstrcmp);
  212. for(i=0, slen=1; i < n_addresses; i++)
  213. slen += strlen(addresses[i])+1;
  214. adrp = address = malloc(slen);
  215. for(i=0; i < n_addresses; i++) {
  216. if (i) *adrp++ = ',';
  217. strcpy(adrp, addresses[i]);
  218. adrp += strlen(addresses[i]);
  219. }
  220. *adrp = 0;
  221. } else
  222. die (STATE_CRITICAL, "%s%s%s\n", _("DNS CRITICAL - '"), NSLOOKUP_COMMAND, _("' msg parsing exited with no address"));
  223. /* compare to expected address */
  224. if (result == STATE_OK && expected_address_cnt > 0) {
  225. result = STATE_CRITICAL;
  226. temp_buffer = "";
  227. for (i=0; i<expected_address_cnt; i++) {
  228. /* check if we get a match and prepare an error string */
  229. if (strcmp(address, expected_address[i]) == 0) result = STATE_OK;
  230. xasprintf(&temp_buffer, "%s%s; ", temp_buffer, expected_address[i]);
  231. }
  232. if (result == STATE_CRITICAL) {
  233. /* Strip off last semicolon... */
  234. temp_buffer[strlen(temp_buffer)-2] = '\0';
  235. xasprintf(&msg, "%s%s%s%s%s", _("expected '"), temp_buffer, _("' but got '"), address, "'");
  236. }
  237. }
  238. /* check if authoritative */
  239. if (result == STATE_OK && expect_authority && !non_authoritative) {
  240. result = STATE_CRITICAL;
  241. if (strncmp(dns_server, "", 1))
  242. xasprintf(&msg, "%s %s %s %s", _("server"), dns_server, _("is not authoritative for"), query_address);
  243. else
  244. xasprintf(&msg, "%s %s", _("there is no authoritative server for"), query_address);
  245. }
  246. /* compare query type to query found, if query type is ANY we can skip as any record is accepted*/
  247. if (result == STATE_OK && strncmp(query_type, "", 1) && (strncmp(query_type, "-querytype=ANY", 15) != 0)) {
  248. if (strncmp(query_type, query_found, 16) != 0) {
  249. if (verbose)
  250. printf( "%s %s %s %s %s\n", _("Failed query for"), query_type, _("only found"), query_found, _(", or nothing"));
  251. result = STATE_CRITICAL;
  252. xasprintf(&msg, "%s %s %s %s", _("query type of"), query_type, _("was not found for"), query_address);
  253. }
  254. }
  255. microsec = deltime (tv);
  256. elapsed_time = (double)microsec / 1.0e6;
  257. if (result == STATE_OK) {
  258. if (strchr (address, ',') == NULL)
  259. multi_address = FALSE;
  260. else
  261. multi_address = TRUE;
  262. result = get_status(elapsed_time, time_thresholds);
  263. if (result == STATE_OK) {
  264. printf ("%s %s: ", _("DNS"), _("OK"));
  265. } else if (result == STATE_WARNING) {
  266. printf ("%s %s: ", _("DNS"), _("WARNING"));
  267. } else if (result == STATE_CRITICAL) {
  268. printf ("%s %s: ", _("DNS"), _("CRITICAL"));
  269. }
  270. printf (ngettext("%.3f second response time", "%.3f seconds response time", elapsed_time), elapsed_time);
  271. printf (". %s %s %s", query_address, _("returns"), address);
  272. if ((time_thresholds->warning != NULL) && (time_thresholds->critical != NULL)) {
  273. printf ("|%s\n", fperfdata ("time", elapsed_time, "s",
  274. TRUE, time_thresholds->warning->end,
  275. TRUE, time_thresholds->critical->end,
  276. TRUE, 0, FALSE, 0));
  277. } else if ((time_thresholds->warning == NULL) && (time_thresholds->critical != NULL)) {
  278. printf ("|%s\n", fperfdata ("time", elapsed_time, "s",
  279. FALSE, 0,
  280. TRUE, time_thresholds->critical->end,
  281. TRUE, 0, FALSE, 0));
  282. } else if ((time_thresholds->warning != NULL) && (time_thresholds->critical == NULL)) {
  283. printf ("|%s\n", fperfdata ("time", elapsed_time, "s",
  284. TRUE, time_thresholds->warning->end,
  285. FALSE, 0,
  286. TRUE, 0, FALSE, 0));
  287. } else
  288. printf ("|%s\n", fperfdata ("time", elapsed_time, "s", FALSE, 0, FALSE, 0, TRUE, 0, FALSE, 0));
  289. }
  290. else if (result == STATE_WARNING)
  291. printf ("%s %s\n", _("DNS WARNING -"), !strcmp (msg, "") ? _("Probably a non-existent host/domain") : msg);
  292. else if (result == STATE_CRITICAL)
  293. printf ("%s %s\n", _("DNS CRITICAL -"), !strcmp (msg, "") ? _("Probably a non-existent host/domain") : msg);
  294. else
  295. printf ("%s %s\n", _("DNS UNKNOWN -"), !strcmp (msg, "") ? _("Probably a non-existent host/domain") : msg);
  296. return result;
  297. }
  298. int
  299. error_scan (char *input_buffer)
  300. {
  301. /* the DNS lookup timed out */
  302. if (strstr (input_buffer, _("Note: nslookup is deprecated and may be removed from future releases.")) ||
  303. strstr (input_buffer, _("Consider using the `dig' or `host' programs instead. Run nslookup with")) ||
  304. strstr (input_buffer, _("the `-sil[ent]' option to prevent this message from appearing.")))
  305. return STATE_OK;
  306. /* DNS server is not running... */
  307. else if (strstr (input_buffer, "No response from server"))
  308. die (STATE_CRITICAL, "%s %s\n", _("No response from DNS"), dns_server);
  309. /* Host name is valid, but server doesn't have records... */
  310. else if (strstr (input_buffer, "No records") || strstr (input_buffer, "No answer"))
  311. die (STATE_CRITICAL, "%s %s %s\n", _("DNS"), dns_server, _("has no records"));
  312. /* Connection was refused */
  313. else if (strstr (input_buffer, "Connection refused") ||
  314. strstr (input_buffer, "Couldn't find server") ||
  315. strstr (input_buffer, "Refused") ||
  316. (strstr (input_buffer, "** server can't find") &&
  317. strstr (input_buffer, ": REFUSED")))
  318. die (STATE_CRITICAL, "%s %s %s\n", _("Connection to DNS"), dns_server, _("was refused"));
  319. /* Query refused (usually by an ACL in the namserver) */
  320. else if (strstr (input_buffer, "Query refused"))
  321. die (STATE_CRITICAL, "%s %s\n", _("Query was refused by DNS server at"), dns_server);
  322. /* No information (e.g. nameserver IP has two PTR records) */
  323. else if (strstr (input_buffer, "No information"))
  324. die (STATE_CRITICAL, "%s %s\n", _("No information returned by DNS server at"), dns_server);
  325. /* Host or domain name does not exist */
  326. else if (strstr (input_buffer, "Non-existent") ||
  327. strstr (input_buffer, "** server can't find") ||
  328. strstr (input_buffer,"NXDOMAIN"))
  329. die (STATE_CRITICAL, "%s %s %s\n", _("Domain"), query_address, _("was not found by the server"));
  330. /* Network is unreachable */
  331. else if (strstr (input_buffer, "Network is unreachable"))
  332. die (STATE_CRITICAL, "%s\n", _("Network is unreachable"));
  333. /* Internal server failure */
  334. else if (strstr (input_buffer, "Server failure"))
  335. die (STATE_CRITICAL, "%s %s\n", _("DNS failure for"), dns_server);
  336. /* Request error or the DNS lookup timed out */
  337. else if (strstr (input_buffer, "Format error") ||
  338. strstr (input_buffer, "Timed out"))
  339. return STATE_WARNING;
  340. return STATE_OK;
  341. }
  342. /* process command-line arguments */
  343. int
  344. process_arguments (int argc, char **argv)
  345. {
  346. int c;
  347. char *warning = NULL;
  348. char *critical = NULL;
  349. int opt_index = 0;
  350. static struct option long_opts[] = {
  351. {"help", no_argument, 0, 'h'},
  352. {"version", no_argument, 0, 'V'},
  353. {"verbose", no_argument, 0, 'v'},
  354. {"timeout", required_argument, 0, 't'},
  355. {"hostname", required_argument, 0, 'H'},
  356. {"server", required_argument, 0, 's'},
  357. {"reverse-server", required_argument, 0, 'r'},
  358. {"querytype", required_argument, 0, 'q'},
  359. {"expected-address", required_argument, 0, 'a'},
  360. {"expect-authority", no_argument, 0, 'A'},
  361. {"accept-cname", no_argument, 0, 'n'},
  362. {"warning", required_argument, 0, 'w'},
  363. {"critical", required_argument, 0, 'c'},
  364. {0, 0, 0, 0}
  365. };
  366. if (argc < 2)
  367. return ERROR;
  368. for (c = 1; c < argc; c++)
  369. if (strcmp ("-to", argv[c]) == 0)
  370. strcpy (argv[c], "-t");
  371. while (1) {
  372. c = getopt_long (argc, argv, "hVvAnt:H:s:r:a:q:w:c:", long_opts, &opt_index);
  373. if (c == -1 || c == EOF)
  374. break;
  375. switch (c) {
  376. case 'h': /* help */
  377. print_help ();
  378. exit (STATE_OK);
  379. case 'V': /* version */
  380. print_revision (progname, NP_VERSION);
  381. exit (STATE_OK);
  382. case 'v': /* version */
  383. verbose = TRUE;
  384. break;
  385. case 't': /* timeout period */
  386. timeout_interval = atoi (optarg);
  387. break;
  388. case 'H': /* hostname */
  389. if (strlen (optarg) >= ADDRESS_LENGTH)
  390. die (STATE_UNKNOWN, "%s\n", _("Input buffer overflow"));
  391. strcpy (query_address, optarg);
  392. break;
  393. case 's': /* server name */
  394. /* TODO: this host_or_die check is probably unnecessary.
  395. * Better to confirm nslookup response matches */
  396. host_or_die(optarg);
  397. if (strlen (optarg) >= ADDRESS_LENGTH)
  398. die (STATE_UNKNOWN, "%s\n", _("Input buffer overflow"));
  399. strcpy (dns_server, optarg);
  400. break;
  401. case 'r': /* reverse server name */
  402. /* TODO: Is this host_or_die necessary? */
  403. host_or_die(optarg);
  404. if (strlen (optarg) >= ADDRESS_LENGTH)
  405. die (STATE_UNKNOWN, "%s\n", _("Input buffer overflow"));
  406. strcpy (ptr_server, optarg);
  407. break;
  408. case 'a': /* expected address */
  409. if (strlen (optarg) >= ADDRESS_LENGTH)
  410. die (STATE_UNKNOWN, "%s\n", _("Input buffer overflow"));
  411. expected_address = (char **)realloc(expected_address, (expected_address_cnt+1) * sizeof(char**));
  412. expected_address[expected_address_cnt] = strdup(optarg);
  413. expected_address_cnt++;
  414. break;
  415. case 'q': /* querytype -- A or AAAA or ANY or SRV or TXT, etc. */
  416. if (strlen (optarg) < 1 || strlen (optarg) > 5)
  417. die (STATE_UNKNOWN, "%s\n", _("Missing valid querytype parameter. Try using 'A' or 'AAAA' or 'SRV'"));
  418. strntoupper(optarg, sizeof(optarg));
  419. strcpy(query_type, "-querytype=");
  420. strcat(query_type, optarg);
  421. query_set = TRUE;
  422. /* logic is set such that we must accept cnames if they are querying for them */
  423. if (strcmp(query_type, "-querytype=CNAME") != 0)
  424. break;
  425. case 'n': /* accept cname responses as a result */
  426. accept_cname = TRUE;
  427. break;
  428. case 'A': /* expect authority */
  429. expect_authority = TRUE;
  430. break;
  431. case 'w':
  432. warning = optarg;
  433. break;
  434. case 'c':
  435. critical = optarg;
  436. break;
  437. default: /* args not parsable */
  438. usage5();
  439. }
  440. }
  441. c = optind;
  442. if (strlen(query_address)==0 && c<argc) {
  443. if (strlen(argv[c])>=ADDRESS_LENGTH)
  444. die (STATE_UNKNOWN, "%s\n", _("Input buffer overflow"));
  445. strcpy (query_address, argv[c++]);
  446. }
  447. if (strlen(dns_server)==0 && c<argc) {
  448. /* TODO: See -s option */
  449. host_or_die(argv[c]);
  450. if (strlen(argv[c]) >= ADDRESS_LENGTH)
  451. die (STATE_UNKNOWN, "%s\n", _("Input buffer overflow"));
  452. strcpy (dns_server, argv[c++]);
  453. }
  454. set_thresholds(&time_thresholds, warning, critical);
  455. return validate_arguments ();
  456. }
  457. int
  458. validate_arguments ()
  459. {
  460. if (query_address[0] == 0)
  461. return ERROR;
  462. return OK;
  463. }
  464. void
  465. print_help (void)
  466. {
  467. print_revision (progname, NP_VERSION);
  468. printf ("%s\n", "Copyright (c) 1999 Ethan Galstad <nagios@nagios.org>");
  469. printf (COPYRIGHT, copyright, email);
  470. printf ("%s\n", _("This plugin uses the nslookup program to obtain the IP address for the given host/domain query."));
  471. printf ("%s\n", _("An optional DNS server to use may be specified."));
  472. printf ("%s\n", _("If no DNS server is specified, the default server(s) specified in /etc/resolv.conf will be used."));
  473. printf ("\n\n");
  474. print_usage ();
  475. printf (UT_HELP_VRSN);
  476. printf (UT_EXTRA_OPTS);
  477. printf ("%s\n", " -H, --hostname=HOST");
  478. printf (" %s\n", _("The name or address you want to query"));
  479. printf ("%s\n", " -s, --server=HOST");
  480. printf (" %s\n", _("Optional DNS server you want to use for the lookup"));
  481. printf ("%s\n", " -q, --querytype=TYPE");
  482. printf (" %s\n", _("Optional DNS record query type where TYPE =(A, AAAA, SRV, TXT, MX, ANY)"));
  483. printf (" %s\n", _("The default query type is 'A' (IPv4 host entry)"));
  484. printf ("%s\n", " -a, --expected-address=IP-ADDRESS|HOST");
  485. printf (" %s\n", _("Optional IP-ADDRESS you expect the DNS server to return. HOST must end with"));
  486. printf (" %s\n", _("a dot (.). This option can be repeated multiple times (Returns OK if any"));
  487. printf (" %s\n", _("value match). If multiple addresses are returned at once, you have to match"));
  488. printf (" %s\n", _("the whole string of addresses separated with commas (sorted alphabetically)."));
  489. printf (" %s\n", _("If you would like to test for the presence of a cname, combine with -n param."));
  490. printf ("%s\n", " -A, --expect-authority");
  491. printf (" %s\n", _("Optionally expect the DNS server to be authoritative for the lookup"));
  492. printf ("%s\n", " -n, --accept-cname");
  493. printf (" %s\n", _("Optionally accept cname responses as a valid result to a query"));
  494. printf (" %s\n", _("The default is to ignore cname responses as part of the result"));
  495. printf ("%s\n", " -w, --warning=seconds");
  496. printf (" %s\n", _("Return warning if elapsed time exceeds value. Default off"));
  497. printf ("%s\n", " -c, --critical=seconds");
  498. printf (" %s\n", _("Return critical if elapsed time exceeds value. Default off"));
  499. printf (UT_CONN_TIMEOUT, DEFAULT_SOCKET_TIMEOUT);
  500. printf (UT_SUPPORT);
  501. }
  502. void
  503. print_usage (void)
  504. {
  505. printf ("%s\n", _("Usage:"));
  506. printf ("%s %s\n", progname, "-H host [-s server] [-q type ] [-a expected-address] [-A] [-n] [-t timeout] [-w warn] [-c crit]");
  507. }