コード例 #1
0
ファイル: NagiosServiceGroup.php プロジェクト: Evolix/lilac
 public function addMembersByServiceGroup($name)
 {
     // First get servicegroup
     $servicegroup = NagiosServiceGroupPeer::getByName($name);
     if (!$servicegroup) {
         return false;
     }
     // Get the members
     $memberships = $servicegroup->getNagiosServiceGroupMembers();
     foreach ($memberships as $membership) {
         $service = $membership->getNagiosService();
         // Check to see if we already have this in our member list
         $id = $this->getId();
         if (!empty($id)) {
             $c = new Criteria();
             $c->add(NagiosServiceGroupMemberPeer::SERVICE_GROUP, $this->getId());
             $c->add(NagiosServiceGroupMemberPeer::SERVICE, $service->getId());
             $relationship = NagiosServiceGroupMemberPeer::doSelectOne($c);
             if ($relationship) {
                 continue;
             }
         }
         // Create new relationship
         $relationship = new NagiosServiceGroupMember();
         $relationship->setNagiosService($service);
         $relationship->setNagiosServiceGroup($this);
         $relationship->save();
     }
     return true;
 }
コード例 #2
0
 public function valid()
 {
     $values = $this->getSegment()->getValues();
     $job = $this->getEngine()->getJob();
     // Check contact existence
     if (isset($values['members'])) {
         $members = explode(",", $values['members'][0]['value']);
         for ($counter = 0; $counter < count($members); $counter += 2) {
             // Get Service
             $service = NagiosServicePeer::getByHostAndDescription($members[$counter], $members[$counter + 1]);
             if (!$service) {
                 $job->addNotice("The member specified by " . $members[$counter] . ":" . $members[$counter + 1] . " was not found.  Setting this service group as queued.");
                 return false;
             }
         }
     }
     if (isset($values['servicegroup_members'])) {
         foreach ($values['servicegroup_members'] as $serviceGroupValues) {
             $c = new Criteria();
             $c->add(NagiosServiceGroupPeer::NAME, $serviceGroupValues['value']);
             $servicegroup = NagiosServiceGroupPeer::doSelectOne($c);
             if (empty($servicegroup)) {
                 $job->addNotice("The service group specified by " . $serviceGroupValues['value'] . " was not found.  Setting this service group as queued.");
                 return false;
             }
         }
     }
     return true;
 }
コード例 #3
0
 public function getByName($name)
 {
     $c = new Criteria();
     $c->add(NagiosServiceGroupPeer::NAME, $name);
     $c->setIgnoreCase(true);
     $servicegroup = NagiosServiceGroupPeer::doSelectOne($c);
     if (!$servicegroup) {
         return false;
     }
     return $servicegroup;
 }
コード例 #4
0
 public function export()
 {
     // Grab our export job
     $engine = $this->getEngine();
     $job = $engine->getJob();
     $job->addNotice("NagiosServiceGroupExporter attempting to export host group configuration.");
     $fp = $this->getOutputFile();
     fputs($fp, "# Written by NagiosServiceGroupExporter from " . LILAC_NAME . " " . LILAC_VERSION . " on " . date("F j, Y, g:i a") . "\n\n");
     $servicegroups = NagiosServiceGroupPeer::doSelect(new Criteria());
     foreach ($servicegroups as $servicegroup) {
         fputs($fp, "define servicegroup {\n");
         $finalArray = array();
         $values = $servicegroup->toArray(BasePeer::TYPE_FIELDNAME);
         foreach ($values as $key => $value) {
             if ($key == 'id') {
                 continue;
             }
             if ($value === null) {
                 continue;
             }
             if ($value === false) {
                 $value = '0';
             }
             if ($key == "name") {
                 $key = "servicegroup_name";
             }
             $finalArray[$key] = $value;
         }
         foreach ($finalArray as $key => $val) {
             fputs($fp, "\t" . $key . "\t" . $val . "\n");
         }
         fputs($fp, "}\n");
         fputs($fp, "\n");
     }
     $job->addNotice("NagiosServiceGroupExporter complete.");
     return true;
 }
