} $type = "hostgroup"; $title = "Hostgroup"; } } } } } if (isset($_POST['request'])) { if ($_POST['request'] == "add_dependency") { // Error checking if (trim($_POST['name']) == '') { $error = "Dependency name cannot be blank."; } else { // Creating dependency. $dependency = new NagiosDependency(); switch ($type) { case 'host': $dependency->setNagiosHost($tempSource); break; case 'service': $dependency->setNagiosService($tempSource); break; case 'hostgroup': $dependency->setNagiosHostgroup($tempSource); break; } $dependency->setName($_POST['name']); $dependency->save(); header("Location: dependency.php?id= " . $dependency->getId()); exit;
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."); }
/** * 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 NagiosDependency $value A NagiosDependency object. * @param string $key (optional) key to use for instance map (for performance boost if key was already calculated externally). */ public static function addInstanceToPool(NagiosDependency $obj, $key = null) { if (Propel::isInstancePoolingEnabled()) { if ($key === null) { $key = (string) $obj->getId(); } // if key === null self::$instances[$key] = $obj; } }
/** * Declares an association between this object and a NagiosDependency object. * * @param NagiosDependency $v * @return NagiosDependencyTarget The current object (for fluent API support) * @throws PropelException */ public function setNagiosDependency(NagiosDependency $v = null) { if ($v === null) { $this->setDependency(NULL); } else { $this->setDependency($v->getId()); } $this->aNagiosDependency = $v; // Add binding for other direction of this n:n relationship. // If this object has already been added to the NagiosDependency object, it will not be re-added. if ($v !== null) { $v->addNagiosDependencyTarget($this); } return $this; }
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 if (isset($values['name'])) { // We are a template $job->addNotice("Saving internal host dependency template: " . $values['name'][0]['value']); NagiosHostDependencyImporter::saveTemplate($values['name'][0]['value'], $segment); return true; } 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; } } } // Okay, we first iterate through any possible dependent_host_name's if (isset($values['dependent_host_name'])) { $host_names = explode(",", $values['dependent_host_name'][0]['value']); foreach ($host_names as $host_name) { $dependency = new NagiosDependency(); $service = NagiosServicePeer::getByHostAndDescription($host_name, $values['dependent_service_description'][0]['value']); if (!$service) { return false; } $dependency->setNagiosService($service); $ret = $this->__process($dependency); if (!$ret) { return false; } $ret = $this->__addTargets($dependency); if (!$ret) { return false; } // Need to give it a temp name $dependency->save(); $dependency->setName("Imported Dependency #" . $dependency->getId()); $dependency->save(); $dependency->clearAllReferences(true); $service->clearAllReferences(true); $job->addNotice("NagiosServiceDependencyImporter finished importing Service Dependency for " . $host_name); } } if (isset($values['dependent_hostgroup_name'])) { $hostgroup_names = explode(",", $values['dependent_hostgroup_name'][0]['value']); foreach ($hostgroup_names as $hostgroup_name) { $dependency = new NagiosDependency(); $service = NagiosServicePeer::getByHostgroupAndDescription($hostgroup_name, $values['dependent_service_description'][0]['value']); if (!$service) { return false; } $dependency->setNagiosService($service); $ret = $this->__process($dependency); if (!$ret) { return false; } $ret = $this->__addTargets($dependency); if (!$ret) { return false; } $dependency->save(); $dependency->setName("Imported Dependency #" . $dependency->getId()); $dependency->save(); $dependency->clearAllReferences(true); $service->clearAllReferences(true); $job->addNotice("NagiosServiceDependencyImporter finished importing Service Dependency for hostgroup " . $hostgroup_name); } } return true; }