Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Net::SNMP::Interfaces how to print the error()

by Mr. Muskrat (Canon)
on Jun 04, 2014 at 19:45 UTC ( #1088729=note: print w/replies, xml ) Need Help??


in reply to Net::SNMP::Interfaces how to print the error()

To clarify what hexcoder said...

Based on the documentation, $Net::SNMP::Interfaces::error is only set if you haven't used RaiseError => 1. You should be able to do one of the following:

#!/usr/bin/perl use strict; use warnings; use Net::SNMP::Interfaces; use Data::Dumper qw(Dumper); my $interfaces = Net::SNMP::Interfaces->new( Hostname => '127.0.0.1', Community => 'public', Port => '1161', RaiseError => 1, # Errors are fatal ); my @ifnames = $interfaces->all_interfaces(); print Dumper (\@ifnames);
#!/usr/bin/perl use strict; use warnings; use Net::SNMP::Interfaces; use Data::Dumper qw(Dumper); my $interfaces = Net::SNMP::Interfaces->new( Hostname => '127.0.0.1', Community => 'public', Port => '1161', ) or die $Net::SNMP::Interfaces::error; my @ifnames = $interfaces->all_interfaces(); print Dumper (\@ifnames);

Replies are listed 'Best First'.
Re^2: Net::SNMP::Interfaces how to print the error()
by thanos1983 (Parson) on Jun 04, 2014 at 20:41 UTC

    To: Mr. Muskrat,

    Thanks for the clarification part, I was not sure if I did understand correctly.

    Well in conclusion, by using the die command:

    my $interfaces = Net::SNMP::Interfaces->new( Hostname => '192.168.18 +4.11', Community => 'public', Port => '1161', #RaiseError => 1, )or die $Net::SNMP::Interfaces::error; my @ifnames = $interfaces->all_interfaces(); print Dumper (\@ifnames);

    The output is:

    No response from remote host "127.0.0.1" at test.pl line 10

    By changing the code to:

    my $interfaces = Net::SNMP::Interfaces->new( Hostname => '127.0.0.1' +, Community => 'public', Port => '1161', RaiseError => 1, ); my @ifnames = $interfaces->all_interfaces();

    The output is:

    Net::SNMP::Interfaces: at test.pl line 10.

    The whole point of my question was that I would like to see a printout like:

    22:19:01.537280 IP 0.0.0.0 > 0.0.0.0: ICMP 0.0.0.0 udp port 1161 unrea +chable, length 36

    Which the actual output of TCPDUMP, in order to inform the user that the port or community or what ever the error is wrong.

    Both solutions indicate that the error comes from line 10 which is Net::SNMP::Interfaces request so there is an indication, I was just looking for something extra since the documentation said that there might give more information if the user include the RaiseError => 1 command.

    Update:

    By removing the RaiseError => 1 the (HASH %arg) like:

    my $interfaces = Net::SNMP::Interfaces->new( Hostname => '192.168.18 +4.11', Community => 'public', Port => '1161', ); my @ifnames = $interfaces->all_interfaces(); print Dumper (\@ifnames);

    The error becomes:

    Can't call method "all_interfaces" on an undefined value at test.pl li +ne 12.

    Which points out to the array, which makes the user wonder what is the error, well in this case I would suggest to use one of the upper solutions so at least the user get's an idea of the error and not be looking at the wrong direction.

    Thank you all for your time and effort, replying to my question.

    Seeking for Perl wisdom...on the process...not there...yet!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1088729]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (3)
As of 2020-08-15 14:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which rocket would you take to Mars?










    Results (79 votes). Check out past polls.

    Notices?