Using Perl to Get a List of IP Addresses from Cisco Call Manager

I need to get a list of IP addresses of phones from Cisco Unified Call Manager, and I would like to be able to do this using Perl and standard modules as much as possible.

I can get addresses using snmpwalk (we use SNMP v3), but for some reason, when I use existing code to try to do the same through SNMP or Net :: SNMP, I only get one IP address. I can't seem to get a single one to give me a complete 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 also get the Phone Description field (156.1.2.1.1.4) and the two fields merge into a text file, so I can use them to query the phones themselves using LWP.

It would be great to combine these two functions in one script to get an IP address and request a phone for its specific details.

Does anyone have a code that does this?

Edit:

snmpwalk returns (a whole bunch):

 SNMPv2-SMI::enterprises.9.9.156.1.2.1.1.6.100 = IpAddress: xxx.xxx.xxx.xxx 

My Perl code that returns a single IP address (I have to retype it because it is 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); } 
+6
source share
1 answer

You can do this with curl and send XML for the risdb request, 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://xxxx:8443/realtimeservice/services/RisPort | xmllint --format - > ris_reg_8.log 

Cm:

 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> 
0
source

Source: https://habr.com/ru/post/985619/


All Articles