Bug#821207: [nagios-plugins-contrib] check_smtp_send fails when sending with --tls

2020-09-25 Thread Gabriel Filion
Hi there,

This bug is still present and it's annoying that we can't use the plugin
with tls connections because of it. There hasn't been any movement
upstream for 8 years now unfortunately.

But, thanks to Jan's input, I've tried a simple workaround of just
commenting out all of the calls to the problematic $smtp->message()
calls and it made the script work again.

I'm attaching the patch that I used for the workaround.
--- /usr/lib/nagios/plugins/check_smtp_send.orig	2020-09-25 15:36:59.291283004 -0400
+++ /usr/lib/nagios/plugins/check_smtp_send	2020-09-25 15:37:38.739800192 -0400
@@ -149,26 +149,26 @@
 	if( $tls and $auth_method ) {
 		$smtp_port = $default_smtp_tls_port unless $smtp_port;
 		$smtp = TLS_auth->new($smtp_server, Timeout=>$timeout, Port=>$smtp_port, User=>$username, Password=>$password, Auth_Method=>$auth_method);
-		if( $smtp ) {
-			my $message = oneline($smtp->message());
-			die "cannot connect with TLS/$auth_method: $message" if $smtp->code() =~ m/53\d/;
-		}
+		#if( $smtp ) {
+		#	my $message = oneline($smtp->message());
+		#	die "cannot connect with TLS/$auth_method: $message" if $smtp->code() =~ m/53\d/;
+		#}
 	}
 	elsif( $tls ) {
 		$smtp_port = $default_smtp_tls_port unless $smtp_port;
 		$smtp = Net::SMTP::TLS->new($smtp_server, Timeout=>$timeout, Port=>$smtp_port, User=>$username, Password=>$password);
-		if( $smtp ) {
-			my $message = oneline($smtp->message());
-			die "cannot connect with TLS: $message" if $smtp->code() =~ m/53\d/;
-		}
+		#if( $smtp ) {
+		#	my $message = oneline($smtp->message());
+		#	die "cannot connect with TLS: $message" if $smtp->code() =~ m/53\d/;
+		#}
 	}
 	elsif( $ssl ) {
 		$smtp_port = $default_smtp_ssl_port unless $smtp_port;
 		$smtp = Net::SMTP::SSL->new($smtp_server, Port => $smtp_port, Timeout=>$timeout,Debug=>$smtp_debug);
 		if( $smtp && $username )  {
 			$smtp->auth($username, $password);
-			my $message = oneline($smtp->message());
-			die "cannot connect with SSL/password: $message" if $smtp->code() =~ m/53\d/;
+			#my $message = oneline($smtp->message());
+			#die "cannot connect with SSL/password: $message" if $smtp->code() =~ m/53\d/;
 		}	
 	}
 	elsif( $auth_method ) {
@@ -176,8 +176,8 @@
 		$smtp = Net::SMTP_auth->new($smtp_server, Port=>$smtp_port, Timeout=>$timeout,Debug=>$smtp_debug);	
 		if( $smtp ) {
 			$smtp->auth($auth_method, $username, $password);
-			my $message = oneline($smtp->message());
-			die "cannot connect with SSL/$auth_method: $message" if $smtp->code() =~ m/53\d/;
+			#my $message = oneline($smtp->message());
+			#die "cannot connect with SSL/$auth_method: $message" if $smtp->code() =~ m/53\d/;
 		}			
 	}
 	else {
@@ -185,8 +185,8 @@
 		$smtp = Net::SMTP->new($smtp_server, Port=>$smtp_port, Timeout=>$timeout,Debug=>$smtp_debug);	
 		if( $smtp && $username ) {
 			$smtp->auth($username, $password);
-			my $message = oneline($smtp->message());
-			die "cannot connect with password: $message" if $smtp->code() =~ m/53\d/;
+			#my $message = oneline($smtp->message());
+			#die "cannot connect with password: $message" if $smtp->code() =~ m/53\d/;
 		}	
 	}
 };


signature.asc
Description: OpenPGP digital signature


Bug#821207: [nagios-plugins-contrib] check_smtp_send fails when sending with --tls

2016-04-16 Thread Jan Wagner
Package: nagios-plugins-contrib
Version: 14.20141104
Severity: important

When using the check_smtp_send to check the smtp server using (start)tls
this fails:

./check_smtp_send -H smtp.gmail.com -p 587 --tls -U tests...@gmail.com
-P XX --mailto tests...@gmail.com --mailfrom testrece...@gmail.com
SMTP SEND CRITICAL - Can't locate object method "message" via package
"Net::SMTP::TLS" at /usr/lib/nagios/plugins/check_smtp_send line 153.

It seems that the problem is introduced upstream in version 0.7.1a by
the "replaces all newlines in the input string with spaces"-fix. The
problematic (upstream) change is attached.

