check_junos, Nagios::Plugin::JUNOS: Moved send_query() to the plugin.

This commit is contained in:
Sebastian Harl 2012-01-03 09:24:25 +01:00
parent 85c8c6d28f
commit e0e3fea452
2 changed files with 33 additions and 33 deletions

View file

@ -148,36 +148,6 @@ $junos->disconnect();
$plugin->nagios_exit($code, $msg); $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 sub check_interface
{ {
my $plugin = shift; my $plugin = shift;
@ -238,7 +208,7 @@ sub get_interfaces
if ((scalar(@targets) == 1) && (! $opts->{'with_description'})) { if ((scalar(@targets) == 1) && (! $opts->{'with_description'})) {
$args->{'interface_name'} = $targets[0]; $args->{'interface_name'} = $targets[0];
} }
$res = send_query($device, $cmd, $args); $res = $plugin->send_query($cmd, $args);
if (! ref $res) { if (! ref $res) {
$plugin->die($res); $plugin->die($res);
@ -504,7 +474,7 @@ sub check_chassis_environment
my $junos = shift; my $junos = shift;
my @targets = @_; my @targets = @_;
my $res = send_query($junos, 'get_environment_information'); my $res = $plugin->send_query('get_environment_information');
my %status_map = ( my %status_map = (
OK => OK, OK => OK,
@ -599,7 +569,7 @@ sub check_system_storage
my $junos = shift; my $junos = shift;
my @targets = @_; 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, foreach my $re (get_object_by_spec($res,
'multi-routing-engine-item')) { 'multi-routing-engine-item')) {

View file

@ -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 sub verbose
{ {
my $self = shift; my $self = shift;