check_tcp.c 20 KB

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