コード例 #5
0
ファイル: NagiosImportEngine.php プロジェクト: Evolix/lilac
 public function init()
 {
     $job = $this->getJob();
     $job->addNotice("NagiosImportEngine Starting...");
     $config = $this->getConfig();
     // Attempt to try and open each config file
     $job->addNotice("Attempting to open " . $config->GetVar('config_file'));
     if (!file_exists($config->getVar('config_file')) || !@fopen($config->getVar('config_file'), "r")) {
         $job->addError("Failed to open " . $config->getVar('config_file'));
         return false;
     }
     $job->addNotice("Attempting to open " . $config->GetVar('cgi_file'));
     if (!file_exists($config->getVar('cgi_file')) || !@fopen($config->getVar('cgi_file'), "r")) {
         $job->addError("Failed to open " . $config->getVar('cgi_file'));
         return false;
     }
     $job->addNotice("Attempting to open " . $config->GetVar('resources_file'));
     if (!file_exists($config->getVar('resources_file')) || !@fopen($config->getVar('resources_file'), "r")) {
         $job->addError("Failed to open " . $config->getVar('resources_file'));
         return false;
     }
     $job->addNotice("Config passed sanity check for Nagios import.  Finished initializing.");
     if ($config->getVar('delete_existing')) {
         $job->addNotice("Removing existing Nagios objects.");
         NagiosTimeperiodPeer::doDeleteAll();
         NagiosCommandPeer::doDeleteAll();
         NagiosContactPeer::doDeleteAll();
         NagiosContactGroupPeer::doDeleteAll();
         NagiosHostTemplatePeer::doDeleteAll();
         NagiosHostPeer::doDeleteAll();
         NagiosHostgroupPeer::doDeleteAll();
         NagiosServiceGroupPeer::doDeleteAll();
         NagiosServiceTemplatePeer::doDeleteAll();
         NagiosServicePeer::doDeleteAll();
         NagiosDependencyPeer::doDeleteAll();
         NagiosDependencyTargetPeer::doDeleteAll();
         NagiosEscalationPeer::doDeleteAll();
     }
     return true;
 }
コード例 #6
0
ファイル: about.php プロジェクト: Evolix/lilac
		<td><?php 
echo NagiosContactGroupPeer::doCount(new Criteria());
?>
</td>
	</tr>
	<tr>
		<td><strong>Total Nagios Host Groups:</strong></td>
		<td><?php 
echo NagiosHostgroupPeer::doCount(new Criteria());
?>
</td>
	</tr>
	<tr class="odd">
		<td><strong>Total Nagios Service Groups:</strong></td>
		<td><?php 
echo NagiosServiceGroupPeer::doCount(new Criteria());
?>
</td>
	</tr>
	<tr>
		<td><strong>Total Nagios Host Templates:</strong></td>
		<td><?php 
echo NagiosHostTemplatePeer::doCount(new Criteria());
?>
</td>
	</tr>
	<tr class="odd">
		<td><strong>Total Nagios Service Templates:</strong></td>
		<td><?php 
