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;
 }
 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;
 }
Esempio n. 3
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;
 }