I posted this on cpanel's forums and I figure I might as well post it here as well:
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
// 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";[/PHP]
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
I have used this on my servers and it works great. As to why cpanel doesn't remove these in the first place, I do not know.