From e0e3fea4523cf835dd5c3cb428a7e5e61d1e9557 Mon Sep 17 00:00:00 2001 From: Sebastian Harl Date: Tue, 3 Jan 2012 09:24:25 +0100 Subject: [PATCH] check_junos, Nagios::Plugin::JUNOS: Moved send_query() to the plugin. --- check_junos.pl | 36 +++------------------------------ perl/lib/Nagios/Plugin/JUNOS.pm | 30 +++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 33 deletions(-) diff --git a/check_junos.pl b/check_junos.pl index 232dd6f..929caa6 100755 --- a/check_junos.pl +++ b/check_junos.pl @@ -148,36 +148,6 @@ $junos->disconnect(); $plugin->nagios_exit($code, $msg); -sub send_query -{ - my $device = shift; - my $query = shift; - my $queryargs = shift; - - my $res; - my $err; - - $plugin->verbose(3, "Sending query '$query' " - . join(", ", map { "$_ => $queryargs->{$_}" } keys %$queryargs) - . " to router."); - - if (ref $queryargs) { - $res = $device->$query(%$queryargs); - } else { - $res = $device->$query(); - } - - if (! ref $res) { - return "ERROR: Failed to execute query '$query'"; - } - - $err = $res->getFirstError(); - if ($err) { - return "ERROR: " . $err->{message}; - } - return $res; -} - sub check_interface { my $plugin = shift; @@ -238,7 +208,7 @@ sub get_interfaces if ((scalar(@targets) == 1) && (! $opts->{'with_description'})) { $args->{'interface_name'} = $targets[0]; } - $res = send_query($device, $cmd, $args); + $res = $plugin->send_query($cmd, $args); if (! ref $res) { $plugin->die($res); @@ -504,7 +474,7 @@ sub check_chassis_environment my $junos = shift; my @targets = @_; - my $res = send_query($junos, 'get_environment_information'); + my $res = $plugin->send_query('get_environment_information'); my %status_map = ( OK => OK, @@ -599,7 +569,7 @@ sub check_system_storage my $junos = shift; my @targets = @_; - my $res = send_query($junos, 'get_system_storage'); + my $res = $plugin->send_query('get_system_storage'); foreach my $re (get_object_by_spec($res, 'multi-routing-engine-item')) { diff --git a/perl/lib/Nagios/Plugin/JUNOS.pm b/perl/lib/Nagios/Plugin/JUNOS.pm index df9d657..0b607fd 100644 --- a/perl/lib/Nagios/Plugin/JUNOS.pm +++ b/perl/lib/Nagios/Plugin/JUNOS.pm @@ -350,6 +350,36 @@ sub run_checks } } +sub send_query +{ + my $self = shift; + my $query = shift; + my $queryargs = shift; + + my $res; + my $err; + + $self->verbose(3, "Sending query '$query' " + . join(", ", map { "$_ => $queryargs->{$_}" } keys %$queryargs) + . " to router."); + + if (ref $queryargs) { + $res = $self->{'junos'}->$query(%$queryargs); + } else { + $res = $self->{'junos'}->$query(); + } + + if (! ref $res) { + return "ERROR: Failed to execute query '$query'"; + } + + $err = $res->getFirstError(); + if ($err) { + return "ERROR: " . $err->{message}; + } + return $res; +} + sub verbose { my $self = shift;