Skip to content

Commit

Permalink
Working on opendcim#592
Browse files Browse the repository at this point in the history
Needs testing - not sure if I've got all cases accounted for or not.
  • Loading branch information
samilliken committed May 20, 2015
1 parent 108563c commit 63eb347
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 27 deletions.
33 changes: 12 additions & 21 deletions assets.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,6 @@ static function getMetrics( $CabinetID ) {
$m->MeasuredPower = $row["Power"];
}

error_log( print_r( $m, true ));
return $m;
}
}
Expand Down Expand Up @@ -1585,18 +1584,14 @@ function CopyDeviceCustomValues($new) {
} else { return false; }
}

static function IncrementFailures($dev=null) {
static function IncrementFailures($dev) {
global $dbh;
if ( $dev == null && $this->DeviceID == null ) {

if ( $dev == null || $dev == 0 ) {
error_log("Device::IncrementFailures - no device ID supplied");
return false;
}

if ( !(isset($this) && get_class($this) == __CLASS__) ) {
$dev = ( $dev == null ) ? $this->DeviceID : $dev;
}

$sql = "update fac_Device set SNMPFailureCount=SNMPFailureCount+1 where DeviceID=$dev";

if ( ! $dbh->query( $sql ) ) {
Expand All @@ -1607,18 +1602,14 @@ static function IncrementFailures($dev=null) {
}
}

static function ResetFailures($dev=null) {
static function ResetFailures($dev) {
global $dbh;

if ( $dev == null && $this->DeviceID == null ) {
if ( $dev == null || $dev == 0 ) {
error_log("Device::ResetFailures - no device ID supplied");
return false;
}

if ( !(isset($this) && get_class($this) == __CLASS__) ) {
$dev = ( $dev == null ) ? $this->DeviceID : $dev;
}

$sql = "update fac_Device set SNMPFailureCount=0 where DeviceID=$dev";

if ( ! $dbh->query( $sql ) ) {
Expand Down Expand Up @@ -3201,10 +3192,10 @@ static function UpdateSensors( $CabinetID = null ) {
if ( $sen->TemperatureOID ) {
if ( $ret = self::OSS_SNMP_Lookup($d, null, "$sen->TemperatureOID") ) {
$temp = floatval( $ret );
$d->ResetFailures();
$d->ResetFailures( $d->DeviceID );
} else {
$temp = 0;
$d->IncrementFailures();
$d->IncrementFailures( $d->DeviceID );
}
} else {
$temp = 0;
Expand All @@ -3213,10 +3204,10 @@ static function UpdateSensors( $CabinetID = null ) {
if ( $sen->HumidityOID ) {
if ( $ret = self::OSS_SNMP_Lookup($d, null, "$sen->HumidityOID") ) {
$humidity = floatval( $ret );
$d->ResetFailures();
$d->ResetFailures( $d->DeviceID );
} else {
$humidity = 0;
$d->IncrementFailures();
$d->IncrementFailures( $d->DeviceID );
}
} else {
$humidity = 0;
Expand All @@ -3241,7 +3232,7 @@ static function UpdateSensors( $CabinetID = null ) {
}

// No need for any further sanitization it was all handled above
$insertsql="INSERT INTO fac_SensorReadings SET DeviceID=$d->DeviceID, Temperature=$temp, Humidity=$humidity, Timestamp=NOW() on duplicate key update Temperature=$temp, Humidity=$humidity, Timestamp=now()";
$insertsql="INSERT INTO fac_SensorReadings SET DeviceID=$d->DeviceID, Temperature=$temp, Humidity=$humidity, LastRead=NOW() on duplicate key update Temperature=$temp, Humidity=$humidity, LastRead=now()";
if(!$dbh->exec($insertsql)){
$info = $dbh->errorInfo();

Expand Down Expand Up @@ -3914,9 +3905,9 @@ static function EnumerateVMs($dev,$debug=false){
$vmList[$vmID]->vmName = trim( str_replace( '"', '', @end( explode( ":", $name ) ) ) );
$vmList[$vmID]->vmState = trim( str_replace( '"', '', @end( explode( ":", $state ) ) ) );
}
$dev->ResetFailures();
$dev->ResetFailures( $dev->DeviceID );
} else {
$dev->IncrementFailures();
$dev->IncrementFailures( $dev->DeviceID );
}

return $vmList;
Expand Down
14 changes: 8 additions & 6 deletions power.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -1106,12 +1106,14 @@ function UpdateStats(){
error_log("PowerDistribution::UpdateStats::PDO Error: {$info[2]} SQL=$sql");
}

$this->PDUID=$row["PDUID"];
$sql="UPDATE fac_PowerDistribution SET FirmwareVersion=\"".
$this->GetSmartCDUVersion()."\" WHERE PDUID=$this->PDUID;";
if(!$dbh->exec($sql)){
$info=$dbh->errorInfo();
error_log("PowerDistribution::UpdateStats::PDO Error: {$info[2]} SQL=$sql");
$this->PDUID=$row["PDUID"];
$ver = $this->GetSmartCDUVersion();
if ( $ver != false && $ver != "" ) {
$sql="UPDATE fac_PowerDistribution SET FirmwareVersion=\"$ver\" WHERE PDUID=$this->PDUID;";
if(!$dbh->exec($sql)){
$info=$dbh->errorInfo();
error_log("PowerDistribution::UpdateStats::PDO Error: {$info[2]} SQL=$sql");
}
}
}
}
Expand Down

0 comments on commit 63eb347

Please sign in to comment.