/**
  * Declares an association between this object and a NagiosContact object.
  *
  * @param      NagiosContact $v
  * @return     NagiosEscalationContact The current object (for fluent API support)
  * @throws     PropelException
  */
 public function setNagiosContact(NagiosContact $v = null)
 {
     if ($v === null) {
         $this->setContact(NULL);
     } else {
         $this->setContact($v->getId());
     }
     $this->aNagiosContact = $v;
     // Add binding for other direction of this n:n relationship.
     // If this object has already been added to the NagiosContact object, it will not be re-added.
     if ($v !== null) {
         $v->addNagiosEscalationContact($this);
     }
     return $this;
 }
Example #2
0
 public function import()
 {
     $engine = $this->getEngine();
     $job = $engine->getJob();
     $job->addNotice("FruityContactImporter beginning to import Contact Configuration.");
     // Contacts
     foreach ($this->dbConn->query("SELECT * FROM nagios_contacts", PDO::FETCH_ASSOC) as $contact) {
         // Check for existing
         if (NagiosContactPeer::getByName($contact['contact_name'])) {
             $job->addNotice("Fruity Contact Importer: Contact " . $contact['contact_name'] . " already exists.  Aborting it's import.");
             continue;
         }
         $newContact = new NagiosContact();
         foreach ($contact as $key => $val) {
             unset($name);
             if ($key == "contact_id") {
                 continue;
             }
             if ($key == "contact_name") {
                 $key = "name";
             }
             if ($key == "host_notification_options_down") {
                 $key = "host_notification_on_down";
             }
             if ($key == "host_notification_options_unreachable") {
                 $key = "host_notification_on_unreachable";
             }
             if ($key == "host_notification_options_recovery") {
                 $key = "host_notification_on_recovery";
             }
             if ($key == "host_notification_options_flapping") {
                 $key = "host_notification_on_flapping";
             }
             if ($key == "service_notification_options_warning") {
                 $key = "service_notification_on_warning";
             }
             if ($key == "service_notification_options_unknown") {
                 $key = "service_notification_on_unknown";
             }
             if ($key == "service_notification_options_critical") {
                 $key = "service_notification_on_critical";
             }
             if ($key == "service_notification_options_recovery") {
                 $key = "service_notification_on_recovery";
             }
             if ($key == "service_notification_options_flapping") {
                 $key = "service_notification_on_flapping";
             }
             if ($key == "host_notification_period") {
                 $name = $this->getTimeperiodNameById($val, $this->dbConn);
                 if ($name) {
                     $newContact->setHostNotificationPeriodByName($name);
                 }
                 continue;
             }
             if ($key == "service_notification_period") {
                 $name = $this->getTimeperiodNameById($val, $this->dbConn);
                 if ($name) {
                     $newContact->setServiceNotificationPeriodByName($name);
                 }
                 continue;
             }
             try {
                 $name = NagiosContactPeer::translateFieldName($key, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_PHPNAME);
             } catch (Exception $e) {
                 $job->addNotice("Fruity Contact Importer: Was unable to store unsupported value: " . $key);
             }
             if (!empty($name)) {
                 $method = "set" . $name;
                 $newContact->{$method}($val);
             }
         }
         $newContact->save();
     }
     // Contact Addresses
     foreach ($this->dbConn->query("SELECT * FROM nagios_contact_addresses", PDO::FETCH_ASSOC) as $address) {
         // Check for required contact
         $name = $this->getContactNameById($address['contact_id'], $this->dbConn);
         if (!$name) {
             $job->addNotice("Fruity Contact Address Importer: Could not find contact with id: " . $address['contact_id']);
             continue;
         }
         $contact = NagiosContactPeer::getByName($name);
         if (!$contact) {
             $job->addNotice("Fruity Contact Address Importer: Could not find contact with name: " . $name);
             continue;
         }
         $newContactAddress = new NagiosContactAddress();
         $newContactAddress->setNagiosContact($contact);
         $newContactAddress->setAddress($address['address']);
         $newContactAddress->save();
     }
     // Contact Notification Commands
     foreach ($this->dbConn->query("SELECT * FROM nagios_contacts_notification_commands", PDO::FETCH_ASSOC) as $notificationCommand) {
         // Check for required contact
         $name = $this->getContactNameById($notificationCommand['contact_id'], $this->dbConn);
         if (!$name) {
             $job->addNotice("Fruity Contact Notification Command Importer: Could not find contact with id: " . $notificationCommand['contact_id']);
             continue;
         }
         $contact = NagiosContactPeer::getByName($name);
         if (!$contact) {
             $job->addNotice("Fruity Contact Notification Command Importer: Could not find contact with name: " . $name);
             continue;
         }
         // Okay, now get the required command
         $name = $this->getCommandNameById($notificationCommand['command_id'], $this->dbConn);
         if (!$name) {
             $job->addNotice("Fruity Crontact Notification Command Importer: Could not find command with id: " . $notificationCommand['contact_id']);
             continue;
         }
         $command = NagiosCommandPeer::getByName($name);
         if (!$contact) {
             $job->addNotice("Fruity Contact Notification Command Importer: Could not find command with name: " . $name);
             continue;
         }
         $newNotificationCommand = new NagiosContactNotificationCommand();
         $newNotificationCommand->setNagiosContact($contact);
         $newNotificationCommand->setNagiosCommand($command);
         $newNotificationCommand->setType($notificationCommand['notification_type']);
         $newNotificationCommand->save();
     }
     // Contact Groups
     foreach ($this->dbConn->query("SELECT * FROM nagios_contactgroups", PDO::FETCH_ASSOC) as $contactGroup) {
         if (NagiosContactGroupPeer::getByName($contactGroup['contactgroup_name'])) {
             $job->addNotice("Fruity Contact Group Importer: Group " . $contactGroup['contactgroup_name'] . "already exists.  Aborting it's import.");
             continue;
         }
         $newContactGroup = new NagiosContactGroup();
         $newContactGroup->setName($contactGroup['contactgroup_name']);
         $newContactGroup->setAlias($contactGroup['alias']);
         $newContactGroup->save();
     }
     // Contact Group Members
     foreach ($this->dbConn->query("SELECT * FROM nagios_contactgroup_membership", PDO::FETCH_ASSOC) as $membership) {
         // Check for required contact
         $name = $this->getContactNameById($membership['contact_id'], $this->dbConn);
         if (!$name) {
             $job->addNotice("Fruity Contact Group Membership Importer: Could not find contact with id: " . $membership['contact_id']);
             continue;
         }
         $contact = NagiosContactPeer::getByName($name);
         if (!$contact) {
             $job->addNotice("Fruity Contact Group Membership Importer: Could not find contact with name: " . $name);
             continue;
         }
         // Okay, now get the required contact group
         $name = $this->getContactGroupNameById($membership['contactgroup_id'], $this->dbConn);
         if (!$name) {
             $job->addNotice("Fruity Contact Group Membership Importer: Could not find contact group with id: " . $membership['contactgroup_id']);
             continue;
         }
         $contactgroup = NagiosContactGroupPeer::getByName($name);
         if (!$contactgroup) {
             $job->addNotice("Fruity Contact Group Membership Importer: Could not find contact group with name: " . $name);
             continue;
         }
         $newMembership = new NagiosContactGroupMember();
         $newMembership->setNagiosContact($contact);
         $newMembership->setNagiosContactGroup($contactgroup);
         $newMembership->save();
     }
     $job->addNotice("FruityContactImporter finished importing Contact Configuration.");
 }
