예제 #1
0
 /**
  * Gets an array of NagiosHostTemplate 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 NagiosHostTemplatesRelatedByNotificationPeriod 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 NagiosHostTemplate[]
  * @throws     PropelException
  */
 public function getNagiosHostTemplatesRelatedByNotificationPeriod($criteria = null, PropelPDO $con = null)
 {
     if ($criteria === null) {
         $criteria = new Criteria(NagiosTimeperiodPeer::DATABASE_NAME);
     } elseif ($criteria instanceof Criteria) {
         $criteria = clone $criteria;
     }
     if ($this->collNagiosHostTemplatesRelatedByNotificationPeriod === null) {
         if ($this->isNew()) {
             $this->collNagiosHostTemplatesRelatedByNotificationPeriod = array();
         } else {
             $criteria->add(NagiosHostTemplatePeer::NOTIFICATION_PERIOD, $this->id);
             NagiosHostTemplatePeer::addSelectColumns($criteria);
             $this->collNagiosHostTemplatesRelatedByNotificationPeriod = NagiosHostTemplatePeer::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(NagiosHostTemplatePeer::NOTIFICATION_PERIOD, $this->id);
             NagiosHostTemplatePeer::addSelectColumns($criteria);
             if (!isset($this->lastNagiosHostTemplateRelatedByNotificationPeriodCriteria) || !$this->lastNagiosHostTemplateRelatedByNotificationPeriodCriteria->equals($criteria)) {
                 $this->collNagiosHostTemplatesRelatedByNotificationPeriod = NagiosHostTemplatePeer::doSelect($criteria, $con);
             }
         }
     }
     $this->lastNagiosHostTemplateRelatedByNotificationPeriodCriteria = $criteria;
     return $this->collNagiosHostTemplatesRelatedByNotificationPeriod;
 }
