Looking up cPanel API call parameters

MattDees

Well-Known Member
Apr 29, 2005
416
1
243
Houston, TX
cPanel Access Level
Root Administrator
So, I'm not sure if I posted this here previous or not, but I have a nifty little dumper CustomEventHandler I wrote that logs all cPanel API calls made to the error_log. This means that you can see what parameters it was called with which is very handy if you need information on how API1/API2 calls are made (for theme development, etc).

This will only print returned data for API2 calls, API1 calls print data rather than return so it is rather difficult to do this.

Installation:

wget sdk.cpanel.net/utils/CustomEventHandler-Dumper.tar.gz
tar vzxf CustomEventHandler-Dumper.tar.gz
cp CustomEventHandler-Dumper/CustomEventHandler.pm /usr/local/cpanel/Cpanel
cp CustomEventHandler-Dumper/Dumper.pm /usr/local/cpanel/perl/Data
tail -f /usr/local/cpanel/logs/error_log

and hit something in the interface.

NOTE: this shold never by run on a production server, thigns like password of new email/ftp/whatever accounts will be logged to the error_log with this enabled

NOTE: if you wish to filter to look for calls within a specific module, please check out the commented line within the event function of CustomEventHandler.pm

When you hit an API call in cPanel (which you will several times for every page):

statsbar:stat
$apiv = 2
$type = post
-----
$cfgref

$VAR1 = {
'rowcounter' => 'mainstats',
'infinitylang' => 'true',
'display' => 'diskusage|bandwidthusage'
};

-----
$dataref

$VAR1 = [
{
'percent10' => 0,
'normalized' => 1,
'rowtype' => 'even',
'percent20' => 0,
'item' => 'Monthly Bandwidth Transfer',
'zeroisunlimited' => 1,
'name' => 'bandwidthusage',
'_maxed' => 1,
'_count' => 0,
'units' => 'MB',
'percent' => 0,
'_max' => 'unlimited',
'count' => 0,
'max' => '∞ MB',
'percent5' => 0,
'langkey' => 'INDXBandwidth',
'module' => 'Stats',
'feature' => 'bandwidth',
'id' => 'bandwidthusage'
},
{
'percent10' => 0,
'normalized' => 1,
'percent5' => 0,
'rowtype' => 'odd',
'percent20' => 0,
'item' => 'Disk Space Usage',
'zeroisunlimited' => 1,
'name' => 'diskusage',
'langkey' => 'INDXDiskUsage',
'_maxed' => 0,
'_count' => '1.32',
'units' => 'MB',
'module' => 'Quota',
'_max' => 1000,
'percent' => 0,
'count' => '1.32',
'max' => '1000 MB',
'id' => 'diskusage'
}
];
 
Last edited:

MattDees

Well-Known Member
Apr 29, 2005
416
1
243
Houston, TX
cPanel Access Level
Root Administrator
This has been updated to log API1 parameters as well.

This now relies on /dev/shm being accessible, so please remember, development servers ONLY.
 

leefrom

Active Member
May 27, 2008
30
0
56
I just thought I'd mention that I've found this to be supremely useful in debugging API calls as well. It's a great way to verify that you are, indeed, making the calls you think you are, for example, and also gives you a chance to inspect the output from a different interface as well.

For example you make a call and it doesn't produce any output. Check the error_log after installing this, and if you don't see it in there--you know you probably aren't interfacing with WHM correctly. Or you do see it, but the parameters aren't what you thought they were--also good information that would be difficult to obtain otherwise.

Golden.