echo NagiosServiceTemplatePeer::doCount(new Criteria());
?>
コード例 #7
0
 public function import()
 {
     $engine = $this->getEngine();
     $job = $engine->getJob();
     $job->addNotice("FruityServiceImporter beginning to import Service Configuration.");
     // Services
     foreach ($this->dbConn->query("SELECT * FROM nagios_services", PDO::FETCH_ASSOC) as $service) {
         $this->importService($service);
     }
     // Service template check commands
     $job->addNotice("FruityServiceImporter now processing Service Check Commands.");
     foreach ($this->dbConn->query("SELECT * FROM nagios_services_check_command_parameters WHERE service_id IS NOT NULL", PDO::FETCH_ASSOC) as $commandParameterInfo) {
         $service = $this->getLilacServiceById($commandParameterInfo['service_id']);
         if (!$service) {
             $job->addNotice("Fruity Service Check Command Parameter Importer: Could not find service with id: " . $commandParameterInfo['service_id']);
             continue;
         }
         $newParameter = new NagiosServiceCheckCommandParameter();
         $newParameter->setService($service->getId());
         $newParameter->setParameter($commandParameterInfo['parameter']);
         $newParameter->save();
     }
     // Service extended information
     $job->addNotice("FruityServiceImporter now processing Service Extended Information.");
     foreach ($this->dbConn->query("SELECT * FROM nagios_services_extended_info", PDO::FETCH_ASSOC) as $extInfo) {
         $service = $this->getLilacServiceById($extInfo['service_id']);
         if (!$service) {
             $job->addNotice("Fruity Service Check Command Parameter Importer: Could not find service with id " . $extInfo['service_id']);
             continue;
         }
         // Go through the extended info, and set it on the template.
         $service->setNotes($extInfo['notes']);
         $service->setNotesUrl($extInfo['notes_url']);
         $service->setActionUrl($extInfo['action_url']);
         $service->setIconImage($extInfo['icon_image']);
         $service->setIconImageAlt($extInfo['icon_image_alt']);
         $service->save();
     }
     // Service contact group memberships
     $job->addNotice("FruityServiceImporter now processing Service Contact Group Memberships.");
     foreach ($this->dbConn->query("SELECT * FROM nagios_service_contactgroups", PDO::FETCH_ASSOC) as $membershipInfo) {
         $service = $this->getLilacServiceById($membershipInfo['service_id']);
         if (!$service) {
             $job->addNotice("Fruity Service Check Command Parameter Importer: Could not find service with id " . $membershipInfo['service_id']);
             continue;
         }
         // Now get Contact Group Name
         $contactGroupName = $this->getContactGroupNameById($membershipInfo['contactgroup_id']);
         if (!$contactGroupName) {
             $job->addNotice("Fruity Service Contact Group Importer: Could not find contact group with id: " . $membershipInfo['contactgroup_id']);
             continue;
         }
         $contactGroup = NagiosContactGroupPeer::getByName($contactGroupName);
         if (!$contactGroup) {
             $job->addNotice("Fruity Service Contact Group Importer: Could not find contact group with name: " . $contactGroupName);
             continue;
         }
         $membership = new NagiosServiceContactGroupMember();
         $membership->setService($service->getId());
         $membership->setNagiosContactGroup($contactGroup);
         $membership->save();
     }
     // Service service group memberships
     $job->addNotice("FruityServiceImporter now processing Service Service Group Memberships.");
     foreach ($this->dbConn->query("SELECT * FROM nagios_servicegroup_membership", PDO::FETCH_ASSOC) as $membershipInfo) {
         $service = $this->getLilacServiceById($membershipInfo['service_id']);
         if (!$service) {
             $job->addNotice("Fruity Service Check Command Parameter Importer: Could not find service with id " . $membershipInfo['service_id']);
             continue;
         }
         // Now get Contact Group Name
         $serviceGroupName = $this->getServiceGroupNameById($membershipInfo['servicegroup_id']);
         if (!$serviceGroupName) {
             $job->addNotice("Fruity Service Service Group Importer: Could not find service group with id: " . $membershipInfo['servicegroup_id']);
             continue;
         }
         $serviceGroup = NagiosServiceGroupPeer::getByName($serviceGroupName);
         if (!$contactGroup) {
             $job->addNotice("Fruity Service Service Group Importer: Could not find service group with name: " . $serviceGroupName);
             continue;
         }
         $membership = new NagiosServiceGroupMember();
         $membership->setService($service->getId());
         $membership->setNagiosServiceGroup($serviceGroup);
         $membership->save();
     }
     $job->addNotice("FruityServiceImporter finished importing Service Group Configuration.");
     $job->addNotice("FruityServiceImporter imported a total of " . $this->totalImported . " services.");
 }
コード例 #8
0
 /**
  * Get the associated NagiosServiceGroup object
  *
  * @param      PropelPDO Optional Connection object.
  * @return     NagiosServiceGroup The associated NagiosServiceGroup object.
  * @throws     PropelException
  */
 public function getNagiosServiceGroup(PropelPDO $con = null)
 {
     if ($this->aNagiosServiceGroup === null && $this->service_group !== null) {
         $c = new Criteria(NagiosServiceGroupPeer::DATABASE_NAME);
         $c->add(NagiosServiceGroupPeer::ID, $this->service_group);
         $this->aNagiosServiceGroup = NagiosServiceGroupPeer::doSelectOne($c, $con);
         /* The following can be used additionally to
         		   guarantee the related object contains a reference
         		   to this object.  This level of coupling may, however, be
         		   undesirable since it could result in an only partially populated collection
         		   in the referenced object.
         		   $this->aNagiosServiceGroup->addNagiosServiceGroupMembers($this);
         		 */
     }
     return $this->aNagiosServiceGroup;
 }
