예제 #1
0
 /**
  * Declares an association between this object and a NagiosTimeperiod object.
  *
  * @param      NagiosTimeperiod $v
  * @return     NagiosEscalation The current object (for fluent API support)
  * @throws     PropelException
  */
 public function setNagiosTimeperiod(NagiosTimeperiod $v = null)
 {
     if ($v === null) {
         $this->setEscalationPeriod(NULL);
     } else {
         $this->setEscalationPeriod($v->getId());
     }
     $this->aNagiosTimeperiod = $v;
     // Add binding for other direction of this n:n relationship.
     // If this object has already been added to the NagiosTimeperiod object, it will not be re-added.
     if ($v !== null) {
         $v->addNagiosEscalation($this);
     }
     return $this;
 }
예제 #2
0
 /**
  * Adds an object to the instance pool.
  *
  * Propel keeps cached copies of objects in an instance pool when they are retrieved
  * from the database.  In some cases -- especially when you override doSelect*()
  * methods in your stub classes -- you may need to explicitly add objects
  * to the cache in order to ensure that the same objects are always returned by doSelect*()
  * and retrieveByPK*() calls.
  *
  * @param      NagiosTimeperiod $value A NagiosTimeperiod object.
  * @param      string $key (optional) key to use for instance map (for performance boost if key was already calculated externally).
  */
 public static function addInstanceToPool(NagiosTimeperiod $obj, $key = null)
 {
     if (Propel::isInstancePoolingEnabled()) {
         if ($key === null) {
             $key = (string) $obj->getId();
         }
         // if key === null
         self::$instances[$key] = $obj;
     }
 }
예제 #3
0
        unset($_GET['timeperiod_id']);
    }
}
if (isset($_POST['request'])) {
    // Load Up The Session Data
    if ($_POST['request'] == 'add_period') {
        // Check for valid field entry
        if (trim($_POST['timeperiod_manage']['timeperiod_name']) == '' || trim($_POST['timeperiod_manage']['alias']) == '') {
            $error = "Fields must be filled in.";
        } else {
            // Check for pre-existing command with same name
            if ($lilac->period_exists($_POST['timeperiod_manage']['timeperiod_name'])) {
                $error = "A time period with that name already exists!";
            } else {
                // All is well for error checking, add the command into the db.
                $timeperiod = new NagiosTimeperiod();
                $timeperiod->setName($_POST['timeperiod_manage']['timeperiod_name']);
                $timeperiod->setAlias($_POST['timeperiod_manage']['alias']);
                $timeperiod->save();
                // Remove session data
                unset($_GET['timeperiod_add']);
                $success = "Time period added.";
            }
        }
    }
}
if (isset($_GET['timeperiod_id'])) {
    $timeperiod = NagiosTimeperiodPeer::retrieveByPK($_GET['timeperiod_id']);
}
// Get list of commands
$lilac->return_period_list($period_list);
예제 #4
0
 public function import()
 {
     $job = $this->getEngine()->getJob();
     $config = $this->getEngine()->getConfig();
     $timePeriod = new NagiosTimeperiod();
     $segment = $this->getSegment();
     // First check if we have a use
     $useTemplate = $segment->get("use");
     if ($useTemplate) {
         // Okay, we need to check to see if we have an existing dependency
         $val = $useTemplate[0]['value'];
         $c = new Criteria();
         $c->add(NagiosTimeperiodPeer::NAME, $val);
         $c->setIgnoreCase(true);
         $dependant = NagiosTimeperiodPeer::doSelectOne($c);
         if ($dependant) {
             // We need to add all the entries from that time period to ours.
             $entries = $dependant->getNagiosTimeperiodEntrys();
             foreach ($entries as $entry) {
                 $tempEntry = new NagiosTimeperiodEntry();
                 $tempEntry->setEntry($entry->getEntry());
                 $tempEntry->setValue($entry->getValue());
                 $timePeriod->addNagiosTimeperiodEntry($tempEntry);
             }
             $exclusions = $dependant->getNagiosTimeperiodExcludesRelatedByTimeperiodId();
             foreach ($exclusions as $exclusion) {
                 $tempExclusion = new NagiosTimeperiodExclude();
                 $tempExclusion->setNagiosTimeperiodRelatedByTimeperiodId($timePeriod);
                 $tempExclusion->setNagiosTimeperiodRelatedByExcludedTimeperiod($exclusion->getNagiosTimeperiodRelatedByExcludedTimePeriod);
             }
             $dependent->clearAllReferences(true);
         }
     }
     $values = $segment->getValues();
     $fileName = $segment->getFilename();
     foreach ($values as $key => $entries) {
         foreach ($entries as $entry) {
             if ($key == "exclude") {
                 continue;
             }
             $value = $entry['value'];
             $lineNum = $entry['line'];
             if ($key == "use") {
                 continue;
             }
             if (key_exists($key, $this->fieldMethods) && $this->fieldMethods[$key] != '') {
                 // Okay, let's check that the method DOES exist
                 if (!method_exists($timePeriod, $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], $timePeriod, $value);
                 }
             } else {
                 // It's an entry. Let's rebuild the string and grab the entry and value
                 // This is pretty hackish
                 $pos = $this->preg_pos("/[0-9]{1,2}:[0-9]{1,2}/", $entry['text']);
                 // Look for the first 00:00
                 $tempLabel = trim(substr($entry['text'], 0, $pos - 1));
                 $commentPos = strpos($entry['text'], ";");
                 if ($commentPos === false) {
                     $commentLength = 0;
                 } else {
                     $commentLength = strlen(substr($entry['text'], $commentPos));
                 }
                 $valLength = strlen($entry['text']) - ($commentLength + $pos);
                 $tempValue = trim(substr($entry['text'], $pos, $valLength));
                 $tempEntry = new NagiosTimeperiodEntry();
                 $tempEntry->setEntry($tempLabel);
                 $tempEntry->setValue($tempValue);
                 $timePeriod->addNagiosTimeperiodEntry($tempEntry);
                 $tempEntry->clearAllReferences(true);
             }
         }
     }
     // Check to see if there is an exclusion
     $excludes = $segment->get("exclude");
     if ($excludes) {
         $val = $excludes[0]['value'];
         // Multiple timeperiods are seperated by a comma
         $timeperiods = explode(",", $val);
         if (count($timeperiods)) {
             foreach ($timeperiods as $timeperiod) {
                 $timeperiod = trim($timeperiod);
                 $c = new Criteria();
                 $c->add(NagiosTimeperiodPeer::NAME, $val);
                 $c->setIgnoreCase(true);
                 $target = NagiosTimeperiodPeer::doSelectOne($c);
                 if (!$target) {
                     $job->addLogEntry("Dependent exclude timeperiod " . $timeperiod . " not found. ", ImportLogEntry::TYPE_NOTICE);
                     return false;
                 } else {
                     $exclusion = new NagiosTimeperiodExclude();
                     $exclusion->setNagiosTimeperiodRelatedByTimeperiodId($timePeriod);
                     $exclusion->setNagiosTimeperiodRelatedByExcludedTimeperiod($target);
                     $exclusion->clearAllReferences(true);
                     $target->clearAllReferences(true);
                 }
             }
         }
     }
     $timePeriod->save();
     $timePeriod->clearAllReferences(true);
     $job->addNotice("NagiosTimePeriodImporter finished importing timeperiod: " . $timePeriod->getName());
     return true;
 }
