I need to retrieve a list of IP addresses of phones from Cisco Unified Call Manager, and I'd like to be able to do it using Perl and standard modules as much as possible.
I can get the addresses using snmpwalk (we are using SNMP v3) but for some reason when I use existing code to try to do the same thing through SNMP or Net::SNMP, the most I get is one IP address. I can't seem to get either one to give me the full list.
Here is my snmpwalk command:
snmpwalk -v3 -u <user> -A <password> -l authNoPriv -a SHA <ip address> 1.3.6.1.4.1.9.9.156.1.2.1.1.6
I'm also getting the phone Description field (156.1.2.1.1.4) and merging those two fields into a text file so I can use them to query the phones themselves using LWP.
It would be great to be able to combine these two functions into one script to get the IP address and query the phone for its specific details.
Does anyone have code that does this?
Edit:
snmpwalk returns (a whole bunch of these):
SNMPv2-SMI::enterprises.9.9.156.1.2.1.1.6.100 = IpAddress: xxx.xxx.xxx.xxx
My Perl code that returns one IP address (I have to retype it because it's on a closed network without Internet access):
use SNMP;
my $ccmip = "xxx.xxx.xxx.xxx";
my $user = "<username>";
my $pass = "<password>";
$sess = new SNMP::Session(DestHost => $ccmip, SecName => $user, SecLevel => 'authnoPriv', AuthPass => $pass, AuthProto => 'SHA', PrivProto => 'AES', PrivPass => $pass, Version => 3);
my $vars = new SNMP::VarList(['1.3.6.1.4.1.9.9.156.1.2.1.1.6']);
my @values = $sess->getnext($vars);
my @table = ();
while ((!$sess->{ErrorStr})) {
push(@table, $values[0]);
@values = $sess->getnext($vars);
}
SNMP.pm
orNet::SNMP
code you wrote that only returns one IP address. Also show the results of thesnmpwalk
and the output of your script. Out of curiosity, what were the Stack Overflow posts with the broken links? It would be nice if we could fix those. – Brownstone@table
only contains one value after you run the script? How are you outputting the results? – Brownstonemy $foo = Foo->new;
instead ofmy $foo = new Foo;
. The docs should probably be updated. And finally, if your OID is a leaf node or only has one child, your current code throws it away. I would do what they do in the docs, e.g.do { my @values = $sess->getnext($vars); push @table, @values; } until ($sess->{ErrorStr});
– Brownstone1.3.6.1.2.1.1.9
. If you can, it would be helpful if you could make a minimal, complete, verifiable example that demonstrates your problem and that others can simply copy-paste and run on their own systems (minus the credentials, of course). – Brownstone