Example #1
0
 public function addMemberByName($name)
 {
     $c = new Criteria();
     $c->add(NagiosContactPeer::NAME, $name);
     $contact = NagiosContactPeer::doSelectOne($c);
     if (!empty($contact)) {
         $membership = new NagiosContactGroupMember();
         $membership->setNagiosContactGroup($this);
         $membership->setNagiosContact($contact);
         $membership->save();
         return true;
     }
     return false;
 }
Example #2
0
         $addError = 1;
         $error = "Fields shown are required and cannot be left blank.";
     } else {
         // Check for pre-existing contact with same name
         if ($lilac->contact_exists($tempData['contact_name'])) {
             $error = "A contact with that name already exists!";
         } else {
             $tempContactGroup = $tempData['contact_group'];
             unset($tempData['contact_group']);
             // All is well for error checking, add the contact into the db.
             $contact = $lilac->add_contact($tempData);
             $success = "Contact added";
             if ($tempContactGroup && $tempContactGroup != 0) {
                 $contactGroup = NagiosContactGroupPeer::retrieveByPK($tempContactGroup);
                 if ($contactGroup && $contact) {
                     $contactGroupMember = new NagiosContactGroupMember();
                     $contactGroupMember->setContact($contact->getId());
                     $contactGroupMember->setContactgroup($contactGroup->getId());
                     $contactGroupMember->save();
                 }
             }
             unset($_GET['contact_add']);
         }
     }
 } else {
     if ($_POST['request'] == 'modify_contact') {
         // Error check!
         if (count($tempData)) {
             foreach ($tempData as $tempVariable) {
                 $tempVariable = trim($tempVariable);
             }
 /**
  * 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      NagiosContactGroupMember $value A NagiosContactGroupMember object.
  * @param      string $key (optional) key to use for instance map (for performance boost if key was already calculated externally).
  */
 public static function addInstanceToPool(NagiosContactGroupMember $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()
 {
     $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.");
 }