check_tcp.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666
  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. /* Parse extra opts if any */
  194. argv=np_extra_opts (&argc, argv, progname);
  195. if (process_arguments (argc, argv) == ERROR)
  196. usage4 (_("Could not parse arguments"));
  197. if(flags & FLAG_VERBOSE) {
  198. printf("Using service %s\n", SERVICE);
  199. printf("Port: %d\n", server_port);
  200. printf("flags: 0x%x\n", (int)flags);
  201. }
  202. if(EXPECT && !server_expect_count)
  203. server_expect_count++;
  204. if(PROTOCOL==IPPROTO_UDP && !(server_expect_count && server_send)){
  205. usage(_("With UDP checks, a send/expect string must be specified."));
  206. }
  207. /* set up the timer */
  208. signal (SIGALRM, socket_timeout_alarm_handler);
  209. alarm (socket_timeout);
  210. /* try to connect to the host at the given port number */
  211. gettimeofday (&tv, NULL);
  212. result = np_net_connect (server_address, server_port, &sd, PROTOCOL);
  213. if (result == STATE_CRITICAL) return STATE_CRITICAL;
  214. #ifdef HAVE_SSL
  215. if (flags & FLAG_SSL){
  216. result = np_net_ssl_init(sd);
  217. if (result == STATE_OK && check_cert == TRUE) {
  218. result = np_net_ssl_check_cert(days_till_exp);
  219. if(result != STATE_OK) {
  220. printf(_("CRITICAL - Cannot retrieve server certificate.\n"));
  221. }
  222. }
  223. }
  224. if(result != STATE_OK){
  225. np_net_ssl_cleanup();
  226. if(sd) close(sd);
  227. return result;
  228. }
  229. #endif /* HAVE_SSL */
  230. if (server_send != NULL) { /* Something to send? */
  231. my_send(server_send, strlen(server_send));
  232. }
  233. if (delay > 0) {
  234. tv.tv_sec += delay;
  235. sleep (delay);
  236. }
  237. if(flags & FLAG_VERBOSE) {
  238. if (server_send) {
  239. printf("Send string: %s\n", server_send);
  240. }
  241. if (server_quit) {
  242. printf("Quit string: %s\n", server_quit);
  243. }
  244. printf("server_expect_count: %d\n", (int)server_expect_count);
  245. for(i = 0; i < server_expect_count; i++)
  246. printf("\t%d: %s\n", i, server_expect[i]);
  247. }
  248. /* if(len) later on, we know we have a non-NULL response */
  249. len = 0;
  250. if (server_expect_count) {
  251. /* watch for the expect string */
  252. while ((i = my_recv(buffer, sizeof(buffer))) > 0) {
  253. status = realloc(status, len + i + 1);
  254. memcpy(&status[len], buffer, i);
  255. len += i;
  256. /* stop reading if user-forced or data-starved */
  257. if(i < sizeof(buffer) || (maxbytes && len >= maxbytes))
  258. break;
  259. if (maxbytes && len >= maxbytes)
  260. break;
  261. }
  262. /* no data when expected, so return critical */
  263. if (len == 0)
  264. die (STATE_CRITICAL, _("No data received from host\n"));
  265. /* force null-termination and strip whitespace from end of output */
  266. status[len--] = '\0';
  267. /* print raw output if we're debugging */
  268. if(flags & FLAG_VERBOSE)
  269. printf("received %d bytes from host\n#-raw-recv-------#\n%s\n#-raw-recv-------#\n",
  270. (int)len + 1, status);
  271. while(isspace(status[len])) status[len--] = '\0';
  272. match = np_expect_match(status,
  273. server_expect,
  274. server_expect_count,
  275. (flags & FLAG_MATCH_ALL ? TRUE : FALSE),
  276. (flags & FLAG_EXACT_MATCH ? TRUE : FALSE),
  277. (flags & FLAG_VERBOSE ? TRUE : FALSE));
  278. }
  279. if (server_quit != NULL) {
  280. my_send(server_quit, strlen(server_quit));
  281. }
  282. #ifdef HAVE_SSL
  283. np_net_ssl_cleanup();
  284. #endif
  285. if (sd) close (sd);
  286. microsec = deltime (tv);
  287. elapsed_time = (double)microsec / 1.0e6;
  288. if (flags & FLAG_TIME_CRIT && elapsed_time > critical_time)
  289. result = STATE_CRITICAL;
  290. else if (flags & FLAG_TIME_WARN && elapsed_time > warning_time)
  291. result = STATE_WARNING;
  292. /* did we get the response we hoped? */
  293. if(match == FALSE && result != STATE_CRITICAL)
  294. result = expect_mismatch_state;
  295. /* reset the alarm */
  296. alarm (0);
  297. /* this is a bit stupid, because we don't want to print the
  298. * response time (which can look ok to the user) if we didn't get
  299. * the response we were looking for. if-else */
  300. printf("%s %s - ", SERVICE, state_text(result));
  301. if(match == FALSE && len && !(flags & FLAG_HIDE_OUTPUT))
  302. printf("Unexpected response from host/socket: %s", status);
  303. else {
  304. if(match == FALSE)
  305. printf("Unexpected response from host/socket on ");
  306. else
  307. printf("%.3f second response time on ", elapsed_time);
  308. if(server_address[0] != '/')
  309. printf("port %d", server_port);
  310. else
  311. printf("socket %s", server_address);
  312. }
  313. if (match != FALSE && !(flags & FLAG_HIDE_OUTPUT) && len)
  314. printf (" [%s]", status);
  315. /* perf-data doesn't apply when server doesn't talk properly,
  316. * so print all zeroes on warn and crit. Use fperfdata since
  317. * localisation settings can make different outputs */
  318. if(match == FALSE)
  319. printf ("|%s",
  320. fperfdata ("time", elapsed_time, "s",
  321. (flags & FLAG_TIME_WARN ? TRUE : FALSE), 0,
  322. (flags & FLAG_TIME_CRIT ? TRUE : FALSE), 0,
  323. TRUE, 0,
  324. TRUE, socket_timeout)
  325. );
  326. else
  327. printf("|%s",
  328. fperfdata ("time", elapsed_time, "s",
  329. (flags & FLAG_TIME_WARN ? TRUE : FALSE), warning_time,
  330. (flags & FLAG_TIME_CRIT ? TRUE : FALSE), critical_time,
  331. TRUE, 0,
  332. TRUE, socket_timeout)
  333. );
  334. putchar('\n');
  335. return result;
  336. }
  337. /* process command-line arguments */
  338. static int
  339. process_arguments (int argc, char **argv)
  340. {
  341. int c;
  342. int escape = 0;
  343. int option = 0;
  344. static struct option longopts[] = {
  345. {"hostname", required_argument, 0, 'H'},
  346. {"critical", required_argument, 0, 'c'},
  347. {"warning", required_argument, 0, 'w'},
  348. {"critical-codes", required_argument, 0, 'C'},
  349. {"warning-codes", required_argument, 0, 'W'},
  350. {"timeout", required_argument, 0, 't'},
  351. {"protocol", required_argument, 0, 'P'}, /* FIXME: Unhandled */
  352. {"port", required_argument, 0, 'p'},
  353. {"escape", no_argument, 0, 'E'},
  354. {"all", no_argument, 0, 'A'},
  355. {"send", required_argument, 0, 's'},
  356. {"expect", required_argument, 0, 'e'},
  357. {"maxbytes", required_argument, 0, 'm'},
  358. {"quit", required_argument, 0, 'q'},
  359. {"jail", no_argument, 0, 'j'},
  360. {"delay", required_argument, 0, 'd'},
  361. {"refuse", required_argument, 0, 'r'},
  362. {"mismatch", required_argument, 0, 'M'},
  363. {"use-ipv4", no_argument, 0, '4'},
  364. {"use-ipv6", no_argument, 0, '6'},
  365. {"verbose", no_argument, 0, 'v'},
  366. {"version", no_argument, 0, 'V'},
  367. {"help", no_argument, 0, 'h'},
  368. {"ssl", no_argument, 0, 'S'},
  369. {"certificate", required_argument, 0, 'D'},
  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_EXTRA_OPTS));
  546. printf (_(UT_HOST_PORT), 'p', "none");
  547. printf (_(UT_IPv46));
  548. printf (" %s\n", "-E, --escape");
  549. printf (" %s\n", _("Can use \\n, \\r, \\t or \\ in send or quit string. Must come before send or quit option"));
  550. printf (" %s\n", _("Default: nothing added to send, \\r\\n added to end of quit"));
  551. printf (" %s\n", "-s, --send=STRING");
  552. printf (" %s\n", _("String to send to the server"));
  553. printf (" %s\n", "-e, --expect=STRING");
  554. printf (" %s %s\n", _("String to expect in server response"), _("(may be repeated)"));
  555. printf (" %s\n", "-A, --all");
  556. printf (" %s\n", _("All expect strings need to occur in server response. Default is any"));
  557. printf (" %s\n", "-q, --quit=STRING");
  558. printf (" %s\n", _("String to send server to initiate a clean close of the connection"));
  559. printf (" %s\n", "-r, --refuse=ok|warn|crit");
  560. printf (" %s\n", _("Accept tcp refusals with states ok, warn, crit (default: crit)"));
  561. printf (" %s\n", "-M, --mismatch=ok|warn|crit");
  562. printf (" %s\n", _("Accept expected string mismatches with states ok, warn, crit (default: warn)"));
  563. printf (" %s\n", "-j, --jail");
  564. printf (" %s\n", _("Hide output from TCP socket"));
  565. printf (" %s\n", "-m, --maxbytes=INTEGER");
  566. printf (" %s\n", _("Close connection once more than this number of bytes are received"));
  567. printf (" %s\n", "-d, --delay=INTEGER");
  568. printf (" %s\n", _("Seconds to wait between sending string and polling for response"));
  569. #ifdef HAVE_SSL
  570. printf (" %s\n", "-D, --certificate=INTEGER");
  571. printf (" %s\n", _("Minimum number of days a certificate has to be valid."));
  572. printf (" %s\n", "-S, --ssl");
  573. printf (" %s\n", _("Use SSL for the connection."));
  574. #endif
  575. printf (_(UT_WARN_CRIT));
  576. printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT);
  577. printf (_(UT_VERBOSE));
  578. #ifdef NP_EXTRA_OPTS
  579. printf ("\n");
  580. printf ("%s\n", _("Notes:"));
  581. printf (_(UT_EXTRA_OPTS_NOTES));
  582. #endif
  583. printf (_(UT_SUPPORT));
  584. }
  585. void
  586. print_usage (void)
  587. {
  588. printf (_("Usage:"));
  589. printf ("%s -H host -p port [-w <warning time>] [-c <critical time>] [-s <send string>]\n",progname);
  590. printf ("[-e <expect string>] [-q <quit string>][-m <maximum bytes>] [-d <delay>]\n");
  591. printf ("[-t <timeout seconds>] [-r <refuse state>] [-M <mismatch state>] [-v] [-4|-6] [-j]\n");
  592. printf ("[-D <days to cert expiry>] [-S <use SSL>] [-E]\n");
  593. }