Access data passed from cPanel in a custom hook?
Hi,
I am starting to write some hooks instead of running shell scripts to further automation, but am having some trouble starting out.
I can make and register my hook, but I cannot run it using variables, I have to hard code everything which defeats the purpose.
Specifically I am starting with one hook that should rename a file on account upgrade/downgrade.
What is the syntax to access the data that you read into $data using
? I can print the information I want to /usr/local/cpanel/logs/error_log using :
and
That gives:
The username, current package and new package all show up, but I cannot seem to access the information in any way. I need to be able to use the 3 variables cur_pkg, new_pkg and user for some comparisons and to identify the file to be edited. I've tried entering the "user" field in $data into my own variable $username using various methods found on forums and in guides and documentation, but have been unsuccessful. I've looked at ARGV and OPTS, but am coming up short as I don't quite grasp it. All the cpanel guides I've seen do not actually use any of the passed data to the hook from what i can tell...oddly enough. As mentioned, if I skip the variable, the hook runs fine and does it's thing. Thank you in advance for any pointers.
my ( $context, $data ) = @_;? I can print the information I want to /usr/local/cpanel/logs/error_log using :
sub _more_logging {
my ( $context, $data ) = @_;
my $pretty_json = JSON->new->pretty;
$logger->info( $pretty_json->encode($context) );
$logger->info( $pretty_json->encode($data) );
and
_more_logging($context, $data);That gives:
info [whostmgr2] {
"category" : "Whostmgr",
"blocking" : 1,
"event" : "Accounts::change_package",
"point" : "main",
"stage" : "pre"
}
info [whostmgr2] {
"cur_pkg" : "Level1pkg",
"new_pkg" : "Level2pkg",
"user" : "cpanel_username"
The username, current package and new package all show up, but I cannot seem to access the information in any way. I need to be able to use the 3 variables cur_pkg, new_pkg and user for some comparisons and to identify the file to be edited. I've tried entering the "user" field in $data into my own variable $username using various methods found on forums and in guides and documentation, but have been unsuccessful. I've looked at ARGV and OPTS, but am coming up short as I don't quite grasp it. All the cpanel guides I've seen do not actually use any of the passed data to the hook from what i can tell...oddly enough. As mentioned, if I skip the variable, the hook runs fine and does it's thing. Thank you in advance for any pointers.
-
Hi @domeneas The following documentation may be helpful for this issue: Guide to Standardized Hooks - Whostmgr Functions - Developer Documentation - cPanel Documentation Guide to Standardized Hooks - Developer Documentation - cPanel Documentation Tutorial - Create a Standardized Hook - Developer Documentation - cPanel Documentation 0 -
Hi, those are the guides I have been looking at for a couple days, but I cannot see ANY example in them on how to address a field read into the $data variable. Tutorial page: In the example the only things they manipulate is a hard coded backup file. They never use anything passed from cpanel to the hook through $data. From what I gather, there isn't even a point to reading: my ( $context, $data ) = @_;
in the example code at all. WHOSTMGR functions page: Lists the information and field names put into $data. As stated, I can output those fine into the log file, see my post above, I know they are there, but I cannot access them in the perl module I am writing. Developer Documentation: Really only links to the two guides above. It does however say [QUOTE] Remember: If you have questions or need help with your customization project, join the conversation on our
The $old_name and $new_name is based on $data's "user" field. How do I address the fields "cur_pkg", "new_pkg" and "user" passed into $data after runningmy ( $context, $data ) = @_;
? Thanks again.0 -
Hello, The following post includes an example you may find helpful: While the script in this post is unrelated to what you are doing, it provides an example of how you can pull variables out of an API event. Thank you. 0
Please sign in to leave a comment.
Comments
3 comments