Пример #1
0
 function addTemplateInheritance($name)
 {
     // First get the template by name
     $template = NagiosHostTemplatePeer::getByName($name);
     if (!$template) {
         return false;
     }
     // Check to see if inheritance already exists
     $id = $this->getId();
     if (!empty($id)) {
         $c = new Criteria();
         $c->add(NagiosHostTemplateInheritancePeer::SOURCE_TEMPLATE, $this->getId());
         $c->add(NagiosHostTemplateInheritancePeer::TARGET_TEMPLATE, $template->getId());
         $relationship = NagiosHostTemplateInheritancePeer::doSelectOne($c);
         if ($relationship) {
             return false;
         }
     }
     // Okay, create new one
     $relationship = new NagiosHostTemplateInheritance();
     $relationship->setNagiosHostTemplateRelatedBySourceTemplate($this);
     $relationship->setNagiosHostTemplateRelatedByTargetTemplate($template);
     $relationship->save();
     return true;
 }
Пример #2
0
 } else {
     if ($_POST['request'] == "add_template_command") {
         $template = NagiosHostTemplatePeer::retrieveByPK($_POST['hostmanage']['template_add']['template_id']);
         if (!$template) {
             $error = "That host template is not found.";
         } else {
             // We need to get the count of templates already inherited
             $templateList = $hostTemplate->getNagiosHostTemplateInheritances();
             foreach ($templateList as $tempTemplate) {
                 if ($tempTemplate->getId() == $_POST['hostmanage']['template_add']['template_id']) {
                     $error = "That template already exists in the inheritance chain.";
                 }
             }
             if (empty($error)) {
                 $newInheritance = new NagiosHostTemplateInheritance();
                 $newInheritance->setNagiosHostTemplateRelatedBySourceTemplate($hostTemplate);
                 $newInheritance->setNagiosHostTemplateRelatedByTargetTemplate($template);
                 $newInheritance->setOrder(count($templateList));
                 try {
                     $newInheritance->save();
                     $success = "Template added to inheritance chain.";
                 } catch (Exception $e) {
                     $error = $e->getMessage();
                 }
             }
         }
     } else {
         if ($_POST['request'] == 'host_template_modify_checks') {
             if (count($modifiedData)) {
                 foreach ($modifiedData as $tempVariable) {
                     $tempVariable = trim($tempVariable);
Пример #3
0
 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;
 }