コード例 #9
0
 /**
  * Populates the object using an array.
  *
  * This is particularly useful when populating an object from one of the
  * request arrays (e.g. $_POST).  This method goes through the column
  * names, checking to see whether a matching key exists in populated
  * array. If so the setByName() method is called for that column.
  *
  * You can specify the key type of the array by additionally passing one
  * of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME,
  * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
  * The default key type is the column's phpname (e.g. 'AuthorId')
  *
  * @param      array  $arr     An array to populate the object from.
  * @param      string $keyType The type of keys the array uses.
  * @return     void
  */
 public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
 {
     $keys = NagiosServiceGroupPeer::getFieldNames($keyType);
     if (array_key_exists($keys[0], $arr)) {
         $this->setId($arr[$keys[0]]);
     }
     if (array_key_exists($keys[1], $arr)) {
         $this->setName($arr[$keys[1]]);
     }
     if (array_key_exists($keys[2], $arr)) {
         $this->setAlias($arr[$keys[2]]);
     }
     if (array_key_exists($keys[3], $arr)) {
         $this->setNotes($arr[$keys[3]]);
     }
     if (array_key_exists($keys[4], $arr)) {
         $this->setNotesUrl($arr[$keys[4]]);
     }
     if (array_key_exists($keys[5], $arr)) {
         $this->setActionUrl($arr[$keys[5]]);
     }
 }
