check_tcp.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654
  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 "common.h"
  34. #include "netutils.h"
  35. #include "utils.h"
  36. #include "utils_tcp.h"
  37. #ifdef HAVE_SSL
  38. static int check_cert = FALSE;
  39. static int days_till_exp;
  40. # define my_recv(buf, len) ((flags & FLAG_SSL) ? np_net_ssl_read(buf, len) : read(sd, buf, len))
  41. # define my_send(buf, len) ((flags & FLAG_SSL) ? np_net_ssl_write(buf, len) : send(sd, buf, len, 0))
  42. #else
  43. # define my_recv(buf, len) read(sd, buf, len)
  44. # define my_send(buf, len) send(sd, buf, len, 0)
  45. #endif
  46. /* int my_recv(char *, size_t); */
  47. static int process_arguments (int, char **);
  48. void print_help (void);
  49. void print_usage (void);
  50. #define EXPECT server_expect[0]
  51. static char *SERVICE = "TCP";
  52. static char *SEND = NULL;
  53. static char *QUIT = NULL;
  54. static int PROTOCOL = IPPROTO_TCP; /* most common is default */
  55. static int PORT = 0;
  56. static int server_port = 0;
  57. static char *server_address = NULL;
  58. static char *server_send = NULL;
  59. static char *server_quit = NULL;
  60. static char **server_expect;
  61. static size_t server_expect_count = 0;
  62. static size_t maxbytes = 0;
  63. static char **warn_codes = NULL;
  64. static size_t warn_codes_count = 0;
  65. static char **crit_codes = NULL;
  66. static size_t crit_codes_count = 0;
  67. static unsigned int delay = 0;
  68. static double warning_time = 0;
  69. static double critical_time = 0;
  70. static double elapsed_time = 0;
  71. static long microsec;
  72. static int sd = 0;
  73. #define MAXBUF 1024
  74. static char buffer[MAXBUF];
  75. static int expect_mismatch_state = STATE_WARNING;
  76. #define FLAG_SSL 0x01
  77. #define FLAG_VERBOSE 0x02
  78. #define FLAG_EXACT_MATCH 0x04
  79. #define FLAG_TIME_WARN 0x08
  80. #define FLAG_TIME_CRIT 0x10
  81. #define FLAG_HIDE_OUTPUT 0x20
  82. #define FLAG_MATCH_ALL 0x40
  83. static size_t flags = FLAG_EXACT_MATCH;
  84. int
  85. main (int argc, char **argv)
  86. {
  87. int result = STATE_UNKNOWN;
  88. int i;
  89. char *status = NULL;
  90. struct timeval tv;
  91. size_t len;
  92. int match = -1;
  93. setlocale (LC_ALL, "");
  94. bindtextdomain (PACKAGE, LOCALEDIR);
  95. textdomain (PACKAGE);
  96. /* determine program- and service-name quickly */
  97. progname = strrchr(argv[0], '/');
  98. if(progname != NULL) progname++;
  99. else progname = argv[0];
  100. len = strlen(progname);
  101. if(len > 6 && !memcmp(progname, "check_", 6)) {
  102. SERVICE = strdup(progname + 6);
  103. for(i = 0; i < len - 6; i++)
  104. SERVICE[i] = toupper(SERVICE[i]);
  105. }
  106. /* set up a resonable buffer at first (will be realloc()'ed if
  107. * user specifies other options) */
  108. server_expect = calloc(sizeof(char *), 2);
  109. /* determine defaults for this service's protocol */
  110. if (!strncmp(SERVICE, "UDP", 3)) {
  111. PROTOCOL = IPPROTO_UDP;
  112. }
  113. else if (!strncmp(SERVICE, "FTP", 3)) {
  114. EXPECT = "220";
  115. QUIT = "QUIT\r\n";
  116. PORT = 21;
  117. }
  118. else if (!strncmp(SERVICE, "POP", 3) || !strncmp(SERVICE, "POP3", 4)) {
  119. EXPECT = "+OK";
  120. QUIT = "QUIT\r\n";
  121. PORT = 110;
  122. }
  123. else if (!strncmp(SERVICE, "SMTP", 4)) {
  124. EXPECT = "220";
  125. QUIT = "QUIT\r\n";
  126. PORT = 25;
  127. }
  128. else if (!strncmp(SERVICE, "IMAP", 4)) {
  129. EXPECT = "* OK";
  130. QUIT = "a1 LOGOUT\r\n";
  131. PORT = 143;
  132. }
  133. #ifdef HAVE_SSL
  134. else if (!strncmp(SERVICE, "SIMAP", 5)) {
  135. EXPECT = "* OK";
  136. QUIT = "a1 LOGOUT\r\n";
  137. flags |= FLAG_SSL;
  138. PORT = 993;
  139. }
  140. else if (!strncmp(SERVICE, "SPOP", 4)) {
  141. EXPECT = "+OK";
  142. QUIT = "QUIT\r\n";
  143. flags |= FLAG_SSL;
  144. PORT = 995;
  145. }
  146. else if (!strncmp(SERVICE, "SSMTP", 5)) {
  147. EXPECT = "220";
  148. QUIT = "QUIT\r\n";
  149. flags |= FLAG_SSL;
  150. PORT = 465;
  151. }
  152. else if (!strncmp(SERVICE, "JABBER", 6)) {
  153. SEND = "<stream:stream to=\'host\' xmlns=\'jabber:client\' xmlns:stream=\'http://etherx.jabber.org/streams\'>\n";
  154. EXPECT = "<?xml version=\'1.0\'?><stream:stream xmlns=\'jabber:client\' xmlns:stream=\'http://etherx.jabber.org/streams\'";
  155. QUIT = "</stream:stream>\n";
  156. flags |= FLAG_HIDE_OUTPUT;
  157. PORT = 5222;
  158. }
  159. else if (!strncmp (SERVICE, "NNTPS", 5)) {
  160. server_expect_count = 2;
  161. server_expect[0] = "200";
  162. server_expect[1] = "201";
  163. QUIT = "QUIT\r\n";
  164. flags |= FLAG_SSL;
  165. PORT = 563;
  166. }
  167. #endif
  168. else if (!strncmp (SERVICE, "NNTP", 4)) {
  169. server_expect_count = 2;
  170. server_expect = malloc(sizeof(char *) * server_expect_count);
  171. server_expect[0] = strdup("200");
  172. server_expect[1] = strdup("201");
  173. QUIT = "QUIT\r\n";
  174. PORT = 119;
  175. }
  176. else if (!strncmp(SERVICE, "CLAMD", 5)) {
  177. SEND = "PING";
  178. EXPECT = "PONG";
  179. QUIT = NULL;
  180. PORT = 3310;
  181. }
  182. /* fallthrough check, so it's supposed to use reverse matching */
  183. else if (strcmp (SERVICE, "TCP"))
  184. usage (_("CRITICAL - Generic check_tcp called with unknown service\n"));
  185. server_address = "127.0.0.1";
  186. server_port = PORT;
  187. server_send = SEND;
  188. server_quit = QUIT;
  189. status = NULL;
  190. /* Parse extra opts if any */
  191. argv=np_extra_opts (&argc, argv, progname);
  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. }
  217. }
  218. if(result != STATE_OK || check_cert == TRUE){
  219. np_net_ssl_cleanup();
  220. if(sd) close(sd);
  221. return result;
  222. }
  223. #endif /* HAVE_SSL */
  224. if (server_send != NULL) { /* Something to send? */
  225. my_send(server_send, strlen(server_send));
  226. }
  227. if (delay > 0) {
  228. tv.tv_sec += delay;
  229. sleep (delay);
  230. }
  231. if(flags & FLAG_VERBOSE) {
  232. if (server_send) {
  233. printf("Send string: %s\n", server_send);
  234. }
  235. if (server_quit) {
  236. printf("Quit string: %s\n", server_quit);
  237. }
  238. printf("server_expect_count: %d\n", (int)server_expect_count);
  239. for(i = 0; i < server_expect_count; i++)
  240. printf("\t%d: %s\n", i, server_expect[i]);
  241. }
  242. /* if(len) later on, we know we have a non-NULL response */
  243. len = 0;
  244. if (server_expect_count) {
  245. /* watch for the expect string */
  246. while ((i = my_recv(buffer, sizeof(buffer))) > 0) {
  247. status = realloc(status, len + i + 1);
  248. memcpy(&status[len], buffer, i);
  249. len += i;
  250. /* stop reading if user-forced or data-starved */
  251. if(i < sizeof(buffer) || (maxbytes && len >= maxbytes))
  252. break;
  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. int option = 0;
  338. static struct option longopts[] = {
  339. {"hostname", required_argument, 0, 'H'},
  340. {"critical", required_argument, 0, 'c'},
  341. {"warning", required_argument, 0, 'w'},
  342. {"critical-codes", required_argument, 0, 'C'},
  343. {"warning-codes", required_argument, 0, 'W'},
  344. {"timeout", required_argument, 0, 't'},
  345. {"protocol", required_argument, 0, 'P'}, /* FIXME: Unhandled */
  346. {"port", required_argument, 0, 'p'},
  347. {"escape", no_argument, 0, 'E'},
  348. {"all", no_argument, 0, 'A'},
  349. {"send", required_argument, 0, 's'},
  350. {"expect", required_argument, 0, 'e'},
  351. {"maxbytes", required_argument, 0, 'm'},
  352. {"quit", required_argument, 0, 'q'},
  353. {"jail", no_argument, 0, 'j'},
  354. {"delay", required_argument, 0, 'd'},
  355. {"refuse", required_argument, 0, 'r'},
  356. {"mismatch", required_argument, 0, 'M'},
  357. {"use-ipv4", no_argument, 0, '4'},
  358. {"use-ipv6", no_argument, 0, '6'},
  359. {"verbose", no_argument, 0, 'v'},
  360. {"version", no_argument, 0, 'V'},
  361. {"help", no_argument, 0, 'h'},
  362. {"ssl", no_argument, 0, 'S'},
  363. {"certificate", required_argument, 0, 'D'},
  364. {0, 0, 0, 0}
  365. };
  366. if (argc < 2)
  367. usage4 (_("No arguments found"));
  368. /* backwards compatibility */
  369. for (c = 1; c < argc; c++) {
  370. if (strcmp ("-to", argv[c]) == 0)
  371. strcpy (argv[c], "-t");
  372. else if (strcmp ("-wt", argv[c]) == 0)
  373. strcpy (argv[c], "-w");
  374. else if (strcmp ("-ct", argv[c]) == 0)
  375. strcpy (argv[c], "-c");
  376. }
  377. if (!is_option (argv[1])) {
  378. server_address = argv[1];
  379. argv[1] = argv[0];
  380. argv = &argv[1];
  381. argc--;
  382. }
  383. while (1) {
  384. c = getopt_long (argc, argv, "+hVv46EAH:s:e:q:m:c:w:t:p:C:W:d:Sr:jD:M:",
  385. longopts, &option);
  386. if (c == -1 || c == EOF || c == 1)
  387. break;
  388. switch (c) {
  389. case '?': /* print short usage statement if args not parsable */
  390. usage5 ();
  391. case 'h': /* help */
  392. print_help ();
  393. exit (STATE_OK);
  394. case 'V': /* version */
  395. print_revision (progname, NP_VERSION);
  396. exit (STATE_OK);
  397. case 'v': /* verbose mode */
  398. flags |= FLAG_VERBOSE;
  399. break;
  400. case '4':
  401. address_family = AF_INET;
  402. break;
  403. case '6':
  404. #ifdef USE_IPV6
  405. address_family = AF_INET6;
  406. #else
  407. usage4 (_("IPv6 support not available"));
  408. #endif
  409. break;
  410. case 'H': /* hostname */
  411. server_address = optarg;
  412. break;
  413. case 'c': /* critical */
  414. critical_time = strtod (optarg, NULL);
  415. flags |= FLAG_TIME_CRIT;
  416. break;
  417. case 'j': /* hide output */
  418. flags |= FLAG_HIDE_OUTPUT;
  419. break;
  420. case 'w': /* warning */
  421. warning_time = strtod (optarg, NULL);
  422. flags |= FLAG_TIME_WARN;
  423. break;
  424. case 'C':
  425. crit_codes = realloc (crit_codes, ++crit_codes_count);
  426. crit_codes[crit_codes_count - 1] = optarg;
  427. break;
  428. case 'W':
  429. warn_codes = realloc (warn_codes, ++warn_codes_count);
  430. warn_codes[warn_codes_count - 1] = optarg;
  431. break;
  432. case 't': /* timeout */
  433. if (!is_intpos (optarg))
  434. usage4 (_("Timeout interval must be a positive integer"));
  435. else
  436. socket_timeout = atoi (optarg);
  437. break;
  438. case 'p': /* port */
  439. if (!is_intpos (optarg))
  440. usage4 (_("Port must be a positive integer"));
  441. else
  442. server_port = atoi (optarg);
  443. break;
  444. case 'E':
  445. escape = 1;
  446. break;
  447. case 's':
  448. if (escape)
  449. server_send = np_escaped_string(optarg);
  450. else
  451. asprintf(&server_send, "%s", optarg);
  452. break;
  453. case 'e': /* expect string (may be repeated) */
  454. flags &= ~FLAG_EXACT_MATCH;
  455. if (server_expect_count == 0)
  456. server_expect = malloc (sizeof (char *) * (++server_expect_count));
  457. else
  458. server_expect = realloc (server_expect, sizeof (char *) * (++server_expect_count));
  459. server_expect[server_expect_count - 1] = optarg;
  460. break;
  461. case 'm':
  462. if (!is_intpos (optarg))
  463. usage4 (_("Maxbytes must be a positive integer"));
  464. else
  465. maxbytes = strtol (optarg, NULL, 0);
  466. break;
  467. case 'q':
  468. if (escape)
  469. server_quit = np_escaped_string(optarg);
  470. else
  471. asprintf(&server_quit, "%s\r\n", optarg);
  472. break;
  473. case 'r':
  474. if (!strncmp(optarg,"ok",2))
  475. econn_refuse_state = STATE_OK;
  476. else if (!strncmp(optarg,"warn",4))
  477. econn_refuse_state = STATE_WARNING;
  478. else if (!strncmp(optarg,"crit",4))
  479. econn_refuse_state = STATE_CRITICAL;
  480. else
  481. usage4 (_("Refuse must be one of ok, warn, crit"));
  482. break;
  483. case 'M':
  484. if (!strncmp(optarg,"ok",2))
  485. expect_mismatch_state = STATE_OK;
  486. else if (!strncmp(optarg,"warn",4))
  487. expect_mismatch_state = STATE_WARNING;
  488. else if (!strncmp(optarg,"crit",4))
  489. expect_mismatch_state = STATE_CRITICAL;
  490. else
  491. usage4 (_("Mismatch must be one of ok, warn, crit"));
  492. break;
  493. case 'd':
  494. if (is_intpos (optarg))
  495. delay = atoi (optarg);
  496. else
  497. usage4 (_("Delay must be a positive integer"));
  498. break;
  499. case 'D': /* Check SSL cert validity - days 'til certificate expiration */
  500. #ifdef HAVE_SSL
  501. # ifdef USE_OPENSSL /* XXX */
  502. if (!is_intnonneg (optarg))
  503. usage2 (_("Invalid certificate expiration period"), optarg);
  504. days_till_exp = atoi (optarg);
  505. check_cert = TRUE;
  506. flags |= FLAG_SSL;
  507. break;
  508. # endif /* USE_OPENSSL */
  509. #endif
  510. /* fallthrough if we don't have ssl */
  511. case 'S':
  512. #ifdef HAVE_SSL
  513. flags |= FLAG_SSL;
  514. #else
  515. die (STATE_UNKNOWN, _("Invalid option - SSL is not available"));
  516. #endif
  517. break;
  518. case 'A':
  519. flags |= FLAG_MATCH_ALL;
  520. break;
  521. }
  522. }
  523. if (server_address == NULL)
  524. usage4 (_("You must provide a server address"));
  525. else if (server_address[0] != '/' && is_host (server_address) == FALSE)
  526. die (STATE_CRITICAL, "%s %s - %s: %s\n", SERVICE, state_text(STATE_CRITICAL), _("Invalid hostname, address or socket"), server_address);
  527. return TRUE;
  528. }
  529. void
  530. print_help (void)
  531. {
  532. print_revision (progname, NP_VERSION);
  533. printf ("Copyright (c) 1999 Ethan Galstad <nagios@nagios.org>\n");
  534. printf (COPYRIGHT, copyright, email);
  535. printf (_("This plugin tests %s connections with the specified host (or unix socket).\n\n"),
  536. SERVICE);
  537. print_usage ();
  538. printf (UT_HELP_VRSN);
  539. printf (UT_EXTRA_OPTS);
  540. printf (UT_HOST_PORT, 'p', "none");
  541. printf (UT_IPv46);
  542. printf (" %s\n", "-E, --escape");
  543. printf (" %s\n", _("Can use \\n, \\r, \\t or \\ in send or quit string. Must come before send or quit option"));
  544. printf (" %s\n", _("Default: nothing added to send, \\r\\n added to end of quit"));
  545. printf (" %s\n", "-s, --send=STRING");
  546. printf (" %s\n", _("String to send to the server"));
  547. printf (" %s\n", "-e, --expect=STRING");
  548. printf (" %s %s\n", _("String to expect in server response"), _("(may be repeated)"));
  549. printf (" %s\n", "-A, --all");
  550. printf (" %s\n", _("All expect strings need to occur in server response. Default is any"));
  551. printf (" %s\n", "-q, --quit=STRING");
  552. printf (" %s\n", _("String to send server to initiate a clean close of the connection"));
  553. printf (" %s\n", "-r, --refuse=ok|warn|crit");
  554. printf (" %s\n", _("Accept TCP refusals with states ok, warn, crit (default: crit)"));
  555. printf (" %s\n", "-M, --mismatch=ok|warn|crit");
  556. printf (" %s\n", _("Accept expected string mismatches with states ok, warn, crit (default: warn)"));
  557. printf (" %s\n", "-j, --jail");
  558. printf (" %s\n", _("Hide output from TCP socket"));
  559. printf (" %s\n", "-m, --maxbytes=INTEGER");
  560. printf (" %s\n", _("Close connection once more than this number of bytes are received"));
  561. printf (" %s\n", "-d, --delay=INTEGER");
  562. printf (" %s\n", _("Seconds to wait between sending string and polling for response"));
  563. #ifdef HAVE_SSL
  564. printf (" %s\n", "-D, --certificate=INTEGER");
  565. printf (" %s\n", _("Minimum number of days a certificate has to be valid."));
  566. printf (" %s\n", "-S, --ssl");
  567. printf (" %s\n", _("Use SSL for the connection."));
  568. #endif
  569. printf (UT_WARN_CRIT);
  570. printf (UT_TIMEOUT, DEFAULT_SOCKET_TIMEOUT);
  571. printf (UT_VERBOSE);
  572. printf (UT_SUPPORT);
  573. }
  574. void
  575. print_usage (void)
  576. {
  577. printf ("%s\n", _("Usage:"));
  578. printf ("%s -H host -p port [-w <warning time>] [-c <critical time>] [-s <send string>]\n",progname);
  579. printf ("[-e <expect string>] [-q <quit string>][-m <maximum bytes>] [-d <delay>]\n");
  580. printf ("[-t <timeout seconds>] [-r <refuse state>] [-M <mismatch state>] [-v] [-4|-6] [-j]\n");
  581. printf ("[-D <days to cert expiry>] [-S <use SSL>] [-E]\n");
  582. }