Пример #1
0
             $membership->setNagiosContactGroup($tempGroup);
             $membership->save();
             $success = "New Service Contact Group Link added.";
         }
     }
 } else {
     if ($_POST['request'] == 'add_servicegroup_command') {
         $c = new Criteria();
         $c->add(NagiosServiceGroupMemberPeer::TEMPLATE, $serviceTemplate->getId());
         $c->add(NagiosServiceGroupMemberPeer::SERVICE_GROUP, $_POST['servicegroup_id']);
         $tempMembership = NagiosServiceGroupMemberPeer::doSelectOne($c);
         if ($tempMembership) {
             $error = "That service group already exists in that list!";
         } else {
             $membership = new NagiosServiceGroupMember();
             $membership->setTemplate($serviceTemplate->getId());
             $membership->setServiceGroup($_POST['servicegroup_id']);
             $membership->save();
             $success = "New Service Group Link added.";
         }
     } else {
         if ($_POST['request'] == 'command_parameter_add') {
             if (trim($_POST['service_manage']['parameter']) == "") {
                 $error = "Parameter cannot be blank.";
             } else {
                 // All is well for error checking, modify the command.
                 $param = new NagiosServiceCheckCommandParameter();
                 $param->setTemplate($serviceTemplate->getId());
                 $param->setParameter($_POST['service_manage']['parameter']);
                 $param->save();
                 $success = "Command Parameter added.";
 public function import()
 {
     $engine = $this->getEngine();
     $job = $engine->getJob();
     $job->addNotice("FruityServiceTemplateImporter beginning to import Service Template Configuration.");
     // Service templates
     $queuedServiceTemplates = array();
     foreach ($this->dbConn->query("SELECT * FROM nagios_service_templates", PDO::FETCH_ASSOC) as $serviceTemplate) {
         if (!$this->importServiceTemplate($serviceTemplate)) {
             $queuedServiceTemplates[] = $serviceTemplate;
         }
     }
     if (count($queuedServiceTemplates)) {
         $job->addNotice("FruityServiceTemplateImporter is now processing queued service templates.");
     }
     while (count($queuedServiceTemplates)) {
         for ($counter = 0; $counter < count($queuedServiceTemplates); $counter++) {
             if ($this->importServiceTemplate($queuedServiceTemplates[$counter])) {
                 unset($queuedServiceTemplates[$counter]);
             }
         }
     }
     // Service template check commands
     $job->addNotice("FruityServiceTemplateImporter now processing Service Template Check Commands.");
     foreach ($this->dbConn->query("SELECT * FROM nagios_services_check_command_parameters WHERE service_template_id IS NOT NULL", PDO::FETCH_ASSOC) as $commandParameterInfo) {
         $serviceTemplateName = $this->getServiceTemplateNameById($commandParameterInfo['service_template_id']);
         if (!$serviceTemplateName) {
             $job->addNotice("Fruity Service Template Check Command Parameter Importer: Could not find service template with id " . $commandParameterInfo['service_template_id']);
             continue;
         }
         // Get the template
         $serviceTemplate = NagiosServiceTemplatePeer::getByName($serviceTemplateName);
         if (!$serviceTemplate) {
             $job->addNotice("Fruity Service Template Check Command Parameter Importer: Could not find service template with name " . $serviceTemplateName);
             continue;
         }
         $newParameter = new NagiosServiceCheckCommandParameter();
         $newParameter->setTemplate($serviceTemplate->getId());
         $newParameter->setParameter($commandParameterInfo['parameter']);
         $newParameter->save();
     }
     // Service template extended information
     $job->addNotice("FruityServiceTemplateImporter now processing Service Template Extended Information.");
     foreach ($this->dbConn->query("SELECT * FROM nagios_service_template_extended_info", PDO::FETCH_ASSOC) as $extInfo) {
         $serviceTemplateName = $this->getServiceTemplateNameById($extInfo['service_template_id']);
         if (!$serviceTemplateName) {
             $job->addNotice("Fruity Service Template Extended Info Importer: Could not find service template with id " . $extInfo['service_template_id']);
             continue;
         }
         // Get the template
         $serviceTemplate = NagiosServiceTemplatePeer::getByName($serviceTemplateName);
         if (!$serviceTemplate) {
             $job->addNotice("Fruity Service Template Extended Info Importer: Could not find service template with name " . $serviceTemplateName);
             continue;
         }
         // Go through the extended info, and set it on the template.
         $serviceTemplate->setNotes($extInfo['notes']);
         $serviceTemplate->setNotesUrl($extInfo['notes_url']);
         $serviceTemplate->setActionUrl($extInfo['action_url']);
         $serviceTemplate->setIconImage($extInfo['icon_image']);
         $serviceTemplate->setIconImageAlt($extInfo['icon_image_alt']);
         $serviceTemplate->save();
     }
     // Service template contact group memberships
     $job->addNotice("FruityServiceTemplateImporter now processing Service Template Contact Group Memberships.");
     foreach ($this->dbConn->query("SELECT * FROM nagios_service_template_contactgroups", PDO::FETCH_ASSOC) as $membershipInfo) {
         $serviceTemplateName = $this->getServiceTemplateNameById($membershipInfo['service_template_id']);
         if (!$serviceTemplateName) {
             $job->addNotice("Fruity Service Template Contact Group Importer: Could not find service template with id " . $membershipInfo['service_template_id']);
             continue;
         }
         // Get the template
         $serviceTemplate = NagiosServiceTemplatePeer::getByName($serviceTemplateName);
         if (!$serviceTemplate) {
             $job->addNotice("Fruity Service Template Contact Group Importer: Could not find service template with name " . $serviceTemplateName);
             continue;
         }
         // Now get Contact Group Name
         $contactGroupName = $this->getContactGroupNameById($membershipInfo['contactgroup_id']);
         if (!$contactGroupName) {
             $job->addNotice("Fruity Service Template Contact Group Importer: Could not find contact group with id: " . $membershipInfo['contactgroup_id']);
             continue;
         }
         $contactGroup = NagiosContactGroupPeer::getByName($contactGroupName);
         if (!$contactGroup) {
             $job->addNotice("Fruity Service Template Contact Group Importer: Could not find contact group with name: " . $contactGroupName);
             continue;
         }
         $membership = new NagiosServiceContactGroupMember();
         $membership->setTemplate($serviceTemplate->getId());
         $membership->setNagiosContactGroup($contactGroup);
         $membership->save();
     }
     // Service template service group memberships
     $job->addNotice("FruityServiceTemplateImporter now processing Service Template Service Group Memberships.");
     foreach ($this->dbConn->query("SELECT * FROM nagios_servicegroup_template_membership", PDO::FETCH_ASSOC) as $membershipInfo) {
         $serviceTemplateName = $this->getServiceTemplateNameById($membershipInfo['service_template_id']);
         if (!$serviceTemplateName) {
             $job->addNotice("Fruity Service Template Service Group Importer: Could not find service template with id " . $membershipInfo['service_template_id']);
             continue;
         }
         // Get the template
         $serviceTemplate = NagiosServiceTemplatePeer::getByName($serviceTemplateName);
         if (!$serviceTemplate) {
             $job->addNotice("Fruity Service Template Service Group Importer: Could not find service template with name " . $serviceTemplateName);
             continue;
         }
         // Now get Contact Group Name
         $serviceGroupName = $this->getServiceGroupNameById($membershipInfo['servicegroup_id']);
         if (!$serviceGroupName) {
             $job->addNotice("Fruity Service Template Service Group Importer: Could not find service group with id: " . $membershipInfo['servicegroup_id']);
             continue;
         }
         $serviceGroup = NagiosServiceGroupPeer::getByName($serviceGroupName);
         if (!$contactGroup) {
             $job->addNotice("Fruity Service Template Service Group Importer: Could not find service group with name: " . $serviceGroupName);
             continue;
         }
         $membership = new NagiosServiceGroupMember();
         $membership->setTemplate($serviceTemplate->getId());
         $membership->setNagiosServiceGroup($serviceGroup);
         $membership->save();
     }
     $job->addNotice("FruityServiceTemplateImporter finished importing Service Group Configuration.");
     $job->addNotice("FruityServiceImported: Finished importing a total of " . $this->totalImported . " Service Templates.");
 }