예제 #5
0
 public function import()
 {
     $engine = $this->getEngine();
     $job = $engine->getJob();
     $job->addNotice("FruityTimeperiodImporter beginning to import Timeperiod Configuration.");
     // Timeperiods
     foreach ($this->dbConn->query("SELECT * FROM nagios_timeperiods", PDO::FETCH_ASSOC) as $timeperiod) {
         // Check for existing timeperiod
         if (NagiosTimeperiodPeer::getByName($timeperiod['timeperiod_name'])) {
             $job->addNotice("Fruity Timeperiod Importer:  The timeperiod " . $timeperiod['timeperiod_name'] . " already exists.  Aborting it's import.");
             continue;
         }
         $newTimeperiod = new NagiosTimeperiod();
         $newTimeperiod->setName($timeperiod['timeperiod_name']);
         $newTimeperiod->setAlias($timeperiod['alias']);
         $newTimeperiod->save();
         if (!empty($timeperiod['sunday'])) {
             $entry = new NagiosTimeperiodEntry();
             $entry->setEntry('sunday');
             $entry->setValue($timeperiod['sunday']);
             $entry->setNagiosTimeperiod($newTimeperiod);
             $entry->save();
         }
         if (!empty($timeperiod['monday'])) {
             $entry = new NagiosTimeperiodEntry();
             $entry->setEntry('monday');
             $entry->setValue($timeperiod['monday']);
             $entry->setNagiosTimeperiod($newTimeperiod);
             $entry->save();
         }
         if (!empty($timeperiod['tuesday'])) {
             $entry = new NagiosTimeperiodEntry();
             $entry->setEntry('tuesday');
             $entry->setValue($timeperiod['tuesday']);
             $entry->setNagiosTimeperiod($newTimeperiod);
             $entry->save();
         }
         if (!empty($timeperiod['wednesday'])) {
             $entry = new NagiosTimeperiodEntry();
             $entry->setEntry('wednesday');
             $entry->setValue($timeperiod['wednesday']);
             $entry->setNagiosTimeperiod($newTimeperiod);
             $entry->save();
         }
         if (!empty($timeperiod['thursday'])) {
             $entry = new NagiosTimeperiodEntry();
             $entry->setEntry('thursday');
             $entry->setValue($timeperiod['thursday']);
             $entry->setNagiosTimeperiod($newTimeperiod);
             $entry->save();
         }
         if (!empty($timeperiod['friday'])) {
             $entry = new NagiosTimeperiodEntry();
             $entry->setEntry('friday');
             $entry->setValue($timeperiod['friday']);
             $entry->setNagiosTimeperiod($newTimeperiod);
             $entry->save();
         }
         if (!empty($timeperiod['saturday'])) {
             $entry = new NagiosTimeperiodEntry();
             $entry->setEntry('saturday');
             $entry->setValue($timeperiod['saturday']);
             $entry->setNagiosTimeperiod($newTimeperiod);
             $entry->save();
         }
     }
     $job->addNotice("FruityTimeperiodImporter finished importing Timeperiod Configuration.");
 }