Exemple #1
0
 public static function getByHostAndDescription($hostname, $description)
 {
     // First get host
     $host = NagiosHostPeer::getByName($hostname);
     if (!$host) {
         return false;
     }
     $c = new Criteria();
     $c->add(NagiosServicePeer::HOST, $host->getId());
     $c->add(NagiosServicePeer::DESCRIPTION, $description);
     $c->setIgnoreCase(true);
     $service = NagiosServicePeer::doSelectOne($c);
     if (!$service) {
         return false;
     }
     return $service;
 }
 public function valid()
 {
     $values = $this->getSegment()->getValues();
     $job = $this->getEngine()->getJob();
     if (isset($values['use'])) {
         // We need to use a template
         $job->addNotice("This Service Ext Info uses a template: " . $values['use'][0]['value']);
         $template = NagiosServiceExtInfoImporter::getTemplateByName($values['use'][0]['value']);
         if (empty($template)) {
             $job->addNotice("That template is not found yet. Setting this host ext info as queued.");
             return false;
         }
     }
     // Check for service existence
     if (!isset($values['host_name']) || !isset($values['service_description'])) {
         $job->addNotice("The host or service for this service ext info is blank.  Service ext Info requires a host name.");
         return false;
     }
     $service = NagiosServicePeer::getByHostAndDescription($values['host_name'][0]['value'], $values['service_description'][0]['value']);
     if (empty($service)) {
         // Okay, so it's not assigned by hostname, last ditch effort, look
         // through hostgroups
         $host = NagiosHostPeer::getByName($values['host_name'][0]['value']);
         if (!$host) {
             $job->addNotice("The service specified by " . $values['host_name'][0]['value'] . ":" . $values['service_description'][0]['value'] . " was not found.  Setting this service ext info as queued.");
             return false;
         }
         // Go through the hostgroups for the host
         $memberships = $host->getNagiosHostgroupMemberships();
         foreach ($memberships as $membership) {
             $hostgroup = $membership->getNagiosHostgroup();
             $service = NagiosServicePeer::getByHostgroupAndDescription($hostgroup->getName(), $values['service_description'][0]['value']);
             if ($service) {
                 break;
             }
         }
     }
     if ($service) {
         $service->clearAllReferences(true);
     }
     if (!$service) {
         $job->addNotice("The service specified by " . $values['host_name'][0]['value'] . ":" . $values['service_description'][0]['value'] . " was not found.  Setting this service ext info as queued.");
         return false;
     }
     return true;
 }
 private function getAppliedHosts($hostValues, $hostgroupValues)
 {
     $appliedHosts = array();
     foreach ($hostValues as $val) {
         $val = $val['value'];
         if ($val == "*") {
             // Get all hosts
             $tempHosts = NagiosHostPeer::doSelect(new Criteria());
             foreach ($tempHosts as $tempHost) {
                 if (!array_key_exists($tempHost->getName(), $appliedHosts)) {
                     $appliedHosts[] = $tempHost;
                 }
             }
         } else {
             if (preg_match("/^!/", $val)) {
                 continue;
             } else {
                 $host = NagiosHostPeer::getByName($val);
                 if (!$host) {
                     // Give error
                     $values = $this->getSegment()->getValues();
                     $job = $this->getEngine()->getJob();
                     $job->addError("The host specified by name: " . $val . " was not found.  Setting this host ext info as queued.");
                     return false;
                 } else {
                     if (!array_key_exists($host->getName(), $appliedHosts)) {
                         $appliedHosts[] = $host;
                     }
                 }
             }
         }
     }
     foreach ($hostgroupValues as $val) {
         $val = $val['value'];
         // First check for *
         // then check for each hostgroup existence, then
         // each additional hostgroup
         if ($val == "*") {
             // Get all hostgroups
             $hostgroups = NagiosHostgroupPeer::doSelect(new Criteria());
             foreach ($hostgroups as $hg) {
                 $hosts = $hostgroup->getNagiosHosts();
                 foreach ($hosts as $tempHost) {
                     if (!array_key_exists($tempHost->getName(), $appliedHosts)) {
                         $appliedHosts[] = $tempHost;
                     }
                 }
             }
         } else {
             if (preg_match("/^!/", $val)) {
                 continue;
             } else {
                 $hg = NagiosHostgroupPeer::getByName($val);
                 if (!$hg) {
                     // Give error
                     $values = $this->getSegment()->getValues();
                     $job = $this->getEngine()->getJob();
                     $job->addError("The hostgroup specified by name: " . $val . " was not found.  Setting this host ext info as queued.");
                     return false;
                 } else {
                     $hosts = $hg->getMembers();
                     foreach ($hosts as $tempHost) {
                         if (!array_key_exists($tempHost->getName(), $appliedHosts)) {
                             $appliedHosts[] = $tempHost;
                         }
                     }
                 }
             }
         }
     }
     // Okay, do exclusions
     foreach ($hostValues as $val) {
         $val = $val['value'];
         if (preg_match("/^!/", $val)) {
             unset($appliedHosts[$val]);
         }
     }
     foreach ($hostgroupValues as $val) {
         $val = $val['value'];
         if (preg_match("/^!/", $val)) {
             $hg = NagiosHostgroupPeer::getByName($val);
             if (!$hg) {
                 // Do nothing
             } else {
                 $hosts = $hg->getMembers();
                 foreach ($hosts as $tempHost) {
                     unset($appliedHosts[$tempHost->getName()]);
                 }
             }
         }
     }
     return $appliedHosts;
 }
