$tempHost->setName($device->getName()); $tempHost->setAlias($device->getDescription()); $tempHost->save(); // Now assign a template, if wanted $template = $device->getNagiosHostTemplate(); if (!empty($template)) { $inheritance = new NagiosHostTemplateInheritance(); $inheritance->setNagiosHost($tempHost); $inheritance->setNagiosHostTemplateRelatedByTargetTemplate($template); $inheritance->save(); } // Now parent $parent = $device->getNagiosHost(); if (!empty($parent)) { $parentRelationship = new NagiosHostParent(); $parentRelationship->setNagiosHostRelatedByChildHost($tempHost); $parentRelationship->setNagiosHostRelatedByParentHost($parent); $parentRelationship->save(); } $totalSuccess++; $device->delete(); } $success = $totalSuccess . " Device(s) Imported."; } } } } } print_header("AutoDiscovery"); if (isset($autodiscoveryJob)) { ?>
function addParentByName($name) { $c = new Criteria(); $c->add(NagiosHostPeer::NAME, $name); $c->setIgnoreCase(true); $host = NagiosHostPeer::doSelectOne($c); if (!$host) { return false; } // Okay, let's first see if there's a parent relationship around $id = $this->getId(); if (!empty($id)) { $c = new Criteria(); $c->add(NagiosHostParentPeer::CHILD_HOST, $this->getId()); $c->add(NagiosHostParentPeer::PARENT_HOST, $host->getId()); $relationship = NagiosHostParentPeer::doSelectOne($c); if ($relationship) { return false; } } // Okay, relationship doesn't exist, let's add it! $relationship = new NagiosHostParent(); $relationship->setNagiosHostRelatedByChildHost($this); $relationship->setNagiosHostRelatedByParentHost($host); $relationship->save(); return true; }