function renderInterfacesStats($object_id) { global $nextorder; global $port_use_age; addCSS("/* Live Interfaces */\n\t\t.text_green { color: #00cc00; }\n\t\t.text_yellow { color: #ff9900; }\n\t\t.text_red { color: #ff0000; }", TRUE); startPortlet('Interfaces statistics'); //get data: show version try { $uptime = queryDevice($object_id, 'getuptime'); } catch (RackTablesError $e) { } echo "<table width='100%'><tr>"; if (permitted(NULL, NULL, 'get_link_status')) { //get data: show interfaces try { $interfaces = queryDevice($object_id, 'getinterfaces'); } catch (RackTablesError $e) { } if (!empty($interfaces)) { $last_reboot = time_convert($uptime); echo "<td"; echo $last_reboot < $port_use_age ? " class='text_red'>" : $last_reboot > 262080 ? " class='text_green'>" : ">"; echo $uptime . "</tr>"; echo "<table width='80%' class='widetable' cellspacing=0 cellpadding='5px' align='center'><tr><th>Port<th>Link status<th>Last input<th>Last clear<th>Input packets<th>Output packets<th>Description</tr>"; $order = 'even'; foreach ($interfaces as $pn => $int) { echo "<tr class='row_{$order}'>"; $order = $nextorder[$order]; echo '<td>' . $pn . '<td'; echo $int['status'] == "connected" ? " class='text_green'>" : ">"; echo $int['status'] . '<td'; echo time_convert($int['last']) > $port_use_age ? " class='text_yellow'>" : ">"; echo $int['last'] . '<td'; echo time_convert($int['clear']) > 0 ? time_convert($int['clear']) < $port_use_age ? " class='text_red'>" : ">" : ">"; echo $int['clear']; echo '<td>' . $int['in_pkts']; echo '<td>' . $int['out_pkts']; echo '<td>' . $int['desc']; echo '</tr>'; } echo "</table></td>"; } } echo "</td></tr></table>"; finishPortlet(); }
function formatPortMacHints($object_id) { $result = array(); $macList = queryDevice($object_id, 'getmaclist'); foreach ($macList as $portname => $list) { $list = $macList[$portname]; $visible_part = count($list) . ' MACs'; $result[$portname]['inline'] = $visible_part; if (count($list)) { $hidden_part = '<table width="100%"><tr><th>MAC<th>VID</tr>'; foreach ($list as $mac) { $hidden_part .= '<tr><td>' . $mac['mac'] . '<td>' . $mac['vid'] . '</tr>'; } $result[$portname]['popup'] = $hidden_part; } } return $result; }
function formatPortMacHints($object_id) { $result = array(); if ($_REQUEST['ac'] == 'get-port-portmac') { $port_name = $_REQUEST['port_name']; $ports = reduceSubarraysToColumn(getObjectPortsAndLinks($_REQUEST['object_id']), 'name'); $macList = in_array($port_name, $ports) ? queryDevice($object_id, 'getportmaclist', array($port_name)) : array(); } else { $macList = queryDevice($object_id, 'getmaclist'); } foreach ($macList as $portname => $list) { $list = $macList[$portname]; $visible_part = count($list) . ' MACs'; $result[$portname]['inline'] = $visible_part; if (count($list)) { $hidden_part = '<table width="100%"><tr><th>MAC<th>VID</tr>'; foreach ($list as $mac) { $hidden_part .= '<tr><td>' . $mac['mac'] . '<td>' . $mac['vid'] . '</tr>'; } $result[$portname]['popup'] = $hidden_part; } } return $result; }
function autoPopulateUCS() { global $ucsproductmap; $ucsm_id = getBypassValue(); $oinfo = spotEntity('object', $ucsm_id); $chassis_id = array(); $done = 0; # There are three request parameters (use_terminal_settings, ucs_login and # ucs_password) not processed here. These are asserted and used inside # queryTerminal(). try { $contents = queryDevice($ucsm_id, 'getinventory'); } catch (RTGatewayError $e) { showError($e->getMessage()); return; } foreach ($contents as $item) { $mname = preg_replace('#^sys/(.+)$#', $oinfo['name'] . '/\\1', $item['DN']); if ($item['type'] == 'NetworkElement') { $new_object_id = commitAddObject($mname, NULL, 8, NULL); # Set H/W Type for Network Switch if (array_key_exists($item['model'], $ucsproductmap)) { commitUpdateAttrValue($new_object_id, 2, $ucsproductmap[$item['model']]); } # Set Serial# commitUpdateAttrValue($new_object_id, 1, $item['serial']); commitLinkEntities('object', $ucsm_id, 'object', $new_object_id); bindIPToObject(ip_parse($item['OOB']), $new_object_id, 'mgmt0', 'regular'); $done++; } elseif ($item['type'] == 'EquipmentChassis') { $chassis_id[$item['DN']] = $new_object_id = commitAddObject($mname, NULL, 1502, NULL); # Set H/W Type for Server Chassis if (array_key_exists($item['model'], $ucsproductmap)) { commitUpdateAttrValue($new_object_id, 2, $ucsproductmap[$item['model']]); } # Set Serial# commitUpdateAttrValue($new_object_id, 1, $item['serial']); commitLinkEntities('object', $ucsm_id, 'object', $new_object_id); $done++; } elseif ($item['type'] == 'ComputeBlade') { if ($item['assigned'] == '') { $new_object_id = commitAddObject($mname, NULL, 4, NULL); } else { $spname = preg_replace('#.+/ls-(.+)#i', '${1}', $item['assigned']) . "(" . $oinfo['name'] . ")"; $new_object_id = commitAddObject($spname, NULL, 4, NULL); } # Set H/W Type for Blade Server if (array_key_exists($item['model'], $ucsproductmap)) { commitUpdateAttrValue($new_object_id, 2, $ucsproductmap[$item['model']]); } # Set Serial# commitUpdateAttrValue($new_object_id, 1, $item['serial']); # Set Slot# commitUpdateAttrValue($new_object_id, 28, $item['slot']); $parent_name = preg_replace('#^([^/]+)/([^/]+)/([^/]+)$#', '${1}/${2}', $item['DN']); if (array_key_exists($parent_name, $chassis_id)) { commitLinkEntities('object', $chassis_id[$parent_name], 'object', $new_object_id); } $done++; } } # endfor showSuccess("Auto-populated UCS Domain '{$oinfo['name']}' with {$done} items"); }
function renderDiscoveredNeighbors($object_id) { global $tabno; $opcode_by_tabno = array('livecdp' => 'getcdpstatus', 'livelldp' => 'getlldpstatus'); try { $neighbors = queryDevice($object_id, $opcode_by_tabno[$tabno]); $neighbors = sortPortList($neighbors); } catch (RTGatewayError $e) { showError($e->getMessage()); return; } $mydevice = spotEntity('object', $object_id); amplifyCell($mydevice); // reindex by port name $myports = array(); foreach ($mydevice['ports'] as $port) { if (mb_strlen($port['name'])) { $myports[$port['name']][] = $port; } } // scroll to selected port if (isset($_REQUEST['hl_port_id'])) { assertUIntArg('hl_port_id'); $hl_port_id = intval($_REQUEST['hl_port_id']); addAutoScrollScript("port-{$hl_port_id}"); } switchportInfoJS($object_id); // load JS code to make portnames interactive printOpFormIntro('importDPData'); echo '<br><table cellspacing=0 cellpadding=5 align=center class=widetable>'; echo '<tr><th colspan=2>local port</th><th></th><th>remote device</th><th colspan=2>remote port</th><th><input type="checkbox" checked id="cb-toggle"></th></tr>'; $inputno = 0; foreach ($neighbors as $local_port => $remote_list) { $initial_row = TRUE; // if port has multiple neighbors, the first table row is initial // array of local ports with the name specified by DP $local_ports = isset($myports[$local_port]) ? $myports[$local_port] : array(); foreach ($remote_list as $dp_neighbor) { $error_message = NULL; $link_matches = FALSE; $portinfo_local = NULL; $portinfo_remote = NULL; $variants = array(); do { // once-cyle fake loop used only to break out of it if (!empty($local_ports)) { $portinfo_local = $local_ports[0]; } // find remote object by DP information $dp_remote_object_id = searchByMgmtHostname($dp_neighbor['device']); if (!$dp_remote_object_id) { $dp_remote_object_id = lookupEntityByString('object', $dp_neighbor['device']); } if (!$dp_remote_object_id) { $error_message = "No such neighbor <i>{$dp_neighbor['device']}</i>"; break; } $dp_remote_object = spotEntity('object', $dp_remote_object_id); amplifyCell($dp_remote_object); $dp_neighbor['port'] = shortenIfName($dp_neighbor['port'], NULL, $dp_remote_object['id']); // get list of ports that have name matching CDP portname $remote_ports = array(); // list of remote (by DP info) ports foreach ($dp_remote_object['ports'] as $port) { if ($port['name'] == $dp_neighbor['port']) { $portinfo_remote = $port; $remote_ports[] = $port; } } // check if ports with such names exist on devices if (empty($local_ports)) { $error_message = "No such local port <i>{$local_port}</i>"; break; } if (empty($remote_ports)) { $error_message = "No such port on " . formatPortLink($dp_remote_object['id'], $dp_remote_object['name'], NULL, NULL); break; } // determine match or mismatch of local link foreach ($local_ports as $portinfo_local) { if ($portinfo_local['remote_id']) { if ($portinfo_local['remote_object_id'] == $dp_remote_object_id and $portinfo_local['remote_name'] == $dp_neighbor['port']) { // set $portinfo_remote to corresponding remote port foreach ($remote_ports as $portinfo_remote) { if ($portinfo_remote['id'] == $portinfo_local['remote_id']) { break; } } $link_matches = TRUE; unset($error_message); } elseif ($portinfo_local['remote_object_id'] != $dp_remote_object_id) { $error_message = "Remote device mismatch - port linked to " . formatLinkedPort($portinfo_local); } else { // ($portinfo_local['remote_name'] != $dp_neighbor['port']) $error_message = "Remote port mismatch - port linked to " . formatPortLink($portinfo_local['remote_object_id'], NULL, $portinfo_local['remote_id'], $portinfo_local['remote_name']); } break 2; } } // no local links found, try to search for remote links foreach ($remote_ports as $portinfo_remote) { if ($portinfo_remote['remote_id']) { $remote_link_html = formatLinkedPort($portinfo_remote); $remote_port_html = formatPortLink($portinfo_remote['object_id'], NULL, $portinfo_remote['id'], $portinfo_remote['name']); $error_message = "Remote port {$remote_port_html} is already linked to {$remote_link_html}"; break 2; } } // no links found on both sides, search for a compatible port pair $port_types = array(); foreach (array('left' => $local_ports, 'right' => $remote_ports) as $side => $port_list) { foreach ($port_list as $portinfo) { $tmp_types = $portinfo['iif_id'] == 1 ? array($portinfo['oif_id'] => $portinfo['oif_name']) : getExistingPortTypeOptions($portinfo['id']); foreach ($tmp_types as $oif_id => $oif_name) { $port_types[$side][$oif_id][] = array('id' => $oif_id, 'name' => $oif_name, 'portinfo' => $portinfo); } } } foreach ($port_types['left'] as $left_id => $left) { foreach ($port_types['right'] as $right_id => $right) { if (arePortTypesCompatible($left_id, $right_id)) { foreach ($left as $left_port) { foreach ($right as $right_port) { $variants[] = array('left' => $left_port, 'right' => $right_port); } } } } } if (!count($variants)) { // no compatible ports found $error_message = "Incompatible port types"; } } while (FALSE); // do { $tr_class = $link_matches ? 'trok' : (isset($error_message) ? 'trerror' : 'trwarning'); echo "<tr class=\"{$tr_class}\">"; if ($initial_row) { $count = count($remote_list); $td_class = ''; if (isset($hl_port_id) and $hl_port_id == $portinfo_local['id']) { $td_class = "class='border_highlight'"; } echo "<td rowspan=\"{$count}\" {$td_class} NOWRAP>" . ($portinfo_local ? formatPortLink($mydevice['id'], NULL, $portinfo_local['id'], $portinfo_local['name'], 'interactive-portname port-menu') : "<a class='interactive-portname port-menu nolink'>{$local_port}</a>") . ($count > 1 ? "<br> ({$count} neighbors)" : '') . '</td>'; $initial_row = FALSE; } echo "<td>" . ($portinfo_local ? formatPortIIFOIF($portinfo_local) : ' ') . "</td>"; echo "<td>" . formatIfTypeVariants($variants, "ports_{$inputno}") . "</td>"; echo "<td>{$dp_neighbor['device']}</td>"; echo "<td>" . ($portinfo_remote ? formatPortLink($dp_remote_object_id, NULL, $portinfo_remote['id'], $portinfo_remote['name']) : $dp_neighbor['port']) . "</td>"; echo "<td>" . ($portinfo_remote ? formatPortIIFOIF($portinfo_remote) : ' ') . "</td>"; echo "<td>"; if (!empty($variants)) { echo "<input type=checkbox name=do_{$inputno} class='cb-makelink'>"; $inputno++; } echo "</td>"; if (isset($error_message)) { echo "<td style=\"background-color: white; border-top: none\">{$error_message}</td>"; } echo "</tr>"; } } if ($inputno) { echo "<input type=hidden name=nports value={$inputno}>"; echo '<tr><td colspan=7 align=center>' . getImageHREF('CREATE', 'import selected', TRUE) . '</td></tr>'; } echo '</table></form>'; addJS(<<<END \$(document).ready(function () { \t\$('#cb-toggle').click(function (event) { \t\tvar list = \$('.cb-makelink'); \t\tfor (var i in list) { \t\t\tvar cb = list[i]; \t\t\tcb.checked = event.target.checked; \t\t} \t}).triggerHandler('click'); }); END , TRUE); }
function getRunning8021QConfig($object_id) { $ret = queryDevice($object_id, 'get8021q'); // Once there is no default VLAN in the parsed data, it means // something else was parsed instead of config text. if (!in_array(VLAN_DFL_ID, $ret['vlanlist']) || empty($ret['portdata'])) { throw new RTGatewayError('communication with device failed'); } return $ret; }