check_tcp.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668
  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'},
  352. {"port", required_argument, 0, 'p'},
  353. {"escape", required_argument, 0, 'E'},
  354. {"all", required_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. #ifdef HAVE_SSL
  369. {"ssl", no_argument, 0, 'S'},
  370. {"certificate", required_argument, 0, 'D'},
  371. #endif
  372. {0, 0, 0, 0}
  373. };
  374. if (argc < 2)
  375. usage4 (_("No arguments found"));
  376. /* backwards compatibility */
  377. for (c = 1; c < argc; c++) {
  378. if (strcmp ("-to", argv[c]) == 0)
  379. strcpy (argv[c], "-t");
  380. else if (strcmp ("-wt", argv[c]) == 0)
  381. strcpy (argv[c], "-w");
  382. else if (strcmp ("-ct", argv[c]) == 0)
  383. strcpy (argv[c], "-c");
  384. }
  385. if (!is_option (argv[1])) {
  386. server_address = argv[1];
  387. argv[1] = argv[0];
  388. argv = &argv[1];
  389. argc--;
  390. }
  391. while (1) {
  392. c = getopt_long (argc, argv, "+hVv46EAH:s:e:q:m:c:w:t:p:C:W:d:Sr:jD:M:",
  393. longopts, &option);
  394. if (c == -1 || c == EOF || c == 1)
  395. break;
  396. switch (c) {
  397. case '?': /* print short usage statement if args not parsable */
  398. usage5 ();
  399. case 'h': /* help */
  400. print_help ();
  401. exit (STATE_OK);
  402. case 'V': /* version */
  403. print_revision (progname, revision);
  404. exit (STATE_OK);
  405. case 'v': /* verbose mode */
  406. flags |= FLAG_VERBOSE;
  407. break;
  408. case '4':
  409. address_family = AF_INET;
  410. break;
  411. case '6':
  412. #ifdef USE_IPV6
  413. address_family = AF_INET6;
  414. #else
  415. usage4 (_("IPv6 support not available"));
  416. #endif
  417. break;
  418. case 'H': /* hostname */
  419. server_address = optarg;
  420. break;
  421. case 'c': /* critical */
  422. critical_time = strtod (optarg, NULL);
  423. flags |= FLAG_TIME_CRIT;
  424. break;
  425. case 'j': /* hide output */
  426. flags |= FLAG_HIDE_OUTPUT;
  427. break;
  428. case 'w': /* warning */
  429. warning_time = strtod (optarg, NULL);
  430. flags |= FLAG_TIME_WARN;
  431. break;
  432. case 'C':
  433. crit_codes = realloc (crit_codes, ++crit_codes_count);
  434. crit_codes[crit_codes_count - 1] = optarg;
  435. break;
  436. case 'W':
  437. warn_codes = realloc (warn_codes, ++warn_codes_count);
  438. warn_codes[warn_codes_count - 1] = optarg;
  439. break;
  440. case 't': /* timeout */
  441. if (!is_intpos (optarg))
  442. usage4 (_("Timeout interval must be a positive integer"));
  443. else
  444. socket_timeout = atoi (optarg);
  445. break;
  446. case 'p': /* port */
  447. if (!is_intpos (optarg))
  448. usage4 (_("Port must be a positive integer"));
  449. else
  450. server_port = atoi (optarg);
  451. break;
  452. case 'E':
  453. escape = 1;
  454. break;
  455. case 's':
  456. if (escape)
  457. server_send = np_escaped_string(optarg);
  458. else
  459. asprintf(&server_send, "%s", optarg);
  460. break;
  461. case 'e': /* expect string (may be repeated) */
  462. flags &= ~FLAG_EXACT_MATCH;
  463. if (server_expect_count == 0)
  464. server_expect = malloc (sizeof (char *) * (++server_expect_count));
  465. else
  466. server_expect = realloc (server_expect, sizeof (char *) * (++server_expect_count));
  467. server_expect[server_expect_count - 1] = optarg;
  468. break;
  469. case 'm':
  470. if (!is_intpos (optarg))
  471. usage4 (_("Maxbytes must be a positive integer"));
  472. else
  473. maxbytes = strtol (optarg, NULL, 0);
  474. break;
  475. case 'q':
  476. if (escape)
  477. server_quit = np_escaped_string(optarg);
  478. else
  479. asprintf(&server_quit, "%s\r\n", optarg);
  480. break;
  481. case 'r':
  482. if (!strncmp(optarg,"ok",2))
  483. econn_refuse_state = STATE_OK;
  484. else if (!strncmp(optarg,"warn",4))
  485. econn_refuse_state = STATE_WARNING;
  486. else if (!strncmp(optarg,"crit",4))
  487. econn_refuse_state = STATE_CRITICAL;
  488. else
  489. usage4 (_("Refuse must be one of ok, warn, crit"));
  490. break;
  491. case 'M':
  492. if (!strncmp(optarg,"ok",2))
  493. expect_mismatch_state = STATE_OK;
  494. else if (!strncmp(optarg,"warn",4))
  495. expect_mismatch_state = STATE_WARNING;
  496. else if (!strncmp(optarg,"crit",4))
  497. expect_mismatch_state = STATE_CRITICAL;
  498. else
  499. usage4 (_("Mismatch must be one of ok, warn, crit"));
  500. break;
  501. case 'd':
  502. if (is_intpos (optarg))
  503. delay = atoi (optarg);
  504. else
  505. usage4 (_("Delay must be a positive integer"));
  506. break;
  507. case 'D': /* Check SSL cert validity - days 'til certificate expiration */
  508. #ifdef HAVE_SSL
  509. # ifdef USE_OPENSSL /* XXX */
  510. if (!is_intnonneg (optarg))
  511. usage2 (_("Invalid certificate expiration period"), optarg);
  512. days_till_exp = atoi (optarg);
  513. check_cert = TRUE;
  514. flags |= FLAG_SSL;
  515. break;
  516. # endif /* USE_OPENSSL */
  517. #endif
  518. /* fallthrough if we don't have ssl */
  519. case 'S':
  520. #ifdef HAVE_SSL
  521. flags |= FLAG_SSL;
  522. #else
  523. die (STATE_UNKNOWN, _("Invalid option - SSL is not available"));
  524. #endif
  525. break;
  526. case 'A':
  527. flags |= FLAG_MATCH_ALL;
  528. break;
  529. }
  530. }
  531. if (server_address == NULL)
  532. usage4 (_("You must provide a server address"));
  533. else if (server_address[0] != '/' && is_host (server_address) == FALSE)
  534. die (STATE_CRITICAL, "%s %s - %s: %s\n", SERVICE, state_text(STATE_CRITICAL), _("Invalid hostname, address or socket"), server_address);
  535. return TRUE;
  536. }
  537. void
  538. print_help (void)
  539. {
  540. print_revision (progname, revision);
  541. printf ("Copyright (c) 1999 Ethan Galstad <nagios@nagios.org>\n");
  542. printf (COPYRIGHT, copyright, email);
  543. printf (_("This plugin tests %s connections with the specified host (or unix socket).\n\n"),
  544. SERVICE);
  545. print_usage ();
  546. printf (_(UT_HELP_VRSN));
  547. printf (_(UT_EXTRA_OPTS));
  548. printf (_(UT_HOST_PORT), 'p', "none");
  549. printf (_(UT_IPv46));
  550. printf (" %s\n", "-E, --escape");
  551. printf (" %s\n", _("Can use \\n, \\r, \\t or \\ in send or quit string. Must come before send or quit option"));
  552. printf (" %s\n", _("Default: nothing added to send, \\r\\n added to end of quit"));
  553. printf (" %s\n", "-s, --send=STRING");
  554. printf (" %s\n", _("String to send to the server"));
  555. printf (" %s\n", "-e, --expect=STRING");
  556. printf (" %s %s\n", _("String to expect in server response"), _("(may be repeated)"));
  557. printf (" %s\n", "-A, --all");
  558. printf (" %s\n", _("All expect strings need to occur in server response. Default is any"));
  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. #ifdef NP_EXTRA_OPTS
  581. printf ("\n");
  582. printf ("%s\n", _("Notes:"));
  583. printf (_(UT_EXTRA_OPTS_NOTES));
  584. #endif
  585. printf (_(UT_SUPPORT));
  586. }
  587. void
  588. print_usage (void)
  589. {
  590. printf (_("Usage:"));
  591. printf ("%s -H host -p port [-w <warning time>] [-c <critical time>] [-s <send string>]\n",progname);
  592. printf ("[-e <expect string>] [-q <quit string>][-m <maximum bytes>] [-d <delay>]\n");
  593. printf ("[-t <timeout seconds>] [-r <refuse state>] [-M <mismatch state>] [-v] [-4|-6] [-j]\n");
  594. printf ("[-D <days to cert expiry>] [-S <use SSL>] [-E]\n");
  595. }