There is also a bug on Launchpad: LP #1497564

Cheers, Jan.
-- 
Never write mail to , you have been warned!
-BEGIN GEEK CODE BLOCK-
Version: 3.12
GIT d-- s+: a C+++ UL P+ L+++ E--- W+++ N+++ o++ K++ w--- O M+ V- PS
PE Y++
PGP++ t-- 5 X R tv- b+ DI D+ G++ e++ h r+++ y
--END GEEK CODE BLOCK--
--- check_smtp_send_0.7.1   2011-11-11 02:56:05.0 +0100
+++ check_smtp_send_0.7.1a  2011-12-13 18:26:16.0 +0100
@@ -1,7 +1,7 @@
 #!/usr/bin/perl
 use strict;
 use POSIX qw(strftime);
-my $VERSION = '0.7.2';
+my $VERSION = '0.7.3';
 my $COPYRIGHT = 'Copyright (C) 2005-2011 Jonathan Buhacoff 
';
 my $LICENSE = 'http://www.gnu.org/licenses/gpl.txt';
 my %status = ( 'OK' => 0, 'WARNING' => 1, 'CRITICAL' => 2, 'UNKNOWN' => 3 );
@@ -147,16 +147,26 @@
if( $tls and $auth_method ) {
$smtp_port = $default_smtp_tls_port unless $smtp_port;
$smtp = TLS_auth->new($smtp_server, Timeout=>$timeout, 
Port=>$smtp_port, User=>$username, Password=>$password, 
Auth_Method=>$auth_method);
+   if( $smtp ) {
+   my $message = oneline($smtp->message());
+   die "cannot connect with TLS/$auth_method: $message" if 
$smtp->code() =~ m/53\d/;
+   }
}
elsif( $tls ) {
$smtp_port = $default_smtp_tls_port unless $smtp_port;
$smtp = Net::SMTP::TLS->new($smtp_server, Timeout=>$timeout, 
Port=>$smtp_port, User=>$username, Password=>$password);
+   if( $smtp ) {
+   my $message = oneline($smtp->message());
+   die "cannot connect with TLS: $message" if 
$smtp->code() =~ m/53\d/;
+   }
}
elsif( $ssl ) {
$smtp_port = $default_smtp_ssl_port unless $smtp_port;
$smtp = Net::SMTP::SSL->new($smtp_server, Port => $smtp_port, 
Timeout=>$timeout,Debug=>$smtp_debug);
if( $smtp && $username )  {
$smtp->auth($username, $password);
+   my $message = oneline($smtp->message());
+   die "cannot connect with SSL/password: $message" if 
$smtp->code() =~ m/53\d/;
}   
}
elsif( $auth_method ) {
@@ -164,6 +174,8 @@
$smtp = Net::SMTP_auth->new($smtp_server, Port=>$smtp_port, 
Timeout=>$timeout,Debug=>$smtp_debug);  
if( $smtp ) {
$smtp->auth($auth_method, $username, $password);
+   my $message = oneline($smtp->message());
+   die "cannot connect with SSL/$auth_method: $message" if 
$smtp->code() =~ m/53\d/;
}   
}
else {
@@ -171,8 +183,10 @@
$smtp = Net::SMTP->new($smtp_server, Port=>$smtp_port, 
Timeout=>$timeout,Debug=>$smtp_debug);   
if( $smtp && $username ) {
$smtp->auth($username, $password);
+   my $message = oneline($smtp->message());
+   die "cannot connect with password: $message" if 
$smtp->code() =~ m/53\d/;
}   
-   }   
+   }
 };
 if( $@ ) {
$@ =~ s/\n/ /g; # the error message can be multiline but we want our 
output to be just one line
@@ -358,6 +372,13 @@
return $string;
 }
 
+# replaces all newlines in the input string with spaces
+sub oneline {
+   my ($input) = @_;
+   $input =~ s/[\r\n]+/ /g;
+   return $input;
+}
+
 # NAME
 #  PluginReport
 # SYNOPSIS
@@ -499,6 +520,14 @@
 
 Use the notls option to turn off the tls option.
 
+Also, you may need to fix your copy of Net::SMTP::TLS. Here is the diff 
against version 0.12:
+
+ 254c254
+ < $me->_command(sprintf("AUTH PLAIN %S",
+ ---
+ > $me->_command(sprintf("AUTH PLAIN %s",
+
+
 =item --ssl
 
 =item --nossl
@@ -721,7 +750,11 @@
  Wed Jul  6 19:18:26 AST 2011
  + the --hostname is now optional; if not provided the plugin will lookup the 
MX record for the --mailto address (requires Net::DNS)
  + version 0.7.2
- 
+
+ Tue Dec 13 09:24:04 PST 2011
+ + separated authentication errors from connection errors
+ + version 0.7.3
+
 =head1 AUTHOR
 
 Jonathan Buhacoff 


signature.asc
Description: