My Collab Lab

mycollablab.org

User Account Status

November 15, 2015 PHP Voicemail

This script is a work in progress that pulls users from Unity along with relivent information for assessments including local vs AD account, if the mailbox has been initialized and if it is setup for Unified Messaging, Mailbox count and unread count/percent. This will be expanded as is goes. Scripts writes standard output to CSV. Because of the way information needs pulled from Unity this script takes a long time to run. Very long on large enviroments.


<?php
  //debug = true;  //uncomment for curl debugging
  $host     = "172.20.0.12";
  $username = "admin";
  $password = "Stryk3r10";

header("Content-Description: File Transfer"); 
header("Content-Type: text/csv"); 
header("Content-Disposition: attachment; filename=UnityExport.csv"); 


function getUsers($get) {

    global $host;
    global $username;
    global $password;
    global $debug;

    $ch=curl_init();

    ob_start();  
    $out = fopen('php://stderr', 'a+');
    
    if ( isset($debug) ) {
        curl_setopt($ch, CURLOPT_VERBOSE, true); 
        curl_setopt($ch, CURLOPT_STDERR, $out);   
    }
    
    $cupiurl="https://".$host.$get;

    curl_setopt( $ch, CURLOPT_URL, $cupiurl );
    curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
    curl_setopt($ch, CURLOPT_USERPWD, $username.":".$password);
    curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    $result = curl_exec($ch);
    curl_close($ch);

    fclose($out);

    $cupi = json_decode(json_encode((array)simplexml_load_string($result)),1);

    return $cupi;
}
function printString($pass_value) {
    if ( ! empty($pass_value) ) {
            return "'".$pass_value."',";
        } else {
            return ",";
        }
}

$user_count = getUsers("/vmrest/users?rowsPerPage=10&pageNumber=0");
$user_count = $user_count['@attributes']['total'];

$user_pages = floor(($user_count / 10)+1);

echo "Alias,DtmfAccessId,FirstName,LastName,DisplayName,Department,LdapType,IsSetForVmEnrollent,UnifiedMessaging,Messages,Unread,Percent\n";
$page = 1;
while ( $page <= $user_pages ) {

    $cupi_array = getUsers("/vmrest/users?rowsPerPage=10&pageNumber=".$page);

    foreach ( $cupi_array['User'] as $user) {
        if ( @$user['Alias'] != '' ) {
            $user_detail = getUsers($user['URI']);
            $external_service = getUsers($user_detail['ExternalServiceAccountsURI']);
            $mailbox = getUsers("/vmrest/mailbox/folders/inbox/messages?userobjectid=".$user['URI']);
            $new_message=0;
            foreach ( $mailbox['Message'] as $message ) {
                if ( $message['Read'] == "false" ) {
                    $new_message++;
                }
            }
        $value  = "'".@$user_detail['Alias']."',";
        $value .= "'".@$user_detail['DtmfAccessId']."',";
        $value .= printString(@$user_detail['FirstName']);
        $value .= printString(@$user_detail['LastName']);
        $value .= printString(@$user_detail['DisplayName']);
        $value .= printString(@$user_detail['Department']);
        if ( @$user_detail['LdapType'] == 3 ){
            $value .= "'LDAP',";
        } else {
            $value .= "'Local',";
        }
        $value .= "'".@$user_detail['IsSetForVmEnrollment']."',";
        if ( @$external_service['@attributes']['total'] == 1 ) {
            $value .= "'true',";
        } else {
            $value .= "'false',";
        }
        $value .= "'".@$mailbox['@attributes']['total']."',";
        $value .= "'".@$new_message."',";
        if ( @$mailbox['@attributes']['total'] > 0 ) {
            $new_message = round( $new_message / @$mailbox['@attributes']['total'] * 100 );
        } else {
            $new_message = 0;
        }
        $value .= "'".$new_message."%'";

            echo $value."\n";
        }
    }
    $page++;
}
?>

analyticsphpstatusunity

IADS - Internal Abbreviated Dialing System

Unity Prompt Upload


Jon Snipes
LinkedIn

My career progressed from head butcher to Collaboration CCIE. There isn’t much technically that carries over between professions, but 8 years of direct customer service experience and squeezing margin out of processes provided a solid base and direction for the rest of my career. My focus today is deep into collaboration messaging, voice and video with the expertise to develop processes and programmatic solutions to complex business problems.

Principal Architect at Cloverhound
CCIE Collaboration 51786
Cisco Webex Expert
2018-2021 Cisco Champion

Categories
  • Cloud (4)
  • Contact Center (1)
  • Development (1)
  • PHP (10)
  • Python (3)
  • Uncategorized (1)
  • Video (2)
  • Voice (12)
  • Voicemail (5)
  • Webex (7)
Recent Posts
  • Azure OAuth2.0 User Authentication December 4, 2021
  • Pass-through Gateway Routing and Dial Peer Groups December 4, 2021
  • Get Started Coding with Python: System Setup and Running Scripts December 4, 2021
  • Exporting CUCM to an Offline Local DB with Python December 4, 2021
  • Connecting to UCCX INFORMIX DB with Python on Linux December 4, 2021
Proudly powered by WordPress | Theme: Doo by ThemeVS.