check_tcp.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689
  1. /*****************************************************************************
  2. *
  3. * Nagios check_tcp plugin
  4. *
  5. * License: GPL
  6. * Copyright (c) 1999-2013 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 = "devel@nagios-plugins.org";
  33. #include <ctype.h>
  34. #include "common.h"
  35. #include "netutils.h"
  36. #include "utils.h"
  37. #include "utils_tcp.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\'?><stream:stream xmlns=\'jabber:client\' xmlns:stream=\'http://etherx.jabber.org/streams\'";
  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 (socket_timeout);
  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) { /* 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. 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. printf("port %d", server_port);
  316. else
  317. printf("socket %s", server_address);
  318. }
  319. if (match != NP_MATCH_FAILURE && !(flags & FLAG_HIDE_OUTPUT) && len)
  320. printf (" [%s]", status);
  321. /* perf-data doesn't apply when server doesn't talk properly,
  322. * so print all zeroes on warn and crit. Use fperfdata since
  323. * localisation settings can make different outputs */
  324. if(match == NP_MATCH_FAILURE)
  325. printf ("|%s",
  326. fperfdata ("time", elapsed_time, "s",
  327. (flags & FLAG_TIME_WARN ? TRUE : FALSE), 0,
  328. (flags & FLAG_TIME_CRIT ? TRUE : FALSE), 0,
  329. TRUE, 0,
  330. TRUE, socket_timeout)
  331. );
  332. else
  333. printf("|%s",
  334. fperfdata ("time", elapsed_time, "s",
  335. (flags & FLAG_TIME_WARN ? TRUE : FALSE), warning_time,
  336. (flags & FLAG_TIME_CRIT ? TRUE : FALSE), critical_time,
  337. TRUE, 0,
  338. TRUE, socket_timeout)
  339. );
  340. putchar('\n');
  341. return result;
  342. }
  343. /* process command-line arguments */
  344. static int
  345. process_arguments (int argc, char **argv)
  346. {
  347. int c;
  348. int escape = 0;
  349. char *temp;
  350. int option = 0;
  351. static struct option longopts[] = {
  352. {"hostname", required_argument, 0, 'H'},
  353. {"critical", required_argument, 0, 'c'},
  354. {"warning", required_argument, 0, 'w'},
  355. {"critical-codes", required_argument, 0, 'C'},
  356. {"warning-codes", required_argument, 0, 'W'},
  357. {"timeout", required_argument, 0, 't'},
  358. {"protocol", required_argument, 0, 'P'}, /* FIXME: Unhandled */
  359. {"port", required_argument, 0, 'p'},
  360. {"escape", no_argument, 0, 'E'},
  361. {"all", no_argument, 0, 'A'},
  362. {"send", required_argument, 0, 's'},
  363. {"expect", required_argument, 0, 'e'},
  364. {"maxbytes", required_argument, 0, 'm'},
  365. {"quit", required_argument, 0, 'q'},
  366. {"jail", no_argument, 0, 'j'},
  367. {"delay", required_argument, 0, 'd'},
  368. {"refuse", required_argument, 0, 'r'},
  369. {"mismatch", required_argument, 0, 'M'},
  370. {"use-ipv4", no_argument, 0, '4'},
  371. {"use-ipv6", no_argument, 0, '6'},
  372. {"verbose", no_argument, 0, 'v'},
  373. {"version", no_argument, 0, 'V'},
  374. {"help", no_argument, 0, 'h'},
  375. {"ssl", no_argument, 0, 'S'},
  376. {"certificate", required_argument, 0, 'D'},
  377. {0, 0, 0, 0}
  378. };
  379. if (argc < 2)
  380. usage4 (_("No arguments found"));
  381. /* backwards compatibility */
  382. for (c = 1; c < argc; c++) {
  383. if (strcmp ("-to", argv[c]) == 0)
  384. strcpy (argv[c], "-t");
  385. else if (strcmp ("-wt", argv[c]) == 0)
  386. strcpy (argv[c], "-w");
  387. else if (strcmp ("-ct", argv[c]) == 0)
  388. strcpy (argv[c], "-c");
  389. }
  390. if (!is_option (argv[1])) {
  391. server_address = argv[1];
  392. argv[1] = argv[0];
  393. argv = &argv[1];
  394. argc--;
  395. }
  396. while (1) {
  397. c = getopt_long (argc, argv, "+hVv46EAH:s:e:q:m:c:w:t:p:C:W:d:Sr:jD:M:",
  398. longopts, &option);
  399. if (c == -1 || c == EOF || c == 1)
  400. break;
  401. switch (c) {
  402. case '?': /* print short usage statement if args not parsable */
  403. usage5 ();
  404. case 'h': /* help */
  405. print_help ();
  406. exit (STATE_OK);
  407. case 'V': /* version */
  408. print_revision (progname, NP_VERSION);
  409. exit (STATE_OK);
  410. case 'v': /* verbose mode */
  411. flags |= FLAG_VERBOSE;
  412. match_flags |= NP_MATCH_VERBOSE;
  413. break;
  414. case '4':
  415. address_family = AF_INET;
  416. break;
  417. case '6':
  418. #ifdef USE_IPV6
  419. address_family = AF_INET6;
  420. #else
  421. usage4 (_("IPv6 support not available"));
  422. #endif
  423. break;
  424. case 'H': /* hostname */
  425. host_specified = TRUE;
  426. server_address = optarg;
  427. break;
  428. case 'c': /* critical */
  429. critical_time = strtod (optarg, NULL);
  430. flags |= FLAG_TIME_CRIT;
  431. break;
  432. case 'j': /* hide output */
  433. flags |= FLAG_HIDE_OUTPUT;
  434. break;
  435. case 'w': /* warning */
  436. warning_time = strtod (optarg, NULL);
  437. flags |= FLAG_TIME_WARN;
  438. break;
  439. case 'C':
  440. crit_codes = realloc (crit_codes, ++crit_codes_count);
  441. crit_codes[crit_codes_count - 1] = optarg;
  442. break;
  443. case 'W':
  444. warn_codes = realloc (warn_codes, ++warn_codes_count);
  445. warn_codes[warn_codes_count - 1] = optarg;
  446. break;
  447. case 't': /* timeout */
  448. if (!is_intpos (optarg))
  449. usage4 (_("Timeout interval must be a positive integer"));
  450. else
  451. socket_timeout = atoi (optarg);
  452. break;
  453. case 'p': /* port */
  454. if (!is_intpos (optarg))
  455. usage4 (_("Port must be a positive integer"));
  456. else
  457. server_port = atoi (optarg);
  458. break;
  459. case 'E':
  460. escape = 1;
  461. break;
  462. case 's':
  463. if (escape)
  464. server_send = np_escaped_string(optarg);
  465. else
  466. xasprintf(&server_send, "%s", optarg);
  467. break;
  468. case 'e': /* expect string (may be repeated) */
  469. match_flags &= ~NP_MATCH_EXACT;
  470. if (server_expect_count == 0)
  471. server_expect = malloc (sizeof (char *) * (++server_expect_count));
  472. else
  473. server_expect = realloc (server_expect, sizeof (char *) * (++server_expect_count));
  474. server_expect[server_expect_count - 1] = optarg;
  475. break;
  476. case 'm':
  477. if (!is_intpos (optarg))
  478. usage4 (_("Maxbytes must be a positive integer"));
  479. else
  480. maxbytes = strtol (optarg, NULL, 0);
  481. break;
  482. case 'q':
  483. if (escape)
  484. server_quit = np_escaped_string(optarg);
  485. else
  486. xasprintf(&server_quit, "%s\r\n", optarg);
  487. break;
  488. case 'r':
  489. if (!strncmp(optarg,"ok",2))
  490. econn_refuse_state = STATE_OK;
  491. else if (!strncmp(optarg,"warn",4))
  492. econn_refuse_state = STATE_WARNING;
  493. else if (!strncmp(optarg,"crit",4))
  494. econn_refuse_state = STATE_CRITICAL;
  495. else
  496. usage4 (_("Refuse must be one of ok, warn, crit"));
  497. break;
  498. case 'M':
  499. if (!strncmp(optarg,"ok",2))
  500. expect_mismatch_state = STATE_OK;
  501. else if (!strncmp(optarg,"warn",4))
  502. expect_mismatch_state = STATE_WARNING;
  503. else if (!strncmp(optarg,"crit",4))
  504. expect_mismatch_state = STATE_CRITICAL;
  505. else
  506. usage4 (_("Mismatch must be one of ok, warn, crit"));
  507. break;
  508. case 'd':
  509. if (is_intpos (optarg))
  510. delay = atoi (optarg);
  511. else
  512. usage4 (_("Delay must be a positive integer"));
  513. break;
  514. case 'D': /* Check SSL cert validity - days 'til certificate expiration */
  515. #ifdef HAVE_SSL
  516. # ifdef USE_OPENSSL /* XXX */
  517. if ((temp=strchr(optarg,','))!=NULL) {
  518. *temp='\0';
  519. if (!is_intnonneg (optarg))
  520. usage2 (_("Invalid certificate expiration period"), optarg); days_till_exp_warn = atoi(optarg);
  521. *temp=',';
  522. temp++;
  523. if (!is_intnonneg (temp))
  524. usage2 (_("Invalid certificate expiration period"), temp);
  525. days_till_exp_crit = atoi (temp);
  526. }
  527. else {
  528. days_till_exp_crit=0;
  529. if (!is_intnonneg (optarg))
  530. usage2 (_("Invalid certificate expiration period"), optarg);
  531. days_till_exp_warn = atoi (optarg);
  532. }
  533. check_cert = TRUE;
  534. flags |= FLAG_SSL;
  535. break;
  536. # endif /* USE_OPENSSL */
  537. #endif
  538. /* fallthrough if we don't have ssl */
  539. case 'S':
  540. #ifdef HAVE_SSL
  541. flags |= FLAG_SSL;
  542. #else
  543. die (STATE_UNKNOWN, _("Invalid option - SSL is not available"));
  544. #endif
  545. break;
  546. case 'A':
  547. match_flags |= NP_MATCH_ALL;
  548. break;
  549. }
  550. }
  551. c = optind;
  552. if(host_specified == FALSE && c < argc)
  553. server_address = strdup (argv[c++]);
  554. if (server_address == NULL)
  555. usage4 (_("You must provide a server address"));
  556. else if (server_address[0] != '/' && is_host (server_address) == FALSE)
  557. die (STATE_CRITICAL, "%s %s - %s: %s\n", SERVICE, state_text(STATE_CRITICAL), _("Invalid hostname, address or socket"), server_address);
  558. return TRUE;
  559. }
  560. void
  561. print_help (void)
  562. {
  563. print_revision (progname, NP_VERSION);
  564. printf ("Copyright (c) 1999 Ethan Galstad <nagios@nagios.org>\n");
  565. printf (COPYRIGHT, copyright, email);
  566. printf (_("This plugin tests %s connections with the specified host (or unix socket).\n\n"),
  567. SERVICE);
  568. print_usage ();
  569. printf (UT_HELP_VRSN);
  570. printf (UT_EXTRA_OPTS);
  571. printf (UT_HOST_PORT, 'p', "none");
  572. printf (UT_IPv46);
  573. printf (" %s\n", "-E, --escape");
  574. printf (" %s\n", _("Can use \\n, \\r, \\t or \\ in send or quit string. Must come before send or quit option"));
  575. printf (" %s\n", _("Default: nothing added to send, \\r\\n added to end of quit"));
  576. printf (" %s\n", "-s, --send=STRING");
  577. printf (" %s\n", _("String to send to the server"));
  578. printf (" %s\n", "-e, --expect=STRING");
  579. printf (" %s %s\n", _("String to expect in server response"), _("(may be repeated)"));
  580. printf (" %s\n", "-A, --all");
  581. printf (" %s\n", _("All expect strings need to occur in server response. Default is any"));
  582. printf (" %s\n", "-q, --quit=STRING");
  583. printf (" %s\n", _("String to send server to initiate a clean close of the connection"));
  584. printf (" %s\n", "-r, --refuse=ok|warn|crit");
  585. printf (" %s\n", _("Accept TCP refusals with states ok, warn, crit (default: crit)"));
  586. printf (" %s\n", "-M, --mismatch=ok|warn|crit");
  587. printf (" %s\n", _("Accept expected string mismatches with states ok, warn, crit (default: warn)"));
  588. printf (" %s\n", "-j, --jail");
  589. printf (" %s\n", _("Hide output from TCP socket"));
  590. printf (" %s\n", "-m, --maxbytes=INTEGER");
  591. printf (" %s\n", _("Close connection once more than this number of bytes are received"));
  592. printf (" %s\n", "-d, --delay=INTEGER");
  593. printf (" %s\n", _("Seconds to wait between sending string and polling for response"));
  594. #ifdef HAVE_SSL
  595. printf (" %s\n", "-D, --certificate=INTEGER[,INTEGER]");
  596. printf (" %s\n", _("Minimum number of days a certificate has to be valid."));
  597. printf (" %s\n", _("1st is #days for warning, 2nd is critical (if not specified - 0)."));
  598. printf (" %s\n", "-S, --ssl");
  599. printf (" %s\n", _("Use SSL for the connection."));
  600. #endif
  601. printf (UT_WARN_CRIT);
  602. printf (UT_CONN_TIMEOUT, DEFAULT_SOCKET_TIMEOUT);
  603. printf (UT_VERBOSE);
  604. printf (UT_SUPPORT);
  605. }
  606. void
  607. print_usage (void)
  608. {
  609. printf ("%s\n", _("Usage:"));
  610. printf ("%s -H host -p port [-w <warning time>] [-c <critical time>] [-s <send string>]\n",progname);
  611. printf ("[-e <expect string>] [-q <quit string>][-m <maximum bytes>] [-d <delay>]\n");
  612. printf ("[-t <timeout seconds>] [-r <refuse state>] [-M <mismatch state>] [-v] [-4|-6] [-j]\n");
  613. printf ("[-D <warn days cert expire>[,<crit days cert expire>]] [-S <use SSL>] [-E]\n");
  614. }