function FullRowView()
{
    if (isset($_REQUEST['row_id'])) {
        $row_id = $_REQUEST['row_id'];
    } else {
        $rack_id = 1;
    }
    global $frvVersion;
    $rowData = getRowInfo($row_id);
    $cellfilter = getCellFilter();
    $rackList = filterCellList(listCells('rack', $row_id), $cellfilter['expression']);
    // echo "<form method=post name=ImportObject action='?module=redirect&page=row&row_id=$row_id&tab=full_row_view&op=preparePrint'>";
    echo "<font size=1em color=gray>version {$frvVersion}&nbsp;</font>";
    // echo "<input type=submit name=got_very_fast_data value='Print view'>";
    // echo "</form>";
    echo '<table><tr><td nowrap="nowrap" valign="top">';
    $count = 1;
    foreach ($rackList as $rack) {
        // echo "<br>Schrank: ${rack['name']} ${rack['id']}";
        // $rackData = spotEntity ('rack', ${rack['id']});
        echo '<div class="phgrack" style="float: top; width: 240px">';
        renderReducedRack("{$rack['id']}");
        echo '</div>';
        echo '</td><td nowrap="nowrap" valign="top">';
    }
    echo '</td></tr></table>';
}
function initRackTablesRack($remain_hostgroups)
{
    // get the data of zabbix hostgroup
    $params = array('output' => 'extend', 'sortfield' => array('name'));
    $result = doPost('hostgroup.get', $params);
    $hostgroups = isset($result['result']) ? $result['result'] : array();
    global $row_id;
    global $rack_height;
    $rowInfo = getRowInfo($row_id);
    $sort_order = $rowInfo['count'];
    foreach ($hostgroups as $hostgroup) {
        if (in_array($hostgroup['name'], $remain_hostgroups)) {
            continue;
        }
        $taglist = genericAssertion('taglist', 'array0');
        $sort_order += 1;
        $rack_id = commitAddObject($hostgroup['name'], NULL, 1560, "", $taglist);
        // set height
        $params = array('output' => array('hostids'), 'groupids' => array($hostgroup['groupid']));
        $result = doPost('host.get', $params);
        $height = isset($result['result']) ? count($result['result']) : 0;
        if ($height < $rack_height) {
            $height = $rack_height;
        }
        commitUpdateAttrValue($rack_id, 27, $height);
        commitUpdateAttrValue($rack_id, 29, $sort_order);
        // Link it to the row
        commitLinkEntities('row', $row_id, 'rack', $rack_id);
    }
    $rackDatas = array();
    $allRacks = scanRealmByText('rack');
    foreach ($allRacks as $rack_id => $rack) {
        $rackDatas[$rack['name']] = $allRacks[$rack_id];
    }
    return $rackDatas;
}
Beispiel #3
0
function addRack()
{
    $taglist = genericAssertion('taglist', 'array0');
    // The new rack(s) should be placed on the bottom of the list, sort-wise
    $rowInfo = getRowInfo($_REQUEST['row_id']);
    $sort_order = $rowInfo['count'] + 1;
    if (isset($_REQUEST['got_data'])) {
        assertStringArg('name');
        assertUIntArg('height1');
        assertStringArg('asset_no', TRUE);
        $rack_id = commitAddObject($_REQUEST['name'], NULL, 1560, $_REQUEST['asset_no'], $taglist);
        // Set the height and sort order
        commitUpdateAttrValue($rack_id, 27, $_REQUEST['height1']);
        commitUpdateAttrValue($rack_id, 29, $sort_order);
        // Link it to the row
        commitLinkEntities('row', $_REQUEST['row_id'], 'rack', $rack_id);
        showSuccess('added rack ' . mkA($_REQUEST['name'], 'rack', $rack_id));
    } elseif (isset($_REQUEST['got_mdata'])) {
        assertUIntArg('height2');
        assertStringArg('names', TRUE);
        // copy-and-paste from renderAddMultipleObjectsForm()
        $names1 = explode("\n", $_REQUEST['names']);
        $names2 = array();
        foreach ($names1 as $line) {
            $parts = explode('\\r', $line);
            reset($parts);
            if (!strlen($parts[0])) {
                continue;
            } else {
                $names2[] = rtrim($parts[0]);
            }
        }
        foreach ($names2 as $cname) {
            $rack_id = commitAddObject($cname, NULL, 1560, NULL, $taglist);
            // Set the height and sort order
            commitUpdateAttrValue($rack_id, 27, $_REQUEST['height2']);
            commitUpdateAttrValue($rack_id, 29, $sort_order);
            $sort_order++;
            // Link it to the row
            commitLinkEntities('row', $_REQUEST['row_id'], 'rack', $rack_id);
            showSuccess('added rack ' . mkA($cname, 'rack', $rack_id));
        }
    } else {
        showFuncMessage(__FUNCTION__, 'ERR2');
    }
}
function addRack()
{
    $taglist = genericAssertion('taglist', 'array0');
    // The new rack(s) should be placed on the bottom of the list, sort-wise
    $rowInfo = getRowInfo($_REQUEST['row_id']);
    $sort_order = $rowInfo['count'] + 1;
    if (isset($_REQUEST['got_data'])) {
        ###############################################################################################
        # Add zabbix group
        $result = addGroup($_REQUEST["name"]);
        if (isset($result["error"])) {
            showError("Adding zabbix group is failed. Error message:" . $result["error"]);
            return;
        }
        # END
        ###############################################################################################
        assertStringArg('name');
        assertUIntArg('height1');
        assertStringArg('asset_no', TRUE);
        $rack_id = commitAddObject($_REQUEST['name'], NULL, 1560, $_REQUEST['asset_no'], $taglist);
        // Set the height and sort order
        commitUpdateAttrValue($rack_id, 27, $_REQUEST['height1']);
        commitUpdateAttrValue($rack_id, 29, $sort_order);
        // Link it to the row
        commitLinkEntities('row', $_REQUEST['row_id'], 'rack', $rack_id);
        showSuccess('added rack ' . mkA($_REQUEST['name'], 'rack', $rack_id));
        ################################################################################################
        # insert information of airconditioner
        $type = isset($_REQUEST['type']) ? $_REQUEST['type'] : 'rack';
        if ($type == 'airconditioner') {
            usePreparedInsertBlade('rack_airconditioner', array('row_id' => $_REQUEST['row_id'], 'rack_id' => $rack_id));
        }
        # insert position information
        $pos_x = isset($_REQUEST['pos_x']) ? $_REQUEST['pos_x'] : null;
        $pos_y = isset($_REQUEST['pos_y']) ? $_REQUEST['pos_y'] : null;
        $pos_z = isset($_REQUEST['pos_z']) ? $_REQUEST['pos_z'] : null;
        # if x,y,z are existing, insert into DB
        if (isset($pos_x) && isset($pos_y) && isset($pos_z)) {
            usePreparedInsertBlade('rack_position', array('row_id' => $_REQUEST['row_id'], 'rack_id' => $rack_id, 'pos_x' => $pos_x, 'pos_y' => $pos_y, 'pos_z' => $pos_z));
        }
        ################################################################################################
    } elseif (isset($_REQUEST['got_mdata'])) {
        assertUIntArg('height2');
        assertStringArg('names', TRUE);
        // copy-and-paste from renderAddMultipleObjectsForm()
        $names1 = explode("\n", $_REQUEST['names']);
        $names2 = array();
        foreach ($names1 as $line) {
            $parts = explode('\\r', $line);
            reset($parts);
            if (!strlen($parts[0])) {
                continue;
            } else {
                $names2[] = rtrim($parts[0]);
            }
        }
        foreach ($names2 as $cname) {
            ################################################################################################
            # add zabbix group
            $result = addGroup($cname);
            if (isset($result["error"])) {
                showError("Adding zabbix group is failed. Error message:" . $result["error"]);
                return;
            }
            # END
            ################################################################################################
            $rack_id = commitAddObject($cname, NULL, 1560, NULL, $taglist);
            // Set the height and sort order
            commitUpdateAttrValue($rack_id, 27, $_REQUEST['height2']);
            commitUpdateAttrValue($rack_id, 29, $sort_order);
            $sort_order++;
            // Link it to the row
            commitLinkEntities('row', $_REQUEST['row_id'], 'rack', $rack_id);
            showSuccess('added rack ' . mkA($cname, 'rack', $rack_id));
        }
    } else {
        showFuncMessage(__FUNCTION__, 'ERR2');
    }
}
Beispiel #5
0
function commitUpdateRack($rack_id, $new_row_id, $new_name, $new_height, $new_has_problems, $new_asset_no, $new_comment)
{
    // Can't shrink a rack if rows being deleted contain mounted objects
    $check_result = usePreparedSelectBlade('SELECT COUNT(*) AS count FROM RackSpace WHERE rack_id = ? AND unit_no > ?', array($rack_id, $new_height));
    $check_row = $check_result->fetch(PDO::FETCH_ASSOC);
    unset($check_result);
    if ($check_row['count'] > 0) {
        throw new InvalidArgException('new_height', $new_height, 'Cannot shrink rack, objects are still mounted there');
    }
    // Determine if the row changed
    $old_rack = spotEntity('rack', $rack_id);
    $old_row_id = $old_rack['row_id'];
    if ($old_row_id != $new_row_id) {
        // Move it to the specified row
        usePreparedUpdateBlade('EntityLink', array('parent_entity_id' => $new_row_id), array('child_entity_type' => 'rack', 'child_entity_id' => $rack_id));
        // Set the sort_order attribute so it's placed at the end of the new row
        $rowInfo = getRowInfo($new_row_id);
        usePreparedUpdateBlade('AttributeValue', array('uint_value' => $rowInfo['count']), array('object_id' => $rack_id, 'attr_id' => 29));
        // Reset the sort order of the old row
        resetRackSortOrder($old_row_id);
    }
    // Update the height
    commitUpdateAttrValue($rack_id, 27, $new_height);
    // Update the rack
    commitUpdateObject($rack_id, $new_name, NULL, $new_has_problems, $new_asset_no, $new_comment);
    recordObjectHistory($rack_id);
}
Beispiel #6
0
function dynamic_title_decoder($path_position)
{
    global $sic, $page_by_realm;
    static $net_id;
    try {
        switch ($path_position) {
            case 'index':
                return array('name' => '/' . getConfigVar('enterprise'), 'params' => array());
            case 'chapter':
                $chapter_no = assertUIntArg('chapter_no');
                $chapters = getChapterList();
                $chapter_name = isset($chapters[$chapter_no]) ? $chapters[$chapter_no]['name'] : 'N/A';
                return array('name' => "Chapter '{$chapter_name}'", 'params' => array('chapter_no' => $chapter_no));
            case 'user':
                $userinfo = spotEntity('user', assertUIntArg('user_id'));
                return array('name' => "Local user '" . $userinfo['user_name'] . "'", 'params' => array('user_id' => $userinfo['user_id']));
            case 'ipv4rspool':
                $pool_info = spotEntity('ipv4rspool', assertUIntArg('pool_id'));
                return array('name' => !strlen($pool_info['name']) ? 'ANONYMOUS' : $pool_info['name'], 'params' => array('pool_id' => $pool_info['id']));
            case 'ipv4vs':
                $vs_info = spotEntity('ipv4vs', assertUIntArg('vs_id'));
                return array('name' => $vs_info['dname'], 'params' => array('vs_id' => $vs_info['id']));
            case 'ipvs':
                $vs_info = spotEntity('ipvs', assertUIntArg('vs_id'));
                return array('name' => $vs_info['name'], 'params' => array('vs_id' => $vs_info['id']));
            case 'object':
                $object = spotEntity('object', assertUIntArg('object_id'));
                return array('name' => $object['dname'], 'params' => array('object_id' => $object['id']));
            case 'location':
                $location = spotEntity('location', assertUIntArg('location_id'));
                return array('name' => $location['name'], 'params' => array('location_id' => $location['id']));
            case 'row':
                global $pageno;
                switch ($pageno) {
                    case 'rack':
                        $rack = spotEntity('rack', assertUIntArg('rack_id'));
                        return array('name' => $rack['row_name'], 'params' => array('row_id' => $rack['row_id'], 'location_id' => $rack['location_id']));
                    case 'row':
                        $row_info = getRowInfo(assertUIntArg('row_id'));
                        return array('name' => $row_info['name'], 'params' => array('row_id' => $row_info['id'], 'location_id' => $row_info['location_id']));
                    default:
                        break;
                }
            case 'rack':
                $rack_info = spotEntity('rack', assertUIntArg('rack_id'));
                return array('name' => $rack_info['name'], 'params' => array('rack_id' => $rack_info['id']));
            case 'search':
                if (isset($_REQUEST['q'])) {
                    return array('name' => "search results for '{$_REQUEST['q']}'", 'params' => array('q' => $_REQUEST['q']));
                } else {
                    return array('name' => 'search results', 'params' => array());
                }
            case 'file':
                $file = spotEntity('file', assertUIntArg('file_id'));
                return array('name' => niftyString($file['name'], 30, FALSE), 'params' => array('file_id' => $_REQUEST['file_id']));
            case 'ipaddress':
                $address = getIPAddress(ip_parse($_REQUEST['ip']));
                return array('name' => niftyString($address['ip'] . ($address['name'] != '' ? ' (' . $address['name'] . ')' : ''), 50, FALSE), 'params' => array('ip' => $address['ip']));
            case 'ipv4net':
            case 'ipv6net':
                global $pageno;
                switch ($pageno) {
                    case 'ipaddress':
                        $net = spotNetworkByIP(ip_parse($_REQUEST['ip']));
                        $ret = array('name' => $net['ip'] . '/' . $net['mask'], 'params' => array('id' => $net['id'], 'page' => $net['realm'], 'hl_ip' => $_REQUEST['ip']));
                        return $ret;
                    default:
                        $net = spotEntity($path_position, assertUIntArg('id'));
                        return array('name' => $net['ip'] . '/' . $net['mask'], 'params' => array('id' => $net['id']));
                }
                break;
            case 'ipv4space':
            case 'ipv6space':
                global $pageno;
                switch ($pageno) {
                    case 'ipaddress':
                        $net_id = getIPAddressNetworkId(ip_parse($_REQUEST['ip']));
                        break;
                    case 'ipv4net':
                    case 'ipv6net':
                        $net_id = $_REQUEST['id'];
                        break;
                    default:
                        $net_id = NULL;
                }
                $params = array();
                if (isset($net_id)) {
                    $params = array('eid' => $net_id, 'hl_net' => 1, 'clear-cf' => '');
                }
                unset($net_id);
                $ip_ver = preg_replace('/[^\\d]*/', '', $path_position);
                return array('name' => "IPv{$ip_ver} space", 'params' => $params);
            case 'vlandomain':
                global $pageno;
                switch ($pageno) {
                    case 'vlandomain':
                        $vdom_id = $_REQUEST['vdom_id'];
                        break;
                    case 'vlan':
                        list($vdom_id, $dummy) = decodeVLANCK($_REQUEST['vlan_ck']);
                        break;
                    default:
                        break;
                }
                $vdlist = getVLANDomainOptions();
                if (!array_key_exists($vdom_id, $vdlist)) {
                    throw new EntityNotFoundException('VLAN domain', $vdom_id);
                }
                return array('name' => niftyString("domain '" . $vdlist[$vdom_id] . "'", 20, FALSE), 'params' => array('vdom_id' => $vdom_id));
            case 'vlan':
                return array('name' => formatVLANAsPlainText(getVLANInfo($sic['vlan_ck'])), 'params' => array('vlan_ck' => $sic['vlan_ck']));
            case 'vst':
                $vst = spotEntity('vst', $sic['vst_id']);
                return array('name' => niftyString("template '" . $vst['description'] . "'", 50, FALSE), 'params' => array('vst_id' => $sic['vst_id']));
            case 'dqueue':
                global $dqtitle;
                return array('name' => 'queue "' . $dqtitle[$sic['dqcode']] . '"', 'params' => array('qcode' => $sic['dqcode']));
            default:
                break;
        }
        // default behaviour is throwing an exception
        throw new RackTablesError('dynamic_title decoding error', RackTablesError::INTERNAL);
    } catch (RackTablesError $e) {
        return array('name' => __FUNCTION__ . '() failure', 'params' => array());
    }
}
 $query = "SELECT id,name FROM Rack WHERE name = '" . $_REQUEST["name"] . "';";
 $result = usePreparedSelectBlade($query);
 foreach ($result as $key => $rack) {
     if ($rack) {
         # if exists, then return
         echo json_encode(array("result" => $rack["id"]));
         return;
     }
 }
 $taglist = genericAssertion('taglist', 'array0');
 // default row id
 global $defaultRowId;
 if (!isset($_REQUEST["row_id"])) {
     $_REQUEST["row_id"] = $defaultRowId;
 }
 $rowInfo = getRowInfo($_REQUEST["row_id"]);
 $sort_order = $rowInfo['count'] + 1;
 if (!isset($_REQUEST["asset_no"])) {
     $_REQUEST["asset_no"] = "";
 }
 $rack_id = commitAddObject($_REQUEST['name'], NULL, 1560, $_REQUEST["asset_no"], $taglist);
 // Set the height and sort order
 if (!isset($_REQUEST["height"])) {
     $_REQUEST["height"] = 42;
 }
 commitUpdateAttrValue($rack_id, 27, $_REQUEST["height"]);
 commitUpdateAttrValue($rack_id, 29, $sort_order);
 // Link it to the row
 commitLinkEntities('row', $_REQUEST['row_id'], 'rack', $rack_id);
 echo json_encode(array("result" => $rack_id));
 return;