コード例 #10
0
ファイル: servicegroups.php プロジェクト: Evolix/lilac
/*
Lilac Service Groups Management Page
*/
include_once 'includes/config.inc';
require_once 'NagiosServiceGroupMember.php';
// SF BUG# 1449764
// servicegroup session data not being unset
// Resolution:
// if(!isset($_GET['id']))
// unset($serviceGroup);
if (!isset($_GET['section']) && isset($_GET['id'])) {
    $_GET['section'] = 'general';
}
// If we're going to modify servicegroup data
if (isset($_GET['id'])) {
    $serviceGroup = NagiosServiceGroupPeer::retrieveByPK($_GET['id']);
    if (!$serviceGroup) {
        header("Location: welcome.php");
        die;
    }
}
// Action Handlers
if (isset($_GET['request'])) {
    if ($_GET['request'] == "delete" && $_GET['section'] == 'members') {
        // !!!!!!!!!!!!!! This is where we do dependency error checking
        $membership = NagiosServiceGroupMemberPeer::retrieveByPK($_GET['member_id']);
        if ($membership) {
            $membership->delete();
            $success = "Member Deleted";
        }
    }
コード例 #11
0
ファイル: FruityImportEngine.php プロジェクト: Evolix/lilac
 public function import()
 {
     $job = $this->getJob();
     $job->addNotice("FruityImportEngine beginning import...");
     $config = $this->getConfig();
     $job->addNotice("Removing existing Nagios objects.");
     NagiosTimeperiodPeer::doDeleteAll();
     NagiosCommandPeer::doDeleteAll();
     NagiosContactPeer::doDeleteAll();
     NagiosContactGroupPeer::doDeleteAll();
     NagiosHostTemplatePeer::doDeleteAll();
     NagiosHostPeer::doDeleteAll();
     NagiosHostgroupPeer::doDeleteAll();
     NagiosServiceGroupPeer::doDeleteAll();
     NagiosServiceTemplatePeer::doDeleteAll();
     NagiosServicePeer::doDeleteAll();
     NagiosDependencyPeer::doDeleteAll();
     NagiosDependencyTargetPeer::doDeleteAll();
     NagiosEscalationPeer::doDeleteAll();
     NagiosBrokerModulePeer::doDeleteAll();
     NagiosMainConfigurationPeer::doDeleteAll();
     NagiosCgiConfigurationPeer::doDeleteAll();
     $importer = new FruityResourceImporter($this, $this->dbConn);
     $importer->import();
     $importer = new FruityCgiImporter($this, $this->dbConn);
     $importer->import();
     $importer = new FruityCommandImporter($this, $this->dbConn);
     $importer->import();
     $importer = new FruityTimeperiodImporter($this, $this->dbConn);
     $importer->import();
     $importer = new FruityContactImporter($this, $this->dbConn);
     $importer->import();
     $importer = new FruityServiceGroupImporter($this, $this->dbConn);
     $importer->import();
     $importer = new FruityServiceTemplateImporter($this, $this->dbConn);
     $importer->import();
     $importer = new FruityHostTemplateImporter($this, $this->dbConn);
     $importer->import();
     $importer = new FruityHostGroupImporter($this, $this->dbConn);
     $importer->import();
     $importer = new FruityHostImporter($this, $this->dbConn);
     $importer->import();
     $importer = new FruityServiceImporter($this, $this->dbConn);
     $importer->import();
     $importer = new FruityDependencyImporter($this, $this->dbConn);
     $importer->import();
     $importer = new FruityEscalationImporter($this, $this->dbConn);
     $importer->import();
     $importer = new FruityMainImporter($this, $this->dbConn);
     $importer->import();
     $job->addNotice("FruityImportEngine completed job.");
     return true;
 }
コード例 #12
0
 function addServicegroupByName($name)
 {
     $c = new Criteria();
     $c->add(NagiosServiceGroupPeer::NAME, $name);
     $c->setIgnoreCase(true);
     $servicegroup = NagiosServiceGroupPeer::doSelectOne($c);
     if (!$servicegroup) {
         return false;
     }
     // Okay, servicegroup is valid, check for relationship
     $id = $this->getId();
     if (!empty($id)) {
         $c = new Criteria();
         $c->add(NagiosServiceGroupMemberPeer::TEMPLATE, $this->getId());
         $c->add(NagiosServiceGroupMemberPeer::SERVICE_GROUP, $servicegroup->getId());
         $relationship = NagiosServiceGroupMemberPeer::doSelectOne($c);
         if ($relationship) {
             return false;
         }
     }
     $relationship = new NagiosServiceGroupMember();
     $relationship->setNagiosServiceTemplate($this);
     $relationship->setNagiosServiceGroup($servicegroup);
     $relationship->save();
     return true;
 }
コード例 #13
0
 public function valid()
 {
     $values = $this->getSegment()->getValues();
     $job = $this->getEngine()->getJob();
     if (isset($values['use'])) {
         // We need to use a template
         $job->addNotice("This Service uses a template: " . $values['use'][0]['value']);
         $template = NagiosServiceTemplatePeer::getByName($values['use'][0]['value']);
         if (empty($template)) {
             $job->addNotice("That template is not found yet. Setting this service as queued.");
             return false;
         }
         $template->clearAllReferences(true);
     }
     // Check time period existence
     if (isset($values['check_period'])) {
         $c = new Criteria();
         $c->add(NagiosTimeperiodPeer::NAME, $values['check_period'][0]['value']);
         $timePeriod = NagiosTimeperiodPeer::doSelectOne($c);
         if (empty($timePeriod)) {
             $job->addNotice("The time period specified by " . $values['check_period'][0]['value'] . " was not found.  Setting this service as queued.");
             return false;
         }
         $timePeriod->clearAllReferences(true);
     }
     if (isset($values['notification_period'])) {
         $c = new Criteria();
         $c->add(NagiosTimeperiodPeer::NAME, $values['notification_period'][0]['value']);
         $timePeriod = NagiosTimeperiodPeer::doSelectOne($c);
         if (empty($timePeriod)) {
             $job->addNotice("The time period specified by " . $values['notification_period'][0]['value'] . " was not found.  Setting this service as queued.");
             return false;
         }
         $timePeriod->clearAllReferences(true);
     }
     // Check command existence
     if (isset($values['check_command'])) {
         $params = explode('!', $values['check_command'][0]['value']);
         $c = new Criteria();
         $c->add(NagiosCommandPeer::NAME, $params[0]);
         $command = NagiosCommandPeer::doSelectOne($c);
         if (empty($command)) {
             $job->addNotice("The command specified by " . $params[0] . " was not found.  Setting this service as queued.");
             return false;
         }
         $command->clearAllReferences(true);
     }
     if (isset($values['event_handler'])) {
         $c = new Criteria();
         $c->add(NagiosCommandPeer::NAME, $values['event_handler'][0]['value']);
         $command = NagiosCommandPeer::doSelectOne($c);
         if (empty($command)) {
             $job->addNotice("The command specified by " . $values['event_handler'][0]['value'] . " was not found.  Setting this service as queued.");
             return false;
         }
         $command->clearAllReferences(true);
     }
     // Check contact groups
     if (isset($values['contact_groups'])) {
         foreach ($values['contact_groups'] as $contactGroupValues) {
             $c = new Criteria();
             $c->add(NagiosContactGroupPeer::NAME, $contactGroupValues['value']);
             $contactgroup = NagiosContactGroupPeer::doSelectOne($c);
             if (empty($contactgroup)) {
                 $job->addNotice("The contact group specified by " . $contactGroupValues['value'] . " was not found.  Setting this service as queued.");
                 return false;
             }
             $contactgroup->clearAllReferences(true);
         }
     }
     if (isset($values['contacts'])) {
         foreach ($values['contacts'] as $contactValues) {
             $c = new Criteria();
             $c->add(NagiosContactPeer::NAME, $contactValues['value']);
             $contactgroup = NagiosContactPeer::doSelectOne($c);
             if (empty($contactgroup)) {
                 $job->addNotice("The contact specified by " . $contactValues['value'] . " was not found.  Setting this service as queued.");
                 return false;
             }
             $contactgroup->clearAllReferences(true);
         }
     }
     // Check host groups
     if (isset($values['servicegroups'])) {
         foreach ($values['servicegroups'] as $serviceGroupValues) {
             $c = new Criteria();
             $c->add(NagiosServiceGroupPeer::NAME, $serviceGroupValues['value']);
             $servicegroup = NagiosServiceGroupPeer::doSelectOne($c);
             if (empty($servicegroup)) {
                 $job->addNotice("The service group specified by " . $serviceGroupValues['value'] . " was not found.  Setting this service as queued.");
                 return false;
             }
             $servicegroup->clearAllReferences(true);
         }
     }
     // Check for hosts
     if (isset($values['host_name'])) {
         foreach ($values['host_name'] as $hostValues) {
             $host = NagiosHostPeer::getByName($hostValues['value']);
             if (empty($host)) {
                 $job->addNotice("The host specified by " . $hostValues['value'] . " was not found.  Setting this service as queued.");
                 return false;
             }
             $host->clearAllReferences(true);
         }
     }
     // Check for hostgroup_name
     if (isset($values['hostgroup_name'])) {
         foreach ($values['hostgroup_name'] as $hostgroupValues) {
             $hostgroup = NagiosHostgroupPeer::getByName($hostgroupValues['value']);
             if (empty($hostgroup)) {
                 $job->addNotice("The host group specified by " . $hostgroupValues['value'] . " was not found.  Setting this service as queued.");
                 return false;
             }
             $hostgroup->clearAllReferences(true);
         }
     }
     // Check for hostgroup_name
     if (isset($values['hostgroup'])) {
         foreach ($values['hostgroup'] as $hostgroupValues) {
             $hostgroup = NagiosHostgroupPeer::getByName($hostgroupValues['value']);
             if (empty($hostgroup)) {
                 $job->addNotice("The host group specified by " . $hostgroupValues['value'] . " was not found.  Setting this service as queued.");
                 return false;
             }
             $hostgroup->clearAllReferences(true);
         }
     }
     return true;
 }
コード例 #14
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(NagiosServiceGroupPeer::DATABASE_NAME, Propel::CONNECTION_READ);
     }
     $objs = null;
     if (empty($pks)) {
         $objs = array();
     } else {
         $criteria = new Criteria(NagiosServiceGroupPeer::DATABASE_NAME);
         $criteria->add(NagiosServiceGroupPeer::ID, $pks, Criteria::IN);
         $objs = NagiosServiceGroupPeer::doSelect($criteria, $con);
     }
     return $objs;
 }
