Esempio n. 1
0
 /**
  * Returns multi-dimension
  *
  * @param unknown_type $hosttemplateinfo
  * @param unknown_type $hosttemplateinfoSources
  * @return unknown
  */
 public function getValues($inherited = false)
 {
     $values = array();
     $c = new Criteria();
     $c->add(NagiosHostTemplateInheritancePeer::SOURCE_TEMPLATE, $this->getId());
     $c->addAscendingOrderByColumn(NagiosHostTemplateInheritancePeer::ORDER);
     $inheritanceTemplates = NagiosHostTemplateInheritancePeer::doSelect($c);
     if (count($inheritanceTemplates)) {
         // This template has inherited templates, let's bring their values in
         foreach ($inheritanceTemplates as $inheritanceItem) {
             $hostTemplate = $inheritanceItem->getNagiosHostTemplateRelatedByTargetTemplate();
             $templateValues = $hostTemplate->getValues(true);
             $values = array_merge($values, $templateValues);
         }
     }
     foreach (NagiosHostTemplatePeer::getFieldNames() as $fieldName) {
         $colName = NagiosHostTemplatePeer::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_host_template.")));
         // $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->getName()), 'value' => $val);
             }
         }
     }
     return $values;
 }
 private function importHostTemplate($templateData)
 {
     $job = $this->getEngine()->getJob();
     // check to see if we have a template by that name
     if (NagiosHostTemplatePeer::getByName($templateData['template_name'])) {
         $job->addNotice("Fruity Host Template Importer: Template " . $templateData['template_name'] . " already exists.  Aborting it's import.");
         return true;
     }
     $newTemplate = new NagiosHostTemplate();
     $newTemplate->setName($templateData['template_name']);
     // Check to see if we need the template
     if (!empty($templateData['use_template_id'])) {
         $name = $this->getHostTemplateNameById($templateData['use_template_id'], $this->dbConn);
         if (!$name) {
             $job->addNotice("Fruity Host Template Importer:  Could not find template with id: " . $templateData['use_template_id'] . ". Aborting it's import.");
             return false;
         } else {
             // Okay, we got the name, does this template exist?
             $template = NagiosHostTemplatePeer::getByName($name);
             if (!$template) {
                 return false;
             } else {
                 // Create a new inheritance relationship
                 $inheritance = new NagiosHostTemplateInheritance();
                 $inheritance->setNagiosHostTemplateRelatedByTargetTemplate($template);
                 $inheritance->setNagiosHostTemplateRelatedBySourceTemplate($newTemplate);
                 try {
                     $inheritance->save();
                 } catch (Exception $e) {
                     $job->addNotice("Fruity Host Template Importer:  Cannot add inheritance from " . $template->getName() . " to " . $newTemplate->getName());
                 }
             }
         }
     }
     // Okay, start 'er up!
     foreach ($templateData as $key => $val) {
         unset($name);
         if ($key == "host_template_id" || $key == "use_template_id" || $key == "template_name") {
             continue;
         }
         if ($key == "template_description") {
             $key = "description";
         }
         if ($key == "notification_options_down") {
             $key = "notification_on_down";
         }
         if ($key == "notification_options_unreachable") {
             $key = "notification_on_unreachable";
         }
         if ($key == "notification_options_recovery") {
             $key = "notification_on_recovery";
         }
         if ($key == "notification_options_flapping") {
             $key = "notification_on_flapping";
         }
         if ($key == "stalking_options_up") {
             $key = "stalking_on_up";
         }
         if ($key == "stalking_options_down") {
             $key = "stalking_on_down";
         }
         if ($key == "stalking_options_unreachable") {
             $key = "stalking_on_unreachable";
         }
         if ($key == "max_check_attempts") {
             $key = "maximum_check_attempts";
         }
         if ($key == "check_command") {
             $name = $this->getCommandNameById($val);
             if ($name) {
                 $command = NagiosCommandPeer::getByName($name);
                 if ($command) {
                     $newTemplate->setCheckCommand($command->getId());
                 }
             }
             continue;
         }
         if ($key == "check_period") {
             $name = $this->getTimeperiodNameById($val);
             if ($name) {
                 $timeperiod = NagiosTimeperiodPeer::getByName($name);
                 if ($timeperiod) {
                     $newTemplate->setCheckPeriod($timeperiod->getId());
                 }
             }
             continue;
         }
         if ($key == "event_handler") {
             $name = $this->getCommandNameById($val);
             if ($name) {
                 $command = NagiosCommandPeer::getByName($name);
                 if ($command) {
                     $newTemplate->setEventHandler($command->getId());
                 }
             }
             continue;
         }
         if ($key == "notification_period") {
             $name = $this->getTimeperiodNameById($val);
             if ($name) {
                 $timeperiod = NagiosTimeperiodPeer::getByName($name);
                 if ($timeperiod) {
                     $newTemplate->setNotificationPeriod($timeperiod->getId());
                 }
             }
             continue;
         }
         try {
             $name = NagiosHostTemplatePeer::translateFieldName($key, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_PHPNAME);
         } catch (Exception $e) {
             $job->addNotice("Fruity Host Template Importer: Was unable to store unsupported value: " . $key);
         }
         if (!empty($name)) {
             $method = "set" . $name;
             $newTemplate->{$method}($val);
         }
     }
     $newTemplate->save();
     $this->totalImported++;
     return true;
 }
Esempio n. 3
0
 /**
  * Sets a field from the object by name passed in as a string.
  *
  * @param      string $name peer name
  * @param      mixed $value field value
  * @param      string $type The type of fieldname the $name is of:
  *                     one of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME
  *                     BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM
  * @return     void
  */
 public function setByName($name, $value, $type = BasePeer::TYPE_PHPNAME)
 {
     $pos = NagiosHostTemplatePeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
     return $this->setByPosition($pos, $value);
 }