Jump to content

Cacti Integration (giving it a go!)


ehuk

Recommended Posts

Hi Guys,

 

I have just spent the last few days having a play with cacti to integrate for our Dedicated and Colo customers.

 

First of all I am not a programmer, just a sysadmin with knowledge of PHP, so I will appreciate any help I can get from the community. (Also, if everything below is completely inefficient, or has security issues, do let me know!)

 

The idea is simple, to integrate bandwidth graphs, and monthly bandwidth usage in the client portal. I think this can be achieved with a few scripts and "custom fields" in WHMCS.

 

So my initial thoughts was to use the "Export" function in Cacti to export the relevant graphs, and using something like this in the clientareproductdetails.tpl

 

{if $groupname eq "Dedicated Servers"}

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

<table cellspacing="1" cellpadding="0" class="frame">
 <tr>
   <td width="1536"><table width="100%" cellpadding="2">
     <tr>
       <td width="160" class="fieldarea"><strong>Total Monthly Usage: (Not sure how this will work yet)</strong></td>
       <td><strong>Coming Soon</strong></td>
     </tr>
     <tr>
       <td class="fieldarea">Daily Graph (5 Min): </td>
       <td><div align="center"><img src="http://0.0.0.0/graphs/graph_{$customfields.1.value}_1.png" alt="" /></div></td>
     </tr>
     <tr>
       <td class="fieldarea">Weekly Graph (30 Min): </td>
       <td><div align="center"><img src="http://0.0.0.0/graphs/graph_{$customfields.1.value}_2.png" alt="" /></div></td>
     </tr>
     <tr>
       <td class="fieldarea">Monthly Graph (2 Hour): </td>
       <td><div align="center"><img src="http://0.0.0.0/graphs/graph_{$customfields.1.value}_3.png" alt="" /></div></td>
     </tr>
     <tr>
       <td class="fieldarea">Yearly Graph (1 Day): </td>
       <td><div align="center"><img src="http://0.0.0.0/graphs/graph_{$customfields.1.value}_3.png" alt="" /></div></td>
     </tr>
   </table></td>
 </tr>
</table>

{/if}

 

{$customfields.1.value} would be something like the Graph ID defined in the Admin section.

 

Now this is all good, but the GraphIDs just follow a +1 sequence, meaning a curious customer can simply change the ID to see what happens. I solution to this would be to somehow edit Cacti to to use a random number.

 

(Just thinking out loud)

 

Another method would be to use individual user logins, and create a script to login automatically through the client portal and gather the graphs through the cacti GUI.

 

Am I on the right track? Would anyone else be interested in working on this with me?

Link to comment
Share on other sites

  • Replies 51
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Posted Images

It shouldn't be difficult to hide the image url.

You can create a custom php script where script shows the image in new locationand changes the name of the image.

 

$file = 'http://0.0.0.0/graphs/graph_'.$customfields.1.value.'_1.png';

$newfile = time ();

$newfile .='.png';

copy($file, "newloacation/".$newfile);

Link to comment
Share on other sites

Hey Guys,

 

I managed to get this working for hiding the URLs:

 

bandwidth.php

 

<?php
//Define Array - Will use MySQL at later stage
$map = array(
1 => "http://bwgraphs/graphs/graphs/graph_13_1.png",
2 => "http://bwgraphs/graphs/graphs/graph_14_1.png",
3 => "http://bwgraphs/graphs/graphs/graph_15_1.png",
);

//Output - Change Content-type depending on your image type
header('Content-type: image/png');

$id = $_GET['id'];
readfile($map[$id]);

exit;
?>

 

The arrays will be stored in a MySQL DB, and maybe editable via an Addon Module? (Will need some help on that!).

 

One problem though, I can't seem to figure out. I can't seam to use readfile on my cacti (test) server!

 

