public function save(PropelPDO $con = null)
 {
     if (NagiosServiceTemplateInheritance::isCircular($this->getTargetTemplate(), $this->getSourceTemplate())) {
         throw new Exception("Adding that inheritance would create a circular chain.");
     } else {
         parent::save($con);
         // Okay, we've saved
     }
 }
Example #2
0
 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;
 }
 /**
  * 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      NagiosServiceTemplateInheritance $value A NagiosServiceTemplateInheritance object.
  * @param      string $key (optional) key to use for instance map (for performance boost if key was already calculated externally).
  */
 public static function addInstanceToPool(NagiosServiceTemplateInheritance $obj, $key = null)
 {
     if (Propel::isInstancePoolingEnabled()) {
         if ($key === null) {
             $key = (string) $obj->getId();
         }
         // if key === null
         self::$instances[$key] = $obj;
     }
 }
Example #4
0
     }
 } else {
     if ($_POST['request'] == "add_template_command") {
         $template = NagiosServiceTemplatePeer::retrieveByPK($_POST['servicemanage']['template_add']['template_id']);
         if (!$template) {
             $error = "That service template is not found.";
         } else {
             // We need to get the count of templates already inherited
             $templateList = $service->getNagiosServiceTemplateInheritances();
             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 NagiosServiceTemplateInheritance();
                 $newInheritance->setNagiosService($service);
                 $newInheritance->setNagiosServiceTemplateRelatedByTargetTemplate($template);
                 $newInheritance->setOrder(count($templateList));
                 try {
                     $newInheritance->save();
                     $success = "Template added to inheritance chain.";
                 } catch (Exception $e) {
                     $error = $e->getMessage();
                 }
             }
         }
     } else {
         if ($_POST['request'] == 'service_template_modify_checks') {
             if (isset($modifiedData['max_check_attempts']) && !is_numeric($modifiedData['max_check_attempts']) || isset($modifiedData['max_check_attempts']) && !($modifiedData['max_check_attempts'] >= 1) || isset($modifiedData['normal_check_interval']) && !is_numeric($modifiedData['normal_check_interval']) || isset($modifiedData['normal_check_interval']) && !($modifiedData['normal_check_interval'] >= 1) || isset($modifiedData['retry_interval']) && !is_numeric($modifiedData['retry_interval']) || isset($modifiedData['retry_interval']) && !($modifiedData['retry_interval'] >= 1) || isset($modifiedData['retry_interval']) && !is_numeric($modifiedData['retry_interval']) || isset($modifiedData['first_notification_delay']) && !is_numeric($modifiedData['first_notification_delay']) || isset($modifiedData['freshness_threshold']) && !($modifiedData['freshness_threshold'] >= 0)) {
                 $addError = 1;
Example #5
0
 function addTemplateInheritance($name)
 {
     // First get the template by name
     $template = NagiosServiceTemplatePeer::getByName($name);
     if (!$template) {
         return false;
     }
     // Check to see if inheritance already exists
     $id = $this->getId();
     if (!empty($id)) {
         $c = new Criteria();
         $c->add(NagiosServiceTemplateInheritancePeer::SOURCE_TEMPLATE, $this->getId());
         $c->add(NagiosServiceTemplateInheritancePeer::TARGET_TEMPLATE, $template->getId());
         $relationship = NagiosServiceTemplateInheritancePeer::doSelectOne($c);
         if ($relationship) {
             return false;
         }
     }
     // Okay, create new one
     $relationship = new NagiosServiceTemplateInheritance();
     $relationship->setNagiosServiceTemplateRelatedBySourceTemplate($this);
     $relationship->setNagiosServiceTemplateRelatedByTargetTemplate($template);
     $relationship->save();
     return true;
 }