cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1283
Views
0
Helpful
0
Comments
cdnadmin
Level 11
Level 11
This document was generated from CDN thread

Created by: Martin Sloan on 27-10-2011 11:22:58 AM
Hello,
 
I'm trying to script the udpate of ~3000 phone description fields in CUCM (8.5.1) using a Perl (5.10.1) script.  Thanks to the info on this site, I have enough built to query the CUCM and return info for end user accounts but I'm struggling to move the script to getPhone/updatePhone.  Here is the getUser script that I'm using (which was again, thanks to the folks here in the forum):
 
use warnings;
use SOAP::Lite;
use diagnostics;
my $cucmip = "10.186.78.4";
my $axl_port = "8443";
my $user = "PerlAXL";
my $password = "Pa$$word";
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/" ;

#get info                                                                                                                                    
print "What is the User ID of the user?\n";
       chomp ($userid = <STDIN>);

#axl request                                                                                                                                 
my $res =  $cm->getUser(SOAP:ata->name("userid" => $userid));
unless ($res->fault) {
    print "That users first name is ".$res->valueof('//getUserResponse/return/user/firstname');
    print "\n";
}

else {
        print join ', ',
        $res->faultcode,
        $res->faultstring;
}
 
If you're able to recommend a way to modify the script to update the description field, it would be much appreciated.  I'm a total noob with Perl/AXL if that isn't obvious enough already, but I'm seriously interested in learning these techniques.  I'm rolling through "Learning Perl" for the fundamentals but I'm not finding much info to map it to CUCM/AXL/SOAP::Lite.  If anyone has a recommendation for reading material, please let me know.
 
Thanks much,
 
Marty

Subject: RE: AXL updatePhone Perl Script
Replied by: Dan-Anders Hook on 28-10-2011 04:49:35 AM
Hi,

I don't remember if I've used updatePhone with Perl, but I found a code snippet that adds phones instead. Maybe this helps you on the way?

Kind regards,

//Dan

 1
 2
 3print "Creating Test Phones\n";
 4
 5my @models = (     'Cisco 7940', 'Cisco 7940', 'Cisco 7960', 'Cisco 7960', 'Cisco 7912',
 6                'Cisco 7912', 'Cisco ATA 186', 'Cisco ATA 186', 'Cisco 7960', 'Cisco 7912',
 7                'Cisco 7911', 'Cisco 7941', 'Cisco 7906', 'Cisco 7961', 'Cisco 7941',
 8                );
 9
10my $test = 3000;
11
12for my $x(0 .. scalar(@models-1)) {
13    my $dn = $test + $x;
14    print " $models[$x] - $dn\n";
15    eval {
16        $som = $result->addLine(    SOAP::Data->name('newLine' => \SOAP::Data->value(
17                        SOAP::Data->name('pattern' => $dn ),
18                        SOAP::Data->name('usage' => '' ),
19                        SOAP::Data->name('routePartitionName' => '' ),
20                ))
21                                );
22    };
23    print $@;
24
25    eval {
26        my $som = $result->addPhone(SOAP::Data->name('newPhone' => \SOAP::Data->value(
27                    SOAP::Data->name('name' => "BAT$dn$dn$dn" ),
28                    SOAP::Data->name('description' => "TAPS Test Phone - $dn" ),
29                    SOAP::Data->name('product' => $models[$x] ),
30                    SOAP::Data->name('model' => $models[$x] ),
31                    SOAP::Data->name('class' => 'Phone' ),
32                    SOAP::Data->name('protocol' => 'Cisco-station' ),
33                    SOAP::Data->name('protocolSide' => 'User' ),
34                    SOAP::Data->name('devicePoolName' => 'Default' ),
35                    SOAP::Data->name('lines' => \SOAP::Data->value(
36                        SOAP::Data->name( 'line' => \SOAP::Data->value(
37                            SOAP::Data->name('label' => "TAPS TEST $dn" ),
38                            SOAP::Data->name('display' => "TAPS TEST $dn" ),
39                            SOAP::Data->name( 'dirn' => \SOAP::Data->value(
40                                SOAP::Data->name('pattern' => $dn ),
41                                SOAP::Data->name('usage' => '' ),
42                                SOAP::Data->name('routePartitionName' => '' ),
43                            )),
44                                                                                SOAP::Data->name('ringSetting' => 'Use System Default' ),
45                            SOAP::Data->name( 'callInfoDisplay' => \SOAP::Data->value(
46                                SOAP::Data->name('callerName' => 'true' ),
47                                SOAP::Data->name('callerNumber' => 'false' ),
48                                SOAP::Data->name('redirectedNumber' => 'false' ),
49                                SOAP::Data->name('dialedNumber' => 'true' ),
50                            )),
51                        ))
52                                  ->attr({'index' => '1'} )
53                    ))
54                )
55            )
56        );
57    };
58    print $@;
59}


Subject: RE: AXL updatePhone Perl Script
Replied by: Martin Sloan on 27-10-2011 02:43:04 PM
UPDATE:

Kept searching and found the info to update the phones.  Here's the new script to update the description field of a phone:

#!/usr/bin/perl                                                                                                                              

use SOAP::Lite;
use Data:umper;

my $cucmip = "10.186.78.4";
my $axl_port = "8443";
my $user = "PerlAXL";
my $password = "Pa$$word";
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/" ;

my $res =
  $cm->updatePhone(
         SOAP:ata->name('name' => 'SEP123456123456'),
         SOAP:ata->name('lines' => SOAP:ata->name('line' => SOAP:ata->name('index' => '1'),
                                                                 SOAP:ata->name('description' => 'AXLTEST2')
                                                      )
                          )
    );

unless ($res->fault) {
}
else {
        print join ', ',
        $res->faultcode,
        $res->faultstring;
}

The next step is to bring in data from a file/CSV and store the device name and description as variables to update all the phones.  If anyone has a recommendation, any help is appreciated.

Thanks,

Marty

Subject: RE: AXL updatePhone Perl Script
Replied by: Martin Sloan on 27-10-2011 10:57:24 PM
Update:

I used the split function to grab data from a tab separated text file to accomplish the bulk update portion.  Here is the code, which updates about 5 phones per second:

#!/usr/bin/perl                                                                

use SOAP::Lite;

my $cucmip = "192.168.10.30"; #Home Lab
my $axl_port = "8443";
my $user = "PerlAXL";
my $password = "Pa$$word";
my $axltoolkit = "AXLAPI.wsdl";

$start=time();

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/" ;

open (FILE, 'CUCM.txt');
while (<FILE>){
    chomp;
    ($name, $description) = split ("\t");
{
my $res =
  $cm->updatePhone(
         SOAP:ata->name('name' => "$name"),
         SOAP:ata->name('lines' => SOAP:ata->name('line' => SOAP:ata->name('index' => '1'),
                                                                 SOAP:ata->name('description' => "$description")
                                                      )
                          )                
    );

unless ($res->fault) {
}
else {
        print join ', ',
        $res->faultcode,
        $res->faultstring;
}}}
close (FILE);

$end = time();

print "That took Perl ", ($end - $start), " second(s) to update\n";

exit;

Thanks,

Marty

Subject: RE: AXL updatePhone Perl Script
Replied by: Martin Sloan on 04-11-2011 04:33:50 PM
Dan,

Thanks for the info!  The phone creation process was next on my list so I do appreciate the point in that direction.

Have a great day.

Marty
Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community:

Quick Links