Jump to content

Get Server Account Usage


Recommended Posts

Hello!

I'm trying to get the number of accounts/users on servers using feeds.

Has anyone accomplished this?

Basically want to pull number with that feed (ie 10/20 allowed on LA #1 server) and create a variable for a status page.

I can probably use stock levels, but I'd rather pull from server usage instead of setting up stock levels for all of those products and fighting suspensions, etc for an accurate reading.

 

Thanks!

Edited by Metahuman Network
Link to comment
Share on other sites

at it's most basic, the data feed code would be along the lines of...

<?php

# Server Accounts Data Feed
# Written by brian!

use WHMCS\Application;
use WHMCS\Database\Capsule;
require("../init.php");

/*
*** USAGE SAMPLES ***
<script language="javascript" src="feeds/serveraccounts.php?serverid=1"></script>
*/

	$whmcs = Application::getInstance();
	$serverid = $whmcs->get_req_var('serverid');
	$num_accounts = Capsule::table('tblservers_remote')->where('server_id', $serverid)->value('num_accounts');
	$max_accounts = Capsule::table('tblservers')->where('id', $serverid)->value('maxaccounts');
	if (!is_numeric($serverid) || empty($serverid)) {
		$accountusage = 'Server ID Not Found';
	} elseif ($max_accounts > 0) {
		$accountusage = $num_accounts.' / '.$max_accounts;
	}
	echo "document.write('".$accountusage."');";

and you would call it in the page by using (assuming the data feed file is called serveraccounts.php and checking the relevant path to the file is correct)....

<script language="javascript" src="feeds/serveraccounts.php?serverid=1"></script>

if the serverid value is valid (e.g it's a number, the server ID of that # exists and it allows more than 0 accounts on it), then it should return "number of accounts  /  max number of accounts" (e.g 12/200).

the output can be expanded to whatever you need it to be (within reason!) - so hopefully if gives you a starting point...

Link to comment
Share on other sites

  • 3 weeks later...

Finally getting around to testing this out, thanks!

After looking at my database, there are no entries in tblservers_remote. How is that table populated?

Where does WHMCS pull these active accounts from?

1337407741_ScreenShot2021-02-08at6_40_56PM.thumb.png.f7e20b6f74f0fd59bf5dec911fa3f83e.png

tblhosting? We could probably pull id from server column where domainstatus is active and add up.

Any idea on that side?

 

Thanks again for all your help! ❤️

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated