/** Create a Virtual Machine in the specified pool @param name The name of the new Virtual Machine @param ip The IP address to assign the VM @param asset Asset tag to use (VM UUID) @param osInfo Operating System information (to be stored as a comment) @param taglist Array of tags to use for this new object @param poolID Virtual Machine pool to parent this object to */ function createVMInPool($name, $ip, $asset, $osInfo, $taglist, $poolID, $vmTypeID) { // make sure there's no duplicates if (getSearchResultByField('RackObject', array('id'), 'name', $name, '', 2)) { return FALSE; } // commitAddObject ($new_name, $new_label, $new_type_id, $new_asset_no, $taglist = array()) $newObject = commitAddObject($name, $name, $vmTypeID, $asset, $taglist); // add IP address to new object if (!empty($ip)) { bindIpToObject(ip_parse($ip), $newObject, 'eth0', 'regular'); } // add OS info to new object if (!empty($osInfo)) { usePreparedUpdateBlade('Object', array('comment' => $osInfo), array('id' => $newObject)); } // set container //commitLinkEntities($parent_entity_type, $parent_entity_id, $child_entity_type, $child_entity_id); commitLinkEntities("object", $poolID, "object", $newObject); }
function getNetUsageAJAX() { assertStringArg('net_id'); list($ip, $mask) = explode('/', $_REQUEST['net_id']); $ip_bin = ip_parse($ip); $net = spotNetworkByIP($ip_bin, $mask + 1); if (!isset($net) or $net['mask'] != $mask) { $net = constructIPRange($ip_bin, $mask); } loadIPAddrList($net); echo getRenderedIPNetCapacity($net); }
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 snmpgeneric_opcreate() { $object_id = $_REQUEST['object_id']; $attr = getAttrValues($object_id); // sg_var_dump_html($_REQUEST); // sg_var_dump_html($attr); /* commitUpdateAttrValue ($object_id, $attr_id, $new_value); */ if (isset($_POST['updateattr'])) { foreach ($_POST['updateattr'] as $attr_id => $value) { // if(empty($attr[$attr_id]['value'])) if (!empty($value)) { commitUpdateAttrValue($object_id, $attr_id, $value); showSuccess("Attribute " . $attr[$attr_id]['name'] . " set to {$value}"); } } unset($attr_id); unset($value); } /* updateattr */ /* create ports */ if (isset($_POST['portcreate'])) { foreach ($_POST['portcreate'] as $if => $value) { $ifName = isset($_POST['ifName'][$if]) ? trim($_POST['ifName'][$if]) : ''; $ifPhysAddress = isset($_POST['ifPhysAddress'][$if]) ? trim($_POST['ifPhysAddress'][$if]) : ''; $ifAlias = isset($_POST['ifAlias'][$if]) ? trim($_POST['ifAlias'][$if]) : ''; $ifDescr = isset($_POST['ifDescr'][$if]) ? trim($_POST['ifDescr'][$if]) : ''; //$visible_label = (empty($ifAlias) ? '' : $ifAlias.'; ').$ifDescr; $visible_label = $ifAlias; if (empty($ifName)) { showError('Port without ifName ' . $_POST['porttypeid'][$if] . ', ' . $visible_label . ', ' . $ifPhysAddress); } else { commitAddPort($object_id, $ifName, $_POST['porttypeid'][$if], $visible_label, $ifPhysAddress); showSuccess('Port created ' . $ifName . ', ' . $_POST['porttypeid'][$if] . ', ' . $visible_label . ', ' . $ifPhysAddress); } } unset($if); unset($value); } /* portcreate */ /* net create */ if (isset($_POST['netcreate'])) { foreach ($_POST['netcreate'] as $id => $addrtype) { $range = $_POST['netprefix'][$id]; $name = $_POST['netname'][$id]; $is_reserved = isset($_POST['netreserve'][$id]); if ($addrtype == 'ipv4' || $addrtype == 'ipv4z') { createIPv4Prefix($range, $name, $is_reserved); } else { createIPv6Prefix($range, $name, $is_reserved); } showSuccess("{$range} {$name} created"); } unset($id); unset($addrtype); } /* netcreate */ /* allocate ipv6 adresses */ if (isset($_POST['ipv6addrcreate'])) { foreach ($_POST['ipv6addrcreate'] as $ipaddr => $if) { bindIPv6ToObject(ip6_parse($ipaddr), $object_id, $_POST['ifName'][$if], 1); /* connected */ showSuccess("{$ipaddr} allocated"); } unset($ipaddr); unset($if); } /* allocate ip adresses */ if (isset($_POST['ipaddrcreate'])) { foreach ($_POST['ipaddrcreate'] as $ipaddr => $if) { bindIPToObject(ip_parse($ipaddr), $object_id, $_POST['ifName'][$if], 1); /* connected */ showSuccess("{$ipaddr} allocated"); } unset($ipaddr); unset($if); } /* ipaddrecreate */ /* update label */ if (isset($_POST['updatelabel'])) { foreach ($_POST['updatelabel'] as $if => $port_id) { $ifAlias = isset($_POST['ifAlias'][$if]) ? trim($_POST['ifAlias'][$if]) : ''; sg_commitUpdatePortLabel($object_id, $port_id, $ifAlias); $ifName = isset($_POST['ifName'][$if]) ? trim($_POST['ifName'][$if]) : ''; showSuccess("label updated on {$ifName} to {$ifAlias}"); } unset($if); unset($port_id); } /* updatemac */ /* update mac addresses only */ if (isset($_POST['updatemac'])) { foreach ($_POST['updatemac'] as $if => $port_id) { $ifPhysAddress = isset($_POST['ifPhysAddress'][$if]) ? trim($_POST['ifPhysAddress'][$if]) : ''; sg_commitUpdatePortl2address($object_id, $port_id, $ifPhysAddress); $ifName = isset($_POST['ifName'][$if]) ? trim($_POST['ifName'][$if]) : ''; showSuccess("l2address updated on {$ifName} to {$ifPhysAddress}"); } unset($if); unset($port_id); } /* updatemac */ /* update port type */ if (isset($_POST['updateporttype'])) { foreach ($_POST['updateporttype'] as $if => $port_id) { $porttypeid = isset($_POST['porttypeid'][$if]) ? trim($_POST['porttypeid'][$if]) : ''; sg_commitUpdatePortType($object_id, $port_id, $porttypeid); $ifName = isset($_POST['ifName'][$if]) ? trim($_POST['ifName'][$if]) : ''; showSuccess("port type updated on {$ifName}"); } unset($if); unset($port_id); } /* updateporttype */ }
function initRackTablesObject($rackDatas) { // zabbix host data $params = array('output' => 'extend'); $result = doPost('host.get', $params); $hosts = isset($result['result']) ? $result['result'] : array(); $objectDatas = array(); foreach ($hosts as $host) { $object_type_id = 4; $object_name = isset($host['host']) ? $host['host'] : ""; $object_label = ""; $object_asset_no = ""; $taglist = array(); $has_problems = $host['status'] == 0 ? 'no' : 'yes'; $object_id = commitAddObject($object_name, $object_label, $object_type_id, $object_asset_no, $taglist); usePreparedUpdateBlade('Object', array('has_problems' => $has_problems), array('id' => $object_id)); $objectDatas[$host['hostid']] = $object_id; // set hostgroup $params = array('output' => array('name'), 'hostids' => array($host['hostid'])); $result = doPost('hostgroup.get', $params); $hostgroups = isset($result['result']) ? $result['result'] : array(); $rack_ids = array(); $_REQUEST = array(); foreach ($hostgroups as $hostgroup) { if (isset($rackDatas[$hostgroup['name']])) { $rack = $rackDatas[$hostgroup['name']]; amplifyCell($rack); array_push($rack_ids, $rack['id']); $height = $rack['height']; for ($i = 0; $i < 3; $i++) { for ($j = $height; $j > 0; $j--) { if ($rack[$j][$i]['state'] == 'F') { # state == "T" : mounted $_REQUEST['atom_' . $rack['id'] . "_{$j}" . "_{$i}"] = 'on'; break 2; } } } } } $_REQUEST['object_id'] = $object_id; $_REQUEST['rackmulti'] = $rack_ids; $object = spotEntity('object', $object_id); $changecnt = 0; // Get a list of rack ids which are parents of the object $parentRacks = reduceSubarraysToColumn(getParents($object, 'rack'), 'id'); $workingRacksData = array(); foreach ($_REQUEST['rackmulti'] as $cand_id) { if (!isset($workingRacksData[$cand_id])) { $rackData = spotEntity('rack', $cand_id); amplifyCell($rackData); $workingRacksData[$cand_id] = $rackData; } else { $rackData = $workingRacksData[$cand_id]; } $is_ro = !rackModificationPermitted($rackData, 'updateObjectAllocation', FALSE); // It's zero-U mounted to this rack on the form, but not in the DB. Mount it. if (isset($_REQUEST["zerou_{$cand_id}"]) && !in_array($cand_id, $parentRacks)) { if ($is_ro) { continue; } $changecnt++; commitLinkEntities('rack', $cand_id, 'object', $object_id); } // It's not zero-U mounted to this rack on the form, but it is in the DB. Unmount it. if (!isset($_REQUEST["zerou_{$cand_id}"]) && in_array($cand_id, $parentRacks)) { if ($is_ro) { continue; } $changecnt++; commitUnlinkEntities('rack', $cand_id, 'object', $object_id); } } foreach ($workingRacksData as &$rd) { applyObjectMountMask($rd, $object_id); } $oldMolecule = getMoleculeForObject($object_id); foreach ($workingRacksData as $rack_id => $rackData) { $is_ro = !rackModificationPermitted($rackData, 'updateObjectAllocation', FALSE); if ($is_ro || !processGridForm($rackData, 'F', 'T', $object_id)) { continue; } $changecnt++; // Reload our working copy after form processing. $rackData = spotEntity('rack', $cand_id); amplifyCell($rackData); applyObjectMountMask($rackData, $object_id); $workingRacksData[$rack_id] = $rackData; } if ($changecnt) { // Log a record. $newMolecule = getMoleculeForObject($object_id); global $remote_username, $sic; usePreparedInsertBlade('MountOperation', array('object_id' => $object_id, 'old_molecule_id' => count($oldMolecule) ? createMolecule($oldMolecule) : NULL, 'new_molecule_id' => count($newMolecule) ? createMolecule($newMolecule) : NULL, 'user_name' => $remote_username, 'comment' => empty($sic['comment']) ? NULL : $sic['comment'])); } // set IP $params = array('output' => 'extend', 'hostids' => $host['hostid']); $result = doPost('hostinterface.get', $params); $hostinterfaces = isset($result['result']) ? $result['result'] : array(); foreach ($hostinterfaces as $interface) { if (isset($interface['ip']) && $interface['ip'] != '127.0.0.1') { $allocs = getObjectIPAllocations($object_id); $current_ips = array(); foreach ($allocs as $alloc) { $ip = $alloc["addrinfo"]["ip"]; $current_ips[$ip] = $ip; } $ip = $interface['ip']; if (!in_array($ip, array_values($current_ips))) { // new IP $ip_bin = ip_parse($ip); if (null == getIPAddressNetworkId($ip_bin)) { // if ip is not exists, adding it into RackTables IPv4Prefix. $range = substr($ip, 0, strripos($ip, '.')) . '.0/24'; $vlan_ck = NULL; $net_id = createIPv4Prefix($range, 'admim', isCheckSet('is_connected'), $taglist); $net_cell = spotEntity('ipv4net', $net_id); if (isset($vlan_ck)) { if (considerConfiguredConstraint($net_cell, 'VLANIPV4NET_LISTSRC')) { commitSupplementVLANIPv4($vlan_ck, $net_id); } } } bindIPToObject($ip_bin, $object_id, "", ""); } } } } return $objectDatas; }
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()); } }
$rackData = spotEntity('rack', $_REQUEST['rack_id']); amplifyCell($rackData); sendAPIResponse($rackData); break; // get info for a single IP address // UI equivalent: /index.php?page=ipaddress&hl_object_id=911&ip=10.200.1.66 // UI handler: renderIPAddress() // get info for a single IP address // UI equivalent: /index.php?page=ipaddress&hl_object_id=911&ip=10.200.1.66 // UI handler: renderIPAddress() case 'get_ipaddress': require_once 'inc/init.php'; assertStringArg("ip", TRUE); // basic IP address info $address = getIPAddress(ip_parse($_REQUEST['ip'])); $address['network_id'] = getIPAddressNetworkId(ip_parse($_REQUEST['ip'])); // TODO: add some / all of the following data // virtual services // ! empty $address['vslist'] // foreach $address['vslist'] as $vs_id // $blah = spotEntity ('ipv4vs', $vs_id) // RS pools // allocations // departing NAT rules // arriving NAT rules sendAPIResponse($address); break; // get one object // UI equivalent: /index.php?page=object&object_id=909 // UI handler: renderObject() // get one object
function ip_checkparse($ip) { try { return ip_parse($ip); } catch (InvalidArgException $e) { return FALSE; } }
function Update() { // Read uploaded file $lines = file($_FILES['userfile']['tmp_name']); // add file contents to facter array foreach ($lines as $line_num => $line) { $tmpfacter = explode("=>", $line, 2); $facter[trim($tmpfacter[0])] = str_replace('"', '', trim($tmpfacter[1])); } // Fix fqdn since all fields have \n inn them $facter['fqdn'] = str_replace("\n", "", $facter['fqdn']); // Check if it's an existing machine // 2011-08-31 <*****@*****.**> // * expanded query to try to match via facter Serialnumber to be able to // match unnamed HW assets. Serial is more precise and less likely to be changed. if (array_key_exists('serialnumber', $facter) && strlen($facter['serialnumber']) > 0 && $facter['serialnumber'] != 'Not Specified') { $query = "select id from RackObject where name = \"{$facter['fqdn']}\" OR asset_no = \"{$facter['serialnumber']}\" LIMIT 1"; } else { $query = "select id from RackObject where name = \"{$facter['fqdn']}\" LIMIT 1"; } unset($result); $result = usePreparedSelectBlade($query); $resultarray = $result->fetchAll(PDO::FETCH_ASSOC); if ($resultarray) { $id = $resultarray[0]['id']; } // If it's a new machine if (!isset($id)) { // Check to see if it's a physical machine and get the correct id for Server if ($facter['is_virtual'] == "false") { // Find server id $query = "select dict_key from Dictionary where dict_value='Server' LIMIT 1"; unset($result); $result = usePreparedSelectBlade($query); $resultarray = $result->fetchAll(); if ($resultarray) { $virtual = $resultarray[0]['dict_key']; } } else { // Find virtual id $query = "select dict_key from Dictionary where dict_value='VM' LIMIT 1"; unset($result); $result = usePreparedSelectBlade($query); $resultarray = $result->fetchAll(PDO::FETCH_ASSOC); if ($resultarray) { $virtual = $resultarray[0]['dict_key']; } } // Add the new machine $newmachine = commitAddObject($facter['fqdn'], "", $virtual, $value = ""); $type_id = getObjectTypeID($newmachine); } else { // Just set some fields I use later down for updating $newmachine = $id; $machineupdate = 1; $type_id = getObjectTypeID($newmachine); } // 2011-08-31 <*****@*****.**> // * Update (unique) name of object. if (array_key_exists('serialnumber', $facter) && strlen($facter['serialnumber']) > 0 && $facter['serialnumber'] != 'Not Specified') { unset($result); $query = "select * from RackObject where asset_no = \"{$facter['serialnumber']}\" LIMIT 1"; $result = usePreparedSelectBlade($query); $resultarray = $result->fetchAll(PDO::FETCH_ASSOC); if ($resultarray) { $id = $resultarray[0]['id']; $label = $resultarray[0]['label']; // Update FQDN commitUpdateObject($id, $facter['fqdn'], $label, 'no', $facter['serialnumber'], 'Facter Import::Update Common Name'); } } // Find HW type id // 2011-08-31 <*****@*****.**> // * adjust format to match default Dictionary Sets if ($facter['is_virtual'] == "false") { $iHWTemp = preg_match('([a-zA-Z]{1,})', $facter['manufacturer'], $matches); $sManufacturer = $matches[0]; $sHW = preg_replace('(\\ )', '\\1%GPASS%', $facter['productname']); $sHWType = $sManufacturer . ' ' . $sHW; $query = "select id from Attribute where name='HW type' LIMIT 1"; unset($result); $result = usePreparedSelectBlade($query); $resultarray = $result->fetchAll(PDO::FETCH_ASSOC); if ($resultarray) { $id = $resultarray[0]['id']; // Update HW type $hw_dict_key = getdict($sHWType, $chapter = 11); commitUpdateAttrValue($object_id = $newmachine, $attr_id = $id, $value = $hw_dict_key); } //Also Check if HYPERVISOR if (isset($facter['is_hypervisor'])) { $query = "select id from Attribute where name REGEXP '^ *Hypervisor Type\$' LIMIT 1"; unset($result); $result = usePreparedSelectBlade($query); $resultarray = $result->fetchAll(PDO::FETCH_ASSOC); if ($resultarray) { $id = $resultarray[0]['id']; // Update Hypervisor type $hypervisor_type = $facter['is_hypervisor']; $hypervisor_type_dict_key = getdict($hw = $hypervisor_type, $chapter = 10005); commitUpdateAttrValue($object_id = $newmachine, $attr_id = $id, $value = $hypervisor_type_dict_key); } //Set Value to Yes $query = "select id from Attribute where name REGEXP '^ *Hypervisor' LIMIT 1"; unset($result); $result = usePreparedSelectBlade($query); $resultarray = $result->fetchAll(PDO::FETCH_ASSOC); if ($resultarray) { $id = $resultarray[0]['id']; // Update Hypervisor type $hypervisor = "Yes"; $hypervisor_dict_key = getdict($hypervisor, $chapter = 29); commitUpdateAttrValue($object_id = $newmachine, $attr_id = $id, $value = $hypervisor_dict_key); } //Find Running VMs $vms = explode(',', $facter['vms']); $vm_count = count($vms); for ($i = 0; $i < $vm_count; $i++) { //addToParent addVmToParent($vms[$i], $newmachine); } } else { $query = "select id from Attribute where name REGEXP '^ *Hypervisor' LIMIT 1"; unset($result); $result = usePreparedSelectBlade($query); $resultarray = $result->fetchAll(PDO::FETCH_ASSOC); if ($resultarray) { $id = $resultarray[0]['id']; // Update Hypervisor type $hypervisor = "No"; $hypervisor_dict_key = getdict($hypervisor, $chapter = 29); commitUpdateAttrValue($object_id = $newmachine, $attr_id = $id, $value = ""); } } } // Find SW type id (OS) $query = "select id from Attribute where name REGEXP '^ *SW type\$' LIMIT 1"; unset($result); $result = usePreparedSelectBlade($query); $resultarray = $result->fetchAll(PDO::FETCH_ASSOC); if ($resultarray) { $id = $resultarray[0]['id']; // Update SW type (OS) $osrelease = $facter['operatingsystem'] . '%GSKIP%' . $facter['operatingsystem'] . ' V' . $facter['operatingsystemrelease']; $os_dict_key = getdict($hw = $osrelease, $chapter = 13); commitUpdateAttrValue($object_id = $newmachine, $attr_id = $id, $value = $os_dict_key); } //Generic to read in from file $manifest_file = fopen("../plugins/manifest", "r") or die("Could not open manifest, make sure it is in the websrv root and called manifest \n"); while (!feof($manifest_file)) { $tmp_line = fgets($manifest_file); if (!empty($tmp_line) && !preg_match("/\\/\\//", $tmp_line)) { @(list($Fact, $Attr, $Chapter) = array_map('trim', explode(',', $tmp_line, 3))); //check for multi-facter names if (strstr($Fact, '.')) { @(list($Fact1, $Fact2) = array_map('trim', explode('.', $Fact))); $value = $facter[$Fact1] . ' ' . $facter[$Fact2]; if (!isset($facter[$Fact1]) || !isset($facter[$Fact2])) { echo "WARNING: {$Fact1} or {$Fact2} does not exist in Facter for this object \n"; continue; } } else { if (!isset($facter[$Fact])) { echo "WARNING: {$Fact} does not exist in Facter for this object \n"; continue; } else { $value = $facter[$Fact]; } } $query = "select id from Attribute where name REGEXP '^ *{$Attr}' LIMIT 1"; unset($result); $result = usePreparedSelectBlade($query); $resultarray = $result->fetchAll(PDO::FETCH_ASSOC); $id = $resultarray[0]['id']; if (!valid($type_id, $id)) { echo "WARNING: Not a valid Mapping for {$Fact} to {$Attr} for objectType {$type_id} \n"; } else { if ($resultarray) { if (!empty($Chapter)) { $name = $value; $name_dict_key = getdict($hw = $name, $chapter = $Chapter); commitUpdateAttrValue($object_id = $newmachine, $attr_id = $id, $value = $name_dict_key); } else { if (preg_match("/[0-9]{1,2}\\/[0-9]{1,2}\\/[0-9]{4}/", $value) || preg_match("/[0-9]{1,2}\\-[0-9]{1,2}\\-[0-9]{4}/", $value) || preg_match("/[0-9]{4}\\-[0-9]{1,2}\\-[0-9]{1,2}/", $value)) { //handle dates commitUpdateAttrValue($newmachine, $id, strtotime($value)); } else { commitUpdateAttrValue($newmachine, $id, $value); } } } } } } fclose($manifest_file); // Add network interfaces // Create an array with interfaces $nics = explode(',', $facter['interfaces']); // Go through all interfaces and add IP and MAC $count = count($nics); for ($i = 0; $i < $count; $i++) { // Remove newline from the field $nics[$i] = str_replace("\n", "", $nics[$i]); // We generally don't monitor sit interfaces. // We don't do this for lo interfaces, too // 2011-08-31 <*****@*****.**> // * Only Document real interfaces, dont do bridges, bonds, vlan-interfaces // when they have no IP defined. if (preg_match('(_|^(bond|lo|sit|vnet|virbr|veth|peth))', $nics[$i]) != 0) { // do nothing } else { // Get IP if (isset($facter['ipaddress_' . $nics[$i]])) { $ip = $facter['ipaddress_' . $nics[$i]]; } // Get MAC if (isset($facter['macaddress_' . $nics[$i]])) { $mac = $facter['macaddress_' . $nics[$i]]; } //check if VM or not if ($facter['is_virtual'] == "false") { // Find 1000Base-T id $query = "select id from PortOuterInterface where oif_name REGEXP '^ *1000Base-T\$' LIMIT 1"; } else { // Find virtual port id $query = "select id from PortOuterInterface where oif_name REGEXP '^ *virtual port\$' LIMIT 1"; } unset($result); $result = usePreparedSelectBlade($query); $resultarray = $result->fetchAll(PDO::FETCH_ASSOC); if ($resultarray) { $nictypeid = $resultarray[0]['id']; } // Remove newline from ip $ip = str_replace("\n", "", $ip); // Check to se if the interface has an ip assigned $query = "SELECT object_id FROM IPv4Allocation where object_id={$newmachine} and name=\"{$nics[$i]}\""; unset($result); $result = usePreparedSelectBlade($query); $resultarray = $result->fetchAll(PDO::FETCH_ASSOC); if ($resultarray) { unset($id); $ipcheck = $resultarray; } // Check if it's been configured a port already $query = "SELECT id,iif_id FROM Port where object_id={$newmachine} and name=\"{$nics[$i]}\""; unset($result); $result = usePreparedSelectBlade($query); $resultarray = $result->fetchAll(PDO::FETCH_ASSOC); if ($resultarray) { $portid = $resultarray[0]['id']; unset($id); $portcheck = $resultarray; } // Add/update port // 2011-08-31 <*****@*****.**> // * Don't touch already existing complex ports if ($resultarray[0]['type'] != 9) { if (count($portcheck) == 1) { commitUpdatePort($newmachine, $portid, $nics[$i], $nictypeid, "Ethernet port", "{$mac}", NULL); } else { commitAddPort($object_id = $newmachine, $nics[$i], $nictypeid, 'Ethernet port', "{$mac}"); } } else { //We've got a complex port, don't touch it, it raises an error with 'Database error: foreign key violation' } if (count($ipcheck) == 1) { if ($ip) { updateAddress(ip_parse($ip), $newmachine, $nics[$i], 'regular'); } } else { if ($ip) { bindIpToObject(ip_parse($ip), $newmachine, $nics[$i], 'regular'); } } unset($portcheck); unset($ipcheck); unset($ip); unset($mac); } } //uncomment to start using auto tags //addTagToObject($facter, $newmachine); return buildRedirectURL(); }