Пример #1
0
 /**
  * Gets an array of NagiosContact objects which contain a foreign key that references this object.
  *
  * If this collection has already been initialized with an identical Criteria, it returns the collection.
  * Otherwise if this NagiosTimeperiod has previously been saved, it will retrieve
  * related NagiosContactsRelatedByServiceNotificationPeriod from storage. If this NagiosTimeperiod is new, it will return
  * an empty collection or the current collection, the criteria is ignored on a new object.
  *
  * @param      PropelPDO $con
  * @param      Criteria $criteria
  * @return     array NagiosContact[]
  * @throws     PropelException
  */
 public function getNagiosContactsRelatedByServiceNotificationPeriod($criteria = null, PropelPDO $con = null)
 {
     if ($criteria === null) {
         $criteria = new Criteria(NagiosTimeperiodPeer::DATABASE_NAME);
     } elseif ($criteria instanceof Criteria) {
         $criteria = clone $criteria;
     }
     if ($this->collNagiosContactsRelatedByServiceNotificationPeriod === null) {
         if ($this->isNew()) {
             $this->collNagiosContactsRelatedByServiceNotificationPeriod = array();
         } else {
             $criteria->add(NagiosContactPeer::SERVICE_NOTIFICATION_PERIOD, $this->id);
             NagiosContactPeer::addSelectColumns($criteria);
             $this->collNagiosContactsRelatedByServiceNotificationPeriod = NagiosContactPeer::doSelect($criteria, $con);
         }
     } else {
         // criteria has no effect for a new object
         if (!$this->isNew()) {
             // 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(NagiosContactPeer::SERVICE_NOTIFICATION_PERIOD, $this->id);
             NagiosContactPeer::addSelectColumns($criteria);
             if (!isset($this->lastNagiosContactRelatedByServiceNotificationPeriodCriteria) || !$this->lastNagiosContactRelatedByServiceNotificationPeriodCriteria->equals($criteria)) {
                 $this->collNagiosContactsRelatedByServiceNotificationPeriod = NagiosContactPeer::doSelect($criteria, $con);
             }
         }
     }
     $this->lastNagiosContactRelatedByServiceNotificationPeriodCriteria = $criteria;
     return $this->collNagiosContactsRelatedByServiceNotificationPeriod;
 }
