public function addObject(\yourCMDB\entities\CmdbObject $object) { //get object information $objectType = $object->getType(); $objectId = $object->getId(); $objectStatus = $object->getStatus(); //get values of ExportVariables dummy1-dummy4 $dummy1Val = "null"; $dummy2Val = "null"; $dummy3Val = "null"; $dummy4Val = "null"; $dummy1 = $this->variables->getVariable("dummy1"); $dummy2 = $this->variables->getVariable("dummy2"); $dummy3 = $this->variables->getVariable("dummy3"); $dummy4 = $this->variables->getVariable("dummy4"); if ($dummy1 != null) { $dummy1Val = $dummy1->getValue($object); } if ($dummy2 != null) { $dummy2Val = $dummy2->getValue($object); } if ($dummy3 != null) { $dummy3Val = $dummy3->getValue($object); } if ($dummy4 != null) { $dummy4Val = $dummy4->getValue($object); } //print object information and variable values echo "exporting object {$objectId} \tof type {$objectType} \tand status {$objectStatus}. "; echo "values of variables dummy1-4: {$dummy1Val}, {$dummy2Val}, {$dummy3Val}, {$dummy4Val}.\n"; }
/** * Returns the value of variable for the given CmdbObject * @param CmdbObject $object the object to get the value */ public function getValue(\yourCMDB\entities\CmdbObject $object) { //get ObjectController $objectController = ObjectController::create(); //get object type config $config = CmdbConfig::create(); $configObjecttype = $config->getObjectTypeConfig(); $value = $this->defaultValue; //if there is a configuration for that object type //use the content of the specified field as value $objectType = $object->getType(); if (isset($this->fieldValue[$objectType]['name'])) { $fieldname = $this->fieldValue[$objectType]['name']; $value = $object->getFieldvalue($fieldname); //check if field is an object reference (type objectref) if (preg_match('/objectref-.*/', $configObjecttype->getFieldType($objectType, $fieldname)) == 1) { try { //get referenced object $refObject = $objectController->getObject($value, "yourCMDB-exporter"); //get value of referenced field if configured if ($this->fieldValue[$objectType]['refobjectfield'] != "") { $refFieldname = $this->fieldValue[$objectType]['refobjectfield']; $value = $refObject->getFieldvalue($refFieldname); } } catch (Exception $e) { } } } //return the value return $value; }
public function addObject(\yourCMDB\entities\CmdbObject $object) { //node foreign Id $nodeForeignId = $object->getId(); //node services $nodeServices = $this->services; //node label $nodeLabel = "undefined"; if ($this->variables->getVariable("nodelabel") != null) { $nodeLabel = $this->formatField($this->variables->getVariable("nodelabel")->getValue($object), self::$nodelabelLength); } //node interfaces $nodeInterfaces = array(); if ($this->variables->getVariable("ip") != null) { $nodeInterfaces = array($this->variables->getVariable("ip")->getValue($object)); } //node monitoring of further IPs if ($this->variables->getVariable("furtherIps") != null) { $nodeFurtherInterfaces = explode(";", $this->variables->getVariable("furtherIps")->getValue($object)); $nodeInterfaces = array_merge($nodeInterfaces, $nodeFurtherInterfaces); } //remove invalid ip interfaces for ($i = 0; $i < count($nodeInterfaces); $i++) { if (filter_var($nodeInterfaces[$i], FILTER_VALIDATE_IP) === FALSE) { unset($nodeInterfaces[$i]); } } //remove duplicates ips $nodeInterfaces = array_unique($nodeInterfaces); //define asset fields and categories for node $nodeAssets = array(); $nodeCategories = array(); //walk through all variables foreach ($this->variables->getVariableNames() as $variableName) { //check if it is an "asset_" variable if (preg_match('/^asset_(.*)$/', $variableName, $matches) == 1) { //check if the asset field exists $fieldname = $matches[1]; if (isset(self::$assetfields[$fieldname])) { $fieldvalue = $this->variables->getVariable($variableName)->getValue($object); $fieldlength = self::$assetfields[$fieldname]; $nodeAssets[$fieldname] = $this->formatField($fieldvalue, $fieldlength); } } //check if it is an "category_" variable if (preg_match('/^category_(.*)$/', $variableName, $matches) == 1) { $categoryname = $matches[1]; //check if it is an unnamed category (example: "category_1") if (preg_match('/^[\\d]+$/', $categoryname) === 1) { $nodeCategories[] = $this->formatField($this->variables->getVariable($variableName)->getValue($object), self::$categoryLength); } else { $nodeCategories[] = $this->formatField($categoryname . "-" . $this->variables->getVariable($variableName)->getValue($object), self::$categoryLength); } } } //add nodes to requisition $xml = $this->addNode($nodeLabel, $nodeForeignId, $nodeInterfaces, $nodeServices, $nodeCategories, $nodeAssets); $this->requisitionXml .= $xml; }
/** * Returns the CmdbLogEntry for the last change of the given object * @param CmdbObject $object CmdbObject for getting the log entries * @param string $user name of the user that wants to get the objects * @return CmdbObjectLogEntry CmdbObjectLogEntry object or null if nothing was found */ public function getChangedLogEntry($object, $user) { //create QueryBuilder $queryBuilder = $this->entityManager->createQueryBuilder(); //create query $queryBuilder->select("l"); $queryBuilder->from("yourCMDB:CmdbObjectLogEntry", "l"); $queryBuilder->andWhere("IDENTITY(l.object) = ?1"); $queryBuilder->setParameter(1, $object->getId()); $queryBuilder->andWhere("l.action != ?2"); $queryBuilder->setParameter(2, "create"); $queryBuilder->orderBy("l.timestamp", "DESC"); //get results $query = $queryBuilder->getQuery(); $logEntries = $query->getResult(); //generate output $logEntry = null; if ($logEntries != null) { $logEntry = $logEntries[0]; } //return return $logEntry; }
/** * Returns all CmdbObjectLinks for an object * @param CmdbObject $object object * @param string $user name of the user that wants to get the values * @returns CmdbObjectLink[] Array with CmdbObjectLinks */ public function getObjectLinks($object, $user) { //create QueryBuilder $queryBuilder = $this->entityManager->createQueryBuilder(); //create query $queryBuilder->select("l"); $queryBuilder->from("yourCMDB:CmdbObjectLink", "l"); $queryBuilder->andWhere("(IDENTITY(l.objectA) = ?1 OR IDENTITY(l.objectB) = ?1)"); $queryBuilder->setParameter(1, $object->getId()); //get results $query = $queryBuilder->getQuery(); $objectLinks = $query->getResult(); //return return $objectLinks; }