Beispiel #1
0
        $tmp['DataCenterName'] = $dc->Name;
        array_push($response['cabinet'], $tmp);
        echoResponse(200, $response);
    }
});
//
//	URL:	/api/v1/cabinet/bydc/:datacenterid
//	Method:	GET
//	Params: datacenterid (passed in URL)
//	Returns: All cabinet information within the given data center, if any
//
$app->get('/cabinet/bydc/:datacenterid', function ($datacenterid) {
    $cab = new Cabinet();
    $dc = new DataCenter();
    $cab->DataCenterID = intval($datacenterid);
    $cList = $cab->ListCabinetsByDC();
    $response['error'] = false;
    $response['errorcode'] = 200;
    $response['cabinet'] = array();
    foreach ($cList as $c) {
        $tmp = array();
        foreach ($c as $prop => $value) {
            $tmp[$prop] = $value;
        }
        if ($dc->DataCenterID != $c->DataCenterID) {
            $dc->DataCenterID = $c->DataCenterID;
            $dc->GetDataCenter();
        }
        $tmp['DataCenterName'] = $dc->Name;
        array_push($response['cabinet'], $tmp);
    }
Beispiel #2
0
        $dcpicklist .= "<option value={$d->DataCenterID}>{$d->Name}</option>";
    }
    $dcpicklist .= '</select>';
    return $dcpicklist;
}
// AJAX - Start
function displayjson($array)
{
    header('Content-Type: application/json');
    echo json_encode($array);
    exit;
}
if (isset($_POST['dc'])) {
    $cab = new Cabinet();
    $cab->DataCenterID = $_POST['dc'];
    displayjson($cab->ListCabinetsByDC());
}
if (isset($_POST['cab'])) {
    $dev = new Device();
    $dev->Cabinet = $_POST['cab'];
    // Filter devices by rights
    $devs = array();
    foreach ($dev->ViewDevicesByCabinet(true) as $d) {
        if ($d->Rights == "Write") {
            $devs[] = $d;
        }
    }
    displayjson($devs);
}
if (isset($_POST['dev'])) {
    $dp = new DevicePorts();
Beispiel #3
0
            }
        } else {
            //update cabinet
            $cab->FrontEdge = $_POST["airflow"];
            $cab->UpdateCabinet();
        }
    }
    exit;
}
if (isset($_POST['dc']) && (isset($_POST['getobjects']) || isset($_POST['getoverview']))) {
    $payload = array();
    if (isset($_POST['getobjects'])) {
        $cab->DataCenterID = $_POST['dc'];
        $zone = new Zone();
        $zone->DataCenterID = $cab->DataCenterID;
        $payload = array('cab' => $cab->ListCabinetsByDC(true), 'zone' => $zone->GetZonesByDC(true));
    } else {
        $dc->DataCenterID = $_POST['dc'];
        $dc->GetDataCenterByID();
        $payload = $dc->GetOverview();
    }
    header('Content-Type: application/json');
    echo json_encode($payload);
    exit;
}
if (!isset($_GET["dc"])) {
    // No soup for you.
    header('Location: ' . redirect());
    exit;
}
$dc->DataCenterID = $_GET["dc"];
Beispiel #4
0
             $devList[$dev->DeviceType][$dev->DeviceID] = array();
         }
     }
 } elseif (isset($_REQUEST['zoneid'])) {
     $zoneid = isset($_POST['zoneid']) ? $_POST['zoneid'] : $_GET['zoneid'];
     $zone = new Zone();
     $zone->ZoneID = $zoneid;
     $zone->GetZone();
     $datacenter = new DataCenter();
     $datacenter->DataCenterID = $zone->DataCenterID;
     $datacenter->GetDataCenter();
     $graphname .= "Zone " . $zone->Description . " in Data Center " . $datacenter->Name;
     $cabinet = new Cabinet();
     $cabinet->DataCenterID = $zone->DataCenterID;
     $cabinet->ZoneID = $zone->ZoneID;
     foreach ($cabinet->ListCabinetsByDC(true, true) as $cab) {
         $device = new Device();
         $device->Cabinet = $cab->CabinetID;
         foreach ($device->ViewDevicesByCabinet(true) as $dev) {
             if (!isset($devList[$dev->DeviceType])) {
                 $devList[$dev->DeviceType] = array();
             }
             $devList[$dev->DeviceType][$dev->DeviceID] = array();
         }
     }
 } elseif (isset($_REQUEST['cabrowid'])) {
     $cabrowid = isset($_POST['cabrowid']) ? $_POST['cabrowid'] : $_GET['cabrowid'];
     $cabrow = new CabRow();
     $cabrow->CabRowID = $cabrowid;
     $cabrow->GetCabRow();
     $cabinet = new Cabinet();
/**
 * Compute the full inventory on devices in the data centers and return the data
 *   center summary statistics
 *
 * @param PHPExcel_Worksheet $worksheet
 * @param array $DProps properties defined for the Excel document
 * @return (array|array|array|boolean)[]
 *      statistics array, device inventory, cabinet inventory
 */
function computeSheetBodyDCInventory($DProps)
{
    global $person;
    global $sessID;
    $dc = new DataCenter();
    $cab = new Cabinet();
    $device = new Device();
    $invData = array();
    $invCab = array();
    $sheetColumns = $DProps['DC Inventory']['Columns'];
    $cabinetColumns = $DProps['Rack Inventory']['Columns'];
    $devTemplates = DeviceTemplate::getTemplateListIndexedbyID();
    $deptList = Department::GetDepartmentListIndexedbyID();
    $contactList = $person->GetUserList('indexed');
    $limitedUser = false;
    $dcList = $dc->GetDCList();
    $Stats = array();
    // A little code to update the counter
    $percentDone = 0;
    $sectionMaxPercent = 40;
    $incrementalPercent = 1 / sizeof($dcList) * $sectionMaxPercent;
    foreach ($dcList as $dc) {
        $dcContainerList = $dc->getContainerList();
        $dcStats = array();
        $cab->DataCenterID = $dc->DataCenterID;
        $dcStats['Fl_Spc'] = $dc->SquareFootage;
        $dcStats['DesignPower'] = $dc->MaxkW;
        $dcStats['Watts'] = 0;
        $dcStats['Rk_Num'] = 0;
        $dcStats['Rk_UtT'] = 0;
        $dcStats['Rk_UtU'] = 0;
        $dcStats['Rk_UtE'] = 0;
        $dcStats['Rk_Res'] = 0;
        $cabList = $cab->ListCabinetsByDC();
        if (count($cabList) == 0) {
            // empty data center room
            $devSpec = makeEmptySpec($sheetColumns, $dcContainerList);
            $devSpec['DC Name'] = $dc->Name;
            $invData[] = $devSpec;
        } else {
            foreach ($cabList as $cab) {
                if (!$person->ReadAccess and $cab->AssignedTo == 0 or $cab->AssignedTo > 0 and !$person->canRead($cab->AssignedTo)) {
                    // User is not allowed to see anything in here
                    $limitedUser = true;
                    continue;
                }
                $zoneName = getZoneName($cab);
                $rowName = getRowName($cab);
                addRackStat($invCab, $cab, $cabinetColumns, $dc, $dcContainerList);
                $cab_height = $cab->CabinetHeight;
                if (mb_strtoupper($cab->Model) == 'RESERVED') {
                    $dcStats['Rk_Res']++;
                } else {
                    $dcStats['Rk_Num']++;
                }
                $dcStats['Rk_UtT'] += $cab_height;
                $device->Cabinet = $cab->CabinetID;
                $device_list = $device->ViewDevicesByCabinet();
                // empty cabinet
                if (count($device_list) == 0 && $cab->CabinetHeight > 0) {
                    $dcStats['Rk_UtE'] += $cab_height;
                    $devSpec = makeEmptySpec($sheetColumns, $dcContainerList);
                    $devSpec['Zone'] = $zoneName;
                    $devSpec['Row'] = $rowName;
                    $devSpec['DC Name'] = $dc->Name;
                    $devSpec['Cabinet'] = $cab->Location;
                    $devSpec['Position'] = 1;
                    $devSpec['Height'] = $cab->CabinetHeight;
                    $devSpec['Device'] = '__EMPTY';
                    $invData[] = $devSpec;
                } else {
                    usort($device_list, 'cmpDevPos');
                    $low_idx = 1;
                    foreach ($device_list as $dev) {
                        if ($low_idx < $dev->Position) {
                            // range of empty slots
                            if ($dev->Position <= $cab_height) {
                                $height = $dev->Position - $low_idx;
                            } else {
                                $height = $cab_height - $low_idx + 1;
                            }
                            if ($height > 0) {
                                $dcStats['Rk_UtE'] += $height;
                                $devSpec = makeEmptySpec($sheetColumns, $dcContainerList);
                                ${$devSpec}['Zone'] = $zoneName;
                                $devSpec['Row'] = $rowName;
                                $devSpec['DC Name'] = $dc->Name;
                                $devSpec['Cabinet'] = $cab->Location;
                                $devSpec['Position'] = $low_idx;
                                $devSpec['Height'] = $height;
                                $devSpec['Device'] = '__EMPTY';
                                $invData[] = $devSpec;
                            }
                            $low_idx = $dev->Position;
                        }
                        // device in cabinet
                        $reserved = $dev->Reservation ? 'reserved' : null;
                        list($manufacturer, $model) = getDeviceTemplateName($devTemplates, $dev);
                        $devSpec = makeEmptySpec($sheetColumns, $dcContainerList);
                        $devSpec['DevID'] = $dev->DeviceID;
                        $devSpec['Zone'] = $zoneName;
                        $devSpec['Row'] = $rowName;
                        $devSpec['DC Name'] = $dc->Name;
                        $devSpec['Cabinet'] = $cab->Location;
                        $devSpec['Position'] = $dev->Position;
                        $devSpec['Half Depth'] = getDeviceDepthPos($dev);
                        $devSpec['Height'] = $dev->Height;
                        $devSpec['Device'] = $dev->Label;
                        $devSpec['Parent Device'] = null;
                        $devSpec['Manufacturer'] = $manufacturer;
                        $devSpec['Model'] = $model;
                        $devSpec['Device Type'] = $dev->DeviceType;
                        $devSpec['Asset Number'] = $dev->AssetTag;
                        $devSpec['Serial No.'] = $dev->SerialNo;
                        $devSpec['Install Date'] = $dev->InstallDate;
                        $devSpec['Warranty End'] = $dev->WarrantyExpire;
                        $devSpec['Owner'] = getOwnerName($dev, $deptList);
                        $devSpec['Power (W)'] = $dev->NominalWatts;
                        $devSpec['Reservation'] = $reserved;
                        $devSpec['Contact'] = getContactName($contactList, $dev->PrimaryContact);
                        $devSpec['Tags'] = getTagsString($dev);
                        $devSpec['Notes'] = html_entity_decode(strip_tags($dev->Notes), ENT_COMPAT, 'UTF-8');
                        $invData[] = $devSpec;
                        $dcStats['Watts'] += $dev->NominalWatts;
                        // devices can be installed at the same position and
                        // could be of different height; count only the free
                        // rack units which are not covered by any device
                        if ($low_idx == $dev->Position) {
                            $low_idx += $dev->Height;
                            $dcStats['Rk_UtU'] += $dev->Height;
                        } else {
                            $rest_height = $dev->Position + $dev->Height - $low_idx;
                            $rest_height = $rest_height > 0 ? $rest_height : 0;
                            $low_idx += $rest_height;
                            $dcStats['Rk_UtU'] += $rest_height;
                        }
                        if ($dev->DeviceType == 'Chassis') {
                            list($watts, $invData) = computeDeviceChildren($sheetColumns, $invData, $dev, $dc->Name, $cab, $devTemplates, $deptList, $contactList, $dcContainerList);
                            $dcStats['Watts'] += $watts;
                        }
                    }
                    if ($low_idx <= $cab->CabinetHeight) {
                        // empty range at the top of the cabinet, $low_idx is
                        // the potentially free location
                        $height = $cab->CabinetHeight - $low_idx + 1;
                        $dcStats['Rk_UtE'] += $height;
                        $devSpec = makeEmptySpec($sheetColumns, $dcContainerList);
                        $devSpec['Zone'] = $zoneName;
                        $devSpec['Row'] = $rowName;
                        $devSpec['DC Name'] = $dc->Name;
                        $devSpec['Cabinet'] = $cab->Location;
                        $devSpec['Position'] = $low_idx;
                        $devSpec['Height'] = $height;
                        $devSpec['Device'] = '__EMPTY';
                        $invData[] = $devSpec;
                    }
                }
            }
        }
        assignStatsVal($Stats, $dc, $dcStats);
        $percentDone += $incrementalPercent;
        JobQueue::updatePercentage($sessID, $percentDone);
    }
    return array($Stats, $invData, $invCab, $limitedUser);
}
Beispiel #6
0
 function GetOverview()
 {
     $this->MakeSafe();
     $statusarray = array();
     // check to see if map was set
     if (strlen($this->DrawingFileName)) {
         $mapfile = "drawings" . DIRECTORY_SEPARATOR . $this->DrawingFileName;
         $overview = array();
         $space = array();
         $weight = array();
         $power = array();
         $temperature = array();
         $humidity = array();
         $realpower = array();
         $colors = array();
         // map was set in config check to ensure a file exists before we attempt to use it
         if (file_exists($mapfile)) {
             $this->dcconfig = new Config();
             $dev = new Device();
             $templ = new DeviceTemplate();
             $cab = new Cabinet();
             // get all color codes and limits for use with loop below
             $CriticalColor = html2rgb($this->dcconfig->ParameterArray["CriticalColor"]);
             $CautionColor = html2rgb($this->dcconfig->ParameterArray["CautionColor"]);
             $GoodColor = html2rgb($this->dcconfig->ParameterArray["GoodColor"]);
             $SpaceRed = intval($this->dcconfig->ParameterArray["SpaceRed"]);
             $SpaceYellow = intval($this->dcconfig->ParameterArray["SpaceYellow"]);
             $WeightRed = intval($this->dcconfig->ParameterArray["WeightRed"]);
             $WeightYellow = intval($this->dcconfig->ParameterArray["WeightYellow"]);
             $PowerRed = intval($this->dcconfig->ParameterArray["PowerRed"]);
             $PowerYellow = intval($this->dcconfig->ParameterArray["PowerYellow"]);
             $unknown = html2rgb('FFFFFF');
             // Copy all colors into an array to export
             $color['unk'] = array('r' => $unknown[0], 'g' => $unknown[1], 'b' => $unknown[2]);
             $color['bad'] = array('r' => $CriticalColor[0], 'g' => $CriticalColor[1], 'b' => $CriticalColor[2]);
             $color['med'] = array('r' => $CautionColor[0], 'g' => $CautionColor[1], 'b' => $CautionColor[2]);
             $color['low'] = array('r' => $GoodColor[0], 'g' => $GoodColor[1], 'b' => $GoodColor[2]);
             $colors = $color;
             // Assign color variables
             $CriticalColor = 'bad';
             $CautionColor = 'med';
             $GoodColor = 'low';
             $unknownColor = 'unk';
             // Temperature
             $TemperatureYellow = intval($this->dcconfig->ParameterArray["TemperatureYellow"]);
             $TemperatureRed = intval($this->dcconfig->ParameterArray["TemperatureRed"]);
             // Humidity
             $HumidityMin = intval($this->dcconfig->ParameterArray["HumidityRedLow"]);
             $HumidityMedMin = intval($this->dcconfig->ParameterArray["HumidityYellowLow"]);
             $HumidityMedMax = intval($this->dcconfig->ParameterArray["HumidityYellowHigh"]);
             $HumidityMax = intval($this->dcconfig->ParameterArray["HumidityRedHigh"]);
             //Real Power
             $RealPowerRed = intval($this->dcconfig->ParameterArray["PowerRed"]);
             $RealPowerYellow = intval($this->dcconfig->ParameterArray["PowerYellow"]);
             // get image file attributes and type
             list($width, $height, $type, $attr) = getimagesize($mapfile);
             $cdus = array();
             $sql = "select c.CabinetID, P.RealPower, P.BreakerSize, P.InputAmperage*PP.PanelVoltage as VoltAmp from \n\t\t\t\t\t(fac_Cabinet c left join (select CabinetID, Wattage as RealPower, BreakerSize, InputAmperage, PanelID from fac_PowerDistribution PD \n\t\t\t\t\tleft join fac_PDUStats PS on PD.PDUID=PS.PDUID) P on c.CabinetID=P.CabinetID) \n\t\t\t\t\tleft join (select PanelVoltage, PanelID from fac_PowerPanel) PP on PP.PanelID=P.PanelID \n\t\t\t\t\twhere PanelVoltage is not null and RealPower is not null and c.DataCenterID=" . intval($this->DataCenterID);
             $rpvalues = $this->query($sql);
             foreach ($rpvalues as $cduRow) {
                 $cabid = $cduRow['CabinetID'];
                 $voltamp = $cduRow['VoltAmp'];
                 $rp = $cduRow['RealPower'];
                 $bs = $cduRow['BreakerSize'];
                 if ($bs == 1) {
                     $maxDraw = $voltamp / 1.732;
                 } elseif ($bs == 2) {
                     $maxDraw = $voltamp;
                 } else {
                     $maxDraw = $voltamp * 1.732;
                 }
                 // De-rate all breakers to 80% sustained load
                 $maxDraw *= 0.8;
                 // Only keep the highest percentage of any single CDU in a cabinet
                 if ($rp > 0) {
                     $pp = intval($rp / $maxDraw * 100);
                 } else {
                     $pp = 0;
                 }
                 $cdus[$cabid] = isset($cdus[$cabid]) && $cdus[$cabid] > $pp ? $cdus[$cabid] : $pp;
             }
             $cab->DataCenterID = $this->DataCenterID;
             $cabList = $cab->ListCabinetsByDC();
             $titletemp = 0;
             $titlerp = 0;
             // read all cabinets and calculate the color to display on the cabinet
             foreach ($cabList as $cabRow) {
                 if ($cabRow->MapX1 == $cabRow->MapX2 || $cabRow->MapY1 == $cabRow->MapY2) {
                     continue;
                 }
                 $currentHeight = $cabRow->CabinetHeight;
                 $metrics = CabinetMetrics::getMetrics($cabRow->CabinetID);
                 $currentTemperature = $metrics->IntakeTemperature;
                 $currentHumidity = $metrics->IntakeHumidity;
                 $currentRealPower = $metrics->MeasuredPower;
                 $used = $metrics->SpaceUsed;
                 // check to make sure the cabinet height is set to keep errors out of the logs
                 if (!isset($cabRow->CabinetHeight) || $cabRow->CabinetHeight == 0) {
                     $SpacePercent = 100;
                 } else {
                     $SpacePercent = number_format($metrics->SpaceUsed / $cabRow->CabinetHeight * 100, 0);
                 }
                 // check to make sure there is a weight limit set to keep errors out of logs
                 if (!isset($cabRow->MaxWeight) || $cabRow->MaxWeight == 0) {
                     $WeightPercent = 0;
                 } else {
                     $WeightPercent = number_format($metrics->CalculatedWeight / $cabRow->MaxWeight * 100, 0);
                 }
                 // check to make sure there is a kilowatt limit set to keep errors out of logs
                 if (!isset($cabRow->MaxKW) || $cabRow->MaxKW == 0) {
                     $PowerPercent = 0;
                 } else {
                     $PowerPercent = number_format($metrics->CalculatedPower / 1000 / $cabRow->MaxKW * 100, 0);
                 }
                 if (!isset($cabRow->MaxKW) || $cabRow->MaxKW == 0) {
                     $RealPowerPercent = 0;
                 } else {
                     $RealPowerPercent = number_format($metrics->MeasuredPower / 1000 / $cabRow->MaxKW * 100, 0, ",", ".");
                 }
                 // check for individual cdu's being weird
                 if (isset($cdus[$cab->CabinetID])) {
                     $RealPowerPercent = $RealPowerPercent > $cdus[$cab->CabinetID] ? $RealPowerPercent : $cdus[$cab->CabinetID];
                 }
                 //Decide which color to paint on the canvas depending on the thresholds
                 if ($SpacePercent > $SpaceRed) {
                     $scolor = $CriticalColor;
                 } elseif ($SpacePercent > $SpaceYellow) {
                     $scolor = $CautionColor;
                 } else {
                     $scolor = $GoodColor;
                 }
                 if ($WeightPercent > $WeightRed) {
                     $wcolor = $CriticalColor;
                 } elseif ($WeightPercent > $WeightYellow) {
                     $wcolor = $CautionColor;
                 } else {
                     $wcolor = $GoodColor;
                 }
                 if ($PowerPercent > $PowerRed) {
                     $pcolor = $CriticalColor;
                 } elseif ($PowerPercent > $PowerYellow) {
                     $pcolor = $CautionColor;
                 } else {
                     $pcolor = $GoodColor;
                 }
                 if ($RealPowerPercent > $RealPowerRed) {
                     $rpcolor = $CriticalColor;
                 } elseif ($RealPowerPercent > $RealPowerYellow) {
                     $rpcolor = $CautionColor;
                 } else {
                     $rpcolor = $GoodColor;
                 }
                 if ($currentTemperature == 0) {
                     $tcolor = $unknownColor;
                 } elseif ($currentTemperature > $TemperatureRed) {
                     $tcolor = $CriticalColor;
                 } elseif ($currentTemperature > $TemperatureYellow) {
                     $tcolor = $CautionColor;
                 } else {
                     $tcolor = $GoodColor;
                 }
                 if ($currentHumidity == 0) {
                     $hcolor = $unknownColor;
                 } elseif ($currentHumidity > $HumidityMax || $currentHumidity < $HumidityMin) {
                     $hcolor = $CriticalColor;
                 } elseif ($currentHumidity > $HumidityMedMax || $currentHumidity < $HumidityMedMin) {
                     $hcolor = $CautionColor;
                 } else {
                     $hcolor = $GoodColor;
                 }
                 foreach (array($scolor, $wcolor, $pcolor, $tcolor, $hcolor, $rpcolor) as $cc) {
                     if ($cc == 'bad') {
                         $color = 'bad';
                         break;
                     } elseif ($cc == 'med') {
                         $color = 'med';
                         break;
                     } else {
                         $color = 'low';
                     }
                 }
                 $overview[$cabRow->CabinetID] = $color;
                 $space[$cabRow->CabinetID] = $scolor;
                 $weight[$cabRow->CabinetID] = $wcolor;
                 $power[$cabRow->CabinetID] = $pcolor;
                 $temperature[$cabRow->CabinetID] = $tcolor;
                 $humidity[$cabRow->CabinetID] = $hcolor;
                 $realpower[$cabRow->CabinetID] = $rpcolor;
                 $airflow[$cabRow->CabinetID] = $cabRow->FrontEdge;
             }
         }
         $tempSQL = "select max(LastRead) as ReadingTime from fac_SensorReadings where DeviceID in (select DeviceID from fac_Device where DeviceType='Sensor' and Cabinet in (select CabinetID from fac_Cabinet where DataCenterID=" . $this->DataCenterID . "))";
         $tempRes = $this->query($tempSQL);
         $tempRow = $tempRes->fetch();
         $pwrSQL = "select max(LastRead) as ReadingTime from fac_PDUStats where PDUID in (select DeviceID from fac_Device where DeviceType='CDU' and Cabinet in (select CabinetID from fac_Cabinet where DataCenterID=" . $this->DataCenterID . "))";
         $pwrRes = $this->query($pwrSQL);
         $pwrRow = $pwrRes->fetch();
         //Key
         $overview['title'] = __("Composite View of Cabinets");
         $space['title'] = __("Occupied Space");
         $weight['title'] = __("Calculated Weight");
         $power['title'] = __("Calculated Power Usage");
         $temperature['title'] = $tempRow["ReadingTime"] > 0 ? __("Measured on") . " " . date('c', strtotime($tempRow["ReadingTime"])) : __("no data");
         $humidity['title'] = $tempRow["ReadingTime"] > 0 ? __("Measured on") . " " . date('c', strtotime($tempRow["ReadingTime"])) : __("no data");
         $realpower['title'] = $pwrRow["ReadingTime"] > 0 ? __("Measured on") . " " . date('c', strtotime($pwrRow["ReadingTime"])) : __("no data");
         $airflow['title'] = __("Air Flow");
         $statusarray = array('overview' => $overview, 'space' => $space, 'weight' => $weight, 'power' => $power, 'humidity' => $humidity, 'temperature' => $temperature, 'realpower' => $realpower, 'airflow' => $airflow, 'colors' => $colors);
     }
     return $statusarray;
 }