public function import()
 {
     $job = $this->getEngine()->getJob();
     $config = $this->getEngine()->getConfig();
     $segment = $this->getSegment();
     $values = $segment->getValues();
     $fileName = $segment->getFilename();
     $servicegroup = new NagiosServiceGroup();
     if (isset($values['members'])) {
         $members = explode(",", $values['members'][0]['value']);
         for ($counter = 0; $counter < count($members); $counter += 2) {
             // Get Service
             $service = NagiosServicePeer::getByHostAndDescription($members[$counter], $members[$counter + 1]);
             $servicegroup->addService($service);
             $service->clearAllReferences(true);
         }
     }
     foreach ($values as $key => $entries) {
         foreach ($entries as $entry) {
             // Skips
             $value = $entry['value'];
             $lineNum = $entry['line'];
             if ($key == 'members') {
                 // Already did it above
                 continue;
             }
             // Okay, let's check that the method DOES exist
             if (!method_exists($servicegroup, $this->fieldMethods[$key])) {
                 $job->addError("Method " . $this->fieldMethods[$key] . " does not exist for variable: " . $key . " on line " . $lineNum . " in file " . $fileName);
                 if (!$config->getVar('continue_error')) {
                     return false;
                 }
             } else {
                 call_user_method($this->fieldMethods[$key], $servicegroup, $value);
             }
         }
     }
     $servicegroup->save();
     $servicegroup->clearAllReferences(true);
     $job->addNotice("NagiosServiceGroupImporter finished importing service group: " . $servicegroup->getName());
     return true;
 }
Esempio n. 2
0
 protected function getLilacServiceById($id)
 {
     // Get service info
     $res = $this->dbConn->query("select * from nagios_services where service_id = " . $id);
     if ($res) {
         $row = $res->fetch();
         // Okay, let's see
         if (!empty($row['host_id'])) {
             $hostName = $this->getHostNameById($row['host_id']);
             return NagiosServicePeer::getByHostAndDescription($hostName, $row['service_description']);
         }
         if (!empty($row['host_template_id'])) {
             $hostTemplateName = $this->getHostTemplateNameById($row['host_template_id']);
             return NagiosServicePeer::getByHostTemplateAndDescription($hostTemplateName, $row['service_description']);
         }
         if (!empty($row['hostgroup_id'])) {
             $hostgroupName = $this->getHostGroupNameById($row['hostgroup_id']);
             return NagiosServicePeer::getByHostgroupAndDescription($hostgroupName, $row['service_description']);
         }
     }
     return false;
 }
 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 service escalation template: " . $values['name'][0]['value']);
         NagiosServiceEscalationImporter::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();
             $service = NagiosServicePeer::getByHostAndDescription($host_name, $values['service_description'][0]['value']);
             if (!$service) {
                 return false;
             }
             $escalation->setNagiosService($service);
             $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();
             $escalation->clearAllReferences(true);
             $service->clearAllReferences(true);
             $job->addNotice("NagiosServiceEscalationImporter finished importing Service Escalation for " . $host_name);
         }
     }
     if (isset($values['hostgroup_name'])) {
         $hostgroup_names = explode(",", $values['hostgroup_name'][0]['value']);
         foreach ($hostgroup_names as $hostgroup_name) {
             $escalation = new NagiosEscalation();
             $service = NagiosServicePeer::getByHostgroupAndDescription($hostgroup_name, $values['service_description'][0]['value']);
             if (!$service) {
                 return false;
             }
             $escalation->setNagiosService($service);
             $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();
             $escalation->clearAllReferences(true);
             $service->clearAllReferences(true);
             $job->addNotice("NagiosServiceEscalationImporter finished importing Service Escalation for hostgroup " . $hostgroup_name);
         }
     }
     return true;
 }
 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 service ext info template: " . $values['name'][0]['value']);
         NagiosServiceExtInfoImporter::saveTemplate($values['name'][0]['value'], $segment);
         return true;
     }
     // Get our host obj
     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;
             }
         }
     }
     $service = NagiosServicePeer::getByHostAndDescription($values['host_name'][0]['value'], $values['service_description'][0]['value']);
     foreach ($values as $key => $entries) {
         foreach ($entries as $entry) {
             // Skips
             $value = $entry['value'];
             $lineNum = $entry['line'];
             if ($key == 'use' || $key == 'name' || $key == 'register' || $key == 'host_name' || $key == 'service_description') {
                 continue;
             }
             // Okay, let's check that the method DOES exist
             if (!method_exists($service, $this->fieldMethods[$key])) {
                 $job->addError("Method " . $this->fieldMethods[$key] . " does not exist for variable: " . $key . " on line " . $lineNum . " in file " . $fileName);
                 if (!$config->getVar('continue_error')) {
                     return false;
                 }
             } else {
                 call_user_method($this->fieldMethods[$key], $service, $value);
             }
         }
     }
     $service->save();
     $service->clearAllReferences(true);
     $job->addNotice("NagiosServiceExtInfo finished importing extended info for: " . $service->getNagiosHost()->getName() . ":" . $service->getDescription());
     return true;
 }