public function getByName($name) { $c = new Criteria(); $c->add(NagiosHostTemplatePeer::NAME, $name); $c->setIgnoreCase(true); $template = NagiosHostTemplatePeer::doSelectOne($c); if (!$template) { return false; } return $template; }
public static function getByHostTemplateAndDescription($hostTemplateName, $description) { // First get host template $template = NagiosHostTemplatePeer::getByName($hostTemplateName); if (!$template) { return false; } $c = new Criteria(); $c->add(NagiosServicePeer::HOST_TEMPLATE, $template->getId()); $c->add(NagiosServicePeer::DESCRIPTION, $description); $c->setIgnoreCase(true); $service = NagiosServicePeer::doSelectOne($c); if (!$service) { return false; } return $service; }
private function importService($serviceData) { $job = $this->getEngine()->getJob(); $newService = new NagiosService(); // Check to see if host or host template exists first if (!empty($serviceData['host_id'])) { $hostName = $this->getHostNameById($serviceData['host_id']); if (!$hostName) { $job->addNotice("Fruity Service Importer: Failed to find host with id: " . $serviceData['host_id']); return true; } $host = NagiosHostPeer::getByName($hostName); if (!$host) { $job->addNotice("Fruity Service Importer: Failed to find host with name: " . $hostName); return true; } $newService->setHost($host->getId()); } else { if (!empty($serviceData['host_template_id'])) { $hostTemplateName = $this->getHostTemplateNameById($serviceData['host_template_id']); if (!$hostTemplateName) { $job->addNotice("Fruity Service Importer: Failed to find host template with id: " . $serviceData['host_template_id']); return true; } $hostTemplate = NagiosHostTemplatePeer::getByName($hostTemplateName); if (!$hostTemplate) { $job->addNotice("Fruity Service Importer: Failed to find host template with name: " . $hostTemplateName); return true; } $newService->setHostTemplate($hostTemplate->getId()); } else { if (!empty($serviceData['hostgroup_id'])) { $hostgroupName = $this->getHostGroupNameById($serviceData['hostgroup_id']); if (!$hostgroupName) { $job->addNotice("Fruity Service Importer: Failed to find host group with id: " . $serviceData['host_template_id']); return true; } $hostgroup = NagiosHostGroupPeer::getByName($hostgroupName); if (!$hostgroup) { $job->addNotice("Fruity Service Importer: Failed to find host group with name: " . $hostGroupName); return true; } $newService->setHostgroup($hostgroup->getId()); } } } // Check to see if we need the template if (!empty($serviceData['use_template_id'])) { $name = $this->getServiceTemplateNameById($serviceData['use_template_id'], $this->dbConn); if (!$name) { $job->addNotice("Fruity Service Importer: Could not find template with id: " . $serviceData['use_template_id'] . ". Aborting it's import."); return false; } else { // Okay, we got the name, does this template exist? $template = NagiosServiceTemplatePeer::getByName($name); if (!$template) { return false; } else { // Create a new inheritance relationship $inheritance = new NagiosServiceTemplateInheritance(); $inheritance->setNagiosServiceTemplateRelatedByTargetTemplate($template); $inheritance->setNagiosService($newService); try { $inheritance->save(); } catch (Exception $e) { $job->addNotice("Fruity Service Template Importer: Cannot add inheritance from " . $template->getName() . " to " . $newService->getName()); } } } } // Okay, start 'er up! foreach ($serviceData as $key => $val) { unset($name); if ($key == "service_template_id" || $key == "use_template_id" || $key == "template_name" || $key == "host_id" || $key == "hostgroup_id" || $key == "host_template_id" || $key == "service_id") { continue; } if ($key == "service_description") { $key = "description"; } if ($key == "notification_options_warning") { $key = "notification_on_warning"; } if ($key == "notification_options_unknown") { $key = "notification_on_unknown"; } if ($key == "notification_options_critical") { $key = "notification_on_critical"; } if ($key == "notification_options_recovery") { $key = "notification_on_recovery"; } if ($key == "notification_options_flapping") { $key = "notification_on_flapping"; } if ($key == "stalking_options_warning") { $key = "stalking_on_warning"; } if ($key == "stalking_options_unknown") { $key = "stalking_on_unknown"; } if ($key == "stalking_options_critical") { $key = "stalking_on_critical"; } if ($key == "stalking_options_ok") { $key = "stalking_on_ok"; } 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) { $newService->setCheckCommand($command->getId()); } } continue; } if ($key == "check_period") { $name = $this->getTimeperiodNameById($val); if ($name) { $timeperiod = NagiosTimeperiodPeer::getByName($name); if ($timeperiod) { $newService->setCheckPeriod($timeperiod->getId()); } } continue; } if ($key == "event_handler") { $name = $this->getCommandNameById($val); if ($name) { $command = NagiosCommandPeer::getByName($name); if ($command) { $newService->setEventHandler($command->getId()); } } continue; } if ($key == "notification_period") { $name = $this->getTimeperiodNameById($val); if ($name) { $timeperiod = NagiosTimeperiodPeer::getByName($name); if ($timeperiod) { $newService->setNotificationPeriod($timeperiod->getId()); } } continue; } try { $name = NagiosServiceTemplatePeer::translateFieldName($key, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_PHPNAME); } catch (Exception $e) { $job->addNotice("Fruity Service Importer: Was unable to store unsupported value: " . $key); } if (!empty($name)) { $method = "set" . $name; $newService->{$method}($val); } } $job->addNotice("Fruity Service Importer: Saved service: " . $newService->getDescription() . " on " . $newService->getOwnerDescription()); $newService->save(); $this->totalImported++; return true; }
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; }
print "No job id provided.\n"; exit(10); } $autodiscoveryJob->addNotice("Starting Background Auto Discovery Process for Job: " . $autodiscoveryJob->getName()); $autodiscoveryJob->setStatus("Running"); $autodiscoveryJob->setStatusCode(AutodiscoveryJob::STATUS_RUNNING); $autodiscoveryJob->save(); $autodiscoveryJob->addNotice("Removing old devices found in this job."); $devices = $autodiscoveryJob->getAutodiscoveryDevices(); foreach ($devices as $device) { $device->delete(); } $defaultTemplateId = $config->getVar("default_template"); if (!empty($defaultTemplateId)) { $autodiscoveryJob->addNotice("Fetching Default Template..."); $defaultTemplate = NagiosHostTemplatePeer::retrieveByPK($defaultTemplateId); if (!$defaultTemplate) { $autodiscoveryJob->addNotice("Failed to find default template requested. Will not be able to assign a default template."); } } $autodiscoveryJob->addNotice("Initializing Auto Discovery Engine: " . $engineClass); $engine = new $engineClass($autodiscoveryJob); if (!$engine->init()) { $autodiscoveryJob->addError("Engine failed to initialize."); $importJob->addError("Auto Discovery Engine of type " . $engineClass . " not found."); $autodiscoveryJob->setStatusCode(AutodiscoveryJob::STATUS_FAILED); $autodiscoveryJob->save(); exit(40); } if (!$engine->discover()) { $autodiscoveryJob->addError("Engine autodiscovery process failed to complete successfully.");
public function init() { $job = $this->getJob(); $job->addNotice("NagiosImportEngine Starting..."); $config = $this->getConfig(); // Attempt to try and open each config file $job->addNotice("Attempting to open " . $config->GetVar('config_file')); if (!file_exists($config->getVar('config_file')) || !@fopen($config->getVar('config_file'), "r")) { $job->addError("Failed to open " . $config->getVar('config_file')); return false; } $job->addNotice("Attempting to open " . $config->GetVar('cgi_file')); if (!file_exists($config->getVar('cgi_file')) || !@fopen($config->getVar('cgi_file'), "r")) { $job->addError("Failed to open " . $config->getVar('cgi_file')); return false; } $job->addNotice("Attempting to open " . $config->GetVar('resources_file')); if (!file_exists($config->getVar('resources_file')) || !@fopen($config->getVar('resources_file'), "r")) { $job->addError("Failed to open " . $config->getVar('resources_file')); return false; } $job->addNotice("Config passed sanity check for Nagios import. Finished initializing."); if ($config->getVar('delete_existing')) { $job->addNotice("Removing existing Nagios objects."); NagiosTimeperiodPeer::doDeleteAll(); NagiosCommandPeer::doDeleteAll(); NagiosContactPeer::doDeleteAll(); NagiosContactGroupPeer::doDeleteAll(); NagiosHostTemplatePeer::doDeleteAll(); NagiosHostPeer::doDeleteAll(); NagiosHostgroupPeer::doDeleteAll(); NagiosServiceGroupPeer::doDeleteAll(); NagiosServiceTemplatePeer::doDeleteAll(); NagiosServicePeer::doDeleteAll(); NagiosDependencyPeer::doDeleteAll(); NagiosDependencyTargetPeer::doDeleteAll(); NagiosEscalationPeer::doDeleteAll(); } return true; }
<td><?php echo NagiosHostgroupPeer::doCount(new Criteria()); ?> </td> </tr> <tr class="odd"> <td><strong>Total Nagios Service Groups:</strong></td> <td><?php echo NagiosServiceGroupPeer::doCount(new Criteria()); ?> </td> </tr> <tr> <td><strong>Total Nagios Host Templates:</strong></td> <td><?php echo NagiosHostTemplatePeer::doCount(new Criteria()); ?> </td> </tr> <tr class="odd"> <td><strong>Total Nagios Service Templates:</strong></td> <td><?php echo NagiosServiceTemplatePeer::doCount(new Criteria()); ?> </td> </tr> <tr> <td><strong>Total Nagios Hosts:</strong></td> <td><?php echo NagiosHostPeer::doCount(new Criteria()); ?>
/** * If this collection has already been initialized with * an identical criteria, it returns the collection. * Otherwise if this NagiosTimeperiod is new, it will return * an empty collection; or if this NagiosTimeperiod has previously * been saved, it will retrieve related NagiosHostTemplatesRelatedByNotificationPeriod from storage. * * This method is protected by default in order to keep the public * api reasonable. You can provide public methods for those you * actually need in NagiosTimeperiod. */ public function getNagiosHostTemplatesRelatedByNotificationPeriodJoinNagiosCommandRelatedByEventHandler($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN) { if ($criteria === null) { $criteria = new Criteria(NagiosTimeperiodPeer::DATABASE_NAME); } elseif ($criteria instanceof Criteria) { $criteria = clone $criteria; } if ($this->collNagiosHostTemplatesRelatedByNotificationPeriod === null) { if ($this->isNew()) { $this->collNagiosHostTemplatesRelatedByNotificationPeriod = array(); } else { $criteria->add(NagiosHostTemplatePeer::NOTIFICATION_PERIOD, $this->id); $this->collNagiosHostTemplatesRelatedByNotificationPeriod = NagiosHostTemplatePeer::doSelectJoinNagiosCommandRelatedByEventHandler($criteria, $con, $join_behavior); } } else { // the following code is to determine if a new query is // called for. If the criteria is the same as the last // one, just return the collection. $criteria->add(NagiosHostTemplatePeer::NOTIFICATION_PERIOD, $this->id); if (!isset($this->lastNagiosHostTemplateRelatedByNotificationPeriodCriteria) || !$this->lastNagiosHostTemplateRelatedByNotificationPeriodCriteria->equals($criteria)) { $this->collNagiosHostTemplatesRelatedByNotificationPeriod = NagiosHostTemplatePeer::doSelectJoinNagiosCommandRelatedByEventHandler($criteria, $con, $join_behavior); } } $this->lastNagiosHostTemplateRelatedByNotificationPeriodCriteria = $criteria; return $this->collNagiosHostTemplatesRelatedByNotificationPeriod; }
public static function match(AutodiscoveryDevice $device, NagiosHostTemplate $defaultTemplate = null) { // Delete previous matches $c = new Criteria(); $c->add(AutodiscoveryDeviceTemplateMatchPeer::DEVICE_ID, $device->getId()); AutodiscoveryDeviceTemplateMatchPeer::doDelete($c); $templates = NagiosHostTemplatePeer::doSelect(new Criteria()); $templateMatches = array(); foreach ($templates as $template) { $templateValues = $template->getValues(); $complexity = 0; $match = 0; $serviceFilters = $template->getNagiosHostTemplateAutodiscoveryServices(); $inheritedServiceFilters = $template->getInheritedNagiosAutodiscoveryServiceFilters(); $serviceFilters = array_merge($serviceFilters, $inheritedServiceFilters); if (!empty($templateValues['autodiscovery_address_filter']) && $templateValues['autodiscovery_address_filter']['value'] != '') { $complexity++; if (preg_match($templateValues['autodiscovery_address_filter']['value'], $device->getAddress())) { $match++; } } if (!empty($templateValues['autodiscovery_hostname_filter']) && $templateValues['autodiscovery_hostname_filter']['value'] != '') { $complexity++; if (preg_match($templateValues['autodiscovery_hostname_filter']['value'], $device->getHostname())) { $match++; } } if (!empty($templateValues['autodiscovery_os_family_filter']) && $templateValues['autodiscovery_os_family_filter']['value'] != '') { $complexity++; if (preg_match($templateValues['autodiscovery_os_family_filter']['value'], $device->getOsfamily())) { $match++; } } if (!empty($templateValues['autodiscovery_os_generation_filter']) && $templateValues['autodiscovery_os_generation_filter']['value'] != '') { $complexity++; if (preg_match($templateValues['autodiscovery_os_generation_filter']['value'], $device->getOsgen())) { $match++; } } if (!empty($templateValues['autodiscovery_os_vendor_filter']) && $templateValues['autodiscovery_os_vendor_filter']['value'] != '') { $complexity++; if (preg_match($templateValues['autodiscovery_os_vendor_filter']['value'], $device->getOsvendor())) { $match++; } } // Checked bases, let's now check service filters $complexity += count($serviceFilters); foreach ($serviceFilters as $filter) { foreach ($device->getAutodiscoveryDeviceServices() as $service) { if ($filter->getPort() == $service->getPort() && $filter->getProtocol() == $service->getProtocol()) { // Okay, we're ALMOST found...let's see if we have any other additional filters. $tempMatch = true; if ($filter->getName() != '') { if (!preg_match($filter->getName(), $service->getName())) { $tempMatch = false; } } if ($filter->getProduct() != '') { if (!preg_match($filter->getProduct(), $service->getProduct())) { $tempMatch = false; } } if ($filter->getVersion() != '') { if (!preg_match($filter->getVersion(), $service->getVersion())) { $tempMatch = false; } } if ($filter->getExtraInformation() != '') { if (!preg_match($filter->getExtraInformation(), $service->getExtraInformation())) { $tempMatch = false; } } if ($tempMatch) { $match++; } } } } // Okay, we got everything, let's determine the percentage. if ($complexity == 0) { // Blank template, no auto-discovery features used. $percentage = 0; continue; } else { $percentage = (int) ((double) $match / (double) $complexity * 100); } if ($percentage == 0) { continue; } // Store the template into the array $templateMatches[$percentage][$complexity][] = $template; } // Okay, let's now create the matches $percentages = array_keys($templateMatches); $assigned = false; for ($percentageCounter = 0; $percentageCounter < count($percentages); $percentageCounter++) { $complexities = array_keys($templateMatches[$percentages[$percentageCounter]]); $complexities = array_reverse($complexities); for ($complexityCount = 0; $complexityCount < count($complexities); $complexityCount++) { foreach ($templateMatches[$percentages[$percentageCounter]][$complexities[$complexityCount]] as $template) { $match = new AutodiscoveryDeviceTemplateMatch(); $match->setAutodiscoveryDevice($device); $match->setNagiosHostTemplate($template); $match->setPercent($percentages[$percentageCounter]); $match->setComplexity($complexities[$complexityCount]); $match->save(); // Add the highest match as the template to assign if (!$assigned) { $assigned = true; $device->setNagiosHostTemplate($template); } } } } // If Not assigned, assign default template if (!$assigned && !empty($defaultTemplate)) { $device->setNagiosHostTemplate($defaultTemplate); } $device->save(); }
public function import() { $engine = $this->getEngine(); $job = $engine->getJob(); $job->addNotice("FruityEscalationImporter beginning to import Dependency Configuration."); foreach ($this->dbConn->query("SELECT * FROM nagios_escalations", PDO::FETCH_ASSOC) as $escalation) { $newEscalation = new NagiosEscalation(); if (!empty($escalation['service_id'])) { // This is a service escalation $lilacService = $this->getLilacServiceById($escalation['service_id']); if (!$lilacService) { $job->addNotice("Fruity Escalation Importer: Failed to get Lilac service with an id matching: " . $escalation['service_id']); return true; } $newEscalation->setService($lilacService->getId()); } else { if (!empty($escalation['host_id'])) { // This is a host escalation $hostName = $this->getHostNameById($escalation['host_id']); $host = NagiosHostPeer::getByName($hostName); if (!$host) { $job->addNotice("Fruity Escalation Importer: Failed to get Lilac host with an name matching: " . $hostName); return true; } $newEscalation->setHost($host->getId()); } else { if (!empty($escalation['service_template_id'])) { // This is a service template escalation $templateName = $this->getServiceTemplateNameById($escalation['service_template_id']); $template = NagiosServiceTemplatePeer::getByName($templateName); if (!$template) { $job->addNotice("Fruity Escalation Importer: Failed to get Lilac service template with name matching: " . $templateName); return true; } $newEscalation->setServiceTemplate($template->getId()); } else { if (!empty($escalation['host_template_id'])) { // This is for a host template escalation $templateName = $this->getHostTemplateNameById($escalation['host_template_id']); $template = NagiosHostTemplatePeer::getByName($templateName); if (!$template) { $job->addNotice("Fruity Escalation Importer: Failed to get Lilac host template with name matching: " . $templateName); return true; } $newEscalation->setHostTemplate($template->getId()); } } } } foreach ($escalation as $key => $val) { unset($name); if ($key == "escalation_id" || $key == "host_id" || $key == "host_template_id" || $key == "service_template_id" || $key == "service_id") { continue; } if ($key == "escalation_description") { $key = "description"; } if ($key == "escalation_period") { $escalationName = $this->getTimeperiodNameById($id); if ($escalationName) { $newEscalation->setEscalationPeriodByName($escalationName); } continue; } try { $name = NagiosEscalationPeer::translateFieldName($key, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_PHPNAME); } catch (Exception $e) { $job->addNotice("Fruity Escalation Importer: Was unable to store unsupported value: " . $key); } if (!empty($name)) { $method = "set" . $name; $newEscalation->{$method}($val); } } $newEscalation->save(); // Handle escalation contact groups. foreach ($this->dbConn->query("SELECT * FROM nagios_escalation_contactgroups WHERE escalation_id = " . $escalation['escalation_id'], PDO::FETCH_ASSOC) as $contactgroup) { $contactgroupName = $this->getContactGroupNameById($contactgroup['contactgroup_id']); if ($contactgroupName) { $lilacContactGroup = NagiosContactGroupPeer::getByName($contactgroupName); if ($lilacContactGroup) { $newContactGroup = new NagiosEscalationContactgroup(); $newContactGroup->setEscalation($newEscalation->getId()); $newContactGroup->setContactgroup($lilacContactGroup->getId()); $newContactGroup->save(); } } } } $job->addNotice("FruityEscalationImporter finished importing Escalation Configuration."); }
public function import() { $job = $this->getJob(); $job->addNotice("FruityImportEngine beginning import..."); $config = $this->getConfig(); $job->addNotice("Removing existing Nagios objects."); NagiosTimeperiodPeer::doDeleteAll(); NagiosCommandPeer::doDeleteAll(); NagiosContactPeer::doDeleteAll(); NagiosContactGroupPeer::doDeleteAll(); NagiosHostTemplatePeer::doDeleteAll(); NagiosHostPeer::doDeleteAll(); NagiosHostgroupPeer::doDeleteAll(); NagiosServiceGroupPeer::doDeleteAll(); NagiosServiceTemplatePeer::doDeleteAll(); NagiosServicePeer::doDeleteAll(); NagiosDependencyPeer::doDeleteAll(); NagiosDependencyTargetPeer::doDeleteAll(); NagiosEscalationPeer::doDeleteAll(); NagiosBrokerModulePeer::doDeleteAll(); NagiosMainConfigurationPeer::doDeleteAll(); NagiosCgiConfigurationPeer::doDeleteAll(); $importer = new FruityResourceImporter($this, $this->dbConn); $importer->import(); $importer = new FruityCgiImporter($this, $this->dbConn); $importer->import(); $importer = new FruityCommandImporter($this, $this->dbConn); $importer->import(); $importer = new FruityTimeperiodImporter($this, $this->dbConn); $importer->import(); $importer = new FruityContactImporter($this, $this->dbConn); $importer->import(); $importer = new FruityServiceGroupImporter($this, $this->dbConn); $importer->import(); $importer = new FruityServiceTemplateImporter($this, $this->dbConn); $importer->import(); $importer = new FruityHostTemplateImporter($this, $this->dbConn); $importer->import(); $importer = new FruityHostGroupImporter($this, $this->dbConn); $importer->import(); $importer = new FruityHostImporter($this, $this->dbConn); $importer->import(); $importer = new FruityServiceImporter($this, $this->dbConn); $importer->import(); $importer = new FruityDependencyImporter($this, $this->dbConn); $importer->import(); $importer = new FruityEscalationImporter($this, $this->dbConn); $importer->import(); $importer = new FruityMainImporter($this, $this->dbConn); $importer->import(); $job->addNotice("FruityImportEngine completed job."); return true; }
/** * Retrieve multiple objects by pkey. * * @param array $pks List of primary keys * @param PropelPDO $con the connection to use * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function retrieveByPKs($pks, PropelPDO $con = null) { if ($con === null) { $con = Propel::getConnection(NagiosHostTemplatePeer::DATABASE_NAME, Propel::CONNECTION_READ); } $objs = null; if (empty($pks)) { $objs = array(); } else { $criteria = new Criteria(NagiosHostTemplatePeer::DATABASE_NAME); $criteria->add(NagiosHostTemplatePeer::ID, $pks, Criteria::IN); $objs = NagiosHostTemplatePeer::doSelect($criteria, $con); } return $objs; }
private function search_text($text) { // LOTS of places to check... // Hosts: name, alias, addresses $c = new Criteria(); $c1 = $c->getNewCriterion(NagiosHostPeer::NAME, "%" . $text . "%", Criteria::LIKE); $c2 = $c->getNewCriterion(nagiosHostPeer::ALIAS, "%" . $text . "%", Criteria::LIKE); $c3 = $c->getNewCriterion(nagiosHostPeer::ADDRESS, "%" . $text . "%", Criteria::LIKE); $c2->addOr($c3); $c1->addOr($c2); $c->add($c1); $c->setIgnoreCase(true); $c->addAscendingOrderByColumn(NagiosHostPeer::NAME); $matchedHosts = NagiosHostPeer::doSelect($c); if (count($matchedHosts)) { foreach ($matchedHosts as $host) { $this->searchResults['hosts'][$host->getId()] = $host; $this->searchCount++; } } // Hostgroups: name, alias $c = new Criteria(); $c1 = $c->getNewCriterion(NagiosHostgroupPeer::NAME, "%" . $text . "%", Criteria::LIKE); $c2 = $c->getNewCriterion(nagiosHostgroupPeer::ALIAS, "%" . $text . "%", Criteria::LIKE); $c1->addOr($c2); $c->add($c1); $c->setIgnoreCase(true); $c->addAscendingOrderByColumn(NagiosHostgroupPeer::NAME); $matchedHostgroups = NagiosHostgroupPeer::doSelect($c); if (count($matchedHostgroups)) { foreach ($matchedHostgroups as $hostgroup) { $this->searchResults['hostgroups'][$hostgroup->getId()] = $hostgroup; $this->searchCount++; } } // Host Templates: name, description $c = new Criteria(); $c1 = $c->getNewCriterion(NagiosHostTemplatePeer::NAME, "%" . $text . "%", Criteria::LIKE); $c2 = $c->getNewCriterion(NagiosHostTemplatePeer::DESCRIPTION, "%" . $text . "%", Criteria::LIKE); $c1->addOr($c2); $c->add($c1); $c->setIgnoreCase(true); $c->addAscendingOrderByColumn(NagiosHostTemplatePeer::NAME); $matchedTemplates = NagiosHostTemplatePeer::doSelect($c); if (count($matchedTemplates)) { foreach ($matchedTemplates as $template) { $this->searchResults['host_templates'][$template->getId()] = $template; $this->searchCount++; } } // Services: description $c = new Criteria(); $c1 = $c->getNewCriterion(NagiosServicePeer::DESCRIPTION, "%" . $text . "%", Criteria::LIKE); $c->add($c1); $c->setIgnoreCase(true); $c->addAscendingOrderByColumn(NagiosServicePeer::DESCRIPTION); $matchedServices = NagiosServicePeer::doSelect($c); if (count($matchedServices)) { foreach ($matchedServices as $service) { $this->searchResults['services'][$service->getId()] = $service; $this->searchCount++; } } // Servicegroups: name, alias $c = new Criteria(); $c1 = $c->getNewCriterion(NagiosServiceGroupPeer::NAME, "%" . $text . "%", Criteria::LIKE); $c2 = $c->getNewCriterion(NagiosServiceGroupPeer::ALIAS, "%" . $text . "%", Criteria::LIKE); $c1->addOr($c2); $c->add($c1); $c->setIgnoreCase(true); $c->addAscendingOrderByColumn(NagiosServiceGroupPeer::NAME); $matchedServicegroups = NagiosServiceGroupPeer::doSelect($c); if (count($matchedServicegroups)) { foreach ($matchedServicegroups as $servicegroup) { $this->searchResults['servicegroups'][$servicegroup->getId()] = $servicegroup; $this->searchCount++; } } // Service Templates: name, description $c = new Criteria(); $c1 = $c->getNewCriterion(NagiosServiceTemplatePeer::NAME, "%" . $text . "%", Criteria::LIKE); $c2 = $c->getNewCriterion(NagiosServiceTemplatePeer::DESCRIPTION, "%" . $text . "%", Criteria::LIKE); $c1->addOr($c2); $c->add($c1); $c->setIgnoreCase(true); $c->addAscendingOrderByColumn(NagiosServiceTemplatePeer::NAME); $matchedTemplates = NagiosServiceTemplatePeer::doSelect($c); if (count($matchedTemplates)) { foreach ($matchedTemplates as $template) { $this->searchResults['service_templates'][$template->getId()] = $template; $this->searchCount++; } } // Service Templates: name, description $c = new Criteria(); $c1 = $c->getNewCriterion(NagiosContactPeer::NAME, "%" . $text . "%", Criteria::LIKE); $c2 = $c->getNewCriterion(NagiosContactPeer::ALIAS, "%" . $text . "%", Criteria::LIKE); $c3 = $c->getNewCriterion(NagiosContactPeer::EMAIL, "%" . $text . "%", Criteria::LIKE); $c2->addOr($c3); $c1->addOr($c2); $c->add($c1); $c->setIgnoreCase(true); $c->addAscendingOrderByColumn(NagiosContactPeer::NAME); $matchedContacts = NagiosContactPeer::doSelect($c); if (count($matchedContacts)) { foreach ($matchedContacts as $contact) { $this->searchResults['contacts'][$contact->getId()] = $contact; $this->searchCount++; } } // ContactGroups: name, alias $c = new Criteria(); $c1 = $c->getNewCriterion(NagiosContactGroupPeer::NAME, "%" . $text . "%", Criteria::LIKE); $c2 = $c->getNewCriterion(NagiosContactGroupPeer::ALIAS, "%" . $text . "%", Criteria::LIKE); $c1->addOr($c2); $c->add($c1); $c->setIgnoreCase(true); $c->addAscendingOrderByColumn(NagiosContactGroupPeer::NAME); $matchedContactgroups = NagiosContactGroupPeer::doSelect($c); if (count($matchedContactgroups)) { foreach ($matchedContactgroups as $contactgroup) { $this->searchResults['contactgroups'][$contactgroup->getId()] = $contactgroup; $this->searchCount++; } } // Timeperiod: name, alias $c = new Criteria(); $c1 = $c->getNewCriterion(NagiosTimeperiodPeer::NAME, "%" . $text . "%", Criteria::LIKE); $c2 = $c->getNewCriterion(NagiosTimeperiodPeer::ALIAS, "%" . $text . "%", Criteria::LIKE); $c1->addOr($c2); $c->add($c1); $c->setIgnoreCase(true); $c->addAscendingOrderByColumn(NagiosTimeperiodPeer::NAME); $matchedPeriods = NagiosTimeperiodPeer::doSelect($c); if (count($matchedPeriods)) { foreach ($matchedPeriods as $period) { $this->searchResults['timeperiods'][$period->getId()] = $period; $this->searchCount++; } } // Command: name, description $c = new Criteria(); $c1 = $c->getNewCriterion(NagiosCommandPeer::NAME, "%" . $text . "%", Criteria::LIKE); $c2 = $c->getNewCriterion(NagiosCommandPeer::DESCRIPTION, "%" . $text . "%", Criteria::LIKE); $c1->addOr($c2); $c->add($c1); $c->setIgnoreCase(true); $c->addAscendingOrderByColumn(NagiosCommandPeer::NAME); $matchedCommands = NagiosCommandPeer::doSelect($c); if (count($matchedCommands)) { foreach ($matchedCommands as $command) { $this->searchResults['commands'][$command->getId()] = $command; $this->searchCount++; } } }
[ <a href="hosts.php?id=<?php echo $_GET['id']; ?> &request=delete" onClick="javascript:return confirmDelete();">Delete This Host</a> ] <?php } if ($_GET['section'] == 'inheritance') { $templateInheritances = $host->getNagiosHostTemplateInheritances(); $numOfTemplates = count($templateInheritances); $exclude_list = array(); if ($numOfTemplates) { foreach ($templateInheritances as $template) { $exclude_list[] = $template->getId(); } } $templateList = NagiosHostTemplatePeer::doSelect(new Criteria()); ?> <table width="100%" border="0"> <tr> <td width="100" align="center" valign="top"> <img src="<?php echo $host_icon_image; ?> " /> </td> <td valign="top"> <table width="100%" align="center" cellspacing="0" cellpadding="2" border="0"> <tr class="altTop"> <td colspan="4">Host Templates To Inherit From (Top to Bottom):</td> </tr> <?php
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."); }
/** * Selects a collection of AutodiscoveryDeviceTemplateMatch objects pre-filled with all related objects except AutodiscoveryDevice. * * @param Criteria $c * @param PropelPDO $con * @param String $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN * @return array Array of AutodiscoveryDeviceTemplateMatch objects. * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function doSelectJoinAllExceptAutodiscoveryDevice(Criteria $c, $con = null, $join_behavior = Criteria::LEFT_JOIN) { $c = clone $c; // Set the correct dbName if it has not been overridden // $c->getDbName() will return the same object if not set to another value // so == check is okay and faster if ($c->getDbName() == Propel::getDefaultDB()) { $c->setDbName(self::DATABASE_NAME); } AutodiscoveryDeviceTemplateMatchPeer::addSelectColumns($c); $startcol2 = AutodiscoveryDeviceTemplateMatchPeer::NUM_COLUMNS - AutodiscoveryDeviceTemplateMatchPeer::NUM_LAZY_LOAD_COLUMNS; NagiosHostTemplatePeer::addSelectColumns($c); $startcol3 = $startcol2 + (NagiosHostTemplatePeer::NUM_COLUMNS - NagiosHostTemplatePeer::NUM_LAZY_LOAD_COLUMNS); $c->addJoin(array(AutodiscoveryDeviceTemplateMatchPeer::HOST_TEMPLATE), array(NagiosHostTemplatePeer::ID), $join_behavior); $stmt = BasePeer::doSelect($c, $con); $results = array(); while ($row = $stmt->fetch(PDO::FETCH_NUM)) { $key1 = AutodiscoveryDeviceTemplateMatchPeer::getPrimaryKeyHashFromRow($row, 0); if (null !== ($obj1 = AutodiscoveryDeviceTemplateMatchPeer::getInstanceFromPool($key1))) { // We no longer rehydrate the object, since this can cause data loss. // See http://propel.phpdb.org/trac/ticket/509 // $obj1->hydrate($row, 0, true); // rehydrate } else { $omClass = AutodiscoveryDeviceTemplateMatchPeer::getOMClass(); $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1); $obj1 = new $cls(); $obj1->hydrate($row); AutodiscoveryDeviceTemplateMatchPeer::addInstanceToPool($obj1, $key1); } // if obj1 already loaded // Add objects for joined NagiosHostTemplate rows $key2 = NagiosHostTemplatePeer::getPrimaryKeyHashFromRow($row, $startcol2); if ($key2 !== null) { $obj2 = NagiosHostTemplatePeer::getInstanceFromPool($key2); if (!$obj2) { $omClass = NagiosHostTemplatePeer::getOMClass(); $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1); $obj2 = new $cls(); $obj2->hydrate($row, $startcol2); NagiosHostTemplatePeer::addInstanceToPool($obj2, $key2); } // if $obj2 already loaded // Add the $obj1 (AutodiscoveryDeviceTemplateMatch) to the collection in $obj2 (NagiosHostTemplate) $obj2->addAutodiscoveryDeviceTemplateMatch($obj1); } // if joined row is not null $results[] = $obj1; } $stmt->closeCursor(); return $results; }
/** * Method perform a DELETE on the database, given a NagiosTimeperiod or Criteria object OR a primary key value. * * @param mixed $values Criteria or NagiosTimeperiod object or primary key or array of primary keys * which is used to create the DELETE statement * @param PropelPDO $con the connection to use * @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows * if supported by native driver or if emulated using Propel. * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function doDelete($values, PropelPDO $con = null) { if ($con === null) { $con = Propel::getConnection(NagiosTimeperiodPeer::DATABASE_NAME, Propel::CONNECTION_WRITE); } if ($values instanceof Criteria) { // invalidate the cache for all objects of this type, since we have no // way of knowing (without running a query) what objects should be invalidated // from the cache based on this Criteria. NagiosTimeperiodPeer::clearInstancePool(); // rename for clarity $criteria = clone $values; } elseif ($values instanceof NagiosTimeperiod) { // invalidate the cache for this single object NagiosTimeperiodPeer::removeInstanceFromPool($values); // create criteria based on pk values $criteria = $values->buildPkeyCriteria(); } else { // it must be the primary key $criteria = new Criteria(self::DATABASE_NAME); $criteria->add(NagiosTimeperiodPeer::ID, (array) $values, Criteria::IN); foreach ((array) $values as $singleval) { // we can invalidate the cache for this single object NagiosTimeperiodPeer::removeInstanceFromPool($singleval); } } // Set the correct dbName $criteria->setDbName(self::DATABASE_NAME); $affectedRows = 0; // initialize var to track total num of affected rows try { // use transaction because $criteria could contain info // for more than one table or we could emulating ON DELETE CASCADE, etc. $con->beginTransaction(); $affectedRows += NagiosTimeperiodPeer::doOnDeleteCascade($criteria, $con); NagiosTimeperiodPeer::doOnDeleteSetNull($criteria, $con); // Because this db requires some delete cascade/set null emulation, we have to // clear the cached instance *after* the emulation has happened (since // instances get re-added by the select statement contained therein). if ($values instanceof Criteria) { NagiosTimeperiodPeer::clearInstancePool(); } else { // it's a PK or object NagiosTimeperiodPeer::removeInstanceFromPool($values); } $affectedRows += BasePeer::doDelete($criteria, $con); // invalidate objects in NagiosTimeperiodEntryPeer instance pool, since one or more of them may be deleted by ON DELETE CASCADE rule. NagiosTimeperiodEntryPeer::clearInstancePool(); // invalidate objects in NagiosTimeperiodExcludePeer instance pool, since one or more of them may be deleted by ON DELETE CASCADE rule. NagiosTimeperiodExcludePeer::clearInstancePool(); // invalidate objects in NagiosTimeperiodExcludePeer instance pool, since one or more of them may be deleted by ON DELETE CASCADE rule. NagiosTimeperiodExcludePeer::clearInstancePool(); // invalidate objects in NagiosContactPeer instance pool, since one or more of them may be deleted by ON DELETE CASCADE rule. NagiosContactPeer::clearInstancePool(); // invalidate objects in NagiosContactPeer instance pool, since one or more of them may be deleted by ON DELETE CASCADE rule. NagiosContactPeer::clearInstancePool(); // invalidate objects in NagiosHostTemplatePeer instance pool, since one or more of them may be deleted by ON DELETE CASCADE rule. NagiosHostTemplatePeer::clearInstancePool(); // invalidate objects in NagiosHostTemplatePeer instance pool, since one or more of them may be deleted by ON DELETE CASCADE rule. NagiosHostTemplatePeer::clearInstancePool(); // invalidate objects in NagiosHostPeer instance pool, since one or more of them may be deleted by ON DELETE CASCADE rule. NagiosHostPeer::clearInstancePool(); // invalidate objects in NagiosHostPeer instance pool, since one or more of them may be deleted by ON DELETE CASCADE rule. NagiosHostPeer::clearInstancePool(); // invalidate objects in NagiosServiceTemplatePeer instance pool, since one or more of them may be deleted by ON DELETE CASCADE rule. NagiosServiceTemplatePeer::clearInstancePool(); // invalidate objects in NagiosServiceTemplatePeer instance pool, since one or more of them may be deleted by ON DELETE CASCADE rule. NagiosServiceTemplatePeer::clearInstancePool(); // invalidate objects in NagiosServicePeer instance pool, since one or more of them may be deleted by ON DELETE CASCADE rule. NagiosServicePeer::clearInstancePool(); // invalidate objects in NagiosServicePeer instance pool, since one or more of them may be deleted by ON DELETE CASCADE rule. NagiosServicePeer::clearInstancePool(); // invalidate objects in NagiosDependencyPeer instance pool, since one or more of them may be deleted by ON DELETE CASCADE rule. NagiosDependencyPeer::clearInstancePool(); // invalidate objects in NagiosEscalationPeer instance pool, since one or more of them may be deleted by ON DELETE CASCADE rule. NagiosEscalationPeer::clearInstancePool(); $con->commit(); return $affectedRows; } catch (PropelException $e) { $con->rollBack(); throw $e; } }
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; }
GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ /* * host_template.php * Author: Taylor Dondich (tdondich at gmail.com) * Description: * Provides interface to maintain host templates * */ include_once 'includes/config.inc'; if (isset($_GET['host_template_id'])) { $tempSource = NagiosHostTemplatePeer::retrieveByPK($_GET['host_template_id']); $link = "host_template.php"; $fieldName = "host_template_id"; if (!$tempSource) { header("Location: welcome.php"); } $type = "hosttemplate"; $title = "Host Template"; } else { if (isset($_GET['host_id'])) { $tempSource = NagiosHostPeer::retrieveByPK($_GET['host_id']); $fieldName = "host_id"; $link = "hosts.php"; if (!$tempSource) { header("Location: welcome.php"); }
/** * Get the associated NagiosHostTemplate object * * @param PropelPDO Optional Connection object. * @return NagiosHostTemplate The associated NagiosHostTemplate object. * @throws PropelException */ public function getNagiosHostTemplate(PropelPDO $con = null) { if ($this->aNagiosHostTemplate === null && $this->host_template !== null) { $c = new Criteria(NagiosHostTemplatePeer::DATABASE_NAME); $c->add(NagiosHostTemplatePeer::ID, $this->host_template); $this->aNagiosHostTemplate = NagiosHostTemplatePeer::doSelectOne($c, $con); /* The following can be used additionally to guarantee the related object contains a reference to this object. This level of coupling may, however, be undesirable since it could result in an only partially populated collection in the referenced object. $this->aNagiosHostTemplate->addNagiosEscalations($this); */ } return $this->aNagiosHostTemplate; }
public function valid() { $values = $this->getSegment()->getValues(); $job = $this->getEngine()->getJob(); if (isset($values['use'])) { // We need to use a template $job->addNotice("This Host uses a template: " . $values['use'][0]['value']); $template = NagiosHostTemplatePeer::getByName($values['use'][0]['value']); if (empty($template)) { if (!isset($values['name'][0]['value'])) { $job->addNotice("That template is not found yet. Setting this host (" . $values['host_name'][0]['value'] . ") as queued."); } else { $job->addNotice("That template is not found yet. Setting this host template (" . $values['name'][0]['value'] . ") as queued."); } return false; } } // Check time period existence if (isset($values['check_period'])) { $c = new Criteria(); $c->add(NagiosTimeperiodPeer::NAME, $values['check_period'][0]['value']); $timePeriod = NagiosTimeperiodPeer::doSelectOne($c); if (empty($timePeriod)) { $job->addNotice("The time period specified by " . $values['check_period'][0]['value'] . " was not found."); return false; } $timePeriod->clearAllReferences(true); } if (isset($values['notification_period'])) { $c = new Criteria(); $c->add(NagiosTimeperiodPeer::NAME, $values['notification_period'][0]['value']); $timePeriod = NagiosTimeperiodPeer::doSelectOne($c); if (empty($timePeriod)) { $job->addNotice("The time period specified by " . $values['notification_period'][0]['value'] . " was not found."); return false; } $timePeriod->clearAllReferences(true); } // Check command existence if (isset($values['check_command'])) { $params = explode("!", $values['check_command'][0]['value']); $c = new Criteria(); $c->add(NagiosCommandPeer::NAME, $params[0]); $command = NagiosCommandPeer::doSelectOne($c); if (empty($command)) { $job->addNotice("The command specified by " . $params[0] . " was not found."); return false; } $command->clearAllReferences(true); } if (isset($values['event_handler'])) { $c = new Criteria(); $c->add(NagiosCommandPeer::NAME, $values['event_handler'][0]['value']); $command = NagiosCommandPeer::doSelectOne($c); if (empty($command)) { $job->addNotice("The command specified by " . $values['event_handler'][0]['value'] . " was not found."); return false; } $command->clearAllReferences(true); } // Check contact groups if (isset($values['contact_groups'])) { foreach ($values['contact_groups'] as $contactGroupValues) { $c = new Criteria(); $c->add(NagiosContactGroupPeer::NAME, $contactGroupValues['value']); $contactgroup = NagiosContactGroupPeer::doSelectOne($c); if (empty($contactgroup)) { $job->addNotice("The contact group specified by " . $contactGroupValues['value'] . " was not found."); return false; } $contactgroup->clearAllReferences(); } } if (isset($values['contacts'])) { foreach ($values['contacts'] as $contactValues) { $c = new Criteria(); $c->add(NagiosContactPeer::NAME, $contactValues['value']); $contactgroup = NagiosContactPeer::doSelectOne($c); if (empty($contactgroup)) { $job->addNotice("The contact specified by " . $contactValues['value'] . " was not found."); return false; } $contactgroup->clearAllReferences(); } } // Check host groups if (isset($values['hostgroups'])) { foreach ($values['hostgroups'] as $hostGroupValues) { $c = new Criteria(); $c->add(NagiosHostgroupPeer::NAME, $hostGroupValues['value']); $hostgroup = NagiosHostgroupPeer::doSelectOne($c); if (empty($hostgroup)) { $job->addNotice("The host group specified by " . $hostGroupValues['value'] . " was not found."); return false; } $hostgroup->clearAllReferences(); } } // Check parents if (isset($values['parents'])) { foreach ($values['parents'] as $parentValues) { $c = new Criteria(); $c->add(NagiosHostPeer::NAME, $parentValues['value']); $host = NagiosHostPeer::doSelectOne($c); if (empty($host)) { $job->addNotice("The host specified by " . $parentValues['value'] . " was not found."); return false; } $host->clearAllReferences(); } } return true; }
/** * Selects a collection of NagiosEscalation objects pre-filled with all related objects except NagiosTimeperiod. * * @param Criteria $c * @param PropelPDO $con * @param String $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN * @return array Array of NagiosEscalation objects. * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function doSelectJoinAllExceptNagiosTimeperiod(Criteria $c, $con = null, $join_behavior = Criteria::LEFT_JOIN) { $c = clone $c; // Set the correct dbName if it has not been overridden // $c->getDbName() will return the same object if not set to another value // so == check is okay and faster if ($c->getDbName() == Propel::getDefaultDB()) { $c->setDbName(self::DATABASE_NAME); } NagiosEscalationPeer::addSelectColumns($c); $startcol2 = NagiosEscalationPeer::NUM_COLUMNS - NagiosEscalationPeer::NUM_LAZY_LOAD_COLUMNS; NagiosHostTemplatePeer::addSelectColumns($c); $startcol3 = $startcol2 + (NagiosHostTemplatePeer::NUM_COLUMNS - NagiosHostTemplatePeer::NUM_LAZY_LOAD_COLUMNS); NagiosHostPeer::addSelectColumns($c); $startcol4 = $startcol3 + (NagiosHostPeer::NUM_COLUMNS - NagiosHostPeer::NUM_LAZY_LOAD_COLUMNS); NagiosServiceTemplatePeer::addSelectColumns($c); $startcol5 = $startcol4 + (NagiosServiceTemplatePeer::NUM_COLUMNS - NagiosServiceTemplatePeer::NUM_LAZY_LOAD_COLUMNS); NagiosServicePeer::addSelectColumns($c); $startcol6 = $startcol5 + (NagiosServicePeer::NUM_COLUMNS - NagiosServicePeer::NUM_LAZY_LOAD_COLUMNS); NagiosHostgroupPeer::addSelectColumns($c); $startcol7 = $startcol6 + (NagiosHostgroupPeer::NUM_COLUMNS - NagiosHostgroupPeer::NUM_LAZY_LOAD_COLUMNS); $c->addJoin(array(NagiosEscalationPeer::HOST_TEMPLATE), array(NagiosHostTemplatePeer::ID), $join_behavior); $c->addJoin(array(NagiosEscalationPeer::HOST), array(NagiosHostPeer::ID), $join_behavior); $c->addJoin(array(NagiosEscalationPeer::SERVICE_TEMPLATE), array(NagiosServiceTemplatePeer::ID), $join_behavior); $c->addJoin(array(NagiosEscalationPeer::SERVICE), array(NagiosServicePeer::ID), $join_behavior); $c->addJoin(array(NagiosEscalationPeer::HOSTGROUP), array(NagiosHostgroupPeer::ID), $join_behavior); $stmt = BasePeer::doSelect($c, $con); $results = array(); while ($row = $stmt->fetch(PDO::FETCH_NUM)) { $key1 = NagiosEscalationPeer::getPrimaryKeyHashFromRow($row, 0); if (null !== ($obj1 = NagiosEscalationPeer::getInstanceFromPool($key1))) { // We no longer rehydrate the object, since this can cause data loss. // See http://propel.phpdb.org/trac/ticket/509 // $obj1->hydrate($row, 0, true); // rehydrate } else { $omClass = NagiosEscalationPeer::getOMClass(); $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1); $obj1 = new $cls(); $obj1->hydrate($row); NagiosEscalationPeer::addInstanceToPool($obj1, $key1); } // if obj1 already loaded // Add objects for joined NagiosHostTemplate rows $key2 = NagiosHostTemplatePeer::getPrimaryKeyHashFromRow($row, $startcol2); if ($key2 !== null) { $obj2 = NagiosHostTemplatePeer::getInstanceFromPool($key2); if (!$obj2) { $omClass = NagiosHostTemplatePeer::getOMClass(); $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1); $obj2 = new $cls(); $obj2->hydrate($row, $startcol2); NagiosHostTemplatePeer::addInstanceToPool($obj2, $key2); } // if $obj2 already loaded // Add the $obj1 (NagiosEscalation) to the collection in $obj2 (NagiosHostTemplate) $obj2->addNagiosEscalation($obj1); } // if joined row is not null // Add objects for joined NagiosHost rows $key3 = NagiosHostPeer::getPrimaryKeyHashFromRow($row, $startcol3); if ($key3 !== null) { $obj3 = NagiosHostPeer::getInstanceFromPool($key3); if (!$obj3) { $omClass = NagiosHostPeer::getOMClass(); $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1); $obj3 = new $cls(); $obj3->hydrate($row, $startcol3); NagiosHostPeer::addInstanceToPool($obj3, $key3); } // if $obj3 already loaded // Add the $obj1 (NagiosEscalation) to the collection in $obj3 (NagiosHost) $obj3->addNagiosEscalation($obj1); } // if joined row is not null // Add objects for joined NagiosServiceTemplate rows $key4 = NagiosServiceTemplatePeer::getPrimaryKeyHashFromRow($row, $startcol4); if ($key4 !== null) { $obj4 = NagiosServiceTemplatePeer::getInstanceFromPool($key4); if (!$obj4) { $omClass = NagiosServiceTemplatePeer::getOMClass(); $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1); $obj4 = new $cls(); $obj4->hydrate($row, $startcol4); NagiosServiceTemplatePeer::addInstanceToPool($obj4, $key4); } // if $obj4 already loaded // Add the $obj1 (NagiosEscalation) to the collection in $obj4 (NagiosServiceTemplate) $obj4->addNagiosEscalation($obj1); } // if joined row is not null // Add objects for joined NagiosService rows $key5 = NagiosServicePeer::getPrimaryKeyHashFromRow($row, $startcol5); if ($key5 !== null) { $obj5 = NagiosServicePeer::getInstanceFromPool($key5); if (!$obj5) { $omClass = NagiosServicePeer::getOMClass(); $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1); $obj5 = new $cls(); $obj5->hydrate($row, $startcol5); NagiosServicePeer::addInstanceToPool($obj5, $key5); } // if $obj5 already loaded // Add the $obj1 (NagiosEscalation) to the collection in $obj5 (NagiosService) $obj5->addNagiosEscalation($obj1); } // if joined row is not null // Add objects for joined NagiosHostgroup rows $key6 = NagiosHostgroupPeer::getPrimaryKeyHashFromRow($row, $startcol6); if ($key6 !== null) { $obj6 = NagiosHostgroupPeer::getInstanceFromPool($key6); if (!$obj6) { $omClass = NagiosHostgroupPeer::getOMClass(); $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1); $obj6 = new $cls(); $obj6->hydrate($row, $startcol6); NagiosHostgroupPeer::addInstanceToPool($obj6, $key6); } // if $obj6 already loaded // Add the $obj1 (NagiosEscalation) to the collection in $obj6 (NagiosHostgroup) $obj6->addNagiosEscalation($obj1); } // if joined row is not null $results[] = $obj1; } $stmt->closeCursor(); return $results; }
/** * Populates the object using an array. * * This is particularly useful when populating an object from one of the * request arrays (e.g. $_POST). This method goes through the column * names, checking to see whether a matching key exists in populated * array. If so the setByName() method is called for that column. * * You can specify the key type of the array by additionally passing one * of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME, * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM. * The default key type is the column's phpname (e.g. 'AuthorId') * * @param array $arr An array to populate the object from. * @param string $keyType The type of keys the array uses. * @return void */ public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME) { $keys = NagiosHostTemplatePeer::getFieldNames($keyType); if (array_key_exists($keys[0], $arr)) { $this->setId($arr[$keys[0]]); } if (array_key_exists($keys[1], $arr)) { $this->setName($arr[$keys[1]]); } if (array_key_exists($keys[2], $arr)) { $this->setDescription($arr[$keys[2]]); } if (array_key_exists($keys[3], $arr)) { $this->setInitialState($arr[$keys[3]]); } if (array_key_exists($keys[4], $arr)) { $this->setCheckCommand($arr[$keys[4]]); } if (array_key_exists($keys[5], $arr)) { $this->setRetryInterval($arr[$keys[5]]); } if (array_key_exists($keys[6], $arr)) { $this->setFirstNotificationDelay($arr[$keys[6]]); } if (array_key_exists($keys[7], $arr)) { $this->setMaximumCheckAttempts($arr[$keys[7]]); } if (array_key_exists($keys[8], $arr)) { $this->setCheckInterval($arr[$keys[8]]); } if (array_key_exists($keys[9], $arr)) { $this->setPassiveChecksEnabled($arr[$keys[9]]); } if (array_key_exists($keys[10], $arr)) { $this->setCheckPeriod($arr[$keys[10]]); } if (array_key_exists($keys[11], $arr)) { $this->setObsessOverHost($arr[$keys[11]]); } if (array_key_exists($keys[12], $arr)) { $this->setCheckFreshness($arr[$keys[12]]); } if (array_key_exists($keys[13], $arr)) { $this->setFreshnessThreshold($arr[$keys[13]]); } if (array_key_exists($keys[14], $arr)) { $this->setActiveChecksEnabled($arr[$keys[14]]); } if (array_key_exists($keys[15], $arr)) { $this->setChecksEnabled($arr[$keys[15]]); } if (array_key_exists($keys[16], $arr)) { $this->setEventHandler($arr[$keys[16]]); } if (array_key_exists($keys[17], $arr)) { $this->setEventHandlerEnabled($arr[$keys[17]]); } if (array_key_exists($keys[18], $arr)) { $this->setLowFlapThreshold($arr[$keys[18]]); } if (array_key_exists($keys[19], $arr)) { $this->setHighFlapThreshold($arr[$keys[19]]); } if (array_key_exists($keys[20], $arr)) { $this->setFlapDetectionEnabled($arr[$keys[20]]); } if (array_key_exists($keys[21], $arr)) { $this->setProcessPerfData($arr[$keys[21]]); } if (array_key_exists($keys[22], $arr)) { $this->setRetainStatusInformation($arr[$keys[22]]); } if (array_key_exists($keys[23], $arr)) { $this->setRetainNonstatusInformation($arr[$keys[23]]); } if (array_key_exists($keys[24], $arr)) { $this->setNotificationInterval($arr[$keys[24]]); } if (array_key_exists($keys[25], $arr)) { $this->setNotificationPeriod($arr[$keys[25]]); } if (array_key_exists($keys[26], $arr)) { $this->setNotificationsEnabled($arr[$keys[26]]); } if (array_key_exists($keys[27], $arr)) { $this->setNotificationOnDown($arr[$keys[27]]); } if (array_key_exists($keys[28], $arr)) { $this->setNotificationOnUnreachable($arr[$keys[28]]); } if (array_key_exists($keys[29], $arr)) { $this->setNotificationOnRecovery($arr[$keys[29]]); } if (array_key_exists($keys[30], $arr)) { $this->setNotificationOnFlapping($arr[$keys[30]]); } if (array_key_exists($keys[31], $arr)) { $this->setNotificationOnScheduledDowntime($arr[$keys[31]]); } if (array_key_exists($keys[32], $arr)) { $this->setStalkingOnUp($arr[$keys[32]]); } if (array_key_exists($keys[33], $arr)) { $this->setStalkingOnDown($arr[$keys[33]]); } if (array_key_exists($keys[34], $arr)) { $this->setStalkingOnUnreachable($arr[$keys[34]]); } if (array_key_exists($keys[35], $arr)) { $this->setFailurePredictionEnabled($arr[$keys[35]]); } if (array_key_exists($keys[36], $arr)) { $this->setFlapDetectionOnUp($arr[$keys[36]]); } if (array_key_exists($keys[37], $arr)) { $this->setFlapDetectionOnDown($arr[$keys[37]]); } if (array_key_exists($keys[38], $arr)) { $this->setFlapDetectionOnUnreachable($arr[$keys[38]]); } if (array_key_exists($keys[39], $arr)) { $this->setNotes($arr[$keys[39]]); } if (array_key_exists($keys[40], $arr)) { $this->setNotesUrl($arr[$keys[40]]); } if (array_key_exists($keys[41], $arr)) { $this->setActionUrl($arr[$keys[41]]); } if (array_key_exists($keys[42], $arr)) { $this->setIconImage($arr[$keys[42]]); } if (array_key_exists($keys[43], $arr)) { $this->setIconImageAlt($arr[$keys[43]]); } if (array_key_exists($keys[44], $arr)) { $this->setVrmlImage($arr[$keys[44]]); } if (array_key_exists($keys[45], $arr)) { $this->setStatusmapImage($arr[$keys[45]]); } if (array_key_exists($keys[46], $arr)) { $this->setTwoDCoords($arr[$keys[46]]); } if (array_key_exists($keys[47], $arr)) { $this->setThreeDCoords($arr[$keys[47]]); } if (array_key_exists($keys[48], $arr)) { $this->setAutodiscoveryAddressFilter($arr[$keys[48]]); } if (array_key_exists($keys[49], $arr)) { $this->setAutodiscoveryHostnameFilter($arr[$keys[49]]); } if (array_key_exists($keys[50], $arr)) { $this->setAutodiscoveryOsFamilyFilter($arr[$keys[50]]); } if (array_key_exists($keys[51], $arr)) { $this->setAutodiscoveryOsGenerationFilter($arr[$keys[51]]); } if (array_key_exists($keys[52], $arr)) { $this->setAutodiscoveryOsVendorFilter($arr[$keys[52]]); } }