The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Deleting / Removing old Urchin Profiles

Discussion in 'cPanel Developers' started by Patiek, Jul 22, 2004.

  1. Patiek

    Patiek Active Member

    Joined:
    May 23, 2003
    Messages:
    36
    Likes Received:
    0
    Trophy Points:
    6
    I got a support ticket the other day asking as to why the client's urchin was not working. I was surprised myself because I knew that the server had a 300 domain/profile urchin license and that this server was only hosting about 100 domains / subdomains.

    I found that cPanel was not removing old Urchin profiles when the domain accounts were being removed from the server. Thus, my urchin profile limit of 300 had been reached and I was given the error Unable to get profile id from configuration database when trying to view a new client's urchin stats.

    I looked around a few different forums for a script to remove old urchin profiles but came up with nothing. So I created my own. I figure running it once a week or month via cron will do the job I need of removing those old urchin profiles:

    PHP:
    #!/usr/local/cpanel/3rdparty/bin/php

    <?php

    // path to urchin folder ~ no trailing slash
    $urchin_path "/usr/local/urchin";

    // Your access hash key from WHM panel
    $accesshash 'INSERT YOUR ACCESS KEY HASH HERE';




    /* Syntax we are using... You can find info on urchin and cpanel sites

    List all urchin profiles - /usr/local/urchin/util/uconf-driver action=list table="profile"
    Remove urchine profile $name - /usr/local/urchin/util/uconf-driver action=delete table="profile" name="$name"
    List all cpanel accounts of $user - $accts = listaccts($host,$user,$accesshash,0);

    */

    // cPanel variables
    require '/usr/local/cpanel/Cpanel/Accounting.php.inc';
    $host "localhost";
    $user "root";



    $accts listaccts($host,$user,$accesshash,0);

    // Cycle through array that is returned. The first of each account array contains domain
    foreach($accts as $current_account)
        
    $ALL_ACCOUNT_DOMAINS[] = $current_account[0];


    // Get number of records in urchin db
    $urchin_num = `{$urchin_path}/util/uconf-driver action=nrecords table="profile"`;

    $urchin_command "{$urchin_path}/util/uconf-driver action=list table=\"profile\" start=0 n=" trim($urchin_num);

    // Contains all return info
    $urchin_id_strings = `$urchin_command`;

    // Create array based on spaces
    foreach(explode(" "$urchin_id_strings) as $current_value)
    {
        
    // Look for format of profile names, store in regs
        
    if (ereg("^(name=)\"([^\"]+)\""$current_value$regs))
        {
            
    // If current profile is not in cpanel accounts, assume it needs to be removed
            
    if (array_search($regs[2], $ALL_ACCOUNT_DOMAINS) === false)
            {
                
    $IDS_TO_REMOVE[] = $regs[2];
            }
        }
    }

    if (!empty(
    $IDS_TO_REMOVE))
    {
        
    // Yes, I know -- we could have done this command earlier. But lets just place it here
        
    foreach($IDS_TO_REMOVE as $current_profile)
        {
            
    // Remove current_profile
            
    $result = `{$urchin_path}/util/uconf-driver action=delete table="profile" name="$current_profile"`;
        }
    }

    // Check new urchin number
    $new_urchin_num = `{$urchin_path}/util/uconf-driver action=nrecords table="profile"`;

    // Echo out how many records have been removed.
    echo "Profiles Removed: " . (trim($urchin_num) - trim($new_urchin_num)) . "\n\n";
    The main two variables that need to be edited are your urchin path and your WHM hash access key.

    This script will pull the account domains on the server from cpanel, check them against the profiles in urchin, and remove any profiles that are old and do not have any corresponding domain account on the server.

    Just place it in a file (something like remove-old-urchin.php).
    # chmod 0755 remove-old-urchin.php
    and execute: # ./remove-old-urchin.php

    Now my new question is... will cpanel automatically create the profiles of the domains that were having problems or is this something I need to do manually as well? I know new domains will be fine, but I am asking about old ones.
     
    #1 Patiek, Jul 22, 2004
    Last edited: Jul 24, 2004
  2. Patiek

    Patiek Active Member

    Joined:
    May 23, 2003
    Messages:
    36
    Likes Received:
    0
    Trophy Points:
    6
    And then I ran across another problem: How do I add the profiles that were not added because of the urchin license limt?

    This script will do that for you:
    PHP:
    #!/usr/local/cpanel/3rdparty/bin/php

    <?php

    // path to urchin folder ~ no trailing slash
    $urchin_path "/usr/local/urchin";

    // Your access hash key from WHM panel
    $accesshash 'INSERT WHM HASH KEY HERE';




    /* Syntax we are using... You can find info on urchin and cpanel sites

    List all urchin profiles - /usr/local/urchin/util/uconf-driver action=list table="profile"
    Remove urchine profile $name - /usr/local/urchin/util/uconf-driver action=delete table="profile" name="$name"
    List all cpanel accounts of $user - $accts = listaccts($host,$user,$accesshash,0);

    */

    // cPanel variables
    require '/usr/local/cpanel/Cpanel/Accounting.php.inc';
    $host "localhost";
    $user "root";



    $accts listaccts($host,$user,$accesshash,0);

    // Cycle through array that is returned. The first of each account array contains domain
    foreach($accts as $current_account)
        
    $ALL_ACCOUNT_DOMAINS[] = $current_account[0];


    // Get number of records in urchin db
    $urchin_num = `{$urchin_path}/util/uconf-driver action=nrecords table="profile"`;

    $urchin_command "{$urchin_path}/util/uconf-driver action=list table=\"profile\" start=0 n=" trim($urchin_num);

    // Contains all return info
    $urchin_id_strings = `$urchin_command`;

    // Create array based on spaces
    foreach(explode(" "$urchin_id_strings) as $current_value)
    {
        
    // Look for format of profile names, store in regs
        
    if (ereg("^(name=)\"([^\"]+)\""$current_value$regs))
        {
            
    $IDS_FROM_URCHIN[] = $regs[2];
        }
    }

    // Cycle through cpanel accounts and check if each exists in urchin
    foreach($ALL_ACCOUNT_DOMAINS as $current_domain)
    {
        if (
    array_search($current_domain$IDS_FROM_URCHIN) === false)
        {
            
    $logfile_format "/usr/local/apache/domlogs/" $current_domain;
            
    $add_profile = `{$urchin_path}/util/uconf-driver action=add table=profile name="$current_domain" ct_name="$current_domain" ct_website="http:\//www.$current_domain" ct_reportdomains="$current_domain,www.$current_domain"`;

            
    $add_logs = `{$urchin_path}/util/uconf-driver action=add table=logfile name="$current_domain" cr_action=2 ct_name="$current_domain" cr_type=local ct_loglocation="$logfile_format" cs_logformat=auto cs_rlist=$add_profile`;

            
    $add_ref = `{$urchin_path}/util/uconf-driver action=set_parameter recnum=$add_profile cs_llist=$add_logs`;
            echo 
    "Added " $current_domain "\n";
        }
    }

    // Check new urchin number
    $new_urchin_num = `{$urchin_path}/util/uconf-driver action=nrecords table="profile"`;

    // Echo out how many records have been added.
    echo "Profiles Added: " . (trim($new_urchin_num) - trim($urchin_num)) . "\n\n";
    It checks the cpanel account against the urchin accounts. If a cpanel account exists that is found not to have an urchin profile, the script creates the profile, the log source, and then links the profile and log source.

    I have tested & executed this on my servers as well. It does the job. This one, however, should only need to be run once (after the first time you run the removal script) because cpanel should add profiles for all new domains created as long as you have not reached your urchin license limit.
     
    #2 Patiek, Jul 22, 2004
    Last edited: Jul 24, 2004
  3. Rockey

    Rockey Registered

    Joined:
    Dec 3, 2003
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    1
    is there a way to stop cpanel from automatically creating Urchin profiles? i only have 100 profiles urchin license and i can't afford to create profiles for all domains and subdomains too :(
     
  4. cyanide

    cyanide Well-Known Member

    Joined:
    Aug 11, 2003
    Messages:
    106
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    Toronto, Canada
    Yeah, I'd kinda like to know the answer to this one also.

    And, thanks for the script for updating Urchin. :) Will come in handy !
     
  5. InternetPEI

    InternetPEI Well-Known Member

    Joined:
    May 26, 2003
    Messages:
    102
    Likes Received:
    0
    Trophy Points:
    16
  6. wadearnold

    wadearnold Well-Known Member

    Joined:
    Jan 13, 2002
    Messages:
    111
    Likes Received:
    0
    Trophy Points:
    16

    Anyone have any luck with this? I have gone through all my profiles and removed the ones that I didn't need. I ran /scripts/runlogsnow and it added everything back. Whatever cpanel is doing is even adding a profile for subdomains. This makes it so that the first 100 domains on my license are used pretty fast. I don't get the chance to add that additional 45 domains that I acutally need.
     
  7. Blue|Fusion

    Blue|Fusion Well-Known Member

    Joined:
    Sep 12, 2004
    Messages:
    378
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    Cleveland, Ohio
    Out of shear curiosity and boredom I tried this out on the latest CURRENT tree. I'm surprised it still works (but hey, that's a great thing!). Unfortunatrly, it doesn't work 100%. Subdomains aren't taken into account when removing the profiles. Running /scripts/runlogsnow adds them again, and no past data is lost so it's not much of a big deal. I set it up to run monthly and to run /scripts/runlogsnow immediately afterwards.
     
Loading...

Share This Page