function getWattsPerRow()
{
    // assertions
    // find the needed attributes
    global $nextorder;
    // Was this function called with a specific row_id?
    if (isset($_REQUEST['row_id'])) {
        assertStringArg('row_id');
        $row_toshow = $_REQUEST['row_id'];
    } else {
        $row_toshow = -1;
    }
    //from renderRackspace(), interface.php:151
    $found_racks = array();
    $rows = array();
    $cellfilter = getCellFilter();
    $rackCount = 0;
    $order = 'odd';
    // get rackspace information
    foreach (getAllRows() as $row_id => $rowInfo) {
        $rackList = filterCellList(listCells('rack', $row_id), $cellfilter['expression']);
        $found_racks = array_merge($found_racks, $rackList);
        $rows[] = array('location_id' => $rowInfo['location_id'], 'location_name' => $rowInfo['location_name'], 'row_id' => $row_id, 'row_name' => $rowInfo['name'], 'racks' => $rackList);
        $rackCount += count($rackList);
    }
    // Main layout starts.
    echo "<table border=0 class=objectview cellspacing=0 cellpadding=0>";
    // Left portlet with list of rows.
    echo "<tr><td class=pcleft width='50%'>";
    startPortlet('Rack Rows (' . count($rows) . ')');
    echo "<table border=0 cellspacing=0 cellpadding=3 width='100%'>\n";
    foreach ($rows as $row) {
        $row_id = $row['row_id'];
        $row_name = $row['row_name'];
        $row_location = $row['location_name'];
        $rackList = $row['racks'];
        echo "<tr class=row_{$order}><td width='20%'></td><td class=tdleft>";
        if (!count($rackList)) {
            echo "{$row_location} - {$row_name} (empty row)";
        } else {
            echo "<a href='" . makeHref(array('page' => 'reports', 'tab' => 'watts_per_row', 'row_id' => $row_id)) . "'>{$row_location} - {$row_name}</a>";
        }
        echo "<td><tr>\n";
        $order = $nextorder[$order];
    }
    echo "</td></tr>\n";
    echo "</table><br>\n";
    finishPortlet();
    echo "</td><td class=pcright>";
    // Right Portlet: Draw the racks in the selected row
    if ($row_toshow > -1) {
        $rowInfo = getRowInfo($row_toshow);
        $cellfilter = getCellFilter();
        $rackList = filterCellList(listCells('rack', $row_toshow), $cellfilter['expression']);
        $rackwidth = getRackImageWidth() * getConfigVar('ROW_SCALE');
        // Maximum number of racks per row is proportionally less, but at least 1.
        $maxPerRow = max(floor(getConfigVar('RACKS_PER_ROW') / getConfigVar('ROW_SCALE')), 1);
        $rackListIdx = 0;
        $rowTotalWattage = 0;
        $order = 'odd';
        startPortlet('Racks within ' . $rowInfo['name'] . ' (' . count($rackList) . ')');
        echo "<table border=0 cellspacing=5 align='center'><tr>";
        foreach ($rackList as $rack) {
            $rackTotalWattage = 0;
            // see renderRack(), interface.php:311
            $rackData = spotEntity('rack', $rack['id']);
            amplifyCell($rackData);
            $objectChildren = getEntityRelatives('children', 'object', $objectData['id']);
            foreach ($rackData['mountedObjects'] as $object) {
                $objectData = spotEntity('object', $object);
                amplifyCell($objectData);
                foreach (getAttrValues($objectData['id']) as $record) {
                    if ($record['name'] == 'Wattage consumption') {
                        $rackTotalWattage += $record['value'];
                    }
                }
            }
            if ($rackListIdx % $maxPerRow == 0) {
                echo $rackListIdx > 0 ? '</tr><tr>' : '<tr>';
            }
            echo "<td align=center class=row_{$order}><a href='" . makeHref(array('page' => 'rack', 'rack_id' => $rack['id'])) . "'>";
            echo "<img border=0 width={$rackwidth} height=" . getRackImageHeight($rack['height']) * getConfigVar('ROW_SCALE');
            echo " title='{$rack['height']} units'";
            echo "src='?module=image&img=minirack&rack_id={$rack['id']}'>";
            echo "<br>{$rack['name']} ({$rackTotalWattage})</a></td>";
            $order = $nextorder[$order];
            $rackListIdx++;
            $rowTotalWattage += $rackTotalWattage;
        }
        echo "</tr><tr><td align=center colspan=";
        print count($rackList);
        echo "><br><b>The row total for attribute Wattage consuption is:  {$rowTotalWattage}</b></td>\n";
        echo "</tr></table>\n";
        finishPortlet();
    }
    echo "</td></tr></table>";
}