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 {
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}->{issuer});
$self->{result_values}->{issuer}
);
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}));
}
@ -77,16 +79,16 @@ sub new {
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$options{options}->add_options(arguments =>
{
"hostname:s" => { name => 'hostname' },
"port:s" => { name => 'port' },
"servername:s" => { name => 'servername' },
"ssl-opt:s@" => { name => 'ssl_opt' },
"timeout:s" => { name => 'timeout', default => '3' },
"warning-status:s" => { name => 'warning_status', default => '%{expiration} < 60' },
"critical-status:s" => { name => 'critical_status', default => '%{expiration} < 30' },
$options{options}->add_options(arguments => {
'hostname:s' => { name => 'hostname' },
'port:s' => { name => 'port' },
'servername:s' => { name => 'servername' },
'ssl-opt:s@' => { name => 'ssl_opt' },
'timeout:s' => { name => 'timeout', default => '3' },
'warning-status:s' => { name => 'warning_status', default => '%{expiration} < 60' },
'critical-status:s' => { name => 'critical_status', default => '%{expiration} < 30' },
});
return $self;
}
@ -121,10 +123,8 @@ sub manage_selection {
my $context = new IO::Socket::SSL::SSL_Context(eval $self->{ssl_context});
eval { IO::Socket::SSL::set_default_context($context) };
if ($@) {
$self->{output}->output_add(severity => 'CRITICAL',
short_msg => sprintf("Error setting SSL context: %s", $@));
$self->{output}->display();
$self->{output}->exit();
$self->{output}->add_option_msg(short_msg => sprintf("Error setting SSL context: %s", $@));
$self->{output}->option_exit();
}
}
@ -138,22 +138,16 @@ sub manage_selection {
);
};
if ($@) {
$self->{output}->output_add(severity => 'CRITICAL',
short_msg => sprintf("%s", $@));
$self->{output}->display();
$self->{output}->exit();
$self->{output}->add_option_msg(short_msg => sprintf("%s", $@));
$self->{output}->option_exit();
}
if (!defined($socket)) {
$self->{output}->output_add(severity => 'CRITICAL',
short_msg => "Error creating SSL socket: $!, SSL error: $SSL_ERROR");
$self->{output}->display();
$self->{output}->exit();
$self->{output}->add_option_msg(short_msg => "Error creating SSL socket: $!, SSL error: $SSL_ERROR");
$self->{output}->option_exit();
}
if (defined($SSL_ERROR)) {
$self->{output}->output_add(severity => 'CRITICAL',
short_msg => "SSL error: $SSL_ERROR");
$self->{output}->display();
$self->{output}->exit();
$self->{output}->add_option_msg(short_msg => "SSL error: $SSL_ERROR");
$self->{output}->option_exit();
}
my $subject = $socket->peer_certificate('commonName');