Greetings,
I'm developing a module to setup a user on my server and sync their usage data to whmcs. I've successfully contextualized usage metrics now the big issue here is how whmcs track usage metrics my progress so far is below:
I've created a new class which implements "ProviderInterface" below is the code for "metrics" function
public function metrics()
{
return [
new Metric(
'disk',
'Disk Utilized',
MetricInterface::TYPE_SNAPSHOT,
new MegaBytes,
new Usage(0)
)
];
}
usage function is
public function usage()
{
$serverData = $this->apiCall('stats');
$usage = [];
foreach ($serverData as $data) {
$usage[$data['username']] = $this->wrapUserData($data);
}
return $usage;
}
tenantusage function is
public function tenantUsage($tenant)
{
$userData = $this->apiCall('user_stats');
return $this->wrapUserData($userData);
}
helper wrapuserdata function is:
private function wrapUserData($data)
{
$wrapped = [];
foreach ($this->metrics() as $metric) {
$key = $metric->systemName();
if ($data[$key]) {
$value = $data[$key];
$metric = $metric->withUsage(
new Usage($value)
);
}
$wrapped[] = $metric;
}
return $wrapped;
}
And lastly helper apicall function which delibrately sends a value somewhat emulating an api call for now.
private function apiCall($action)
{
if($action == "stats"){
return [
[
"username" => "kamran@domain.com", //this represents my username which is provided to whmcs
"disk" => 100
]
];
}
else{
return [
[
"disk" => 100
]
];
}
}
Okay so far in the above mentioned code, date and time updates but usage details are not updating. BTW I'm checking metrics using module parameters using $params["metricStats"][0]["currentvalue"]
So please help me with the below mentioned questions.
What is the correct way to return "usage()" function including what should be the identifier of the tenant(i.e. the key of value usage object where key should be serviceid?accountid?userid? of the tenant)?
Whenever cron job "TenantUsageMetrics" runs only "usage()" function is invoked and never "tenantusage()" why?
Also if my syntax is wrong a possible example would be tremendous.
Thank you for hearing me out!