ehuk Posted March 7, 2009 Share Posted March 7, 2009 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? 0 Quote Link to comment Share on other sites More sharing options...
zoilodiaz Posted March 10, 2009 Share Posted March 10, 2009 hello, this is really good module for WHMCS work whit catci and all people use colocation or datacenter can sell server using WHMCS and this take one point out of UbertSmith DC. 0 Quote Link to comment Share on other sites More sharing options...
quicklyweb Posted March 12, 2009 Share Posted March 12, 2009 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); 0 Quote Link to comment Share on other sites More sharing options...
ehuk Posted March 12, 2009 Author Share Posted March 12, 2009 Thanks for that tip! That will solve a lot of problems!! I will give it ago and report back. 0 Quote Link to comment Share on other sites More sharing options...
ehuk Posted March 12, 2009 Author Share Posted March 12, 2009 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? 0 Quote Link to comment Share on other sites More sharing options...
ehuk Posted March 13, 2009 Author Share Posted March 13, 2009 Ignore the error, that seems to have sorted its self out. Time to get the SQL going! A little teaser... 0 Quote Link to comment Share on other sites More sharing options...
ehuk Posted March 13, 2009 Author Share Posted March 13, 2009 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; ?> 0 Quote Link to comment Share on other sites More sharing options...
arisythila Posted March 18, 2009 Share Posted March 18, 2009 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 0 Quote Link to comment Share on other sites More sharing options...
siforek Posted March 18, 2009 Share Posted March 18, 2009 Ignore the error, that seems to have sorted its self out. Time to get the SQL going! A little teaser... Very nice. Well done! 0 Quote Link to comment Share on other sites More sharing options...
Emerson Posted March 18, 2009 Share Posted March 18, 2009 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. 0 Quote Link to comment Share on other sites More sharing options...
arisythila Posted March 18, 2009 Share Posted March 18, 2009 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 0 Quote Link to comment Share on other sites More sharing options...
ehuk Posted March 18, 2009 Author Share Posted March 18, 2009 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! 0 Quote Link to comment Share on other sites More sharing options...
Emerson Posted March 19, 2009 Share Posted March 19, 2009 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? 0 Quote Link to comment Share on other sites More sharing options...
ehuk Posted March 19, 2009 Author Share Posted March 19, 2009 Ah sorry, forgot to mention that: http://www.yourwebsite.com/whmcs/bandwidth.php?id=13_1 (Daily Graph) http://www.yourwebsite.com/whmcs/bandwidth.php?id=13_2 (Weekly Graph) http://www.yourwebsite.com/whmcs/bandwidth.php?id=13_3 (Monthly Graph) http://www.yourwebsite.com/whmcs/bandwidth.php?id=13_4 (Yearly Graph) In my templates however I used: http://www.yourwebsite.com/whmcs/bandwidth.php?id={$customfields.1.value}_1 (Daily Graph) http://www.yourwebsite.com/whmcs/bandwidth.php?id={$customfields.1.value}_2 (Weekly Graph) http://www.yourwebsite.com/whmcs/bandwidth.php?id={$customfields.1.value}_3 (Monthly Graph) http://www.yourwebsite.com/whmcs/bandwidth.php?id={$customfields.1.value}_4 (Yearly Graph) Where {$customfields.1.value} is the ID Custom Field in the Admin Section. 0 Quote Link to comment Share on other sites More sharing options...
Emerson Posted March 19, 2009 Share Posted March 19, 2009 k I still dont get it. the php code you have above, is that the EXACT php code you are using in your bandwidth.php file? 0 Quote Link to comment Share on other sites More sharing options...
snelweg Posted March 19, 2009 Share Posted March 19, 2009 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 0 Quote Link to comment Share on other sites More sharing options...
Emerson Posted March 20, 2009 Share Posted March 20, 2009 ehuk, I have sent you a PM 0 Quote Link to comment Share on other sites More sharing options...
ehuk Posted March 22, 2009 Author Share Posted March 22, 2009 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? 0 Quote Link to comment Share on other sites More sharing options...
cyberneticos Posted March 22, 2009 Share Posted March 22, 2009 (edited) 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 March 22, 2009 by cyberneticos 0 Quote Link to comment Share on other sites More sharing options...
ehuk Posted March 23, 2009 Author Share Posted March 23, 2009 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! 0 Quote Link to comment Share on other sites More sharing options...
Emerson Posted March 23, 2009 Share Posted March 23, 2009 ehuk, sounds good. Thanks. So you have not been able to get the graph id passed to bandwidth.php yet? 0 Quote Link to comment Share on other sites More sharing options...
ehuk Posted March 23, 2009 Author Share Posted March 23, 2009 Nope I managed to get the bandwidth.php file working fine. What exactly is the problem on your end? 0 Quote Link to comment Share on other sites More sharing options...
Emerson Posted March 23, 2009 Share Posted March 23, 2009 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? 0 Quote Link to comment Share on other sites More sharing options...
ehuk Posted March 23, 2009 Author Share Posted March 23, 2009 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. 0 Quote Link to comment Share on other sites More sharing options...
Emerson Posted March 23, 2009 Share Posted March 23, 2009 Ahh ok I get it now. BUt that does not really hide the location of the graph as you can still just play with the id=X and you will see other users graphs. We need help LOL 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.