From 0d4f3dab1a5ba9a3287da5d54036355e8211ac6d Mon Sep 17 00:00:00 2001 From: Sebastian Harl Date: Tue, 3 Jan 2012 11:56:14 +0100 Subject: [PATCH] Nagios::Plugin::JUNOS: send_query: Support fallback to JUNOS::Device::command. --- perl/lib/Nagios/Plugin/JUNOS.pm | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/perl/lib/Nagios/Plugin/JUNOS.pm b/perl/lib/Nagios/Plugin/JUNOS.pm index 5ce9775..072cdd9 100644 --- a/perl/lib/Nagios/Plugin/JUNOS.pm +++ b/perl/lib/Nagios/Plugin/JUNOS.pm @@ -390,7 +390,7 @@ sub send_query { my $self = shift; my $query = shift; - my $queryargs = shift; + my $queryargs = shift || {}; my $res; my $err; @@ -399,10 +399,15 @@ sub send_query . join(", ", map { "$_ => $queryargs->{$_}" } keys %$queryargs) . " to router."); - if (ref $queryargs) { + if (scalar(keys %$queryargs)) { $res = $self->{'junos'}->$query(%$queryargs); } else { - $res = $self->{'junos'}->$query(); + eval { + $res = $self->{'junos'}->$query(); + }; + if ($@) { + $res = $self->{'junos'}->command($query); + } } if (! ref $res) {