/** * Declares an association between this object and a NagiosHostTemplate object. * * @param NagiosHostTemplate $v * @return NagiosEscalation The current object (for fluent API support) * @throws PropelException */ public function setNagiosHostTemplate(NagiosHostTemplate $v = null) { if ($v === null) { $this->setHostTemplate(NULL); } else { $this->setHostTemplate($v->getId()); } $this->aNagiosHostTemplate = $v; // Add binding for other direction of this n:n relationship. // If this object has already been added to the NagiosHostTemplate object, it will not be re-added. if ($v !== null) { $v->addNagiosEscalation($this); } return $this; }
private function importHostTemplate($templateData) { $job = $this->getEngine()->getJob(); // check to see if we have a template by that name if (NagiosHostTemplatePeer::getByName($templateData['template_name'])) { $job->addNotice("Fruity Host Template Importer: Template " . $templateData['template_name'] . " already exists. Aborting it's import."); return true; } $newTemplate = new NagiosHostTemplate(); $newTemplate->setName($templateData['template_name']); // Check to see if we need the template if (!empty($templateData['use_template_id'])) { $name = $this->getHostTemplateNameById($templateData['use_template_id'], $this->dbConn); if (!$name) { $job->addNotice("Fruity Host Template Importer: Could not find template with id: " . $templateData['use_template_id'] . ". Aborting it's import."); return false; } else { // Okay, we got the name, does this template exist? $template = NagiosHostTemplatePeer::getByName($name); if (!$template) { return false; } else { // Create a new inheritance relationship $inheritance = new NagiosHostTemplateInheritance(); $inheritance->setNagiosHostTemplateRelatedByTargetTemplate($template); $inheritance->setNagiosHostTemplateRelatedBySourceTemplate($newTemplate); try { $inheritance->save(); } catch (Exception $e) { $job->addNotice("Fruity Host Template Importer: Cannot add inheritance from " . $template->getName() . " to " . $newTemplate->getName()); } } } } // Okay, start 'er up! foreach ($templateData as $key => $val) { unset($name); if ($key == "host_template_id" || $key == "use_template_id" || $key == "template_name") { continue; } if ($key == "template_description") { $key = "description"; } if ($key == "notification_options_down") { $key = "notification_on_down"; } if ($key == "notification_options_unreachable") { $key = "notification_on_unreachable"; } if ($key == "notification_options_recovery") { $key = "notification_on_recovery"; } if ($key == "notification_options_flapping") { $key = "notification_on_flapping"; } if ($key == "stalking_options_up") { $key = "stalking_on_up"; } if ($key == "stalking_options_down") { $key = "stalking_on_down"; } if ($key == "stalking_options_unreachable") { $key = "stalking_on_unreachable"; } if ($key == "max_check_attempts") { $key = "maximum_check_attempts"; } if ($key == "check_command") { $name = $this->getCommandNameById($val); if ($name) { $command = NagiosCommandPeer::getByName($name); if ($command) { $newTemplate->setCheckCommand($command->getId()); } } continue; } if ($key == "check_period") { $name = $this->getTimeperiodNameById($val); if ($name) { $timeperiod = NagiosTimeperiodPeer::getByName($name); if ($timeperiod) { $newTemplate->setCheckPeriod($timeperiod->getId()); } } continue; } if ($key == "event_handler") { $name = $this->getCommandNameById($val); if ($name) { $command = NagiosCommandPeer::getByName($name); if ($command) { $newTemplate->setEventHandler($command->getId()); } } continue; } if ($key == "notification_period") { $name = $this->getTimeperiodNameById($val); if ($name) { $timeperiod = NagiosTimeperiodPeer::getByName($name); if ($timeperiod) { $newTemplate->setNotificationPeriod($timeperiod->getId()); } } continue; } try { $name = NagiosHostTemplatePeer::translateFieldName($key, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_PHPNAME); } catch (Exception $e) { $job->addNotice("Fruity Host Template Importer: Was unable to store unsupported value: " . $key); } if (!empty($name)) { $method = "set" . $name; $newTemplate->{$method}($val); } } $newTemplate->save(); $this->totalImported++; return true; }
* Provides interface to maintain host templates * */ include_once 'includes/config.inc'; if (isset($_POST['request'])) { if ($_POST['request'] == 'add_host_template') { // Check for pre-existing host template with same name if ($lilac->host_template_exists($_POST['template_name'])) { $error = "A host template with that name already exists!"; } else { // Field Error Checking if ($_POST['template_name'] == '' || $_POST['template_description'] == '') { $addError = 1; $error = "Fields shown are required and cannot be left blank."; } else { $template = new NagiosHostTemplate(); $template->setName($_POST['template_name']); $template->setDescription($_POST['template_description']); $template->save(); header("Location: host_template.php?id=" . $template->getId()); die; } } } } print_header("Host Template Editor"); print_window_header("Add Host Template", "100%"); ?> <form name="host_template_add_form" method="post" action="add_host_template.php"> <input type="hidden" name="request" value="add_host_template" /> <?php
/** * Adds an object to the instance pool. * * Propel keeps cached copies of objects in an instance pool when they are retrieved * from the database. In some cases -- especially when you override doSelect*() * methods in your stub classes -- you may need to explicitly add objects * to the cache in order to ensure that the same objects are always returned by doSelect*() * and retrieveByPK*() calls. * * @param NagiosHostTemplate $value A NagiosHostTemplate object. * @param string $key (optional) key to use for instance map (for performance boost if key was already calculated externally). */ public static function addInstanceToPool(NagiosHostTemplate $obj, $key = null) { if (Propel::isInstancePoolingEnabled()) { if ($key === null) { $key = (string) $obj->getId(); } // if key === null self::$instances[$key] = $obj; } }