#!/usr/bin/perl use strict; use warnings; use LWP::UserAgent; use LWP::Protocol::https; use XML::Simple; use Time::Piece; my $ua = LWP::UserAgent->new(ssl_opts => { SSL_verify_mode => IO::Socket::SSL::SSL_VERIFY_NONE, verify_hostname => 0, }); my $xml = new XML::Simple(ForceArray => ['User']); # Get Unity subscriber data from cucxnpub one page at a time # 2000 records to a page my $url = "https://cucxnpub/vmrest/users?rowsPerPage=2000"; my $userName = 'user'; my $passwd = 'password'; my $page = 1; my @userdata; while(1){ my $req = HTTP::Request->new(GET => $url."&pageNumber=$page"); $req->authorization_basic($userName,$passwd); $req->content_type('application/xml'); my $response = $ua->request($req); unless ( $response->is_success ){ die $response->status_line; } my $content = $response->decoded_content; my $data = $xml->XMLin($content); my $size = @{ $data->{User} || [] }; print "Page $page : $size\n"; # If we don't get at least one user end the loop last if ( $size == 0 ); # Build the userdata array, each entry contains "username,extension" for my $user ( @{$data->{User}} ){ push @userdata,"$user->{Alias},$user->{DtmfAccessId}"; } ++$page; } # Create a timestamp containing year, month, and day my $timestamp = localtime->ymd(''); # Dump the results of the unity query to a file my $dir = '/usr/scripts/unityLDAP/'; my $outfile = $dir."$timestamp-unity.csv"; open UNITY,'>',$outfile or die "Could not open $outfile : $!"; print UNITY "$_\n" for @userdata; close UNITY; printf "%d records written to %s\n",scalar @userdata,$outfile;