public static function getByHostTemplateAndDescription($hostTemplateName, $description) { // First get host template $template = NagiosHostTemplatePeer::getByName($hostTemplateName); if (!$template) { return false; } $c = new Criteria(); $c->add(NagiosServicePeer::HOST_TEMPLATE, $template->getId()); $c->add(NagiosServicePeer::DESCRIPTION, $description); $c->setIgnoreCase(true); $service = NagiosServicePeer::doSelectOne($c); if (!$service) { return false; } return $service; }
public function import() { $job = $this->getEngine()->getJob(); $config = $this->getEngine()->getConfig(); $segment = $this->getSegment(); $values = $segment->getValues(); $fileName = $segment->getFilename(); $servicegroup = new NagiosServiceGroup(); 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]); $servicegroup->addService($service); $service->clearAllReferences(true); } } foreach ($values as $key => $entries) { foreach ($entries as $entry) { // Skips $value = $entry['value']; $lineNum = $entry['line']; if ($key == 'members') { // Already did it above continue; } // Okay, let's check that the method DOES exist if (!method_exists($servicegroup, $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], $servicegroup, $value); } } } $servicegroup->save(); $servicegroup->clearAllReferences(true); $job->addNotice("NagiosServiceGroupImporter finished importing service group: " . $servicegroup->getName()); return true; }
public function getValues($inherited = false) { $values = array(); $c = new Criteria(); $c->add(NagiosServiceTemplateInheritancePeer::SOURCE_SERVICE, $this->getId()); $c->addAscendingOrderByColumn(NagiosServiceTemplateInheritancePeer::ORDER); $inheritanceTemplates = NagiosServiceTemplateInheritancePeer::doSelect($c); if (count($inheritanceTemplates)) { // This template has inherited templates, let's bring their values in foreach ($inheritanceTemplates as $inheritanceItem) { $serviceTemplate = $inheritanceItem->getNagiosServiceTemplateRelatedByTargetTemplate(); $templateValues = $serviceTemplate->getValues(true); $values = array_merge($values, $templateValues); } } foreach (NagiosServicePeer::getFieldNames() as $fieldName) { $colName = NagiosServicePeer::translateFieldName($fieldName, BasePeer::TYPE_PHPNAME, BasePeer::TYPE_COLNAME); // At this point, $fieldName is the fieldname for each column in our table record $colName = strtolower(substr($colName, strlen("nagios_service."))); // $colName is now the abbreviated column name. switch ($colName) { case 'maximum_check_attempts': $colName = 'max_check_attempts'; break; } $methodName = "get" . $fieldName; if (method_exists($this, $methodName)) { $val = $this->{$methodName}(); if ($val !== null) { // Yay, let's populate $values[$colName] = array('inherited' => $inherited, 'source' => array('id' => $this->getId(), 'name' => $this->getDescription()), 'value' => $val); } } } return $values; }
/** * If this collection has already been initialized with * an identical criteria, it returns the collection. * Otherwise if this NagiosTimeperiod is new, it will return * an empty collection; or if this NagiosTimeperiod has previously * been saved, it will retrieve related NagiosServicesRelatedByNotificationPeriod from storage. * * This method is protected by default in order to keep the public * api reasonable. You can provide public methods for those you * actually need in NagiosTimeperiod. */ public function getNagiosServicesRelatedByNotificationPeriodJoinNagiosCommandRelatedByEventHandler($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN) { if ($criteria === null) { $criteria = new Criteria(NagiosTimeperiodPeer::DATABASE_NAME); } elseif ($criteria instanceof Criteria) { $criteria = clone $criteria; } if ($this->collNagiosServicesRelatedByNotificationPeriod === null) { if ($this->isNew()) { $this->collNagiosServicesRelatedByNotificationPeriod = array(); } else { $criteria->add(NagiosServicePeer::NOTIFICATION_PERIOD, $this->id); $this->collNagiosServicesRelatedByNotificationPeriod = NagiosServicePeer::doSelectJoinNagiosCommandRelatedByEventHandler($criteria, $con, $join_behavior); } } else { // 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(NagiosServicePeer::NOTIFICATION_PERIOD, $this->id); if (!isset($this->lastNagiosServiceRelatedByNotificationPeriodCriteria) || !$this->lastNagiosServiceRelatedByNotificationPeriodCriteria->equals($criteria)) { $this->collNagiosServicesRelatedByNotificationPeriod = NagiosServicePeer::doSelectJoinNagiosCommandRelatedByEventHandler($criteria, $con, $join_behavior); } } $this->lastNagiosServiceRelatedByNotificationPeriodCriteria = $criteria; return $this->collNagiosServicesRelatedByNotificationPeriod; }
} } // Action Handlers if (isset($_GET['request'])) { if ($_GET['request'] == "delete" && $_GET['section'] == 'groups') { $c = new Criteria(); $c->add(NagiosHostgroupMembershipPeer::HOST, $_GET['id']); $c->add(NagiosHostgroupMembershipPeer::HOSTGROUP, $_GET['hostgroup_id']); $membership = NagiosHostgroupMembershipPeer::doSelectOne($c); if ($membership) { $membership->delete(); $success = "Membership Deleted"; } } else { if ($_GET['request'] == "delete" && $_GET['section'] == 'services') { $service = NagiosServicePeer::retrieveByPK($_GET['service_id']); if ($service) { $service->delete(); $success = "Service Deleted"; } } else { if ($_GET['request'] == "delete" && $_GET['section'] == 'general') { if (!$host->delete()) { $error = "Unable to delete Host. Something depends on it."; } else { $status_msg = "Deleted Host."; unset($_GET['request']); unset($_GET['id']); } } else { if ($_GET['request'] == "delete" && $_GET['section'] == 'inheritance') {
/** * Method perform a DELETE on the database, given a NagiosTimeperiod or Criteria object OR a primary key value. * * @param mixed $values Criteria or NagiosTimeperiod object or primary key or array of primary keys * which is used to create the DELETE statement * @param PropelPDO $con the connection to use * @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows * if supported by native driver or if emulated using Propel. * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function doDelete($values, PropelPDO $con = null) { if ($con === null) { $con = Propel::getConnection(NagiosTimeperiodPeer::DATABASE_NAME, Propel::CONNECTION_WRITE); } if ($values instanceof Criteria) { // invalidate the cache for all objects of this type, since we have no // way of knowing (without running a query) what objects should be invalidated // from the cache based on this Criteria. NagiosTimeperiodPeer::clearInstancePool(); // rename for clarity $criteria = clone $values; } elseif ($values instanceof NagiosTimeperiod) { // invalidate the cache for this single object NagiosTimeperiodPeer::removeInstanceFromPool($values); // create criteria based on pk values $criteria = $values->buildPkeyCriteria(); } else { // it must be the primary key $criteria = new Criteria(self::DATABASE_NAME); $criteria->add(NagiosTimeperiodPeer::ID, (array) $values, Criteria::IN); foreach ((array) $values as $singleval) { // we can invalidate the cache for this single object NagiosTimeperiodPeer::removeInstanceFromPool($singleval); } } // Set the correct dbName $criteria->setDbName(self::DATABASE_NAME); $affectedRows = 0; // initialize var to track total num of affected rows try { // use transaction because $criteria could contain info // for more than one table or we could emulating ON DELETE CASCADE, etc. $con->beginTransaction(); $affectedRows += NagiosTimeperiodPeer::doOnDeleteCascade($criteria, $con); NagiosTimeperiodPeer::doOnDeleteSetNull($criteria, $con); // Because this db requires some delete cascade/set null emulation, we have to // clear the cached instance *after* the emulation has happened (since // instances get re-added by the select statement contained therein). if ($values instanceof Criteria) { NagiosTimeperiodPeer::clearInstancePool(); } else { // it's a PK or object NagiosTimeperiodPeer::removeInstanceFromPool($values); } $affectedRows += BasePeer::doDelete($criteria, $con); // invalidate objects in NagiosTimeperiodEntryPeer instance pool, since one or more of them may be deleted by ON DELETE CASCADE rule. NagiosTimeperiodEntryPeer::clearInstancePool(); // invalidate objects in NagiosTimeperiodExcludePeer instance pool, since one or more of them may be deleted by ON DELETE CASCADE rule. NagiosTimeperiodExcludePeer::clearInstancePool(); // invalidate objects in NagiosTimeperiodExcludePeer instance pool, since one or more of them may be deleted by ON DELETE CASCADE rule. NagiosTimeperiodExcludePeer::clearInstancePool(); // invalidate objects in NagiosContactPeer instance pool, since one or more of them may be deleted by ON DELETE CASCADE rule. NagiosContactPeer::clearInstancePool(); // invalidate objects in NagiosContactPeer instance pool, since one or more of them may be deleted by ON DELETE CASCADE rule. NagiosContactPeer::clearInstancePool(); // invalidate objects in NagiosHostTemplatePeer instance pool, since one or more of them may be deleted by ON DELETE CASCADE rule. NagiosHostTemplatePeer::clearInstancePool(); // invalidate objects in NagiosHostTemplatePeer instance pool, since one or more of them may be deleted by ON DELETE CASCADE rule. NagiosHostTemplatePeer::clearInstancePool(); // invalidate objects in NagiosHostPeer instance pool, since one or more of them may be deleted by ON DELETE CASCADE rule. NagiosHostPeer::clearInstancePool(); // invalidate objects in NagiosHostPeer instance pool, since one or more of them may be deleted by ON DELETE CASCADE rule. NagiosHostPeer::clearInstancePool(); // invalidate objects in NagiosServiceTemplatePeer instance pool, since one or more of them may be deleted by ON DELETE CASCADE rule. NagiosServiceTemplatePeer::clearInstancePool(); // invalidate objects in NagiosServiceTemplatePeer instance pool, since one or more of them may be deleted by ON DELETE CASCADE rule. NagiosServiceTemplatePeer::clearInstancePool(); // invalidate objects in NagiosServicePeer instance pool, since one or more of them may be deleted by ON DELETE CASCADE rule. NagiosServicePeer::clearInstancePool(); // invalidate objects in NagiosServicePeer instance pool, since one or more of them may be deleted by ON DELETE CASCADE rule. NagiosServicePeer::clearInstancePool(); // invalidate objects in NagiosDependencyPeer instance pool, since one or more of them may be deleted by ON DELETE CASCADE rule. NagiosDependencyPeer::clearInstancePool(); // invalidate objects in NagiosEscalationPeer instance pool, since one or more of them may be deleted by ON DELETE CASCADE rule. NagiosEscalationPeer::clearInstancePool(); $con->commit(); return $affectedRows; } catch (PropelException $e) { $con->rollBack(); throw $e; } }
/** * 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 = NagiosServicePeer::getFieldNames($keyType); if (array_key_exists($keys[0], $arr)) { $this->setId($arr[$keys[0]]); } if (array_key_exists($keys[1], $arr)) { $this->setDescription($arr[$keys[1]]); } if (array_key_exists($keys[2], $arr)) { $this->setDisplayName($arr[$keys[2]]); } if (array_key_exists($keys[3], $arr)) { $this->setHost($arr[$keys[3]]); } if (array_key_exists($keys[4], $arr)) { $this->setHostTemplate($arr[$keys[4]]); } if (array_key_exists($keys[5], $arr)) { $this->setHostgroup($arr[$keys[5]]); } if (array_key_exists($keys[6], $arr)) { $this->setInitialState($arr[$keys[6]]); } if (array_key_exists($keys[7], $arr)) { $this->setIsVolatile($arr[$keys[7]]); } if (array_key_exists($keys[8], $arr)) { $this->setCheckCommand($arr[$keys[8]]); } if (array_key_exists($keys[9], $arr)) { $this->setMaximumCheckAttempts($arr[$keys[9]]); } if (array_key_exists($keys[10], $arr)) { $this->setNormalCheckInterval($arr[$keys[10]]); } if (array_key_exists($keys[11], $arr)) { $this->setRetryInterval($arr[$keys[11]]); } if (array_key_exists($keys[12], $arr)) { $this->setFirstNotificationDelay($arr[$keys[12]]); } if (array_key_exists($keys[13], $arr)) { $this->setActiveChecksEnabled($arr[$keys[13]]); } if (array_key_exists($keys[14], $arr)) { $this->setPassiveChecksEnabled($arr[$keys[14]]); } if (array_key_exists($keys[15], $arr)) { $this->setCheckPeriod($arr[$keys[15]]); } if (array_key_exists($keys[16], $arr)) { $this->setParallelizeCheck($arr[$keys[16]]); } if (array_key_exists($keys[17], $arr)) { $this->setObsessOverService($arr[$keys[17]]); } if (array_key_exists($keys[18], $arr)) { $this->setCheckFreshness($arr[$keys[18]]); } if (array_key_exists($keys[19], $arr)) { $this->setFreshnessThreshold($arr[$keys[19]]); } if (array_key_exists($keys[20], $arr)) { $this->setEventHandler($arr[$keys[20]]); } if (array_key_exists($keys[21], $arr)) { $this->setEventHandlerEnabled($arr[$keys[21]]); } if (array_key_exists($keys[22], $arr)) { $this->setLowFlapThreshold($arr[$keys[22]]); } if (array_key_exists($keys[23], $arr)) { $this->setHighFlapThreshold($arr[$keys[23]]); } if (array_key_exists($keys[24], $arr)) { $this->setFlapDetectionEnabled($arr[$keys[24]]); } if (array_key_exists($keys[25], $arr)) { $this->setFlapDetectionOnOk($arr[$keys[25]]); } if (array_key_exists($keys[26], $arr)) { $this->setFlapDetectionOnWarning($arr[$keys[26]]); } if (array_key_exists($keys[27], $arr)) { $this->setFlapDetectionOnCritical($arr[$keys[27]]); } if (array_key_exists($keys[28], $arr)) { $this->setFlapDetectionOnUnknown($arr[$keys[28]]); } if (array_key_exists($keys[29], $arr)) { $this->setProcessPerfData($arr[$keys[29]]); } if (array_key_exists($keys[30], $arr)) { $this->setRetainStatusInformation($arr[$keys[30]]); } if (array_key_exists($keys[31], $arr)) { $this->setRetainNonstatusInformation($arr[$keys[31]]); } if (array_key_exists($keys[32], $arr)) { $this->setNotificationInterval($arr[$keys[32]]); } if (array_key_exists($keys[33], $arr)) { $this->setNotificationPeriod($arr[$keys[33]]); } if (array_key_exists($keys[34], $arr)) { $this->setNotificationOnWarning($arr[$keys[34]]); } if (array_key_exists($keys[35], $arr)) { $this->setNotificationOnUnknown($arr[$keys[35]]); } if (array_key_exists($keys[36], $arr)) { $this->setNotificationOnCritical($arr[$keys[36]]); } if (array_key_exists($keys[37], $arr)) { $this->setNotificationOnRecovery($arr[$keys[37]]); } if (array_key_exists($keys[38], $arr)) { $this->setNotificationOnFlapping($arr[$keys[38]]); } if (array_key_exists($keys[39], $arr)) { $this->setNotificationOnScheduledDowntime($arr[$keys[39]]); } if (array_key_exists($keys[40], $arr)) { $this->setNotificationsEnabled($arr[$keys[40]]); } if (array_key_exists($keys[41], $arr)) { $this->setStalkingOnOk($arr[$keys[41]]); } if (array_key_exists($keys[42], $arr)) { $this->setStalkingOnWarning($arr[$keys[42]]); } if (array_key_exists($keys[43], $arr)) { $this->setStalkingOnUnknown($arr[$keys[43]]); } if (array_key_exists($keys[44], $arr)) { $this->setStalkingOnCritical($arr[$keys[44]]); } if (array_key_exists($keys[45], $arr)) { $this->setFailurePredictionEnabled($arr[$keys[45]]); } if (array_key_exists($keys[46], $arr)) { $this->setNotes($arr[$keys[46]]); } if (array_key_exists($keys[47], $arr)) { $this->setNotesUrl($arr[$keys[47]]); } if (array_key_exists($keys[48], $arr)) { $this->setActionUrl($arr[$keys[48]]); } if (array_key_exists($keys[49], $arr)) { $this->setIconImage($arr[$keys[49]]); } if (array_key_exists($keys[50], $arr)) { $this->setIconImageAlt($arr[$keys[50]]); } }
/** * This is a method for emulating ON DELETE CASCADE for DBs that don't support this * feature (like MySQL or SQLite). * * This method is not very speedy because it must perform a query first to get * the implicated records and then perform the deletes by calling those Peer classes. * * This method should be used within a transaction if possible. * * @param Criteria $criteria * @param PropelPDO $con * @return int The number of affected rows (if supported by underlying database driver). */ protected static function doOnDeleteCascade(Criteria $criteria, PropelPDO $con) { // initialize var to track total num of affected rows $affectedRows = 0; // first find the objects that are implicated by the $criteria $objects = NagiosHostPeer::doSelect($criteria, $con); foreach ($objects as $obj) { // delete related NagiosService objects $c = new Criteria(NagiosServicePeer::DATABASE_NAME); $c->add(NagiosServicePeer::HOST, $obj->getId()); $affectedRows += NagiosServicePeer::doDelete($c, $con); // delete related NagiosHostContactMember objects $c = new Criteria(NagiosHostContactMemberPeer::DATABASE_NAME); $c->add(NagiosHostContactMemberPeer::HOST, $obj->getId()); $affectedRows += NagiosHostContactMemberPeer::doDelete($c, $con); // delete related NagiosDependency objects $c = new Criteria(NagiosDependencyPeer::DATABASE_NAME); $c->add(NagiosDependencyPeer::HOST, $obj->getId()); $affectedRows += NagiosDependencyPeer::doDelete($c, $con); // delete related NagiosDependencyTarget objects $c = new Criteria(NagiosDependencyTargetPeer::DATABASE_NAME); $c->add(NagiosDependencyTargetPeer::TARGET_HOST, $obj->getId()); $affectedRows += NagiosDependencyTargetPeer::doDelete($c, $con); // delete related NagiosEscalation objects $c = new Criteria(NagiosEscalationPeer::DATABASE_NAME); $c->add(NagiosEscalationPeer::HOST, $obj->getId()); $affectedRows += NagiosEscalationPeer::doDelete($c, $con); // delete related NagiosHostContactgroup objects $c = new Criteria(NagiosHostContactgroupPeer::DATABASE_NAME); $c->add(NagiosHostContactgroupPeer::HOST, $obj->getId()); $affectedRows += NagiosHostContactgroupPeer::doDelete($c, $con); // delete related NagiosHostgroupMembership objects $c = new Criteria(NagiosHostgroupMembershipPeer::DATABASE_NAME); $c->add(NagiosHostgroupMembershipPeer::HOST, $obj->getId()); $affectedRows += NagiosHostgroupMembershipPeer::doDelete($c, $con); // delete related NagiosHostCheckCommandParameter objects $c = new Criteria(NagiosHostCheckCommandParameterPeer::DATABASE_NAME); $c->add(NagiosHostCheckCommandParameterPeer::HOST, $obj->getId()); $affectedRows += NagiosHostCheckCommandParameterPeer::doDelete($c, $con); // delete related NagiosHostParent objects $c = new Criteria(NagiosHostParentPeer::DATABASE_NAME); $c->add(NagiosHostParentPeer::CHILD_HOST, $obj->getId()); $affectedRows += NagiosHostParentPeer::doDelete($c, $con); // delete related NagiosHostParent objects $c = new Criteria(NagiosHostParentPeer::DATABASE_NAME); $c->add(NagiosHostParentPeer::PARENT_HOST, $obj->getId()); $affectedRows += NagiosHostParentPeer::doDelete($c, $con); // delete related NagiosHostTemplateInheritance objects $c = new Criteria(NagiosHostTemplateInheritancePeer::DATABASE_NAME); $c->add(NagiosHostTemplateInheritancePeer::SOURCE_HOST, $obj->getId()); $affectedRows += NagiosHostTemplateInheritancePeer::doDelete($c, $con); } return $affectedRows; }
/** * Get the associated NagiosService object * * @param PropelPDO Optional Connection object. * @return NagiosService The associated NagiosService object. * @throws PropelException */ public function getNagiosService(PropelPDO $con = null) { if ($this->aNagiosService === null && $this->source_service !== null) { $c = new Criteria(NagiosServicePeer::DATABASE_NAME); $c->add(NagiosServicePeer::ID, $this->source_service); $this->aNagiosService = NagiosServicePeer::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->aNagiosService->addNagiosServiceTemplateInheritances($this); */ } return $this->aNagiosService; }
/** * 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(NagiosServicePeer::DATABASE_NAME, Propel::CONNECTION_READ); } $objs = null; if (empty($pks)) { $objs = array(); } else { $criteria = new Criteria(NagiosServicePeer::DATABASE_NAME); $criteria->add(NagiosServicePeer::ID, $pks, Criteria::IN); $objs = NagiosServicePeer::doSelect($criteria, $con); } return $objs; }
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; }
$service = new NagiosService(); $service->setDescription($_POST['service_description']); $service->setDisplayName($_POST['display_name']); $service->setHost($host->getId()); $service->save(); header("Location: service.php?id=" . $service->getId()); die; } } else { if (isset($hostgroup)) { // Host logic $c = new Criteria(); $c->add(NagiosServicePeer::DESCRIPTION, $_POST['service_description']); $c->add(NagiosServicePeer::HOSTGROUP, $hostgroup->getId()); $c->setIgnoreCase(true); $service = NagiosServicePeer::doSelectOne($c); if ($service) { $error = "A service with that description already exists for that hostgroup."; } else { // Let's add. $service = new NagiosService(); $service->setDescription($_POST['service_description']); $service->setDisplayName($_POST['display_name']); $service->setHostgroup($hostgroup->getId()); $service->save(); header("Location: service.php?id=" . $service->getId()); die; } } } }
/** * If this collection has already been initialized with * an identical criteria, it returns the collection. * Otherwise if this NagiosHostgroup is new, it will return * an empty collection; or if this NagiosHostgroup has previously * been saved, it will retrieve related NagiosServices from storage. * * This method is protected by default in order to keep the public * api reasonable. You can provide public methods for those you * actually need in NagiosHostgroup. */ public function getNagiosServicesJoinNagiosTimeperiodRelatedByNotificationPeriod($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN) { if ($criteria === null) { $criteria = new Criteria(NagiosHostgroupPeer::DATABASE_NAME); } elseif ($criteria instanceof Criteria) { $criteria = clone $criteria; } if ($this->collNagiosServices === null) { if ($this->isNew()) { $this->collNagiosServices = array(); } else { $criteria->add(NagiosServicePeer::HOSTGROUP, $this->id); $this->collNagiosServices = NagiosServicePeer::doSelectJoinNagiosTimeperiodRelatedByNotificationPeriod($criteria, $con, $join_behavior); } } else { // 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(NagiosServicePeer::HOSTGROUP, $this->id); if (!isset($this->lastNagiosServiceCriteria) || !$this->lastNagiosServiceCriteria->equals($criteria)) { $this->collNagiosServices = NagiosServicePeer::doSelectJoinNagiosTimeperiodRelatedByNotificationPeriod($criteria, $con, $join_behavior); } } $this->lastNagiosServiceCriteria = $criteria; return $this->collNagiosServices; }
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++; } } }
</table> <br /> <br /> [ <a href="add_dependency.php?hostgroup_id=<?php echo $_GET['id']; ?> ">Create A New Dependency For This Hostgroup</a> ] </td> </tr> </table> <?php } else { if ($_GET['section'] == 'services') { $c = new Criteria(); $c->add(NagiosServicePeer::HOSTGROUP, $_GET['id']); $hostgroupServiceList = NagiosServicePeer::doSelect($c); $numOfServices = count($hostgroupServiceList); ?> <table width="100%" border="0"> <tr> <td width="100" align="center" valign="top"> <img src="<?php echo $path_config['image_root']; ?> services.gif" /> </td> <td valign="top"> <table width="100%" align="center" cellspacing="0" cellpadding="2" border="0"> <tr class="altTop"> <td colspan="2">Services Explicitly Linked to This Hostgroup:</td> </tr>
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()); ?> </td> </tr> <tr> <td><strong>Total Nagios Hosts:</strong></td> <td><?php echo NagiosHostPeer::doCount(new Criteria()); ?> </td> </tr> <tr class="odd"> <td><strong>Total Nagios Services:</strong></td> <td><?php echo NagiosServicePeer::doCountAll(); ?> </td> </tr> </table> <?php print_window_footer(); print_footer();
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; }
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 service escalation template: " . $values['name'][0]['value']); NagiosServiceEscalationImporter::saveTemplate($values['name'][0]['value'], $segment); return true; } // 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; } } } // Okay, we first iterate through any possible dependent_host_name's if (isset($values['host_name'])) { $host_names = explode(",", $values['host_name'][0]['value']); foreach ($host_names as $host_name) { $escalation = new NagiosEscalation(); $service = NagiosServicePeer::getByHostAndDescription($host_name, $values['service_description'][0]['value']); if (!$service) { return false; } $escalation->setNagiosService($service); $ret = $this->__process($escalation); if (!$ret) { return false; } $ret = $this->__addContacts($escalation); if (!$ret) { return false; } // Need to give it a temp name $escalation->save(); $escalation->setDescription("Imported Escalation #" . $escalation->getId()); $escalation->save(); $escalation->clearAllReferences(true); $service->clearAllReferences(true); $job->addNotice("NagiosServiceEscalationImporter finished importing Service Escalation for " . $host_name); } } if (isset($values['hostgroup_name'])) { $hostgroup_names = explode(",", $values['hostgroup_name'][0]['value']); foreach ($hostgroup_names as $hostgroup_name) { $escalation = new NagiosEscalation(); $service = NagiosServicePeer::getByHostgroupAndDescription($hostgroup_name, $values['service_description'][0]['value']); if (!$service) { return false; } $escalation->setNagiosService($service); $ret = $this->__process($escalation); if (!$ret) { return false; } $ret = $this->__addContacts($escalation); if (!$ret) { return false; } $escalation->save(); $escalation->setDescription("Imported Escalation #" . $escalation->getId()); $escalation->save(); $escalation->clearAllReferences(true); $service->clearAllReferences(true); $job->addNotice("NagiosServiceEscalationImporter finished importing Service Escalation for hostgroup " . $hostgroup_name); } } return true; }
/** * Selects a collection of NagiosServiceContactGroupMember objects pre-filled with all related objects except NagiosContactGroup. * * @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 NagiosServiceContactGroupMember objects. * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function doSelectJoinAllExceptNagiosContactGroup(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); } NagiosServiceContactGroupMemberPeer::addSelectColumns($c); $startcol2 = NagiosServiceContactGroupMemberPeer::NUM_COLUMNS - NagiosServiceContactGroupMemberPeer::NUM_LAZY_LOAD_COLUMNS; NagiosServicePeer::addSelectColumns($c); $startcol3 = $startcol2 + (NagiosServicePeer::NUM_COLUMNS - NagiosServicePeer::NUM_LAZY_LOAD_COLUMNS); NagiosServiceTemplatePeer::addSelectColumns($c); $startcol4 = $startcol3 + (NagiosServiceTemplatePeer::NUM_COLUMNS - NagiosServiceTemplatePeer::NUM_LAZY_LOAD_COLUMNS); $c->addJoin(array(NagiosServiceContactGroupMemberPeer::SERVICE), array(NagiosServicePeer::ID), $join_behavior); $c->addJoin(array(NagiosServiceContactGroupMemberPeer::TEMPLATE), array(NagiosServiceTemplatePeer::ID), $join_behavior); $stmt = BasePeer::doSelect($c, $con); $results = array(); while ($row = $stmt->fetch(PDO::FETCH_NUM)) { $key1 = NagiosServiceContactGroupMemberPeer::getPrimaryKeyHashFromRow($row, 0); if (null !== ($obj1 = NagiosServiceContactGroupMemberPeer::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 = NagiosServiceContactGroupMemberPeer::getOMClass(); $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1); $obj1 = new $cls(); $obj1->hydrate($row); NagiosServiceContactGroupMemberPeer::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 (NagiosServiceContactGroupMember) to the collection in $obj2 (NagiosService) $obj2->addNagiosServiceContactGroupMember($obj1); } // if joined row is not null // Add objects for joined NagiosServiceTemplate rows $key3 = NagiosServiceTemplatePeer::getPrimaryKeyHashFromRow($row, $startcol3); if ($key3 !== null) { $obj3 = NagiosServiceTemplatePeer::getInstanceFromPool($key3); if (!$obj3) { $omClass = NagiosServiceTemplatePeer::getOMClass(); $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1); $obj3 = new $cls(); $obj3->hydrate($row, $startcol3); NagiosServiceTemplatePeer::addInstanceToPool($obj3, $key3); } // if $obj3 already loaded // Add the $obj1 (NagiosServiceContactGroupMember) to the collection in $obj3 (NagiosServiceTemplate) $obj3->addNagiosServiceContactGroupMember($obj1); } // if joined row is not null $results[] = $obj1; } $stmt->closeCursor(); return $results; }
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 service ext info template: " . $values['name'][0]['value']); NagiosServiceExtInfoImporter::saveTemplate($values['name'][0]['value'], $segment); return true; } // Get our host obj 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; } } } $service = NagiosServicePeer::getByHostAndDescription($values['host_name'][0]['value'], $values['service_description'][0]['value']); foreach ($values as $key => $entries) { foreach ($entries as $entry) { // Skips $value = $entry['value']; $lineNum = $entry['line']; if ($key == 'use' || $key == 'name' || $key == 'register' || $key == 'host_name' || $key == 'service_description') { continue; } // Okay, let's check that the method DOES exist if (!method_exists($service, $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], $service, $value); } } } $service->save(); $service->clearAllReferences(true); $job->addNotice("NagiosServiceExtInfo finished importing extended info for: " . $service->getNagiosHost()->getName() . ":" . $service->getDescription()); return true; }