private function importServiceTemplate($templateData) { $job = $this->getEngine()->getJob(); // check to see if we have a template by that name if (NagiosServiceTemplatePeer::getByName($templateData['template_name'])) { $job->addNotice("Fruity Service Template Importer: Template " . $templateData['template_name'] . " already exists. Aborting it's import."); return true; } $newTemplate = new NagiosServiceTemplate(); $newTemplate->setName($templateData['template_name']); // Check to see if we need the template if (!empty($templateData['use_template_id'])) { $name = $this->getServiceTemplateNameById($templateData['use_template_id'], $this->dbConn); if (!$name) { $job->addNotice("Fruity Service 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 = NagiosServiceTemplatePeer::getByName($name); if (!$template) { return false; } else { // Create a new inheritance relationship $inheritance = new NagiosServiceTemplateInheritance(); $inheritance->setNagiosServiceTemplateRelatedByTargetTemplate($template); $inheritance->setNagiosServiceTemplateRelatedBySourceTemplate($newTemplate); try { $inheritance->save(); } catch (Exception $e) { $job->addNotice("Fruity Service Template Importer: Cannot add inheritance from " . $template->getName() . " to " . $newTemplate->getName()); } } } } // Okay, start 'er up! foreach ($templateData as $key => $val) { unset($name); if ($key == "service_template_id" || $key == "use_template_id" || $key == "template_name") { continue; } if ($key == "template_description") { $key = "description"; } if ($key == "notification_options_warning") { $key = "notification_on_warning"; } if ($key == "notification_options_unknown") { $key = "notification_on_unknown"; } if ($key == "notification_options_critical") { $key = "notification_on_critical"; } if ($key == "notification_options_recovery") { $key = "notification_on_recovery"; } if ($key == "notification_options_flapping") { $key = "notification_on_flapping"; } if ($key == "stalking_options_warning") { $key = "stalking_on_warning"; } if ($key == "stalking_options_unknown") { $key = "stalking_on_unknown"; } if ($key == "stalking_options_critical") { $key = "stalking_on_critical"; } if ($key == "stalking_options_ok") { $key = "stalking_on_ok"; } if ($key == "max_check_attempts") { $key = "maximum_check_attempts"; } if ($key == "retry_check_interval") { $key = "retry_interval"; } 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 = NagiosServiceTemplatePeer::translateFieldName($key, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_PHPNAME); } catch (Exception $e) { $job->addNotice("Fruity Service Template Importer: Was unable to store unsupported value: " . $key); } if (!empty($name)) { $method = "set" . $name; $newTemplate->{$method}($val); } } $job->addNotice("Fruity Service Template Importer: Saved service template: " . $newTemplate->getName()); $newTemplate->save(); $this->totalImported++; return true; }
* */ include_once 'includes/config.inc'; if (isset($_POST['request'])) { if ($_POST['request'] == 'add_service_template') { // Check for pre-existing service template with same name if ($lilac->service_template_exists($_POST['template_name'])) { $error = "A service template with that name already exists!"; } else { // Field Error Checking if ($_POST['template_name'] == '' || $_POST['template_description'] == '') { $addError = 1; $error = "Fields shown are required and cannot be left blank."; } else { $template = new NagiosServiceTemplate(); $template->setName($_POST['template_name']); $template->setDescription($_POST['template_description']); $template->save(); header("Location: service_template.php?id=" . $template->getId()); } } } } print_header("Service Template Editor"); print_window_header("Add Service Template", "100%"); ?> <form name="service_template_add_form" method="post" action="add_service_template.php"> <input type="hidden" name="request" value="add_service_template" /> <?php double_pane_form_window_start(); ?>