Пример #2
0
 /**
  * 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(NagiosContactPeer::DATABASE_NAME, Propel::CONNECTION_READ);
     }
     $objs = null;
     if (empty($pks)) {
         $objs = array();
     } else {
         $criteria = new Criteria(NagiosContactPeer::DATABASE_NAME);
         $criteria->add(NagiosContactPeer::ID, $pks, Criteria::IN);
         $objs = NagiosContactPeer::doSelect($criteria, $con);
     }
     return $objs;
 }
Пример #3
0
 public function export()
 {
     // Grab our export job
     $engine = $this->getEngine();
     $job = $engine->getJob();
     $job->addNotice("NagiosContactExporter attempting to export contact configuration.");
     $fp = $this->getOutputFile();
     fputs($fp, "# Written by NagiosContactExporter from " . LILAC_NAME . " " . LILAC_VERSION . " on " . date("F j, Y, g:i a") . "\n\n");
     $contacts = NagiosContactPeer::doSelect(new Criteria());
     foreach ($contacts as $contact) {
         fputs($fp, "define contact {\n");
         $finalArray = array();
         $values = $contact->toArray(BasePeer::TYPE_FIELDNAME);
         foreach ($values as $key => $value) {
             if ($key == 'id' || $key == 'host_notification_on_down' || $key == 'host_notification_on_unreachable' || $key == 'host_notification_on_recovery' || $key == 'host_notification_on_flapping' || $key == 'host_notification_on_scheduled_downtime' || $key == 'service_notification_on_warning' || $key == 'service_notification_on_unknown' || $key == 'service_notification_on_critical' || $key == 'service_notification_on_recovery' || $key == 'service_notification_on_flapping') {
                 continue;
             }
             if ($key == 'name') {
                 $key = 'contact_name';
             }
             if ($value === null) {
                 continue;
             }
             if ($value === false) {
                 $value = '0';
             }
             if ($key == "host_notification_period" || $key == "service_notification_period") {
                 $timeperiod = NagiosTimeperiodPeer::retrieveByPK($value);
                 if (!$timeperiod) {
                     $job->addError("Unable to find timeperiod with id: " . $value . " for " . $key);
                     return false;
                 }
                 $value = $timeperiod->getName();
             }
             $finalArray[$key] = $value;
         }
         foreach ($finalArray as $key => $val) {
             fputs($fp, "\t" . $key . "\t" . $val . "\n");
         }
         // Notification On changes
         if (!$contact->getHostNotificationOnDown() && !$contact->getHostNotificationOnUnreachable() && !$contact->getHostNotificationOnRecovery() && !$contact->getHostNotificationOnFlapping()) {
             // Do nothing
         } else {
             fputs($fp, "\thost_notification_options\t");
             if ($contact->getHostNotificationOnDown()) {
                 fputs($fp, "d");
                 if ($contact->getHostNotificationOnUnreachable() || $contact->getHostNotificationOnRecovery() || $contact->getHostNotificationOnFlapping() || $contact->getHostNotificationOnScheduledDowntime()) {
                     fputs($fp, ",");
                 }
             }
             if ($contact->getHostNotificationOnUnreachable()) {
                 fputs($fp, "u");
                 if ($contact->getHostNotificationOnRecovery() || $contact->getHostNotificationOnFlapping() || $contact->getHostNotificationOnScheduledDowntime()) {
                     fputs($fp, ",");
                 }
             }
             if ($contact->getHostNotificationOnRecovery()) {
                 fputs($fp, "r");
                 if ($contact->getHostNotificationOnFlapping() || $contact->getHostNotificationOnScheduledDowntime()) {
                     fputs($fp, ",");
                 }
             }
             if ($contact->getHostNotificationOnFlapping()) {
                 fputs($fp, "f");
                 if ($contact->getHostNotificationOnScheduledDowntime()) {
                     fputs($fp, ",");
                 }
             }
             if ($contact->getHostNotificationOnScheduledDowntime()) {
                 fputs($fp, "s");
             }
             fputs($fp, "\n");
         }
         if (!$contact->getServiceNotificationOnWarning() && !$contact->getServiceNotificationOnUnknown() && !$contact->getServiceNotificationOnCritical() && !$contact->getServiceNotificationOnRecovery()) {
             // Do nothing
         } else {
             fputs($fp, "\tservice_notification_options\t");
             if ($contact->getServiceNotificationOnWarning()) {
                 fputs($fp, "w");
                 if ($contact->getServiceNotificationOnUnknown() || $contact->getServiceNotificationOnCritical() || $contact->getServiceNotificationOnRecovery()) {
                     fputs($fp, ",");
                 }
             }
             if ($contact->getServiceNotificationOnUnknown()) {
                 fputs($fp, "u");
                 if ($contact->getServiceNotificationOnCritical() || $contact->getServiceNotificationOnRecovery()) {
                     fputs($fp, ",");
                 }
             }
             if ($contact->getServiceNotificationOnCritical()) {
                 fputs($fp, "c");
                 if ($contact->getServiceNotificationOnRecovery() || $contact->getServiceNotificationOnFlapping()) {
                     fputs($fp, ",");
                 }
             }
             if ($contact->getServiceNotificationOnRecovery()) {
                 fputs($fp, "r");
                 if ($contact->getServiceNotificationOnFlapping()) {
                     fputs($fp, ",");
                 }
             }
             if ($contact->getServiceNotificationOnFlapping()) {
                 fputs($fp, "f");
             }
             fputs($fp, "\n");
         }
         // Get notification commands
         $c = new Criteria();
         $c->add(NagiosContactNotificationCommandPeer::TYPE, "host");
         $hostNotificationCommands = $contact->getNagiosContactNotificationCommands($c);
         $c = new Criteria();
         $c->add(NagiosContactNotificationCommandPeer::TYPE, "service");
         $serviceNotificationCommands = $contact->getNagiosContactNotificationCommands($c);
         if (count($hostNotificationCommands)) {
             fputs($fp, "\thost_notification_commands\t");
             $first = true;
             foreach ($hostNotificationCommands as $command) {
                 if (!$first) {
                     fputs($fp, ",");
                 } else {
                     $first = false;
                 }
                 fputs($fp, $command->getNagiosCommand()->getName());
             }
             fputs($fp, "\n");
         }
         if (count($serviceNotificationCommands)) {
             fputs($fp, "\tservice_notification_commands\t");
             $first = true;
             foreach ($serviceNotificationCommands as $command) {
                 if (!$first) {
                     fputs($fp, ",");
                 } else {
                     $first = false;
                 }
                 fputs($fp, $command->getNagiosCommand()->getName());
             }
             fputs($fp, "\n");
         }
         // Get Addresses
         $c = new Criteria();
         $c->addAscendingOrderByColumn(NagiosContactAddressPeer::ID);
         $addresses = $contact->getNagiosContactAddresss($c);
         if (count($addresses)) {
             $counter = 1;
             foreach ($addresses as $address) {
                 fputs($fp, "\taddress" . $counter++ . "\t" . $address->getAddress() . "\n");
             }
         }
         fputs($fp, "}\n");
         fputs($fp, "\n");
     }
     $job->addNotice("NagiosContactExporter complete.");
     return true;
 }
Пример #4
0
 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++;
         }
     }
 }