diff --git a/check_junos.pl b/check_junos.pl index 395dfba..3dab609 100755 --- a/check_junos.pl +++ b/check_junos.pl @@ -144,8 +144,6 @@ $plugin->run_checks(); my ($code, $msg) = $plugin->check_messages(join => ', '); -$junos->disconnect(); - $plugin->nagios_exit($code, $msg); sub check_interface diff --git a/perl/lib/Nagios/Plugin/JUNOS.pm b/perl/lib/Nagios/Plugin/JUNOS.pm index 265a128..72af7fe 100644 --- a/perl/lib/Nagios/Plugin/JUNOS.pm +++ b/perl/lib/Nagios/Plugin/JUNOS.pm @@ -438,6 +438,16 @@ sub get_query_object_value return $res->getFirstChild->getNodeValue; } +sub nagios_exit +{ + my $self = shift; + + if ($self->{'junos'}) { + $self->{'junos'}->disconnect(); + } + $self->SUPER::nagios_exit(@_); +} + sub verbose { my $self = shift;