public function save(PropelPDO $con = null)
 {
     if (NagiosHostTemplateInheritance::isCircular($this->getTargetTemplate(), $this->getSourceTemplate())) {
         throw new Exception("Adding that inheritance would create a circular chain.");
     } else {
         parent::save($con);
         // Okay, we've saved
     }
 }
示例#2
0
 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;
 }
示例#3
0
文件: hosts.php 项目: Evolix/lilac
     }
 } else {
     if ($_POST['request'] == "add_template_command") {
         $template = NagiosHostTemplatePeer::retrieveByPK($_POST['hostmanage']['template_add']['template_id']);
         if (!$template) {
             $error = "That host template is not found.";
         } else {
             // We need to get the count of templates already inherited
             $templateList = $host->getNagiosHostTemplateInheritances();
             foreach ($templateList as $tempTemplate) {
                 if ($tempTemplate->getId() == $_POST['hostmanage']['template_add']['template_id']) {
                     $error = "That template already exists in the inheritance chain.";
                 }
             }
             if (empty($error)) {
                 $newInheritance = new NagiosHostTemplateInheritance();
                 $newInheritance->setNagiosHost($host);
                 $newInheritance->setNagiosHostTemplateRelatedByTargetTemplate($template);
                 $newInheritance->setOrder(count($templateList));
                 try {
                     $newInheritance->save();
                     $success = "Template added to inheritance chain.";
                 } catch (Exception $e) {
                     $error = $e->getMessage();
                 }
             }
         }
     } else {
         if ($_POST['request'] == 'host_template_modify_checks') {
             if (count($modifiedData)) {
                 foreach ($modifiedData as $tempVariable) {
示例#4
0
 function addTemplateInheritance($name)
 {
     // First get the template by name
     $template = NagiosHostTemplatePeer::getByName($name);
     if (!$template) {
         return false;
     }
     // Check to see if inheritance already exists
     $id = $this->getId();
     if (!empty($id)) {
         $c = new Criteria();
         $c->add(NagiosHostTemplateInheritancePeer::SOURCE_TEMPLATE, $this->getId());
         $c->add(NagiosHostTemplateInheritancePeer::TARGET_TEMPLATE, $template->getId());
         $relationship = NagiosHostTemplateInheritancePeer::doSelectOne($c);
         if ($relationship) {
             return false;
         }
     }
     // Okay, create new one
     $relationship = new NagiosHostTemplateInheritance();
     $relationship->setNagiosHostTemplateRelatedBySourceTemplate($this);
     $relationship->setNagiosHostTemplateRelatedByTargetTemplate($template);
     $relationship->save();
     return true;
 }
示例#5
0
     }
 }
 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);
             $parentRelationship->save();
         }
         $totalSuccess++;
         $device->delete();
     }
 /**
  * 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      NagiosHostTemplateInheritance $value A NagiosHostTemplateInheritance object.
  * @param      string $key (optional) key to use for instance map (for performance boost if key was already calculated externally).
  */
 public static function addInstanceToPool(NagiosHostTemplateInheritance $obj, $key = null)
 {
     if (Propel::isInstancePoolingEnabled()) {
         if ($key === null) {
             $key = (string) $obj->getId();
         }
         // if key === null
         self::$instances[$key] = $obj;
     }
 }