Example #3
0
 /**
  * Adds an object to the instance pool.
  *
  * Propel keeps cached copies of objects in an instance pool when they are retrieved
  * from the database.  In some cases -- especially when you override doSelect*()
  * methods in your stub classes -- you may need to explicitly add objects
  * to the cache in order to ensure that the same objects are always returned by doSelect*()
  * and retrieveByPK*() calls.
  *
  * @param      NagiosContact $value A NagiosContact object.
  * @param      string $key (optional) key to use for instance map (for performance boost if key was already calculated externally).
  */
 public static function addInstanceToPool(NagiosContact $obj, $key = null)
 {
     if (Propel::isInstancePoolingEnabled()) {
         if ($key === null) {
             $key = (string) $obj->getId();
         }
         // if key === null
         self::$instances[$key] = $obj;
     }
 }
Example #4
0
 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 contact template: " . $values['name'][0]['value']);
         NagiosContactImporter::saveTemplate($values['name'][0]['value'], $segment);
         return true;
     }
     $contact = new NagiosContact();
     // 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;
             }
         }
     }
     foreach ($values as $key => $entries) {
         foreach ($entries as $entry) {
             // Skips
             $value = $entry['value'];
             $lineNum = $entry['line'];
             if ($key == 'use' || $key == 'name' || $key == 'register') {
                 continue;
             }
             // Address
             if (strpos($key, "address") === 0) {
                 $contact->addAddress($value);
                 continue;
             }
             if ($key == 'service_notification_options') {
                 $options = explode(",", $entry['value']);
                 foreach ($options as $option) {
                     switch (strtolower(trim($option))) {
                         case 'w':
                             $contact->setServiceNotificationOnWarning(true);
                             break;
                         case 'u':
                             $contact->setServiceNotificationOnUnknown(true);
                             break;
                         case 'c':
                             $contact->setServiceNotificationOnCritical(true);
                             break;
                         case 'r':
                             $contact->setServiceNotificationOnRecovery(true);
                             break;
                         case 'f':
                             $contact->setServiceNotificationOnFlapping(true);
                             break;
                     }
                 }
                 continue;
             }
             if ($key == 'host_notification_options') {
                 $options = explode(",", $entry['value']);
                 foreach ($options as $option) {
                     switch (strtolower(trim($option))) {
                         case 'd':
                             $contact->setHostNotificationOnDown(true);
                             break;
                         case 'u':
                             $contact->setHostNotificationOnUnreachable(true);
                             break;
                         case 'r':
                             $contact->setHostNotificationOnRecovery(true);
                             break;
                         case 'f':
                             $contact->setHostNotificationOnFlapping(true);
                             break;
                         case 's':
                             $contact->setHostNotificationOnScheduledDowntime(true);
                             break;
                     }
                 }
                 continue;
             }
             // Okay, let's check that the method DOES exist
             if (!method_exists($contact, $this->fieldMethods[$key])) {
                 $job->addError("Method " . $this->fieldMethods[$key] . " does not exist for variable: " . $key . " on line " . $lineNum . " in file " . $fileName);
                 if (!$config->getVar('continue_error')) {
                     return false;
                 }
             } else {
                 call_user_method($this->fieldMethods[$key], $contact, $value);
             }
         }
     }
     $contact->save();
     $contact->clearAllReferences(true);
     $job->addNotice("NagiosContactImporter finished importing contact: " . $contact->getName());
     return true;
 }