/** * Declares an association between this object and a NagiosHost object. * * @param NagiosHost $v * @return NagiosEscalation The current object (for fluent API support) * @throws PropelException */ public function setNagiosHost(NagiosHost $v = null) { if ($v === null) { $this->setHost(NULL); } else { $this->setHost($v->getId()); } $this->aNagiosHost = $v; // Add binding for other direction of this n:n relationship. // If this object has already been added to the NagiosHost object, it will not be re-added. if ($v !== null) { $v->addNagiosEscalation($this); } return $this; }
if (isset($_POST['request']) && $_POST['request'] == 'add_host') { // Check for pre-existing host template with same name 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();
private function importHost($hostData) { $job = $this->getEngine()->getJob(); // check to see if we have a host by that name if (NagiosHostPeer::getByName($hostData['host_name'])) { $job->addNotice("Fruity Host Importer: Host " . $hostData['host_name'] . " already exists. Aborting it's import."); return true; } $newHost = new NagiosHost(); $newHost->setName($hostData['host_name']); // Check to see if we need the template if (!empty($hostData['use_template_id'])) { $name = $this->getHostTemplateNameById($hostData['use_template_id'], $this->dbConn); if (!$name) { $job->addNotice("Fruity Host Importer: Could not find template with id: " . $hostData['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) { $job->addNotice("Fruity Host Importer: Could not find a template in the system with the name of: " . $name . ". Aborting it's import."); return false; } else { // Create a new inheritance relationship $inheritance = new NagiosHostTemplateInheritance(); $inheritance->setNagiosHostTemplateRelatedByTargetTemplate($template); $inheritance->setNagiosHost($newHost); try { $inheritance->save(); } catch (Exception $e) { $job->addNotice("Fruity Host Importer: Cannot add inheritance from " . $template->getName() . " to " . $newHost->getName()); } } } } // Okay, start 'er up! foreach ($hostData as $key => $val) { unset($name); if ($key == "host_id" || $key == "use_template_id" || $key == "host_name") { continue; } if ($key == "parents") { // we're gonna do parents after this continue; } 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 == "retry_check_interval") { $key = "retry_interval"; } if ($key == "check_command") { $name = $this->getCommandNameById($val); if ($name) { $command = NagiosCommandPeer::getByName($name); if ($command) { $newHost->setCheckCommand($command->getId()); } } continue; } if ($key == "check_period") { $name = $this->getTimeperiodNameById($val); if ($name) { $timeperiod = NagiosTimeperiodPeer::getByName($name); if ($timeperiod) { $newHost->setCheckPeriod($timeperiod->getId()); } } continue; } if ($key == "event_handler") { $name = $this->getCommandNameById($val); if ($name) { $command = NagiosCommandPeer::getByName($name); if ($command) { $newHost->setEventHandler($command->getId()); } } continue; } if ($key == "notification_period") { $name = $this->getTimeperiodNameById($val); if ($name) { $timeperiod = NagiosTimeperiodPeer::getByName($name); if ($timeperiod) { $newHost->setNotificationPeriod($timeperiod->getId()); } } continue; } try { $name = NagiosHostPeer::translateFieldName($key, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_PHPNAME); } catch (Exception $e) { $job->addNotice("Fruity Host Importer: Was unable to store unsupported value: " . $key); } if (!empty($name)) { $method = "set" . $name; $newHost->{$method}($val); } } $newHost->save(); $job->addNotice("FruityHostImporter: Imported new host: " . $newHost->getName()); $this->totalImported++; return true; }
$c->setIgnoreCase(true); $host = AutodiscoveryDevicePeer::doSelectOne($c); if ($host->getId() == $device->getId()) { 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)) {
public function import() { $job = $this->getEngine()->getJob(); $config = $this->getEngine()->getConfig(); $segment = $this->getSegment(); $values = $segment->getValues(); $fileName = $segment->getFilename(); // We need to determine if we are a template $isTemplate = false; if (isset($values['name'])) { $obj = new NagiosHostTemplate(); $isTemplate = true; } else { $obj = new NagiosHost(); $isTemplate = false; } foreach ($values as $key => &$entries) { if ($key == "check_command") { foreach ($entries as $entry) { if (empty($newEntry)) { $newEntry = $entry; } else { $newEntry['value'] .= "," . $entry['value']; } } $entries = array($newEntry); } } foreach ($values as $key => $entries) { foreach ($entries as $entry) { // Skips $value = $entry['value']; $lineNum = $entry['line']; if ($key == 'register') { continue; } if ($key == 'use') { // We need to add a template inheritance $obj->addTemplateInheritance($entry['value']); continue; } if ($key == 'check_command') { $options = explode("!", $entry['value']); // Okay, first we add the check command parameter. $obj->setCheckCommandByName($options[0]); if (count($options > 0)) { for ($counter = 1; $counter < count($options); $counter++) { $obj->addCheckCommandParameter($options[$counter]); } } continue; } if ($key == 'flap_detection_options') { $options = explode(",", $entry['value']); foreach ($options as $option) { switch (strtolower(trim($option))) { case 'o': $obj->setFlapDetectionOnUp(true); break; case 'd': $obj->setFlapDetectionOnDown(true); break; case 'u': $obj->setFlapDetectionOnUnreachable(true); break; } } continue; } if ($key == 'stalking_options') { $options = explode(",", $entry['value']); foreach ($options as $option) { switch (strtolower(trim($option))) { case 'o': $obj->setStalkingOnUp(true); break; case 'd': $obj->setStalkingOnDown(true); break; case 'u': $obj->setStalkingOnUnreachable(true); break; } } continue; } if ($key == 'notification_options') { $options = explode(",", $entry['value']); foreach ($options as $option) { switch (strtolower(trim($option))) { case 'd': $obj->setNotificationOnDown(true); break; case 'u': $obj->setNotificationOnUnreachable(true); break; case 'r': $obj->setNotificationOnRecovery(true); break; case 'f': $obj->setNotificationOnFlapping(true); break; case 's': $obj->setNotificationOnScheduledDowntime(true); break; } } continue; } // Okay, let's check that the method DOES exist if (!method_exists($obj, $this->fieldMethods[$key])) { $job->addError("Method " . $this->fieldMethods[$key] . " does not exist for variable: " . $key . " on line " . $lineNum . " in file " . $fileName); if (!$config->getVar('continue_error')) { return false; } } else { call_user_method($this->fieldMethods[$key], $obj, $value); } } } $obj->save(); $obj->clearAllReferences(true); if ($isTemplate) { $job->addNotice("NagiosHostImporter finished importing host template: " . $obj->getName()); } else { $job->addNotice("NagiosHostImporter finished importing host: " . $obj->getName()); } return true; }
/** * 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 NagiosHost $value A NagiosHost object. * @param string $key (optional) key to use for instance map (for performance boost if key was already calculated externally). */ public static function addInstanceToPool(NagiosHost $obj, $key = null) { if (Propel::isInstancePoolingEnabled()) { if ($key === null) { $key = (string) $obj->getId(); } // if key === null self::$instances[$key] = $obj; } }