This commit is contained in:
garnier-quentin 2020-01-20 14:11:38 +01:00
parent 9a2ff0fd4c
commit 1328c8d48d
1 changed files with 29 additions and 35 deletions

View File

@ -32,9 +32,11 @@ use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold)
sub custom_status_output { sub custom_status_output {
my ($self, %options) = @_; my ($self, %options) = @_;
my $msg = sprintf("Certificate for '%s' expires in '%d' days [%s] - Issuer: '%s'", my $msg = sprintf(
"Certificate for '%s' expires in '%d' days [%s] - Issuer: '%s'",
$self->{result_values}->{subject}, $self->{result_values}->{expiration}, $self->{result_values}->{date}, $self->{result_values}->{subject}, $self->{result_values}->{expiration}, $self->{result_values}->{date},
$self->{result_values}->{issuer}); $self->{result_values}->{issuer}
);
if (defined($self->{result_values}->{alt_subjects}) && $self->{result_values}->{alt_subjects} ne '') { if (defined($self->{result_values}->{alt_subjects}) && $self->{result_values}->{alt_subjects} ne '') {
$self->{output}->output_add(long_msg => sprintf("Alternative subject names: %s.", $self->{result_values}->{alt_subjects})); $self->{output}->output_add(long_msg => sprintf("Alternative subject names: %s.", $self->{result_values}->{alt_subjects}));
} }
@ -77,16 +79,16 @@ sub new {
my $self = $class->SUPER::new(package => __PACKAGE__, %options); my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class; bless $self, $class;
$options{options}->add_options(arguments => $options{options}->add_options(arguments => {
{ 'hostname:s' => { name => 'hostname' },
"hostname:s" => { name => 'hostname' }, 'port:s' => { name => 'port' },
"port:s" => { name => 'port' }, 'servername:s' => { name => 'servername' },
"servername:s" => { name => 'servername' }, 'ssl-opt:s@' => { name => 'ssl_opt' },
"ssl-opt:s@" => { name => 'ssl_opt' }, 'timeout:s' => { name => 'timeout', default => '3' },
"timeout:s" => { name => 'timeout', default => '3' }, 'warning-status:s' => { name => 'warning_status', default => '%{expiration} < 60' },
"warning-status:s" => { name => 'warning_status', default => '%{expiration} < 60' }, 'critical-status:s' => { name => 'critical_status', default => '%{expiration} < 30' },
"critical-status:s" => { name => 'critical_status', default => '%{expiration} < 30' },
}); });
return $self; return $self;
} }
@ -121,10 +123,8 @@ sub manage_selection {
my $context = new IO::Socket::SSL::SSL_Context(eval $self->{ssl_context}); my $context = new IO::Socket::SSL::SSL_Context(eval $self->{ssl_context});
eval { IO::Socket::SSL::set_default_context($context) }; eval { IO::Socket::SSL::set_default_context($context) };
if ($@) { if ($@) {
$self->{output}->output_add(severity => 'CRITICAL', $self->{output}->add_option_msg(short_msg => sprintf("Error setting SSL context: %s", $@));
short_msg => sprintf("Error setting SSL context: %s", $@)); $self->{output}->option_exit();
$self->{output}->display();
$self->{output}->exit();
} }
} }
@ -138,22 +138,16 @@ sub manage_selection {
); );
}; };
if ($@) { if ($@) {
$self->{output}->output_add(severity => 'CRITICAL', $self->{output}->add_option_msg(short_msg => sprintf("%s", $@));
short_msg => sprintf("%s", $@)); $self->{output}->option_exit();
$self->{output}->display();
$self->{output}->exit();
} }
if (!defined($socket)) { if (!defined($socket)) {
$self->{output}->output_add(severity => 'CRITICAL', $self->{output}->add_option_msg(short_msg => "Error creating SSL socket: $!, SSL error: $SSL_ERROR");
short_msg => "Error creating SSL socket: $!, SSL error: $SSL_ERROR"); $self->{output}->option_exit();
$self->{output}->display();
$self->{output}->exit();
} }
if (defined($SSL_ERROR)) { if (defined($SSL_ERROR)) {
$self->{output}->output_add(severity => 'CRITICAL', $self->{output}->add_option_msg(short_msg => "SSL error: $SSL_ERROR");
short_msg => "SSL error: $SSL_ERROR"); $self->{output}->option_exit();
$self->{output}->display();
$self->{output}->exit();
} }
my $subject = $socket->peer_certificate('commonName'); my $subject = $socket->peer_certificate('commonName');