How to retrun value from custom hooks cpanel uapi module

Operating System & Version
centos 7
cPanel & WHM Version
latest

syslint

Well-Known Member
Verifed Vendor
Oct 9, 2006
268
7
168
India
cPanel Access Level
Root Administrator
Twitter
Hello,

I need help with a resturn value of custom hook module. The module code is as follows,

Perl:
sub foo {

    my ( $args, $result, $response ) = @_;
    my ( $arg1, $arg2 ) = $args->get( 'arg1', 'arg2' );
    my $feature = 'cfoo_foo';
    if ( !main::hasfeature($feature) ) {                   
        $result->error( '_ERROR_FEATURE', $feature );
        return;
    }
    if ( $Cpanel::CPDATA{'DEMO'} ) {
        $result->error( '_ERROR_DEMO_MODE', $feature );
        return;
    }
    my $success=0;
    if ($arg1 eq "foo"){
        $success=1;
    }
    else{
        $success=0;
    }
    if ($success) {
        $result->data();
        return 1;
    }
    else {
        return 0;
    }
}

The hook code is below,( the hook is python fun.py


Python:
runcmd="some-command-out-put-as-json"
da=os.popen(runcmd).read().rstrip()
return_value['status']=1
return_value['status_msg']=runcmd
return_value['msg']=da
result=json.loads(json.dumps(return_value))
return(result)


The debug result is as follows,



Code:
[2020-11-29 12:55:51 +0530] info [cpanel] ---debug_hooks---
[2020-11-29 12:55:51 +0530] info [cpanel]             msg: Beginning execution of script hook.
[2020-11-29 12:55:51 +0530] info [cpanel]           stage: pre
[2020-11-29 12:55:51 +0530] info [cpanel]          result: 0
[2020-11-29 12:55:51 +0530] info [cpanel]           point: main
[2020-11-29 12:55:51 +0530] info [cpanel]              id: 4ac88d48-ec5e-4088-82d7-32580762b169
[2020-11-29 12:55:51 +0530] info [cpanel]            hook: /usr/local/foo/cphooks/fun.py
[2020-11-29 12:55:51 +0530] info [cpanel]   escalateprivs: 1
[2020-11-29 12:55:51 +0530] info [cpanel]          weight: 100
[2020-11-29 12:55:51 +0530] info [cpanel] HOOK INFO: hook /usr/local/foo/cphooks/fun.py did not output any data
[2020-11-29 12:55:51 +0530] info [cpanel] ---debug_hooks---
[2020-11-29 12:55:51 +0530] info [cpanel]             msg: Finished execution of script hook.
[2020-11-29 12:55:51 +0530] info [cpanel]           stage: pre
[2020-11-29 12:55:51 +0530] info [cpanel]          result: 1
[2020-11-29 12:55:51 +0530] info [cpanel]           point: main
[2020-11-29 12:55:51 +0530] info [cpanel]              id: 4ac88d48-ec5e-4088-82d7-32580762b169
[2020-11-29 12:55:51 +0530] info [cpanel]            hook: /usr/local/foo/cphooks/fun.py
[2020-11-29 12:55:51 +0530] info [cpanel]   escalateprivs: 1
[2020-11-29 12:55:51 +0530] info [cpanel]          weight: 100

As you can see the "result" . Doesnt have any value. The hook works fine. Please help what am I missing
I checked the documentation of custom modules in cpanel and result management option. But I am unable to return the results.
 
Last edited by a moderator:

cPRex

Jurassic Moderator
Staff member
Oct 19, 2014
7,442
1,004
313
cPanel Access Level
Root Administrator
Hey there! I'm not sure that I have enough information to properly answer this for you based on the details provided. Can you let me know specifically what you're looking to do with the API/hook system? Once I know that I may be able to get you better details.
 

syslint

Well-Known Member
Verifed Vendor
Oct 9, 2006
268
7
168
India
cPanel Access Level
Root Administrator
Twitter
Hey there! I'm not sure that I have enough information to properly answer this for you based on the details provided. Can you let me know specifically what you're looking to do with the API/hook system? Once I know that I may be able to get you better details.
I need to get return result from the api hook. I already given sample code and the steps.
 

cPRex

Jurassic Moderator
Staff member
Oct 19, 2014
7,442
1,004
313
cPanel Access Level
Root Administrator
@syslint - I had our development team look at this yesterday and they let me know there wasn't enough details provided for us to get you more information. I'm also not seeing any familiar API calls from cPanel in the example listed. For this situation, it might be better to put in a ticket with our team so we can access the server with the issue and run the scripts on our side.