check_tcp.c 19 KB

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