Пример #1
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(NagiosEscalationPeer::DATABASE_NAME, Propel::CONNECTION_READ);
     }
     $objs = null;
     if (empty($pks)) {
         $objs = array();
     } else {
         $criteria = new Criteria(NagiosEscalationPeer::DATABASE_NAME);
         $criteria->add(NagiosEscalationPeer::ID, $pks, Criteria::IN);
         $objs = NagiosEscalationPeer::doSelect($criteria, $con);
     }
     return $objs;
 }
 /**
  * Selects a collection of NagiosEscalationContactgroup 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 NagiosEscalationContactgroup 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);
     }
     NagiosEscalationContactgroupPeer::addSelectColumns($c);
     $startcol2 = NagiosEscalationContactgroupPeer::NUM_COLUMNS - NagiosEscalationContactgroupPeer::NUM_LAZY_LOAD_COLUMNS;
     NagiosEscalationPeer::addSelectColumns($c);
     $startcol3 = $startcol2 + (NagiosEscalationPeer::NUM_COLUMNS - NagiosEscalationPeer::NUM_LAZY_LOAD_COLUMNS);
     $c->addJoin(array(NagiosEscalationContactgroupPeer::ESCALATION), array(NagiosEscalationPeer::ID), $join_behavior);
     $stmt = BasePeer::doSelect($c, $con);
     $results = array();
     while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
         $key1 = NagiosEscalationContactgroupPeer::getPrimaryKeyHashFromRow($row, 0);
         if (null !== ($obj1 = NagiosEscalationContactgroupPeer::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 = NagiosEscalationContactgroupPeer::getOMClass();
             $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1);
             $obj1 = new $cls();
             $obj1->hydrate($row);
             NagiosEscalationContactgroupPeer::addInstanceToPool($obj1, $key1);
         }
         // if obj1 already loaded
         // Add objects for joined NagiosEscalation rows
         $key2 = NagiosEscalationPeer::getPrimaryKeyHashFromRow($row, $startcol2);
         if ($key2 !== null) {
             $obj2 = NagiosEscalationPeer::getInstanceFromPool($key2);
             if (!$obj2) {
                 $omClass = NagiosEscalationPeer::getOMClass();
                 $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1);
                 $obj2 = new $cls();
                 $obj2->hydrate($row, $startcol2);
                 NagiosEscalationPeer::addInstanceToPool($obj2, $key2);
             }
             // if $obj2 already loaded
             // Add the $obj1 (NagiosEscalationContactgroup) to the collection in $obj2 (NagiosEscalation)
             $obj2->addNagiosEscalationContactgroup($obj1);
         }
         // if joined row is not null
         $results[] = $obj1;
     }
     $stmt->closeCursor();
     return $results;
 }
Пример #3
0
 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;
 }
Пример #4
0
 /**
  * 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 NagiosEscalations 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 getNagiosEscalationsJoinNagiosHostgroup($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->collNagiosEscalations === null) {
         if ($this->isNew()) {
             $this->collNagiosEscalations = array();
         } else {
             $criteria->add(NagiosEscalationPeer::ESCALATION_PERIOD, $this->id);
             $this->collNagiosEscalations = NagiosEscalationPeer::doSelectJoinNagiosHostgroup($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(NagiosEscalationPeer::ESCALATION_PERIOD, $this->id);
         if (!isset($this->lastNagiosEscalationCriteria) || !$this->lastNagiosEscalationCriteria->equals($criteria)) {
             $this->collNagiosEscalations = NagiosEscalationPeer::doSelectJoinNagiosHostgroup($criteria, $con, $join_behavior);
         }
     }
     $this->lastNagiosEscalationCriteria = $criteria;
     return $this->collNagiosEscalations;
 }
Пример #5
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 = NagiosEscalationPeer::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->setHostTemplate($arr[$keys[2]]);
     }
     if (array_key_exists($keys[3], $arr)) {
         $this->setHost($arr[$keys[3]]);
     }
     if (array_key_exists($keys[4], $arr)) {
         $this->setHostgroup($arr[$keys[4]]);
     }
     if (array_key_exists($keys[5], $arr)) {
         $this->setServiceTemplate($arr[$keys[5]]);
     }
     if (array_key_exists($keys[6], $arr)) {
         $this->setService($arr[$keys[6]]);
     }
     if (array_key_exists($keys[7], $arr)) {
         $this->setFirstNotification($arr[$keys[7]]);
     }
     if (array_key_exists($keys[8], $arr)) {
         $this->setLastNotification($arr[$keys[8]]);
     }
     if (array_key_exists($keys[9], $arr)) {
         $this->setNotificationInterval($arr[$keys[9]]);
     }
     if (array_key_exists($keys[10], $arr)) {
         $this->setEscalationPeriod($arr[$keys[10]]);
     }
     if (array_key_exists($keys[11], $arr)) {
         $this->setEscalationOptionsUp($arr[$keys[11]]);
     }
     if (array_key_exists($keys[12], $arr)) {
         $this->setEscalationOptionsDown($arr[$keys[12]]);
     }
     if (array_key_exists($keys[13], $arr)) {
         $this->setEscalationOptionsUnreachable($arr[$keys[13]]);
     }
     if (array_key_exists($keys[14], $arr)) {
         $this->setEscalationOptionsOk($arr[$keys[14]]);
     }
     if (array_key_exists($keys[15], $arr)) {
         $this->setEscalationOptionsWarning($arr[$keys[15]]);
     }
     if (array_key_exists($keys[16], $arr)) {
         $this->setEscalationOptionsUnknown($arr[$keys[16]]);
     }
     if (array_key_exists($keys[17], $arr)) {
         $this->setEscalationOptionsCritical($arr[$keys[17]]);
     }
 }
Пример #6
0
 /**
  * Get the associated NagiosEscalation object
  *
  * @param      PropelPDO Optional Connection object.
  * @return     NagiosEscalation The associated NagiosEscalation object.
  * @throws     PropelException
  */
 public function getNagiosEscalation(PropelPDO $con = null)
 {
     if ($this->aNagiosEscalation === null && $this->escalation !== null) {
         $c = new Criteria(NagiosEscalationPeer::DATABASE_NAME);
         $c->add(NagiosEscalationPeer::ID, $this->escalation);
         $this->aNagiosEscalation = NagiosEscalationPeer::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->aNagiosEscalation->addNagiosEscalationContacts($this);
         		 */
     }
     return $this->aNagiosEscalation;
 }