Exemple #4
0
 private function importHost($hostData)
 {
     $job = $this->getEngine()->getJob();
     // check to see if we have a host by that name
     if (NagiosHostPeer::getByName($hostData['host_name'])) {
         $job->addNotice("Fruity Host Importer: Host " . $hostData['host_name'] . " already exists.  Aborting it's import.");
         return true;
     }
     $newHost = new NagiosHost();
     $newHost->setName($hostData['host_name']);
     // Check to see if we need the template
     if (!empty($hostData['use_template_id'])) {
         $name = $this->getHostTemplateNameById($hostData['use_template_id'], $this->dbConn);
         if (!$name) {
             $job->addNotice("Fruity Host Importer:  Could not find template with id: " . $hostData['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) {
                 $job->addNotice("Fruity Host Importer: Could not find a template in the system with the name of: " . $name . ". Aborting it's import.");
                 return false;
             } else {
                 // Create a new inheritance relationship
                 $inheritance = new NagiosHostTemplateInheritance();
                 $inheritance->setNagiosHostTemplateRelatedByTargetTemplate($template);
                 $inheritance->setNagiosHost($newHost);
                 try {
                     $inheritance->save();
                 } catch (Exception $e) {
                     $job->addNotice("Fruity Host Importer:  Cannot add inheritance from " . $template->getName() . " to " . $newHost->getName());
                 }
             }
         }
     }
     // Okay, start 'er up!
     foreach ($hostData as $key => $val) {
         unset($name);
         if ($key == "host_id" || $key == "use_template_id" || $key == "host_name") {
             continue;
         }
         if ($key == "parents") {
             // we're gonna do parents after this
             continue;
         }
         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 == "retry_check_interval") {
             $key = "retry_interval";
         }
         if ($key == "check_command") {
             $name = $this->getCommandNameById($val);
             if ($name) {
                 $command = NagiosCommandPeer::getByName($name);
                 if ($command) {
                     $newHost->setCheckCommand($command->getId());
                 }
             }
             continue;
         }
         if ($key == "check_period") {
             $name = $this->getTimeperiodNameById($val);
             if ($name) {
                 $timeperiod = NagiosTimeperiodPeer::getByName($name);
                 if ($timeperiod) {
                     $newHost->setCheckPeriod($timeperiod->getId());
                 }
             }
             continue;
         }
         if ($key == "event_handler") {
             $name = $this->getCommandNameById($val);
             if ($name) {
                 $command = NagiosCommandPeer::getByName($name);
                 if ($command) {
                     $newHost->setEventHandler($command->getId());
                 }
             }
             continue;
         }
         if ($key == "notification_period") {
             $name = $this->getTimeperiodNameById($val);
             if ($name) {
                 $timeperiod = NagiosTimeperiodPeer::getByName($name);
                 if ($timeperiod) {
                     $newHost->setNotificationPeriod($timeperiod->getId());
                 }
             }
             continue;
         }
         try {
             $name = NagiosHostPeer::translateFieldName($key, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_PHPNAME);
         } catch (Exception $e) {
             $job->addNotice("Fruity Host Importer: Was unable to store unsupported value: " . $key);
         }
         if (!empty($name)) {
             $method = "set" . $name;
             $newHost->{$method}($val);
         }
     }
     $newHost->save();
     $job->addNotice("FruityHostImporter: Imported new host: " . $newHost->getName());
     $this->totalImported++;
     return true;
 }
 private function importService($serviceData)
 {
     $job = $this->getEngine()->getJob();
     $newService = new NagiosService();
     // Check to see if host or host template exists first
     if (!empty($serviceData['host_id'])) {
         $hostName = $this->getHostNameById($serviceData['host_id']);
         if (!$hostName) {
             $job->addNotice("Fruity Service Importer: Failed to find host with id: " . $serviceData['host_id']);
             return true;
         }
         $host = NagiosHostPeer::getByName($hostName);
         if (!$host) {
             $job->addNotice("Fruity Service Importer: Failed to find host with name: " . $hostName);
             return true;
         }
         $newService->setHost($host->getId());
     } else {
         if (!empty($serviceData['host_template_id'])) {
             $hostTemplateName = $this->getHostTemplateNameById($serviceData['host_template_id']);
             if (!$hostTemplateName) {
                 $job->addNotice("Fruity Service Importer: Failed to find host template with id: " . $serviceData['host_template_id']);
                 return true;
             }
             $hostTemplate = NagiosHostTemplatePeer::getByName($hostTemplateName);
             if (!$hostTemplate) {
                 $job->addNotice("Fruity Service Importer: Failed to find host template with name: " . $hostTemplateName);
                 return true;
             }
             $newService->setHostTemplate($hostTemplate->getId());
         } else {
             if (!empty($serviceData['hostgroup_id'])) {
                 $hostgroupName = $this->getHostGroupNameById($serviceData['hostgroup_id']);
                 if (!$hostgroupName) {
                     $job->addNotice("Fruity Service Importer: Failed to find host group with id: " . $serviceData['host_template_id']);
                     return true;
                 }
                 $hostgroup = NagiosHostGroupPeer::getByName($hostgroupName);
                 if (!$hostgroup) {
                     $job->addNotice("Fruity Service Importer: Failed to find host group with name: " . $hostGroupName);
                     return true;
                 }
                 $newService->setHostgroup($hostgroup->getId());
             }
         }
     }
     // Check to see if we need the template
     if (!empty($serviceData['use_template_id'])) {
         $name = $this->getServiceTemplateNameById($serviceData['use_template_id'], $this->dbConn);
         if (!$name) {
             $job->addNotice("Fruity Service Importer:  Could not find template with id: " . $serviceData['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->setNagiosService($newService);
                 try {
                     $inheritance->save();
                 } catch (Exception $e) {
                     $job->addNotice("Fruity Service Template Importer:  Cannot add inheritance from " . $template->getName() . " to " . $newService->getName());
                 }
             }
         }
     }
     // Okay, start 'er up!
     foreach ($serviceData as $key => $val) {
         unset($name);
         if ($key == "service_template_id" || $key == "use_template_id" || $key == "template_name" || $key == "host_id" || $key == "hostgroup_id" || $key == "host_template_id" || $key == "service_id") {
             continue;
         }
         if ($key == "service_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) {
                     $newService->setCheckCommand($command->getId());
                 }
             }
             continue;
         }
         if ($key == "check_period") {
             $name = $this->getTimeperiodNameById($val);
             if ($name) {
                 $timeperiod = NagiosTimeperiodPeer::getByName($name);
                 if ($timeperiod) {
                     $newService->setCheckPeriod($timeperiod->getId());
                 }
             }
             continue;
         }
         if ($key == "event_handler") {
             $name = $this->getCommandNameById($val);
             if ($name) {
                 $command = NagiosCommandPeer::getByName($name);
                 if ($command) {
                     $newService->setEventHandler($command->getId());
                 }
             }
             continue;
         }
         if ($key == "notification_period") {
             $name = $this->getTimeperiodNameById($val);
             if ($name) {
                 $timeperiod = NagiosTimeperiodPeer::getByName($name);
                 if ($timeperiod) {
                     $newService->setNotificationPeriod($timeperiod->getId());
                 }
             }
             continue;
         }
         try {
             $name = NagiosServiceTemplatePeer::translateFieldName($key, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_PHPNAME);
         } catch (Exception $e) {
             $job->addNotice("Fruity Service Importer: Was unable to store unsupported value: " . $key);
         }
         if (!empty($name)) {
             $method = "set" . $name;
             $newService->{$method}($val);
         }
     }
     $job->addNotice("Fruity Service Importer: Saved service: " . $newService->getDescription() . " on " . $newService->getOwnerDescription());
     $newService->save();
     $this->totalImported++;
     return true;
 }
 public function import()
 {
     $engine = $this->getEngine();
     $job = $engine->getJob();
     $job->addNotice("FruityDependencyImporter beginning to import Dependency Configuration.");
     foreach ($this->dbConn->query("SELECT * FROM nagios_dependencies", PDO::FETCH_ASSOC) as $dependency) {
         $newDependency = new NagiosDependency();
         if (!empty($dependency['service_id'])) {
             // This is a service dependency
             $lilacService = $this->getLilacServiceById($dependency['service_id']);
             if (!$lilacService) {
                 $job->addNotice("Fruity Dependency Importer: Failed to get Lilac service with an id matching: " . $dependency['service_id']);
                 return true;
             }
             $newDependency->setService($lilacService->getId());
             // Create Target
             $targetLilacService = $this->getLilacServiceById($dependency['target_service_id']);
             if (!$targetLilacService) {
                 $job->addNotice("Fruity Dependency Importer: Failed to get Lilac service with an id matching: " . $dependency['target_service_id']);
                 return true;
             }
             $target = new NagiosDependencyTarget();
             $target->setNagiosDependency($newDependency);
             $target->setTargetService($targetLilacService->getId());
             $target->save();
         } else {
             if (!empty($dependency['host_id'])) {
                 // This is a host dependency
                 $hostName = $this->getHostNameById($dependency['host_id']);
                 $host = NagiosHostPeer::getByName($hostName);
                 if (!$host) {
                     $job->addNotice("Fruity Dependency Importer: Failed to get Lilac host with an name matching: " . $hostName);
                     return true;
                 }
                 $newDependency->setHost($host->getId());
                 // Create Target
                 $hostName = $this->getHostNameById($dependency['target_host_id']);
                 $host = NagiosHostPeer::getByName($hostName);
                 if (!$host) {
                     $job->addNotice("Fruity Dependency Importer: Failed to get Lilac host with an name matching: " . $hostName);
                     return true;
                 }
                 $target = new NagiosDependencyTarget();
                 $target->setNagiosDependency($newDependency);
                 $target->setTargetHost($host->getId());
                 $target->save();
             } else {
                 if (!empty($dependency['service_template_id'])) {
                     // This is a service template dependency
                     $templateName = $this->getServiceTemplateNameById($dependency['service_template_id']);
                     $template = NagiosServiceTemplatePeer::getByName($templateName);
                     if (!$template) {
                         $job->addNotice("Fruity Dependency Importer: Failed to get Lilac service template with  name matching: " . $templateName);
                         return true;
                     }
                     $newDependency->setServiceTemplate($template->getId());
                     // Create Target
                     $targetLilacService = $this->getLilacServiceById($dependency['target_service_id']);
                     if (!$targetLilacService) {
                         $job->addNotice("Fruity Dependency Importer: Failed to get Lilac service with an id matching: " . $dependency['target_service_id']);
                         return true;
                     }
                     $target = new NagiosDependencyTarget();
                     $target->setNagiosDependency($newDependency);
                     $target->setTargetService($targetLilacService->getId());
                     $target->save();
                 } else {
                     if (!empty($dependency['host_template_id'])) {
                         // This is for a host template dependency
                         $templateName = $this->getHostTemplateNameById($dependency['host_template_id']);
                         $template = NagiosHostTemplatePeer::getByName($templateName);
                         if (!$template) {
                             $job->addNotice("Fruity Dependency Importer: Failed to get Lilac host template with  name matching: " . $templateName);
                             return true;
                         }
                         $newDependency->setHostTemplate($template->getId());
                         $hostName = $this->getHostNameById($dependency['target_host_id']);
                         $host = NagiosHostPeer::getByName($hostName);
                         if (!$host) {
                             $job->addNotice("Fruity Dependency Importer: Failed to get Lilac host with an name matching: " . $hostName);
                             return true;
                         }
                         $target = new NagiosDependencyTarget();
                         $target->setNagiosDependency($newDependency);
                         $target->setTargetHost($host->getId());
                         $target->save();
                     }
                 }
             }
         }
         foreach ($dependency as $key => $val) {
             unset($name);
             if ($key == "dependency_id" || $key == "host_id" || $key == "host_template_id" || $key == "service_template_id" || $key == "service_id" || $key == "target_service_id" || $key == "target_host_id") {
                 continue;
             }
             if ($key == "command_name") {
                 $key = "name";
             }
             if ($key == "command_line") {
                 $key = "line";
             }
             if ($key == "command_desc") {
                 $key = "description";
             }
             try {
                 $name = NagiosDependencyPeer::translateFieldName($key, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_PHPNAME);
             } catch (Exception $e) {
                 $job->addNotice("Fruity Dependency Importer: Was unable to store unsupported value: " . $key);
             }
             if (!empty($name)) {
                 $method = "set" . $name;
                 $newDependency->{$method}($val);
             }
         }
         $newDependency->save();
         $newDependency->setName("Imported Dependency #" . $newDependency->getId());
         $newDependency->save();
         $job->addNotice("FruityDependencyImporter imported dependency with id: " . $newDependency->getId());
     }
     $job->addNotice("FruityDependencyImporter finished importing Dependency Configuration.");
 }
 public function import()
 {
     $job = $this->getEngine()->getJob();
     $config = $this->getEngine()->getConfig();
     $segment = $this->getSegment();
     $values = $segment->getValues();
     $fileName = $segment->getFilename();
     // We need to determine if we are a template
     if (isset($values['name'])) {
         // We are a template
         $job->addNotice("Saving internal host escalation template: " . $values['name'][0]['value']);
         NagiosHostEscalationImporter::saveTemplate($values['name'][0]['value'], $segment);
         return true;
     }
     // Check if we need to bring in values from a template
     if (isset($values['use'])) {
         // We sure are using a template!
         // Okay, hokey multi-inheritance support for the importer
         $tempValues = $this->getTemplateValues($values['use'][0]['value']);
         // Okay, go through each
         foreach ($tempValues as $key => $val) {
             if (!isset($values[$key])) {
                 $values[$key] = $val;
             }
         }
     }
     // Okay, we first iterate through any possible dependent_host_name's
     if (isset($values['host_name'])) {
         $host_names = explode(",", $values['host_name'][0]['value']);
         foreach ($host_names as $host_name) {
             $escalation = new NagiosEscalation();
             $host = NagiosHostPeer::getByName($host_name);
             if (!$host) {
                 return false;
             }
             $escalation->setNagiosHost($host);
             $ret = $this->__process($escalation);
             if (!$ret) {
                 return false;
             }
             $ret = $this->__addContacts($escalation);
             if (!$ret) {
                 return false;
             }
             // Need to give it a temp name
             $escalation->save();
             $escalation->setDescription("Imported Escalation #" . $escalation->getId());
             $escalation->save();
             $job->addNotice("NagiosHostEscalation finished importing Host Escalation for " . $host_name);
             $host->clearAllReferences(true);
             $escalation->clearAllReferences(true);
         }
     }
     if (isset($values['hostgroup_name'])) {
         $hostgroup_names = explode(",", $values['hostgroup_name'][0]['value']);
         foreach ($hostgroup_names as $hostgroup_name) {
             $escalation = new NagiosEscalation();
             $hostgroup = NagiosHostgroupPeer::getByName($hostgroup_name);
             if (!$hostgroup) {
                 return false;
             }
             $escalation->setNagiosHostgroup($hostgroup);
             $ret = $this->__process($escalation);
             if (!$ret) {
                 return false;
             }
             $ret = $this->__addContacts($escalation);
             if (!$ret) {
                 return false;
             }
             $escalation->save();
             $escalation->setDescription("Imported Escalation #" . $escalation->getId());
             $escalation->save();
             $job->addNotice("NagiosHostEscalation finished importing Host Escalation for hostgroup " . $hostgroup_name);
             $hostgroup->clearAllReferences(true);
             $escalation->clearAllReferences(true);
         }
     }
     return true;
 }
 public function import()
 {
     $engine = $this->getEngine();
     $job = $engine->getJob();
     $job->addNotice("FruityEscalationImporter beginning to import Dependency Configuration.");
     foreach ($this->dbConn->query("SELECT * FROM nagios_escalations", PDO::FETCH_ASSOC) as $escalation) {
         $newEscalation = new NagiosEscalation();
         if (!empty($escalation['service_id'])) {
             // This is a service escalation
             $lilacService = $this->getLilacServiceById($escalation['service_id']);
             if (!$lilacService) {
                 $job->addNotice("Fruity Escalation Importer: Failed to get Lilac service with an id matching: " . $escalation['service_id']);
                 return true;
             }
             $newEscalation->setService($lilacService->getId());
         } else {
             if (!empty($escalation['host_id'])) {
                 // This is a host escalation
                 $hostName = $this->getHostNameById($escalation['host_id']);
                 $host = NagiosHostPeer::getByName($hostName);
                 if (!$host) {
                     $job->addNotice("Fruity Escalation Importer: Failed to get Lilac host with an name matching: " . $hostName);
                     return true;
                 }
                 $newEscalation->setHost($host->getId());
             } else {
                 if (!empty($escalation['service_template_id'])) {
                     // This is a service template escalation
                     $templateName = $this->getServiceTemplateNameById($escalation['service_template_id']);
                     $template = NagiosServiceTemplatePeer::getByName($templateName);
                     if (!$template) {
                         $job->addNotice("Fruity Escalation Importer: Failed to get Lilac service template with  name matching: " . $templateName);
                         return true;
                     }
                     $newEscalation->setServiceTemplate($template->getId());
                 } else {
                     if (!empty($escalation['host_template_id'])) {
                         // This is for a host template escalation
                         $templateName = $this->getHostTemplateNameById($escalation['host_template_id']);
                         $template = NagiosHostTemplatePeer::getByName($templateName);
                         if (!$template) {
                             $job->addNotice("Fruity Escalation Importer: Failed to get Lilac host template with  name matching: " . $templateName);
                             return true;
                         }
                         $newEscalation->setHostTemplate($template->getId());
                     }
                 }
             }
         }
         foreach ($escalation as $key => $val) {
             unset($name);
             if ($key == "escalation_id" || $key == "host_id" || $key == "host_template_id" || $key == "service_template_id" || $key == "service_id") {
                 continue;
             }
             if ($key == "escalation_description") {
                 $key = "description";
             }
             if ($key == "escalation_period") {
                 $escalationName = $this->getTimeperiodNameById($id);
                 if ($escalationName) {
                     $newEscalation->setEscalationPeriodByName($escalationName);
                 }
                 continue;
             }
             try {
                 $name = NagiosEscalationPeer::translateFieldName($key, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_PHPNAME);
             } catch (Exception $e) {
                 $job->addNotice("Fruity Escalation Importer: Was unable to store unsupported value: " . $key);
             }
             if (!empty($name)) {
                 $method = "set" . $name;
                 $newEscalation->{$method}($val);
             }
         }
         $newEscalation->save();
         // Handle escalation contact groups.
         foreach ($this->dbConn->query("SELECT * FROM nagios_escalation_contactgroups WHERE escalation_id = " . $escalation['escalation_id'], PDO::FETCH_ASSOC) as $contactgroup) {
             $contactgroupName = $this->getContactGroupNameById($contactgroup['contactgroup_id']);
             if ($contactgroupName) {
                 $lilacContactGroup = NagiosContactGroupPeer::getByName($contactgroupName);
                 if ($lilacContactGroup) {
                     $newContactGroup = new NagiosEscalationContactgroup();
                     $newContactGroup->setEscalation($newEscalation->getId());
                     $newContactGroup->setContactgroup($lilacContactGroup->getId());
                     $newContactGroup->save();
                 }
             }
         }
     }
     $job->addNotice("FruityEscalationImporter finished importing Escalation Configuration.");
 }
 public function import()
 {
     $job = $this->getEngine()->getJob();
     $config = $this->getEngine()->getConfig();
     $segment = $this->getSegment();
     $values = $segment->getValues();
     $fileName = $segment->getFilename();
     // We need to determine if we are a template
     $isTemplate = false;
     if (isset($values['name'])) {
         // We're a template, just do a template process.
         $obj = new NagiosServiceTemplate();
         $ret = $this->__process($obj);
         if (!$ret) {
             return false;
         }
         $obj->save();
         $obj->clearAllReferences(true);
         $job->addNotice("NagiosServiceImporter finished importing service template: " . $obj->getName());
         return true;
     } else {
         // Okay, we need to create new Services for each type
         if (isset($values['host_name'])) {
             foreach ($values['host_name'] as $hostNameValues) {
                 $obj = new NagiosService();
                 $host = NagiosHostPeer::getByName($hostNameValues['value']);
                 if (!$host) {
                     return false;
                 }
                 // Okay, we got a proper host
                 $obj->setNagiosHost($host);
                 $ret = $this->__process($obj);
                 if (!$ret) {
                     return false;
                 }
                 $obj->save();
                 $host->clearAllReferences(true);
                 $job->addNotice("NagiosServiceImporter finished importing service : " . $obj->getDescription() . " for host: " . $host->getName());
             }
         }
         // Okay, now search for hostgroups
         if (isset($values['hostgroup_name'])) {
             foreach ($values['hostgroup_name'] as $hostGroupValues) {
                 $obj = new NagiosService();
                 $hostgroup = NagiosHostgroupPeer::getByName($hostGroupValues['value']);
                 if (!$hostgroup) {
                     return false;
                 }
                 // Okay, we got a proper hostgroup
                 $obj->setNagiosHostgroup($hostgroup);
                 $ret = $this->__process($obj);
                 if (!$ret) {
                     return false;
                 }
                 $obj->save();
                 $hostgroup->clearAllReferences(true);
             }
         }
         // Okay, now search for hostgroups
         if (isset($values['hostgroup'])) {
             foreach ($values['hostgroup'] as $hostGroupValues) {
                 $obj = new NagiosService();
                 $hostgroup = NagiosHostgroupPeer::getByName($hostGroupValues['value']);
                 if (!$hostgroup) {
                     return false;
                 }
                 // Okay, we got a proper hostgroup
                 $obj->setNagiosHostgroup($hostgroup);
                 $ret = $this->__process($obj);
                 if (!$ret) {
                     return false;
                 }
                 $obj->save();
                 $hostgroup->clearAllReferences(true);
             }
         }
     }
     $obj->clearAllReferences(true);
     return true;
 }
Exemple #10
0
 public function addMemberByName($name)
 {
     // Support for adding ALL hosts
     if ($name == "*") {
         $hosts = NagiosHostPeer::doSelect(new Criteria());
         foreach ($hosts as $host) {
             $this->addMemberByName($host->getName());
         }
         return true;
     }
     $host = NagiosHostPeer::getByName($name);
     if (!$host) {
         return false;
     }
     $id = $this->getId();
     if (!empty($id)) {
         $c = new Criteria();
         $c->add(NagiosHostgroupMembershipPeer::HOSTGROUP, $this->getId());
         $c->add(NagiosHostgroupMembershipPeer::HOST, $host->getId());
         $relationship = NagiosHostgroupMembershipPeer::doSelectOne($c);
         if ($relationship) {
             return true;
         }
         // Already exists.
     }
     // Create new relationship
     $relationship = new NagiosHostgroupMembership();
     $relationship->setNagiosHost($host);
     $relationship->setNagiosHostgroup($this);
     $relationship->save();
     return true;
 }