if ($lilac->host_exists($_POST['host_manage']['host_name'])) { $error = "A host with that name already exists!"; } else { // Field Error Checking if (count($_POST['host_manage'])) { foreach ($_POST['host_manage'] as $tempVariable) { $tempVariable = trim($tempVariable); } } if ($_POST['host_manage']['host_name'] == '' || $_POST['host_manage']['alias'] == '' || $_POST['host_manage']['address'] == '') { $error = "Fields shown are required and cannot be left blank."; } else { // All is well for error checking, add the host into the db. $tempHost = new NagiosHost(); $tempHost->setName($_POST['host_manage']['host_name']); $tempHost->setAlias($_POST['host_manage']['alias']); if (isset($_GET['parent_id'])) { // Get the host by that parent_id $host = NagiosHostPeer::retrieveByPk($_GET['parent_id']); if ($host) { // valid host, add parent $tempHost->addParentByName($host->getName()); } } $tempHost->setAddress($_POST['host_manage']['address']); if (isset($_POST['host_manage']['display_name'])) { $tempHost->setDisplayName($_POST['host_manage']['display_name']); } $tempHost->save(); header("Location: hosts.php?id=" . $tempHost->getId()); die;
unset($host); } } if (!empty($host)) { $error = "A host already exists with the name of " . $device->getName() . ". Change the device's name before importing."; } } if (empty($error)) { $totalSuccess = 0; // Okay, no errors, let's create our hosts! foreach ($_POST['selectedDevices'] as $deviceId) { $device = AutodiscoveryDevicePeer::retrieveByPK($deviceId); $tempHost = new NagiosHost(); $tempHost->setAddress($device->getAddress()); $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);