check_tcp.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662
  1. /*****************************************************************************
  2. *
  3. * Nagios check_tcp plugin
  4. *
  5. * License: GPL
  6. * Copyright (c) 1999-2006 nagios-plugins team
  7. *
  8. * Last Modified: $Date$
  9. *
  10. * Description:
  11. *
  12. * This file contains the check_tcp plugin
  13. *
  14. * License Information:
  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 2 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, write to the Free Software
  28. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  29. *
  30. * $Id$
  31. *
  32. *****************************************************************************/
  33. /* progname "check_tcp" changes depending on symlink called */
  34. char *progname;
  35. const char *revision = "$Revision$";
  36. const char *copyright = "1999-2006";
  37. const char *email = "nagiosplug-devel@lists.sourceforge.net";
  38. #include "common.h"
  39. #include "netutils.h"
  40. #include "utils.h"
  41. #ifdef HAVE_SSL
  42. static int check_cert = FALSE;
  43. static int days_till_exp;
  44. # define my_recv(buf, len) ((flags & FLAG_SSL) ? np_net_ssl_read(buf, len) : read(sd, buf, len))
  45. # define my_send(buf, len) ((flags & FLAG_SSL) ? np_net_ssl_write(buf, len) : send(sd, buf, len, 0))
  46. #else
  47. # define my_recv(buf, len) read(sd, buf, len)
  48. # define my_send(buf, len) send(sd, buf, len, 0)
  49. #endif
  50. /* int my_recv(char *, size_t); */
  51. static int process_arguments (int, char **);
  52. void print_help (void);
  53. void print_usage (void);
  54. #define EXPECT server_expect[0]
  55. static char *SERVICE = "TCP";
  56. static char *SEND = NULL;
  57. static char *QUIT = NULL;
  58. static int PROTOCOL = IPPROTO_TCP; /* most common is default */
  59. static int PORT = 0;
  60. static int server_port = 0;
  61. static char *server_address = NULL;
  62. static char *server_send = NULL;
  63. static char *server_quit = NULL;
  64. static char **server_expect;
  65. static size_t server_expect_count = 0;
  66. static size_t maxbytes = 0;
  67. static char **warn_codes = NULL;
  68. static size_t warn_codes_count = 0;
  69. static char **crit_codes = NULL;
  70. static size_t crit_codes_count = 0;
  71. static unsigned int delay = 0;
  72. static double warning_time = 0;
  73. static double critical_time = 0;
  74. static double elapsed_time = 0;
  75. static long microsec;
  76. static int sd = 0;
  77. #define MAXBUF 1024
  78. static char buffer[MAXBUF];
  79. static int expect_mismatch_state = STATE_WARNING;
  80. #define FLAG_SSL 0x01
  81. #define FLAG_VERBOSE 0x02
  82. #define FLAG_EXACT_MATCH 0x04
  83. #define FLAG_TIME_WARN 0x08
  84. #define FLAG_TIME_CRIT 0x10
  85. #define FLAG_HIDE_OUTPUT 0x20
  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, 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. if (process_arguments (argc, argv) == ERROR)
  193. usage4 (_("Could not parse arguments"));
  194. if(flags & FLAG_VERBOSE) {
  195. printf("Using service %s\n", SERVICE);
  196. printf("Port: %d\n", server_port);
  197. printf("flags: 0x%x\n", (int)flags);
  198. }
  199. if(EXPECT && !server_expect_count)
  200. server_expect_count++;
  201. if(PROTOCOL==IPPROTO_UDP && !(server_expect_count && server_send)){
  202. usage(_("With UDP checks, a send/expect string must be specified."));
  203. }
  204. /* set up the timer */
  205. signal (SIGALRM, socket_timeout_alarm_handler);
  206. alarm (socket_timeout);
  207. /* try to connect to the host at the given port number */
  208. gettimeofday (&tv, NULL);
  209. result = np_net_connect (server_address, server_port, &sd, PROTOCOL);
  210. if (result == STATE_CRITICAL) return STATE_CRITICAL;
  211. #ifdef HAVE_SSL
  212. if (flags & FLAG_SSL){
  213. result = np_net_ssl_init(sd);
  214. if (result == STATE_OK && check_cert == TRUE) {
  215. result = np_net_ssl_check_cert(days_till_exp);
  216. if(result != STATE_OK) {
  217. printf(_("CRITICAL - Cannot retrieve server certificate.\n"));
  218. }
  219. }
  220. }
  221. if(result != STATE_OK){
  222. np_net_ssl_cleanup();
  223. if(sd) close(sd);
  224. return result;
  225. }
  226. #endif /* HAVE_SSL */
  227. if (server_send != NULL) { /* Something to send? */
  228. my_send(server_send, strlen(server_send));
  229. }
  230. if (delay > 0) {
  231. tv.tv_sec += delay;
  232. sleep (delay);
  233. }
  234. if(flags & FLAG_VERBOSE) {
  235. if (server_send) {
  236. printf("Send string: %s\n", server_send);
  237. }
  238. if (server_quit) {
  239. printf("Quit string: %s\n", server_quit);
  240. }
  241. printf("server_expect_count: %d\n", (int)server_expect_count);
  242. for(i = 0; i < server_expect_count; i++)
  243. printf("\t%d: %s\n", i, server_expect[i]);
  244. }
  245. /* if(len) later on, we know we have a non-NULL response */
  246. len = 0;
  247. if (server_expect_count) {
  248. /* watch for the expect string */
  249. while ((i = my_recv(buffer, sizeof(buffer))) > 0) {
  250. status = realloc(status, len + i + 1);
  251. memcpy(&status[len], buffer, i);
  252. len += i;
  253. /* stop reading if user-forced or data-starved */
  254. if(i < sizeof(buffer) || (maxbytes && len >= maxbytes))
  255. break;
  256. if (maxbytes && len >= maxbytes)
  257. break;
  258. }
  259. /* no data when expected, so return critical */
  260. if (len == 0)
  261. die (STATE_CRITICAL, _("No data received from host\n"));
  262. /* force null-termination and strip whitespace from end of output */
  263. status[len--] = '\0';
  264. /* print raw output if we're debugging */
  265. if(flags & FLAG_VERBOSE)
  266. printf("received %d bytes from host\n#-raw-recv-------#\n%s\n#-raw-recv-------#\n",
  267. (int)len + 1, status);
  268. while(isspace(status[len])) status[len--] = '\0';
  269. for (i = 0; i < server_expect_count; i++) {
  270. match = -2; /* tag it so we know if we tried and failed */
  271. if (flags & FLAG_VERBOSE)
  272. printf ("looking for [%s] %s [%s]\n", server_expect[i],
  273. (flags & FLAG_EXACT_MATCH) ? "in beginning of" : "anywhere in",
  274. status);
  275. /* match it. math first in short-circuit */
  276. if ((flags & FLAG_EXACT_MATCH && !strncmp(status, server_expect[i], strlen(server_expect[i]))) ||
  277. (!(flags & FLAG_EXACT_MATCH) && strstr(status, server_expect[i])))
  278. {
  279. if(flags & FLAG_VERBOSE) puts("found it");
  280. match = i;
  281. break;
  282. }
  283. }
  284. }
  285. if (server_quit != NULL) {
  286. my_send(server_quit, strlen(server_quit));
  287. }
  288. #ifdef HAVE_SSL
  289. np_net_ssl_cleanup();
  290. #endif
  291. if (sd) close (sd);
  292. microsec = deltime (tv);
  293. elapsed_time = (double)microsec / 1.0e6;
  294. if (flags & FLAG_TIME_CRIT && elapsed_time > critical_time)
  295. result = STATE_CRITICAL;
  296. else if (flags & FLAG_TIME_WARN && elapsed_time > warning_time)
  297. result = STATE_WARNING;
  298. /* did we get the response we hoped? */
  299. if(match == -2 && result != STATE_CRITICAL)
  300. result = expect_mismatch_state;
  301. /* reset the alarm */
  302. alarm (0);
  303. /* this is a bit stupid, because we don't want to print the
  304. * response time (which can look ok to the user) if we didn't get
  305. * the response we were looking for. if-else */
  306. printf("%s %s - ", SERVICE, state_text(result));
  307. if(match == -2 && len && !(flags & FLAG_HIDE_OUTPUT))
  308. printf("Unexpected response from host/socket: %s", status);
  309. else {
  310. if(match == -2)
  311. printf("Unexpected response from host/socket on ");
  312. else
  313. printf("%.3f second response time on ", elapsed_time);
  314. if(server_address[0] != '/')
  315. printf("port %d", server_port);
  316. else
  317. printf("socket %s", server_address);
  318. }
  319. if (match != -2 && !(flags & FLAG_HIDE_OUTPUT) && len)
  320. printf (" [%s]", status);
  321. /* perf-data doesn't apply when server doesn't talk properly,
  322. * so print all zeroes on warn and crit. Use fperfdata since
  323. * localisation settings can make different outputs */
  324. if(match == -2)
  325. printf ("|%s",
  326. fperfdata ("time", elapsed_time, "s",
  327. TRUE, 0,
  328. TRUE, 0,
  329. TRUE, 0,
  330. TRUE, socket_timeout)
  331. );
  332. else
  333. printf("|%s",
  334. fperfdata ("time", elapsed_time, "s",
  335. TRUE, warning_time,
  336. TRUE, critical_time,
  337. TRUE, 0,
  338. TRUE, socket_timeout)
  339. );
  340. putchar('\n');
  341. return result;
  342. }
  343. /* process command-line arguments */
  344. static int
  345. process_arguments (int argc, char **argv)
  346. {
  347. int c;
  348. int escape = 0;
  349. int option = 0;
  350. static struct option longopts[] = {
  351. {"hostname", required_argument, 0, 'H'},
  352. {"critical", required_argument, 0, 'c'},
  353. {"warning", required_argument, 0, 'w'},
  354. {"critical-codes", required_argument, 0, 'C'},
  355. {"warning-codes", required_argument, 0, 'W'},
  356. {"timeout", required_argument, 0, 't'},
  357. {"protocol", required_argument, 0, 'P'},
  358. {"port", required_argument, 0, 'p'},
  359. {"escape", required_argument, 0, 'E'},
  360. {"send", required_argument, 0, 's'},
  361. {"expect", required_argument, 0, 'e'},
  362. {"maxbytes", required_argument, 0, 'm'},
  363. {"quit", required_argument, 0, 'q'},
  364. {"jail", no_argument, 0, 'j'},
  365. {"delay", required_argument, 0, 'd'},
  366. {"refuse", required_argument, 0, 'r'},
  367. {"mismatch", required_argument, 0, 'M'},
  368. {"use-ipv4", no_argument, 0, '4'},
  369. {"use-ipv6", no_argument, 0, '6'},
  370. {"verbose", no_argument, 0, 'v'},
  371. {"version", no_argument, 0, 'V'},
  372. {"help", no_argument, 0, 'h'},
  373. #ifdef HAVE_SSL
  374. {"ssl", no_argument, 0, 'S'},
  375. {"certificate", required_argument, 0, 'D'},
  376. #endif
  377. {0, 0, 0, 0}
  378. };
  379. if (argc < 2)
  380. usage4 (_("No arguments found"));
  381. /* backwards compatibility */
  382. for (c = 1; c < argc; c++) {
  383. if (strcmp ("-to", argv[c]) == 0)
  384. strcpy (argv[c], "-t");
  385. else if (strcmp ("-wt", argv[c]) == 0)
  386. strcpy (argv[c], "-w");
  387. else if (strcmp ("-ct", argv[c]) == 0)
  388. strcpy (argv[c], "-c");
  389. }
  390. if (!is_option (argv[1])) {
  391. server_address = argv[1];
  392. argv[1] = argv[0];
  393. argv = &argv[1];
  394. argc--;
  395. }
  396. while (1) {
  397. c = getopt_long (argc, argv, "+hVv46EH:s:e:q:m:c:w:t:p:C:W:d:Sr:jD:M:",
  398. longopts, &option);
  399. if (c == -1 || c == EOF || c == 1)
  400. break;
  401. switch (c) {
  402. case '?': /* print short usage statement if args not parsable */
  403. usage5 ();
  404. case 'h': /* help */
  405. print_help ();
  406. exit (STATE_OK);
  407. case 'V': /* version */
  408. print_revision (progname, revision);
  409. exit (STATE_OK);
  410. case 'v': /* verbose mode */
  411. flags |= FLAG_VERBOSE;
  412. break;
  413. case '4':
  414. address_family = AF_INET;
  415. break;
  416. case '6':
  417. #ifdef USE_IPV6
  418. address_family = AF_INET6;
  419. #else
  420. usage4 (_("IPv6 support not available"));
  421. #endif
  422. break;
  423. case 'H': /* hostname */
  424. server_address = optarg;
  425. break;
  426. case 'c': /* critical */
  427. critical_time = strtod (optarg, NULL);
  428. flags |= FLAG_TIME_CRIT;
  429. break;
  430. case 'j': /* hide output */
  431. flags |= FLAG_HIDE_OUTPUT;
  432. break;
  433. case 'w': /* warning */
  434. warning_time = strtod (optarg, NULL);
  435. flags |= FLAG_TIME_WARN;
  436. break;
  437. case 'C':
  438. crit_codes = realloc (crit_codes, ++crit_codes_count);
  439. crit_codes[crit_codes_count - 1] = optarg;
  440. break;
  441. case 'W':
  442. warn_codes = realloc (warn_codes, ++warn_codes_count);
  443. warn_codes[warn_codes_count - 1] = optarg;
  444. break;
  445. case 't': /* timeout */
  446. if (!is_intpos (optarg))
  447. usage4 (_("Timeout interval must be a positive integer"));
  448. else
  449. socket_timeout = atoi (optarg);
  450. break;
  451. case 'p': /* port */
  452. if (!is_intpos (optarg))
  453. usage4 (_("Port must be a positive integer"));
  454. else
  455. server_port = atoi (optarg);
  456. break;
  457. case 'E':
  458. escape = 1;
  459. break;
  460. case 's':
  461. if (escape)
  462. server_send = np_escaped_string(optarg);
  463. else
  464. asprintf(&server_send, "%s", optarg);
  465. break;
  466. case 'e': /* expect string (may be repeated) */
  467. EXPECT = NULL;
  468. flags &= ~FLAG_EXACT_MATCH;
  469. if (server_expect_count == 0)
  470. server_expect = malloc (sizeof (char *) * (++server_expect_count));
  471. else
  472. server_expect = realloc (server_expect, sizeof (char *) * (++server_expect_count));
  473. server_expect[server_expect_count - 1] = optarg;
  474. break;
  475. case 'm':
  476. if (!is_intpos (optarg))
  477. usage4 (_("Maxbytes must be a positive integer"));
  478. else
  479. maxbytes = strtol (optarg, NULL, 0);
  480. break;
  481. case 'q':
  482. if (escape)
  483. server_quit = np_escaped_string(optarg);
  484. else
  485. asprintf(&server_quit, "%s\r\n", optarg);
  486. break;
  487. case 'r':
  488. if (!strncmp(optarg,"ok",2))
  489. econn_refuse_state = STATE_OK;
  490. else if (!strncmp(optarg,"warn",4))
  491. econn_refuse_state = STATE_WARNING;
  492. else if (!strncmp(optarg,"crit",4))
  493. econn_refuse_state = STATE_CRITICAL;
  494. else
  495. usage4 (_("Refuse must be one of ok, warn, crit"));
  496. break;
  497. case 'M':
  498. if (!strncmp(optarg,"ok",2))
  499. expect_mismatch_state = STATE_OK;
  500. else if (!strncmp(optarg,"warn",4))
  501. expect_mismatch_state = STATE_WARNING;
  502. else if (!strncmp(optarg,"crit",4))
  503. expect_mismatch_state = STATE_CRITICAL;
  504. else
  505. usage4 (_("Mismatch must be one of ok, warn, crit"));
  506. break;
  507. case 'd':
  508. if (is_intpos (optarg))
  509. delay = atoi (optarg);
  510. else
  511. usage4 (_("Delay must be a positive integer"));
  512. break;
  513. case 'D': /* Check SSL cert validity - days 'til certificate expiration */
  514. #ifdef HAVE_SSL
  515. # ifdef USE_OPENSSL /* XXX */
  516. if (!is_intnonneg (optarg))
  517. usage2 (_("Invalid certificate expiration period"), optarg);
  518. days_till_exp = atoi (optarg);
  519. check_cert = TRUE;
  520. flags |= FLAG_SSL;
  521. break;
  522. # endif /* USE_OPENSSL */
  523. #endif
  524. /* fallthrough if we don't have ssl */
  525. case 'S':
  526. #ifdef HAVE_SSL
  527. flags |= FLAG_SSL;
  528. #else
  529. die (STATE_UNKNOWN, _("Invalid option - SSL is not available"));
  530. #endif
  531. break;
  532. }
  533. }
  534. if (server_address == NULL)
  535. usage4 (_("You must provide a server address"));
  536. else if (server_address[0] != '/' && is_host (server_address) == FALSE)
  537. die (STATE_CRITICAL, "%s %s - %s: %s\n", SERVICE, state_text(STATE_CRITICAL), _("Invalid hostname, address or socket"), server_address);
  538. return TRUE;
  539. }
  540. void
  541. print_help (void)
  542. {
  543. print_revision (progname, revision);
  544. printf ("Copyright (c) 1999 Ethan Galstad <nagios@nagios.org>\n");
  545. printf (COPYRIGHT, copyright, email);
  546. printf (_("This plugin tests %s connections with the specified host (or unix socket).\n\n"),
  547. SERVICE);
  548. print_usage ();
  549. printf (_(UT_HELP_VRSN));
  550. printf (_(UT_HOST_PORT), 'p', "none");
  551. printf (_(UT_IPv46));
  552. printf (" %s\n", "-E, --escape");
  553. printf (" %s\n", _("Can use \\n, \\r, \\t or \\ in send or quit string. Must come before send or quit option"));
  554. printf (" %s\n", _("Default: nothing added to send, \\r\\n added to end of quit"));
  555. printf (" %s\n", "-s, --send=STRING");
  556. printf (" %s\n", _("String to send to the server"));
  557. printf (" %s\n", "-e, --expect=STRING");
  558. printf (" %s\n", _("String to expect in server response"));
  559. printf (" %s\n", "-q, --quit=STRING");
  560. printf (" %s\n", _("String to send server to initiate a clean close of the connection"));
  561. printf (" %s\n", "-r, --refuse=ok|warn|crit");
  562. printf (" %s\n", _("Accept tcp refusals with states ok, warn, crit (default: crit)"));
  563. printf (" %s\n", "-M, --mismatch=ok|warn|crit");
  564. printf (" %s\n", _("Accept expected string mismatches with states ok, warn, crit (default: warn)"));
  565. printf (" %s\n", "-j, --jail");
  566. printf (" %s\n", _("Hide output from TCP socket"));
  567. printf (" %s\n", "-m, --maxbytes=INTEGER");
  568. printf (" %s\n", _("Close connection once more than this number of bytes are received"));
  569. printf (" %s\n", "-d, --delay=INTEGER");
  570. printf (" %s\n", _("Seconds to wait between sending string and polling for response"));
  571. #ifdef HAVE_SSL
  572. printf (" %s\n", "-D, --certificate=INTEGER");
  573. printf (" %s\n", _("Minimum number of days a certificate has to be valid."));
  574. printf (" %s\n", "-S, --ssl");
  575. printf (" %s\n", _("Use SSL for the connection."));
  576. #endif
  577. printf (_(UT_WARN_CRIT));
  578. printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT);
  579. printf (_(UT_VERBOSE));
  580. printf (_(UT_SUPPORT));
  581. }
  582. void
  583. print_usage (void)
  584. {
  585. printf (_("Usage:"));
  586. printf ("%s -H host -p port [-w <warning time>] [-c <critical time>] [-s <send string>]\n",progname);
  587. printf ("[-e <expect string>] [-q <quit string>][-m <maximum bytes>] [-d <delay>]\n");
  588. printf ("[-t <timeout seconds>] [-r <refuse state>] [-M <mismatch state>] [-v] [-4|-6] [-j]\n");
  589. printf ("[-D <days to cert expiry>] [-S <use SSL>] [-E]\n");
  590. }