Пример #7
0
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/
/*
 * escalation.php
 * Author:	Taylor Dondich (tdondich at gmail.com)
 * Description:
 * 	Provides interface to maintain escalations
 *
*/
include_once 'includes/config.inc';
if (!isset($_GET['id'])) {
    header("Location: welcome.php");
    exit;
} else {
    $escalation = NagiosEscalationPeer::retrieveByPK($_GET['id']);
    if (!$escalation) {
        header("Location: welcome.php");
        exit;
    }
}
// Data preparation
if (!isset($_GET['section'])) {
    $_GET['section'] = 'general';
}
if (isset($_GET['temp_host_id'])) {
    $tempData['escalation_manage']['target_host_id'] = NULL;
}
if (isset($_GET['escalation_add'])) {
    $sublink = "?escalation_add=1";
    if (isset($_GET['host_id'])) {
Пример #8
0
 /**
  * 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;
     }
 }
Пример #9
0
 /**
  * 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;
 }
Пример #10
0
 public function export()
 {
     global $lilac;
     // Grab our export job
     $engine = $this->getEngine();
     $job = $engine->getJob();
     $job->addNotice("NagiosEscalationExporter attempting to export escalation configuration.");
     $fp = $this->getOutputFile();
     fputs($fp, "# Written by NagiosEscalationExporter from " . LILAC_NAME . " " . LILAC_VERSION . " on " . date("F j, Y, g:i a") . "\n\n");
     $hostgroups = NagiosHostgroupPeer::doSelect(new Criteria());
     foreach ($hostgroups as $hostgroup) {
         $job->addNotice("Processing escalations for hostgroup: " . $hostgroup->getName());
         $escalations = $hostgroup->getNagiosEscalations();
         foreach ($escalations as $escalation) {
             $this->_exportEscalation($escalation, "hostgroup", $hostgroup);
         }
     }
     $hosts = NagiosHostPeer::doSelect(new Criteria());
     foreach ($hosts as $host) {
         // Got hosts
         // Get inherited escalations first
         $job->addNotice("Processing escalations for host: " . $host->getName());
         $inheritedEscalations = $host->getInheritedEscalations();
         foreach ($inheritedEscalations as $escalation) {
             $this->_exportEscalation($escalation, "host", $host);
         }
         ${$escalations} = $host->getNagiosEscalations();
         foreach (${$escalations} as $escalation) {
             $this->_exportEscalation($escalation, "host", $host);
         }
         // Get our services
         $inheritedServices = $host->getInheritedServices();
         foreach ($inheritedServices as $service) {
             $job->addNotice("Processing escalations for service: " . $service->getDescription() . " on " . $host->getName());
             $serviceInheritedEscalations = $service->getInheritedEscalations();
             foreach ($serviceInheritedEscalations as $escalation) {
                 $this->_exportEscalation($escalation, "service", $service, $host);
             }
             $c = new Criteria();
             $c->add(NagiosEscalationPeer::HOST, $host->getId());
             $c->add(NagiosEscalationPeer::SERVICE, $service->getId());
             $serviceEscalations = NagiosEscalationPeer::doSelect($c);
             foreach ($serviceEscalations as $escalation) {
                 $this->_exportEscalation($escalation, "service", $service, $host);
             }
         }
         $services = $host->getNagiosServices();
         foreach ($services as $service) {
             $job->addNotice("Processing escalations for service: " . $service->getDescription() . " on " . $host->getName());
             $serviceInheritedEscalations = $service->getInheritedEscalations();
             foreach ($serviceInheritedEscalations as $escalation) {
                 $this->_exportEscalation($escalation, "service", $service, $host);
             }
             $serviceEscalations = $service->getNagiosEscalations();
             foreach ($serviceEscalations as $escalation) {
                 $this->_exportEscalation($escalation, "service", $service, $host);
             }
         }
         $job->addNotice("Completed escalations export for host: " . $host->getName());
     }
     $job->addNotice("NagiosEscalationExporter complete.");
     return true;
 }
Пример #11
0
 public function import()
 {
     $engine = $this->getEngine();
     $job = $engine->getJob();
     $job->addNotice("FruityEscalationImporter beginning to import Dependency Configuration.");
     foreach ($this->dbConn->query("SELECT * FROM nagios_escalations", PDO::FETCH_ASSOC) as $escalation) {
         $newEscalation = new NagiosEscalation();
         if (!empty($escalation['service_id'])) {
             // This is a service escalation
             $lilacService = $this->getLilacServiceById($escalation['service_id']);
             if (!$lilacService) {
                 $job->addNotice("Fruity Escalation Importer: Failed to get Lilac service with an id matching: " . $escalation['service_id']);
                 return true;
             }
             $newEscalation->setService($lilacService->getId());
         } else {
             if (!empty($escalation['host_id'])) {
                 // This is a host escalation
                 $hostName = $this->getHostNameById($escalation['host_id']);
                 $host = NagiosHostPeer::getByName($hostName);
                 if (!$host) {
                     $job->addNotice("Fruity Escalation Importer: Failed to get Lilac host with an name matching: " . $hostName);
                     return true;
                 }
                 $newEscalation->setHost($host->getId());
             } else {
                 if (!empty($escalation['service_template_id'])) {
                     // This is a service template escalation
                     $templateName = $this->getServiceTemplateNameById($escalation['service_template_id']);
                     $template = NagiosServiceTemplatePeer::getByName($templateName);
                     if (!$template) {
                         $job->addNotice("Fruity Escalation Importer: Failed to get Lilac service template with  name matching: " . $templateName);
                         return true;
                     }
                     $newEscalation->setServiceTemplate($template->getId());
                 } else {
                     if (!empty($escalation['host_template_id'])) {
                         // This is for a host template escalation
                         $templateName = $this->getHostTemplateNameById($escalation['host_template_id']);
                         $template = NagiosHostTemplatePeer::getByName($templateName);
                         if (!$template) {
                             $job->addNotice("Fruity Escalation Importer: Failed to get Lilac host template with  name matching: " . $templateName);
                             return true;
                         }
                         $newEscalation->setHostTemplate($template->getId());
                     }
                 }
             }
         }
         foreach ($escalation as $key => $val) {
             unset($name);
             if ($key == "escalation_id" || $key == "host_id" || $key == "host_template_id" || $key == "service_template_id" || $key == "service_id") {
                 continue;
             }
             if ($key == "escalation_description") {
                 $key = "description";
             }
             if ($key == "escalation_period") {
                 $escalationName = $this->getTimeperiodNameById($id);
                 if ($escalationName) {
                     $newEscalation->setEscalationPeriodByName($escalationName);
                 }
                 continue;
             }
             try {
                 $name = NagiosEscalationPeer::translateFieldName($key, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_PHPNAME);
             } catch (Exception $e) {
                 $job->addNotice("Fruity Escalation Importer: Was unable to store unsupported value: " . $key);
             }
             if (!empty($name)) {
                 $method = "set" . $name;
                 $newEscalation->{$method}($val);
             }
         }
         $newEscalation->save();
         // Handle escalation contact groups.
         foreach ($this->dbConn->query("SELECT * FROM nagios_escalation_contactgroups WHERE escalation_id = " . $escalation['escalation_id'], PDO::FETCH_ASSOC) as $contactgroup) {
             $contactgroupName = $this->getContactGroupNameById($contactgroup['contactgroup_id']);
             if ($contactgroupName) {
                 $lilacContactGroup = NagiosContactGroupPeer::getByName($contactgroupName);
                 if ($lilacContactGroup) {
                     $newContactGroup = new NagiosEscalationContactgroup();
                     $newContactGroup->setEscalation($newEscalation->getId());
                     $newContactGroup->setContactgroup($lilacContactGroup->getId());
                     $newContactGroup->save();
                 }
             }
         }
     }
     $job->addNotice("FruityEscalationImporter finished importing Escalation Configuration.");
 }
Пример #12
0
 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;
 }