check_tcp.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673
  1. /*****************************************************************************
  2. *
  3. * Nagios check_tcp plugin
  4. *
  5. * License: GPL
  6. * Copyright (c) 1999-2008 Nagios Plugins Development Team
  7. *
  8. * Description:
  9. *
  10. * This file contains the check_tcp plugin
  11. *
  12. *
  13. * This program is free software: you can redistribute it and/or modify
  14. * it under the terms of the GNU General Public License as published by
  15. * the Free Software Foundation, either version 3 of the License, or
  16. * (at your option) any later version.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU General Public License
  24. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  25. *
  26. * $Id$
  27. *
  28. *****************************************************************************/
  29. /* progname "check_tcp" changes depending on symlink called */
  30. char *progname;
  31. const char *copyright = "1999-2008";
  32. const char *email = "nagiosplug-devel@lists.sourceforge.net";
  33. #include <ctype.h>
  34. #include "common.h"
  35. #include "netutils.h"
  36. #include "utils.h"
  37. #include "utils_tcp.h"
  38. #ifdef HAVE_SSL
  39. static int check_cert = FALSE;
  40. static int days_till_exp_warn, days_till_exp_crit;
  41. # define my_recv(buf, len) ((flags & FLAG_SSL) ? np_net_ssl_read(buf, len) : read(sd, buf, len))
  42. # define my_send(buf, len) ((flags & FLAG_SSL) ? np_net_ssl_write(buf, len) : send(sd, buf, len, 0))
  43. #else
  44. # define my_recv(buf, len) read(sd, buf, len)
  45. # define my_send(buf, len) send(sd, buf, len, 0)
  46. #endif
  47. /* int my_recv(char *, size_t); */
  48. static int process_arguments (int, char **);
  49. void print_help (void);
  50. void print_usage (void);
  51. #define EXPECT server_expect[0]
  52. static char *SERVICE = "TCP";
  53. static char *SEND = NULL;
  54. static char *QUIT = NULL;
  55. static int PROTOCOL = IPPROTO_TCP; /* most common is default */
  56. static int PORT = 0;
  57. static int server_port = 0;
  58. static char *server_address = NULL;
  59. static int host_specified = FALSE;
  60. static char *server_send = NULL;
  61. static char *server_quit = NULL;
  62. static char **server_expect;
  63. static size_t server_expect_count = 0;
  64. static size_t maxbytes = 0;
  65. static char **warn_codes = NULL;
  66. static size_t warn_codes_count = 0;
  67. static char **crit_codes = NULL;
  68. static size_t crit_codes_count = 0;
  69. static unsigned int delay = 0;
  70. static double warning_time = 0;
  71. static double critical_time = 0;
  72. static double elapsed_time = 0;
  73. static long microsec;
  74. static int sd = 0;
  75. #define MAXBUF 1024
  76. static char buffer[MAXBUF];
  77. static int expect_mismatch_state = STATE_WARNING;
  78. #define FLAG_SSL 0x01
  79. #define FLAG_VERBOSE 0x02
  80. #define FLAG_EXACT_MATCH 0x04
  81. #define FLAG_TIME_WARN 0x08
  82. #define FLAG_TIME_CRIT 0x10
  83. #define FLAG_HIDE_OUTPUT 0x20
  84. #define FLAG_MATCH_ALL 0x40
  85. static size_t flags = FLAG_EXACT_MATCH;
  86. int
  87. main (int argc, char **argv)
  88. {
  89. int result = STATE_UNKNOWN;
  90. int i;
  91. char *status = NULL;
  92. struct timeval tv;
  93. size_t len;
  94. int match = -1;
  95. setlocale (LC_ALL, "");
  96. bindtextdomain (PACKAGE, LOCALEDIR);
  97. textdomain (PACKAGE);
  98. /* determine program- and service-name quickly */
  99. progname = strrchr(argv[0], '/');
  100. if(progname != NULL) progname++;
  101. else progname = argv[0];
  102. len = strlen(progname);
  103. if(len > 6 && !memcmp(progname, "check_", 6)) {
  104. SERVICE = strdup(progname + 6);
  105. for(i = 0; i < len - 6; i++)
  106. SERVICE[i] = toupper(SERVICE[i]);
  107. }
  108. /* set up a resonable buffer at first (will be realloc()'ed if
  109. * user specifies other options) */
  110. server_expect = calloc(sizeof(char *), 2);
  111. /* determine defaults for this service's protocol */
  112. if (!strncmp(SERVICE, "UDP", 3)) {
  113. PROTOCOL = IPPROTO_UDP;
  114. }
  115. else if (!strncmp(SERVICE, "FTP", 3)) {
  116. EXPECT = "220";
  117. QUIT = "QUIT\r\n";
  118. PORT = 21;
  119. }
  120. else if (!strncmp(SERVICE, "POP", 3) || !strncmp(SERVICE, "POP3", 4)) {
  121. EXPECT = "+OK";
  122. QUIT = "QUIT\r\n";
  123. PORT = 110;
  124. }
  125. else if (!strncmp(SERVICE, "SMTP", 4)) {
  126. EXPECT = "220";
  127. QUIT = "QUIT\r\n";
  128. PORT = 25;
  129. }
  130. else if (!strncmp(SERVICE, "IMAP", 4)) {
  131. EXPECT = "* OK";
  132. QUIT = "a1 LOGOUT\r\n";
  133. PORT = 143;
  134. }
  135. #ifdef HAVE_SSL
  136. else if (!strncmp(SERVICE, "SIMAP", 5)) {
  137. EXPECT = "* OK";
  138. QUIT = "a1 LOGOUT\r\n";
  139. flags |= FLAG_SSL;
  140. PORT = 993;
  141. }
  142. else if (!strncmp(SERVICE, "SPOP", 4)) {
  143. EXPECT = "+OK";
  144. QUIT = "QUIT\r\n";
  145. flags |= FLAG_SSL;
  146. PORT = 995;
  147. }
  148. else if (!strncmp(SERVICE, "SSMTP", 5)) {
  149. EXPECT = "220";
  150. QUIT = "QUIT\r\n";
  151. flags |= FLAG_SSL;
  152. PORT = 465;
  153. }
  154. else if (!strncmp(SERVICE, "JABBER", 6)) {
  155. SEND = "<stream:stream to=\'host\' xmlns=\'jabber:client\' xmlns:stream=\'http://etherx.jabber.org/streams\'>\n";
  156. EXPECT = "<?xml version=\'1.0\'?><stream:stream xmlns=\'jabber:client\' xmlns:stream=\'http://etherx.jabber.org/streams\'";
  157. QUIT = "</stream:stream>\n";
  158. flags |= FLAG_HIDE_OUTPUT;
  159. PORT = 5222;
  160. }
  161. else if (!strncmp (SERVICE, "NNTPS", 5)) {
  162. server_expect_count = 2;
  163. server_expect[0] = "200";
  164. server_expect[1] = "201";
  165. QUIT = "QUIT\r\n";
  166. flags |= FLAG_SSL;
  167. PORT = 563;
  168. }
  169. #endif
  170. else if (!strncmp (SERVICE, "NNTP", 4)) {
  171. server_expect_count = 2;
  172. server_expect = malloc(sizeof(char *) * server_expect_count);
  173. server_expect[0] = strdup("200");
  174. server_expect[1] = strdup("201");
  175. QUIT = "QUIT\r\n";
  176. PORT = 119;
  177. }
  178. else if (!strncmp(SERVICE, "CLAMD", 5)) {
  179. SEND = "PING";
  180. EXPECT = "PONG";
  181. QUIT = NULL;
  182. PORT = 3310;
  183. }
  184. /* fallthrough check, so it's supposed to use reverse matching */
  185. else if (strcmp (SERVICE, "TCP"))
  186. usage (_("CRITICAL - Generic check_tcp called with unknown service\n"));
  187. server_address = "127.0.0.1";
  188. server_port = PORT;
  189. server_send = SEND;
  190. server_quit = QUIT;
  191. status = NULL;
  192. /* Parse extra opts if any */
  193. argv=np_extra_opts (&argc, argv, progname);
  194. if (process_arguments (argc, argv) == ERROR)
  195. usage4 (_("Could not parse arguments"));
  196. if(flags & FLAG_VERBOSE) {
  197. printf("Using service %s\n", SERVICE);
  198. printf("Port: %d\n", server_port);
  199. printf("flags: 0x%x\n", (int)flags);
  200. }
  201. if(EXPECT && !server_expect_count)
  202. server_expect_count++;
  203. if(PROTOCOL==IPPROTO_UDP && !(server_expect_count && server_send)){
  204. usage(_("With UDP checks, a send/expect string must be specified."));
  205. }
  206. /* set up the timer */
  207. signal (SIGALRM, socket_timeout_alarm_handler);
  208. alarm (socket_timeout);
  209. /* try to connect to the host at the given port number */
  210. gettimeofday (&tv, NULL);
  211. result = np_net_connect (server_address, server_port, &sd, PROTOCOL);
  212. if (result == STATE_CRITICAL) return STATE_CRITICAL;
  213. #ifdef HAVE_SSL
  214. if (flags & FLAG_SSL){
  215. result = np_net_ssl_init(sd);
  216. if (result == STATE_OK && check_cert == TRUE) {
  217. result = np_net_ssl_check_cert(days_till_exp_warn, days_till_exp_crit);
  218. }
  219. }
  220. if(result != STATE_OK){
  221. np_net_ssl_cleanup();
  222. if(sd) close(sd);
  223. return result;
  224. }
  225. #endif /* HAVE_SSL */
  226. if (server_send != NULL) { /* Something to send? */
  227. my_send(server_send, strlen(server_send));
  228. }
  229. if (delay > 0) {
  230. tv.tv_sec += delay;
  231. sleep (delay);
  232. }
  233. if(flags & FLAG_VERBOSE) {
  234. if (server_send) {
  235. printf("Send string: %s\n", server_send);
  236. }
  237. if (server_quit) {
  238. printf("Quit string: %s\n", server_quit);
  239. }
  240. printf("server_expect_count: %d\n", (int)server_expect_count);
  241. for(i = 0; i < server_expect_count; i++)
  242. printf("\t%d: %s\n", i, server_expect[i]);
  243. }
  244. /* if(len) later on, we know we have a non-NULL response */
  245. len = 0;
  246. if (server_expect_count) {
  247. /* watch for the expect string */
  248. while ((i = my_recv(buffer, sizeof(buffer))) > 0) {
  249. status = realloc(status, len + i + 1);
  250. memcpy(&status[len], buffer, i);
  251. len += i;
  252. /* stop reading if user-forced */
  253. if (maxbytes && len >= maxbytes)
  254. break;
  255. }
  256. /* no data when expected, so return critical */
  257. if (len == 0)
  258. die (STATE_CRITICAL, _("No data received from host\n"));
  259. /* force null-termination and strip whitespace from end of output */
  260. status[len--] = '\0';
  261. /* print raw output if we're debugging */
  262. if(flags & FLAG_VERBOSE)
  263. printf("received %d bytes from host\n#-raw-recv-------#\n%s\n#-raw-recv-------#\n",
  264. (int)len + 1, status);
  265. while(isspace(status[len])) status[len--] = '\0';
  266. match = np_expect_match(status,
  267. server_expect,
  268. server_expect_count,
  269. (flags & FLAG_MATCH_ALL ? TRUE : FALSE),
  270. (flags & FLAG_EXACT_MATCH ? TRUE : FALSE),
  271. (flags & FLAG_VERBOSE ? TRUE : FALSE));
  272. }
  273. if (server_quit != NULL) {
  274. my_send(server_quit, strlen(server_quit));
  275. }
  276. #ifdef HAVE_SSL
  277. np_net_ssl_cleanup();
  278. #endif
  279. if (sd) close (sd);
  280. microsec = deltime (tv);
  281. elapsed_time = (double)microsec / 1.0e6;
  282. if (flags & FLAG_TIME_CRIT && elapsed_time > critical_time)
  283. result = STATE_CRITICAL;
  284. else if (flags & FLAG_TIME_WARN && elapsed_time > warning_time)
  285. result = STATE_WARNING;
  286. /* did we get the response we hoped? */
  287. if(match == FALSE && result != STATE_CRITICAL)
  288. result = expect_mismatch_state;
  289. /* reset the alarm */
  290. alarm (0);
  291. /* this is a bit stupid, because we don't want to print the
  292. * response time (which can look ok to the user) if we didn't get
  293. * the response we were looking for. if-else */
  294. printf("%s %s - ", SERVICE, state_text(result));
  295. if(match == FALSE && len && !(flags & FLAG_HIDE_OUTPUT))
  296. printf("Unexpected response from host/socket: %s", status);
  297. else {
  298. if(match == FALSE)
  299. printf("Unexpected response from host/socket on ");
  300. else
  301. printf("%.3f second response time on ", elapsed_time);
  302. if(server_address[0] != '/')
  303. printf("port %d", server_port);
  304. else
  305. printf("socket %s", server_address);
  306. }
  307. if (match != FALSE && !(flags & FLAG_HIDE_OUTPUT) && len)
  308. printf (" [%s]", status);
  309. /* perf-data doesn't apply when server doesn't talk properly,
  310. * so print all zeroes on warn and crit. Use fperfdata since
  311. * localisation settings can make different outputs */
  312. if(match == FALSE)
  313. printf ("|%s",
  314. fperfdata ("time", elapsed_time, "s",
  315. (flags & FLAG_TIME_WARN ? TRUE : FALSE), 0,
  316. (flags & FLAG_TIME_CRIT ? TRUE : FALSE), 0,
  317. TRUE, 0,
  318. TRUE, socket_timeout)
  319. );
  320. else
  321. printf("|%s",
  322. fperfdata ("time", elapsed_time, "s",
  323. (flags & FLAG_TIME_WARN ? TRUE : FALSE), warning_time,
  324. (flags & FLAG_TIME_CRIT ? TRUE : FALSE), critical_time,
  325. TRUE, 0,
  326. TRUE, socket_timeout)
  327. );
  328. putchar('\n');
  329. return result;
  330. }
  331. /* process command-line arguments */
  332. static int
  333. process_arguments (int argc, char **argv)
  334. {
  335. int c;
  336. int escape = 0;
  337. char *temp;
  338. int option = 0;
  339. static struct option longopts[] = {
  340. {"hostname", required_argument, 0, 'H'},
  341. {"critical", required_argument, 0, 'c'},
  342. {"warning", required_argument, 0, 'w'},
  343. {"critical-codes", required_argument, 0, 'C'},
  344. {"warning-codes", required_argument, 0, 'W'},
  345. {"timeout", required_argument, 0, 't'},
  346. {"protocol", required_argument, 0, 'P'}, /* FIXME: Unhandled */
  347. {"port", required_argument, 0, 'p'},
  348. {"escape", no_argument, 0, 'E'},
  349. {"all", no_argument, 0, 'A'},
  350. {"send", required_argument, 0, 's'},
  351. {"expect", required_argument, 0, 'e'},
  352. {"maxbytes", required_argument, 0, 'm'},
  353. {"quit", required_argument, 0, 'q'},
  354. {"jail", no_argument, 0, 'j'},
  355. {"delay", required_argument, 0, 'd'},
  356. {"refuse", required_argument, 0, 'r'},
  357. {"mismatch", required_argument, 0, 'M'},
  358. {"use-ipv4", no_argument, 0, '4'},
  359. {"use-ipv6", no_argument, 0, '6'},
  360. {"verbose", no_argument, 0, 'v'},
  361. {"version", no_argument, 0, 'V'},
  362. {"help", no_argument, 0, 'h'},
  363. {"ssl", no_argument, 0, 'S'},
  364. {"certificate", required_argument, 0, 'D'},
  365. {0, 0, 0, 0}
  366. };
  367. if (argc < 2)
  368. usage4 (_("No arguments found"));
  369. /* backwards compatibility */
  370. for (c = 1; c < argc; c++) {
  371. if (strcmp ("-to", argv[c]) == 0)
  372. strcpy (argv[c], "-t");
  373. else if (strcmp ("-wt", argv[c]) == 0)
  374. strcpy (argv[c], "-w");
  375. else if (strcmp ("-ct", argv[c]) == 0)
  376. strcpy (argv[c], "-c");
  377. }
  378. if (!is_option (argv[1])) {
  379. server_address = argv[1];
  380. argv[1] = argv[0];
  381. argv = &argv[1];
  382. argc--;
  383. }
  384. while (1) {
  385. c = getopt_long (argc, argv, "+hVv46EAH:s:e:q:m:c:w:t:p:C:W:d:Sr:jD:M:",
  386. longopts, &option);
  387. if (c == -1 || c == EOF || c == 1)
  388. break;
  389. switch (c) {
  390. case '?': /* print short usage statement if args not parsable */
  391. usage5 ();
  392. case 'h': /* help */
  393. print_help ();
  394. exit (STATE_OK);
  395. case 'V': /* version */
  396. print_revision (progname, NP_VERSION);
  397. exit (STATE_OK);
  398. case 'v': /* verbose mode */
  399. flags |= FLAG_VERBOSE;
  400. break;
  401. case '4':
  402. address_family = AF_INET;
  403. break;
  404. case '6':
  405. #ifdef USE_IPV6
  406. address_family = AF_INET6;
  407. #else
  408. usage4 (_("IPv6 support not available"));
  409. #endif
  410. break;
  411. case 'H': /* hostname */
  412. host_specified = TRUE;
  413. server_address = optarg;
  414. break;
  415. case 'c': /* critical */
  416. critical_time = strtod (optarg, NULL);
  417. flags |= FLAG_TIME_CRIT;
  418. break;
  419. case 'j': /* hide output */
  420. flags |= FLAG_HIDE_OUTPUT;
  421. break;
  422. case 'w': /* warning */
  423. warning_time = strtod (optarg, NULL);
  424. flags |= FLAG_TIME_WARN;
  425. break;
  426. case 'C':
  427. crit_codes = realloc (crit_codes, ++crit_codes_count);
  428. crit_codes[crit_codes_count - 1] = optarg;
  429. break;
  430. case 'W':
  431. warn_codes = realloc (warn_codes, ++warn_codes_count);
  432. warn_codes[warn_codes_count - 1] = optarg;
  433. break;
  434. case 't': /* timeout */
  435. if (!is_intpos (optarg))
  436. usage4 (_("Timeout interval must be a positive integer"));
  437. else
  438. socket_timeout = atoi (optarg);
  439. break;
  440. case 'p': /* port */
  441. if (!is_intpos (optarg))
  442. usage4 (_("Port must be a positive integer"));
  443. else
  444. server_port = atoi (optarg);
  445. break;
  446. case 'E':
  447. escape = 1;
  448. break;
  449. case 's':
  450. if (escape)
  451. server_send = np_escaped_string(optarg);
  452. else
  453. xasprintf(&server_send, "%s", optarg);
  454. break;
  455. case 'e': /* expect string (may be repeated) */
  456. flags &= ~FLAG_EXACT_MATCH;
  457. if (server_expect_count == 0)
  458. server_expect = malloc (sizeof (char *) * (++server_expect_count));
  459. else
  460. server_expect = realloc (server_expect, sizeof (char *) * (++server_expect_count));
  461. server_expect[server_expect_count - 1] = optarg;
  462. break;
  463. case 'm':
  464. if (!is_intpos (optarg))
  465. usage4 (_("Maxbytes must be a positive integer"));
  466. else
  467. maxbytes = strtol (optarg, NULL, 0);
  468. break;
  469. case 'q':
  470. if (escape)
  471. server_quit = np_escaped_string(optarg);
  472. else
  473. xasprintf(&server_quit, "%s\r\n", optarg);
  474. break;
  475. case 'r':
  476. if (!strncmp(optarg,"ok",2))
  477. econn_refuse_state = STATE_OK;
  478. else if (!strncmp(optarg,"warn",4))
  479. econn_refuse_state = STATE_WARNING;
  480. else if (!strncmp(optarg,"crit",4))
  481. econn_refuse_state = STATE_CRITICAL;
  482. else
  483. usage4 (_("Refuse must be one of ok, warn, crit"));
  484. break;
  485. case 'M':
  486. if (!strncmp(optarg,"ok",2))
  487. expect_mismatch_state = STATE_OK;
  488. else if (!strncmp(optarg,"warn",4))
  489. expect_mismatch_state = STATE_WARNING;
  490. else if (!strncmp(optarg,"crit",4))
  491. expect_mismatch_state = STATE_CRITICAL;
  492. else
  493. usage4 (_("Mismatch must be one of ok, warn, crit"));
  494. break;
  495. case 'd':
  496. if (is_intpos (optarg))
  497. delay = atoi (optarg);
  498. else
  499. usage4 (_("Delay must be a positive integer"));
  500. break;
  501. case 'D': /* Check SSL cert validity - days 'til certificate expiration */
  502. #ifdef HAVE_SSL
  503. # ifdef USE_OPENSSL /* XXX */
  504. if ((temp=strchr(optarg,','))!=NULL) {
  505. *temp='\0';
  506. if (!is_intnonneg (optarg))
  507. usage2 (_("Invalid certificate expiration period"), optarg); days_till_exp_warn = atoi(optarg);
  508. *temp=',';
  509. temp++;
  510. if (!is_intnonneg (temp))
  511. usage2 (_("Invalid certificate expiration period"), temp);
  512. days_till_exp_crit = atoi (temp);
  513. }
  514. else {
  515. days_till_exp_crit=0;
  516. if (!is_intnonneg (optarg))
  517. usage2 (_("Invalid certificate expiration period"), optarg);
  518. days_till_exp_warn = atoi (optarg);
  519. }
  520. check_cert = TRUE;
  521. flags |= FLAG_SSL;
  522. break;
  523. # endif /* USE_OPENSSL */
  524. #endif
  525. /* fallthrough if we don't have ssl */
  526. case 'S':
  527. #ifdef HAVE_SSL
  528. flags |= FLAG_SSL;
  529. #else
  530. die (STATE_UNKNOWN, _("Invalid option - SSL is not available"));
  531. #endif
  532. break;
  533. case 'A':
  534. flags |= FLAG_MATCH_ALL;
  535. break;
  536. }
  537. }
  538. c = optind;
  539. if(host_specified == FALSE && c < argc)
  540. server_address = strdup (argv[c++]);
  541. if (server_address == NULL)
  542. usage4 (_("You must provide a server address"));
  543. else if (server_address[0] != '/' && is_host (server_address) == FALSE)
  544. die (STATE_CRITICAL, "%s %s - %s: %s\n", SERVICE, state_text(STATE_CRITICAL), _("Invalid hostname, address or socket"), server_address);
  545. return TRUE;
  546. }
  547. void
  548. print_help (void)
  549. {
  550. print_revision (progname, NP_VERSION);
  551. printf ("Copyright (c) 1999 Ethan Galstad <nagios@nagios.org>\n");
  552. printf (COPYRIGHT, copyright, email);
  553. printf (_("This plugin tests %s connections with the specified host (or unix socket).\n\n"),
  554. SERVICE);
  555. print_usage ();
  556. printf (UT_HELP_VRSN);
  557. printf (UT_EXTRA_OPTS);
  558. printf (UT_HOST_PORT, 'p', "none");
  559. printf (UT_IPv46);
  560. printf (" %s\n", "-E, --escape");
  561. printf (" %s\n", _("Can use \\n, \\r, \\t or \\ in send or quit string. Must come before send or quit option"));
  562. printf (" %s\n", _("Default: nothing added to send, \\r\\n added to end of quit"));
  563. printf (" %s\n", "-s, --send=STRING");
  564. printf (" %s\n", _("String to send to the server"));
  565. printf (" %s\n", "-e, --expect=STRING");
  566. printf (" %s %s\n", _("String to expect in server response"), _("(may be repeated)"));
  567. printf (" %s\n", "-A, --all");
  568. printf (" %s\n", _("All expect strings need to occur in server response. Default is any"));
  569. printf (" %s\n", "-q, --quit=STRING");
  570. printf (" %s\n", _("String to send server to initiate a clean close of the connection"));
  571. printf (" %s\n", "-r, --refuse=ok|warn|crit");
  572. printf (" %s\n", _("Accept TCP refusals with states ok, warn, crit (default: crit)"));
  573. printf (" %s\n", "-M, --mismatch=ok|warn|crit");
  574. printf (" %s\n", _("Accept expected string mismatches with states ok, warn, crit (default: warn)"));
  575. printf (" %s\n", "-j, --jail");
  576. printf (" %s\n", _("Hide output from TCP socket"));
  577. printf (" %s\n", "-m, --maxbytes=INTEGER");
  578. printf (" %s\n", _("Close connection once more than this number of bytes are received"));
  579. printf (" %s\n", "-d, --delay=INTEGER");
  580. printf (" %s\n", _("Seconds to wait between sending string and polling for response"));
  581. #ifdef HAVE_SSL
  582. printf (" %s\n", "-D, --certificate=INTEGER[,INTEGER]");
  583. printf (" %s\n", _("Minimum number of days a certificate has to be valid."));
  584. printf (" %s\n", _("1st is #days for warning, 2nd is critical (if not specified - 0)."));
  585. printf (" %s\n", "-S, --ssl");
  586. printf (" %s\n", _("Use SSL for the connection."));
  587. #endif
  588. printf (UT_WARN_CRIT);
  589. printf (UT_TIMEOUT, DEFAULT_SOCKET_TIMEOUT);
  590. printf (UT_VERBOSE);
  591. printf (UT_SUPPORT);
  592. }
  593. void
  594. print_usage (void)
  595. {
  596. printf ("%s\n", _("Usage:"));
  597. printf ("%s -H host -p port [-w <warning time>] [-c <critical time>] [-s <send string>]\n",progname);
  598. printf ("[-e <expect string>] [-q <quit string>][-m <maximum bytes>] [-d <delay>]\n");
  599. printf ("[-t <timeout seconds>] [-r <refuse state>] [-M <mismatch state>] [-v] [-4|-6] [-j]\n");
  600. printf ("[-D <warn days cert expire>[,<crit days cert expire>]] [-S <use SSL>] [-E]\n");
  601. }