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.

Looking up cPanel API call parameters

Discussion in 'cPanel Developers' started by MattDees, Sep 8, 2009.

  1. MattDees

    MattDees cPanel Product Owner
    Staff Member

    Joined:
    Apr 29, 2005
    Messages:
    417
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    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'
    }
    ];
     
    #1 MattDees, Sep 8, 2009
    Last edited: Sep 9, 2009
  2. MattDees

    MattDees cPanel Product Owner
    Staff Member

    Joined:
    Apr 29, 2005
    Messages:
    417
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    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.
     
  3. leefrom

    leefrom Active Member

    Joined:
    May 27, 2008
    Messages:
    30
    Likes Received:
    0
    Trophy Points:
    6
    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.
     
Loading...

Share This Page