Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

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

by thanos1983 (Parson)
on Jun 04, 2014 at 20:41 UTC ( #1088737=note: print w/replies, xml ) Need Help??


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

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://1088737]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (7)
As of 2020-11-27 21:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?