+ Enhance error message
This commit is contained in:
parent
baf0bbe845
commit
0faaec35cb
|
@ -67,7 +67,11 @@ sub check_options {
|
||||||
sub run {
|
sub run {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
my $icmp_sock = new IO::Socket::INET(Proto=>"icmp");
|
my $icmp_sock = new IO::Socket::INET(Proto => "icmp");
|
||||||
|
if (!defined($icmp_sock)) {
|
||||||
|
$self->{output}->add_option_msg(short_msg => "Cannot create socket: $!");
|
||||||
|
$self->{output}->option_exit();
|
||||||
|
}
|
||||||
my $read_set = new IO::Select();
|
my $read_set = new IO::Select();
|
||||||
$read_set->add($icmp_sock);
|
$read_set->add($icmp_sock);
|
||||||
|
|
||||||
|
@ -78,7 +82,8 @@ sub run {
|
||||||
|
|
||||||
$sock->send("Hello");
|
$sock->send("Hello");
|
||||||
close($sock);
|
close($sock);
|
||||||
(my $new_readable) = IO::Select->select($read_set, undef, undef, $self->{option_results}->{timeout});
|
|
||||||
|
my ($new_readable) = IO::Select->select($read_set, undef, undef, $self->{option_results}->{timeout});
|
||||||
my $icmp_arrived = 0;
|
my $icmp_arrived = 0;
|
||||||
foreach $sock (@$new_readable) {
|
foreach $sock (@$new_readable) {
|
||||||
if ($sock == $icmp_sock) {
|
if ($sock == $icmp_sock) {
|
||||||
|
@ -89,8 +94,8 @@ sub run {
|
||||||
close($icmp_sock);
|
close($icmp_sock);
|
||||||
|
|
||||||
if ($icmp_arrived == 1) {
|
if ($icmp_arrived == 1) {
|
||||||
$self->{output}->output_add(severity => 'CRITICAL',
|
$self->{output}->output_add(severity => 'CRITICAL',
|
||||||
short_msg => sprintf("Connection failed on port %s", $self->{option_results}->{port}));
|
short_msg => sprintf("Connection failed on port %s", $self->{option_results}->{port}));
|
||||||
} else {
|
} else {
|
||||||
$self->{output}->output_add(severity => 'OK',
|
$self->{output}->output_add(severity => 'OK',
|
||||||
short_msg => sprintf("Connection success on port %s", $self->{option_results}->{port}));
|
short_msg => sprintf("Connection success on port %s", $self->{option_results}->{port}));
|
||||||
|
|
Loading…
Reference in New Issue