Skip to content

Instantly share code, notes, and snippets.

@darrenparkinson
Last active February 5, 2020 01:42
Show Gist options
  • Save darrenparkinson/9979639 to your computer and use it in GitHub Desktop.
Save darrenparkinson/9979639 to your computer and use it in GitHub Desktop.
Simple Perl Script to request information from Cisco Communications Manager AXL API
#!/usr/bin/perl -w
use strict;
use warnings;
use Text::CSV;
use LWP::UserAgent;
use LWP::Protocol::https;
use HTTP::Request;
use MIME::Base64;
use XML::LibXML;
#username und password for CUCM
my $encoded = encode_base64('username:password');
#URL of AXL service
my $cucmAxlUrl = 'https://192.168.7.41/axl/';
my $soapAction = "CUCM:DB ver=9.1";
my $message;
my $userAgent;
my $request;
my $response;
#deactivate certificate validation
$userAgent = LWP::UserAgent->new(
agent => 'perl post',
ssl_opts => { SSL_verify_mode => 'SSL_VERIFY_NONE' },
);
# Example for listing a line
$message = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:axl="http://www.cisco.com/AXL/API/9.1">
<soapenv:Header/>
<soapenv:Body>
<axl:listLine sequence="1234">
<searchCriteria>
<pattern>2001</pattern>
</searchCriteria>
<returnedTags>
<pattern/>
<description/>
<usage/>
<routePartitionName/>
</returnedTags>
</axl:listLine>
</soapenv:Body>
</soapenv:Envelope>';
#generate HTTP request and header
$request = HTTP::Request->new('POST', $cucmAxlUrl);
$request->header(Authorization => "Basic $encoded", 'Content-Type' => 'text/xml; charset=utf-8', 'SOAPAction' => $soapAction);
$request->content($message);
#send HTTP request
$response = $userAgent->request($request);
#extract xml from the response
my $xmldoc = XML::LibXML->load_xml(string => $response->decoded_content) or die "error with xml";
#use xpath syntax to find the results
print $xmldoc->findnodes('//pattern/text()') . "\n";
print $xmldoc->findnodes('//description/text()') . "\n";
print $xmldoc->findnodes('//usage/text()') . "\n";
print $xmldoc->findnodes('//routePartitionName/text()') . "\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment