PDA

Bekijk Volledige Versie : Gezocht: SNMP reboot IpoMan 1201



Anoniem
22/12/09, 15:26
Langzaam maar zeker is het de bedoeling om over te gaan op de IpoMan remote reboot oplossingen. Op dit moment draait het op apparatuur van APC, maar deze gaat dus vervangen worden.

Dit zal ook betekenen dat we ons CP aan moeten gaan passen - en voor een klein deel wil ik hier graag iemand voor inhuren. Het gaat mij puur om de aanpassing zodat we in plaats van de onderstaande code een variant kunnen gebruiken die aansluit bij de IpoMan.

Omdat voor niets de zon op gaat is het geen probleem om hier voor te betalen; zolang de geboden oplossing werkt. Graag wil ik ook terug kunnen vallen op hetzelfde bedrijf/persoon bij het configureren van MRTG. Er zijn wat twijfels over de gevonden voorbeelden namelijk.

De code die wij nu gebruiken is simpel:


$reboot = snmpset($ip, $snmp, $mib, i, 3);

Piwi-Web
23/12/09, 00:16
Ipoclass is gewoon op het I-net te vinden.
Zie hieronder de code:


<?php

require_once "HttpClient.class.php";

/**
* This class switches the Ingrasys IpoMan 1200 outlets from PHP.
*
* The HttpClient class from Incutio is required:
* http://scripts.incutio.com/httpclient/
*
* Be aware that we use plain HTTP, so the communication is not
* encrypted. For security reasons you should not use this class
* through a public access network.
*
* @version 1.1 (May 8, 2008)
* @author Stefan Mensink <opensource@basemotive.nl>
* @copyright Basemotive V.O.F.
*/
class IpoMan {
private $ipaddress = null;
private $username = null;
private $password = null;
private $immediateswitching = null;
private $client = null;

/**
* Constructs the IpoMan class
*
* @param string $ipaddress The IP-address (or hostname) for the IpoMan
* @param string $username The username to authenticate with
* @param string $password The username to authenticate with
* @param boolean $immediateswitching Whether or not we want to temporary set the on/off delays to 0 when switching an outlet
*/
public function __construct($ipaddress, $username, $password, $immediateswitching=false) {
$this->ipaddress = $ipaddress;
$this->username = $username;
$this->password = $password;
$this->immediateswitching = $immediateswitching;

$this->client = new HttpClient($ipaddress);
$this->client->setAuthorization($username, $password);
}

/**
* Turns an outlet off and on.
*
* @param integer $outlet The outlet number to switch, 0 is the first outlet, 11 is the last
* @param integer $delay The delay between switching off and on in seconds
*/
public function resetOutlet($outlet, $delay=1) {
// Set outlet on/off delays to 0
if ($this->immediateswitching) {
$outletSettings = $this->getOutletSettings();

if ($outlet < 2) $outletonid = "XAAAAAAABADL".chr(ord('A')+$outlet+14);
else $outletonid = "XAAAAAAABADM".chr(ord('A')+$outlet-2);
$outletoffid = "XAAAAAAABADL".chr(ord('A')+$outlet+2);

if ($outletSettings[$outletonid]!="0" || $outletSettings[$outletoffid]!="0") {
$tmpOutletSettings = $outletSettings;
$tmpOutletSettings[$outletonid] = "0";
$tmpOutletSettings[$outletoffid] = "0";
$this->setOutletSettings($tmpOutletSettings);
var_dump($tmpOutletSettings);

$needRestoreOutletSettings = true;
} else {
$needRestoreOutletSettings = false;
}
}

// Turn outlet off
$callarray = array();
for ($i=0; $i<12; $i++) {
$outletid = "XAAAAAAABOEB".chr(ord('A')+$i);
$callarray[$outletid] = ($outlet==$i ? "3" : "1");
}
$this->client->post('/PageControl.htm', $callarray);

sleep($delay);

// Turn outlet on
$callarray = array();
for ($i=0; $i<12; $i++) {
$outletid = "XAAAAAAABOEB".chr(ord('A')+$i);
$callarray[$outletid] = ($outlet==$i ? "2" : "1");
}
$this->client->post('/PageControl.htm', $callarray);

// Restore default outlet settings
if ($this->immediateswitching && $needRestoreOutletSettings) {
$this->setOutletSettings($outletSettings);
}
}

/**
* Turns an outlet on.
*
* @param integer $outlet The outlet number to switch, 0 is the first outlet, 11 is the last
*/
public function switchOn($outlet) {
// Make sure we have something to do
if ($this->getOutletStatus($outlet)=="1") return;

// Set outlet on delay to 0
if ($this->immediateswitching) {
$outletSettings = $this->getOutletSettings();

if ($outlet < 2) $outletonid = "XAAAAAAABADL".chr(ord('A')+$outlet+14);
else $outletonid = "XAAAAAAABADM".chr(ord('A')+$outlet-2);

if ($outletSettings[$outletonid]!="0") {
$tmpOutletSettings = $outletSettings;
$tmpOutletSettings[$outletonid] = "0";
$this->setOutletSettings($tmpOutletSettings);
$needRestoreOutletSettings = true;
} else {
$needRestoreOutletSettings = false;
}
}

// Turn outlet on
$callarray = array();
for ($i=0; $i<12; $i++) {
$outletid = "XAAAAAAABOEB".chr(ord('A')+$i);
$callarray[$outletid] = ($outlet==$i ? "2" : "1");
}


$this->client->post('/PageControl.htm', $callarray);

// Restore default outlet settings
if ($this->immediateswitching && $needRestoreOutletSettings) {
$this->setOutletSettings($outletSettings);
}
}

/**
* Turns an outlet off.
*
* @param integer $outlet The outlet number to switch, 0 is the first outlet, 11 is the last
*/
public function switchOff($outlet) {
// Make sure we have something to do
if ($this->getOutletStatus($outlet)=="0") return;

// Set outlet off delay to 0
if ($this->immediateswitching) {
$outletSettings = $this->getOutletSettings();

$outletoffid = "XAAAAAAABADL".chr(ord('A')+$outlet+2);

if ($outletSettings[$outletoffid]!="0") {
$tmpOutletSettings = $outletSettings;
$tmpOutletSettings[$outletoffid] = "0";
$this->setOutletSettings($tmpOutletSettings);
$needRestoreOutletSettings = true;
} else {
$needRestoreOutletSettings = false;
}
}

// Turn outlet off
$callarray = array();
for ($i=0; $i<12; $i++) {
$outletid = "XAAAAAAABOEB".chr(ord('A')+$i);
$callarray[$outletid] = ($outlet==$i ? "3" : "1");
}
$this->client->post('/PageControl.htm', $callarray);

// Restore default outlet settings
if ($this->immediateswitching && $needRestoreOutletSettings) {
$this->setOutletSettings($outletSettings);
}
}

/**
* Retrieves the outlet status.
*
* @param integer $outlet The outlet number to retrieve the status for; if ommitted, all outlet statuses are returned
* @return array All outlet statuses, or an integer if a specific outlet was specified
*/
public function getOutletStatus($outlet='') {
$result = array();

$this->client->get("/Outlet.js");
$content = $this->client->getContent();
$content_split = explode("\n", $content);
foreach ($content_split as $line) {
if (strpos($line, "var Power_status") !== false) {
$pos1 = strpos($line, '(');
$pos2 = strpos($line, ')');
$arraypart = substr($line, $pos1+1, $pos2-$pos1-1);
$outletstatusarray = explode(',', $arraypart);
foreach ($outletstatusarray as $status) {
$result[] = ($status=='"power on"'?1:0);
}
}
}

if ($outlet!='')
return $result[$outlet];
else
return $result;
}

/**
* Retrieves the value for a form element from the PageControl html.
*/
private function getContentValue($content, $id) {
$pos = strpos($content, $id);
$pos2 = strpos($content, 'VALUE="', $pos)+7;
$pos3 = strpos($content, '"', $pos2);
$value = substr($content, $pos2, $pos3-$pos2);
return $value;
}

/**
* Retrieves all the outlet settings from the IpoMan as an array, so we can post it
* again.
*/
private function getOutletSettings() {
$result = $this->client->get("/PageControl.htm");
$content = $this->client->getContent();

$outletSettings = array();

for ($i=0; $i<12; $i++) {
// Outlet Name
$outletid = "XAAAAAAABADJ".chr(ord('A')+$i+1);
$outletSettings[$outletid] = $this->getContentValue($content, $outletid);
// Outlet Location
$outletid = "XAAAAAAABADK".chr(ord('A')+$i+1);
$outletSettings[$outletid] = $this->getContentValue($content, $outletid);
// Power on Delay (secs)
if ($i < 2) $outletid = "XAAAAAAABADL".chr(ord('A')+$i+14);
else $outletid = "XAAAAAAABADM".chr(ord('A')+$i-2);
$outletSettings[$outletid] = $this->getContentValue($content, $outletid);
// Power off Delay (secs)
$outletid = "XAAAAAAABADL".chr(ord('A')+$i+2);
$outletSettings[$outletid] = $this->getContentValue($content, $outletid);
// Output current threshold
$outletid = "XAAAAAAABADG".chr(ord('A')+$i+1);
$outletSettings[$outletid] = $this->getContentValue($content, $outletid);
}

return $outletSettings;
}

/**
* Sets all the outlet settings to the values given in the array.
*/
private function setOutletSettings($outletSettings) {
$this->client->post('/PageControl.htm', $outletSettings);
}

public function dump() {
//$result = $this->client->get("/PagePDUStatus.htm");
$result = $this->client->get("/OutletTableStatus.js");
$content = $this->client->getContent();
echo $content."\n\n";
}

}

?>

Je hebt er ook de httpclient voor nodig. Die is te vinden door even simpel te googlen :)

Poort aanzetten:

$object = new IpoMan($row['IP'],"admin","wachtwoord");
$object->switchOn($ipo_out);

Poort uitzetten:

$object = new IpoMan($row['IP'],"admin","wachtwoord");
$object->switchOff($ipo_out);

Poort resetten:

$object = new IpoMan($row['IP'],"admin","wachtwoord");
$object->resetOutlet($ipo_out);

Ik hoop dat je hier iets aan hebt ;)
Gewoon de class includen en dan spelen maar!

EDIT: Ik bied mij trouwens ook aan als ik het voor je moet inbouwen :) (zie nu pas dat dit in aanbiedingen gezocht staat!)

Anoniem
23/12/09, 08:30
Het inbouwen van die class moet wel lukken, alleen had ik gehoopt dat we dit via SNMP konden doen. Via HTTP is nogal 'dirty' als je het mij vraagt. Maar dat is niet mogelijk blijkbaar? Anders hou ik mij nog steeds aanbevolen. Mocht dat niet kunnen is het geen probleem om dit in te bouwen. Overigens zal dit puur een code snippet worden, de benodigde variabelen en velden worden gewoon door ons aangeleverd. Inbouwen zullen wij daarna zelf oppakken.

Dan blijft MRTG over. MRTG is overigens noodzakelijk in verband met onze SQL monitoring. Tenzij iemand beschikt over een tool die het apparaat kan uitlezen en het KWh verbruik naar SQL kan sturen.

PreServer
23/12/09, 14:10
Beste GetUp,

Wij hebben net een ipoman snmp class ontwikkeld voor ons nieuwe control panel.
De class is lekker simpel en heeft geen andere dependencies dan php-snmp

Het gebruik is als simpel als:

<?php

require_once 'ipoman.php';

$ipoman = new ipoman($hostname, $snmp_write_community);
$ipoman->on($port);

?>

de volgende functies zijn beschikbaar in de class:

isOn($port)
isOff($port)

on($port, $sync = true)
off($port, $sync = true)
cycle($port, $wait = 5000, $sync = true)

status()

De prijs van deze class is 95 euro ex btw voor een geencode versie en 195 euro voor de source

Mrtg/cacti configuren is ook geen probleem, deze is bij ons ook uitgebreider dan de voorbeelden die op internet te vinden zijn

Voor meer informatie of vragen kunt u mij een pm sturen,

Met vriendelijke groet,

Wijtec

PreServer
23/12/09, 16:18
Op verzoek is de prijs verlaagd naar 145 euro en de class uitgebreid met de volgende functies:

power ($port)
current ($port)
ckwh ($port)
volt ()

Mvg,

Wijtec