예제 #2
0
파일: hosts.php 프로젝트: Evolix/lilac
		[ <a href="hosts.php?id=<?php 
        echo $_GET['id'];
        ?>
&request=delete" onClick="javascript:return confirmDelete();">Delete This Host</a> ]
		<?php 
    }
    if ($_GET['section'] == 'inheritance') {
        $templateInheritances = $host->getNagiosHostTemplateInheritances();
        $numOfTemplates = count($templateInheritances);
        $exclude_list = array();
        if ($numOfTemplates) {
            foreach ($templateInheritances as $template) {
                $exclude_list[] = $template->getId();
            }
        }
        $templateList = NagiosHostTemplatePeer::doSelect(new Criteria());
        ?>
		<table width="100%" border="0">
		<tr>
			<td width="100" align="center" valign="top">
			<img src="<?php 
        echo $host_icon_image;
        ?>
" />
			</td>
			<td valign="top">
			<table width="100%" align="center" cellspacing="0" cellpadding="2" border="0">
				<tr class="altTop">
				<td colspan="4">Host Templates To Inherit From (Top to Bottom):</td>
				</tr>
				<?php 
예제 #3
0
 public static function match(AutodiscoveryDevice $device, NagiosHostTemplate $defaultTemplate = null)
 {
     // Delete previous matches
     $c = new Criteria();
     $c->add(AutodiscoveryDeviceTemplateMatchPeer::DEVICE_ID, $device->getId());
     AutodiscoveryDeviceTemplateMatchPeer::doDelete($c);
     $templates = NagiosHostTemplatePeer::doSelect(new Criteria());
     $templateMatches = array();
     foreach ($templates as $template) {
         $templateValues = $template->getValues();
         $complexity = 0;
         $match = 0;
         $serviceFilters = $template->getNagiosHostTemplateAutodiscoveryServices();
         $inheritedServiceFilters = $template->getInheritedNagiosAutodiscoveryServiceFilters();
         $serviceFilters = array_merge($serviceFilters, $inheritedServiceFilters);
         if (!empty($templateValues['autodiscovery_address_filter']) && $templateValues['autodiscovery_address_filter']['value'] != '') {
             $complexity++;
             if (preg_match($templateValues['autodiscovery_address_filter']['value'], $device->getAddress())) {
                 $match++;
             }
         }
         if (!empty($templateValues['autodiscovery_hostname_filter']) && $templateValues['autodiscovery_hostname_filter']['value'] != '') {
             $complexity++;
             if (preg_match($templateValues['autodiscovery_hostname_filter']['value'], $device->getHostname())) {
                 $match++;
             }
         }
         if (!empty($templateValues['autodiscovery_os_family_filter']) && $templateValues['autodiscovery_os_family_filter']['value'] != '') {
             $complexity++;
             if (preg_match($templateValues['autodiscovery_os_family_filter']['value'], $device->getOsfamily())) {
                 $match++;
             }
         }
         if (!empty($templateValues['autodiscovery_os_generation_filter']) && $templateValues['autodiscovery_os_generation_filter']['value'] != '') {
             $complexity++;
             if (preg_match($templateValues['autodiscovery_os_generation_filter']['value'], $device->getOsgen())) {
                 $match++;
             }
         }
         if (!empty($templateValues['autodiscovery_os_vendor_filter']) && $templateValues['autodiscovery_os_vendor_filter']['value'] != '') {
             $complexity++;
             if (preg_match($templateValues['autodiscovery_os_vendor_filter']['value'], $device->getOsvendor())) {
                 $match++;
             }
         }
         // Checked bases, let's now check service filters
         $complexity += count($serviceFilters);
         foreach ($serviceFilters as $filter) {
             foreach ($device->getAutodiscoveryDeviceServices() as $service) {
                 if ($filter->getPort() == $service->getPort() && $filter->getProtocol() == $service->getProtocol()) {
                     // Okay, we're ALMOST found...let's see if we have any other additional filters.
                     $tempMatch = true;
                     if ($filter->getName() != '') {
                         if (!preg_match($filter->getName(), $service->getName())) {
                             $tempMatch = false;
                         }
                     }
                     if ($filter->getProduct() != '') {
                         if (!preg_match($filter->getProduct(), $service->getProduct())) {
                             $tempMatch = false;
                         }
                     }
                     if ($filter->getVersion() != '') {
                         if (!preg_match($filter->getVersion(), $service->getVersion())) {
                             $tempMatch = false;
                         }
                     }
                     if ($filter->getExtraInformation() != '') {
                         if (!preg_match($filter->getExtraInformation(), $service->getExtraInformation())) {
                             $tempMatch = false;
                         }
                     }
                     if ($tempMatch) {
                         $match++;
                     }
                 }
             }
         }
         // Okay, we got everything, let's determine the percentage.
         if ($complexity == 0) {
             // Blank template, no auto-discovery features used.
             $percentage = 0;
             continue;
         } else {
             $percentage = (int) ((double) $match / (double) $complexity * 100);
         }
         if ($percentage == 0) {
             continue;
         }
         // Store the template into the array
         $templateMatches[$percentage][$complexity][] = $template;
     }
     // Okay, let's now create the matches
     $percentages = array_keys($templateMatches);
     $assigned = false;
     for ($percentageCounter = 0; $percentageCounter < count($percentages); $percentageCounter++) {
         $complexities = array_keys($templateMatches[$percentages[$percentageCounter]]);
         $complexities = array_reverse($complexities);
         for ($complexityCount = 0; $complexityCount < count($complexities); $complexityCount++) {
             foreach ($templateMatches[$percentages[$percentageCounter]][$complexities[$complexityCount]] as $template) {
                 $match = new AutodiscoveryDeviceTemplateMatch();
                 $match->setAutodiscoveryDevice($device);
                 $match->setNagiosHostTemplate($template);
                 $match->setPercent($percentages[$percentageCounter]);
                 $match->setComplexity($complexities[$complexityCount]);
                 $match->save();
                 // Add the highest match as the template to assign
                 if (!$assigned) {
                     $assigned = true;
                     $device->setNagiosHostTemplate($template);
                 }
             }
         }
     }
     // If Not assigned, assign default template
     if (!$assigned && !empty($defaultTemplate)) {
         $device->setNagiosHostTemplate($defaultTemplate);
     }
     $device->save();
 }
예제 #4
0
 /**
  * Gets an array of NagiosHostTemplate 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 NagiosCommand has previously been saved, it will retrieve
  * related NagiosHostTemplatesRelatedByEventHandler from storage. If this NagiosCommand 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 NagiosHostTemplate[]
  * @throws     PropelException
  */
 public function getNagiosHostTemplatesRelatedByEventHandler($criteria = null, PropelPDO $con = null)
 {
     if ($criteria === null) {
         $criteria = new Criteria(NagiosCommandPeer::DATABASE_NAME);
     } elseif ($criteria instanceof Criteria) {
         $criteria = clone $criteria;
     }
     if ($this->collNagiosHostTemplatesRelatedByEventHandler === null) {
         if ($this->isNew()) {
             $this->collNagiosHostTemplatesRelatedByEventHandler = array();
         } else {
             $criteria->add(NagiosHostTemplatePeer::EVENT_HANDLER, $this->id);
             NagiosHostTemplatePeer::addSelectColumns($criteria);
             $this->collNagiosHostTemplatesRelatedByEventHandler = NagiosHostTemplatePeer::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(NagiosHostTemplatePeer::EVENT_HANDLER, $this->id);
             NagiosHostTemplatePeer::addSelectColumns($criteria);
             if (!isset($this->lastNagiosHostTemplateRelatedByEventHandlerCriteria) || !$this->lastNagiosHostTemplateRelatedByEventHandlerCriteria->equals($criteria)) {
                 $this->collNagiosHostTemplatesRelatedByEventHandler = NagiosHostTemplatePeer::doSelect($criteria, $con);
             }
         }
     }
     $this->lastNagiosHostTemplateRelatedByEventHandlerCriteria = $criteria;
     return $this->collNagiosHostTemplatesRelatedByEventHandler;
 }
예제 #5
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(NagiosHostTemplatePeer::DATABASE_NAME, Propel::CONNECTION_READ);
     }
     $objs = null;
     if (empty($pks)) {
         $objs = array();
     } else {
         $criteria = new Criteria(NagiosHostTemplatePeer::DATABASE_NAME);
         $criteria->add(NagiosHostTemplatePeer::ID, $pks, Criteria::IN);
         $objs = NagiosHostTemplatePeer::doSelect($criteria, $con);
     }
     return $objs;
 }
예제 #6
0
파일: search.php 프로젝트: Evolix/lilac
 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++;
         }
     }
 }