AXL perl script "getuser" associatedDevices

Version 1
    This document was generated from CDN thread

    Created by: Michael Schmidt on 05-04-2012 03:56:21 PM
    Hi,
     
    we try to read out with the "getuser" AXL perl script the devices (hardphone / udp) which are associated to an End User.
     
    Getting back the "firstname" and the "lastname" of a user is working with this but getting back the "associatedDevices" we only get back HASH(0x33e1324) instead of the associated Cisco hardphone SEPxxxxxxxxxxxx:
     
        print "That users first name is ".$res->valueof('//getUserResponse/return/user/firstname');
        print "\n";
        print "That users last name is ".$res->valueof('//getUserResponse/return/user/lastname');
            print "\n";
        print "AssociatedDevices ".$res->valueof('//getUserResponse/return/user/associatedDevices/');
        print "\n";
     
    Does anybody knows this problem and how we can solve this?
     
    BR
    Michael

    Subject: RE: AXL perl script "getuser" associatedDevices
    Replied by: Michael Schmidt on 05-04-2012 05:25:01 PM
    Hi Marty,

    the end user has associated

    1 x "Controlled Devices" --> 1 x SEPxxxxxxxxxxxx
    1 x "Controlled Profiles" --> 1 x UDP (user device profile)

    I will try your suggestion as soon as possible because I`m actually not in the office. I will try to test this tomorrow from remote from a server directly.

    BR
    Michael

    Subject: RE: AXL perl script "getuser" associatedDevices
    Replied by: Michael Schmidt on 06-04-2012 05:50:43 AM
    Hi Marty,

    thank you very much.

    I also just tried it and it worked with this command

    print "AssociatedDevices ".$res->valueof('//getUserResponse/return/user/associatedDevices/device/');

    instead of

    print "AssociatedDevices ".$res->valueof('//getUserResponse/return/user/associatedDevices/');

    Now I also get back the associated SEP device which I also see in the GUI.

    I make some further tests and write you back if I have some further problems.

    Thank you so far.

    BR
    Michael

    Subject: RE: AXL perl script "getuser" associatedDevices
    Replied by: Martin Sloan on 05-04-2012 05:14:17 PM
    Hi Michael,

    I'm thinking that the user has more than 1 device associated and the CUCM is returning the results in a hash which you'd have to de-reference and print/other afterward.  If you use Data:umper and:

              print Dumper($res-paramsall());

    you could post the results here and I'll try to help further.

    Thanks,

    Marty

    Subject: RE: AXL perl script "getuser" associatedDevices
    Replied by: Martin Sloan on 05-04-2012 10:36:48 PM
    Hi Michael,

    Thanks, I got a chance to test and this worked for me.

    print "AssociatedDevices ".$res->valueof('//getUserResponse/return/user/associatedDevices/device/');   # 'device' added to the end

    The XML structure of the return message looks like this:

    $VAR1 = {
              'user' => {
                        'pin' => '',
                        'firstname' => 'Martin',
                        'department' => '',
                        'userid' => 'msloan'',
                        'lastname' => 'Sloan',
                        'primaryDevice' => 'SEP001D4560F000',
                        'password' => '',
                        'remoteDestinationLimit' => '4',
                        'digestCredentials' => '',
                        'associatedDevices' => {
                                               'device' => 'SEP001D4560F000'
                                             },
                        'enableCTI' => 'true',
                        'telephoneNumber' => '',
                        'associatedPC' => '',
                        'phoneProfiles' => {

                        etc....

    The device info is a level deeper in the structure.  When there is more than 1 device associated, the XML structure changes and includes an anonymous hash (square brackets):

    'associatedDevices' => {
                                               'device' => [
                                                           'SEP001D4560F000',
                                                           'SEP9743'
                                                         ]
                                             },
    When you try to access assocaiatedDevices->device the same way as above when there are multiple devices, it returns ARRAY(something).  I can assist if you need (and don't mind using Data Dumper!)

    HTH

    Marty

    Subject: RE: AXL perl script "getuser" associatedDevices
    Replied by: Michael Schmidt on 06-04-2012 04:44:38 PM
    Hi Marty,

    how the perl script have to look like when a user have more than one phone associated?

    For example

    1 x cisco hardphone
    1 x Cisco Unified Client Services Framework


    I tried this but it`s not working:

        print "AssociatedDevices ".$res->valueof('//getUserResponse/return/user/associatedDevices/device0/');
    print "\n";
        print "AssociatedDevices ".$res->valueof('//getUserResponse/return/user/associatedDevices/device1/');
    print "\n";


        print "AssociatedDevices ".$res->valueof('//getUserResponse/return/user/associatedDevices/device/0/');
    print "\n";
        print "AssociatedDevices ".$res->valueof('//getUserResponse/return/user/associatedDevices/device/1/');
    print "\n";

    BR
    Michael

    Subject: RE: AXL perl script "getuser" associatedDevices
    Replied by: Martin Sloan on 07-04-2012 09:48:12 AM
    Hey Michael,

    I use something like this:

    unless ($res->fault) {
    $Data:umper::Incident=3;
            my ($reply) = $res->paramsall();
    my $devices = $reply->{user}{associatedDevices}{device};
    foreach (@$devices) {
                print "$_\n";
    }
        }

    This will grab each device and print it.  Let me know if you have any issues.

    Marty

    Subject: RE: AXL perl script "getuser" associatedDevices
    Replied by: Martin Sloan on 08-04-2012 12:36:49 PM
    Hey Michael,

    Glad it worked for you and Happy Easter to you too!

    It sounds like you have the right game plan for updating the devices.  I have run into some weirdness with the updatePhone method when adding lines but I don't think you'll hit that here.  I found that when adding a line to a phone with updatePhone the line gets added but all other lines are removed!  Just test it out if you haven't already to make sure all is well after the update.

    If you wanted to save a message or two you could (but certainly don't have to) use the SQL Update method since both the hard phone and UDP reside in the device table.  Just send a message something like "update device set description = "new description" where description = "old description" (assuming the update is actually intended for the description field :-).  This would update all hardphones, CUPC clients, IP Communicators, UDP's etc in one message.

    Have a great holiday and let me know if you need anything else.

    Marty

    Subject: RE: AXL perl script "getuser" associatedDevices
    Replied by: Michael Schmidt on 07-04-2012 05:28:14 PM
    Hi Marty,

    thank you so much. I hope you have Happy Easter.

    With adding this to the perl script getuser.pl it`s working to read out also for example 2 associated devices:

    my ($reply) = $res->paramsall();
    my $devices = $reply->{user}{associatedDevices}{device};
    foreach (@$devices) {
    print "$_\n";
    }

    What we trying to use this script "getuser" additional with "updatePhone", "updateLine" and "updateDeviceProfile" for is to update the change of name in the Active Directory automatically at the phones.

    The "updatePhone", "updateLine" and "updateDeviceProfile" scripts are already working and I hope we can implement this after Easter.

    So if there is a name changed in the Activce Directory we want to read out the associated devices with getuser and then update the phone, line and deviceprofile of the user.

    Is this the easiest why of implement the automatically change of the disply / configured names at the Cisco phones? Do you also use perl scripts for automatically change of the name at the Cisco phones?

    BR
    Michael

    Subject: RE: AXL perl script "getuser" associatedDevices
    Replied by: Michael Schmidt on 08-04-2012 04:24:02 PM
    Hi Marty,

    I thank you so much for your great help :-)

    I will be back in the office at Friday and test all these things.

    For the moment I just have some more questions but it`s not really urgent:

    In our "getuser" script we using this prompt for asking for the username to get the infos about:

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


    1. Is it also possible to read out with "getuser" every user from the CUCM without inserting one specified username?

    2. Is it also possible just to display all the users with "getuser" which have one phone and / or UDP associated?


    In the worst-case scenario when a username have changed in the active directory the affected end user has no phone and / or UDP associated at CUCM.


    3. Is there also a command like "getuser" just for getting back the associated devices for a DN (directory number)? Maybe something like "getline"?


    Because when the name in AD is changed and the affected end user have not associated the phone and also not the UDP at CUCM I just would search for the end users DN and for the associated devices with this DN which I also would see at CUCM web gui when I open the DN of the end user.

    BR
    Michael

    Subject: RE: AXL perl script "getuser" associatedDevices
    Replied by: Martin Sloan on 11-04-2012 09:42:50 AM
    Hi Michael,

    For these issues, I would typically use the SQL select method.  I've been using the update and select methods more and more since I find it easier to get and update the information that way.  For your questions, here's what I would do:

    1. Is it also possible to read out with "getuser" every user from the CUCM without inserting one specified username?

      - I would use "select userid from enduser".  This is assuming you want to list only userid.  You could use "select userid,firstname,lastname,etc...." if you want more info. (Check out the data dictionary for any info on the DB tables - this info is for v8.5.1)

    2. Is it also possible just to display all the users with "getuser" which have one phone and / or UDP associated?

      - Use something like "select e.userid, e.firstname, e.lastname, d.name device from ((device d inner join enduserdevicemap em on d.pkid = em.fkdevice) inner join enduser e on e.pkid = em.fkenduser)"  There may be a more elegant way to get the info, but this would be my approach.  It will list users an associated devices.

    3. Is there also a command like "getuser" just for getting back the associated devices for a DN (directory number)? Maybe something like "getline"?

      - For this one, you could "select n.dnorpattern, d.name device from ((numplan n inner join devicenumplanmap dnpm on n.pkid = dnpm.fknumplan) inner join device d on d.pkid = dnpm.fkdevice) order by n.dnorpattern".  This will give you a list of DN's with their associated devices, ordered by DN.

    This would be my approach but there might be an easier way to do it through the "list" methods (which I've always had issues getting to work for some reason.....).  If you're more comfortable staying away from the SQL statements someone here might be able to recommend a way using the list methods, but I hope this info does help!

    Marty

    Subject: RE: AXL perl script "getuser" associatedDevices
    Replied by: Michael Schmidt on 11-04-2012 04:31:21 AM
    Hi Marty,

    do you have any answers to these 3 questions?

    BR
    Michael

    Subject: RE: AXL perl script "getuser" associatedDevices
    Replied by: Michael Schmidt on 12-04-2012 04:06:41 PM
    Hi Marty,

    many thanks for your answers.

    Is it possible you mail me some SQL examples to get these informations?

    BR
    Michael