Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update example for Usage Metrics, fix incorrect use of username which should be domain, add simulated API call example, add code comments #296

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion provisioning-modules/usage-metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,24 @@ class MyMetricsProvider implements ProviderInterface
];
}

// This function is called by WHMCS cron job, TenantUsageMetrics
// Applies to all Product/Service that has Metrics
public function usage()
{
$serverData = $this->apiCall('stats');
$usage = [];
foreach ($serverData as $data) {
$usage[$data['username']] = $this->wrapUserData($data);
// Note that usage is indexed by domain name
$usage[$data['domain']] = $this->wrapUserData($data);
}

// All domains on the server with metrics should be returned, indexed by domain name
return $usage;
}

// This function is called when the "Refresh Now" button is clicked in WHMCS
// Applies to a single Product/Service
// $tenant parameter is the Product/Service domain name
public function tenantUsage($tenant)
{
$userData = $this->apiCall('user_stats');
Expand Down Expand Up @@ -113,6 +120,31 @@ class MyMetricsProvider implements ProviderInterface
private function apiCall($action)
{
// make remote call with $moduleParams

// Simulate an API call
// In WHMCS, create a Product/Service with domain name as shown below to collect these statistics

$response = [];
if ($action == 'stats') {
// Note domain is required to identify the tenant and metric
$response = [
[
'domain' =>'example1.com',
'emailaddr' => 10
],
[
'domain' =>'example2.com',
'emailaddr' => 20
]
];
} elseif ($action == 'user_stats') {
$response = [
// Note domain is not required for a single tenant
'emailaddr' => 10
];
}

return $response;
}
}
```
Expand Down