Jump to content

Cacti Integration (giving it a go!)


ehuk

Recommended Posts

  • Replies 51
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Posted Images

Ok so I have a friend that was nice enough to get this script for us.

It works and although it does show the GID on the URL it only allows you access to the graphs if you are logged in and they belong to you.

 

Big thanks to Jon at http://www.websitecm.com for doing this on his own time and allowing me to share this code with you guys.

 

Any feedback would be appreciated.

 

Please see the attached file for the bandwith.php file as well as the graphs directory where the graphs need to be.

Just upload everything to your WHMCS directory and make sure that cacti is exporting the graphs to the WHMCS/graphs directory.

 

In clientareaproductdetails.tpl I added:

 

{if $groupname eq "Dedicated Servers"}

<p class="heading2">Bandwidth Graphs (Beta)</p>

<table cellspacing="1" cellpadding="0" class="frame">
 <tr>
   <td><table width="100%" cellpadding="2">
     <tr>
       <td nowrap class="fieldarea"><strong>Total Monthly Usage:</strong></td>
       <td width="100%"><strong>Coming Soon</strong></td>
     </tr>
</table>
<table border="0" cellpadding="0" cellspacing="5" class="frame">
     <tr>
       <td nowrap class="fieldarea">Daily Graph<br>(5 Min): </td>
       <td><div align="center"><img src="/WHMCS/bandwidth.php?id={$customfields.1.value}&image=1" /></div></td>
     </tr>
     <tr>
       <td nowrap class="fieldarea">Weekly Graph<br>(30 Min): </td>
       <td><div align="center"><img src="/WHMCS/bandwidth.php?id={$customfields.1.value}&image=2" /></div></td>
     </tr>
     <tr>
       <td nowrap class="fieldarea">Monthly Graph<br>(2 Hour): </td>
       <td><div align="center"><img src="/WHMCS/bandwidth.php?id={$customfields.1.value}&image=3" /></div></td>
     </tr>
     <tr>
       <td nowrap class="fieldarea">Yearly Graph<br>(1 Day): </td>
       <td><div align="center"><img src="/WHMCS/bandwidth.php?id={$customfields.1.value}&image=4" /></div></td>
     </tr>
   </table></td>
 </tr>
</table>

{/if}

 

 

Any feedback would be appreciated.

bandwidth.zip

Link to comment
Share on other sites

Hi Emerson,

 

That looks awesome! I will give it a go once I get the the new Cacti server back up. Only problem is we have our Cacti and Website on two separate servers, and the built in FTP solution kinda sucks! So I will come up with something with rsync!

Link to comment
Share on other sites

Hey ehuk,

Yes, it is working awesome. Knowing that nosies can not see other's graphs is nice.

 

Yup, I spent a good time last night trying the FTP export and had no luck.

I ended up doing a quick and dirty script to just rsync the graphs from the cacti server to the whmcs server and that is working pretty good.

Link to comment
Share on other sites

I just tried this out and the logic seems to be there but I am not getting the graphs to load properly. I am seeing the image place holders instead (which is weird) and if I login as a user with another assigned GID and use the old URL then I get the image not found graphic.

 

The images are present in the /graphs/ directory with a URL similar to /graphs/graph_1_1.png, /graphs/graph_1_2.png, etc.

 

Any ideas?

Link to comment
Share on other sites

I just tried this out and the logic seems to be there but I am not getting the graphs to load properly. I am seeing the image place holders instead (which is weird) and if I login as a user with another assigned GID and use the old URL then I get the image not found graphic.

 

The images are present in the /graphs/ directory with a URL similar to /graphs/graph_1_1.png, /graphs/graph_1_2.png, etc.

 

Any ideas?

 

I tried breaking this down to see if the query itself from a raw mysql perspective would work with our WHMCS installation. Thus far, I have created a custom client field called id and then on one of our test accounts, I have assigned a value of 5. Our domain is similar to blah.domainname.com, so the bandwidth.php file is located at the root of the subdirectory and we have a graphs sub-folder which is keeping all of our .png files.

 

