Snowman Posted April 12, 2010 Share Posted April 12, 2010 (edited) Ok heres a basic improvement on APEX's post for the reboot function earlier in this discussion just change the MIB string to suit your model APC Ive tested it out on AP7951 and AP7952 and AP7953 switched rack units follow the instructions that APEX Provided: 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 Instead of following APEX's step 5add the following code to the bottom of the template file so that it creates its own section (i use a tabulated page on our own install to show it on a sperate tab) <table> <tr> <td><h3>Remote Reboot</h3></td> </tr> {if $customfield.name != "apcconfig"} <tr> <td>Remote Reboot facility currently not available </td> </tr> {else} <tr> <td>The remote reboot service allows you to remotely reboot or power your server on or off from the helpdesk system. <br><br><b>Please note:</b> you should only click on the button once and wait as it can take anywhere up to 15 to 20 minutes for the process to complete.<br><br> </td> </tr> <tr> <td><b>Current Status:</b><i>pending</i> {php} function displayPowerStatus($result) { $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 = "private"; $a = trim(snmpget($apcinfo[0], $community, $mib, 20000), "INTEGER: "); switch ($a) { case 1: $return = "On"; break; case 2: $return = "Off"; break; case 3: $return = "Rebooting"; break; default: $return = "Error"; break; } echo ($return); } {/php} <br><br> </td> </tr> <tr> <td> <table width="96%"> <tr><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> </td> {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 = "private"; $result = snmpset($apcinfo[0], $community, $mib, i, "3"); # echo($result); } {/php} <td> <form method="post" action="{$smarty.server.PHP_SELF}?action=productdetails"> <input type="hidden" name="id" value="{$id}" /> <input type="submit" name="turnoff" value="Power Off"> </form> </td> {php} if(isset($_POST['turnoff'])) { $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 = "private"; $result = snmpset($apcinfo[0], $community, $mib, i, "2"); # echo($result); } {/php} <td> <form method="post" action="{$smarty.server.PHP_SELF}?action=productdetails"> <input type="hidden" name="id" value="{$id}" /> <input type="submit" name="turnon" value="Power On"> </form> </td> {php} if(isset($_POST['turnon'])) { $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 = "private"; $result = snmpset($apcinfo[0], $community, $mib, i, "1"); # echo($result); } {/php} <td> <form method="post" action="{$smarty.server.PHP_SELF}?action=productdetails"> <input type="hidden" name="id" value="{$id}" /> <input type="submit" name="delayon" value="Delayed Power On"> </form> </td> {php} if(isset($_POST['delayon'])) { $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 = "private"; $result = snmpset($apcinfo[0], $community, $mib, i, "4"); # echo($result); } {/php} <td> <form method="post" action="{$smarty.server.PHP_SELF}?action=productdetails"> <input type="hidden" name="id" value="{$id}" /> <input type="submit" name="delayoff" value="Delayed Power Off"> </form> </td> {php} if(isset($_POST['delayoff'])) { $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 = "private"; $result = snmpset($apcinfo[0], $community, $mib, i, "5"); # echo($result); } {/php} <td> <form method="post" action="{$smarty.server.PHP_SELF}?action=productdetails"> <input type="hidden" name="id" value="{$id}" /> <input type="submit" name="delayreboot" value="Delayed Reboot"> </form> </td> {php} if(isset($_POST['delayreboot'])) { $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 = "private"; $result = snmpset($apcinfo[0], $community, $mib, i, "1"); # echo($result); } {/php} </td> </tr> </table> {/if} </td> </tr> </table> You will need to adjust each reference of private in the lines: $community = "private"; to use the community string you have setup for write+ mode on your apc im yet to complete the functionDisplayStatus section where it will show the current status of the apc port as im not sure on how to display the returned status within the smarty template but the other functions work well. The code does need some clean up and separation of the language file and better database integration but i will address that in a full module of this in a couple of weeks when i get a chance to complete the cleanup and debug and cleanup of a few of the functions, for example im using repeated functions for each of the reboot buttons instead of one form and an else/if setup Edited April 12, 2010 by Snowman 0 Quote Link to comment Share on other sites More sharing options...
NetwiseHosting Posted May 11, 2010 Share Posted May 11, 2010 Hi Snowman, Firstly thanks for publishing this, you must have spent a huge amount of time on it, much appreciated. I have followed the installation exactly and have it all displaying on the test product page fine but I have a feeling I have the wrong MIB string, I was just wondering how I can locate the correct one? All our devices are the AP7920 model. Thanks again and I look forward to hearing back from you. Kind regards, Matthew 0 Quote Link to comment Share on other sites More sharing options...
Snowman Posted May 11, 2010 Share Posted May 11, 2010 while im not 100% certain the 7920 should use the same MIB string 0 Quote Link to comment Share on other sites More sharing options...
NetwiseHosting Posted May 12, 2010 Share Posted May 12, 2010 Hi Snowman, I think your right. I have just checked and PHP-SNMP isn't installed/running on the server so I believe this to be where the problem lies. I will let you know how I get on. Kind regards, Matthew 0 Quote Link to comment Share on other sites More sharing options...
NetwiseHosting Posted August 13, 2010 Share Posted August 13, 2010 Hi Snowman, Just a quick update to thank you for your code, I have finally got around to integrating the system properly with PHP-SNMP etc and its all working great. One quick question if you don't mind, did you ever get the Current Status code working within your system? The only other mod I was thinking of integrating would be both a popup on button submission to tell the user that their server is now being restarted and to be patient and also to make the buttons inactive for 10 minutes or so. Any thoughts on this? Thanks in advance and have a good weekend. Matthew 0 Quote Link to comment Share on other sites More sharing options...
othellotech Posted August 13, 2010 Share Posted August 13, 2010 One quick question if you don't mind, did you ever get the Current Status code working within your system? The only other mod I was thinking of integrating would be both a popup on button submission to tell the user that their server is now being restarted and to be patient and also to make the buttons inactive for 10 minutes or so. Any thoughts on this? It's absolutely essential or they just keep clicking "reboot" over and over until they frvckup the box/drives/etc We disable the buttons after use, until a time has passed, along with showing "recent" apc activity to them 0 Quote Link to comment Share on other sites More sharing options...
wsa Posted August 16, 2010 Share Posted August 16, 2010 What error is give you 0 Quote Link to comment Share on other sites More sharing options...
bacterie Posted October 18, 2010 Share Posted October 18, 2010 Hello everyone, I am trying to integrate the reboot functionality, but i keep getting another page, without styling, with the same buttons on it. I press the button but nothing happens. When i run a tcpdump on the host, it doesn't capture any packets destined for the PDU. My PDU is an AP7911, the MIB string works from console. I saw that Matthew had a similar problem, Mattew how did you managed to solve it? Thank you. 0 Quote Link to comment Share on other sites More sharing options...
NetwiseHosting Posted October 18, 2010 Share Posted October 18, 2010 Hello everyone, I am trying to integrate the reboot functionality, but i keep getting another page, without styling, with the same buttons on it. I press the button but nothing happens. When i run a tcpdump on the host, it doesn't capture any packets destined for the PDU. My PDU is an AP7911, the MIB string works from console. I saw that Matthew had a similar problem, Mattew how did you managed to solve it? Thank you. Hi Bacterie, It's a common issue and it usually means that PHP-SNMP is not installed/running on your web server. We recompiled PHP to include the SNMP module and it worked great. I hope this helps. Kind regards, Matthew 0 Quote Link to comment Share on other sites More sharing options...
bacterie Posted October 18, 2010 Share Posted October 18, 2010 Hi Bacterie, It's a common issue and it usually means that PHP-SNMP is not installed/running on your web server. We recompiled PHP to include the SNMP module and it worked great. I hope this helps. Kind regards, Matthew Thank You very much Matthew, It seems that in Debian, although the php5-snmp package was installed, it is not enabled by default. I had to create the config by hand for it. This seems to be a bug in Debian. The reboot works as it's supposed to do. Did anyone managed to implement a wait code that disables the button for a while? Thanks. 0 Quote Link to comment Share on other sites More sharing options...
laszlof Posted October 18, 2010 Share Posted October 18, 2010 It shouldn't be too difficult to do with jquery. Just submit the form using a .ajax() call, and set the disabled attribute on the button for X amount of time. 0 Quote Link to comment Share on other sites More sharing options...
thebyp Posted October 21, 2010 Share Posted October 21, 2010 It's absolutely essential or they just keep clicking "reboot" over and over until they frvckup the box/drives/etc We disable the buttons after use, until a time has passed, along with showing "recent" apc activity to them Did you get this working? If so would you be able to share the code for this part? 0 Quote Link to comment Share on other sites More sharing options...
cyberneticos Posted October 22, 2010 Share Posted October 22, 2010 Hi, We're building our own small DC, and I think this module would be cool to have. Is it working in production for anyone? Thanks 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.