Perl and AXL

Version 1
    This document was generated from CDN thread

    Created by: Leonard LECOUEY on 19-01-2010 11:16:08 AM
    Hello,
     
    I'm trying to do some AXL query on a CallManager 6 to only retrieve information from this device. The purpose is to do some monitoring with this info.
    I looked for some tutorials or examples of scripts to get what I wanted, but I didn't found anything that explains clearly.
    I started to write a simple script. The dialogue with the CallManager is working and I'm getting requested information (in debuging mode).
     
    But I don't know how to get only one piece of the information. I think all is stored in a table, but I don¿t know how interrogate it?
     
    For example, I interrogate my CUCM for one user, passing the userid in my SOAP query. But how can I only get the phone number of this user?
     
    Other question, is the AXLtoolkit necessary if I only do request and no modification on my CUCM?
     
    There is a way to list, for example, all the phone registered on the call manager?


    #!/usr/bin/perl
    use warnings;
    use strict;
    use SOAP::Lite;

    my $cucmip = "xxx.xxx.xxx";
    my $axl_port = "8443";
    my $user = "axl";
    my $password = "axl";
    my $axltoolkit = "AXLAPI.wsdl";

    BEGIN {
      sub SOAP::Transport::HTTP::Client::get_basic_credentials {
        return ($user => $password)
      };
    }

    my $cm = new SOAP::Lite
        encodingStyle => '',
        uri => "$axltoolkit",
        proxy => "https://$cucmip:$axl_port/axl/" ;

    #axl request
    my $res =  $cm->getUser(SOAP:ata->name("userid" => "chni"));
    unless ($res->fault) {
    print $res->paramsall();
        }
     else {
            print join ', ',
            $res->faultcode,
            $res->faultstring;
    }


    Thanks

    Subject: RE: Perl and AXL
    Replied by: Dan-Anders Hook on 31-01-2010 03:43:31 PM
    Hi,
     
    I modified your code to only show the telephoneNumber, see below. The structure of the AXL requests and responses is documented in the Admin XML Interface spec available at http://developer.cisco.com/web/axl/docs. As for your question about returning a list of registered phones you would have to use the Serviceability API. The AXL API is only for provisioning, it does not contain any runtime information such as registration status and ip addresses of phones. However, to produce a list of registered phones you would probably have to use both API's because the Serviceability API only returns 200 devices at a time. You have to query the AXL API to get a list of devices, and then query the Serviceability with a request the contains max 200 devices at a time.
    (Oh, and for you other readers the happy face in the code below should be replaced with a colon and then a D, but I guess you already figured that one out )

    #!/usr/bin/perl
    use warnings;
    use strict;
    use SOAP::Lite;
    my $cucmip = "xxx.xxx.xxx.xxx";
    my $axl_port = "8443";
    my $user = "axl";
    my $password = "axl";
    my $axltoolkit = "AXLAPI.wsdl";
    BEGIN {
      sub SOAP::Transport::HTTP::Client::get_basic_credentials {
        return ($user => $password)
      };
    }
    my $cm = new SOAP::Lite
        encodingStyle => '',
        uri => "$axltoolkit",
        proxy => "https://$cucmip:$axl_port/axl/" ;
    #axl request
    my $res =  $cm->getUser(SOAP:ata->name("userid" => "chni"));
    unless ($res->fault) {
     print $res->valueof('//getUserResponse/return/user/telephoneNumber');
     print "\n";
    }
       
     else {
            print join ', ',
            $res->faultcode,
            $res->faultstring;
    }
     
     

    Subject: RE: Perl and AXL
    Replied by: Garrett Skjelstad on 08-02-2011 03:35:41 PM
    I hate to resurrect an old thread, but how would you adapt this to handle getting a list? Say getting a list of all users by name? say first name? I attempted:

    i had tried both:
    "firstname" => ""
    and
    "firstname" => '*'

    Code below:

    #!/usr/bin/perl -w
    use strict;
    use warnings;
    use SOAP::Lite +trace => 'debug';
    use Data:umper;
    use MIME::Base64;

            my $cucmip = "xx.xx.xx.xx";
            my $axl_port = "8443";
            my $user = "axl";
            my $password = "axl";
            my $axltoolkit = "AXLAPI.wsdl";

            my $cm = new SOAP::Lite
                    encodingStyle => '',
                    uri => "$axltoolkit",
                    proxy => "https://$cucmip:$axl_port/axl/" ;

            $cm = Login($cm,$user,$password);

            #axl request
            my $res =  $cm->listUserByName(SOAP:ata->name("firstname" => ""));
            unless ($res->fault) {
                     print Dumper($res->valueof('//listUserByNameResponse/return'));
            } else {
                    print join ', ',
                    "FAULTCODE: " . $res->faultcode,
                    "FAULTSTRING: " . $res->faultstring;
            }

    ################################################

    sub Login {
            $cm->transport->http_request->header (
                    'Authorization' => 'Basic ' . encode_base64("$user:$password", '')
            );

            return $cm;
    }
    ##################################################

    Subject: RE: Perl and AXL
    Replied by: Dan-Anders Hook on 08-02-2011 03:46:52 PM
    Hi,

    No worries, perl never gets old...

    I think the wildcard you are looking for is "%", i.e "firstname" => "%"

    If you have many users you might consider using searchLimit, skip and first to limit the size of the response.

    Kind regards,

    //Dan

    Subject: RE: Perl and AXL
    Replied by: Dan-Anders Hook on 08-02-2011 04:02:30 PM
    Hi again,

    Noticed that you are missing some of the elements. Lastname and searchLimit is mandatory.

    #!/usr/bin/perl -w
    use strict;
    use warnings;
    use SOAP::Lite +trace => 'debug';
    use Data:umper;
    use MIME::Base64;

    my $cucmip = "xx.xx.xx.xx";
    my $axl_port = "8443";
    my $user = "axl";
    my $password = "axl";
    my $axltoolkit = "AXLAPI.wsdl";

    my $cm = new SOAP::Lite
    encodingStyle => '',
    uri => "$axltoolkit",
    proxy => "https://$cucmip:$axl_port/axl/" ;

    $cm = Login($cm,$user,$password);

    #axl request
    my $res = $cm->listUserByName(SOAP:ata->name("firstname" => "%"),
                   SOAP:ata->name("lastname" => "%"),
                   SOAP:ata->name("searchLimit" => "")
    );
    unless ($res->fault) {
    print Dumper($res->valueof('//listUserByNameResponse/return'));
    } else {
    print join ', ',
    "FAULTCODE: " . $res->faultcode,
    "FAULTSTRING: " . $res->faultstring;
    }

    ################################################

    sub Login {
    $cm->transport->http_request->header (
    'Authorization' => 'Basic ' . encode_base64("$user:$password", '')
    );

    return $cm;
    }
    ##################################################

    Kind regards,

    //Dan