Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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);
}
like image 853
WVEagle81 Avatar asked Apr 21 '15 15:04

WVEagle81


1 Answers

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>
like image 122
Chester Rieman Avatar answered Sep 27 '22 18:09

Chester Rieman