コード例 #1
0
 public function import()
 {
     $engine = $this->getEngine();
     $job = $engine->getJob();
     $job->addNotice("FruityDependencyImporter beginning to import Dependency Configuration.");
     foreach ($this->dbConn->query("SELECT * FROM nagios_dependencies", PDO::FETCH_ASSOC) as $dependency) {
         $newDependency = new NagiosDependency();
         if (!empty($dependency['service_id'])) {
             // This is a service dependency
             $lilacService = $this->getLilacServiceById($dependency['service_id']);
             if (!$lilacService) {
                 $job->addNotice("Fruity Dependency Importer: Failed to get Lilac service with an id matching: " . $dependency['service_id']);
                 return true;
             }
             $newDependency->setService($lilacService->getId());
             // Create Target
             $targetLilacService = $this->getLilacServiceById($dependency['target_service_id']);
             if (!$targetLilacService) {
                 $job->addNotice("Fruity Dependency Importer: Failed to get Lilac service with an id matching: " . $dependency['target_service_id']);
                 return true;
             }
             $target = new NagiosDependencyTarget();
             $target->setNagiosDependency($newDependency);
             $target->setTargetService($targetLilacService->getId());
             $target->save();
         } else {
             if (!empty($dependency['host_id'])) {
                 // This is a host dependency
                 $hostName = $this->getHostNameById($dependency['host_id']);
                 $host = NagiosHostPeer::getByName($hostName);
                 if (!$host) {
                     $job->addNotice("Fruity Dependency Importer: Failed to get Lilac host with an name matching: " . $hostName);
                     return true;
                 }
                 $newDependency->setHost($host->getId());
                 // Create Target
                 $hostName = $this->getHostNameById($dependency['target_host_id']);
                 $host = NagiosHostPeer::getByName($hostName);
                 if (!$host) {
                     $job->addNotice("Fruity Dependency Importer: Failed to get Lilac host with an name matching: " . $hostName);
                     return true;
                 }
                 $target = new NagiosDependencyTarget();
                 $target->setNagiosDependency($newDependency);
                 $target->setTargetHost($host->getId());
                 $target->save();
             } else {
                 if (!empty($dependency['service_template_id'])) {
                     // This is a service template dependency
                     $templateName = $this->getServiceTemplateNameById($dependency['service_template_id']);
                     $template = NagiosServiceTemplatePeer::getByName($templateName);
                     if (!$template) {
                         $job->addNotice("Fruity Dependency Importer: Failed to get Lilac service template with  name matching: " . $templateName);
                         return true;
                     }
                     $newDependency->setServiceTemplate($template->getId());
                     // Create Target
                     $targetLilacService = $this->getLilacServiceById($dependency['target_service_id']);
                     if (!$targetLilacService) {
                         $job->addNotice("Fruity Dependency Importer: Failed to get Lilac service with an id matching: " . $dependency['target_service_id']);
                         return true;
                     }
                     $target = new NagiosDependencyTarget();
                     $target->setNagiosDependency($newDependency);
                     $target->setTargetService($targetLilacService->getId());
                     $target->save();
                 } else {
                     if (!empty($dependency['host_template_id'])) {
                         // This is for a host template dependency
                         $templateName = $this->getHostTemplateNameById($dependency['host_template_id']);
                         $template = NagiosHostTemplatePeer::getByName($templateName);
                         if (!$template) {
                             $job->addNotice("Fruity Dependency Importer: Failed to get Lilac host template with  name matching: " . $templateName);
                             return true;
                         }
                         $newDependency->setHostTemplate($template->getId());
                         $hostName = $this->getHostNameById($dependency['target_host_id']);
                         $host = NagiosHostPeer::getByName($hostName);
                         if (!$host) {
                             $job->addNotice("Fruity Dependency Importer: Failed to get Lilac host with an name matching: " . $hostName);
                             return true;
                         }
                         $target = new NagiosDependencyTarget();
                         $target->setNagiosDependency($newDependency);
                         $target->setTargetHost($host->getId());
                         $target->save();
                     }
                 }
             }
         }
         foreach ($dependency as $key => $val) {
             unset($name);
             if ($key == "dependency_id" || $key == "host_id" || $key == "host_template_id" || $key == "service_template_id" || $key == "service_id" || $key == "target_service_id" || $key == "target_host_id") {
                 continue;
             }
             if ($key == "command_name") {
                 $key = "name";
             }
             if ($key == "command_line") {
                 $key = "line";
             }
             if ($key == "command_desc") {
                 $key = "description";
             }
             try {
                 $name = NagiosDependencyPeer::translateFieldName($key, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_PHPNAME);
             } catch (Exception $e) {
                 $job->addNotice("Fruity Dependency Importer: Was unable to store unsupported value: " . $key);
             }
             if (!empty($name)) {
                 $method = "set" . $name;
                 $newDependency->{$method}($val);
             }
         }
         $newDependency->save();
         $newDependency->setName("Imported Dependency #" . $newDependency->getId());
         $newDependency->save();
         $job->addNotice("FruityDependencyImporter imported dependency with id: " . $newDependency->getId());
     }
     $job->addNotice("FruityDependencyImporter finished importing Dependency Configuration.");
 }
コード例 #2
0
 /**
  * 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      NagiosDependencyTarget $value A NagiosDependencyTarget object.
  * @param      string $key (optional) key to use for instance map (for performance boost if key was already calculated externally).
  */
 public static function addInstanceToPool(NagiosDependencyTarget $obj, $key = null)
 {
     if (Propel::isInstancePoolingEnabled()) {
         if ($key === null) {
             $key = (string) $obj->getId();
         }
         // if key === null
         self::$instances[$key] = $obj;
     }
 }
コード例 #3
0
 public function __addTargets($dependency)
 {
     $job = $this->getEngine()->getJob();
     $config = $this->getEngine()->getConfig();
     $segment = $this->getSegment();
     $values = $segment->getValues();
     $fileName = $segment->getFilename();
     if (isset($values['use'])) {
         // We sure are using a template!
         // Okay, hokey multi-inheritance support for the importer
         $tempValues = $this->getTemplateValues($values['use'][0]['value']);
         // Okay, go through each
         foreach ($tempValues as $key => $val) {
             if (!isset($values[$key])) {
                 $values[$key] = $val;
             }
         }
     }
     if (isset($values['host_name'])) {
         $host_names = explode(",", $values['host_name'][0]['value']);
         foreach ($host_names as $host_name) {
             $service = NagiosServicePeer::getByHostAndDescription($host_name, $values['service_description'][0]['value']);
             if (!$service) {
                 return false;
             }
             // Create target
             $target = new NagiosDependencyTarget();
             $target->setNagiosDependency($dependency);
             $target->setNagiosHost($service->getNagiosHost());
             $target->setNagiosService($service);
             $target->save();
             $target->clearAllReferences(true);
             $service->clearAllReferences(true);
         }
     }
     if (isset($values['hostgroup_name'])) {
         $hostgroup_names = explode(",", $values['hostgroup_name'][0]['value']);
         foreach ($hostgroup_names as $hostgroup_name) {
             $service = NagiosServicePeer::getByHostgroupAndDescription($hostgroup_name, $values['service_description'][0]['value']);
             if (!$service) {
                 return false;
             }
             // Create target
             $target = new NagiosDependencyTarget();
             $target->setNagiosDependency($dependency);
             $target->setNagiosHostgroup($service->getNagiosHostgroup());
             $target->setNagiosService($service);
             $target->save();
             $target->clearAllReferences(true);
             $service->clearAllReferences(true);
         }
     }
     return true;
 }
コード例 #4
0
ファイル: dependency.php プロジェクト: Evolix/lilac
                 if (!$found) {
                     // Check inherited services
                     $inheritedServices = $host->getInheritedServices();
                     foreach ($inheritedServices as $service) {
                         if ($service->getDescription() == $_POST['service_select']) {
                             // We found it!
                             // Check for existence
                             $c = new Criteria();
                             $c->add(NagiosDependencyTargetPeer::DEPENDENCY, $dependency->getId());
                             $c->add(NagiosDependencyTargetPeer::TARGET_HOST, $host->getId());
                             $c->add(NagiosDependencyTargetPeer::TARGET_SERVICE, $service->getId());
                             $target = NagiosDependencyTargetPeer::doSelectOne($c);
                             if ($target) {
                                 $error = "That target already exists.";
                             } else {
                                 $target = new NagiosDependencyTarget();
                                 $target->setNagiosDependency($dependency);
                                 $target->setNagiosHost($host);
                                 $target->setNagiosService($service);
                                 $target->save();
                                 $success = "Created target.";
                                 $found = true;
                                 break;
                             }
                         }
                     }
                 }
             }
         }
     }
 }