PHP Classes

Apc Switch: Manage an APC Rack PDU over ssh

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 83 All time: 10,060 This week: 455Up
Version License PHP version Categories
apcswitch 1.0MIT/X Consortium ...5.5PHP 5, Systems administration, Hardware
Description 

Author

This class can Manage an APC Rack PDU over ssh.

It can connect to a APC switch via SSH to retrieve information about the status.

It can also perform performs power on, power off and reboot operations for the connected equipment.

Innovation Award
PHP Programming Innovation award nominee
November 2017
Number 6
APC Rack PDU is a device that can monitor the electric consumption of devices that are connected to it.

This class connect to a Rack PDU device via SSH to retrieve information about the status of the device and other types of consumption information.

Manuel Lemos
Picture of Igor Dyshlenko
  Performance   Level  
Name: Igor Dyshlenko is available for providing paid consulting. Contact Igor Dyshlenko .
Classes: 3 packages by
Country: Ukraine Ukraine
Age: 53
All time rank: 384665 in Ukraine Ukraine
Week rank: 178 Up4 in Ukraine Ukraine Up
Innovation award
Innovation award
Nominee: 1x

Example

<?php
/**
 * Example of use ApcSwitch class.
 *
 * @author Igor Dyshlenko
 * @category Console
 * @see example.html
 * @license https://opensource.org/licenses/MIT MIT
 */

?>
<!DOCTYPE html>
<html>
    <head>
        <title>Example of use ApcSwitch class</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
    </head>
    <body>
        <pre>
<?php

$start
= time();

ini_set('request_order', 'CGP');

// Report all PHP errors
error_reporting(-1);
ini_set('error_reporting', E_ALL);

require_once
'LogWrapper.php';
require_once
'ShellConnector.php';
require_once
'Ssh2Connector.php';
require_once
'Shell.php';
require_once
'ApcSwitch.php';

// Logger initialization
require_once 'Log.php';
$logger = Log::singleton('console');
$logger->setMask(PEAR_LOG_ALL);

const
LANE_IP = 'xxx.xxx.xxx.xxx';
const
OUTLET_ID = 'Server 1-A';

const
   
LOGIN = 'username',
   
PASSWORD = 'password';

$logger->info('Run main code.');

$apc = new ApcSwitch(LANE_IP, LOGIN, PASSWORD, $logger);

$s = $apc->getInfo();
echo
"\nMain info = ";
var_dump($s);

$b = $apc->getBanksInfo();
echo
"\nBanks info = ";
var_dump($b);

echo
"\nOutlets list = ";
$ol = $apc->getIds();
var_dump($ol);

echo
"\nOutlet info = ";
$o = $apc->getOutletInfo(OUTLET_ID);
var_dump($o);

echo
"\nTurn ON Outlet.\n";
$apc->turnOn(OUTLET_ID);
echo
"\nOutlet info = ";
$oOn = $apc->getOutletInfo(OUTLET_ID);
var_dump($oOn);

sleep(3);

echo
"\nTurn OFF Outlet.\n";
$apc->turn(OUTLET_ID, 'Off');
echo
"\nOutlet info = ";
$oOff = $apc->getOutletInfo(OUTLET_ID);
var_dump($oOff);

$apc->disconnect();

echo
"\n\nScript finished. Runing time = ", time() - $start, ' seconds.';

?>

        </pre>
    </body>
</html>


  Files folder image Files (7)  
File Role Description
Accessible without login Plain text file ApcSwitch.php Class ApcSwitch class
Accessible without login HTML file example.html Output The result of executing the script example.php
Accessible without login Plain text file example.php Example Example of use
Accessible without login Plain text file LogWrapper.php Class Logger wrapper
Accessible without login Plain text file Shell.php Class Shell class
Accessible without login Plain text file ShellConnector.php Class Connector Interface
Accessible without login Plain text file Ssh2Connector.php Class Ssh2Connector class

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 0%
Total:83
This week:0
All time:10,060
This week:455Up