summaryrefslogtreecommitdiffstats
path: root/plugins/check_smtp.c
diff options
context:
space:
mode:
authorTon Voon <ton.voon@opsera.com>2011-07-15 15:48:45 (GMT)
committerTon Voon <ton.voon@opsera.com>2011-07-15 15:48:45 (GMT)
commite7f6da0211d1ee86f76ad5c3a36c6d58d53b1091 (patch)
treee1694c0f73a5cc582ff61ce54b250ed2b966feae /plugins/check_smtp.c
parent5ebe25fc24d33cf2d7b46fce9e746a58e0115010 (diff)
downloadmonitoring-plugins-e7f6da0211d1ee86f76ad5c3a36c6d58d53b1091.tar.gz
New option to check_smtp to ignore failures when sending QUIT (#3358348 - Duncan Ferguson)
Diffstat (limited to 'plugins/check_smtp.c')
-rw-r--r--plugins/check_smtp.c30
1 files changed, 26 insertions, 4 deletions
diff --git a/plugins/check_smtp.c b/plugins/check_smtp.c
index ed49163..6c5994c 100644
--- a/plugins/check_smtp.c
+++ b/plugins/check_smtp.c
@@ -114,6 +114,7 @@ enum {
114 TCP_PROTOCOL = 1, 114 TCP_PROTOCOL = 1,
115 UDP_PROTOCOL = 2, 115 UDP_PROTOCOL = 2,
116}; 116};
117int ignore_send_quit_failure = FALSE;
117 118
118 119
119int 120int
@@ -129,6 +130,9 @@ main (int argc, char **argv)
129 char *error_msg = ""; 130 char *error_msg = "";
130 struct timeval tv; 131 struct timeval tv;
131 132
133 /* Catch pipe errors in read/write - sometimes occurs when writing QUIT */
134 (void) signal (SIGPIPE, SIG_IGN);
135
132 setlocale (LC_ALL, ""); 136 setlocale (LC_ALL, "");
133 bindtextdomain (PACKAGE, LOCALEDIR); 137 bindtextdomain (PACKAGE, LOCALEDIR);
134 textdomain (PACKAGE); 138 textdomain (PACKAGE);
@@ -476,6 +480,7 @@ process_arguments (int argc, char **argv)
476 {"help", no_argument, 0, 'h'}, 480 {"help", no_argument, 0, 'h'},
477 {"starttls",no_argument,0,'S'}, 481 {"starttls",no_argument,0,'S'},
478 {"certificate",required_argument,0,'D'}, 482 {"certificate",required_argument,0,'D'},
483 {"ignore-quit-failure",no_argument,0,'q'},
479 {0, 0, 0, 0} 484 {0, 0, 0, 0}
480 }; 485 };
481 486
@@ -492,7 +497,7 @@ process_arguments (int argc, char **argv)
492 } 497 }
493 498
494 while (1) { 499 while (1) {
495 c = getopt_long (argc, argv, "+hVv46t:p:f:e:c:w:H:C:R:SD:F:A:U:P:", 500 c = getopt_long (argc, argv, "+hVv46t:p:f:e:c:w:H:C:R:SD:F:A:U:P:q",
496 longopts, &option); 501 longopts, &option);
497 502
498 if (c == -1 || c == EOF) 503 if (c == -1 || c == EOF)
@@ -579,6 +584,9 @@ process_arguments (int argc, char **argv)
579 case 'v': /* verbose */ 584 case 'v': /* verbose */
580 verbose++; 585 verbose++;
581 break; 586 break;
587 case 'q':
588 ignore_send_quit_failure++; /* ignore problem sending QUIT */
589 break;
582 case 't': /* timeout */ 590 case 't': /* timeout */
583 if (is_intnonneg (optarg)) { 591 if (is_intnonneg (optarg)) {
584 socket_timeout = atoi (optarg); 592 socket_timeout = atoi (optarg);
@@ -662,8 +670,20 @@ void
662smtp_quit(void) 670smtp_quit(void)
663{ 671{
664 int bytes; 672 int bytes;
673 int n;
674
675 n = my_send(SMTP_QUIT, strlen(SMTP_QUIT));
676 if(n < 0) {
677 if(ignore_send_quit_failure) {
678 if(verbose) {
679 printf(_("Connection closed by server before sending QUIT command\n"));
680 }
681 return;
682 }
683 die (STATE_UNKNOWN,
684 _("Connection closed by server before sending QUIT command\n"));
685 }
665 686
666 my_send(SMTP_QUIT, strlen(SMTP_QUIT));
667 if (verbose) 687 if (verbose)
668 printf(_("sent %s\n"), "QUIT"); 688 printf(_("sent %s\n"), "QUIT");
669 689
@@ -797,7 +817,9 @@ print_help (void)
797 printf (" %s\n", _("SMTP AUTH username")); 817 printf (" %s\n", _("SMTP AUTH username"));
798 printf (" %s\n", "-P, --authpass=STRING"); 818 printf (" %s\n", "-P, --authpass=STRING");
799 printf (" %s\n", _("SMTP AUTH password")); 819 printf (" %s\n", _("SMTP AUTH password"));
800 820 printf (" %s\n", "-q, --ignore-quit-failure");
821 printf (" %s\n", _("Ignore failure when sending QUIT command to server"));
822
801 printf (UT_WARN_CRIT); 823 printf (UT_WARN_CRIT);
802 824
803 printf (UT_TIMEOUT, DEFAULT_SOCKET_TIMEOUT); 825 printf (UT_TIMEOUT, DEFAULT_SOCKET_TIMEOUT);
@@ -821,6 +843,6 @@ print_usage (void)
821 printf ("%s\n", _("Usage:")); 843 printf ("%s\n", _("Usage:"));
822 printf ("%s -H host [-p port] [-e expect] [-C command] [-f from addr]", progname); 844 printf ("%s -H host [-p port] [-e expect] [-C command] [-f from addr]", progname);
823 printf ("[-A authtype -U authuser -P authpass] [-w warn] [-c crit] [-t timeout]\n"); 845 printf ("[-A authtype -U authuser -P authpass] [-w warn] [-c crit] [-t timeout]\n");
824 printf ("[-F fqdn] [-S] [-D days] [-v] [-4|-6]\n"); 846 printf ("[-F fqdn] [-S] [-D days] [-v] [-4|-6] [-q]\n");
825} 847}
826 848