mirror of
https://github.com/centreon/centreon-plugins.git
synced 2025-07-27 23:54:18 +02:00
Fix #2020
This commit is contained in:
parent
7781606453
commit
097b057bca
@ -32,15 +32,15 @@ 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', },
|
'warning:s' => { name => 'warning' },
|
||||||
"warning:s" => { name => 'warning' },
|
'critical:s' => { name => 'critical' },
|
||||||
"critical:s" => { name => 'critical' },
|
'timeout:s' => { name => 'timeout', default => '3' },
|
||||||
"timeout:s" => { name => 'timeout', default => '3' },
|
'ssl' => { name => 'ssl' }
|
||||||
"ssl" => { name => 'ssl' },
|
});
|
||||||
});
|
|
||||||
return $self;
|
return $self;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,38 +72,49 @@ sub run {
|
|||||||
my ($connection, $timing0, $timeelapsed);
|
my ($connection, $timing0, $timeelapsed);
|
||||||
if (defined($self->{option_results}->{ssl})) {
|
if (defined($self->{option_results}->{ssl})) {
|
||||||
$timing0 = [gettimeofday];
|
$timing0 = [gettimeofday];
|
||||||
$connection = IO::Socket::SSL->new(PeerAddr => $self->{option_results}->{hostname},
|
$connection = IO::Socket::SSL->new(
|
||||||
PeerPort => $self->{option_results}->{port},
|
PeerAddr => $self->{option_results}->{hostname},
|
||||||
Timeout => $self->{option_results}->{timeout},
|
PeerPort => $self->{option_results}->{port},
|
||||||
);
|
Timeout => $self->{option_results}->{timeout},
|
||||||
|
);
|
||||||
$timeelapsed = tv_interval ($timing0, [gettimeofday]);
|
$timeelapsed = tv_interval ($timing0, [gettimeofday]);
|
||||||
} else {
|
} else {
|
||||||
$timing0 = [gettimeofday];
|
$timing0 = [gettimeofday];
|
||||||
$connection = IO::Socket::INET->new(PeerAddr => $self->{option_results}->{hostname},
|
$connection = IO::Socket::INET->new(
|
||||||
PeerPort => $self->{option_results}->{port},
|
PeerAddr => $self->{option_results}->{hostname},
|
||||||
Timeout => $self->{option_results}->{timeout},
|
PeerPort => $self->{option_results}->{port},
|
||||||
);
|
Timeout => $self->{option_results}->{timeout},
|
||||||
|
);
|
||||||
$timeelapsed = tv_interval ($timing0, [gettimeofday]);
|
$timeelapsed = tv_interval ($timing0, [gettimeofday]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!defined($connection)) {
|
if (!defined($connection)) {
|
||||||
if (!defined($!) || ($! eq '')) {
|
if (!defined($!) || ($! eq '')) {
|
||||||
$self->{output}->output_add(severity => 'CRITICAL',
|
$self->{output}->output_add(
|
||||||
short_msg => sprintf("Connection failed on port %s : SSL error", $self->{option_results}->{port}));
|
severity => 'CRITICAL',
|
||||||
|
short_msg => sprintf("Connection failed on port %s : SSL error", $self->{option_results}->{port})
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
$self->{output}->output_add(severity => 'CRITICAL',
|
$self->{output}->output_add(
|
||||||
short_msg => sprintf("Connection failed on port %s : %s", $self->{option_results}->{port}, $!));
|
severity => 'CRITICAL',
|
||||||
|
short_msg => sprintf("Connection failed on port %s : %s", $self->{option_results}->{port}, $!)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
my $exit = $self->{perfdata}->threshold_check(value => $timeelapsed, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
|
my $exit = $self->{perfdata}->threshold_check(value => $timeelapsed, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
|
||||||
$self->{output}->output_add(severity => $exit,
|
$self->{output}->output_add(
|
||||||
short_msg => sprintf("Response time on port %s is %.3fs", $self->{option_results}->{port}, $timeelapsed));
|
severity => $exit,
|
||||||
$self->{output}->perfdata_add(label => 'time',
|
short_msg => sprintf("Response time on port %s is %.3fs", $self->{option_results}->{port}, $timeelapsed));
|
||||||
value => sprintf('%.3f', $timeelapsed),
|
$self->{output}->perfdata_add(
|
||||||
unit => 's',
|
label => 'time',
|
||||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
|
value => sprintf('%.3f', $timeelapsed),
|
||||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
|
unit => 's',
|
||||||
min => 0);
|
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
|
||||||
|
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
|
||||||
|
min => 0
|
||||||
|
);
|
||||||
|
|
||||||
|
close($connection);
|
||||||
}
|
}
|
||||||
|
|
||||||
$self->{output}->display();
|
$self->{output}->display();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user