check_tcp.c 19 KB

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