Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
That shows that trying to retype code to simplify it shouldnt be done after 2am. This time I am pasting the code as it is.
#!/usr/bin/perl -w use strict; use Net::SNMP; my @devices = qw(2500 7200 7500 12000); my $retries = "1"; my $wait = "5.0"; my $mtu = "1500"; my $version = "1"; my $debug = "0"; my $community = "public"; my $snmp_username = ""; ## v3 my $snmp_authkey = ""; ## v3 my $snmp_authpassword = ""; ## v3 my $snmp_authprotocol = ""; ## v3 my %oid = ( version => ".1.3.6.1.2.1.1.1.0", ); &execute("run","tftp"); sub execute { ## pull source and destination of files my %args = ( s => $_[0], d => $_[1], ); foreach (@devices) { chomp $_; $args{h} = $_; &action(\%args); } } sub action { my $args = shift; ## set up initial parameters for this nodes snmp session(s) my $s = &create_snmp($args); ## grab the ios major revision number my $ios_version = $s->get_request ($oid{version}); ## grab an error if it exists $args->{e} = $s->error; ## close the snmp session $s->close; print "$args->{h} has IOS:\n\n$ios_version\n\n"; } sub create_snmp { ## get hostname to be used into local variable my $args = shift; ## create the hash of version independent options to pass to the met +hod my %snmp_options = ( hostname => "$args->{h}", retries => "$retries", timeout => "$wait", mtu => "$mtu", version => "$snmp_version", debug => "$debug", ); ## declare our variable to be set and returned my $s; ## test for snmpv3 usage if ( $snmp_version eq "snmpv3" ) { $snmp_options{username} = "$snmp_username"; $snmp_options{authkey} = "$snmp_authkey" if ($snmp_authkey); $snmp_options{authpassword} = "$snmp_authpassword" if ($snmp_authpassword); if ($snmp_authprotocol) { $snmp_options{authprotocol} = "$snmp_authprotocol"; $snmp_options{privkey} = "$snmp_authkey"; $snmp_options{privpassword} = "$snmp_authpassword"; } ## initiate session with v3 values $s = Net::SNMP->session(\%snmp_options); } else { ## set the v1/2c specific session traits $snmp_options{community} = $community; ## initiate session with v1/2c values $s= Net::SNMP->session(\%snmp_options); } ## provide our new session information return $s; ## end create_snmp() }

Thanks for looking into this. -c


In reply to Re: Re: using return to create a module object by c
in thread using return to create a module object by c

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (4)
As of 2024-04-24 07:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found