note
c
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.
<code>
#!/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 method
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()
}
</code><p>
Thanks for looking into this. -[c]
179806
179809