npTechnologies Posted January 18, 2009 Share Posted January 18, 2009 We have just added bandwidth graphs to our client area and are interested now in allowing reboots of dedicated servers via our client area. We use APC AP7930 PDUs in the datacenter. It looks like this can be accomplished via the MIB and SNMP. Anyone have any experience or any luck accomplishing this? I would like to be able to show the outlet status, this have a reboot button next to the outlet status. I would be willing to hire someone for this if you have any suggestions. 0 Quote Link to comment Share on other sites More sharing options...
npTechnologies Posted January 19, 2009 Author Share Posted January 19, 2009 OK, I have made some progress on this on my own. But I am not very strong with PHP. Basically, what I want to do is add a button that says "Reboot Server" in the clientareaproductdetails.php When the customer hits this button, it will of course reboot their server. Here is the code that will reboot the server by using SNMP to commuicate with my APC device : snmpset -v 1 -c communityname xx.xx.xx.xx 1.3.6.1.4.1.318.1.1.4.4.2.1.3.# integer 3 Of course, xx.xx.xx.xx is the IP of my APC device. The '#' at the end of the long OID would be the outlet number. I will store the IP of the APC device and the outlet number as a custom field for the product: pduip = IP of the device pduoutlet = outlet number So, by using the custom fields, all I would have to do is put that information in the command above and execute it when the customer hits the reboot button. Any help as to how I can accomplish this? It would also be nice to display the outlet status somewhere close to the button, which can be poled by using snmpget to the same OID as above (integer of 1 or 2 is returned to indicate outlet status). But that isn't critical unless someone knows how to accomplish this. Anybody done this and care to help? 0 Quote Link to comment Share on other sites More sharing options...
mylove4life Posted January 19, 2009 Share Posted January 19, 2009 did you hit the APC website? I recall some one asking that on there site... 0 Quote Link to comment Share on other sites More sharing options...
npTechnologies Posted January 19, 2009 Author Share Posted January 19, 2009 I did not see anything in the forums, but I will have a look again... 0 Quote Link to comment Share on other sites More sharing options...
npTechnologies Posted January 19, 2009 Author Share Posted January 19, 2009 I am thinking I am going to have to store this differently in the custom fields, ie : xx.xx.xx.xx:## (ip address:outlet #) 0 Quote Link to comment Share on other sites More sharing options...
rslyon Posted January 19, 2009 Share Posted January 19, 2009 I would love to see this feature. 0 Quote Link to comment Share on other sites More sharing options...
ravotech Posted January 19, 2009 Share Posted January 19, 2009 We have just added bandwidth graphs to our client area and are interested now in allowing reboots of dedicated servers via our client area. We use APC AP7930 PDUs in the datacenter. It looks like this can be accomplished via the MIB and SNMP. Anyone have any experience or any luck accomplishing this?I would like to be able to show the outlet status, this have a reboot button next to the outlet status. I would be willing to hire someone for this if you have any suggestions. APC rebooter is the easiest thing AFAIK. The code is simple and not much. Graphs has been a struggle for us actually. Did you integrate cacti graphs to whmcs or use custom scripts? 0 Quote Link to comment Share on other sites More sharing options...
npTechnologies Posted January 19, 2009 Author Share Posted January 19, 2009 I understand that I can loop through the custom fields until I come to the field that contains the IP address of the remote reboot device, then I can just plug the value of the field into the snmpset command from above. But then how do I extract and use the outlet number needed? I would think since I will know the name of the custom field I could do it somehow. 0 Quote Link to comment Share on other sites More sharing options...
Emerson Posted February 19, 2009 Share Posted February 19, 2009 Hi themicro, Did you get anywhere with this? I am looking to have the same thing. 0 Quote Link to comment Share on other sites More sharing options...
msaunders Posted February 19, 2009 Share Posted February 19, 2009 Themicro Are you going to make your mod available to other WHMCS users or what are your plans ? Tnks Martin 0 Quote Link to comment Share on other sites More sharing options...
wsa Posted March 15, 2009 Share Posted March 15, 2009 In a month I have a APC & Cacti Mod 0 Quote Link to comment Share on other sites More sharing options...
othellotech Posted March 15, 2009 Share Posted March 15, 2009 apc's are pretty easy to control/integrate... $APCresponse = snmpget($APCip, $community, ".1.3.6.1.4.1.318.1.1.4.4.2.1.3.$APCport"); $APCresponse = str_replace('INTEGER: ', '', $APCresponse); switch ($APCresponse) { case '1': $returnVal = 'On'; break; case '2': $returnVal = 'Off'; break; case '3': $returnVal = 'Reboot'; break; case '4': $returnVal = 'Unknown'; break; case '5': $returnVal = 'On with delay'; break; case '6': $returnVal = 'Off with delay'; break; case '7': $returnVal = 'Reboot with delay'; break; default: $returnVal = $APCresponse; } snmpset ( $APCip, $community, ".1.3.6.1.4.1.318.1.1.4.4.2.1.3.$APCport", 'i', $rebootOption) 0 Quote Link to comment Share on other sites More sharing options...
ravotech Posted March 17, 2009 Share Posted March 17, 2009 apc's are pretty easy to control/integrate... Does this code work on any APC? Where did you find the snmp code? I couldn't find it in the manual... 0 Quote Link to comment Share on other sites More sharing options...
Hostserve Posted May 22, 2009 Share Posted May 22, 2009 umm.. does any one have any more details on this... ? I'd love to be able to add this to our whmcs for clients. 0 Quote Link to comment Share on other sites More sharing options...
gbwebhosts Posted June 7, 2009 Share Posted June 7, 2009 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"); } 0 Quote Link to comment Share on other sites More sharing options...
apex Posted October 18, 2009 Share Posted October 18, 2009 Here's a complete (albeit basic and a hack) setup for remote reboot functionality in the client's product page. This should work well for dedicated servers connected to APC PDU's. I used the apc/snmp code from the previous post. 1) Enable Write+ SNMP access to your APC device. 2) Either install php-snmp, or compile snmp support into your version of PHP, if it's not already there. For each Product/Service which is going to have reboot capabilities: 3) Open the Product/Service setup page and create a new Custom Field called 'apcconfig'. The type should be 'Text Box'. Leave all three checkboxes unchecked (this is important). Now navigate to each Client account and navigate to the Product/Service which will be rebootable. You should see the newly created "apcconfig" text box, which is blank. 4) Enter the APC IP address and the Power Outlet number of the device to be rebootable, separated by a comma. For example: 192.168.0.1,1 This would be used for an APC device at 192.168.0.1 and to reboot power outlet #1: 5) Edit the template file: templates/portal/clientareaproductdetails.tpl Replace this code: {foreach from=$customfields item=customfield} <tr> <td class="fieldarea">{$customfield.name}:</td> <td>{$customfield.value}</td> </tr> {/foreach} With this code: 6) Note: Replace 'yourapccommunitystringhere' with the community string you use for Write+ access to the APC. It's usually set to 'private' by default. {foreach from=$customfields item=customfield} {if $customfield.name != "apcconfig"} <tr> <td class="fieldarea">{$customfield.name}:</td> <td>{$customfield.value}</td> </tr> {else} <tr> <td class="fieldarea">Remote Reboot</td> <td> <form method="post" action="{$smarty.server.PHP_SELF}?action=productdetails"> <input type="hidden" name="id" value="{$id}" /> <input type="submit" name="submitz" value="Reboot Server"> </form> {php} if(isset($_POST['submitz'])) { $customfield = $this->get_template_vars('customfield'); $apcinfo = explode(",", $customfield['value']); $mib = ".1.3.6.1.4.1.318.1.1.12.3.3.1.1.4."; $mib = $mib.$apcinfo[1]; $community = "yourapccommunitystringhere"; $result = snmpset($apcinfo[0], $community, $mib, i, "3"); # echo($result); } {/php} </td> </tr> {/if} {/foreach} That's it. Be sure you replaced 'yourapccommunitystringhere' as described above. You can uncomment the echo command at the bottom if you want to display error messages associated with the SNMP command. For a client to reboot his/her server he would login to his account and navigate to My Services. Then click on the small icon leading to the Product Details page for the server to be rebooted. There should be a "Reboot Server" button in the middle of the page. When clicked this will issue the "Immediate Reboot" option on the APC. There is no confirmation or success dialog, although that's what I'll be adding next. This could be done in a much simpler way, but this is the only way I could think of so the client couldn't edit the port number, and reboot someone else's server 0 Quote Link to comment Share on other sites More sharing options...
apex Posted October 19, 2009 Share Posted October 19, 2009 On second thought, it seems better to have the reboot button available next to each product on the Products page instead of in the product description page. This code is a bit different because an SQL query is required to get the 'apcconfig' variable we setup in the previous post {php} $username="user"; $password="pass"; $database="database"; mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $pid = $this->get_template_vars('service'); $pid = ($pid['id']); $query="SELECT tblcustomfieldsvalues.value as cf from tblcustomfieldsvalues where relid = $pid;"; $result=mysql_query($query); while ($row = mysql_fetch_assoc($result)) { $cf = $row['cf']; } mysql_free_result($result); {/php} <td> <form method="post" action="{$smarty.server.PHP_SELF}?action=products"> <input type="hidden" name="id" value="{$id}" /> <input type="submit" name="submitz" value="Reboot Server"> </form> {php} if(isset($_POST['submitz'])) { $apcinfo = explode(",", $cf); $mib = ".1.3.6.1.4.1.318.1.1.12.3.3.1.1.4."; $mib = $mib.$apcinfo[1]; $result = snmpset($apcinfo[0], "communitystringhere", $mib, i, "3"); # echo($result); } {/php} You should be able to paste this into an appropriate location in clientareaproducts.tpl, change the three settings at the top, your community string at the bottom, and be good to go. 0 Quote Link to comment Share on other sites More sharing options...
Snowman Posted February 5, 2010 Share Posted February 5, 2010 Im a bit puzzled by the last bit of this code and where to place it in the clientareaproducts.tpl file can anyone advise? 0 Quote Link to comment Share on other sites More sharing options...
NetwiseHosting Posted February 26, 2010 Share Posted February 26, 2010 Hi All, I was wondering if somone could offer some assistance. I have followed the above tutorial step by step and everything seems ok except when I click the button in the product details page it takes me to another, less styled product details page with the same button. If this is clicked then nothing happens. I realise this information is vaague but I am not sure where to go from here, any help would be very gratefully received. Kind regards, Matthew 0 Quote Link to comment Share on other sites More sharing options...
Snowman Posted March 18, 2010 Share Posted March 18, 2010 Ive been working thru this module and i have the basics up and running Thanks for the code you supplied apex Im going to have a bit of a play around with the code and see if it can return the APC result message to the client I may also look at adding in the power on and power off functions as well. Has anyone looked at doing any of this already as i dont want to go and replicate what someone may have already coded? 0 Quote Link to comment Share on other sites More sharing options...
NetwiseHosting Posted March 19, 2010 Share Posted March 19, 2010 Ive been working thru this module and i have the basics up and running Thanks for the code you supplied apex Im going to have a bit of a play around with the code and see if it can return the APC result message to the client I may also look at adding in the power on and power off functions as well. Has anyone looked at doing any of this already as i dont want to go and replicate what someone may have already coded? Hi Snowman, Glad to hear you have had luck installing/configuring this feature. I have been playing with it on and off over the last couple of weeks and after double checking code etc I have come to the decision that SNMP-PHP must not be enabled/installed on my host. Just wondering if you had trouble with this at all? Kind regards, Matthew 0 Quote Link to comment Share on other sites More sharing options...
othellotech Posted March 19, 2010 Share Posted March 19, 2010 I have come to the decision that SNMP-PHP must not be enabled/installed on my host SNMP in PHP through Apache after 5.1.6 is "broken" - caused some interesting "hacks" needed for our power control modules 0 Quote Link to comment Share on other sites More sharing options...
Snowman Posted April 10, 2010 Share Posted April 10, 2010 SNMP in PHP through Apache after 5.1.6 is "broken" - caused some interesting "hacks" needed for our power control modules I cant say ive seen any issues and we are running php 5.2.13 currently and waiting to go up to 5.3.2 as soon as we know everythign is compatible Im looking at ways to add in the current status of the APC port, along with buttons to turn it off and on and a response message but im still trying to get my head around this presently there probably should also be some form of mechanism added to prevent a client from hitting it over and over and over, because as you will all know it does take a while for a server to respond to an apc boot... perhaps a 5 minute block on the button or something? 0 Quote Link to comment Share on other sites More sharing options...
NetwiseHosting Posted April 10, 2010 Share Posted April 10, 2010 Hi again Snowman, Thanks for your response. We are still not having huge amounts of luck integrating this feature, I was just wondering if you would consider doing this for us at all? If so what level of pricing would we be looking at? Thanks in advance. Kind regards, Matthew 0 Quote Link to comment Share on other sites More sharing options...
Snowman Posted April 10, 2010 Share Posted April 10, 2010 Matthew I am trying a few different options currently to work out the best option. The biggest stumbling block is going to be that different apc modules have different MIB's so that makes it difficult... and the way a couple of the other apc reboot modules around work prevent us from using it as they rely on the addon to be a server module which i dont think is right. Once we have a better performing working solution i will let you know. 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.