コード例 #15
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++;
         }
     }
 }
コード例 #16
0
 /**
  * Selects a collection of NagiosServiceGroupMember objects pre-filled with all related objects except NagiosServiceTemplate.
  *
  * @param      Criteria  $c
  * @param      PropelPDO $con
  * @param      String    $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN
  * @return     array Array of NagiosServiceGroupMember objects.
  * @throws     PropelException Any exceptions caught during processing will be
  *		 rethrown wrapped into a PropelException.
  */
 public static function doSelectJoinAllExceptNagiosServiceTemplate(Criteria $c, $con = null, $join_behavior = Criteria::LEFT_JOIN)
 {
     $c = clone $c;
     // Set the correct dbName if it has not been overridden
     // $c->getDbName() will return the same object if not set to another value
     // so == check is okay and faster
     if ($c->getDbName() == Propel::getDefaultDB()) {
         $c->setDbName(self::DATABASE_NAME);
     }
     NagiosServiceGroupMemberPeer::addSelectColumns($c);
     $startcol2 = NagiosServiceGroupMemberPeer::NUM_COLUMNS - NagiosServiceGroupMemberPeer::NUM_LAZY_LOAD_COLUMNS;
     NagiosServicePeer::addSelectColumns($c);
     $startcol3 = $startcol2 + (NagiosServicePeer::NUM_COLUMNS - NagiosServicePeer::NUM_LAZY_LOAD_COLUMNS);
     NagiosServiceGroupPeer::addSelectColumns($c);
     $startcol4 = $startcol3 + (NagiosServiceGroupPeer::NUM_COLUMNS - NagiosServiceGroupPeer::NUM_LAZY_LOAD_COLUMNS);
     $c->addJoin(array(NagiosServiceGroupMemberPeer::SERVICE), array(NagiosServicePeer::ID), $join_behavior);
     $c->addJoin(array(NagiosServiceGroupMemberPeer::SERVICE_GROUP), array(NagiosServiceGroupPeer::ID), $join_behavior);
     $stmt = BasePeer::doSelect($c, $con);
     $results = array();
     while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
         $key1 = NagiosServiceGroupMemberPeer::getPrimaryKeyHashFromRow($row, 0);
         if (null !== ($obj1 = NagiosServiceGroupMemberPeer::getInstanceFromPool($key1))) {
             // We no longer rehydrate the object, since this can cause data loss.
             // See http://propel.phpdb.org/trac/ticket/509
             // $obj1->hydrate($row, 0, true); // rehydrate
         } else {
             $omClass = NagiosServiceGroupMemberPeer::getOMClass();
             $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1);
             $obj1 = new $cls();
             $obj1->hydrate($row);
             NagiosServiceGroupMemberPeer::addInstanceToPool($obj1, $key1);
         }
         // if obj1 already loaded
         // Add objects for joined NagiosService rows
         $key2 = NagiosServicePeer::getPrimaryKeyHashFromRow($row, $startcol2);
         if ($key2 !== null) {
             $obj2 = NagiosServicePeer::getInstanceFromPool($key2);
             if (!$obj2) {
                 $omClass = NagiosServicePeer::getOMClass();
                 $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1);
                 $obj2 = new $cls();
                 $obj2->hydrate($row, $startcol2);
                 NagiosServicePeer::addInstanceToPool($obj2, $key2);
             }
             // if $obj2 already loaded
             // Add the $obj1 (NagiosServiceGroupMember) to the collection in $obj2 (NagiosService)
             $obj2->addNagiosServiceGroupMember($obj1);
         }
         // if joined row is not null
         // Add objects for joined NagiosServiceGroup rows
         $key3 = NagiosServiceGroupPeer::getPrimaryKeyHashFromRow($row, $startcol3);
         if ($key3 !== null) {
             $obj3 = NagiosServiceGroupPeer::getInstanceFromPool($key3);
             if (!$obj3) {
                 $omClass = NagiosServiceGroupPeer::getOMClass();
                 $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1);
                 $obj3 = new $cls();
                 $obj3->hydrate($row, $startcol3);
                 NagiosServiceGroupPeer::addInstanceToPool($obj3, $key3);
             }
             // if $obj3 already loaded
             // Add the $obj1 (NagiosServiceGroupMember) to the collection in $obj3 (NagiosServiceGroup)
             $obj3->addNagiosServiceGroupMember($obj1);
         }
         // if joined row is not null
         $results[] = $obj1;
     }
     $stmt->closeCursor();
     return $results;
 }