Esempio n. 1
0
 public function import()
 {
     $job = $this->getEngine()->getJob();
     $config = $this->getEngine()->getConfig();
     $command = new NagiosCommand();
     $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(NagiosCommandPeer::NAME, $val);
         $c->setIgnoreCase(true);
         $dependant = NagiosCommandPeer::doSelectOne($c);
         if ($dependant) {
             $command->setLine($dependant->getLine());
         }
         $dependant->clearAllReferences(true);
     }
     $values = $segment->getValues();
     $fileName = $segment->getFilename();
     $commandLine = array();
     foreach ($values as $key => $entries) {
         foreach ($entries as $entry) {
             $value = $entry['value'];
             $lineNum = $entry['line'];
             if (key_exists($key, $this->fieldMethods) && $this->fieldMethods[$key] != '') {
                 if ($key == "command_line") {
                     // Combine into our line array
                     $commandLine[] = $value;
                     continue;
                 }
                 // Okay, let's check that the method DOES exist
                 if (!method_exists($command, $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], $command, $value);
                 }
             }
         }
     }
     // re-assemble command
     $commandLine = implode(',', $commandLine);
     $command->setLine($commandLine);
     $command->save();
     $command->clearAllReferences(true);
     $job->addNotice("NagiosCommandImporter finished importing command: " . $command->getName());
     return true;
 }
Esempio n. 2
0
 public function import()
 {
     $engine = $this->getEngine();
     $job = $engine->getJob();
     $job->addNotice("FruityCommandImporter beginning to import Command Configuration.");
     foreach ($this->dbConn->query("SELECT * FROM nagios_commands", PDO::FETCH_ASSOC) as $command) {
         $newCommand = new NagiosCommand();
         foreach ($command as $key => $val) {
             unset($name);
             if ($key == "command_id" || $key == "network_id") {
                 continue;
             }
             if ($key == "command_name") {
                 $key = "name";
             }
             if ($key == "command_line") {
                 $key = "line";
             }
             if ($key == "command_desc") {
                 $key = "description";
             }
             try {
                 $name = NagiosCommandPeer::translateFieldName($key, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_PHPNAME);
             } catch (Exception $e) {
                 $job->addNotice("Fruity Command Importer: Was unable to store unsupported value: " . $key);
             }
             if (!empty($name)) {
                 $method = "set" . $name;
                 $newCommand->{$method}($val);
             }
         }
         // Check to see if the command already exists
         if (NagiosCommandPeer::getByName($newCommand->getName())) {
             $job->addNotice("Fruity Command Importer: The command " . $newCommand->getName() . " already exists.  Aborting it's import.");
         } else {
             $newCommand->save();
         }
     }
     $job->addNotice("FruityCommandImporter finished importing Command Configuration.");
 }
Esempio n. 3
0
 /**
  * Declares an association between this object and a NagiosCommand object.
  *
  * @param      NagiosCommand $v
  * @return     NagiosHost The current object (for fluent API support)
  * @throws     PropelException
  */
 public function setNagiosCommandRelatedByEventHandler(NagiosCommand $v = null)
 {
     if ($v === null) {
         $this->setEventHandler(NULL);
     } else {
         $this->setEventHandler($v->getId());
     }
     $this->aNagiosCommandRelatedByEventHandler = $v;
     // Add binding for other direction of this n:n relationship.
     // If this object has already been added to the NagiosCommand object, it will not be re-added.
     if ($v !== null) {
         $v->addNagiosHostRelatedByEventHandler($this);
     }
     return $this;
 }
Esempio n. 4
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      NagiosCommand $value A NagiosCommand object.
  * @param      string $key (optional) key to use for instance map (for performance boost if key was already calculated externally).
  */
 public static function addInstanceToPool(NagiosCommand $obj, $key = null)
 {
     if (Propel::isInstancePoolingEnabled()) {
         if ($key === null) {
             $key = (string) $obj->getId();
         }
         // if key === null
         self::$instances[$key] = $obj;
     }
 }
 /**
  * Declares an association between this object and a NagiosCommand object.
  *
  * @param      NagiosCommand $v
  * @return     NagiosContactNotificationCommand The current object (for fluent API support)
  * @throws     PropelException
  */
 public function setNagiosCommand(NagiosCommand $v = null)
 {
     if ($v === null) {
         $this->setCommand(NULL);
     } else {
         $this->setCommand($v->getId());
     }
     $this->aNagiosCommand = $v;
     // Add binding for other direction of this n:n relationship.
     // If this object has already been added to the NagiosCommand object, it will not be re-added.
     if ($v !== null) {
         $v->addNagiosContactNotificationCommand($this);
     }
     return $this;
 }