If i go directly to the URL based on how the code is calling it then the image loads however once I login as the test user I see the default "data not available" image.

 

From what I have been able to figure out we have a situation where the query is resulting in two relid entries with different values and fieldids. However, I am not sure if this is causing a problem. I tried adding an AND v.fieldid=21 (21 is the fieldid assigned to our custom customer field) but this did not work at all.

 

If I commend out the section where the security check is performed then the graphs load fine. So this confirms that it is something to do with this "check". I assigned an id value to a user that does not have this problem and the images still do not load the only thing that is left could be where the comparison of uid and h.userid. If i do this logic manually using mysql syntax then it works fine and the value is what I am expecting but the code doesn't yield any results at runtime.

 

To the people that got this working, any ideas?

 

Also, if the id field is created as a customer field then how is it being protected? As a user I can do to my details and change my field id value and view graphs from other users and the code does not have the logic to retrieve the value of the custom id field if it is created as an admin only field.

 

I see in the example, that a custom page was created so does this mean that the if customfields element was/should be removed from the clientareadetails.tpl?

Link to comment
Share on other sites

  • 4 weeks later...
  • 1 month later...
function manageAPCPort($apcip, $apcport, $apcpass, $action) {
$apcportcontrolmib = ".1.3.6.1.4.1.318.1.1.12.3.3.1.1.4.";
$mib = $apcportcontrolmib.$apcport;

$result = snmpset($apcip, $apcpass, $mib, i, $action);

return $result;
}

function pdu_action($pdus, $action) {

$power = explode("\n",$pdus);

foreach($power as $value):
	list($pdu,$pdu_port) = split(":",$value);


	$sqlresult = mysql_query("SELECT address, username, password, community, Type FROM mod_pdu WHERE name='".strtoupper($pdu)."'");
	$row = mysql_fetch_row($sqlresult);

	$pdu_address	= trim($row[0]);
	$pdu_username	= trim($row[1]);
	$pdu_password	= trim($row[2]);
	$pdu_community	= trim($row[3]);
	$pdu_type	= trim($row[4]);

	$pdu_port	= trim($pdu_port);
	$pdu_type	= "APC";

	switch (strtoupper($pdu_type)) {
		case "APC":
			switch (strtoupper($action)) {
				case "OFF":
					$pdu_action = "2";
				break;
				case "REBOOT":
					$pdu_action = "3";
				break;
				default:
					$pdu_action = "1";
				break;
			}
			$apc = manageAPCPort($pdu_address, $pdu_port, $pdu_community, $pdu_action);
		break;
	}
	if (!$apc){

		$result .= $value." could not be set to ".$action."<br>";
	}

endforeach;

return $result;
}


function modulename_AdminCustomButtonArray() {
# This function can define additional functions your module supports, the example here is a reboot button and then the reboot function is defined below
   $buttonarray = array(
 "Reboot" => "reboot",
 "Power ON" => "on",
 "Power OFF" => "off",
);
return $buttonarray;
}

function modulename_reboot($params) {
return "asdfasf".pdu_action($params['customfields']['PDU'], "REBOOT");	
}

function modulename_on($params) {
return pdu_action($params['customfields']['PDU'], "ON");
}

function modulename_off($params) {
return pdu_action($params['customfields']['PDU'], "OFF");
}

Link to comment
Share on other sites

function manageAPCPort($apcip, $apcport, $apcpass, $action) {
$apcportcontrolmib = ".1.3.6.1.4.1.318.1.1.12.3.3.1.1.4.";
$mib = $apcportcontrolmib.$apcport;

$result = snmpset($apcip, $apcpass, $mib, i, $action);

return $result;
}

