check_dns.c 22 KB

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