I'm trying to do a snmpwalk to the AP status on a wlc. I'm really new to perl so bear with me but I was working with this guide. I was able to get the CPU Utilization just fine, but that was just a get request where as this is a walk.
My input: perl test.pl -H 10.192.54.30 -C public -O .1.3.6.1.4.1.14179.2.2.1.1.6.0 -w 20 -c 30
The code:
#!/bin/perl
use strict;
use warnings;
use Net::SNMP;
use Getopt::Long qw(:config no_ignore_case);
my $hostaddr = '';
my $community = '';
my $crit = '';
my $warn = '';
my $oid = '';
GetOptions(
"host|H=s" => \$hostaddr,
"community|C=s" => \$community,
"crit|c:s" => \$crit,
"warn|w:s" => \$warn,
"oid|O=s" => \$oid);
print "$hostaddr $community $crit $warn $oid\n";
my ($session, $error) = Net::SNMP->session(
-hostname => "$hostaddr",
-community => "$community",
-timeout => "30",
-port => "161");
if (!defined($session)) {
printf("ERROR: %s.\n", $error);
exit 1;
}
my $response = $session->get_table( -baseoid => $oid );
if (! defined $response) {
die "Failed to get OID '$oid': " . $session->error;
}
foreach my $key (keys %$response) {
print "$key: $response->{$key}\n";
}
my $err = $session->error;
if ($err){
return 1;
}
print "\n";
exit 0;
The output:
10.192.54.30 public 30 20 .1.3.6.1.4.1.14179.2.2.1.1.6.0
Can't use an undefined value as a HASH reference at test.pl line 26.