Using Perl to get list of IP addresses from Cisco Call Manager
Asked Answered
B

1

8

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);
}
Bloodstone answered 21/4, 2015 at 15:35 Comment(9)
Please edit your question to show the SNMP.pm or Net::SNMP code you wrote that only returns one IP address. Also show the results of the snmpwalk 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
One of the posts I found is this one: #101120Bloodstone
The original post has been edited with the code and snmpwalk resultsBloodstone
I don't have a device that I can test that particular OID on, but your code works for me for a different OID. Are you saying that @table only contains one value after you run the script? How are you outputting the results?Brownstone
Yes, that's correct. I'm just doing a simple foreach loop to print out the table.Bloodstone
Also, you should avoid indirect object notation and use my $foo = Foo->new; instead of my $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});Brownstone
Can you show all of the relevant code (including how you print the results), as well as the generated output? Also, do you have this problem with other OIDs or just this one? Perhaps try some standard OIDs like 1.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
Using some code I found on the perlmonks site I was able to do the query and get the results I'm looking for. perlmonks.org/bare/?node_id=341313Bloodstone
@user141715: Stack Overflow is meant to be a public resource, rather than a forum where individuals can resolve their own problems. That means that your post needs a proper statement of the problem in the question, as well as an answer (that you can write yourself and accept) that contains the code that you used to fix the issueVivien
G
1

You can do this with curl and send an XML to query the risdb since only registered phones will have IP addresses:

curl -s -k -u axluser:${AXLPASSWORD} -H 'Content-type: text/xml;' -H 'SOAPAction: "CUCM:DB ver=8.0"' -d @ris_reg.xml https://x.x.x.x:8443/realtimeservice/services/RisPort | xmllint --format - > ris_reg_8.log

See:

ris_reg.xml:<?xml version="1.0" encoding="utf-8"?> <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"  xmlns:xsd="http://www.w3.org/2001/XMLSchema"  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">   <soapenv:Body>
    <ns1:SelectCmDevice soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"  xmlns:ns1="http://schemas.cisco.com/ast/soap/">
      <StateInfo xsi:type="xsd:string"/>
      <CmSelectionCriteria href="#id0"/>
    </ns1:SelectCmDevice>
    <multiRef id="id0" soapenc:root="0"  soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"  xsi:type="ns2:CmSelectionCriteria"  xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"  xmlns:ns2="http://schemas.cisco.com/ast/soap/">
      <MaxReturnedDevices xsi:type="xsd:unsignedInt">0</MaxReturnedDevices>
      <Class xsi:type="xsd:string">Phone</Class>
      <Model xsi:type="xsd:unsignedInt">503</Model>
      <Status xsi:type="xsd:string">Registered</Status>
      <NodeName xsi:type="xsd:string" xsi:nil="true"/>
      <SelectBy xsi:type="xsd:string">Name</SelectBy>
      <SelectItems soapenc:arrayType="ns2:SelectItem[1]" xsi:type="soapenc:Array">
        <item href="#id1"/>
      </SelectItems>
    </multiRef>
    <multiRef id="id1" soapenc:root="0"  soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"  xsi:type="ns3:SelectItem" xmlns:ns3="http://schemas.cisco.com/ast/soap/"  xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
      <Item xsi:type="xsd:string">*</Item>
    </multiRef>   </soapenv:Body> </soapenv:Envelope>
Gerius answered 29/9, 2015 at 1:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.