function pdu_action($pdus, $action) {

$power = explode("\n",$pdus);

foreach($power as $value):
	list($pdu,$pdu_port) = split(":",$value);


	$sqlresult = mysql_query("SELECT address, username, password, community, Type FROM mod_pdu WHERE name='".strtoupper($pdu)."'");
	$row = mysql_fetch_row($sqlresult);

	$pdu_address	= trim($row[0]);
	$pdu_username	= trim($row[1]);
	$pdu_password	= trim($row[2]);
	$pdu_community	= trim($row[3]);
	$pdu_type	= trim($row[4]);

	$pdu_port	= trim($pdu_port);
	$pdu_type	= "APC";

	switch (strtoupper($pdu_type)) {
		case "APC":
			switch (strtoupper($action)) {
				case "OFF":
					$pdu_action = "2";
				break;
				case "REBOOT":
					$pdu_action = "3";
				break;
				default:
					$pdu_action = "1";
				break;
			}
			$apc = manageAPCPort($pdu_address, $pdu_port, $pdu_community, $pdu_action);
		break;
	}
	if (!$apc){

		$result .= $value." could not be set to ".$action."<br>";
	}

endforeach;

return $result;
}


function modulename_AdminCustomButtonArray() {
# This function can define additional functions your module supports, the example here is a reboot button and then the reboot function is defined below
   $buttonarray = array(
 "Reboot" => "reboot",
 "Power ON" => "on",
 "Power OFF" => "off",
);
return $buttonarray;
}

function modulename_reboot($params) {
return "asdfasf".pdu_action($params['customfields']['PDU'], "REBOOT");	
}

function modulename_on($params) {
return pdu_action($params['customfields']['PDU'], "ON");
}

function modulename_off($params) {
return pdu_action($params['customfields']['PDU'], "OFF");
}

 

Do you have instructions for getting this feature setup like what files to edit?

Link to comment
Share on other sites

  • 1 month later...

I took a different approach:

 

In cacti, I made the graph title "switch-x-x-x-x#4 - ProductID:125" (the WHMCS product ID)

 

I passed bandwidth.php the product ID, and had it check the product ID with the user ID for verification.

 

My cacti is hosted on a remote server, so I opened up MySQL to the WHMCS host to check for the ProductID in the title and get the local graph ID.

 

Then bandwidth.php readfile()s the exported graph PNG from the remote server.

 

I think I made it a little complicated but this way you don't need custom fields in WHMCS, as you can't add a custom field to an entire product group (right?)

Link to comment
Share on other sites

  • 4 weeks later...

hi

 

ive been trying to get this working all day.

 

i have set cacti every 5 mins to put the files in /graph/ which it is doing just fine.

 

i have a custom port "SwitchPort" and configured the dedi server to use port 11 (For example) in whmcs.

 

in clientareproducts i have ie

 

img src="/bandwidth.php?id={$SwitchPort.1.value}&image=1

 

then when I login as clients it shows the no data available image.

 

/graph/ has ie graph_11_1.png etc

Link to comment
Share on other sites

  • 3 weeks later...
  • 2 weeks later...
hi

 

ive been trying to get this working all day.

 

i have set cacti every 5 mins to put the files in /graph/ which it is doing just fine.

 

i have a custom port "SwitchPort" and configured the dedi server to use port 11 (For example) in whmcs.

 

in clientareproducts i have ie

 

 

 

then when I login as clients it shows the no data available image.

 

/graph/ has ie graph_11_1.png etc

 

 

 

Have you setup rsync to get the graphs from your cacti machine to the /graphs/ folder? Is the custom field working correctly?

 

Emerson I have only recently played around with your script and it worked perfectly! Many thanks.

Link to comment
Share on other sites

  • 1 month later...

We have finished our dedicated server monitor .. this plug in monitors bandwidth usage on a rolling month, gives customers real time stats and bills for bandwidth overage using the billable option in WHMC. It gives the admin the ability to turn off and on servers with the click of a button, send emails, projections and basically is a completed pkg. We will be adding 95th percentile in the next iteration.

 

 

please watch demo 1 and demo 2.. they are a continuation.

 

we will be making this plug-in available shortly

 

Bill

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