/**
  * 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      NagiosEscalationContactgroup $value A NagiosEscalationContactgroup object.
  * @param      string $key (optional) key to use for instance map (for performance boost if key was already calculated externally).
  */
 public static function addInstanceToPool(NagiosEscalationContactgroup $obj, $key = null)
 {
     if (Propel::isInstancePoolingEnabled()) {
         if ($key === null) {
             $key = (string) $obj->getId();
         }
         // if key === null
         self::$instances[$key] = $obj;
     }
 }
 private function __addContacts($escalation)
 {
     $job = $this->getEngine()->getJob();
     $config = $this->getEngine()->getConfig();
     $segment = $this->getSegment();
     $values = $segment->getValues();
     $fileName = $segment->getFilename();
     // Check if we need to bring in values from a template
     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['contacts'])) {
         $contactNames = explode(",", $values['contacts'][0]['value']);
         foreach ($contactNames as $contact_name) {
             $contact = NagiosContactPeer::getByName($contact_name);
             if (!$contact) {
                 return false;
             }
             $relationship = new NagiosEscalationContact();
             $relationship->setNagiosContact($contact);
             $relationship->setNagiosEscalation($escalation);
             $relationship->save();
             $contact->clearAllReferences(true);
         }
     }
     if (isset($values['contact_groups'])) {
         $contactGroupNames = explode(",", $values['contact_groups'][0]['value']);
         foreach ($contactGroupNames as $contactgroup_name) {
             $contactgroup = NagiosContactGroupPeer::getByName($contactgroup_name);
             if (!$contactgroup) {
                 return false;
             }
             $relationship = new NagiosEscalationContactgroup();
             $relationship->setNagiosContactGroup($contactgroup);
             $relationship->setNagiosEscalation($escalation);
             $relationship->save();
             $contactgroup->clearAllReferences(true);
         }
     }
     return true;
 }
Beispiel #3
0
         if (isset($_POST['escalation_manage']['escalation_options_critical'])) {
             $escalation->setEscalationOptionsCritical(true);
         } else {
             $escalation->setEscalationOptionsCritical(false);
         }
         $escalation->save();
         $success = "Escalation modified.";
         unset($_GET['edit']);
     }
 } else {
     if ($_POST['request'] == 'add_contactgroup_command') {
         if ($lilac->escalation_has_contactgroup($_GET['id'], $_POST['escalation_manage']['contactgroup_add']['contactgroup_id'])) {
             $error = "That contact group already exists in that list!";
             unset($_POST['escalation_manage']);
         } else {
             $membership = new NagiosEscalationContactgroup();
             $membership->setNagiosEscalation($escalation);
             $membership->setContactgroup($_POST['escalation_manage']['contactgroup_add']['contactgroup_id']);
             $membership->save();
             $success = "New Escalation Contact Group Link added.";
             unset($_POST['escalation_manage']);
         }
     } else {
         if ($_POST['request'] == 'add_contact_command') {
             $c = new Criteria();
             $c->add(NagiosEscalationContactPeer::ESCALATION, $_GET['id']);
             $c->add(NagiosEscalationContactPeer::CONTACT, $_POST['escalation_manage']['contact_add']['contact_id']);
             $membership = NagiosEscalationContactPeer::doSelectOne($c);
             if ($membership) {
                 $error = "That contact already exists in that list!";
             } else {
 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.");
 }