Warning: readfile(http://bwgraphs.xxxxxxxxxxxx.co.uk/graphs/graphs/graph_13_1.png) [function.readfile]: failed to open stream: Connection timed out in /home/xxxxxx/bandwidth.php on line 9

 

It works when I change the URL of the image to another server, but doesn't work from my cacti server! Any ideas?

 

The server is behind a PFSense FW with NAT, not sure if that will help.

 

Any ideas?

Link to comment
Share on other sites

Now I my knowledge of php breaks down! I have created a table mod_cacti and I have two fields; pid = product ID, gid = graph ID

 

In the original script, I used an example gid of 13, of which there are 4 graphs:

 

graphs/graph_13_1.png - Daily

graphs/graph_13_2.png - Weekly

graphs/graph_13_3.png - Monthly

graphs/graph_13_4.png - Yearly

 

$map = array(
'13_1' => "http://bwgraphs.xxxxxxxxxxxxxxxxx.co.uk/graphs/graphs/graph_13_1.png",
'13_2' => "http://bwgraphs.xxxxxxxxxxxxxxxxx.co.uk/graphs/graphs/graph_13_2.png",
'13_3' => "http://bwgraphs.xxxxxxxxxxxxxxxxx.co.uk/graphs/graphs/graph_13_3.png",
'13_4' => "http://bwgraphs.xxxxxxxxxxxxxxxxx.co.uk/graphs/graphs/graph_13_4.png",

);

 

Insert into clientareaproductdetails.tpl:

 

http://www.xxxxxxx.co.uk/client/bandwidth.php?id={$customfields.1.value}_1

http://www.xxxxxxx.co.uk/client/bandwidth.php?id={$customfields.1.value}_2

http://www.xxxxxxx.co.uk/client/bandwidth.php?id={$customfields.1.value}_3

http://www.xxxxxxx.co.uk/client/bandwidth.php?id={$customfields.1.value}_4

 

So what I am try to do now is to fetch gid from the mysql field rather than manually putting in in the script manually.

 

I am sure its something simple, but I am hoping someone with PHP knowledge will cooksomething up!

 

<?php
require 'configuration.php';

mysql_connect("$db_host", "$db_username", "$db_password") or
   die("Could not connect: " . mysql_error());
mysql_select_db("$db_name");

$result = mysql_query("SELECT pid, gid FROM mod_cacti");

//Define Array - Will use MySQL at later stage
$map = array(
'13_1' => "http://bwgraphs.xxxxxxxxxxxxxxxxx.co.uk/graphs/graphs/graph_13_1.png",
'13_2' => "http://bwgraphs.xxxxxxxxxxxxxxxxx.co.uk/graphs/graphs/graph_13_2.png",
'13_3' => "http://bwgraphs.xxxxxxxxxxxxxxxxx.co.uk/graphs/graphs/graph_13_3.png",
'13_4' => "http://bwgraphs.xxxxxxxxxxxxxxxxx.co.uk/graphs/graphs/graph_13_4.png",

);

//Output - Change Content-type depending on your image type
header('Content-type: image/png');

$id = $_GET['id'];
readfile($map[$id]);

exit;


?>

Link to comment
Share on other sites

Which version of Cacti are you running? My graphs are all pulled from

 

http://cacti.blah.com/graph_imagewhm.php?action=view&local_graph_id=229&rra_id=1

 

So I'm wondering its easy to do what you guys are doing, but how do we do authentication. make it automatically log in.

 

~Michael

 

For this you would use the export graph feature of cacti then point to those graphics. This is why he mentioned the need to mask the URL of the image.

Link to comment
Share on other sites

Just figured that out.

 

This is what I have so far.

 

1. Setup the export graph feature in cacti.

 

2. rsync that graphs directory over to my billing directory (So you dont get "this website is unsafe errors)

 

then i just follow the code above. I have not got the calculation stuff done yet tho.

 

~Michael

Link to comment
Share on other sites

Hi Michael,

 

As Emerson mentioned I chose to use the export function, but you can use rsync. Either way I would recommend masking your graphs, the script on Post 5 works a treat and I am using it live.

 

Another mod I did was to use a separate custom field (Drop down) to select the cacti server (we use multiple servers).

 

I am still looking for assistance to convert this to an Admin Addon module. Please PM me details!

Link to comment
Share on other sites

Hi Michael,

 

As Emerson mentioned I chose to use the export function, but you can use rsync. Either way I would recommend masking your graphs, the script on Post 5 works a treat and I am using it live.

 

Another mod I did was to use a separate custom field (Drop down) to select the cacti server (we use multiple servers).

 

I am still looking for assistance to convert this to an Admin Addon module. Please PM me details!

 

 

On post 5 you showed how to do it with the GID of 13. How did you get the GID to pass to the bandwidth.php file?

Link to comment
Share on other sites

I am still looking for assistance to convert this to an Admin Addon module. Please PM me details!

 

Would love to help out. PHP programmer for a few years now.

I am playing around with the same stuff you are doing, would be great if we could share.

The use of a custom-field and some template scripting is ok, but I want to be able to edit the list of graphs (and APC's) from the back-end. And I just can't find anyhting about how to do that. I can make an AddOn, but I want it to appear in the configuration menu.

 

The APC reboot thingy is another thing I am working on.

Same stuff basicly.

 

Ton

Link to comment
Share on other sites

Hi Guys,

 

Sorry for the delay, just making changes to the actual cacti server, moving it on to a VPS rather than a dedicated machine, just having some issues with inter-vlan routing, so had to sort all that out first!

 

@ Emerson

 

I think its best if I reply publicly on this one, I want to get this working as an free "addon module". I have no plans of charging for this.

 

@ snelweg

 

As I mentioned on my "NOC Management" thread (Client Discussion) I want to get a set of modules out there which will help customers (like us) who mainly deal with dedicated servers, colo, and rackspace. I thought the Cacti graphs would be a good place to start, but I would like to see some APC Reboot (SNMP) integration.

 

I am thinking modules for:

 

Cacti Graphs

APC Remote Reboot

KVM over IP via DRAC (not sure if this is possible)

Remote Reboot via DRAC (not sure if this is possible)

IP Management

Reverse DNS Delegations

Rackspace Management (Where servers are located etc.)

Simple Expenses Sheet (How much Revenue from a Rack, Cost of a Rack)

(anything else you can think of)?

 

Obviously that's a lot of work, but once done, I think that's it for all our needs!

 

I am sure people would love to see this?

Link to comment
Share on other sites

OF course we would love to see this. And I really think you should set up a donation button at least. I would like to help out testing your addons.

 

My only concern is,. how long would you plan on maintaining these addons ? The good thing about paying a commercial prodcut is that it gives us a sense of security to stay on top of new whmcs releases.

 

thanks !

Edited by cyberneticos
Link to comment
Share on other sites

Hi There,

 

This is the reason I want it open in the community, for free, my knowledge only goes so far, but if we can get a few people involved, I hope it will keep up to date quite well.

 

Most of the modules are quite simple, so it shouldn't breakdown with updates, but that is the exact reason I don't want to make a commercial product. That is not our business, but hell if someone else makes a commercial product I will buy it!

Link to comment
Share on other sites

I don't get how to pass the variable to the file.

Like on post 5 you showed the file using a hard coded gid (13). How are you passing that to bandwidth.php from a custom field?

Is the code on post 5 the exact code you are using live?

Link to comment
Share on other sites

Ahhh yes that is exactly as I am using. I haven't yet found a way to pass the GID from the custom field to the file.

 

The bandwidth.php file has to have the graph links manually inserted.

 

I am hoping with some help, to add these graph links by a small page or an addon module.

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