mirror of
https://github.com/centreon/centreon-plugins.git
synced 2025-07-28 08:04:36 +02:00
Refs #6322 - Fix Error handling
This commit is contained in:
parent
1e9657c608
commit
68d99cc0ec
@ -48,7 +48,7 @@ sub new {
|
|||||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||||
bless $self, $class;
|
bless $self, $class;
|
||||||
|
|
||||||
$self->{version} = '1.0';
|
$self->{version} = '1.1';
|
||||||
$options{options}->add_options(arguments =>
|
$options{options}->add_options(arguments =>
|
||||||
{
|
{
|
||||||
"hostname:s" => { name => 'hostname' },
|
"hostname:s" => { name => 'hostname' },
|
||||||
@ -93,29 +93,25 @@ sub check_options {
|
|||||||
sub run {
|
sub run {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
if (!defined($self->{option_results}->{port})) {
|
|
||||||
$self->{option_results}->{port} = centreon::plugins::httplib::get_port($self);
|
|
||||||
}
|
|
||||||
|
|
||||||
#Global variables
|
#Global variables
|
||||||
my ($connection, $ctx, $ssl, $cert);
|
my ($connection, $ctx, $ssl, $cert);
|
||||||
|
|
||||||
#Create Socket connection
|
#Create Socket connection
|
||||||
$connection = IO::Socket::INET->new(PeerAddr => $self->{option_results}->{hostname},
|
$connection = IO::Socket::INET->new(PeerAddr => $self->{option_results}->{hostname},
|
||||||
PeerPort => $self->{option_results}->{port},
|
PeerPort => $self->{option_results}->{port},
|
||||||
Timeout => $self->{option_results}->{timeout},
|
Timeout => $self->{option_results}->{timeout},
|
||||||
);
|
);
|
||||||
if (!defined($connection)) {
|
if (!defined($connection)) {
|
||||||
if (!defined($!) || ($! eq '')) {
|
$self->{output}->output_add(severity => 'CRITICAL',
|
||||||
$self->{output}->output_add(severity => 'CRITICAL',
|
short_msg => sprintf("%s", $!));
|
||||||
short_msg => "Connection failed : SSL error");
|
$self->{output}->display();
|
||||||
}
|
$self->{output}->exit();
|
||||||
} else {
|
} else {
|
||||||
#Create SSL context
|
#Create SSL context
|
||||||
eval { $ctx = Net::SSLeay::CTX_new() };
|
eval { $ctx = Net::SSLeay::CTX_new() };
|
||||||
if ($@) {
|
if ($@) {
|
||||||
$self->{output}->output_add(severity => 'CRITICAL',
|
$self->{output}->output_add(severity => 'CRITICAL',
|
||||||
short_msg => "Connection failed : SSL error");
|
short_msg => sprintf ("%s", $!));
|
||||||
|
|
||||||
$self->{output}->display();
|
$self->{output}->display();
|
||||||
$self->{output}->exit()
|
$self->{output}->exit()
|
||||||
@ -127,7 +123,7 @@ sub run {
|
|||||||
eval { $ssl = Net::SSLeay::new($ctx) };
|
eval { $ssl = Net::SSLeay::new($ctx) };
|
||||||
if ($@) {
|
if ($@) {
|
||||||
$self->{output}->output_add(severity => 'CRITICAL',
|
$self->{output}->output_add(severity => 'CRITICAL',
|
||||||
short_msg => "Connection failed : SSL error");
|
short_msg => sprintf("%s", $!));
|
||||||
|
|
||||||
$self->{output}->display();
|
$self->{output}->display();
|
||||||
$self->{output}->exit()
|
$self->{output}->exit()
|
||||||
@ -136,7 +132,7 @@ sub run {
|
|||||||
eval { Net::SSLeay::set_fd($ssl, fileno($connection)) };
|
eval { Net::SSLeay::set_fd($ssl, fileno($connection)) };
|
||||||
if ($@) {
|
if ($@) {
|
||||||
$self->{output}->output_add(severity => 'CRITICAL',
|
$self->{output}->output_add(severity => 'CRITICAL',
|
||||||
short_msg => "Connection failed : SSL error");
|
short_msg => sprintf("%s", $!));
|
||||||
|
|
||||||
$self->{output}->display();
|
$self->{output}->display();
|
||||||
$self->{output}->exit()
|
$self->{output}->exit()
|
||||||
@ -145,7 +141,7 @@ sub run {
|
|||||||
eval { Net::SSLeay::connect($ssl) };
|
eval { Net::SSLeay::connect($ssl) };
|
||||||
if ($@) {
|
if ($@) {
|
||||||
$self->{output}->output_add(severity => 'CRITICAL',
|
$self->{output}->output_add(severity => 'CRITICAL',
|
||||||
short_msg => "Connection failed : SSL error");
|
short_msg => sprintf("%s", $!));
|
||||||
|
|
||||||
$self->{output}->display();
|
$self->{output}->display();
|
||||||
$self->{output}->exit()
|
$self->{output}->exit()
|
||||||
@ -169,7 +165,7 @@ sub run {
|
|||||||
#Subject Name
|
#Subject Name
|
||||||
} elsif ($self->{option_results}->{validity_mode} eq 'subject') {
|
} elsif ($self->{option_results}->{validity_mode} eq 'subject') {
|
||||||
my $subject_name = Net::SSLeay::X509_NAME_oneline(Net::SSLeay::X509_get_subject_name($cert));
|
my $subject_name = Net::SSLeay::X509_NAME_oneline(Net::SSLeay::X509_get_subject_name($cert));
|
||||||
if ( $subject_name =~ /$self->{option_results}->{subjectname}/mi ) {
|
if ( $self->{option_results}->{subjectname} =~ /$subject_name/mi ) {
|
||||||
$self->{output}->output_add(severity => 'OK',
|
$self->{output}->output_add(severity => 'OK',
|
||||||
short_msg => sprintf("Subject Name %s is present in Certificate :%s", $self->{option_results}->{subjectname}, $subject_name));
|
short_msg => sprintf("Subject Name %s is present in Certificate :%s", $self->{option_results}->{subjectname}, $subject_name));
|
||||||
} else {
|
} else {
|
||||||
@ -183,7 +179,7 @@ sub run {
|
|||||||
#Issuer Name
|
#Issuer Name
|
||||||
} elsif ($self->{option_results}->{validity_mode} eq 'issuer') {
|
} elsif ($self->{option_results}->{validity_mode} eq 'issuer') {
|
||||||
my $issuer_name = Net::SSLeay::X509_NAME_oneline(Net::SSLeay::X509_get_issuer_name($cert));
|
my $issuer_name = Net::SSLeay::X509_NAME_oneline(Net::SSLeay::X509_get_issuer_name($cert));
|
||||||
if ( $issuer_name =~ /$self->{option_results}->{issuername}/mi ) {
|
if ( $self->{option_results}->{issuer} =~ /$issuer_name/mi ) {
|
||||||
$self->{output}->output_add(severity => 'OK',
|
$self->{output}->output_add(severity => 'OK',
|
||||||
short_msg => sprintf("Issuer Name %s is present in Certificate :%s", $self->{option_results}->{issuername}, $issuer_name));
|
short_msg => sprintf("Issuer Name %s is present in Certificate :%s", $self->{option_results}->{issuername}, $issuer_name));
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user