本文整理汇总了PHP中spotEntity函数的典型用法代码示例。如果您正苦于以下问题:PHP spotEntity函数的具体用法?PHP spotEntity怎么用?PHP spotEntity使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了spotEntity函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getExpirationsText
function getExpirationsText()
{
$row_format = "%3s|%-30s|%-15s|%-15s|%s\r\n";
$ret = '';
$breakdown = array();
$breakdown[21] = array(array('from' => -365, 'to' => 0, 'title' => 'has expired within last year'), array('from' => 0, 'to' => 30, 'title' => 'expires within 30 days'));
$breakdown[22] = $breakdown[21];
$breakdown[24] = $breakdown[21];
$attrmap = getAttrMap();
foreach ($breakdown as $attr_id => $sections) {
$ret .= $attrmap[$attr_id]['name'] . "\r\n";
$ret .= "===========================================\r\n";
foreach ($sections as $section) {
$count = 1;
$result = scanAttrRelativeDays($attr_id, $section['from'], $section['to']);
if (!count($result)) {
continue;
}
$ret .= $section['title'] . "\r\n";
$ret .= "-----------------------------------------------------------------------------------\r\n";
$ret .= sprintf($row_format, '#', 'Name', 'Asset Tag', 'OEM S/N 1', 'Date Warranty Expires');
$ret .= "-----------------------------------------------------------------------------------\r\n";
foreach ($result as $row) {
$object = spotEntity('object', $row['object_id']);
$attributes = getAttrValues($object['id']);
$ret .= sprintf($row_format, $count, $object['dname'], $object['asset_no'], array_key_exists(1, $attributes) ? $attributes[1]['a_value'] : '', datetimestrFromTimestamp($row['uint_value']));
$count++;
}
$ret .= "-----------------------------------------------------------------------------------\r\n";
}
$ret .= "\r\n";
}
return $ret;
}
示例2: NagiosTabHandler
function NagiosTabHandler()
{
global $nagios_user, $nagios_password, $nagios_url;
# Load object data
assertUIntArg('object_id', __FUNCTION__);
$object = spotEntity('object', $_REQUEST['object_id']);
$nagios_url_cgi = $nagios_url . '/cgi-bin/status.cgi?host=%%NAGIOS%%';
$nagios_url_cgi = str_replace("%%NAGIOS%%", urlencode($object['name']), $nagios_url_cgi);
# Curl request
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $nagios_url_cgi);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, "{$nagios_user}:{$nagios_password}");
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$output = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
# Remove unwanted tags & headline & hyperlinks
$output = strip_tags($output, '<p><div><table><tr><td><th><br><a>');
$output = substr($output, strpos($output, '<'));
$output = str_replace("HREF='", "onclick='return popup(this.href);' target='_blank' HREF='{$nagios_url}/cgi-bin/", $output);
$output = str_replace("href='", "onclick='return popup(this.href);' target='_blank' href='{$nagios_url}/cgi-bin/", $output);
$output = str_replace($nagios_url . "/cgi-bin/http://www.nagios.org", "http://www.nagios.org", $output);
# Output
htmlExtras();
echo '<div class=portlet><h2>Nagios</h2>' . $output . '</div>';
}
示例3: CableIDTabHandler
function CableIDTabHandler()
{
echo '<div class=portlet><h2>Cable ID Helper</h2></div>';
$rack = spotEntity('rack', $_REQUEST['rack_id']);
$result = usePreparedSelectBlade('SELECT DISTINCT object_id FROM RackSpace WHERE rack_id = ? ', array($rack['id']));
$objects = $result->fetchAll(PDO::FETCH_ASSOC);
$cableIDs = array();
foreach ($objects as $object) {
$pals = getObjectPortsAndLinks($object['object_id']);
foreach ($pals as $portLink) {
if ($portLink['cableid']) {
$new = true;
$dublicate = false;
foreach ($cableIDs as $key => $cableID) {
if ($portLink['object_id'] == $cableID['object1_id'] && $portLink['name'] == $cableID['object1_port'] || $portLink['object_id'] == $cableID['object2_id'] && $portLink['name'] == $cableID['object2_port']) {
$new = false;
// Link already in List
}
// Check for duplicate cable ids
if ($new && $portLink['cableid'] == $cableID['cableID']) {
$dublicate = true;
$cableIDs[$key]['dublicate'] = true;
}
}
if ($new) {
$cableID = array();
$cableID['cableID'] = $portLink['cableid'];
$cableID['object1_id'] = $portLink['object_id'];
$cableID['object1_name'] = $portLink['object_name'];
$cableID['object1_port'] = $portLink['name'];
$cableID['object2_id'] = $portLink['remote_object_id'];
$cableID['object2_name'] = $portLink['remote_object_name'];
$cableID['object2_port'] = $portLink['remote_name'];
$cableID['dublicate'] = $dublicate;
array_push($cableIDs, $cableID);
}
}
}
}
// Sort by cableIDs
usort($cableIDs, function ($elem1, $elem2) {
return strnatcasecmp($elem1['cableID'], $elem2['cableID']);
});
// Print table
echo '<table class="cooltable" align="center" border="0" cellpadding="5" cellspacing="0">' . '<tbody>' . ' <tr>' . ' <th>CableID</th>' . ' <th>Object 1</th>' . ' <th>Object 2</th>' . ' </tr>';
$i = 0;
foreach ($cableIDs as $cableID) {
if ($i % 2) {
$class = 'row_even tdleft';
} else {
$class = 'row_odd tdleft';
}
if ($cableID['dublicate']) {
$class .= ' trerror';
}
echo '<tr class="' . $class . '">' . '<td>' . $cableID['cableID'] . '</td>' . '<td><a href="' . makeHref(array('page' => 'object', 'object_id' => $cableID['object1_id'])) . '">' . $cableID['object1_name'] . ': ' . $cableID['object1_port'] . '</a></td>' . '<td><a href="' . makeHref(array('page' => 'object', 'object_id' => $cableID['object2_id'])) . '">' . $cableID['object2_name'] . ': ' . $cableID['object2_port'] . '</a></td>' . '</tr>';
$i++;
}
echo ' </tbody>' . '</table>';
}
示例4: requireMandatoryAttrGeneric
function requireMandatoryAttrGeneric($listsrc, $attr_id, $newval)
{
$object_id = getBypassValue();
$attrs = getAttrValues($object_id);
if (array_key_exists($attr_id, $attrs) && considerGivenConstraint(spotEntity('object', $object_id), $listsrc) && !mb_strlen($newval)) {
showError('Mandatory attribute "' . $attrs[$attr_id]['name'] . '" not set');
stopOpPropagation();
}
return '';
}
示例5: renderUser
function renderUser($user_id)
{
$userinfo = spotEntity('user', $user_id);
$summary = array();
$summary['Account name'] = $userinfo['user_name'];
$summary['Real name'] = $userinfo['user_realname'];
$summary['tags'] = '';
renderEntitySummary($userinfo, 'summary', $summary);
renderFilesPortlet('user', $user_id);
}
示例6: __construct
public function __construct($lb_id, $vs_id, $rs_id, $db_row = NULL)
{
$this->lb = spotEntity('object', $lb_id);
$this->vs = spotEntity('ipv4vs', $vs_id);
$this->rs = spotEntity('ipv4rspool', $rs_id);
$this->display_cells = array('lb', 'vs', 'rs');
if (isset($db_row)) {
$this->slb = $db_row;
} else {
$result = usePreparedSelectBlade("SELECT prio, vsconfig, rsconfig FROM IPv4LB WHERE object_id = ? AND vs_id = ? AND rspool_id = ?", array($lb_id, $vs_id, $rs_id));
if ($row = $result->fetch(PDO::FETCH_ASSOC)) {
$this->slb = $row;
} else {
throw new RackTablesError("SLB triplet not found in the DB");
}
}
}
示例7: ripeTab
function ripeTab($id)
{
$ripe_db = "http://rest.db.ripe.net/search.xml?source=ripe&query-string=";
assertUIntArg('id');
$net = spotEntity('ipv4net', $id);
loadIPAddrList($net);
$startip = ip4_bin2int($net['ip_bin']);
$endip = ip4_bin2int(ip_last($net));
// Get Data from RIPE
$ripe_inetnum_str = ip4_format(ip4_int2bin($startip)) . ' - ' . ip4_format(ip4_int2bin($endip));
$ripe_query = $ripe_db . ip4_format(ip4_int2bin($startip));
$ripe_result_str = file_get_contents($ripe_query, false, NULL);
$ripe_result = simplexml_load_string($ripe_result_str);
// Check inetnum object
$ripe_inetnum_check = "/whois-resources/objects/object[@type='inetnum']/attributes/attribute[@name='inetnum'][@value='{$ripe_inetnum_str}']";
$ripe_inetnum = $ripe_result->xpath($ripe_inetnum_check);
if (empty($ripe_inetnum)) {
echo "<div class=trerror><center><h1>{$net['ip']}/{$net['mask']}</h1><h2>{$net['name']}</h2></center></div>\n";
} else {
$ripe_netname_check = "/whois-resources/objects/object[@type='inetnum']/attributes/attribute[@name='netname']";
$ripe_netname = $ripe_result->xpath($ripe_netname_check);
$netname = trim($ripe_netname[0]['value']);
if (strcmp($netname, $net['name']) != 0) {
echo "<div class=trwarning><center><h1>{$net['ip']}/{$net['mask']}</h1><h2>{$net['name']}</h2></center></div><div><center>";
} else {
echo "<div class=trok><center><h1>{$net['ip']}/{$net['mask']}</h1><h2>{$net['name']}</h2></center></div><div><center>";
}
printOpFormIntro('importRipeData', array('ripe_query' => $ripe_query, 'net_id' => $id, 'net_name' => $netname));
echo "<input type=submit value='Import RIPE records in to comments'></center></div>";
echo "</form>";
}
// echo '<em>'.$ripe_query.'</em>';
echo "<table border=0 width='100%'><tr><td class=pcleft>";
$filedir = realpath(dirname(__FILE__));
$ripe_xsl = simplexml_load_file($filedir . '/ripe_html.xsl');
startPortlet("RIPE Information Datatbase<br>{$ripe_inetnum_str}");
$proc = new XSLTProcessor();
$proc->importStyleSheet($ripe_xsl);
echo '<div class=commentblock>' . trim($proc->transformToXML($ripe_result)) . '</div>';
finishPortlet();
echo "</td></tr></table>\n";
}
示例8: renderEditVService
function renderEditVService($vsid)
{
$vsinfo = spotEntity('ipv4vs', $vsid);
printOpFormIntro('updIPv4VS');
echo '<table border=0 align=center>';
echo "<tr><th class=tdright>VIP:</th><td class=tdleft><input type=text name=vip value='{$vsinfo['vip']}'></td></tr>\n";
echo "<tr><th class=tdright>Port:</th><td class=tdleft><input type=text name=vport value='{$vsinfo['vport']}'></td></tr>\n";
echo "<tr><th class=tdright>Proto:</th><td class=tdleft>";
global $vs_proto;
printSelect($vs_proto, array('name' => 'proto'), $vsinfo['proto']);
echo "</td></tr>\n";
echo "<tr><th class=tdright>Name:</th><td class=tdleft><input type=text name=name value='{$vsinfo['name']}'></td></tr>\n";
echo "<tr><th class=tdright>Tags:</th><td class=tdleft>";
printTagsPicker();
echo "</td></tr>\n";
echo "<tr><th class=tdright>VS config:</th><td class=tdleft><textarea name=vsconfig rows=20 cols=80>{$vsinfo['vsconfig']}</textarea></td></tr>\n";
echo "<tr><th class=tdright>RS config:</th><td class=tdleft><textarea name=rsconfig rows=20 cols=80>{$vsinfo['rsconfig']}</textarea></td></tr>\n";
echo "<tr><th class=submit colspan=2>";
printImageHREF('SAVE', 'Save changes', TRUE);
echo "</td></tr>\n";
echo "</table></form>\n";
// delete link
echo '<p class="centered">';
if ($vsinfo['refcnt'] > 0) {
echo getOpLink(NULL, 'Delete virtual service', 'nodestroy', "Could not delete: there are {$vsinfo['refcnt']} LB links");
} else {
echo getOpLink(array('op' => 'del', 'id' => $vsinfo['id']), 'Delete virtual service', 'destroy');
}
}
示例9: doSNMPmining
function doSNMPmining($object_id, $snmpsetup)
{
global $objectInfo;
$objectInfo = spotEntity('object', $object_id);
$objectInfo['attrs'] = getAttrValues($object_id);
$endpoints = findAllEndpoints($object_id, $objectInfo['name']);
if (count($endpoints) == 0) {
showFuncMessage(__FUNCTION__, 'ERR1');
// endpoint not found
return;
}
if (count($endpoints) > 1) {
showFuncMessage(__FUNCTION__, 'ERR2');
// can't pick an address
return;
}
switch ($objectInfo['objtype_id']) {
case 7:
// Router
// Router
case 8:
// Network switch
// Network switch
case 965:
// Wireless
// Wireless
case 1503:
// Network chassis
$device = new RTSNMPDevice($endpoints[0], $snmpsetup);
return doGenericSNMPmining($device);
case 2:
$device = new APCPowerSwitch($endpoints[0], $snmpsetup);
return doPDUSNMPmining($device);
}
}
示例10: findAutoTagWarnings
function findAutoTagWarnings($expr)
{
global $user_defined_atags;
$self = __FUNCTION__;
static $entityIDs = array('' => array('object', 'Object'), 'ipv4net' => array('ipv4net', 'IPv4 network'), 'ipv6net' => array('ipv6net', 'IPv6 network'), 'rack' => array('rack', 'Rack'), 'row' => array('row', 'Row'), 'location' => array('location', 'Location'), 'ipvs' => array('ipv4vs', 'Virtual service'), 'ipv4rsp' => array('ipv4rspool', 'RS pool'), 'file' => array('file', 'File'), 'vst' => array('vst', '802.1Q template'), 'user' => array('user', 'User'));
switch ($expr['type']) {
case 'LEX_TRUE':
case 'LEX_FALSE':
case 'LEX_PREDICATE':
case 'LEX_TAG':
return array();
case 'LEX_AUTOTAG':
switch (1) {
case preg_match('/^\\$(.*)?id_(\\d+)$/', $expr['load'], $m) && isset($entityIDs[$m[1]]):
list($realm, $description) = $entityIDs[$m[1]];
try {
spotEntity($realm, $m[2]);
return array();
} catch (EntityNotFoundException $e) {
return array(array('header' => refRCLineno($expr['lineno']), 'class' => 'warning', 'text' => "{$description} with ID '{$recid}' does not exist."));
}
case preg_match('/^\\$username_/', $expr['load']):
$recid = preg_replace('/^\\$username_/', '', $expr['load']);
global $require_local_account;
if (!$require_local_account) {
return array();
}
if (NULL !== getUserIDByUsername($recid)) {
return array();
}
return array(array('header' => refRCLineno($expr['lineno']), 'class' => 'warning', 'text' => "Local user account '{$recid}' does not exist."));
case preg_match('/^\\$page_([\\p{L}0-9]+)$/u', $expr['load'], $m):
$recid = $m[1];
global $page;
if (isset($page[$recid])) {
return array();
}
return array(array('header' => refRCLineno($expr['lineno']), 'class' => 'warning', 'text' => "Page number '{$recid}' does not exist."));
case preg_match('/^\\$(tab|op)_[\\p{L}0-9_]+$/u', $expr['load']):
case preg_match('/^\\$any_(op|rack|object|ip4net|ip6net|net|ipv4vs|vs|ipv4rsp|rsp|file|location|row)$/', $expr['load']):
case preg_match('/^\\$typeid_\\d+$/', $expr['load']):
// FIXME: check value validity
// FIXME: check value validity
case preg_match('/^\\$cn_.+$/', $expr['load']):
// FIXME: check name validity and asset existence
// FIXME: check name validity and asset existence
case preg_match('/^\\$lgcn_.+$/', $expr['load']):
// FIXME: check name validity
// FIXME: check name validity
case preg_match('/^\\$(vlan|fromvlan|tovlan)_\\d+$/', $expr['load']):
case preg_match('/^\\$(aggregate|unused|nameless|portless|unmounted|untagged|no_asset_tag|runs_8021Q)$/', $expr['load']):
case preg_match('/^\\$(masklen_eq|spare)_\\d{1,3}$/', $expr['load']):
case preg_match('/^\\$attr_\\d+(_\\d+)?$/', $expr['load']):
case preg_match('/^\\$ip4net(-\\d{1,3}){5}$/', $expr['load']):
case preg_match('/^\\$(8021Q_domain|8021Q_tpl)_\\d+$/', $expr['load']):
case preg_match('/^\\$type_(tcp|udp|mark)$/', $expr['load']):
return array();
default:
foreach ($user_defined_atags as $regexp) {
if (preg_match($regexp, $expr['load'])) {
return array();
}
}
return array(array('header' => refRCLineno($expr['lineno']), 'class' => 'warning', 'text' => "Martian autotag '{$expr['load']}'"));
}
case 'SYNT_NOT_EXPR':
return $self($expr['load']);
case 'SYNT_AND_EXPR':
case 'SYNT_EXPR':
return array_merge($self($expr['left']), $self($expr['right']));
default:
return array(array('header' => "internal error in {$self}", 'class' => 'error', 'text' => "Skipped expression of unknown type '{$expr['type']}'"));
}
}
示例11: exit
}
// don't indicate failure unless the pidfile is 15 minutes or more old
if ($current_time < $pidfile_mtime + 15 * 60) {
exit(0);
}
print_message_line("Failed to lock {$filename}, already locked by PID " . trim(fgets($fp, 10)));
exit(1);
}
ftruncate($fp, 0);
fwrite($fp, getmypid() . "\n");
// don't close $fp yet: we need to keep an flock
}
// fetch all the needed data from DB (preparing for DB connection loss)
$switch_queue = array();
foreach ($switch_list as $object_id) {
$cell = spotEntity('object', $object_id);
$new_disabled = !considerConfiguredConstraint($cell, 'SYNC_802Q_LISTSRC');
$queue = detectVLANSwitchQueue(getVLANSwitchInfo($object_id));
if ($queue == 'disabled' xor $new_disabled) {
usePreparedExecuteBlade('UPDATE VLANSwitch SET out_of_sync="yes", last_error_ts=NOW(), last_errno=? WHERE object_id=?', array($new_disabled ? E_8021Q_SYNC_DISABLED : E_8021Q_NOERROR, $object_id));
} elseif (in_array($queue, $todo[$options['mode']])) {
$switch_queue[] = $cell;
}
}
// YOU SHOULD NOT USE DB FUNCTIONS BELOW IN THE PARENT PROCESS
// THE PARENT'S DB CONNECTION IS LOST DUE TO RECONNECTING IN THE CHILD
$fork_slots = getConfigVar('SYNCDOMAIN_MAX_PROCESSES');
$do_fork = $fork_slots > 1 and extension_loaded('pcntl');
if ($fork_slots > 1 and !$do_fork) {
throw new RackTablesError('PHP extension \'pcntl\' not found, can not use childs', RackTablesError::MISCONFIGURED);
}
示例12: buildVSMigratePlan
function buildVSMigratePlan($new_vs_id, $vs_id_list)
{
$ret = array('properties' => array('vsconfig' => '', 'rsconfig' => ''), 'ports' => array(), 'vips' => array(), 'triplets' => array(), 'messages' => array());
$config_stat = array('vsconfig' => array(), 'rsconfig' => array());
$gt = array();
// grouped triplets
foreach ($vs_id_list as $vs_id) {
$vsinfo = spotEntity('ipv4vs', $vs_id);
// create nesessary vips and ports
if ($vsinfo['proto'] != 'MARK') {
$vip_key = $vsinfo['vip_bin'];
$port_key = $vsinfo['proto'] . '-' . $vsinfo['vport'];
$ret['vips'][$vip_key] = array('vip' => $vsinfo['vip_bin'], 'vsconfig' => '', 'rsconfig' => '');
$ret['ports'][$port_key] = array('proto' => $vsinfo['proto'], 'vport' => $vsinfo['vport'], 'vsconfig' => '', 'rsconfig' => '');
} else {
$vip_key = '';
$mark = implode('', unpack('N', $vsinfo['vip_bin']));
$port_key = $vsinfo['proto'] . '-' . $mark;
$ret['ports'][$port_key] = array('proto' => $vsinfo['proto'], 'vport' => $mark, 'vsconfig' => '', 'rsconfig' => '');
}
// fill triplets
foreach (SLBTriplet::getTriplets($vsinfo) as $triplet) {
$tr_key = $triplet->lb['id'] . '-' . $triplet->rs['id'];
if (!isset($ret['triplets'][$tr_key])) {
$ret['triplets'][$tr_key] = array('object_id' => $triplet->lb['id'], 'rspool_id' => $triplet->rs['id'], 'vs_id' => $new_vs_id, 'vips' => array(), 'ports' => array());
}
$configs = array('vsconfig' => tokenizeConfig($triplet->vs['vsconfig'] . "\n" . $triplet->slb['vsconfig']), 'rsconfig' => tokenizeConfig($triplet->vs['rsconfig'] . "\n" . $triplet->slb['rsconfig']));
if ($vsinfo['proto'] != 'MARK') {
if (!isset($ret['triplets'][$tr_key]['ports'][$port_key])) {
$ret['triplets'][$tr_key]['ports'][$port_key] = array('proto' => $vsinfo['proto'], 'vport' => $vsinfo['vport'], 'vsconfig' => '', 'rsconfig' => '');
}
if (!isset($ret['triplets'][$tr_key]['vips'][$vip_key])) {
$ret['triplets'][$tr_key]['vips'][$vip_key] = array('vip' => $vsinfo['vip_bin'], 'prio' => NULL, 'vsconfig' => '', 'rsconfig' => '');
}
if ('' != $triplet->slb['prio']) {
$ret['triplets'][$tr_key]['vips'][$vip_key]['prio'] = $triplet->slb['prio'];
}
} else {
$ret['triplets'][$tr_key]['ports'][$port_key] = array('proto' => $vsinfo['proto'], 'vport' => $mark, 'vsconfig' => '', 'rsconfig' => '');
}
$old_tr_key = $tr_key . '-' . $vip_key . '-' . $port_key;
$gt['all'][$old_tr_key] = $triplet;
$gt['ports'][$port_key][$old_tr_key] = $triplet;
$gt['vips'][$vip_key][$old_tr_key] = $triplet;
$gt['vip_links'][$tr_key][$vip_key][$old_tr_key] = $triplet;
$gt['port_links'][$tr_key][$port_key][$old_tr_key] = $triplet;
foreach ($configs as $conf_type => $list) {
foreach ($list as $line) {
$config_stat[$conf_type][$line][$old_tr_key] = $triplet;
}
}
}
}
// reduce common config lines and move them from $config_stat into $ret
foreach ($config_stat as $conf_type => $stat) {
foreach ($stat as $line => $used_in_triplets) {
$added_to_triplets = array();
$wrong_triplets = array();
if (!array_sub($gt['all'], $used_in_triplets)) {
// line used in all triplets
concatConfig($ret['properties'][$conf_type], $line);
continue;
}
foreach ($gt['ports'] as $port_key => $port_triplets) {
$diff = array_sub($port_triplets, $used_in_triplets);
if (count($diff) < count($port_triplets) / 2) {
// line used in most triplets of this port
$added_to_triplets += $port_triplets;
$wrong_triplets += $diff;
concatConfig($ret['ports'][$port_key][$conf_type], $line);
}
}
foreach ($gt['vips'] as $vip_key => $vip_triplets) {
if (!array_sub($vip_triplets, $used_in_triplets)) {
if (count($vip_triplets) == count(array_sub($vip_triplets, $added_to_triplets))) {
// if none of the $vip_triplets are in $added_to_triplets,
// line used in all triplets of this vip
$added_to_triplets += $vip_triplets;
concatConfig($ret['vips'][$vip_key][$conf_type], $line);
}
}
}
foreach ($used_in_triplets as $old_tr_key => $triplet) {
if (isset($added_to_triplets[$old_tr_key])) {
continue;
}
$tr_key = $triplet->lb['id'] . '-' . $triplet->rs['id'];
if ($triplet->vs['proto'] != 'MARK') {
$vip_key = $triplet->vs['vip_bin'];
$port_key = $triplet->vs['proto'] . '-' . $triplet->vs['vport'];
} else {
$vip_key = '';
$port_key = $triplet->vs['proto'] . '-' . implode('', unpack('N', $triplet->vs['vip_bin']));
}
// if all the triplets for a given port contain line, add it to the ports' config
if (!array_sub($gt['port_links'][$tr_key][$port_key], $used_in_triplets)) {
if (count($gt['port_links'][$tr_key][$port_key]) == count(array_sub($gt['port_links'][$tr_key][$port_key], $added_to_triplets))) {
$added_to_triplets += $gt['port_links'][$tr_key][$port_key];
concatConfig($ret['triplets'][$tr_key]['ports'][$port_key][$conf_type], $line);
}
//.........这里部分代码省略.........
示例13: gwDeployDeviceConfig
function gwDeployDeviceConfig($object_id, $breed, $text)
{
if ($text == '') {
throw new InvalidArgException('text', '', 'deploy text is empty');
}
$objectInfo = spotEntity('object', $object_id);
$endpoints = findAllEndpoints($object_id, $objectInfo['name']);
if (count($endpoints) == 0) {
throw new RTGatewayError('no management address set');
}
if (count($endpoints) > 1) {
throw new RTGatewayError('cannot pick management address');
}
$endpoint = str_replace(' ', '\\ ', str_replace(' ', '+', $endpoints[0]));
$tmpfilename = tempnam('', 'RackTables-deviceconfig-');
if (FALSE === file_put_contents($tmpfilename, $text)) {
unlink($tmpfilename);
throw new RTGatewayError('failed to write to temporary file');
}
try {
queryGateway('deviceconfig', array("deploy {$endpoint} {$breed} {$tmpfilename}"));
unlink($tmpfilename);
} catch (RTGatewayError $e) {
unlink($tmpfilename);
throw $e;
}
}
示例14: snmpgeneric_list
function snmpgeneric_list($object_id)
{
global $sg_create_noconnector_ports, $sg_known_sysObjectIDs, $sg_portoifoptions, $sg_ifType_ignore;
if (isset($_POST['snmpconfig'])) {
$snmpconfig = $_POST;
} else {
showError("Missing SNMP Config");
return;
}
// sg_var_dump_html($snmpconfig);
echo '<body onload="document.getElementById(\'createbutton\').focus();">';
addJS('function setchecked(classname) { var boxes = document.getElementsByClassName(classname);
var value = document.getElementById(classname).checked;
for(i=0;i<boxes.length;i++) {
if(boxes[i].disabled == false)
boxes[i].checked=value;
}
};', TRUE);
$object = spotEntity('object', $object_id);
$object['attr'] = getAttrValues($object_id);
$snmpdev = new mySNMP($snmpconfig['version'], $snmpconfig['host'], $snmpconfig['community']);
if ($snmpconfig['version'] == "v3") {
$snmpdev->setSecurity($snmpconfig['sec_level'], $snmpconfig['auth_protocol'], $snmpconfig['auth_passphrase'], $snmpconfig['priv_protocol'], $snmpconfig['priv_passphrase']);
}
$snmpdev->init();
if ($snmpdev->getErrno()) {
showError($snmpdev->getError());
return;
}
/* SNMP connect successfull */
showSuccess("SNMP " . $snmpconfig['version'] . " connect to {$snmpconfig['host']} successfull");
echo '<form name=CreatePorts method=post action=' . $_SERVER['REQUEST_URI'] . '&module=redirect&op=create>';
echo "<strong>System Informations</strong>";
echo "<table>";
// echo "<tr><th>OID</th><th>Value</th></tr>";
$systemoids = array('sysDescr', 'sysObjectID', 'sysUpTime', 'sysContact', 'sysName', 'sysLocation');
foreach ($systemoids as $shortoid) {
$value = $snmpdev->{$shortoid};
if ($shortoid == 'sysUpTime') {
/* in hundredths of a second */
$secs = (int) ($value / 100);
$days = (int) ($secs / (60 * 60 * 24));
$secs -= $days * 60 * 60 * 24;
$hours = (int) ($secs / (60 * 60));
$secs -= $hours * 60 * 60;
$mins = (int) ($secs / 60);
$secs -= $mins * 60;
$value = "{$value} ({$days} {$hours}:{$mins}:{$secs})";
}
echo "<tr><td title=\"" . $snmpdev->lastgetoid . "\" align=\"right\">{$shortoid}: </td><td>{$value}</td></tr>";
}
unset($shortoid);
echo "</table>";
/* sysObjectID Attributes and Ports */
$sysObjectID['object'] =& $object;
/* get sysObjectID */
$sysObjectID['raw_value'] = $snmpdev->sysObjectID;
//$sysObjectID['raw_value'] = 'NET-SNMP-MIB::netSnmpAgentOIDs.10';
$sysObjectID['value'] = preg_replace('/^.*enterprises\\.([\\.[:digit:]]+)$/', '\\1', $sysObjectID['raw_value']);
/* try snmptranslate to numeric */
if (preg_match('/[^\\.0-9]+/', $sysObjectID['value'])) {
$numeric_value = $snmpdev->translatetonumeric($sysObjectID['value']);
if (!empty($numeric_value)) {
showSuccess("sysObjectID: " . $sysObjectID['value'] . " translated to {$numeric_value}");
$sysObjectID['value'] = preg_replace('/^.1.3.6.1.4.1.([\\.[:digit:]]+)$/', '\\1', $numeric_value);
}
}
/* array_merge doesn't work with numeric keys !! */
$sysObjectID['attr'] = array();
$sysObjectID['port'] = array();
$sysobjid = $sysObjectID['value'];
$count = 1;
while ($count) {
if (isset($sg_known_sysObjectIDs[$sysobjid])) {
$sysObjectID = $sysObjectID + $sg_known_sysObjectIDs[$sysobjid];
if (isset($sg_known_sysObjectIDs[$sysobjid]['attr'])) {
$sysObjectID['attr'] = $sysObjectID['attr'] + $sg_known_sysObjectIDs[$sysobjid]['attr'];
}
if (isset($sg_known_sysObjectIDs[$sysobjid]['port'])) {
$sysObjectID['port'] = $sysObjectID['port'] + $sg_known_sysObjectIDs[$sysobjid]['port'];
}
if (isset($sg_known_sysObjectIDs[$sysobjid]['text'])) {
showSuccess("found sysObjectID ({$sysobjid}) " . $sg_known_sysObjectIDs[$sysobjid]['text']);
}
}
$sysobjid = preg_replace('/\\.[[:digit:]]+$/', '', $sysobjid, 1, $count);
/* add default sysobjectid */
if ($count == 0 && $sysobjid != 'default') {
$sysobjid = 'default';
$count = 1;
}
}
$sysObjectID['vendor_number'] = $sysobjid;
/* device pf */
if (isset($sysObjectID['pf'])) {
foreach ($sysObjectID['pf'] as $function) {
if (function_exists($function)) {
/* call device pf */
$function($snmpdev, $sysObjectID, NULL);
} else {
//.........这里部分代码省略.........
示例15: error_log
case 'dict':
$oldvalue = $oldvalues[$attr_id]['key'];
break;
default:
}
// skip noops
if ($value === $oldvalue) {
continue;
}
// finally update our value
error_log("update attribute ID {$attr_id} from {$oldvalue} to {$value}");
commitUpdateAttrValue($object_id, $attr_id, $value);
}
}
// see if we also need to update the object type
$object = spotEntity('object', $object_id);
if ($sic['object_type_id'] != $object['objtype_id']) {
error_log("object type id for object {$object_id} will be changed from " . $object['objtype_id'] . ' to ' . $sic['object_type_id']);
// check that the two types are compatible
if (!array_key_exists($sic['object_type_id'], getObjectTypeChangeOptions($object_id))) {
throw new InvalidRequestArgException('new type_id', $sic['object_type_id'], 'incompatible with requested attribute values');
}
usePreparedUpdateBlade('RackObject', array('objtype_id' => $sic['object_type_id']), array('id' => $object_id));
}
// Invalidate thumb cache of all racks objects could occupy.
foreach (getResidentRacksData($object_id, FALSE) as $rack_id) {
usePreparedDeleteBlade('RackThumbnail', array('rack_id' => $rack_id));
}
// ok, now we're good
$dbxlink->commit();
// redirect to the get_object URL for the edited object