check_tcp.c 19 KB

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