Community Forums
Connect with us on LinkedIn
Community Notice
+ Reply to Thread
Results 1 to 7 of 7
  1. #1
    Member
    Join Date
    May 2003
    Posts
    36

    Talking Deleting / Removing old Urchin Profiles

    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 Code:
    #!/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.
    Last edited by Patiek; 07-24-2004 at 05:14 PM.

  2. #2
    Member
    Join Date
    May 2003
    Posts
    36

    Default

    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 Code:
    #!/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.
    Last edited by Patiek; 07-24-2004 at 05:15 PM.

  3. #3
    Registered User
    Join Date
    Dec 2003
    Posts
    1

    Default

    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. #4
    Member
    Join Date
    Aug 2003
    Location
    Toronto, Canada
    Posts
    107

    Default

    Quote Originally Posted by Rockey
    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
    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. #5
    Member
    Join Date
    May 2003
    Posts
    102

    Default

    Thanks! .

  6. #6
    Member
    Join Date
    Jan 2002
    Posts
    113

    Default

    Quote Originally Posted by cyanide
    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 !

    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. #7
    Member
    Join Date
    Sep 2004
    Location
    Cleveland, Ohio
    Posts
    378

    Default

    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.

Similar Threads & Tags
Similar threads

  1. Cpanel no longer uatomatically added urchin profiles..
    By secwrd in forum cPanel and WHM Discussions
    Replies: 1
    Last Post: 02-17-2007, 10:19 AM
  2. How to delete Urchin profiles?
    By BraveX in forum cPanel and WHM Discussions
    Replies: 6
    Last Post: 03-14-2006, 11:08 PM
  3. help: cpanel automatically re-adding urchin profiles
    By Jeff-C in forum cPanel and WHM Discussions
    Replies: 4
    Last Post: 12-20-2005, 07:24 PM
  4. Urchin Profiles Being Deleted Automatically
    By Brando in forum cPanel and WHM Discussions
    Replies: 0
    Last Post: 05-17-2005, 01:45 AM
  5. Only autocreate Urchin profiles for some plan types
    By peeeeeter in forum cPanel and WHM Discussions
    Replies: 2
    Last Post: 04-02-2005, 10:49 AM
Linkedin       Facebook       Twitter       RSS       Flickr       YouTube